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() ) );
205 SelectionIntoArgument();
209 //=================================================================================
210 // function : ClickOnOk()
212 //=================================================================================
213 void OperationGUI_PartitionDlg::ClickOnOk()
215 if ( ClickOnApply() )
220 //=================================================================================
221 // function : ClickOnApply()
223 //=================================================================================
224 bool OperationGUI_PartitionDlg::ClickOnApply()
231 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
232 // ConstructorsClicked( getConstructorId() );
237 //=================================================================================
238 // function : SelectionIntoArgument()
239 // purpose : Called when selection as changed or other case
240 //=================================================================================
241 void OperationGUI_PartitionDlg::SelectionIntoArgument()
243 myEditCurrentArgument->setText( "" );
244 QString aString = "";
246 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
247 SALOME_ListIO aSelList;
248 aSelMgr->selectedObjects(aSelList);
250 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
253 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
254 myListShapes.length( 0 );
255 myListMaterials.length( 0 );
257 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
258 myListTools.length( 0 );
261 // One and only one plane can be selected
263 if ( getConstructorId() == 1 &&
264 myEditCurrentArgument == GroupPoints->LineEdit2 &&
266 myListTools.length( 0 );
270 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
271 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
272 myListMaterials.length( 0 );
273 if ( !myListShapes.length() )
276 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
277 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
278 if ( !myListTools.length() )
282 myEditCurrentArgument->setText( aString );
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
292 QPushButton* send = (QPushButton*)sender();
294 if ( send == GroupPoints->PushButton1 ) {
295 myEditCurrentArgument = GroupPoints->LineEdit1;
296 GroupPoints->PushButton2->setDown(false);
297 GroupPoints->LineEdit1->setEnabled(true);
298 GroupPoints->LineEdit2->setEnabled(false);
300 else if ( send == GroupPoints->PushButton2 ) {
301 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
302 myEditCurrentArgument = GroupPoints->LineEdit2;
303 GroupPoints->PushButton1->setDown(false);
304 GroupPoints->LineEdit1->setEnabled(false);
305 GroupPoints->LineEdit2->setEnabled(true);
306 if ( getConstructorId() == 1 )
307 globalSelection( GEOM_PLANE );
310 globalSelection( GEOM_ALLSHAPES );
312 myEditCurrentArgument->setFocus();
313 SelectionIntoArgument();
318 //=================================================================================
319 // function : LineEditReturnPressed()
321 //=================================================================================
322 void OperationGUI_PartitionDlg::LineEditReturnPressed()
324 QLineEdit* send = (QLineEdit*)sender();
326 if ( send == GroupPoints->LineEdit1 ||
327 send == GroupPoints->LineEdit2 ) {
328 myEditCurrentArgument = send;
329 GEOMBase_Skeleton::LineEditReturnPressed();
334 //=================================================================================
335 // function : ActivateThisDialog()
337 //=================================================================================
338 void OperationGUI_PartitionDlg::ActivateThisDialog()
340 GEOMBase_Skeleton::ActivateThisDialog();
341 connect( myGeomGUI->getApp()->selectionMgr(),
342 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
344 ConstructorsClicked( getConstructorId() );
348 //=================================================================================
349 // function : enterEvent()
351 //=================================================================================
352 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
354 if ( !mainFrame()->GroupConstructors->isEnabled() )
355 this->ActivateThisDialog();
359 //=================================================================================
360 // function : createOperation
362 //=================================================================================
363 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
365 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
369 //=================================================================================
370 // function : isValid
372 //=================================================================================
373 bool OperationGUI_PartitionDlg::isValid( QString& )
375 return ( myListShapes.length() || myListTools.length() ||
376 myListKeepInside.length() || myListRemoveInside.length() );
380 //=================================================================================
381 // function : execute
383 //=================================================================================
384 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
388 GEOM::GEOM_Object_var anObj;
391 int aLimit = GetLimit();
392 int aConstructorId = getConstructorId();
393 int aKeepNonlimitShapes = 0;
395 if ( aConstructorId == 1 ) {
396 aLimit = GEOM::SHAPE;
399 if ( GroupPoints->CheckButton1->isChecked() ) {
400 aKeepNonlimitShapes = 1;
403 aKeepNonlimitShapes = 0;
407 if ( isValid( msg ) ) {
408 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
409 anObj = anOper->MakePartition( myListShapes, myListTools,
410 myListKeepInside, myListRemoveInside,
411 aLimit, false, myListMaterials, aKeepNonlimitShapes );
415 if ( !anObj->_is_nil() ) {
417 GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
418 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
420 for (; It.More(); It.Next())
424 objects.push_back( anObj._retn() );
426 SUIT_MessageBox::warning(this,
427 QObject::tr("GEOM_ERROR"),
428 QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
434 //=================================================================================
435 // function : restoreSubShapes
437 //=================================================================================
438 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
439 SALOMEDS::SObject_ptr theSObject )
441 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
442 // empty list of arguments means that all arguments should be restored
443 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
444 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
445 /*theInheritFirstArg=*/myListShapes.length() == 1,
446 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
450 //=======================================================================
451 //function : ComboTextChanged
453 //=======================================================================
454 void OperationGUI_PartitionDlg::ComboTextChanged()
456 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
457 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
458 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
459 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
460 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
461 //GroupPoints->PushButton3->setEnabled(IsEnabled);
462 //GroupPoints->PushButton4->setEnabled(IsEnabled);
465 //=================================================================================
466 // function : GetLimit()
468 //=================================================================================
469 int OperationGUI_PartitionDlg::GetLimit() const
471 int aLimit = GroupPoints->ComboBox1->currentIndex();
474 case 0: aLimit = GEOM::SOLID ; break;
475 case 1: aLimit = GEOM::SHELL ; break;
476 case 2: aLimit = GEOM::FACE ; break;
477 case 3: aLimit = GEOM::WIRE ; break;
478 case 4: aLimit = GEOM::EDGE ; break;
479 case 5: aLimit = GEOM::VERTEX; break;
480 default: aLimit = GEOM::SHAPE ;