1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_PartitionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "OperationGUI_PartitionDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
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>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
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)
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")));
59 setWindowTitle(tr("GEOM_PARTITION_TITLE"));
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();
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"));
82 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
83 layout->setMargin(0); layout->setSpacing(6);
84 layout->addWidget(GroupPoints);
86 /***************************************************************/
88 setHelpFileName("partition_page.html");
94 //=================================================================================
95 // function : ~OperationGUI_PartitionDlg()
96 // purpose : Destroys the object and frees any allocated resources
97 //=================================================================================
98 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
100 // no need to delete child widgets, Qt does it all for us
103 void OperationGUI_PartitionDlg::SetListMaterials(GEOM::ListOfLong ListMaterials)
105 myListMaterials = ListMaterials;
108 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
110 return myListMaterials;
113 //=================================================================================
116 //=================================================================================
117 void OperationGUI_PartitionDlg::Init()
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);
128 mainFrame()->GroupBoxPublish->show();
130 /* signals and slots connections */
131 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
132 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
134 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
136 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
137 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
140 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
142 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
144 connect(myGeomGUI->getApp()->selectionMgr(),
145 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
147 initName(tr("GEOM_PARTITION"));
149 ConstructorsClicked(0);
150 GroupPoints->PushButton1->click();
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose : Radio button management
157 //=================================================================================
158 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
160 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
163 myListShapes.length(0);
164 myListTools.length(0);
165 myListKeepInside.length(0);
166 myListRemoveInside.length(0);
167 myListMaterials.length(0);
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);
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);
193 myEditCurrentArgument = GroupPoints->LineEdit1;
194 GroupPoints->LineEdit1->clear();
195 GroupPoints->LineEdit2->clear();
197 qApp->processEvents();
199 resize(minimumSizeHint());
201 myEditCurrentArgument->setFocus();
202 connect(myGeomGUI->getApp()->selectionMgr(),
203 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 SelectionIntoArgument();
208 //=================================================================================
209 // function : ClickOnOk()
211 //=================================================================================
212 void OperationGUI_PartitionDlg::ClickOnOk()
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 bool OperationGUI_PartitionDlg::ClickOnApply()
229 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
230 // ConstructorsClicked(getConstructorId());
235 //=================================================================================
236 // function : SelectionIntoArgument()
237 // purpose : Called when selection as changed or other case
238 //=================================================================================
239 void OperationGUI_PartitionDlg::SelectionIntoArgument()
241 myEditCurrentArgument->setText("");
242 QString aString = "";
244 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
245 SALOME_ListIO aSelList;
246 aSelMgr->selectedObjects(aSelList);
248 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
251 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
252 myListShapes.length(0);
253 myListMaterials.length(0);
255 else if (myEditCurrentArgument == GroupPoints->LineEdit2)
256 myListTools.length(0);
259 // One and only one plane can be selected
261 if (getConstructorId() == 1 &&
262 myEditCurrentArgument == GroupPoints->LineEdit2 &&
264 myListTools.length(0);
268 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
269 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
270 myListMaterials.length(0);
271 if (!myListShapes.length())
274 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
275 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
276 if (!myListTools.length())
280 myEditCurrentArgument->setText(aString);
284 //=================================================================================
285 // function : SetEditCurrentArgument()
287 //=================================================================================
288 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
290 QPushButton* send = (QPushButton*)sender();
292 if (send == GroupPoints->PushButton1) {
293 myEditCurrentArgument = GroupPoints->LineEdit1;
294 GroupPoints->PushButton2->setDown(false);
295 GroupPoints->LineEdit1->setEnabled(true);
296 GroupPoints->LineEdit2->setEnabled(false);
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);
308 globalSelection(GEOM_ALLSHAPES);
310 myEditCurrentArgument->setFocus();
311 SelectionIntoArgument();
316 //=================================================================================
317 // function : LineEditReturnPressed()
319 //=================================================================================
320 void OperationGUI_PartitionDlg::LineEditReturnPressed()
322 QLineEdit* send = (QLineEdit*)sender();
324 if (send == GroupPoints->LineEdit1 ||
325 send == GroupPoints->LineEdit2) {
326 myEditCurrentArgument = send;
327 GEOMBase_Skeleton::LineEditReturnPressed();
332 //=================================================================================
333 // function : ActivateThisDialog()
335 //=================================================================================
336 void OperationGUI_PartitionDlg::ActivateThisDialog()
338 GEOMBase_Skeleton::ActivateThisDialog();
339 connect(myGeomGUI->getApp()->selectionMgr(),
340 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
342 ConstructorsClicked(getConstructorId());
346 //=================================================================================
347 // function : enterEvent()
349 //=================================================================================
350 void OperationGUI_PartitionDlg::enterEvent(QEvent*)
352 if (!mainFrame()->GroupConstructors->isEnabled())
353 this->ActivateThisDialog();
357 //=================================================================================
358 // function : createOperation
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
363 return getGeomEngine()->GetIBooleanOperations(getStudyId());
367 //=================================================================================
368 // function : isValid
370 //=================================================================================
371 bool OperationGUI_PartitionDlg::isValid(QString&)
373 return (myListShapes.length() || myListTools.length() ||
374 myListKeepInside.length() || myListRemoveInside.length());
378 //=================================================================================
379 // function : execute
381 //=================================================================================
382 bool OperationGUI_PartitionDlg::execute(ObjectList& objects)
386 GEOM::GEOM_Object_var anObj;
389 int aLimit = GetLimit();
390 int aConstructorId = getConstructorId();
391 int aKeepNonlimitShapes = 0;
393 if (aConstructorId == 1) {
394 aLimit = GEOM::SHAPE;
397 if (GroupPoints->CheckButton1->isChecked()) {
398 aKeepNonlimitShapes = 1;
401 aKeepNonlimitShapes = 0;
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);
413 if (!anObj->_is_nil()) {
415 GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
416 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
418 for (; It.More(); It.Next())
422 objects.push_back(anObj._retn());
424 SUIT_MessageBox::warning(this,
425 QObject::tr("GEOM_ERROR"),
426 QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
432 //=================================================================================
433 // function : restoreSubShapes
435 //=================================================================================
436 void OperationGUI_PartitionDlg::restoreSubShapes(SALOMEDS::Study_ptr theStudy,
437 SALOMEDS::SObject_ptr theSObject)
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
448 //=======================================================================
449 //function : ComboTextChanged
451 //=======================================================================
452 void OperationGUI_PartitionDlg::ComboTextChanged()
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);
463 //=================================================================================
464 // function : GetLimit()
466 //=================================================================================
467 int OperationGUI_PartitionDlg::GetLimit() const
469 int aLimit = GroupPoints->ComboBox1->currentIndex();
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 ;