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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "QAD_Desktop.h"
36 #include <qcheckbox.h>
38 #include "utilities.h"
40 //=================================================================================
41 // class : OperationGUI_PartitionDlg()
42 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION_PLANE")));
52 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_PARTITION_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->setPixmap(image1);
60 RadioButton3->close(TRUE);
62 // Full partition (contains half-space partition)
63 GroupPoints = new DlgRef_4Sel1List1Check_QTD(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
65 GroupPoints->GroupBox2->setTitle(tr("SUPPRESS_RESULT"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_RECONSTRUCTION_LIMIT"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_SUPPRESS_RESULT_INSIDE"));
70 GroupPoints->TextLabel5->setText(tr("GEOM_SUPPRESS_RESULT_OUTSIDE"));
71 GroupPoints->CheckBox1->setText(tr("GEOM_REMOVE_WEBS"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
74 GroupPoints->PushButton3->setPixmap(image2);
75 GroupPoints->PushButton4->setPixmap(image2);
76 GroupPoints->PushButton5->setText(tr("GEOM_SET_MATERIALS"));
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupPoints->LineEdit3->setReadOnly( true );
80 GroupPoints->LineEdit4->setReadOnly( true );
82 Layout1->addWidget(GroupPoints, 2, 0);
83 /***************************************************************/
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"));
113 /* signals and slots connections */
114 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
115 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
118 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
120 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetMaterials()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(GroupPoints->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(onRemoveWebs(bool)));
131 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
133 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
135 initName( tr( "GEOM_PARTITION" ) );
136 ConstructorsClicked( 0 );
140 //=================================================================================
141 // function : ConstructorsClicked()
142 // purpose : Radio button management
143 //=================================================================================
144 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
146 disconnect(mySelection, 0, this, 0);
149 myListShapes.length(0);
150 myListTools.length(0);
151 myListKeepInside.length(0);
152 myListRemoveInside.length(0);
153 myListMaterials.length(0);
155 switch (constructorId)
157 case 0: /*Full partition */
159 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
160 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
162 GroupPoints->TextLabel3->show();
163 GroupPoints->ComboBox1->show();
164 GroupPoints->GroupBox2->show();
166 GroupPoints->ComboBox1->setCurrentItem(0);
167 GroupPoints->LineEdit3->clear();
168 GroupPoints->LineEdit4->clear();
171 case 1: /*Half-space partition */
174 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
175 GroupPoints->GroupBox2->hide();
176 GroupPoints->TextLabel3->hide();
177 GroupPoints->ComboBox1->hide();
178 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
184 myEditCurrentArgument = GroupPoints->LineEdit1;
185 GroupPoints->LineEdit1->clear();
186 GroupPoints->LineEdit2->clear();
189 myEditCurrentArgument->setFocus();
190 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 MESSAGE(width()<<" "<<height());
195 //=================================================================================
196 // function : ClickOnOk()
198 //=================================================================================
199 void OperationGUI_PartitionDlg::ClickOnOk()
201 if ( ClickOnApply() )
206 //=================================================================================
207 // function : ClickOnApply()
209 //=================================================================================
210 bool OperationGUI_PartitionDlg::ClickOnApply()
216 ConstructorsClicked( getConstructorId() );
221 //=======================================================================
222 // function : ClickOnCancel()
224 //=======================================================================
225 void OperationGUI_PartitionDlg::ClickOnCancel()
227 GEOMBase_Skeleton::ClickOnCancel();
231 //=================================================================================
232 // function : SelectionIntoArgument()
233 // purpose : Called when selection as changed or other case
234 //=================================================================================
235 void OperationGUI_PartitionDlg::SelectionIntoArgument()
237 myEditCurrentArgument->setText("");
238 QString aString = "";
240 int nbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aString);
243 if(myEditCurrentArgument == GroupPoints->LineEdit1)
245 myListShapes.length(0);
246 myListMaterials.length(0);
248 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
249 myListTools.length(0);
250 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
251 myListRemoveInside.length(0);
252 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
253 myListKeepInside.length(0);
256 // One and only one plane can be selected
258 if(getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel!=1) {
259 myListTools.length(0);
263 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
264 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myListShapes);
265 myListMaterials.length(0);
266 if (!myListShapes.length())
269 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
270 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myListTools);
271 if (!myListTools.length())
274 else if(myEditCurrentArgument == GroupPoints->LineEdit3) {
275 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myListRemoveInside);
276 if (!myListRemoveInside.length())
279 else if(myEditCurrentArgument == GroupPoints->LineEdit4) {
280 GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myListKeepInside);
281 if (!myListKeepInside.length())
285 myEditCurrentArgument->setText(aString);
289 //=================================================================================
290 // function : SetEditCurrentArgument()
292 //=================================================================================
293 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
295 QPushButton* send = (QPushButton*)sender();
297 if(send == GroupPoints->PushButton1)
298 myEditCurrentArgument = GroupPoints->LineEdit1;
299 else if(send == GroupPoints->PushButton2)
301 myEditCurrentArgument = GroupPoints->LineEdit2;
302 if( getConstructorId()==1 )
303 globalSelection( GEOM_PLANE );
305 else if(send == GroupPoints->PushButton3)
306 myEditCurrentArgument = GroupPoints->LineEdit3;
307 else if(send == GroupPoints->PushButton4)
308 myEditCurrentArgument = GroupPoints->LineEdit4;
312 myEditCurrentArgument->setFocus();
313 SelectionIntoArgument();
317 //=================================================================================
318 // function : LineEditReturnPressed()
320 //=================================================================================
321 void OperationGUI_PartitionDlg::LineEditReturnPressed()
323 QLineEdit* send = (QLineEdit*)sender();
325 if(send == GroupPoints->LineEdit1 ||
326 send == GroupPoints->LineEdit2 ||
327 send == GroupPoints->LineEdit3 ||
328 send == GroupPoints->LineEdit4 )
330 myEditCurrentArgument = send;
331 GEOMBase_Skeleton::LineEditReturnPressed();
336 //=================================================================================
337 // function : ActivateThisDialog()
339 //=================================================================================
340 void OperationGUI_PartitionDlg::ActivateThisDialog()
342 GEOMBase_Skeleton::ActivateThisDialog();
343 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
345 ConstructorsClicked( getConstructorId() );
349 //=================================================================================
350 // function : DeactivateActiveDialog()
351 // purpose : public slot to deactivate if active
352 //=================================================================================
353 void OperationGUI_PartitionDlg::DeactivateActiveDialog()
355 GEOMBase_Skeleton::DeactivateActiveDialog();
359 //=================================================================================
360 // function : enterEvent()
362 //=================================================================================
363 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
365 if(!GroupConstructors->isEnabled())
366 this->ActivateThisDialog();
370 //=================================================================================
371 // function : createOperation
373 //=================================================================================
374 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
376 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
380 //=================================================================================
381 // function : isValid
383 //=================================================================================
384 bool OperationGUI_PartitionDlg::isValid( QString& msg )
386 return (myListShapes.length() || myListTools.length() ||
387 myListKeepInside.length() || myListRemoveInside.length());
391 //=================================================================================
392 // function : execute
394 //=================================================================================
395 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
399 GEOM::GEOM_Object_var anObj;
402 int aLimit = GetLimit();
403 int aConstructorId = getConstructorId();
405 if (aConstructorId==1)
406 aLimit = GEOM::SHAPE;
411 if ( aConstructorId==0 && !toRemoveWebs() )
412 myListMaterials.length(0);
414 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakePartition(myListShapes,
424 if ( !anObj->_is_nil() )
425 objects.push_back( anObj._retn() );
431 //=================================================================================
432 // function : closeEvent
434 //=================================================================================
435 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
437 GEOMBase_Skeleton::closeEvent( e );
441 //=======================================================================
442 //function : ComboTextChanged
444 //=======================================================================
446 void OperationGUI_PartitionDlg::ComboTextChanged()
448 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
449 GroupPoints->LineEdit3->setEnabled(IsEnabled);
450 GroupPoints->LineEdit4->setEnabled(IsEnabled);
451 GroupPoints->TextLabel4->setEnabled(IsEnabled);
452 GroupPoints->TextLabel5->setEnabled(IsEnabled);
453 GroupPoints->PushButton3->setEnabled(IsEnabled);
454 GroupPoints->PushButton4->setEnabled(IsEnabled);
458 //=================================================================================
459 // function : SetMaterials()
461 //=================================================================================
462 void OperationGUI_PartitionDlg::SetMaterials()
464 SALOME_Selection* Sel =
465 SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
466 MESSAGE("OperationGUI_MaterialDlg ...");
467 OperationGUI_MaterialDlg *aDlg =
468 new OperationGUI_MaterialDlg(this, "", Sel, myListShapes, true);
469 MESSAGE("OperationGUI_MaterialDlg");
474 //=================================================================================
475 // function : onRemoveWebs()
477 //=================================================================================
478 void OperationGUI_PartitionDlg::onRemoveWebs(bool isChecked)
480 if (GroupPoints->CheckBox1->isChecked() != isChecked)
481 GroupPoints->CheckBox1->setChecked(isChecked);
483 GroupPoints->PushButton5->setEnabled(isChecked);
487 //=================================================================================
488 // function : toRemoveWebs()
490 //=================================================================================
491 bool OperationGUI_PartitionDlg::toRemoveWebs() const
493 return GroupPoints->CheckBox1->isChecked();
497 //=================================================================================
498 // function : GetLimit()
500 //=================================================================================
501 int OperationGUI_PartitionDlg::GetLimit() const
503 int aLimit = GroupPoints->ComboBox1->currentItem();
509 aLimit = GEOM::SOLID;
514 aLimit = GEOM::SHELL;
534 aLimit = GEOM::VERTEX;
538 aLimit = GEOM::SHAPE;