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