1 // Copyright (C) 2007-2022 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, 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 //=================================================================================
45 // class : BooleanGUI_Dialog()
46 // purpose : Constructs a BooleanGUI_Dialog 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 BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
52 QWidget* parent, bool modal, Qt::WindowFlags fl)
53 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
54 myOperation(theOperation)
57 QString aTitle, aCaption;
58 switch (myOperation) {
59 case BooleanGUI::COMMON:
60 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
61 aTitle = tr("GEOM_COMMON");
62 aCaption = tr("GEOM_COMMON_TITLE");
63 setHelpFileName("common_operation_page.html");
66 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
67 aTitle = tr("GEOM_CUT");
68 aCaption = tr("GEOM_CUT_TITLE");
69 setHelpFileName("cut_operation_page.html");
71 case BooleanGUI::FUSE:
72 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
73 aTitle = tr("GEOM_FUSE");
74 aCaption = tr("GEOM_FUSE_TITLE");
75 setHelpFileName("fuse_operation_page.html");
77 case BooleanGUI::SECTION:
78 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
79 aTitle = tr("GEOM_SECTION");
80 aCaption = tr("GEOM_SECTION_TITLE");
81 setHelpFileName("section_opeartion_page.html");
84 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
86 setWindowTitle(aCaption);
88 /***************************************************************/
89 mainFrame()->GroupConstructors->setTitle(aTitle);
90 mainFrame()->RadioButton1->setIcon(image0);
91 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
92 mainFrame()->RadioButton2->close();
93 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
94 mainFrame()->RadioButton3->close();
96 myGroup = new DlgRef_2Sel2Spin3Check(centralWidget());
98 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
99 if (myOperation == BooleanGUI::CUT) {
100 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
101 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECTS"));
103 else if (myOperation == BooleanGUI::SECTION) {
104 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
105 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
106 } else { // Fuse or Common
107 myGroup->TextLabel1->setText(tr( "GEOM_SELECTED_OBJECTS" ));
108 myGroup->TextLabel2->hide();
109 myGroup->PushButton2->hide();
110 myGroup->LineEdit2->hide();
112 if (myOperation == BooleanGUI::FUSE) {
113 myGroup->CheckBox2->setText(tr("GEOM_BOOL_REMOVE_EXTRA_EDGES"));
117 myGroup->PushButton1->setIcon(image1);
118 myGroup->LineEdit1->setReadOnly(true);
120 if (myOperation != BooleanGUI::FUSE) {
121 myGroup->CheckBox2->hide();
123 if (myOperation != BooleanGUI::COMMON) {
124 myGroup->PushButton2->setIcon(image1);
125 myGroup->LineEdit2->setReadOnly(true);
129 myGroup->TextLabel3->hide();
130 myGroup->TextLabel4->hide();
131 myGroup->SpinBox_DX->hide();
132 myGroup->SpinBox_DY->hide();
133 myGroup->CheckBox3->hide();
134 myGroup->CheckBox1->setText(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
136 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
137 layout->setMargin(0); layout->setSpacing(6);
138 layout->addWidget(myGroup);
139 /***************************************************************/
142 mainFrame()->CheckBoxPreview->setChecked( false );
143 mainFrame()->CheckBoxPreview->hide();
149 //=================================================================================
150 // function : ~BooleanGUI_Dialog()
151 // purpose : Destroys the object and frees any allocated resources
152 //=================================================================================
153 BooleanGUI_Dialog::~BooleanGUI_Dialog()
157 //=================================================================================
160 //=================================================================================
161 void BooleanGUI_Dialog::Init()
163 mainFrame()->GroupBoxPublish->show();
166 myEditCurrentArgument = myGroup->LineEdit1;
168 myGroup->LineEdit1->setText("");
169 myGroup->LineEdit2->setText("");
170 myGroup->CheckBox1->setChecked(true);
172 if (myOperation == BooleanGUI::FUSE) {
173 myGroup->CheckBox2->setChecked(true);
179 // signals and slots connections
180 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
181 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
183 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
185 if (!myGroup->PushButton2->isHidden()) {
186 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
189 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
190 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()), Qt::UniqueConnection);
192 initName(mainFrame()->GroupConstructors->title());
194 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
195 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
196 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
198 mainFrame()->RadioButton1->setFocus();
200 globalSelection(GEOM_ALLSHAPES);
201 //localSelection(TopAbs_SHAPE); // VSR 24/09/2015: deactivate local selection in BOP (CoTech decision)
203 myGroup->PushButton1->click();
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void BooleanGUI_Dialog::ClickOnOk()
213 setIsApplyAndClose( true );
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 bool BooleanGUI_Dialog::ClickOnApply()
228 // activate selection and connect selection manager
229 myGroup->PushButton1->click();
233 //=================================================================================
234 // function : reset()
236 //=================================================================================
237 void BooleanGUI_Dialog::reset()
242 //=================================================================================
243 // function : singleSelection
244 // purpose : Performs single selection. Called from SelectionIntoArgument()
245 //=================================================================================
246 void BooleanGUI_Dialog::singleSelection()
248 myEditCurrentArgument->setText("");
250 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
252 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
253 QString aName = GEOMBase::GetName( aSelectedObject.get() );
254 myEditCurrentArgument->setText( aName );
257 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
258 myGeomGUI->getApp()->selectionMgr()->clearSelected();
259 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
260 this, SLOT(SelectionIntoArgument()), Qt::UniqueConnection);
262 if (myEditCurrentArgument == myGroup->LineEdit1) {
263 myObject1 = aSelectedObject;
264 if (!myGroup->PushButton2->isHidden() && !myObjects.count())
265 myGroup->PushButton2->click();
267 else if (myEditCurrentArgument == myGroup->LineEdit2) {
269 myObjects << aSelectedObject;
271 myGroup->PushButton1->click();
275 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
276 else if (myEditCurrentArgument == myGroup->LineEdit2) reset();
280 //=================================================================================
281 // function : multipleSelection
282 // purpose : Performs multiple selection. Called from SelectionIntoArgument()
283 //=================================================================================
284 void BooleanGUI_Dialog::multipleSelection()
286 myEditCurrentArgument->setText( "" );
289 myObjects = getSelected( TopAbs_SHAPE, -1 );
291 int i = myObjects.count();
293 myEditCurrentArgument->setText( GEOMBase::GetName( myObjects.first().get() ) );
294 } else if ( i > 0 ) {
295 myEditCurrentArgument->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
299 //=================================================================================
300 // function : SelectionIntoArgument()
301 // purpose : Called when selection is changed or on dialog initialization or activation
302 //=================================================================================
303 void BooleanGUI_Dialog::SelectionIntoArgument()
305 myEditCurrentArgument->setText("");
306 if ( myOperation == BooleanGUI::SECTION ||
307 (myOperation == BooleanGUI::CUT &&
308 myEditCurrentArgument == myGroup->LineEdit1)) {
317 //=================================================================================
318 // function : SetEditCurrentArgument()
320 //=================================================================================
321 void BooleanGUI_Dialog::SetEditCurrentArgument()
323 QPushButton* send = (QPushButton*)sender();
325 if (send == myGroup->PushButton1) {
326 myEditCurrentArgument = myGroup->LineEdit1;
328 if (!myGroup->PushButton2->isHidden()) {
329 myGroup->PushButton2->setDown(false);
330 myGroup->LineEdit2->setEnabled(false);
333 else if (send == myGroup->PushButton2) {
334 myEditCurrentArgument = myGroup->LineEdit2;
336 myGroup->PushButton1->setDown(false);
337 myGroup->LineEdit1->setEnabled(false);
340 globalSelection(GEOM_ALLSHAPES);
341 //localSelection(TopAbs_SHAPE); // VSR 24/09/2015: deactivate local selection in BOP (CoTech decision)
344 myEditCurrentArgument->setEnabled(true);
345 myEditCurrentArgument->setFocus();
346 // after setFocus(), because it will be setDown(false) when loses focus
349 SelectionIntoArgument();
352 //=================================================================================
353 // function : ActivateThisDialog()
355 //=================================================================================
356 void BooleanGUI_Dialog::ActivateThisDialog()
358 GEOMBase_Skeleton::ActivateThisDialog();
360 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
361 this, SLOT( SelectionIntoArgument() ), Qt::UniqueConnection );
365 //=================================================================================
366 // function : enterEvent()
367 // purpose : when mouse enter onto the QWidget
368 //=================================================================================
369 void BooleanGUI_Dialog::enterEvent (QEvent*)
371 if (!mainFrame()->GroupConstructors->isEnabled())
372 ActivateThisDialog();
375 //=================================================================================
376 // function : createOperation
378 //=================================================================================
379 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
381 return getGeomEngine()->GetIBooleanOperations();
384 //=================================================================================
385 // function : isValid
387 //=================================================================================
388 bool BooleanGUI_Dialog::isValid (QString&)
392 switch (myOperation) {
393 case BooleanGUI::FUSE:
394 case BooleanGUI::COMMON:
395 isOK = myObjects.count() > 1;
397 case BooleanGUI::CUT:
398 isOK = myObject1 && myObjects.count();
400 case BooleanGUI::SECTION:
401 isOK = myObject1 && (myObjects.count() == 1);
410 //=================================================================================
411 // function : execute
413 //=================================================================================
414 bool BooleanGUI_Dialog::execute (ObjectList& objects)
416 GEOM::GEOM_Object_var anObj;
418 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
419 const bool isCheckSelfInte = myGroup->CheckBox1->isChecked();
421 GEOM::ListOfGO_var anObjects = new GEOM::ListOfGO();
422 anObjects->length( myObjects.count() );
423 for ( int i = 0; i < myObjects.count(); i++ )
424 anObjects[i] = myObjects[i].copy();
426 switch (myOperation) {
427 case BooleanGUI::FUSE:
429 const bool isRmExtraEdges = myGroup->CheckBox2->isChecked();
431 anObj = anOper->MakeFuseList
432 (anObjects, isCheckSelfInte, isRmExtraEdges);
435 case BooleanGUI::COMMON:
436 anObj = anOper->MakeCommonList(anObjects, isCheckSelfInte);
438 case BooleanGUI::CUT:
440 anOper->MakeCutList(myObject1.get(), anObjects, isCheckSelfInte);
442 case BooleanGUI::SECTION:
443 anObj = anOper->MakeBoolean
444 (myObject1.get(), anObjects[0], myOperation, isCheckSelfInte);
450 if (!anObj->_is_nil())
451 objects.push_back(anObj._retn());
456 //=================================================================================
457 // function : restoreSubShapes
459 //=================================================================================
460 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::SObject_ptr theSObject)
462 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
463 // empty list of arguments means that all arguments should be restored
464 getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
465 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
466 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
467 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false
471 //=================================================================================
472 // function : addSubshapesToStudy
473 // purpose : virtual method to add new SubObjects if local selection
474 //=================================================================================
475 void BooleanGUI_Dialog::addSubshapesToStudy()
477 GEOMBase::PublishSubObject( myObject1.get() );
478 for ( int i = 0; i < myObjects.count(); i++ )
479 GEOMBase::PublishSubObject( myObjects[i].get() );
482 //=================================================================================
483 // function : getSourceObjects
484 // purpose : virtual method to get source objects
485 //=================================================================================
486 QList<GEOM::GeomObjPtr> BooleanGUI_Dialog::getSourceObjects()
488 QList<GEOM::GeomObjPtr> res(myObjects);