1 // Copyright (C) 2007-2024 CEA, EDF, 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, or (at your option) any later version.
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 // VSR 22/08/2012: issue 0021787: remove "Preview" button from BOP and Partition operations
46 // Comment next line to enable preview in Partition dialog box
49 #define DEFAULT_FUZZY_VALUE 1e-5
52 //=================================================================================
53 // class : OperationGUI_PartitionDlg()
54 // purpose : Constructs a OperationGUI_PartitionDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 OperationGUI_PartitionDlg::OperationGUI_PartitionDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
60 : GEOMBase_Skeleton( theGeometryGUI, parent, false )
62 SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
63 QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION" ) ) );
64 QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_PARTITION_PLANE" ) ) );
65 QPixmap image2( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
67 setWindowTitle( tr( "GEOM_PARTITION_TITLE" ) );
69 /***************************************************************/
70 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
71 mainFrame()->RadioButton1->setIcon( image0 );
72 mainFrame()->RadioButton2->setIcon( image1 );
73 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
74 mainFrame()->RadioButton2->close();
75 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
76 mainFrame()->RadioButton3->close();
78 // Full partition (contains half-space partition)
79 GroupPoints = new DlgRef_2Sel1List2Check( centralWidget() );
80 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
81 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
82 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
83 GroupPoints->TextLabel3->setText( tr( "GEOM_RECONSTRUCTION_LIMIT" ) );
84 GroupPoints->PushButton1->setIcon( image2 );
85 GroupPoints->PushButton2->setIcon( image2 );
86 GroupPoints->LineEdit1->setReadOnly( true );
87 GroupPoints->LineEdit2->setReadOnly( true );
88 GroupPoints->LineEdit1->setEnabled( true );
89 GroupPoints->LineEdit2->setEnabled( false );
90 GroupPoints->CheckButton1->setText( tr( "GEOM_KEEP_NONLIMIT_SHAPES" ) );
91 GroupPoints->CheckButton2->setText( tr( "GEOM_NO_SELF_INTERSECTION" ) );
93 mySelfInte = new QCheckBox(GroupPoints->GroupBox1);
94 mySelfInte->setText(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
95 GroupPoints->gridLayout1->addWidget(mySelfInte, 5, 0, 1, 3);
97 // Add all "fuzzy parameter" related widgets
98 myFuzzyChk = new QCheckBox(GroupPoints->GroupBox1);
99 myFuzzyChk->setText(tr("GEOM_USE_FUZZY_PARAMETER"));
100 GroupPoints->gridLayout1->addWidget(myFuzzyChk, 6, 0, 1, 3);
102 myFuzzyLbl = new QLabel(GroupPoints->GroupBox1);
103 myFuzzyLbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
104 myFuzzyLbl->setText(tr("GEOM_FUZZY_PARAMETER"));
105 GroupPoints->gridLayout1->addWidget(myFuzzyLbl, 7, 0, 1, 2);
107 myFuzzyEdt = new SalomeApp_DoubleSpinBox(GroupPoints->GroupBox1);
108 initSpinBox( myFuzzyEdt, 1.e-7, 10.0, DEFAULT_FUZZY_VALUE, "length_tol_precision" );
109 myFuzzyEdt->setValue(DEFAULT_FUZZY_VALUE);
110 GroupPoints->gridLayout1->addWidget(myFuzzyEdt, 7, 2);
112 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
113 layout->setMargin( 0 ); layout->setSpacing( 6 );
114 layout->addWidget( GroupPoints );
116 /***************************************************************/
118 setHelpFileName( "partition_page.html" );
121 mainFrame()->CheckBoxPreview->setChecked( false );
122 mainFrame()->CheckBoxPreview->hide();
128 //=================================================================================
129 // function : ~OperationGUI_PartitionDlg()
130 // purpose : Destroys the object and frees any allocated resources
131 //=================================================================================
132 OperationGUI_PartitionDlg::~OperationGUI_PartitionDlg()
134 // no need to delete child widgets, Qt does it all for us
137 void OperationGUI_PartitionDlg::SetListMaterials( GEOM::ListOfLong ListMaterials )
139 myListMaterials = ListMaterials;
142 GEOM::ListOfLong OperationGUI_PartitionDlg::GetListMaterials()
144 return myListMaterials;
147 //=================================================================================
150 //=================================================================================
151 void OperationGUI_PartitionDlg::Init()
153 /* type for sub-shape selection */
154 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SOLID" ) );
155 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SOLID);
156 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_SHELL" ) );
157 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::SHELL);
158 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_FACE" ) );
159 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::FACE);
160 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_WIRE" ) );
161 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::WIRE);
162 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_EDGE" ) );
163 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::EDGE);
164 GroupPoints->ComboBox1->addItem( tr( "GEOM_RECONSTRUCTION_LIMIT_VERTEX" ) );
165 GroupPoints->ComboBox1->setItemData(GroupPoints->ComboBox1->count()-1, GEOM::VERTEX);
166 GroupPoints->CheckButton1->setChecked( false );
167 mySelfInte->setChecked(false);
169 // Do not use Fuzzy parameter by default
170 myFuzzyChk->setChecked(false);
171 myFuzzyLbl->setEnabled(false);
172 myFuzzyEdt->setEnabled(false);
174 mainFrame()->GroupBoxPublish->show();
176 /* signals and slots connections */
177 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
178 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
180 connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
182 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
183 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
185 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
186 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
188 connect( GroupPoints->ComboBox1, SIGNAL( activated( int ) ), this, SLOT( ComboTextChanged() ) );
190 connect( myGeomGUI->getApp()->selectionMgr(),
191 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
193 connect( GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
194 connect( GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
195 connect( GroupPoints->CheckButton2, SIGNAL(toggled(bool)), mySelfInte, SLOT(setEnabled(bool)) );
196 connect( mySelfInte, SIGNAL(toggled(bool)), this, SLOT(processPreview()) );
198 connect( myFuzzyChk, SIGNAL(stateChanged(int)), this, SLOT(UseFuzzyChanged(int)));
200 mySelfInte->setEnabled(GroupPoints->CheckButton2->isChecked());
201 initName( tr( "GEOM_PARTITION" ) );
203 ConstructorsClicked( 0 );
204 GroupPoints->PushButton1->click();
208 //=================================================================================
209 // function : ConstructorsClicked()
210 // purpose : Radio button management
211 //=================================================================================
212 void OperationGUI_PartitionDlg::ConstructorsClicked( int constructorId )
214 disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
217 switch ( constructorId ) {
218 case 0: /*Full partition */
219 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION" ) );
220 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
221 GroupPoints->TextLabel2->setText( tr( "GEOM_TOOL_OBJECTS" ) );
222 GroupPoints->TextLabel3->show();
223 GroupPoints->ComboBox1->show();
224 GroupPoints->ComboBox1->setCurrentIndex( 0 );
225 GroupPoints->CheckButton1->show();
226 GroupPoints->CheckButton2->show();
228 GroupPoints->PushButton1->setDown( true );
229 GroupPoints->PushButton2->setDown( false );
230 GroupPoints->LineEdit1->setEnabled(true);
231 GroupPoints->LineEdit2->setEnabled(false);
233 case 1: /*Half-space partition */
234 GroupPoints->GroupBox1->setTitle( tr( "GEOM_PARTITION_HALFSPACE" ) );
235 GroupPoints->TextLabel3->hide();
236 GroupPoints->ComboBox1->hide();
237 GroupPoints->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
238 GroupPoints->TextLabel2->setText( tr( "GEOM_PLANE" ) );
239 GroupPoints->CheckButton1->hide();
240 GroupPoints->CheckButton2->hide();
242 GroupPoints->PushButton1->setDown( true );
243 GroupPoints->LineEdit1->setEnabled(true);
247 myEditCurrentArgument = GroupPoints->LineEdit1;
248 GroupPoints->LineEdit1->clear();
249 GroupPoints->LineEdit2->clear();
251 qApp->processEvents();
253 resize( minimumSizeHint() );
255 myEditCurrentArgument->setFocus();
256 connect( myGeomGUI->getApp()->selectionMgr(),
257 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
258 SelectionIntoArgument();
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void OperationGUI_PartitionDlg::ClickOnOk()
268 setIsApplyAndClose( true );
269 if ( ClickOnApply() )
274 //=================================================================================
275 // function : ClickOnApply()
277 //=================================================================================
278 bool OperationGUI_PartitionDlg::ClickOnApply()
284 // 0020854: EDF 1398 GEOM: Ergonomy of Partition GUI window
285 // ConstructorsClicked( getConstructorId() );
290 //=================================================================================
291 // function : UseFuzzyChanged()
292 // purpose : This slot is called whenever the status of CheckButton3 has changed
293 //=================================================================================
294 void OperationGUI_PartitionDlg::UseFuzzyChanged(int state)
296 QCheckBox* send = (QCheckBox*)sender();
298 if (send == myFuzzyChk) {
299 bool isChecked = (state != Qt::Unchecked);
300 myFuzzyLbl->setEnabled(isChecked);
301 myFuzzyEdt->setEnabled(isChecked);
306 //=================================================================================
307 // function : SelectionIntoArgument()
308 // purpose : Called when selection as changed or other case
309 //=================================================================================
310 void OperationGUI_PartitionDlg::SelectionIntoArgument()
312 myEditCurrentArgument->setText( "" );
313 QString aString = "";
315 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
316 SALOME_ListIO aSelList;
317 aSelMgr->selectedObjects(aSelList);
319 int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
321 if ( getConstructorId() == 1 ) {
322 // for half-selection, only one shape can be selected as an object
323 // and only one plane as a tool
325 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
326 myListShapes.length( 0 );
327 // myListMaterials.length( 0 ); // obsolete
330 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
331 myListTools.length( 0 );
338 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
339 myListShapes.length( 0 );
340 //myListMaterials.length( 0 ); // obsolete
343 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
344 myListTools.length( 0 );
350 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
351 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
352 //myListMaterials.length( 0 ); // obsolete
354 GEOM::shape_type type = GEOM::SHAPE;
355 for (int i = 0; i < (int)myListShapes.length(); i++)
356 type = qMin( type, myListShapes[i]->GetMaxShapeType() );
357 int idx = qMax( 0, GroupPoints->ComboBox1->findData( type ) );
358 GroupPoints->ComboBox1->setCurrentIndex( idx );
360 if ( !myListShapes.length() )
363 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
364 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
365 if ( !myListTools.length() )
367 else if ( myListTools.length() == 1 && getConstructorId() == 1 ) {
368 GEOM::GEOM_IMeasureOperations_var mOp = getGeomEngine()->GetIMeasureOperations();
369 GEOM::ListOfLong_var intList;
370 GEOM::ListOfDouble_var dblList;
371 GEOM::GEOM_IKindOfShape::shape_kind kind = mOp->KindOfShape( myListTools[0].in(), intList.out(), dblList.out() );
373 if ( kind < GEOM::GEOM_IKindOfShape::DISK_CIRCLE || kind > GEOM::GEOM_IKindOfShape::PLANAR ) {
374 myListTools.length( 0 );
380 myEditCurrentArgument->setText( aString );
385 //=================================================================================
386 // function : SetEditCurrentArgument()
388 //=================================================================================
389 void OperationGUI_PartitionDlg::SetEditCurrentArgument()
391 QPushButton* send = (QPushButton*)sender();
393 if ( send == GroupPoints->PushButton1 ) {
394 myEditCurrentArgument = GroupPoints->LineEdit1;
395 GroupPoints->PushButton2->setDown(false);
396 GroupPoints->LineEdit1->setEnabled(true);
397 GroupPoints->LineEdit2->setEnabled(false);
399 else if ( send == GroupPoints->PushButton2 ) {
400 myGeomGUI->getApp()->selectionMgr()->clearSelected(); //clear prewious selection
401 myEditCurrentArgument = GroupPoints->LineEdit2;
402 GroupPoints->PushButton1->setDown(false);
403 GroupPoints->LineEdit1->setEnabled(false);
404 GroupPoints->LineEdit2->setEnabled(true);
405 if ( getConstructorId() == 1 )
406 globalSelection( GEOM_PLANE );
409 globalSelection( GEOM_ALLSHAPES );
411 myEditCurrentArgument->setFocus();
412 SelectionIntoArgument();
418 //=================================================================================
419 // function : LineEditReturnPressed()
421 //=================================================================================
422 void OperationGUI_PartitionDlg::LineEditReturnPressed()
424 QLineEdit* send = (QLineEdit*)sender();
426 if ( send == GroupPoints->LineEdit1 ||
427 send == GroupPoints->LineEdit2 ) {
428 myEditCurrentArgument = send;
429 GEOMBase_Skeleton::LineEditReturnPressed();
434 //=================================================================================
435 // function : ActivateThisDialog()
437 //=================================================================================
438 void OperationGUI_PartitionDlg::ActivateThisDialog()
440 GEOMBase_Skeleton::ActivateThisDialog();
441 connect( myGeomGUI->getApp()->selectionMgr(),
442 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
444 ConstructorsClicked( getConstructorId() );
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void OperationGUI_PartitionDlg::enterEvent( QEvent* )
455 if ( !mainFrame()->GroupConstructors->isEnabled() )
456 this->ActivateThisDialog();
460 //=================================================================================
461 // function : createOperation
463 //=================================================================================
464 GEOM::GEOM_IOperations_ptr OperationGUI_PartitionDlg::createOperation()
466 return getGeomEngine()->GetIBooleanOperations();
470 //=================================================================================
471 // function : isValid
473 //=================================================================================
474 bool OperationGUI_PartitionDlg::isValid (QString& )
476 return (getConstructorId() == 0 ?
477 myListShapes.length() :
478 myListShapes.length() && myListTools.length());
482 //=================================================================================
483 // function : execute
485 //=================================================================================
486 bool OperationGUI_PartitionDlg::execute (ObjectList& objects)
489 GEOM::GEOM_Object_var anObj;
491 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
493 bool useFuzzyParam = myFuzzyChk->isChecked();
494 double aFuzzyParam = (useFuzzyParam ? myFuzzyEdt->value() : -1.0);
496 switch ( getConstructorId() ) {
499 bool isDetectSelfInte = mySelfInte->isChecked();
500 int aLimit = GetLimit();
501 int aKeepNonlimitShapes = GroupPoints->CheckButton1->isChecked();
502 bool aNoSelfIntersection = GroupPoints->CheckButton2->isChecked();
504 anObj = aNoSelfIntersection ?
505 anOper->MakePartitionNonSelfIntersectedShapeWithFuzzy(myListShapes, myListTools,
506 myListKeepInside, myListRemoveInside,
507 aLimit, false, myListMaterials, aKeepNonlimitShapes,
508 isDetectSelfInte, aFuzzyParam) :
509 anOper->MakePartitionWithFuzzy(myListShapes, myListTools,
510 myListKeepInside, myListRemoveInside,
511 aLimit, false, myListMaterials, aKeepNonlimitShapes, aFuzzyParam);
517 anObj = anOper->MakeHalfPartitionWithFuzzy(myListShapes[0].in(), myListTools[0].in(), aFuzzyParam);
523 if ( !anObj->_is_nil() ) {
525 GEOMBase::GetShape( anObj, aShape, TopAbs_SHAPE );
526 TopoDS_Iterator It( aShape, Standard_True, Standard_True );
528 for (; It.More(); It.Next())
532 objects.push_back( anObj._retn() );
534 SUIT_MessageBox::warning( this,
535 QObject::tr( "GEOM_ERROR" ),
536 QObject::tr( "GEOM_WRN_PARTITION_RESULT_EMPTY" ) );
542 //=================================================================================
543 // function : restoreSubShapes
545 //=================================================================================
546 void OperationGUI_PartitionDlg::restoreSubShapes( SALOMEDS::SObject_ptr theSObject )
548 if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
549 // empty list of arguments means that all arguments should be restored
550 getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
551 /*theFindMethod=*/GEOM::FSM_GetInPlaceByHistory,
552 /*theInheritFirstArg=*/myListShapes.length() == 1 && myListTools.length() == 0,
553 mainFrame()->CheckBoxAddPrefix->isChecked() ); // ? false
557 //=======================================================================
558 //function : ComboTextChanged
560 //=======================================================================
561 void OperationGUI_PartitionDlg::ComboTextChanged()
566 //=================================================================================
567 // function : GetLimit()
569 //=================================================================================
570 int OperationGUI_PartitionDlg::GetLimit() const
572 int aLimit = GroupPoints->ComboBox1->currentIndex();
575 case 0: aLimit = GEOM::SOLID ; break;
576 case 1: aLimit = GEOM::SHELL ; break;
577 case 2: aLimit = GEOM::FACE ; break;
578 case 3: aLimit = GEOM::WIRE ; break;
579 case 4: aLimit = GEOM::EDGE ; break;
580 case 5: aLimit = GEOM::VERTEX; break;
581 default: aLimit = GEOM::SHAPE ;
587 //=================================================================================
588 // function : getSourceObjects
589 // purpose : virtual method to get source objects
590 //=================================================================================
591 QList<GEOM::GeomObjPtr> OperationGUI_PartitionDlg::getSourceObjects()
593 QList<GEOM::GeomObjPtr> res;
594 for (int i = 0; i < (int)myListShapes.length(); i++) {
595 GEOM::GeomObjPtr aGeomObjPtr(myListShapes[i]);
598 for (int i = 0; i < (int)myListTools.length(); i++) {
599 GEOM::GeomObjPtr aGeomObjPtr(myListTools[i]);
602 for (int i = 0; i < (int)myListRemoveInside.length(); i++) {
603 GEOM::GeomObjPtr aGeomObjPtr(myListRemoveInside[i]);
606 for (int i = 0; i < (int)myListKeepInside.length(); i++) {
607 GEOM::GeomObjPtr aGeomObjPtr(myListKeepInside[i]);