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"
30 #include "OperationGUI_MaterialDlg.h"
32 #include "GEOMImpl_Types.hxx"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
39 #include <qcheckbox.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_4Sel1List1Check_QTD(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
72 GroupPoints->GroupBox2->setTitle(tr("SUPPRESS_RESULT"));
73 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
74 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
75 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
76 GroupPoints->TextLabel4->setText(tr("GEOM_SUPPRESS_RESULT_INSIDE"));
77 GroupPoints->TextLabel5->setText(tr("GEOM_SUPPRESS_RESULT_OUTSIDE"));
78 GroupPoints->CheckBox1->setText(tr("GEOM_REMOVE_WEBS"));
79 GroupPoints->PushButton1->setPixmap(image2);
80 GroupPoints->PushButton2->setPixmap(image2);
81 GroupPoints->PushButton3->setPixmap(image2);
82 GroupPoints->PushButton4->setPixmap(image2);
83 GroupPoints->PushButton5->setText(tr("GEOM_SET_MATERIALS"));
84 GroupPoints->LineEdit1->setReadOnly( true );
85 GroupPoints->LineEdit2->setReadOnly( true );
86 GroupPoints->LineEdit3->setReadOnly( true );
87 GroupPoints->LineEdit4->setReadOnly( true );
89 Layout1->addWidget(GroupPoints, 2, 0);
90 /***************************************************************/
92 setHelpFileName("partition.htm");
98 //=================================================================================
99 // function : ~OperationGUI_PartitionDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
104 // no need to delete child widgets, Qt does it all for us
108 //=================================================================================
111 //=================================================================================
112 void OperationGUI_PartitionDlg::Init()
114 /* type for sub shape selection */
115 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
116 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
117 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
118 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
119 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
120 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
122 /* signals and slots connections */
123 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
124 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
125 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
127 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetMaterials()));
133 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
135 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(onRemoveWebs(bool)));
140 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
142 connect(myGeomGUI->getApp()->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
145 initName( tr( "GEOM_PARTITION" ) );
146 ConstructorsClicked( 0 );
150 //=================================================================================
151 // function : ConstructorsClicked()
152 // purpose : Radio button management
153 //=================================================================================
154 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
156 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
159 myListShapes.length(0);
160 myListTools.length(0);
161 myListKeepInside.length(0);
162 myListRemoveInside.length(0);
163 myListMaterials.length(0);
165 switch (constructorId)
167 case 0: /*Full partition */
169 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
170 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
172 GroupPoints->TextLabel3->show();
173 GroupPoints->ComboBox1->show();
174 GroupPoints->GroupBox2->show();
176 GroupPoints->ComboBox1->setCurrentItem(0);
177 GroupPoints->LineEdit3->clear();
178 GroupPoints->LineEdit4->clear();
181 case 1: /*Half-space partition */
184 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
185 GroupPoints->GroupBox2->hide();
186 GroupPoints->TextLabel3->hide();
187 GroupPoints->ComboBox1->hide();
188 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
194 myEditCurrentArgument = GroupPoints->LineEdit1;
195 GroupPoints->LineEdit1->clear();
196 GroupPoints->LineEdit2->clear();
199 myEditCurrentArgument->setFocus();
200 connect(myGeomGUI->getApp()->selectionMgr(),
201 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
202 MESSAGE(width()<<" "<<height());
206 //=================================================================================
207 // function : ClickOnOk()
209 //=================================================================================
210 void OperationGUI_PartitionDlg::ClickOnOk()
212 if ( ClickOnApply() )
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 bool OperationGUI_PartitionDlg::ClickOnApply()
227 ConstructorsClicked( getConstructorId() );
232 //=================================================================================
233 // function : SelectionIntoArgument()
234 // purpose : Called when selection as changed or other case
235 //=================================================================================
236 void OperationGUI_PartitionDlg::SelectionIntoArgument()
238 myEditCurrentArgument->setText( "" );
239 QString aString = "";
241 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
245 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
247 myListShapes.length( 0 );
248 myListMaterials.length( 0 );
250 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
251 myListTools.length( 0 );
252 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
253 myListRemoveInside.length( 0 );
254 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
255 myListKeepInside.length( 0 );
258 // One and only one plane can be selected
260 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
262 myListTools.length( 0 );
266 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
268 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
269 myListMaterials.length( 0 );
270 if ( !myListShapes.length() )
273 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
275 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
276 if ( !myListTools.length() )
279 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
281 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListRemoveInside, true );
282 if (!myListRemoveInside.length())
285 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
287 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListKeepInside, true );
288 if ( !myListKeepInside.length() )
292 myEditCurrentArgument->setText( aString );
296 //=================================================================================
297 // function : SetEditCurrentArgument()
299 //=================================================================================
300 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
302 QPushButton* send = (QPushButton*)sender();
304 if(send == GroupPoints->PushButton1)
305 myEditCurrentArgument = GroupPoints->LineEdit1;
306 else if(send == GroupPoints->PushButton2)
308 myEditCurrentArgument = GroupPoints->LineEdit2;
309 if( getConstructorId()==1 )
310 globalSelection( GEOM_PLANE );
312 else if(send == GroupPoints->PushButton3)
313 myEditCurrentArgument = GroupPoints->LineEdit3;
314 else if(send == GroupPoints->PushButton4)
315 myEditCurrentArgument = GroupPoints->LineEdit4;
317 globalSelection( GEOM_ALLSHAPES );
319 myEditCurrentArgument->setFocus();
320 SelectionIntoArgument();
324 //=================================================================================
325 // function : LineEditReturnPressed()
327 //=================================================================================
328 void OperationGUI_PartitionDlg::LineEditReturnPressed()
330 QLineEdit* send = (QLineEdit*)sender();
332 if(send == GroupPoints->LineEdit1 ||
333 send == GroupPoints->LineEdit2 ||
334 send == GroupPoints->LineEdit3 ||
335 send == GroupPoints->LineEdit4 )
337 myEditCurrentArgument = send;
338 GEOMBase_Skeleton::LineEditReturnPressed();
343 //=================================================================================
344 // function : ActivateThisDialog()
346 //=================================================================================
347 void OperationGUI_PartitionDlg::ActivateThisDialog()
349 GEOMBase_Skeleton::ActivateThisDialog();
350 connect(myGeomGUI->getApp()->selectionMgr(),
351 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
353 ConstructorsClicked( getConstructorId() );
357 //=================================================================================
358 // function : enterEvent()
360 //=================================================================================
361 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
363 if (!GroupConstructors->isEnabled())
364 this->ActivateThisDialog();
368 //=================================================================================
369 // function : createOperation
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
374 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
378 //=================================================================================
379 // function : isValid
381 //=================================================================================
382 bool OperationGUI_PartitionDlg::isValid( QString& msg )
384 return (myListShapes.length() || myListTools.length() ||
385 myListKeepInside.length() || myListRemoveInside.length());
389 //=================================================================================
390 // function : execute
392 //=================================================================================
393 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
397 GEOM::GEOM_Object_var anObj;
400 int aLimit = GetLimit();
401 int aConstructorId = getConstructorId();
403 if (aConstructorId == 1)
404 aLimit = GEOM::SHAPE;
406 if (isValid( msg )) {
407 if (aConstructorId == 0 && !toRemoveWebs())
408 myListMaterials.length(0);
410 anObj = GEOM::GEOM_IBooleanOperations::_narrow(getOperation())->
411 MakePartition(myListShapes, myListTools,
412 myListKeepInside, myListRemoveInside,
413 aLimit, toRemoveWebs(), myListMaterials);
417 if (!anObj->_is_nil())
418 objects.push_back( anObj._retn() );
424 //=================================================================================
425 // function : closeEvent
427 //=================================================================================
428 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
430 GEOMBase_Skeleton::closeEvent( e );
434 //=======================================================================
435 //function : ComboTextChanged
437 //=======================================================================
438 void OperationGUI_PartitionDlg::ComboTextChanged()
440 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
441 GroupPoints->LineEdit3->setEnabled(IsEnabled);
442 GroupPoints->LineEdit4->setEnabled(IsEnabled);
443 GroupPoints->TextLabel4->setEnabled(IsEnabled);
444 GroupPoints->TextLabel5->setEnabled(IsEnabled);
445 GroupPoints->PushButton3->setEnabled(IsEnabled);
446 GroupPoints->PushButton4->setEnabled(IsEnabled);
450 //=================================================================================
451 // function : SetMaterials()
453 //=================================================================================
454 void OperationGUI_PartitionDlg::SetMaterials()
456 OperationGUI_MaterialDlg* aDlg =
457 new OperationGUI_MaterialDlg(myGeomGUI, this, "", myListShapes, true);
462 //=================================================================================
463 // function : onRemoveWebs()
465 //=================================================================================
466 void OperationGUI_PartitionDlg::onRemoveWebs(bool isChecked)
468 if (GroupPoints->CheckBox1->isChecked() != isChecked)
469 GroupPoints->CheckBox1->setChecked(isChecked);
471 GroupPoints->PushButton5->setEnabled(isChecked);
475 //=================================================================================
476 // function : toRemoveWebs()
478 //=================================================================================
479 bool OperationGUI_PartitionDlg::toRemoveWebs() const
481 return GroupPoints->CheckBox1->isChecked();
485 //=================================================================================
486 // function : GetLimit()
488 //=================================================================================
489 int OperationGUI_PartitionDlg::GetLimit() const
491 int aLimit = GroupPoints->ComboBox1->currentItem();
495 case 0: aLimit = GEOM::SOLID ; break;
496 case 1: aLimit = GEOM::SHELL ; break;
497 case 2: aLimit = GEOM::FACE ; break;
498 case 3: aLimit = GEOM::WIRE ; break;
499 case 4: aLimit = GEOM::EDGE ; break;
500 case 5: aLimit = GEOM::VERTEX; break;
501 default: aLimit = GEOM::SHAPE ;