1 // Copyright (C) 2007-2008 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
28 #include "OperationGUI_PartitionDlg.h"
30 #include "GEOMImpl_Types.hxx"
32 #include "SUIT_Desktop.h"
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
37 #include <qcheckbox.h>
38 #include <qradiobutton.h>
39 #include <qcombobox.h>
42 #include "utilities.h"
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, "OperationGUI_PartitionDlg", false,
53 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
57 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
58 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
60 setCaption(tr("GEOM_PARTITION_TITLE"));
62 /***************************************************************/
63 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
64 RadioButton1->setPixmap(image0);
65 RadioButton2->setPixmap(image1);
66 RadioButton3->close(TRUE);
68 // Full partition (contains half-space partition)
69 GroupPoints = new DlgRef_2Sel1List1Check_QTD(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
73 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
74 GroupPoints->PushButton1->setPixmap(image2);
75 GroupPoints->PushButton2->setPixmap(image2);
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
78 GroupPoints->radioButton4->setText(tr("GEOM_KEEP_NONLIMIT_SHAPES"));
80 Layout1->addWidget(GroupPoints, 2, 0);
81 /***************************************************************/
83 setHelpFileName("partition_page.html");
89 //=================================================================================
90 // function : ~OperationGUI_PartitionDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
95 // no need to delete child widgets, Qt does it all for us
99 //=================================================================================
102 //=================================================================================
103 void OperationGUI_PartitionDlg::Init()
105 /* type for sub shape selection */
106 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
107 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
108 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
109 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
110 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
111 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
112 GroupPoints->radioButton4->setChecked(FALSE);
114 GroupBoxPublish->show();
116 /* signals and slots connections */
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
121 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
129 connect(myGeomGUI->getApp()->selectionMgr(),
130 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
132 initName( tr( "GEOM_PARTITION" ) );
133 ConstructorsClicked( 0 );
137 //=================================================================================
138 // function : ConstructorsClicked()
139 // purpose : Radio button management
140 //=================================================================================
141 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
143 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
146 myListShapes.length(0);
147 myListTools.length(0);
148 myListKeepInside.length(0);
149 myListRemoveInside.length(0);
150 myListMaterials.length(0);
152 switch (constructorId)
154 case 0: /*Full partition */
156 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
157 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
159 GroupPoints->TextLabel3->show();
160 GroupPoints->ComboBox1->show();
161 GroupPoints->ComboBox1->setCurrentItem(0);
162 GroupPoints->radioButton4->show();
165 case 1: /*Half-space partition */
168 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
169 GroupPoints->TextLabel3->hide();
170 GroupPoints->ComboBox1->hide();
171 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
172 GroupPoints->radioButton4->hide();
178 myEditCurrentArgument = GroupPoints->LineEdit1;
179 GroupPoints->LineEdit1->clear();
180 GroupPoints->LineEdit2->clear();
182 myEditCurrentArgument->setFocus();
183 connect(myGeomGUI->getApp()->selectionMgr(),
184 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 MESSAGE(width()<<" "<<height());
189 //=================================================================================
190 // function : ClickOnOk()
192 //=================================================================================
193 void OperationGUI_PartitionDlg::ClickOnOk()
195 if ( ClickOnApply() )
200 //=================================================================================
201 // function : ClickOnApply()
203 //=================================================================================
204 bool OperationGUI_PartitionDlg::ClickOnApply()
210 ConstructorsClicked( getConstructorId() );
215 //=================================================================================
216 // function : SelectionIntoArgument()
217 // purpose : Called when selection as changed or other case
218 //=================================================================================
219 void OperationGUI_PartitionDlg::SelectionIntoArgument()
221 myEditCurrentArgument->setText( "" );
222 QString aString = "";
224 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
228 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
230 myListShapes.length( 0 );
231 myListMaterials.length( 0 );
233 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
234 myListTools.length( 0 );
237 // One and only one plane can be selected
239 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
241 myListTools.length( 0 );
245 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
247 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
248 myListMaterials.length( 0 );
249 if ( !myListShapes.length() )
252 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
254 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
255 if ( !myListTools.length() )
259 myEditCurrentArgument->setText( aString );
263 //=================================================================================
264 // function : SetEditCurrentArgument()
266 //=================================================================================
267 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
269 QPushButton* send = (QPushButton*)sender();
271 if(send == GroupPoints->PushButton1)
272 myEditCurrentArgument = GroupPoints->LineEdit1;
273 else if(send == GroupPoints->PushButton2)
275 myEditCurrentArgument = GroupPoints->LineEdit2;
276 if( getConstructorId()==1 )
277 globalSelection( GEOM_PLANE );
280 globalSelection( GEOM_ALLSHAPES );
282 myEditCurrentArgument->setFocus();
283 SelectionIntoArgument();
287 //=================================================================================
288 // function : LineEditReturnPressed()
290 //=================================================================================
291 void OperationGUI_PartitionDlg::LineEditReturnPressed()
293 QLineEdit* send = (QLineEdit*)sender();
295 if(send == GroupPoints->LineEdit1 ||
296 send == GroupPoints->LineEdit2 )
298 myEditCurrentArgument = send;
299 GEOMBase_Skeleton::LineEditReturnPressed();
304 //=================================================================================
305 // function : ActivateThisDialog()
307 //=================================================================================
308 void OperationGUI_PartitionDlg::ActivateThisDialog()
310 GEOMBase_Skeleton::ActivateThisDialog();
311 connect(myGeomGUI->getApp()->selectionMgr(),
312 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 ConstructorsClicked( getConstructorId() );
318 //=================================================================================
319 // function : enterEvent()
321 //=================================================================================
322 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
324 if (!GroupConstructors->isEnabled())
325 this->ActivateThisDialog();
329 //=================================================================================
330 // function : createOperation
332 //=================================================================================
333 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
335 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
339 //=================================================================================
340 // function : isValid
342 //=================================================================================
343 bool OperationGUI_PartitionDlg::isValid( QString& msg )
345 return (myListShapes.length() || myListTools.length() ||
346 myListKeepInside.length() || myListRemoveInside.length());
350 //=================================================================================
351 // function : execute
353 //=================================================================================
354 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
358 GEOM::GEOM_Object_var anObj;
361 int aLimit = GetLimit();
362 int aConstructorId = getConstructorId();
364 int aKeepNonlimitShapes = 0;
365 if (aConstructorId == 1) {
366 aLimit = GEOM::SHAPE;
369 if(GroupPoints->radioButton4->isChecked()) {
370 aKeepNonlimitShapes = 1;
373 aKeepNonlimitShapes = 0;
377 if (isValid( msg )) {
379 anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
380 MakePartition(myListShapes, myListTools,
381 myListKeepInside, myListRemoveInside,
382 aLimit, false, myListMaterials, aKeepNonlimitShapes);
386 if (!anObj->_is_nil())
387 objects.push_back( anObj._retn() );
392 //=================================================================================
393 // function : restoreSubShapes
395 //=================================================================================
396 void OperationGUI_PartitionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
397 SALOMEDS::SObject_ptr theSObject)
399 if (CheckBoxRestoreSS->isChecked()) {
400 // empty list of arguments means that all arguments should be restored
401 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
402 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
403 /*theInheritFirstArg=*/myListShapes.length() == 1); // ? false
407 //=======================================================================
408 //function : ComboTextChanged
410 //=======================================================================
411 void OperationGUI_PartitionDlg::ComboTextChanged()
413 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
414 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
415 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
416 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
417 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
418 //GroupPoints->PushButton3->setEnabled(IsEnabled);
419 //GroupPoints->PushButton4->setEnabled(IsEnabled);
422 //=================================================================================
423 // function : GetLimit()
425 //=================================================================================
426 int OperationGUI_PartitionDlg::GetLimit() const
428 int aLimit = GroupPoints->ComboBox1->currentItem();
432 case 0: aLimit = GEOM::SOLID ; break;
433 case 1: aLimit = GEOM::SHELL ; break;
434 case 2: aLimit = GEOM::FACE ; break;
435 case 3: aLimit = GEOM::WIRE ; break;
436 case 4: aLimit = GEOM::EDGE ; break;
437 case 5: aLimit = GEOM::VERTEX; break;
438 default: aLimit = GEOM::SHAPE ;