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, true );
244 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
246 myListShapes.length( 0 );
247 myListMaterials.length( 0 );
249 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
250 myListTools.length( 0 );
251 else if ( myEditCurrentArgument == GroupPoints->LineEdit3 )
252 myListRemoveInside.length( 0 );
253 else if ( myEditCurrentArgument == GroupPoints->LineEdit4 )
254 myListKeepInside.length( 0 );
257 // One and only one plane can be selected
259 if ( getConstructorId() == 1 && myEditCurrentArgument == GroupPoints->LineEdit2 && nbSel != 1 )
261 myListTools.length( 0 );
265 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
267 GEOMBase::ConvertListOfIOInListOfGO( mySelection->StoredIObjects(), myListShapes, true );
268 myListMaterials.length( 0 );
269 if ( !myListShapes.length() )
272 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
274 GEOMBase::ConvertListOfIOInListOfGO( mySelection->StoredIObjects(), myListTools, true );
275 if ( !myListTools.length() )
278 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
280 GEOMBase::ConvertListOfIOInListOfGO( mySelection->StoredIObjects(), myListRemoveInside, true );
281 if (!myListRemoveInside.length())
284 else if(myEditCurrentArgument == GroupPoints->LineEdit4)
286 GEOMBase::ConvertListOfIOInListOfGO( mySelection->StoredIObjects(), myListKeepInside, true );
287 if ( !myListKeepInside.length() )
291 myEditCurrentArgument->setText( aString );
295 //=================================================================================
296 // function : SetEditCurrentArgument()
298 //=================================================================================
299 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
301 QPushButton* send = (QPushButton*)sender();
303 if(send == GroupPoints->PushButton1)
304 myEditCurrentArgument = GroupPoints->LineEdit1;
305 else if(send == GroupPoints->PushButton2)
307 myEditCurrentArgument = GroupPoints->LineEdit2;
308 if( getConstructorId()==1 )
309 globalSelection( GEOM_PLANE );
311 else if(send == GroupPoints->PushButton3)
312 myEditCurrentArgument = GroupPoints->LineEdit3;
313 else if(send == GroupPoints->PushButton4)
314 myEditCurrentArgument = GroupPoints->LineEdit4;
316 globalSelection( GEOM_ALLSHAPES );
318 myEditCurrentArgument->setFocus();
319 SelectionIntoArgument();
323 //=================================================================================
324 // function : LineEditReturnPressed()
326 //=================================================================================
327 void OperationGUI_PartitionDlg::LineEditReturnPressed()
329 QLineEdit* send = (QLineEdit*)sender();
331 if(send == GroupPoints->LineEdit1 ||
332 send == GroupPoints->LineEdit2 ||
333 send == GroupPoints->LineEdit3 ||
334 send == GroupPoints->LineEdit4 )
336 myEditCurrentArgument = send;
337 GEOMBase_Skeleton::LineEditReturnPressed();
342 //=================================================================================
343 // function : ActivateThisDialog()
345 //=================================================================================
346 void OperationGUI_PartitionDlg::ActivateThisDialog()
348 GEOMBase_Skeleton::ActivateThisDialog();
349 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
351 ConstructorsClicked( getConstructorId() );
355 //=================================================================================
356 // function : DeactivateActiveDialog()
357 // purpose : public slot to deactivate if active
358 //=================================================================================
359 void OperationGUI_PartitionDlg::DeactivateActiveDialog()
361 GEOMBase_Skeleton::DeactivateActiveDialog();
365 //=================================================================================
366 // function : enterEvent()
368 //=================================================================================
369 void OperationGUI_PartitionDlg::enterEvent(QEvent* e)
371 if(!GroupConstructors->isEnabled())
372 this->ActivateThisDialog();
376 //=================================================================================
377 // function : createOperation
379 //=================================================================================
380 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
382 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
386 //=================================================================================
387 // function : isValid
389 //=================================================================================
390 bool OperationGUI_PartitionDlg::isValid( QString& msg )
392 return (myListShapes.length() || myListTools.length() ||
393 myListKeepInside.length() || myListRemoveInside.length());
397 //=================================================================================
398 // function : execute
400 //=================================================================================
401 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
405 GEOM::GEOM_Object_var anObj;
408 int aLimit = GetLimit();
409 int aConstructorId = getConstructorId();
411 if (aConstructorId==1)
412 aLimit = GEOM::SHAPE;
417 if ( aConstructorId==0 && !toRemoveWebs() )
418 myListMaterials.length(0);
420 anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakePartition(myListShapes,
430 if ( !anObj->_is_nil() )
431 objects.push_back( anObj._retn() );
437 //=================================================================================
438 // function : closeEvent
440 //=================================================================================
441 void OperationGUI_PartitionDlg::closeEvent( QCloseEvent* e )
443 GEOMBase_Skeleton::closeEvent( e );
447 //=======================================================================
448 //function : ComboTextChanged
450 //=======================================================================
452 void OperationGUI_PartitionDlg::ComboTextChanged()
454 bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
455 GroupPoints->LineEdit3->setEnabled(IsEnabled);
456 GroupPoints->LineEdit4->setEnabled(IsEnabled);
457 GroupPoints->TextLabel4->setEnabled(IsEnabled);
458 GroupPoints->TextLabel5->setEnabled(IsEnabled);
459 GroupPoints->PushButton3->setEnabled(IsEnabled);
460 GroupPoints->PushButton4->setEnabled(IsEnabled);
464 //=================================================================================
465 // function : SetMaterials()
467 //=================================================================================
468 void OperationGUI_PartitionDlg::SetMaterials()
470 SALOME_Selection* Sel =
471 SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
472 MESSAGE("OperationGUI_MaterialDlg ...");
473 OperationGUI_MaterialDlg *aDlg =
474 new OperationGUI_MaterialDlg(this, "", Sel, myListShapes, true);
475 MESSAGE("OperationGUI_MaterialDlg");
480 //=================================================================================
481 // function : onRemoveWebs()
483 //=================================================================================
484 void OperationGUI_PartitionDlg::onRemoveWebs(bool isChecked)
486 if (GroupPoints->CheckBox1->isChecked() != isChecked)
487 GroupPoints->CheckBox1->setChecked(isChecked);
489 GroupPoints->PushButton5->setEnabled(isChecked);
493 //=================================================================================
494 // function : toRemoveWebs()
496 //=================================================================================
497 bool OperationGUI_PartitionDlg::toRemoveWebs() const
499 return GroupPoints->CheckBox1->isChecked();
503 //=================================================================================
504 // function : GetLimit()
506 //=================================================================================
507 int OperationGUI_PartitionDlg::GetLimit() const
509 int aLimit = GroupPoints->ComboBox1->currentItem();
515 aLimit = GEOM::SOLID;
520 aLimit = GEOM::SHELL;
540 aLimit = GEOM::VERTEX;
544 aLimit = GEOM::SHAPE;