1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : OperationGUI_PartitionDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "OperationGUI_PartitionDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_MessageBox.h>
39 #include <SalomeApp_Application.h>
40 #include <LightApp_SelectionMgr.h>
42 #include <TopoDS_Iterator.hxx>
43 #include <TopoDS_Shape.hxx>
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, false )
55 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
57 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION_PLANE" ) ) );
58 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
60 setWindowTitle( tr( "GEOM_PARTITION_TITLE" ) );
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
64 mainFrame()->RadioButton1->setIcon( image0 );
65 mainFrame()->RadioButton2->setIcon( image1 );
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 // Full partition (contains half-space partition)
70 GroupPoints = new DlgRef_2Sel1List1Check( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
74 GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
75 GroupPoints->PushButton1->setIcon( image2 );
76 GroupPoints->PushButton2->setIcon( image2 );
77 GroupPoints->LineEdit1->setReadOnly( true );
78 GroupPoints->LineEdit2->setReadOnly( true );
79 GroupPoints->LineEdit1->setEnabled(true);
80 GroupPoints->LineEdit2->setEnabled(false);
81 GroupPoints->CheckButton1->setText( tr( "GEOM_KEEP_NONLIMIT_SHAPES" ) );
83 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
84 layout->setMargin( 0 ); layout->setSpacing( 6 );
85 layout->addWidget( GroupPoints );
87 /***************************************************************/
89 setHelpFileName( "partition_page.html" );
95 //=================================================================================
96 // function : ~OperationGUI_PartitionDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
101 // no need to delete child widgets, Qt does it all for us
104 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
106 myListMaterials = ListMaterials;
109 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
111 return myListMaterials;
114 //=================================================================================
117 //=================================================================================
118 void OperationGUI_PartitionDlg::Init()
120 /* type for sub shape selection */
121 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
122 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
123 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
124 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
125 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
126 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
127 GroupPoints->CheckButton1->setChecked( false );
129 mainFrame()->GroupBoxPublish->show();
131 /* signals and slots connections */
132 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
133 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
135 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
137 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
140 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
141 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
143 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
145 connect( myGeomGUI->getApp()->selectionMgr(),
146 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
148 initName( tr( "GEOM_PARTITION" ) );
150 ConstructorsClicked( 0 );
151 GroupPoints->PushButton1->click();
155 //=================================================================================
156 // function : ConstructorsClicked()
157 // purpose : Radio button management
158 //=================================================================================
159 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
161 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
164 myListShapes.length( 0 );
165 myListTools.length( 0 );
166 myListKeepInside.length( 0 );
167 myListRemoveInside.length( 0 );
168 myListMaterials.length( 0 );
170 switch ( constructorId ) {
171 case 0: /*Full partition */
172 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
173 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
174 GroupPoints->TextLabel3->show();
175 GroupPoints->ComboBox1->show();
176 GroupPoints->ComboBox1->setCurrentIndex( 0 );
177 GroupPoints->CheckButton1->show();
178 GroupPoints->PushButton1->setDown( true );
179 GroupPoints->PushButton2->setDown( false );
180 GroupPoints->LineEdit1->setEnabled(true);
181 GroupPoints->LineEdit2->setEnabled(false);
183 case 1: /*Half-space partition */
184 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
185 GroupPoints->TextLabel3->hide();
186 GroupPoints->ComboBox1->hide();
187 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
188 GroupPoints->CheckButton1->hide();
189 GroupPoints->PushButton1->setDown( true );
190 GroupPoints->LineEdit1->setEnabled(true);
194 myEditCurrentArgument = GroupPoints->LineEdit1;
195 GroupPoints->LineEdit1->clear();
196 GroupPoints->LineEdit2->clear();
198 qApp->processEvents();
200 resize( minimumSizeHint() );
202 myEditCurrentArgument->setFocus();
203 connect( myGeomGUI->getApp()->selectionMgr(),
204 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
208 //=================================================================================
209 // function : ClickOnOk()
211 //=================================================================================
212 void OperationGUI_PartitionDlg::ClickOnOk()
214 if ( ClickOnApply() )
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 bool OperationGUI_PartitionDlg::ClickOnApply()
230 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
231 // ConstructorsClicked( getConstructorId() );
236 //=================================================================================
237 // function : SelectionIntoArgument()
238 // purpose : Called when selection as changed or other case
239 //=================================================================================
240 void OperationGUI_PartitionDlg::SelectionIntoArgument()
242 myEditCurrentArgument->setText( "" );
243 QString aString = "";
245 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
246 SALOME_ListIO aSelList;
247 aSelMgr->selectedObjects(aSelList);
249 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
252 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
253 myListShapes.length( 0 );
254 myListMaterials.length( 0 );
256 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
257 myListTools.length( 0 );
260 // One and only one plane can be selected
262 if ( getConstructorId() == 1 &&
263 myEditCurrentArgument == GroupPoints->LineEdit2 &&
265 myListTools.length( 0 );
269 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
270 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
271 myListMaterials.length( 0 );
272 if ( !myListShapes.length() )
275 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
276 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
277 if ( !myListTools.length() )
281 myEditCurrentArgument->setText( aString );
285 //=================================================================================
286 // function : SetEditCurrentArgument()
288 //=================================================================================
289 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
291 QPushButton* send = (QPushButton*)sender();
293 if ( send == GroupPoints->PushButton1 ) {
294 myEditCurrentArgument = GroupPoints->LineEdit1;
295 GroupPoints->PushButton2->setDown(false);
296 GroupPoints->LineEdit1->setEnabled(true);
297 GroupPoints->LineEdit2->setEnabled(false);
299 else if ( send == GroupPoints->PushButton2 ) {
300 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
301 myEditCurrentArgument = GroupPoints->LineEdit2;
302 GroupPoints->PushButton1->setDown(false);
303 GroupPoints->LineEdit1->setEnabled(false);
304 GroupPoints->LineEdit2->setEnabled(true);
305 if ( getConstructorId() == 1 )
306 globalSelection( GEOM_PLANE );
309 globalSelection( GEOM_ALLSHAPES );
311 myEditCurrentArgument->setFocus();
312 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 myEditCurrentArgument = send;
328 GEOMBase_Skeleton::LineEditReturnPressed();
333 //=================================================================================
334 // function : ActivateThisDialog()
336 //=================================================================================
337 void OperationGUI_PartitionDlg::ActivateThisDialog()
339 GEOMBase_Skeleton::ActivateThisDialog();
340 connect( myGeomGUI->getApp()->selectionMgr(),
341 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
343 ConstructorsClicked( getConstructorId() );
347 //=================================================================================
348 // function : enterEvent()
350 //=================================================================================
351 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
353 if ( !mainFrame()->GroupConstructors->isEnabled() )
354 this->ActivateThisDialog();
358 //=================================================================================
359 // function : createOperation
361 //=================================================================================
362 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
364 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
368 //=================================================================================
369 // function : isValid
371 //=================================================================================
372 bool OperationGUI_PartitionDlg::isValid( QString& )
374 return ( myListShapes.length() || myListTools.length() ||
375 myListKeepInside.length() || myListRemoveInside.length() );
379 //=================================================================================
380 // function : execute
382 //=================================================================================
383 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
387 GEOM::GEOM_Object_var anObj;
390 int aLimit = GetLimit();
391 int aConstructorId = getConstructorId();
392 int aKeepNonlimitShapes = 0;
394 if ( aConstructorId == 1 ) {
395 aLimit = GEOM::SHAPE;
398 if ( GroupPoints->CheckButton1->isChecked() ) {
399 aKeepNonlimitShapes = 1;
402 aKeepNonlimitShapes = 0;
406 if ( isValid( msg ) ) {
407 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
408 anObj = anOper->MakePartition( myListShapes, myListTools,
409 myListKeepInside, myListRemoveInside,
410 aLimit, false, myListMaterials, aKeepNonlimitShapes );
414 if ( !anObj->_is_nil() ) {
416 GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
417 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
419 for (; It.More(); It.Next())
423 objects.push_back( anObj._retn() );
425 SUIT_MessageBox::warning(this,
426 QObject::tr("GEOM_ERROR"),
427 QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
433 //=================================================================================
434 // function : restoreSubShapes
436 //=================================================================================
437 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
438 SALOMEDS::SObject_ptr theSObject )
440 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
441 // empty list of arguments means that all arguments should be restored
442 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
443 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
444 /*theInheritFirstArg=*/myListShapes.length() == 1,
445 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
449 //=======================================================================
450 //function : ComboTextChanged
452 //=======================================================================
453 void OperationGUI_PartitionDlg::ComboTextChanged()
455 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
456 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
457 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
458 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
459 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
460 //GroupPoints->PushButton3->setEnabled(IsEnabled);
461 //GroupPoints->PushButton4->setEnabled(IsEnabled);
464 //=================================================================================
465 // function : GetLimit()
467 //=================================================================================
468 int OperationGUI_PartitionDlg::GetLimit() const
470 int aLimit = GroupPoints->ComboBox1->currentIndex();
473 case 0: aLimit = GEOM::SOLID ; break;
474 case 1: aLimit = GEOM::SHELL ; break;
475 case 2: aLimit = GEOM::FACE ; break;
476 case 3: aLimit = GEOM::WIRE ; break;
477 case 4: aLimit = GEOM::EDGE ; break;
478 case 5: aLimit = GEOM::VERTEX; break;
479 default: aLimit = GEOM::SHAPE ;