]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_PartitionDlg.cxx
Salome HOME
RNC: EDF 1618 Modified sketcher to allow creation of arcs of circle with the destinat...
[modules/geom.git] / src / OperationGUI / OperationGUI_PartitionDlg.cxx
1 //  Copyright (C) 2007-2010  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 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : OperationGUI_PartitionDlg.cxx
24 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "OperationGUI_PartitionDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <GEOMImpl_Types.hxx>
33
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
43
44 //=================================================================================
45 // class    : OperationGUI_PartitionDlg()
46 // purpose  : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
52   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
53 {
54   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
55   QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
56   QPixmap image1(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
57   QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
58
59   setWindowTitle(tr("GEOM_PARTITION_TITLE"));
60
61   /***************************************************************/
62   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PARTITION"));
63   mainFrame()->RadioButton1->setIcon(image0);
64   mainFrame()->RadioButton2->setIcon(image1);
65   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
66   mainFrame()->RadioButton3->close();
67
68   // Full partition (contains half-space partition)
69   GroupPoints = new DlgRef_2Sel1List1Check(centralWidget());
70   GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
71   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
72   GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECTS"));
73   GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
74   GroupPoints->PushButton1->setIcon(image2);
75   GroupPoints->PushButton2->setIcon(image2);
76   GroupPoints->LineEdit1->setReadOnly(true);
77   GroupPoints->LineEdit2->setReadOnly(true);
78   GroupPoints->LineEdit1->setEnabled(true);
79   GroupPoints->LineEdit2->setEnabled(false);
80   GroupPoints->CheckButton1->setText(tr("GEOM_KEEP_NONLIMIT_SHAPES"));
81
82   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
83   layout->setMargin(0); layout->setSpacing(6);
84   layout->addWidget(GroupPoints);
85
86   /***************************************************************/
87
88   setHelpFileName("partition_page.html");
89
90   Init();
91 }
92
93
94 //=================================================================================
95 // function : ~OperationGUI_PartitionDlg()
96 // purpose  : Destroys the object and frees any allocated resources
97 //=================================================================================
98 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
99 {
100   // no need to delete child widgets, Qt does it all for us
101 }
102
103 void OperationGUI_PartitionDlg::SetListMaterials(GEOM::ListOfLong ListMaterials)
104 {
105   myListMaterials = ListMaterials;
106 }
107
108 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
109 {
110   return myListMaterials;
111 }
112
113 //=================================================================================
114 // function : Init()
115 // purpose  :
116 //=================================================================================
117 void OperationGUI_PartitionDlg::Init()
118 {
119   /* type for sub shape selection */
120   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
121   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
122   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
123   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
124   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
125   GroupPoints->ComboBox1->addItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
126   GroupPoints->CheckButton1->setChecked(false);
127
128   mainFrame()->GroupBoxPublish->show();
129
130   /* signals and slots connections */
131   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
133
134   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
135
136   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138
139   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
141
142   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
143
144   connect(myGeomGUI->getApp()->selectionMgr(),
145            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
146
147   initName(tr("GEOM_PARTITION"));
148
149   ConstructorsClicked(0);
150   GroupPoints->PushButton1->click();
151 }
152
153
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose  : Radio button management
157 //=================================================================================
158 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
159 {
160   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
161   globalSelection();
162
163   myListShapes.length(0);
164   myListTools.length(0);
165   myListKeepInside.length(0);
166   myListRemoveInside.length(0);
167   myListMaterials.length(0);
168
169   switch (constructorId) {
170   case 0: /*Full partition */
171     GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
172     GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECTS"));
173     GroupPoints->TextLabel3->show();
174     GroupPoints->ComboBox1->show();
175     GroupPoints->ComboBox1->setCurrentIndex(0);
176     GroupPoints->CheckButton1->show();
177     GroupPoints->PushButton1->setDown(true);
178     GroupPoints->PushButton2->setDown(false);
179     GroupPoints->LineEdit1->setEnabled(true);
180     GroupPoints->LineEdit2->setEnabled(false);
181     break;
182   case 1: /*Half-space partition */
183     GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
184     GroupPoints->TextLabel3->hide();
185     GroupPoints->ComboBox1->hide();
186     GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
187     GroupPoints->CheckButton1->hide();
188     GroupPoints->PushButton1->setDown(true);
189     GroupPoints->LineEdit1->setEnabled(true);
190     break;
191   }
192
193   myEditCurrentArgument = GroupPoints->LineEdit1;
194   GroupPoints->LineEdit1->clear();
195   GroupPoints->LineEdit2->clear();
196
197   qApp->processEvents();
198   updateGeometry();
199   resize(minimumSizeHint());
200
201   myEditCurrentArgument->setFocus();
202   connect(myGeomGUI->getApp()->selectionMgr(),
203            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204   SelectionIntoArgument();
205 }
206
207
208 //=================================================================================
209 // function : ClickOnOk()
210 // purpose  :
211 //=================================================================================
212 void OperationGUI_PartitionDlg::ClickOnOk()
213 {
214   if (ClickOnApply())
215     ClickOnCancel();
216 }
217
218
219 //=================================================================================
220 // function : ClickOnApply()
221 // purpose  :
222 //=================================================================================
223 bool OperationGUI_PartitionDlg::ClickOnApply()
224 {
225   if (!onAccept())
226     return false;
227
228   initName();
229   //  0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
230   //  ConstructorsClicked(getConstructorId());
231   return true;
232 }
233
234
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose  : Called when selection as changed or other case
238 //=================================================================================
239 void OperationGUI_PartitionDlg::SelectionIntoArgument()
240 {
241   myEditCurrentArgument->setText("");
242   QString aString = "";
243
244   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
245   SALOME_ListIO aSelList;
246   aSelMgr->selectedObjects(aSelList);
247
248   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
249
250   if (nbSel < 1) {
251     if (myEditCurrentArgument == GroupPoints->LineEdit1) {
252       myListShapes.length(0);
253       myListMaterials.length(0);
254     }
255     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
256       myListTools.length(0);
257   }
258
259   // One and only one plane can be selected
260
261   if (getConstructorId() == 1 &&
262        myEditCurrentArgument == GroupPoints->LineEdit2 &&
263        nbSel != 1) {
264     myListTools.length(0);
265     return;
266   }
267
268   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
269     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
270     myListMaterials.length(0);
271     if (!myListShapes.length())
272       return;
273   }
274   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
275     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
276     if (!myListTools.length())
277       return;
278   }
279
280   myEditCurrentArgument->setText(aString);
281 }
282
283
284 //=================================================================================
285 // function : SetEditCurrentArgument()
286 // purpose  :
287 //=================================================================================
288 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
289 {
290   QPushButton* send = (QPushButton*)sender();
291
292   if (send == GroupPoints->PushButton1) {
293     myEditCurrentArgument = GroupPoints->LineEdit1;
294     GroupPoints->PushButton2->setDown(false);
295     GroupPoints->LineEdit1->setEnabled(true);
296     GroupPoints->LineEdit2->setEnabled(false);
297   }
298   else if (send == GroupPoints->PushButton2) {
299     myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
300     myEditCurrentArgument = GroupPoints->LineEdit2;
301     GroupPoints->PushButton1->setDown(false);
302     GroupPoints->LineEdit1->setEnabled(false);
303     GroupPoints->LineEdit2->setEnabled(true);
304     if (getConstructorId() == 1)
305       globalSelection(GEOM_PLANE);
306   }
307
308   globalSelection(GEOM_ALLSHAPES);
309
310   myEditCurrentArgument->setFocus();
311   SelectionIntoArgument();
312   send->setDown(true);
313 }
314
315
316 //=================================================================================
317 // function : LineEditReturnPressed()
318 // purpose  :
319 //=================================================================================
320 void OperationGUI_PartitionDlg::LineEditReturnPressed()
321 {
322   QLineEdit* send = (QLineEdit*)sender();
323
324   if (send == GroupPoints->LineEdit1 ||
325        send == GroupPoints->LineEdit2) {
326       myEditCurrentArgument = send;
327       GEOMBase_Skeleton::LineEditReturnPressed();
328   }
329 }
330
331
332 //=================================================================================
333 // function : ActivateThisDialog()
334 // purpose  :
335 //=================================================================================
336 void OperationGUI_PartitionDlg::ActivateThisDialog()
337 {
338   GEOMBase_Skeleton::ActivateThisDialog();
339   connect(myGeomGUI->getApp()->selectionMgr(),
340            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
341
342   ConstructorsClicked(getConstructorId());
343 }
344
345
346 //=================================================================================
347 // function : enterEvent()
348 // purpose  :
349 //=================================================================================
350 void OperationGUI_PartitionDlg::enterEvent(QEvent*)
351 {
352   if (!mainFrame()->GroupConstructors->isEnabled())
353     this->ActivateThisDialog();
354 }
355
356
357 //=================================================================================
358 // function : createOperation
359 // purpose  :
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
362 {
363   return getGeomEngine()->GetIBooleanOperations(getStudyId());
364 }
365
366
367 //=================================================================================
368 // function : isValid
369 // purpose  :
370 //=================================================================================
371 bool OperationGUI_PartitionDlg::isValid(QString&)
372 {
373   return (myListShapes.length()     || myListTools.length() ||
374           myListKeepInside.length() || myListRemoveInside.length());
375 }
376
377
378 //=================================================================================
379 // function : execute
380 // purpose  :
381 //=================================================================================
382 bool OperationGUI_PartitionDlg::execute(ObjectList& objects)
383 {
384   bool res = false;
385
386   GEOM::GEOM_Object_var anObj;
387   QString msg;
388
389   int aLimit = GetLimit();
390   int aConstructorId = getConstructorId();
391   int aKeepNonlimitShapes = 0;
392
393   if (aConstructorId == 1) {
394     aLimit = GEOM::SHAPE;
395   }
396   else {
397     if (GroupPoints->CheckButton1->isChecked()) {
398       aKeepNonlimitShapes = 1;
399     }
400     else {
401       aKeepNonlimitShapes = 0;
402     }
403   }
404
405   if (isValid(msg)) {
406     GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
407     anObj = anOper->MakePartition(myListShapes, myListTools,
408                                   myListKeepInside, myListRemoveInside,
409                                   aLimit, false, myListMaterials, aKeepNonlimitShapes);
410     res = true;
411   }
412
413   if (!anObj->_is_nil()) {
414     TopoDS_Shape aShape;
415     GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
416     TopoDS_Iterator It (aShape, Standard_True, Standard_True);
417     int nbSubshapes=0;
418     for (; It.More(); It.Next())
419       nbSubshapes++;
420
421     if (nbSubshapes)
422       objects.push_back(anObj._retn());
423     else
424       SUIT_MessageBox::warning(this,
425                                QObject::tr("GEOM_ERROR"),
426                                QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
427   }
428
429   return res;
430 }
431
432 //=================================================================================
433 // function : restoreSubShapes
434 // purpose  :
435 //=================================================================================
436 void OperationGUI_PartitionDlg::restoreSubShapes(SALOMEDS::Study_ptr   theStudy,
437                                                  SALOMEDS::SObject_ptr theSObject)
438 {
439   if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
440     // empty list of arguments means that all arguments should be restored
441     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
442                                         /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
443                                         /*theInheritFirstArg=*/myListShapes.length() == 1,
444                                         mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false
445   }
446 }
447
448 //=======================================================================
449 //function : ComboTextChanged
450 //purpose  :
451 //=======================================================================
452 void OperationGUI_PartitionDlg::ComboTextChanged()
453 {
454   //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
455   //GroupPoints->LineEdit3->setEnabled(IsEnabled);
456   //GroupPoints->LineEdit4->setEnabled(IsEnabled);
457   //GroupPoints->TextLabel4->setEnabled(IsEnabled);
458   //GroupPoints->TextLabel5->setEnabled(IsEnabled);
459   //GroupPoints->PushButton3->setEnabled(IsEnabled);
460   //GroupPoints->PushButton4->setEnabled(IsEnabled);
461 }
462
463 //=================================================================================
464 // function : GetLimit()
465 // purpose  :
466 //=================================================================================
467 int OperationGUI_PartitionDlg::GetLimit() const
468 {
469   int aLimit = GroupPoints->ComboBox1->currentIndex();
470
471   switch (aLimit) {
472   case 0:  aLimit = GEOM::SOLID ; break;
473   case 1:  aLimit = GEOM::SHELL ; break;
474   case 2:  aLimit = GEOM::FACE  ; break;
475   case 3:  aLimit = GEOM::WIRE  ; break;
476   case 4:  aLimit = GEOM::EDGE  ; break;
477   case 5:  aLimit = GEOM::VERTEX; break;
478   default: aLimit = GEOM::SHAPE ;
479   }
480
481   return aLimit;
482 }