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 "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(QWidget* parent, const char* name, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION")));
56 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PARTITION_PLANE")));
57 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_PARTITION_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_PARTITION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 // Full partition (contains half-space partition)
68 GroupPoints = new DlgRef_4Sel1List1Check_QTD(this, "GroupPoints");
69 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
70 GroupPoints->GroupBox2->setTitle(tr("SUPPRESS_RESULT"));
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->TextLabel4->setText(tr("GEOM_SUPPRESS_RESULT_INSIDE"));
75 GroupPoints->TextLabel5->setText(tr("GEOM_SUPPRESS_RESULT_OUTSIDE"));
76 GroupPoints->CheckBox1->setText(tr("GEOM_REMOVE_WEBS"));
77 GroupPoints->PushButton1->setPixmap(image2);
78 GroupPoints->PushButton2->setPixmap(image2);
79 GroupPoints->PushButton3->setPixmap(image2);
80 GroupPoints->PushButton4->setPixmap(image2);
81 GroupPoints->PushButton5->setText(tr("GEOM_SET_MATERIALS"));
82 GroupPoints->LineEdit1->setReadOnly( true );
83 GroupPoints->LineEdit2->setReadOnly( true );
84 GroupPoints->LineEdit3->setReadOnly( true );
85 GroupPoints->LineEdit4->setReadOnly( true );
87 Layout1->addWidget(GroupPoints, 2, 0);
88 /***************************************************************/
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
104 //=================================================================================
107 //=================================================================================
108 void OperationGUI_PartitionDlg::Init()
110 /* type for sub shape selection */
111 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SOLID"));
112 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_SHELL"));
113 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_FACE"));
114 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_WIRE"));
115 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_EDGE"));
116 GroupPoints->ComboBox1->insertItem(tr("GEOM_RECONSTRUCTION_LIMIT_VERTEX"));
118 /* signals and slots connections */
119 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
120 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
121 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
123 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126 connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127 connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetMaterials()));
129 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
131 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
132 connect(GroupPoints->LineEdit4, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
134 connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(onRemoveWebs(bool)));
136 connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
138 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
139 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
141 initName( tr( "GEOM_PARTITION" ) );
142 ConstructorsClicked( 0 );
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose : Radio button management
149 //=================================================================================
150 void OperationGUI_PartitionDlg::ConstructorsClicked(int constructorId)
152 disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
155 myListShapes.length(0);
156 myListTools.length(0);
157 myListKeepInside.length(0);
158 myListRemoveInside.length(0);
159 myListMaterials.length(0);
161 switch (constructorId)
163 case 0: /*Full partition */
165 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION"));
166 GroupPoints->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
168 GroupPoints->TextLabel3->show();
169 GroupPoints->ComboBox1->show();
170 GroupPoints->GroupBox2->show();
172 GroupPoints->ComboBox1->setCurrentItem(0);
173 GroupPoints->LineEdit3->clear();
174 GroupPoints->LineEdit4->clear();
177 case 1: /*Half-space partition */
180 GroupPoints->GroupBox1->setTitle(tr("GEOM_PARTITION_HALFSPACE"));
181 GroupPoints->GroupBox2->hide();
182 GroupPoints->TextLabel3->hide();
183 GroupPoints->ComboBox1->hide();
184 GroupPoints->TextLabel2->setText(tr("GEOM_PLANE"));
190 myEditCurrentArgument = GroupPoints->LineEdit1;
191 GroupPoints->LineEdit1->clear();
192 GroupPoints->LineEdit2->clear();
195 myEditCurrentArgument->setFocus();
196 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
197 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
198 MESSAGE(width()<<" "<<height());
202 //=================================================================================
203 // function : ClickOnOk()
205 //=================================================================================
206 void OperationGUI_PartitionDlg::ClickOnOk()
208 if ( ClickOnApply() )
213 //=================================================================================
214 // function : ClickOnApply()
216 //=================================================================================
217 bool OperationGUI_PartitionDlg::ClickOnApply()
223 ConstructorsClicked( getConstructorId() );
228 //=======================================================================
229 // function : ClickOnCancel()
231 //=======================================================================
232 void OperationGUI_PartitionDlg::ClickOnCancel()
234 GEOMBase_Skeleton::ClickOnCancel();
238 //=================================================================================
239 // function : SelectionIntoArgument()
240 // purpose : Called when selection as changed or other case
241 //=================================================================================
242 void OperationGUI_PartitionDlg::SelectionIntoArgument()
244 myEditCurrentArgument->setText( "" );
245 QString aString = "";
247 int nbSel = GEOMBase::GetNameOfSelectedIObjects( selectedIO(), aString, true );
251 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
253 myListShapes.length( 0 );
254 myListMaterials.length( 0 );
256 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
257 myListTools.length( 0 );
258 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
259 myListRemoveInside.length( 0 );
260 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
261 myListKeepInside.length( 0 );
264 // One and only one plane can be selected
266 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
268 myListTools.length( 0 );
272 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
274 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListShapes, true );
275 myListMaterials.length( 0 );
276 if ( !myListShapes.length() )
279 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
281 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListTools, true );
282 if ( !myListTools.length() )
285 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
287 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListRemoveInside, true );
288 if (!myListRemoveInside.length())
291 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
293 GEOMBase::ConvertListOfIOInListOfGO( selectedIO(), myListKeepInside, true );
294 if ( !myListKeepInside.length() )
298 myEditCurrentArgument->setText( aString );
302 //=================================================================================
303 // function : SetEditCurrentArgument()
305 //=================================================================================
306 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
308 QPushButton* send = (QPushButton*)sender();
310 if(send == GroupPoints->PushButton1)
311 myEditCurrentArgument = GroupPoints->LineEdit1;
312 else if(send == GroupPoints->PushButton2)
314 myEditCurrentArgument = GroupPoints->LineEdit2;
315 if( getConstructorId()==1 )
316 globalSelection( GEOM_PLANE );
318 else if(send == GroupPoints->PushButton3)
319 myEditCurrentArgument = GroupPoints->LineEdit3;
320 else if(send == GroupPoints->PushButton4)
321 myEditCurrentArgument = GroupPoints->LineEdit4;
323 globalSelection( GEOM_ALLSHAPES );
325 myEditCurrentArgument->setFocus();
326 SelectionIntoArgument();
330 //=================================================================================
331 // function : LineEditReturnPressed()
333 //=================================================================================
334 void OperationGUI_PartitionDlg::LineEditReturnPressed()
336 QLineEdit* send = (QLineEdit*)sender();
338 if(send == GroupPoints->LineEdit1 ||
339 send == GroupPoints->LineEdit2 ||
340 send == GroupPoints->LineEdit3 ||
341 send == GroupPoints->LineEdit4 )
343 myEditCurrentArgument = send;
344 GEOMBase_Skeleton::LineEditReturnPressed();
349 //=================================================================================
350 // function : ActivateThisDialog()
352 //=================================================================================
353 void OperationGUI_PartitionDlg::ActivateThisDialog()
355 GEOMBase_Skeleton::ActivateThisDialog();
356 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
357 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
359 ConstructorsClicked( getConstructorId() );
363 //=================================================================================
364 // function : DeactivateActiveDialog()
365 // purpose : public slot to deactivate if active
366 //=================================================================================
367 void OperationGUI_PartitionDlg::DeactivateActiveDialog()
369 GEOMBase_Skeleton::DeactivateActiveDialog();
373 //=================================================================================
374 // function : enterEvent()
376 //=================================================================================
377 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
379 if(!GroupConstructors->isEnabled())
380 this->ActivateThisDialog();
384 //=================================================================================
385 // function : createOperation
387 //=================================================================================
388 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
390 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
394 //=================================================================================
395 // function : isValid
397 //=================================================================================
398 bool OperationGUI_PartitionDlg::isValid( QString& msg )
400 return (myListShapes.length() || myListTools.length() ||
401 myListKeepInside.length() || myListRemoveInside.length());
405 //=================================================================================
406 // function : execute
408 //=================================================================================
409 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
413 GEOM::GEOM_Object_var anObj;
416 int aLimit = GetLimit();
417 int aConstructorId = getConstructorId();
419 if (aConstructorId==1)
420 aLimit = GEOM::SHAPE;
425 if ( aConstructorId==0 && !toRemoveWebs() )
426 myListMaterials.length(0);
428 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakePartition(myListShapes,
438 if ( !anObj->_is_nil() )
439 objects.push_back( anObj._retn() );
445 //=================================================================================
446 // function : closeEvent
448 //=================================================================================
449 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
451 GEOMBase_Skeleton::closeEvent( e );
455 //=======================================================================
456 //function : ComboTextChanged
458 //=======================================================================
460 void OperationGUI_PartitionDlg::ComboTextChanged()
462 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
463 GroupPoints->LineEdit3->setEnabled(IsEnabled);
464 GroupPoints->LineEdit4->setEnabled(IsEnabled);
465 GroupPoints->TextLabel4->setEnabled(IsEnabled);
466 GroupPoints->TextLabel5->setEnabled(IsEnabled);
467 GroupPoints->PushButton3->setEnabled(IsEnabled);
468 GroupPoints->PushButton4->setEnabled(IsEnabled);
472 //=================================================================================
473 // function : SetMaterials()
475 //=================================================================================
476 void OperationGUI_PartitionDlg::SetMaterials()
478 MESSAGE("OperationGUI_MaterialDlg ...");
479 OperationGUI_MaterialDlg *aDlg =
480 new OperationGUI_MaterialDlg(this, "", myListShapes, true);
481 MESSAGE("OperationGUI_MaterialDlg");
486 //=================================================================================
487 // function : onRemoveWebs()
489 //=================================================================================
490 void OperationGUI_PartitionDlg::onRemoveWebs(bool isChecked)
492 if (GroupPoints->CheckBox1->isChecked() != isChecked)
493 GroupPoints->CheckBox1->setChecked(isChecked);
495 GroupPoints->PushButton5->setEnabled(isChecked);
499 //=================================================================================
500 // function : toRemoveWebs()
502 //=================================================================================
503 bool OperationGUI_PartitionDlg::toRemoveWebs() const
505 return GroupPoints->CheckBox1->isChecked();
509 //=================================================================================
510 // function : GetLimit()
512 //=================================================================================
513 int OperationGUI_PartitionDlg::GetLimit() const
515 int aLimit = GroupPoints->ComboBox1->currentItem();
521 aLimit = GEOM::SOLID;
526 aLimit = GEOM::SHELL;
546 aLimit = GEOM::VERTEX;
550 aLimit = GEOM::SHAPE;