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 : BooleanGUI_Dialog.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "BooleanGUI.h"
28 #include "BooleanGUI_Dialog.h"
31 #include <GeometryGUI.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SALOME_ListIO.hxx>
40 // VSR 22/08/2012: issue 0021787: remove "Preview" button from BOP and Partition operations
41 // Comment next line to enable preview in BOP dialog box
44 #define DEFAULT_FUZZY_VALUE 1e-5
47 //=================================================================================
48 // class : BooleanGUI_Dialog()
49 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
50 // name 'name' and widget flags set to 'f'.
51 // The dialog will by default be modeless, unless you set 'modal' to
52 // TRUE to construct a modal dialog.
53 //=================================================================================
54 BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
55 QWidget* parent, bool modal, Qt::WindowFlags fl)
56 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
57 myOperation(theOperation)
60 QString aTitle, aCaption;
61 switch (myOperation) {
62 case BooleanGUI::COMMON:
63 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
64 aTitle = tr("GEOM_COMMON");
65 aCaption = tr("GEOM_COMMON_TITLE");
66 setHelpFileName("common_operation_page.html");
69 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
70 aTitle = tr("GEOM_CUT");
71 aCaption = tr("GEOM_CUT_TITLE");
72 setHelpFileName("cut_operation_page.html");
74 case BooleanGUI::FUSE:
75 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
76 aTitle = tr("GEOM_FUSE");
77 aCaption = tr("GEOM_FUSE_TITLE");
78 setHelpFileName("fuse_operation_page.html");
80 case BooleanGUI::SECTION:
81 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
82 aTitle = tr("GEOM_SECTION");
83 aCaption = tr("GEOM_SECTION_TITLE");
84 setHelpFileName("section_operation_page.html");
87 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
89 setWindowTitle(aCaption);
91 /***************************************************************/
92 mainFrame()->GroupConstructors->setTitle(aTitle);
93 mainFrame()->RadioButton1->setIcon(image0);
94 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
95 mainFrame()->RadioButton2->close();
96 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
97 mainFrame()->RadioButton3->close();
99 myGroup = new DlgRef_2Sel2Spin3Check(centralWidget());
101 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
102 if (myOperation == BooleanGUI::CUT) {
103 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
104 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECTS"));
106 else if (myOperation == BooleanGUI::SECTION) {
107 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
108 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
109 } else { // Fuse or Common
110 myGroup->TextLabel1->setText(tr( "GEOM_SELECTED_OBJECTS" ));
111 myGroup->TextLabel2->hide();
112 myGroup->PushButton2->hide();
113 myGroup->LineEdit2->hide();
115 if (myOperation == BooleanGUI::FUSE) {
116 myGroup->CheckBox2->setText(tr("GEOM_BOOL_REMOVE_EXTRA_EDGES"));
120 myGroup->PushButton1->setIcon(image1);
121 myGroup->LineEdit1->setReadOnly(true);
123 if (myOperation != BooleanGUI::FUSE) {
124 myGroup->CheckBox2->hide();
126 if (myOperation != BooleanGUI::COMMON) {
127 myGroup->PushButton2->setIcon(image1);
128 myGroup->LineEdit2->setReadOnly(true);
132 myGroup->TextLabel3->hide();
133 myGroup->TextLabel4->hide();
134 myGroup->SpinBox_DX->hide();
135 myGroup->SpinBox_DY->hide();
136 myGroup->CheckBox1->setText(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
138 // Add all "fuzzy parameter" related widgets
139 myGroup->CheckBox3->setText(tr("GEOM_USE_FUZZY_PARAMETER"));
141 myFuzzyLbl = new QLabel(myGroup->GroupBox1);
142 myFuzzyLbl->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
143 myFuzzyLbl->setText(tr("GEOM_FUZZY_PARAMETER"));
144 myGroup->gridLayout1->addWidget(myFuzzyLbl, 7, 0, 1, 2);
146 myFuzzyEdt = new SalomeApp_DoubleSpinBox(myGroup->GroupBox1);
147 initSpinBox( myFuzzyEdt, 1.e-7, 10.0, DEFAULT_FUZZY_VALUE, "length_tol_precision" );
148 myFuzzyEdt->setValue(DEFAULT_FUZZY_VALUE);
149 myGroup->gridLayout1->addWidget(myFuzzyEdt, 7, 2);
151 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
152 layout->setMargin(0); layout->setSpacing(6);
153 layout->addWidget(myGroup);
154 /***************************************************************/
157 mainFrame()->CheckBoxPreview->setChecked( false );
158 mainFrame()->CheckBoxPreview->hide();
164 //=================================================================================
165 // function : ~BooleanGUI_Dialog()
166 // purpose : Destroys the object and frees any allocated resources
167 //=================================================================================
168 BooleanGUI_Dialog::~BooleanGUI_Dialog()
172 //=================================================================================
175 //=================================================================================
176 void BooleanGUI_Dialog::Init()
178 mainFrame()->GroupBoxPublish->show();
181 myEditCurrentArgument = myGroup->LineEdit1;
183 myGroup->LineEdit1->setText("");
184 myGroup->LineEdit2->setText("");
185 myGroup->CheckBox1->setChecked(true);
187 if (myOperation == BooleanGUI::FUSE) {
188 myGroup->CheckBox2->setChecked(true);
191 // Do not use Fuzzy parameter by default
192 myGroup->CheckBox3->setChecked(false);
193 myFuzzyLbl->setEnabled(false);
194 myFuzzyEdt->setEnabled(false);
199 // signals and slots connections
200 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
201 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
203 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
205 if (!myGroup->PushButton2->isHidden()) {
206 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
209 if (!myGroup->CheckBox3->isHidden()) {
210 connect(myGroup->CheckBox3, SIGNAL(stateChanged(int)), this, SLOT(UseFuzzyChanged(int)));
213 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
214 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()), Qt::UniqueConnection);
216 initName(mainFrame()->GroupConstructors->title());
218 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
219 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
220 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
222 mainFrame()->RadioButton1->setFocus();
224 globalSelection(GEOM_ALLSHAPES);
225 //localSelection(TopAbs_SHAPE); // VSR 24/09/2015: deactivate local selection in BOP (CoTech decision)
227 myGroup->PushButton1->click();
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void BooleanGUI_Dialog::ClickOnOk()
237 setIsApplyAndClose( true );
242 //=================================================================================
243 // function : ClickOnApply()
245 //=================================================================================
246 bool BooleanGUI_Dialog::ClickOnApply()
252 // activate selection and connect selection manager
253 myGroup->PushButton1->click();
257 //=================================================================================
258 // function : reset()
260 //=================================================================================
261 void BooleanGUI_Dialog::reset()
266 //=================================================================================
267 // function : singleSelection
268 // purpose : Performs single selection. Called from SelectionIntoArgument()
269 //=================================================================================
270 void BooleanGUI_Dialog::singleSelection()
272 myEditCurrentArgument->setText("");
274 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
276 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
277 QString aName = GEOMBase::GetName( aSelectedObject.get() );
278 myEditCurrentArgument->setText( aName );
281 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
282 myGeomGUI->getApp()->selectionMgr()->clearSelected();
283 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
284 this, SLOT(SelectionIntoArgument()), Qt::UniqueConnection);
286 if (myEditCurrentArgument == myGroup->LineEdit1) {
287 myObject1 = aSelectedObject;
288 if (!myGroup->PushButton2->isHidden() && !myObjects.count())
289 myGroup->PushButton2->click();
291 else if (myEditCurrentArgument == myGroup->LineEdit2) {
293 myObjects << aSelectedObject;
295 myGroup->PushButton1->click();
299 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
300 else if (myEditCurrentArgument == myGroup->LineEdit2) reset();
304 //=================================================================================
305 // function : multipleSelection
306 // purpose : Performs multiple selection. Called from SelectionIntoArgument()
307 //=================================================================================
308 void BooleanGUI_Dialog::multipleSelection()
310 myEditCurrentArgument->setText( "" );
313 myObjects = getSelected( TopAbs_SHAPE, -1 );
315 int i = myObjects.count();
317 myEditCurrentArgument->setText( GEOMBase::GetName( myObjects.first().get() ) );
318 } else if ( i > 0 ) {
319 myEditCurrentArgument->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
323 //=================================================================================
324 // function : SelectionIntoArgument()
325 // purpose : Called when selection is changed or on dialog initialization or activation
326 //=================================================================================
327 void BooleanGUI_Dialog::SelectionIntoArgument()
329 myEditCurrentArgument->setText("");
330 if ( myOperation == BooleanGUI::SECTION ||
331 (myOperation == BooleanGUI::CUT &&
332 myEditCurrentArgument == myGroup->LineEdit1)) {
341 //=================================================================================
342 // function : UseFuzzyChanged()
343 // purpose : This slot is called whenever the status of CheckButton3 has changed
344 //=================================================================================
345 void BooleanGUI_Dialog::UseFuzzyChanged(int state)
347 QCheckBox* send = (QCheckBox*)sender();
349 if (send == myGroup->CheckBox3) {
350 bool isChecked = (state != Qt::Unchecked);
351 myFuzzyLbl->setEnabled(isChecked);
352 myFuzzyEdt->setEnabled(isChecked);
356 //=================================================================================
357 // function : SetEditCurrentArgument()
359 //=================================================================================
360 void BooleanGUI_Dialog::SetEditCurrentArgument()
362 QPushButton* send = (QPushButton*)sender();
364 if (send == myGroup->PushButton1) {
365 myEditCurrentArgument = myGroup->LineEdit1;
367 if (!myGroup->PushButton2->isHidden()) {
368 myGroup->PushButton2->setDown(false);
369 myGroup->LineEdit2->setEnabled(false);
372 else if (send == myGroup->PushButton2) {
373 myEditCurrentArgument = myGroup->LineEdit2;
375 myGroup->PushButton1->setDown(false);
376 myGroup->LineEdit1->setEnabled(false);
379 globalSelection(GEOM_ALLSHAPES);
380 //localSelection(TopAbs_SHAPE); // VSR 24/09/2015: deactivate local selection in BOP (CoTech decision)
383 myEditCurrentArgument->setEnabled(true);
384 myEditCurrentArgument->setFocus();
385 // after setFocus(), because it will be setDown(false) when loses focus
388 SelectionIntoArgument();
391 //=================================================================================
392 // function : ActivateThisDialog()
394 //=================================================================================
395 void BooleanGUI_Dialog::ActivateThisDialog()
397 GEOMBase_Skeleton::ActivateThisDialog();
399 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
400 this, SLOT( SelectionIntoArgument() ), Qt::UniqueConnection );
404 //=================================================================================
405 // function : enterEvent()
406 // purpose : when mouse enter onto the QWidget
407 //=================================================================================
408 void BooleanGUI_Dialog::enterEvent (QEvent*)
410 if (!mainFrame()->GroupConstructors->isEnabled())
411 ActivateThisDialog();
414 //=================================================================================
415 // function : createOperation
417 //=================================================================================
418 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
420 return getGeomEngine()->GetIBooleanOperations();
423 //=================================================================================
424 // function : isValid
426 //=================================================================================
427 bool BooleanGUI_Dialog::isValid (QString&)
431 switch (myOperation) {
432 case BooleanGUI::FUSE:
433 case BooleanGUI::COMMON:
434 isOK = myObjects.count() > 1;
436 case BooleanGUI::CUT:
437 isOK = myObject1 && myObjects.count();
439 case BooleanGUI::SECTION:
440 isOK = myObject1 && (myObjects.count() == 1);
449 //=================================================================================
450 // function : execute
452 //=================================================================================
453 bool BooleanGUI_Dialog::execute (ObjectList& objects)
455 GEOM::GEOM_Object_var anObj;
457 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
458 const bool isCheckSelfInte = myGroup->CheckBox1->isChecked();
459 const bool useFuzzyParam = myGroup->CheckBox3->isChecked();
460 const double fuzzyValue = (useFuzzyParam ? myFuzzyEdt->value() : -1);
462 GEOM::ListOfGO_var anObjects = new GEOM::ListOfGO();
463 anObjects->length( myObjects.count() );
464 for ( int i = 0; i < myObjects.count(); i++ )
465 anObjects[i] = myObjects[i].copy();
467 switch (myOperation) {
468 case BooleanGUI::FUSE:
470 const bool isRmExtraEdges = myGroup->CheckBox2->isChecked();
471 anObj = anOper->MakeFuseListWithFuzzy(anObjects, isCheckSelfInte, isRmExtraEdges, fuzzyValue);
474 case BooleanGUI::COMMON:
475 anObj = anOper->MakeCommonListWithFuzzy(anObjects, isCheckSelfInte, fuzzyValue);
477 case BooleanGUI::CUT:
478 anObj = anOper->MakeCutListWithFuzzy(myObject1.get(), anObjects, isCheckSelfInte, fuzzyValue);
480 case BooleanGUI::SECTION:
481 anObj = anOper->MakeBooleanWithFuzzy(myObject1.get(), anObjects[0], myOperation, isCheckSelfInte, fuzzyValue);
487 if (!anObj->_is_nil())
488 objects.push_back(anObj._retn());
493 //=================================================================================
494 // function : restoreSubShapes
496 //=================================================================================
497 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::SObject_ptr theSObject)
499 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
500 // empty list of arguments means that all arguments should be restored
501 getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
502 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
503 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
504 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false
508 //=================================================================================
509 // function : addSubshapesToStudy
510 // purpose : virtual method to add new SubObjects if local selection
511 //=================================================================================
512 void BooleanGUI_Dialog::addSubshapesToStudy()
514 GEOMBase::PublishSubObject( myObject1.get() );
515 for ( int i = 0; i < myObjects.count(); i++ )
516 GEOMBase::PublishSubObject( myObjects[i].get() );
519 //=================================================================================
520 // function : getSourceObjects
521 // purpose : virtual method to get source objects
522 //=================================================================================
523 QList<GEOM::GeomObjPtr> BooleanGUI_Dialog::getSourceObjects()
525 QList<GEOM::GeomObjPtr> res(myObjects);