Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
options-volumic-homology.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 
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 #include "compute-homology.hh"
28 
29 #include <QtGui/QGridLayout>
30 #include <QtGui/QHBoxLayout>
31 #include <QtGui/QLabel>
32 #include <Qt3Support/Q3Accel>
33 
34 #ifndef _WINDOWS
35 #include "chrono.hh"
36 #endif
37 
38 // Constructeur
39 //-------------
41  QDialog(parent) ,
42  FParent(parent) ,
43  FUpdate(false),
44  FHomology(NULL)
45 {
46  // Modification du titre de la boite de dialogue
47  setWindowTitle("Homology") ;
48 
49  // Definition du raccourci
50 
51  Q3Accel * Raccourci = new Q3Accel(this) ;
52  Raccourci -> insertItem(QKeySequence(Qt :: Key_Space) , 9) ;
53  Raccourci -> connectItem(9 , this , SLOT(close())) ;
54 
55  QVBoxLayout * placement = new QVBoxLayout(this) ;
56 
57  //-- global --
58  FGenerators = new QGroupBox("Generators") ;
59  QGridLayout * global = new QGridLayout(FGenerators) ;
60 
61  Fh0 = new QLabel("") ;
62  Fh1free = new QLabel("") ;
63  Fh1torsion = new QLabel("") ;
64  Fh2free = new QLabel("") ;
65  Fh2torsion = new QLabel("") ;
66  Fh3 = new QLabel("") ;
67 
68  FButtonH0 = new QPushButton("H0:");
69  FButtonH1free = new QPushButton("free:");
70  FButtonH1torsion = new QPushButton("torsion:");
71  FButtonH2free = new QPushButton("free:");
72  FButtonH2torsion = new QPushButton("torsion:");
73  FButtonH3 = new QPushButton("H3:");
74 
75  FButtonH0->setCheckable(true);
76  connect(FButtonH0, SIGNAL(toggled(bool)), this,
77  SLOT(callbackToggleH0(bool)));
78 
79  FButtonH1free->setCheckable(true);
80  connect(FButtonH1free, SIGNAL(toggled(bool)), this,
81  SLOT(callbackToggleH1free(bool)));
82 
83  FButtonH1torsion->setCheckable(true);
84  connect(FButtonH1torsion, SIGNAL(toggled(bool)), this,
85  SLOT(callbackToggleH1torsion(bool)));
86 
87  FButtonH2free->setCheckable(true);
88  connect(FButtonH2free, SIGNAL(toggled(bool)), this,
89  SLOT(callbackToggleH2free(bool)));
90 
91  FButtonH2torsion->setCheckable(true);
92  connect(FButtonH2torsion, SIGNAL(toggled(bool)), this,
93  SLOT(callbackToggleH2torsion(bool)));
94 
95  FButtonH3->setCheckable(true);
96  connect(FButtonH3, SIGNAL(toggled(bool)), this,
97  SLOT(callbackToggleH3(bool)));
98 
99  global->addWidget(FButtonH0 , 1 , 0) ;
100  global->addWidget(Fh0 , 1 , 1) ;
101 
102  global->addWidget(new QLabel("H1:") , 2 , 0) ;
103 
104  global->addWidget(FButtonH1free , 2 , 1) ;
105  global->addWidget(Fh1free , 2 , 2) ;
106 
107  global->addWidget(FButtonH1torsion , 2 , 3) ;
108  global->addWidget(Fh1torsion , 2 , 4) ;
109 
110  global->addWidget(new QLabel("H2:") , 3 , 0) ;
111 
112  global->addWidget(FButtonH2free , 3 , 1) ;
113  global->addWidget(Fh2free , 3 , 2) ;
114 
115  global->addWidget(FButtonH2torsion , 3 , 3) ;
116  global->addWidget(Fh2torsion , 3 , 4) ;
117 
118  global->addWidget(FButtonH3 , 4 , 0) ;
119  global->addWidget(Fh3 , 4 , 1) ;
120 
121  //-- volume --
122  FInfo = new QGroupBox("Performances") ;
123  QGridLayout * pointed = new QGridLayout(FInfo) ;
124 
125  FTime = new QLabel("") ;
126  FMemory = new QLabel("") ;
127 
128  pointed->addWidget(new QLabel("time:") , 1 , 0);
129  pointed->addWidget(FTime , 1 , 1) ;
130 
131  pointed->addWidget(new QLabel("memory:") , 2 , 0);
132  pointed->addWidget(FMemory , 2 , 1) ;
133 
134  // placement dans le layout principal
135  placement -> addWidget(FGenerators) ;
136  placement -> addWidget(FInfo) ;
137 }
138 
139 // Destructeur
140 //------------
142 { delete FHomology; }
143 
145 {
146  delete FHomology;
147 
148  std::ostringstream os;
149 
150 #ifndef _WINDOWS
151  CChrono c; c.setMode(PUS_MODE); c.start();
152 #endif
153 
154  FHomology = new GMap3d::CHomology(FParent->getControler()->getMap(),
155  FParent->getControler()->
156  getSelectionMark());
157  if ( FHomology!=NULL && FHomology->computeVolumicHomology() )
158  FParent->getControler()->setMessage("Homology computed.");
159  else
160  FParent->getControler()->
161  setMessage("Impossible to compute Homology: not enough memory.");
162 
163 #ifndef _WINDOWS
164  c.stop();
165 #endif
166 
167  // Ho
168  os.str("-");
169  os<<FHomology->getH0FreeGenerators();
170  Fh0->setText(os.str().c_str()) ;
171 
172  // H1free
173  os.str("");
174  os<<FHomology->getH1FreeGenerators();
175  Fh1free->setText(os.str().c_str()) ;
176 
177  // H1torsion
178  os.str("");
179  os<<FHomology->getH1TorsionGenerators();
180  Fh1torsion->setText(os.str().c_str()) ;
181 
182  // H2free
183  os.str("-");
184  os<<FHomology->getH2FreeGenerators();
185  Fh2free->setText(os.str().c_str()) ;
186 
187  // H2torsion
188  os.str("");
189  os<<FHomology->getH2TorsionGenerators();
190  Fh2torsion->setText(os.str().c_str()) ;
191 
192  // H3
193  os.str("-");
194  os<<FHomology->getH3FreeGenerators();
195  Fh3->setText(os.str().c_str()) ;
196 
197  // Memory
198  os.str("");
199  unsigned long s = FHomology->size();
200  std::string unit(" bytes");
201  if ( s>8000 )
202  {
203  s/=1024;
204  unit = " kilo-bytes";
205  if ( s>8000 )
206  {
207  s/=1024;
208  unit = " mega-bytes";
209  }
210  }
211 
212  os<<s<<unit;
213  FMemory->setText(os.str().c_str()) ;
214 
215  // Time
216  os.str("");
217 #ifndef _WINDOWS
218  os<<c.getTime("");
219 #endif
220  FTime->setText(os.str().c_str()) ;
221 
222  FButtonH0->setChecked(FHomology->getShowH0());
223  FButtonH1free->setChecked(FHomology->getShowH1free());
224  FButtonH1torsion->setChecked(FHomology->getShowH1torsion());
225  FButtonH2free->setChecked(FHomology->getShowH2free());
226  FButtonH2torsion->setChecked(FHomology->getShowH2torsion());
227  FButtonH3->setChecked(FHomology->getShowH3());
228 
229  FParent->getControler()->setSelectionChanged();
230  FParent -> repaint() ;
231 }
232 
234 {
235  show() ;
236  update() ;
237 }
238 
239 void OptionsVolumicHomology::callbackToggleH0(bool ADraw)
240 {
241  FHomology->setShowH0(ADraw);
242  FParent->getControler()->setSelectionChanged();
243  FParent -> repaint() ;
244 }
245 
246 void OptionsVolumicHomology::callbackToggleH1free(bool ADraw)
247 {
248  FHomology->setShowH1free(ADraw);
249  FParent->getControler()->setSelectionChanged();
250  FParent -> repaint() ;
251 }
252 
253 void OptionsVolumicHomology::callbackToggleH1torsion(bool ADraw)
254 {
255  FHomology->setShowH1torsion(ADraw);
256  FParent->getControler()->setSelectionChanged();
257  FParent -> repaint() ;
258 }
259 
260 void OptionsVolumicHomology::callbackToggleH2free(bool ADraw)
261 {
262  FHomology->setShowH2free(ADraw);
263  FParent->getControler()->setSelectionChanged();
264  FParent -> repaint() ;
265 }
266 
267 void OptionsVolumicHomology::callbackToggleH2torsion(bool ADraw)
268 {
269  FHomology->setShowH2torsion(ADraw);
270  FParent->getControler()->setSelectionChanged();
271  FParent -> repaint() ;
272 }
273 
274 void OptionsVolumicHomology::callbackToggleH3(bool ADraw)
275 {
276  FHomology->setShowH3(ADraw);
277  FParent->getControler()->setSelectionChanged();
278  FParent -> repaint() ;
279 }
280 
281