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_2Sel1List2Check( 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" ) );
82 GroupPoints->CheckButton2->setText( tr( "GEOM_NO_SELF_INTERSECTION" ) );
84 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85 layout->setMargin( 0 ); layout->setSpacing( 6 );
86 layout->addWidget( GroupPoints );
88 /***************************************************************/
90 setHelpFileName( "partition_page.html" );
96 //=================================================================================
97 // function : ~OperationGUI_PartitionDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
102 // no need to delete child widgets, Qt does it all for us
105 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
107 myListMaterials = ListMaterials;
110 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
112 return myListMaterials;
115 //=================================================================================
118 //=================================================================================
119 void OperationGUI_PartitionDlg::Init()
121 /* type for sub shape selection */
122 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
123 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SOLID);
124 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
125 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SHELL);
126 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
127 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::FACE);
128 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
129 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::WIRE);
130 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
131 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::EDGE);
132 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
133 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::VERTEX);
134 GroupPoints->CheckButton1->setChecked( false );
136 mainFrame()->GroupBoxPublish->show();
138 /* signals and slots connections */
139 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
140 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
142 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
144 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
145 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
147 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
148 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
150 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
152 connect( myGeomGUI->getApp()->selectionMgr(),
153 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
155 connect( GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
156 connect( GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
158 initName( tr( "GEOM_PARTITION" ) );
160 ConstructorsClicked( 0 );
161 GroupPoints->PushButton1->click();
165 //=================================================================================
166 // function : ConstructorsClicked()
167 // purpose : Radio button management
168 //=================================================================================
169 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
171 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
174 //myListShapes.length( 0 );
175 //myListTools.length( 0 );
176 //myListKeepInside.length( 0 ); // obsolete
177 //myListRemoveInside.length( 0 ); // obsolete
178 //myListMaterials.length( 0 ); // obsolete
180 switch ( constructorId ) {
181 case 0: /*Full partition */
182 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
183 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
184 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
185 GroupPoints->TextLabel3->show();
186 GroupPoints->ComboBox1->show();
187 GroupPoints->ComboBox1->setCurrentIndex( 0 );
188 GroupPoints->CheckButton1->show();
189 GroupPoints->CheckButton2->show();
190 GroupPoints->PushButton1->setDown( true );
191 GroupPoints->PushButton2->setDown( false );
192 GroupPoints->LineEdit1->setEnabled(true);
193 GroupPoints->LineEdit2->setEnabled(false);
195 case 1: /*Half-space partition */
196 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
197 GroupPoints->TextLabel3->hide();
198 GroupPoints->ComboBox1->hide();
199 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
200 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
201 GroupPoints->CheckButton1->hide();
202 GroupPoints->CheckButton2->hide();
203 GroupPoints->PushButton1->setDown( true );
204 GroupPoints->LineEdit1->setEnabled(true);
208 myEditCurrentArgument = GroupPoints->LineEdit1;
209 GroupPoints->LineEdit1->clear();
210 GroupPoints->LineEdit2->clear();
212 qApp->processEvents();
214 resize( minimumSizeHint() );
216 myEditCurrentArgument->setFocus();
217 connect( myGeomGUI->getApp()->selectionMgr(),
218 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
219 SelectionIntoArgument();
223 //=================================================================================
224 // function : ClickOnOk()
226 //=================================================================================
227 void OperationGUI_PartitionDlg::ClickOnOk()
229 if ( ClickOnApply() )
234 //=================================================================================
235 // function : ClickOnApply()
237 //=================================================================================
238 bool OperationGUI_PartitionDlg::ClickOnApply()
245 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
246 // ConstructorsClicked( getConstructorId() );
251 //=================================================================================
252 // function : SelectionIntoArgument()
253 // purpose : Called when selection as changed or other case
254 //=================================================================================
255 void OperationGUI_PartitionDlg::SelectionIntoArgument()
257 myEditCurrentArgument->setText( "" );
258 QString aString = "";
260 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
261 SALOME_ListIO aSelList;
262 aSelMgr->selectedObjects(aSelList);
264 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
266 if ( getConstructorId() == 1 ) {
267 // for half-selection, only one shape can be selected as an object
268 // and only one plane as a tool
270 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
271 myListShapes.length( 0 );
272 // myListMaterials.length( 0 ); // obsolete
275 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
276 myListTools.length( 0 );
283 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
284 myListShapes.length( 0 );
285 //myListMaterials.length( 0 ); // obsolete
288 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
289 myListTools.length( 0 );
295 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
296 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
297 //myListMaterials.length( 0 ); // obsolete
299 GEOM::shape_type type = GEOM::SHAPE;
300 for (int i = 0; i < myListShapes.length(); i++)
301 type = qMin( type, myListShapes[i]->GetMaxShapeType() );
302 int idx = qMax( 0, GroupPoints->ComboBox1->findData( type ) );
303 GroupPoints->ComboBox1->setCurrentIndex( idx );
305 if ( !myListShapes.length() )
308 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
309 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
310 if ( !myListTools.length() )
312 else if ( myListTools.length() == 1 && getConstructorId() == 1 ) {
313 GEOM::GEOM_IMeasureOperations_var mOp = getGeomEngine()->GetIMeasureOperations( getStudyId() );
314 GEOM::ListOfLong_var intList;
315 GEOM::ListOfDouble_var dblList;
316 GEOM::GEOM_IKindOfShape::shape_kind kind = mOp->KindOfShape( myListTools[0].in(), intList.out(), dblList.out() );
318 if ( kind < GEOM::GEOM_IKindOfShape::DISK_CIRCLE || kind > GEOM::GEOM_IKindOfShape::PLANAR ) {
319 myListTools.length( 0 );
325 myEditCurrentArgument->setText( aString );
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
338 if ( send == GroupPoints->PushButton1 ) {
339 myEditCurrentArgument = GroupPoints->LineEdit1;
340 GroupPoints->PushButton2->setDown(false);
341 GroupPoints->LineEdit1->setEnabled(true);
342 GroupPoints->LineEdit2->setEnabled(false);
344 else if ( send == GroupPoints->PushButton2 ) {
345 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
346 myEditCurrentArgument = GroupPoints->LineEdit2;
347 GroupPoints->PushButton1->setDown(false);
348 GroupPoints->LineEdit1->setEnabled(false);
349 GroupPoints->LineEdit2->setEnabled(true);
350 if ( getConstructorId() == 1 )
351 globalSelection( GEOM_PLANE );
354 globalSelection( GEOM_ALLSHAPES );
356 myEditCurrentArgument->setFocus();
357 SelectionIntoArgument();
363 //=================================================================================
364 // function : LineEditReturnPressed()
366 //=================================================================================
367 void OperationGUI_PartitionDlg::LineEditReturnPressed()
369 QLineEdit* send = (QLineEdit*)sender();
371 if ( send == GroupPoints->LineEdit1 ||
372 send == GroupPoints->LineEdit2 ) {
373 myEditCurrentArgument = send;
374 GEOMBase_Skeleton::LineEditReturnPressed();
379 //=================================================================================
380 // function : ActivateThisDialog()
382 //=================================================================================
383 void OperationGUI_PartitionDlg::ActivateThisDialog()
385 GEOMBase_Skeleton::ActivateThisDialog();
386 connect( myGeomGUI->getApp()->selectionMgr(),
387 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
389 ConstructorsClicked( getConstructorId() );
394 //=================================================================================
395 // function : enterEvent()
397 //=================================================================================
398 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
400 if ( !mainFrame()->GroupConstructors->isEnabled() )
401 this->ActivateThisDialog();
405 //=================================================================================
406 // function : createOperation
408 //=================================================================================
409 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
411 return getGeomEngine()->GetIBooleanOperations( getStudyId() );
415 //=================================================================================
416 // function : isValid
418 //=================================================================================
419 bool OperationGUI_PartitionDlg::isValid( QString& )
421 return ( myListShapes.length() || myListTools.length() ); // || myListKeepInside.length() || myListRemoveInside.length() // obsolete
425 //=================================================================================
426 // function : execute
428 //=================================================================================
429 bool OperationGUI_PartitionDlg::execute( ObjectList& objects )
432 GEOM::GEOM_Object_var anObj;
434 int aLimit = GetLimit();
435 int aKeepNonlimitShapes = GroupPoints->CheckButton1->isChecked();
436 bool aNoSelfIntersection = GroupPoints->CheckButton2->isChecked();
438 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() );
440 switch ( getConstructorId() ) {
442 anObj = aNoSelfIntersection ?
443 anOper->MakePartitionNonSelfIntersectedShape( myListShapes, myListTools,
444 myListKeepInside, myListRemoveInside,
445 aLimit, false, myListMaterials, aKeepNonlimitShapes ) :
446 anOper->MakePartition( myListShapes, myListTools,
447 myListKeepInside, myListRemoveInside,
448 aLimit, false, myListMaterials, aKeepNonlimitShapes );
452 anObj = anOper->MakeHalfPartition( myListShapes[0].in(), myListTools[0].in() );
457 if ( !anObj->_is_nil() ) {
459 GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE );
460 TopoDS_Iterator It( aShape, Standard_True, Standard_True );
462 for ( ; It.More(); It.Next() )
466 objects.push_back( anObj._retn() );
468 SUIT_MessageBox::warning( this,
469 QObject::tr( "GEOM_ERROR" ),
470 QObject::tr( "GEOM_WRN_PARTITION_RESULT_EMPTY" ) );
476 //=================================================================================
477 // function : restoreSubShapes
479 //=================================================================================
480 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::Study_ptr theStudy,
481 SALOMEDS::SObject_ptr theSObject )
483 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
484 // empty list of arguments means that all arguments should be restored
485 getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
486 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
487 /*theInheritFirstArg=*/myListShapes.length() == 1,
488 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
492 //=======================================================================
493 //function : ComboTextChanged
495 //=======================================================================
496 void OperationGUI_PartitionDlg::ComboTextChanged()
498 //bool IsEnabled = GroupPoints->ComboBox1->currentItem() < 3;
499 //GroupPoints->LineEdit3->setEnabled(IsEnabled);
500 //GroupPoints->LineEdit4->setEnabled(IsEnabled);
501 //GroupPoints->TextLabel4->setEnabled(IsEnabled);
502 //GroupPoints->TextLabel5->setEnabled(IsEnabled);
503 //GroupPoints->PushButton3->setEnabled(IsEnabled);
504 //GroupPoints->PushButton4->setEnabled(IsEnabled);
508 //=================================================================================
509 // function : GetLimit()
511 //=================================================================================
512 int OperationGUI_PartitionDlg::GetLimit() const
514 int aLimit = GroupPoints->ComboBox1->currentIndex();
517 case 0: aLimit = GEOM::SOLID ; break;
518 case 1: aLimit = GEOM::SHELL ; break;
519 case 2: aLimit = GEOM::FACE ; break;
520 case 3: aLimit = GEOM::WIRE ; break;
521 case 4: aLimit = GEOM::EDGE ; break;
522 case 5: aLimit = GEOM::VERTEX; break;
523 default: aLimit = GEOM::SHAPE ;