1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : OperationGUI_PartitionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "OperationGUI_PartitionDlg.h"
29 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
44 //=================================================================================
45 // class : OperationGUI_PartitionDlg()
46 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
52 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
54 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
55 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
56 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION_PLANE" ) ) );
57 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr( "GEOM_PARTITION_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
63 mainFrame()->RadioButton1->setIcon( image0 );
64 mainFrame()->RadioButton2->setIcon( image1 );
65 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
66 mainFrame()->RadioButton3->close();
68 // Full partition (contains half-space partition)
69 GroupPoints = new DlgRef_2Sel1List1Check( centralWidget() );
70 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
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->PushButton1->setIcon( image2 );
75 GroupPoints->PushButton2->setIcon( image2 );
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
78 GroupPoints->LineEdit1->setEnabled(true);
79 GroupPoints->LineEdit2->setEnabled(false);
80 GroupPoints->CheckButton1->setText( tr( "GEOM_KEEP_NONLIMIT_SHAPES" ) );
82 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
83 layout->setMargin( 0 ); layout->setSpacing( 6 );
84 layout->addWidget( GroupPoints );
86 /***************************************************************/
88 setHelpFileName( "partition_page.html" );
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
103 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
105 myListMaterials = ListMaterials;
108 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
110 return myListMaterials;
113 //=================================================================================
116 //=================================================================================
117 void OperationGUI_PartitionDlg::Init()
119 /* type for sub shape selection */
120 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
121 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
122 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
123 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
124 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
125 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
126 GroupPoints->CheckButton1->setChecked( false );
128 mainFrame()->GroupBoxPublish->show();
130 /* signals and slots connections */
131 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
132 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
134 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
136 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
137 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
139 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
140 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
142 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
144 connect( myGeomGUI->getApp()->selectionMgr(),
145 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
147 initName( tr( "GEOM_PARTITION" ) );
149 ConstructorsClicked( 0 );
150 GroupPoints->PushButton1->click();
154 //=================================================================================
155 // function : ConstructorsClicked()
156 // purpose : Radio button management
157 //=================================================================================
158 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
160 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
163 myListShapes.length( 0 );
164 myListTools.length( 0 );
165 myListKeepInside.length( 0 );
166 myListRemoveInside.length( 0 );
167 myListMaterials.length( 0 );
169 switch ( constructorId ) {
170 case 0: /*Full partition */
171 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
172 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECT" ) );
173 GroupPoints->TextLabel3->show();
174 GroupPoints->ComboBox1->show();
175 GroupPoints->ComboBox1->setCurrentIndex( 0 );
176 GroupPoints->CheckButton1->show();
177 GroupPoints->PushButton1->setDown( true );
178 GroupPoints->PushButton2->setDown( false );
179 GroupPoints->LineEdit1->setEnabled(true);
180 GroupPoints->LineEdit2->setEnabled(false);
182 case 1: /*Half-space partition */
183 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
184 GroupPoints->TextLabel3->hide();
185 GroupPoints->ComboBox1->hide();
186 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
187 GroupPoints->CheckButton1->hide();
188 GroupPoints->PushButton1->setDown( true );
189 GroupPoints->LineEdit1->setEnabled(true);
193 myEditCurrentArgument = GroupPoints->LineEdit1;
194 GroupPoints->LineEdit1->clear();
195 GroupPoints->LineEdit2->clear();
197 qApp->processEvents();
199 resize( minimumSizeHint() );
201 myEditCurrentArgument->setFocus();
202 connect( myGeomGUI->getApp()->selectionMgr(),
203 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void OperationGUI_PartitionDlg::ClickOnOk()
213 if ( ClickOnApply() )
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 bool OperationGUI_PartitionDlg::ClickOnApply()
228 ConstructorsClicked( getConstructorId() );
233 //=================================================================================
234 // function : SelectionIntoArgument()
235 // purpose : Called when selection as changed or other case
236 //=================================================================================
237 void OperationGUI_PartitionDlg::SelectionIntoArgument()
239 myEditCurrentArgument->setText( "" );
240 QString aString = "";
242 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
243 SALOME_ListIO aSelList;
244 aSelMgr->selectedObjects(aSelList);
246 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
249 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
250 myListShapes.length( 0 );
251 myListMaterials.length( 0 );
253 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
254 myListTools.length( 0 );
257 // One and only one plane can be selected
259 if ( getConstructorId() == 1 &&
260 myEditCurrentArgument == GroupPoints->LineEdit2 &&
262 myListTools.length( 0 );
266 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
267 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
268 myListMaterials.length( 0 );
269 if ( !myListShapes.length() )
272 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
273 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
274 if ( !myListTools.length() )
278 myEditCurrentArgument->setText( aString );
282 //=================================================================================
283 // function : SetEditCurrentArgument()
285 //=================================================================================
286 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
288 QPushButton* send = (QPushButton*)sender();
290 if ( send == GroupPoints->PushButton1 ) {
291 myEditCurrentArgument = GroupPoints->LineEdit1;
292 GroupPoints->PushButton2->setDown(false);
293 GroupPoints->LineEdit1->setEnabled(true);
294 GroupPoints->LineEdit2->setEnabled(false);
296 else if ( send == GroupPoints->PushButton2 ) {
297 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
298 myEditCurrentArgument = GroupPoints->LineEdit2;
299 GroupPoints->PushButton1->setDown(false);
300 GroupPoints->LineEdit1->setEnabled(false);
301 GroupPoints->LineEdit2->setEnabled(true);
302 if ( getConstructorId() == 1 )
303 globalSelection( GEOM_PLANE );
306 globalSelection( GEOM_ALLSHAPES );
308 myEditCurrentArgument->setFocus();
309 SelectionIntoArgument();
314 //=================================================================================
315 // function : LineEditReturnPressed()
317 //=================================================================================
318 void OperationGUI_PartitionDlg::LineEditReturnPressed()
320 QLineEdit* send = (QLineEdit*)sender();
322 if ( send == GroupPoints->LineEdit1 ||
323 send == GroupPoints->LineEdit2 ) {
324 myEditCurrentArgument = send;
325 GEOMBase_Skeleton::LineEditReturnPressed();
330 //=================================================================================
331 // function : ActivateThisDialog()
333 //=================================================================================
334 void OperationGUI_PartitionDlg::ActivateThisDialog()
336 GEOMBase_Skeleton::ActivateThisDialog();
337 connect( myGeomGUI->getApp()->selectionMgr(),
338 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
340 ConstructorsClicked( getConstructorId() );
344 //=================================================================================
345 // function : enterEvent()
347 //=================================================================================
348 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
350 if ( !mainFrame()->GroupConstructors->isEnabled() )
351 this->ActivateThisDialog();
355 //=================================================================================
356 // function : createOperation
358 //=================================================================================
359 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
361 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
365 //=================================================================================
366 // function : isValid
368 //=================================================================================
369 bool OperationGUI_PartitionDlg::isValid( QString& )
371 return ( myListShapes.length() || myListTools.length() ||
372 myListKeepInside.length() || myListRemoveInside.length() );
376 //=================================================================================
377 // function : execute
379 //=================================================================================
380 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
384 GEOM::GEOM_Object_var anObj;
387 int aLimit = GetLimit();
388 int aConstructorId = getConstructorId();
389 int aKeepNonlimitShapes = 0;
391 if ( aConstructorId == 1 ) {
392 aLimit = GEOM::SHAPE;
395 if ( GroupPoints->CheckButton1->isChecked() ) {
396 aKeepNonlimitShapes = 1;
399 aKeepNonlimitShapes = 0;
403 if ( isValid( msg ) ) {
404 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
405 anObj = anOper->MakePartition( myListShapes, myListTools,
406 myListKeepInside, myListRemoveInside,
407 aLimit, false, myListMaterials, aKeepNonlimitShapes );
411 if ( !anObj->_is_nil() ) {
413 GEOMBase::GetShape(anObj, aShape, TopAbs_SHAPE);
414 TopoDS_Iterator It (aShape, Standard_True, Standard_True);
416 for (; It.More(); It.Next())
420 objects.push_back( anObj._retn() );
422 SUIT_MessageBox::warning(this,
423 QObject::tr("GEOM_ERROR"),
424 QObject::tr("GEOM_WRN_PARTITION_RESULT_EMPTY"));
430 //=================================================================================
431 // function : restoreSubShapes
433 //=================================================================================
434 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
435 SALOMEDS::SObject_ptr theSObject )
437 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
438 // empty list of arguments means that all arguments should be restored
439 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
440 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
441 /*theInheritFirstArg=*/myListShapes.length() == 1,
442 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
446 //=======================================================================
447 //function : ComboTextChanged
449 //=======================================================================
450 void OperationGUI_PartitionDlg::ComboTextChanged()
452 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
453 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
454 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
455 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
456 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
457 //GroupPoints->PushButton3->setEnabled(IsEnabled);
458 //GroupPoints->PushButton4->setEnabled(IsEnabled);
461 //=================================================================================
462 // function : GetLimit()
464 //=================================================================================
465 int OperationGUI_PartitionDlg::GetLimit() const
467 int aLimit = GroupPoints->ComboBox1->currentIndex();
470 case 0: aLimit = GEOM::SOLID ; break;
471 case 1: aLimit = GEOM::SHELL ; break;
472 case 2: aLimit = GEOM::FACE ; break;
473 case 3: aLimit = GEOM::WIRE ; break;
474 case 4: aLimit = GEOM::EDGE ; break;
475 case 5: aLimit = GEOM::VERTEX; break;
476 default: aLimit = GEOM::SHAPE ;