]> SALOME platform Git repositories - modules/geom.git/blob - src/AdvancedGUI/AdvancedGUI_DividedDiskDlg.cxx
Salome HOME
EDF 2281 : Second constructor and final documentation for the divided disk
[modules/geom.git] / src / AdvancedGUI / AdvancedGUI_DividedDiskDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 #include "AdvancedGUI_DividedDiskDlg.h"
23
24 #include <DlgRef.h>
25 #include <GeometryGUI.h>
26 #include <GEOMBase.h>
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33 // OCCT Includes
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS.hxx>
36 #include <TopExp.hxx>
37 #include <TColStd_IndexedMapOfInteger.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39
40 #include <GEOMImpl_Types.hxx>
41
42 //=================================================================================
43 // Constructor
44 //=================================================================================
45 AdvancedGUI_DividedDiskDlg::AdvancedGUI_DividedDiskDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
46   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
47 {
48 //   QPixmap imageOp  (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DIVIDEDDISK_R_RATIO")));
49   QPixmap imageOp1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_R")));
50   QPixmap imageOp2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_DISK_PNT_VEC_R")));
51   QPixmap imageSel (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
52
53   setWindowTitle(tr("GEOM_DIVIDEDDISK_TITLE"));
54
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDEDDISK"));
57   mainFrame()->RadioButton1->setIcon(imageOp1);
58   mainFrame()->RadioButton2->setIcon(imageOp2);
59 //   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
60 //   mainFrame()->RadioButton2->close();
61   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
62   mainFrame()->RadioButton3->close();
63
64   GroupParams      = new DlgRef_1Spin(centralWidget());
65   GroupParams->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
66   GroupParams->TextLabel1->setText(tr("GEOM_RADIUS"));
67   
68   GroupOrientation = new DlgRef_3Radio(centralWidget());
69   GroupOrientation->GroupBox1->setTitle(tr("GEOM_ORIENTATION"));
70   GroupOrientation->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
71   GroupOrientation->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
72   GroupOrientation->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
73   
74   GroupPntVecR = new DlgRef_2Sel1Spin(centralWidget());
75   GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76   GroupPntVecR->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
77   GroupPntVecR->TextLabel2->setText(tr("GEOM_VECTOR"));
78   GroupPntVecR->TextLabel3->setText(tr("GEOM_RADIUS"));
79   GroupPntVecR->PushButton1->setIcon(imageSel);
80   GroupPntVecR->PushButton2->setIcon(imageSel);
81   GroupPntVecR->LineEdit1->setReadOnly(true);
82   GroupPntVecR->LineEdit2->setReadOnly(true);
83   //@@ setup dialog box layout here @@//
84
85   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
86   layout->setMargin(0); layout->setSpacing(6);
87   layout->addWidget(GroupParams);
88   layout->addWidget(GroupOrientation);
89   layout->addWidget(GroupPntVecR);
90   /***************************************************************/
91
92   setHelpFileName("create_divideddisk_page.html");
93
94   Init();
95 }
96
97 //=================================================================================
98 // Destructor
99 //=================================================================================
100 AdvancedGUI_DividedDiskDlg::~AdvancedGUI_DividedDiskDlg()
101 {
102   // no need to delete child widgets, Qt does it all for us
103 }
104
105 //=================================================================================
106 // function : Init()
107 // purpose  :
108 //=================================================================================
109 void AdvancedGUI_DividedDiskDlg::Init()
110 {
111   // Get setting of step value from file configuration
112   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
113   double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
114
115   // min, max, step and decimals for spin boxes & initial values
116   initSpinBox(GroupParams->SpinBox_DX, 0.00001, COORD_MAX, step, "length_precision" );
117   GroupParams ->SpinBox_DX->setValue(100);
118   GroupPntVecR->SpinBox_DX->setValue(100);
119   
120   GroupOrientation->RadioButton1->setChecked(true);
121   myOrientation = 1;
122
123   // Signal/slot connections
124   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126   connect(myGeomGUI,     SIGNAL(SignalDefaultStepValueChanged(double)),
127           this,          SLOT(SetDoubleSpinBoxStep(double)));
128   
129   connect(this,                           SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
130
131   connect(GroupPntVecR->PushButton1,      SIGNAL(clicked()),                this, SLOT(SetEditCurrentArgument()));
132   connect(GroupPntVecR->PushButton2,      SIGNAL(clicked()),                this, SLOT(SetEditCurrentArgument()));
133
134   connect(GroupParams->SpinBox_DX,        SIGNAL(valueChanged(double)),     this, SLOT(ValueChangedInSpinBox()));  
135   connect(GroupPntVecR->SpinBox_DX,       SIGNAL(valueChanged(double)),     this, SLOT(ValueChangedInSpinBox()));
136   
137   connect(GroupOrientation->RadioButton1, SIGNAL(clicked()),                this, SLOT(RadioButtonClicked()));
138   connect(GroupOrientation->RadioButton2, SIGNAL(clicked()),                this, SLOT(RadioButtonClicked()));
139   connect(GroupOrientation->RadioButton3, SIGNAL(clicked()),                this, SLOT(RadioButtonClicked()));
140
141   initName(tr("GEOM_DIVIDEDDISK"));
142   
143   ConstructorsClicked(0);
144 }
145
146 //=================================================================================
147 // function : SetDoubleSpinBoxStep()
148 // purpose  : Double spin box management
149 //=================================================================================
150 void AdvancedGUI_DividedDiskDlg::SetDoubleSpinBoxStep (double step)
151 {
152   //@@ set double spin box step for all spin boxes here @@//
153 }
154
155 //=================================================================================
156 // function : ConstructorsClicked()
157 // purpose  : Radio button management
158 //=================================================================================
159 void AdvancedGUI_DividedDiskDlg::ConstructorsClicked (int constructorId)
160 {
161   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
162
163   switch (constructorId) {
164   case 0:
165     {
166       GroupPntVecR->hide();
167       GroupParams->show();
168       GroupOrientation->show();
169
170       disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
171       globalSelection(); // close local contexts, if any
172       break;
173     }
174   case 1:
175     {
176       GroupParams->hide();
177       GroupOrientation->hide();
178       GroupPntVecR->show();
179
180       GroupPntVecR->PushButton1->click();
181       break;
182     }
183   }
184
185   qApp->processEvents();
186   updateGeometry();
187   resize(minimumSizeHint());
188   SelectionIntoArgument();
189
190   displayPreview(true);
191 }
192
193 //=================================================================================
194 // function : RadioButtonClicked()
195 // purpose  : Radio button management
196 //=================================================================================
197 void AdvancedGUI_DividedDiskDlg::RadioButtonClicked()
198
199   if (GroupOrientation->RadioButton1->isChecked())
200     myOrientation = 1;
201   else if (GroupOrientation->RadioButton2->isChecked())
202     myOrientation = 2;
203   else if (GroupOrientation->RadioButton3->isChecked())
204     myOrientation = 3;
205   
206   displayPreview(true);
207 }
208
209 //=================================================================================
210 // function : ClickOnOk()
211 // purpose  :
212 //=================================================================================
213 void AdvancedGUI_DividedDiskDlg::ClickOnOk()
214 {
215   if (ClickOnApply())
216     ClickOnCancel();
217 }
218
219 //=================================================================================
220 // function : ClickOnApply()
221 // purpose  :
222 //=================================================================================
223 bool AdvancedGUI_DividedDiskDlg::ClickOnApply()
224 {
225   if (!onAccept())
226     return false;
227
228   initName();
229
230   return true;
231 }
232
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose  : Called when selection is changed or on dialog initialization or activation
236 //=================================================================================
237 void AdvancedGUI_DividedDiskDlg::SelectionIntoArgument()
238 {
239   if (getConstructorId() == 0)
240     return;
241
242   erasePreview();
243   myEditCurrentArgument->setText("");
244
245   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
246   SALOME_ListIO aSelList;
247   aSelMgr->selectedObjects(aSelList);
248
249   if (aSelList.Extent() != 1) {
250     if      (myEditCurrentArgument == GroupPntVecR->LineEdit1) myPoint.nullify();
251     else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) myDir.nullify();
252     return;
253   }
254
255   TopAbs_ShapeEnum aNeedType = myEditCurrentArgument == GroupPntVecR->LineEdit2 ? TopAbs_EDGE : TopAbs_VERTEX;
256   GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
257   TopoDS_Shape aShape;
258   if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ){
259     QString aName = GEOMBase::GetName( aSelectedObject.get() );
260
261     myEditCurrentArgument->setText(aName);
262     
263     // clear selection
264     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
265     myGeomGUI->getApp()->selectionMgr()->clearSelected();
266     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
267         this, SLOT(SelectionIntoArgument()));
268     
269     if (myEditCurrentArgument == GroupPntVecR->LineEdit1) {
270       myPoint = aSelectedObject;
271       if (myPoint && !myDir)
272     GroupPntVecR->PushButton2->click();
273     }
274     else if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
275       myDir = aSelectedObject;
276       if (myDir && !myPoint)
277     GroupPntVecR->PushButton1->click();
278     }
279   }
280   displayPreview(true);
281 }
282
283 //=================================================================================
284 // function : SetEditCurrentArgument()
285 // purpose  :
286 //=================================================================================
287 void AdvancedGUI_DividedDiskDlg::SetEditCurrentArgument()
288 {
289   QPushButton* send = (QPushButton*)sender();
290
291   if (send == GroupPntVecR->PushButton1) {
292     myEditCurrentArgument = GroupPntVecR->LineEdit1;
293
294     GroupPntVecR->PushButton2->setDown(false);
295     GroupPntVecR->LineEdit2->setEnabled(false);
296   }
297   else if (send == GroupPntVecR->PushButton2) {
298     myEditCurrentArgument = GroupPntVecR->LineEdit2;
299
300     GroupPntVecR->PushButton1->setDown(false);
301     GroupPntVecR->LineEdit1->setEnabled(false);
302   }
303
304   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
305   if (myEditCurrentArgument == GroupPntVecR->LineEdit2) {
306     globalSelection(); // close local contexts, if any
307     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
308   }
309   else {
310     globalSelection(); // close local contexts, if any
311     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
312   }
313   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
314           this, SLOT(SelectionIntoArgument()));
315
316   // enable line edit
317   myEditCurrentArgument->setEnabled(true);
318   myEditCurrentArgument->setFocus();
319   // after setFocus(), because it will be setDown(false) when loses focus
320   send->setDown(true);
321
322   // seems we need it only to avoid preview disappearing, caused by selection mode change
323   displayPreview(true);
324 }
325
326 //=================================================================================
327 // function : ActivateThisDialog()
328 // purpose  :
329 //=================================================================================
330 void AdvancedGUI_DividedDiskDlg::ActivateThisDialog()
331 {
332   GEOMBase_Skeleton::ActivateThisDialog();
333   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
334            this, SLOT( SelectionIntoArgument() ) );
335   
336   ConstructorsClicked( getConstructorId() );
337 }
338
339 //=================================================================================
340 // function : enterEvent [REDEFINED]
341 // purpose  :
342 //=================================================================================
343 void AdvancedGUI_DividedDiskDlg::enterEvent (QEvent*)
344 {
345   if (!mainFrame()->GroupConstructors->isEnabled())
346     ActivateThisDialog();
347 }
348
349 //=================================================================================
350 // function : ValueChangedInSpinBox()
351 // purpose  :
352 //=================================================================================
353 void AdvancedGUI_DividedDiskDlg::ValueChangedInSpinBox()
354 {
355   displayPreview(true);
356 }
357
358 //=================================================================================
359 // function : createOperation
360 // purpose  :
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr AdvancedGUI_DividedDiskDlg::createOperation()
363 {
364   return getGeomEngine()->GetIAdvancedOperations(getStudyId());
365 }
366
367 //=================================================================================
368 // function : isValid
369 // purpose  :
370 //=================================================================================
371 bool AdvancedGUI_DividedDiskDlg::isValid (QString& msg)
372 {
373   bool ok = true;
374
375   //@@ add custom validation actions here @@//
376
377   return ok;
378 }
379
380 //=================================================================================
381 // function : execute
382 // purpose  :
383 //=================================================================================
384 bool AdvancedGUI_DividedDiskDlg::execute (ObjectList& objects)
385 {
386   bool res = false;
387
388   GEOM::GEOM_Object_var anObj;
389
390   GEOM::GEOM_IAdvancedOperations_var anOper = GEOM::GEOM_IAdvancedOperations::_narrow(getOperation());
391   CORBA::Double theRatio = 50;  
392   CORBA::Double theR = 0;
393   
394   switch (getConstructorId()) {
395   case 0:
396     theR = GroupParams->SpinBox_DX->value(); // init parameter value from dialog box ;
397
398     // call engine function
399     anObj = anOper->MakeDividedDisk(theR, theRatio, myOrientation);
400     res = !anObj->_is_nil();
401     if (res && !IsPreview())
402     {
403       QStringList aParameters;
404       aParameters << GroupParams->SpinBox_DX->text();
405       if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
406     }
407     break;
408   case 1:
409     theR = GroupPntVecR->SpinBox_DX->value(); 
410     
411     // call engine function
412     anObj = anOper->MakeDividedDiskPntVecR(myPoint.get(), myDir.get(), theR, theRatio);
413     res = !anObj->_is_nil();
414     if (res && !IsPreview())
415     {
416       QStringList aParameters;
417       aParameters << GroupPntVecR->SpinBox_DX->text();
418       if ( aParameters.count() > 0 ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
419     }
420     break;
421   }
422     
423   
424   if (res)
425     objects.push_back(anObj._retn());
426
427   return res;
428 }