Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
options-carac.qt.cc
Go to the documentation of this file.
1 /*
2  * Moka : Un modeleur de 3-G-cartes.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of Moka
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "options-carac.qt.hh"
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 
28 #include <QtGui/QGridLayout>
29 #include <QtGui/QHBoxLayout>
30 #include <QtGui/QLabel>
31 #include <Qt3Support/Q3Accel>
32 
33 
34 // Constructeur
35 //-------------
37  :
38  QDialog(parent) ,
39  FParent(parent) ,
40  FUpdate(false)
41 {
42  // Modification du titre de la boite de dialogue
43  setWindowTitle("Topological characteristics") ;
44 
45  // Definition du raccourci
46 
47  Q3Accel * Raccourci = new Q3Accel(this) ;
48  Raccourci -> insertItem(QKeySequence(Qt :: Key_Space) , 9) ;
49  Raccourci -> connectItem(9 , this , SLOT(close())) ;
50 
51  QHBoxLayout * placement = new QHBoxLayout(this) ;
52 
53  //-- global --
54  FGlobal = new QGroupBox("Globals") ;
55  QGridLayout * global = new QGridLayout(FGlobal) ;
56 
57  global->addWidget(new QLabel("darts:") , 1 , 0) ;
58  global->addWidget(new QLabel("vertices:") , 2 , 0) ;
59  global->addWidget(new QLabel("edges:") , 3 , 0);
60  global->addWidget(new QLabel("faces:") , 4 , 0) ;
61  global->addWidget(new QLabel("volumes:") , 5 , 0) ;
62  global->addWidget(new QLabel("composants:") , 6 , 0) ;
63 
64  for (int i = 0 ; i < 6 ; i++)
65  {
66  FGlobalCells [i] = new QLabel("") ;
67  global -> addWidget(FGlobalCells [ i ] , i + 1 , 1) ;
68  }
69 
70  global -> addWidget(new QLabel("0-borders:") , 2 , 2) ;
71  global -> addWidget(new QLabel("1-borders:") , 3 , 2) ;
72  global -> addWidget(new QLabel("2-borders:") , 4 , 2) ;
73  global -> addWidget(new QLabel("3-borders:") , 5 , 2) ;
74 
75  for (int i = 0 ; i < 4 ; i++)
76  {
77  FGlobalBorders [i] = new QLabel("") ;
78  global -> addWidget(FGlobalBorders [ i ] , i + 2 , 3) ;
79  }
80 
81  //-- volume --
82  FPointed = new QGroupBox("Volume incident to 'last'") ;
83  QGridLayout * pointed = new QGridLayout(FPointed) ;
84 
85  pointed->addWidget(new QLabel("darts:") , 1 , 0);
86  pointed->addWidget(new QLabel("vertices:") , 2 , 0);
87  pointed->addWidget(new QLabel("edges:") , 3 , 0);
88  pointed->addWidget(new QLabel("faces:") , 4 , 0);
89 
90  for (int i = 0 ; i < 4 ; i++)
91  FPointedCells [i] = new QLabel("") ;
92 
93  for (int i = 0 ; i < 4 ; i++)
94  pointed -> addWidget(FPointedCells [ i ] , i + 1 , 1) ;
95 
96 
97  pointed -> addWidget(new QLabel("0-borders:") , 1 , 2) ;
98  pointed -> addWidget(new QLabel("1-borders:") , 2 , 2) ;
99  pointed -> addWidget(new QLabel("2-borders:") , 3 , 2) ;
100 
101  for (int i = 0 ; i < 3 ; i++)
102  FPointedBorders [i] = new QLabel("") ;
103 
104  for (int i = 0 ; i < 3 ; i++)
105  pointed -> addWidget(FPointedBorders [ i ] , i + 1 , 3) ;
106 
107  QWidget * WPar = new QWidget ;
108  QGridLayout * par = new QGridLayout(WPar) ;
109 
110  par->
111  addWidget(new QLabel("Euler characteristic:"),1 , 0) ;
112  par->
113  addWidget(new QLabel("Orientability coefficient:"),2 , 0) ;
114  par -> addWidget(new QLabel("Genus:") , 3 , 0) ;
115 
116  FEulerLabel = new QLabel("") ;
117  par -> addWidget(FEulerLabel , 1 , 1) ;
118  FOrientLabel = new QLabel("") ;
119  par -> addWidget(FOrientLabel , 2 , 1) ;
120  FGenusLabel = new QLabel("") ;
121  par -> addWidget(FGenusLabel , 3 , 1) ;
122  FNameLabel = new QLabel("") ;
123 
124  pointed -> addWidget(WPar);
125  pointed -> addWidget(FNameLabel);
126 
127  // placement dans le layout principal
128  placement -> addWidget(FGlobal) ;
129  placement -> addWidget(FPointed) ;
130 }
131 
132 // Destructeur
133 //------------
135 {}
136 
138 {
139  // Calcul des caracteristiques topologiques:
140  int nb[4], nb2WhenClosed;
141  int nc[5], nd;
142  int euler, orient, genus;
143 
144  char buffer[64];
145 
146  // Caracteristiques generales:
147  FParent -> getControler()
148  -> getMapGlobalCharacteristics(& nd,
149  & nc [ 0 ] , & nc [ 1 ] , & nc [ 2 ] ,
150  & nc [ 3 ] , & nc [ 4 ] , & nb [ 0 ] ,
151  & nb [ 1 ] , & nb [ 2 ] , & nb [ 3 ]) ;
152 
153  sprintf(buffer, "%d", nd) ;
154  FGlobalCells [ 0 ] -> setText(buffer) ;
155 
156  for (int i = 0 ; i < 4 ; ++i)
157  {
158  sprintf(buffer , "%d" , nc [ i ]) ;
159  FGlobalCells [ i+1 ] -> setText(buffer) ;
160 
161  sprintf(buffer , "%d" , nb [ i ]) ;
162  FGlobalBorders [ i ] -> setText(buffer) ;
163  }
164 
165  sprintf(buffer , "%d" , nc [ 4 ]) ;
166  FGlobalCells [ 5 ] -> setText(buffer) ;
167 
168  // Caracteristiques de l'objet pointe:
169  string name;
170 
171  bool ok =
172  FParent -> getControler()
173  -> getSurfaceCharacteristics(& name , & nd ,
174  & nc [ 0 ] , & nc [ 1 ] , & nc [ 2 ] ,
175  & nb [ 0 ] , & nb [ 1 ] , & nb [ 2 ] ,
176  & nb2WhenClosed ,
177  & euler , & orient , & genus) ;
178 
179  if (ok)
180  {
181  sprintf(buffer , "%d" , nd) ;
182  FPointedCells [ 0 ] -> setText(buffer) ;
183 
184  for (int i = 0 ; i < 3 ; ++i)
185  {
186  sprintf(buffer , "%d" , nc [ i ]) ;
187  FPointedCells [ i+1 ] -> setText(buffer) ;
188 
189  sprintf(buffer , "%d" , nb [ i ]) ;
190  FPointedBorders [ i ] -> setText(buffer) ;
191  }
192 
193  sprintf(buffer , "%d" , euler) ;
194  FEulerLabel -> setText(buffer) ;
195 
196  sprintf(buffer , "%d" , orient) ;
197  FOrientLabel -> setText(buffer) ;
198 
199  sprintf(buffer , "%d" , genus) ;
200  FGenusLabel -> setText(buffer) ;
201 
202  FNameLabel->setText(QString::fromUtf8(name.c_str()));
203  }
204  else
205  {
206  FPointedCells [ 0 ] -> setText("") ;
207 
208  for (int i = 0 ; i < 3 ; ++i)
209  {
210  FPointedBorders [ i ] -> setText("") ;
211  FPointedCells [ i+1 ] -> setText("") ;
212  }
213 
214  FEulerLabel -> setText("") ;
215  FOrientLabel -> setText("") ;
216  FGenusLabel -> setText("") ;
217  FNameLabel -> setText("") ;
218  }
219 
220  FParent -> repaint() ;
221 }
222 
224 {
225  show() ;
226  update() ;
227 }