1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : OperationGUI_PartitionDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "OperationGUI_PartitionDlg.h"
31 #include "GEOMImpl_Types.hxx"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SalomeApp_Application.h"
36 #include "LightApp_SelectionMgr.h"
38 #include <qcheckbox.h>
39 #include <qradiobutton.h>
40 #include <qcombobox.h>
43 #include "utilities.h"
45 //=================================================================================
46 // class : OperationGUI_PartitionDlg()
47 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(GeometryGUI* theGeometryGUI, QWidget* parent)
53 :GEOMBase_Skeleton(theGeometryGUI, parent, "OperationGUI_PartitionDlg", false,
54 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
56 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
57 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION")));
58 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_PARTITION_PLANE")));
59 QPixmap image2 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
61 setCaption(tr("GEOM_PARTITION_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->setPixmap(image1);
67 RadioButton3->close(TRUE);
69 // Full partition (contains half-space partition)
70 GroupPoints = new DlgRef_2Sel1List1Check_QTD(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupPoints->radioButton4->setText(tr("GEOM_KEEP_NONLIMIT_SHAPES"));
81 Layout1->addWidget(GroupPoints, 2, 0);
82 /***************************************************************/
84 setHelpFileName("partition_page.html");
90 //=================================================================================
91 // function : ~OperationGUI_PartitionDlg()
92 // purpose : Destroys the object and frees any allocated resources
93 //=================================================================================
94 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
96 // no need to delete child widgets, Qt does it all for us
100 //=================================================================================
103 //=================================================================================
104 void OperationGUI_PartitionDlg::Init()
106 /* type for sub shape selection */
107 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
108 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
109 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
110 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
111 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
112 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
113 GroupPoints->radioButton4->setChecked(FALSE);
115 GroupBoxPublish->show();
117 /* signals and slots connections */
118 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
119 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
122 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
130 connect(myGeomGUI->getApp()->selectionMgr(),
131 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
133 initName( tr( "GEOM_PARTITION" ) );
134 ConstructorsClicked( 0 );
138 //=================================================================================
139 // function : ConstructorsClicked()
140 // purpose : Radio button management
141 //=================================================================================
142 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
144 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
147 myListShapes.length(0);
148 myListTools.length(0);
149 myListKeepInside.length(0);
150 myListRemoveInside.length(0);
151 myListMaterials.length(0);
153 switch (constructorId)
155 case 0: /*Full partition */
157 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
158 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
160 GroupPoints->TextLabel3->show();
161 GroupPoints->ComboBox1->show();
162 GroupPoints->ComboBox1->setCurrentItem(0);
163 GroupPoints->radioButton4->show();
166 case 1: /*Half-space partition */
169 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
170 GroupPoints->TextLabel3->hide();
171 GroupPoints->ComboBox1->hide();
172 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
173 GroupPoints->radioButton4->hide();
179 myEditCurrentArgument = GroupPoints->LineEdit1;
180 GroupPoints->LineEdit1->clear();
181 GroupPoints->LineEdit2->clear();
183 myEditCurrentArgument->setFocus();
184 connect(myGeomGUI->getApp()->selectionMgr(),
185 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
186 MESSAGE(width()<<" "<<height());
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void OperationGUI_PartitionDlg::ClickOnOk()
196 if ( ClickOnApply() )
201 //=================================================================================
202 // function : ClickOnApply()
204 //=================================================================================
205 bool OperationGUI_PartitionDlg::ClickOnApply()
211 ConstructorsClicked( getConstructorId() );
216 //=================================================================================
217 // function : SelectionIntoArgument()
218 // purpose : Called when selection as changed or other case
219 //=================================================================================
220 void OperationGUI_PartitionDlg::SelectionIntoArgument()
222 myEditCurrentArgument->setText( "" );
223 QString aString = "";
225 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
229 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
231 myListShapes.length( 0 );
232 myListMaterials.length( 0 );
234 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
235 myListTools.length( 0 );
238 // One and only one plane can be selected
240 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
242 myListTools.length( 0 );
246 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
248 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
249 myListMaterials.length( 0 );
250 if ( !myListShapes.length() )
253 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
255 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
256 if ( !myListTools.length() )
260 myEditCurrentArgument->setText( aString );
264 //=================================================================================
265 // function : SetEditCurrentArgument()
267 //=================================================================================
268 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
270 QPushButton* send = (QPushButton*)sender();
272 if(send == GroupPoints->PushButton1)
273 myEditCurrentArgument = GroupPoints->LineEdit1;
274 else if(send == GroupPoints->PushButton2)
276 myEditCurrentArgument = GroupPoints->LineEdit2;
277 if( getConstructorId()==1 )
278 globalSelection( GEOM_PLANE );
281 globalSelection( GEOM_ALLSHAPES );
283 myEditCurrentArgument->setFocus();
284 SelectionIntoArgument();
288 //=================================================================================
289 // function : LineEditReturnPressed()
291 //=================================================================================
292 void OperationGUI_PartitionDlg::LineEditReturnPressed()
294 QLineEdit* send = (QLineEdit*)sender();
296 if(send == GroupPoints->LineEdit1 ||
297 send == GroupPoints->LineEdit2 )
299 myEditCurrentArgument = send;
300 GEOMBase_Skeleton::LineEditReturnPressed();
305 //=================================================================================
306 // function : ActivateThisDialog()
308 //=================================================================================
309 void OperationGUI_PartitionDlg::ActivateThisDialog()
311 GEOMBase_Skeleton::ActivateThisDialog();
312 connect(myGeomGUI->getApp()->selectionMgr(),
313 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 ConstructorsClicked( getConstructorId() );
319 //=================================================================================
320 // function : enterEvent()
322 //=================================================================================
323 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
325 if (!GroupConstructors->isEnabled())
326 this->ActivateThisDialog();
330 //=================================================================================
331 // function : createOperation
333 //=================================================================================
334 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
336 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
340 //=================================================================================
341 // function : isValid
343 //=================================================================================
344 bool OperationGUI_PartitionDlg::isValid( QString& msg )
346 return (myListShapes.length() || myListTools.length() ||
347 myListKeepInside.length() || myListRemoveInside.length());
351 //=================================================================================
352 // function : execute
354 //=================================================================================
355 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
359 GEOM::GEOM_Object_var anObj;
362 int aLimit = GetLimit();
363 int aConstructorId = getConstructorId();
365 int aKeepNonlimitShapes = 0;
366 if (aConstructorId == 1) {
367 aLimit = GEOM::SHAPE;
370 if(GroupPoints->radioButton4->isChecked()) {
371 aKeepNonlimitShapes = 1;
374 aKeepNonlimitShapes = 0;
378 if (isValid( msg )) {
380 anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
381 MakePartition(myListShapes, myListTools,
382 myListKeepInside, myListRemoveInside,
383 aLimit, false, myListMaterials, aKeepNonlimitShapes);
387 if (!anObj->_is_nil())
388 objects.push_back( anObj._retn() );
393 //=================================================================================
394 // function : restoreSubShapes
396 //=================================================================================
397 void OperationGUI_PartitionDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
398 SALOMEDS::SObject_ptr theSObject)
400 if (CheckBoxRestoreSS->isChecked()) {
401 // empty list of arguments means that all arguments should be restored
402 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
403 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
404 /*theInheritFirstArg=*/myListShapes.length() == 1); // ? false
408 //=======================================================================
409 //function : ComboTextChanged
411 //=======================================================================
412 void OperationGUI_PartitionDlg::ComboTextChanged()
414 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
415 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
416 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
417 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
418 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
419 //GroupPoints->PushButton3->setEnabled(IsEnabled);
420 //GroupPoints->PushButton4->setEnabled(IsEnabled);
423 //=================================================================================
424 // function : GetLimit()
426 //=================================================================================
427 int OperationGUI_PartitionDlg::GetLimit() const
429 int aLimit = GroupPoints->ComboBox1->currentItem();
433 case 0: aLimit = GEOM::SOLID ; break;
434 case 1: aLimit = GEOM::SHELL ; break;
435 case 2: aLimit = GEOM::FACE ; break;
436 case 3: aLimit = GEOM::WIRE ; break;
437 case 4: aLimit = GEOM::EDGE ; break;
438 case 5: aLimit = GEOM::VERTEX; break;
439 default: aLimit = GEOM::SHAPE ;