1 // Copyright (C) 2007-2013 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 : 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_ListIteratorOfListIO.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_2Sel2Spin1Check(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();
113 myGroup->PushButton1->setIcon(image1);
114 myGroup->LineEdit1->setReadOnly(true);
116 if (myOperation != BooleanGUI::FUSE && myOperation != BooleanGUI::COMMON) {
117 myGroup->PushButton2->setIcon(image1);
118 myGroup->LineEdit2->setReadOnly(true);
121 myGroup->TextLabel3->hide();
122 myGroup->TextLabel4->hide();
123 myGroup->SpinBox_DX->hide();
124 myGroup->SpinBox_DY->hide();
125 myGroup->CheckButton1->setText(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
127 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
128 layout->setMargin(0); layout->setSpacing(6);
129 layout->addWidget(myGroup);
130 /***************************************************************/
133 mainFrame()->CheckBoxPreview->setChecked( false );
134 mainFrame()->CheckBoxPreview->hide();
140 //=================================================================================
141 // function : ~BooleanGUI_Dialog()
142 // purpose : Destroys the object and frees any allocated resources
143 //=================================================================================
144 BooleanGUI_Dialog::~BooleanGUI_Dialog()
148 //=================================================================================
151 //=================================================================================
152 void BooleanGUI_Dialog::Init()
154 mainFrame()->GroupBoxPublish->show();
157 myEditCurrentArgument = myGroup->LineEdit1;
159 myGroup->LineEdit1->setText("");
160 myGroup->LineEdit2->setText("");
161 myGroup->CheckButton1->setChecked(true);
165 // signals and slots connections
166 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
167 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
169 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
171 if (!myGroup->PushButton2->isHidden()) {
172 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
175 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
176 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
178 initName(mainFrame()->GroupConstructors->title());
180 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
181 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
182 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
184 mainFrame()->RadioButton1->setFocus();
186 globalSelection(GEOM_ALLSHAPES);
188 myGroup->PushButton1->click();
189 SelectionIntoArgument();
193 //=================================================================================
194 // function : ClickOnOk()
196 //=================================================================================
197 void BooleanGUI_Dialog::ClickOnOk()
199 setIsApplyAndClose( true );
204 //=================================================================================
205 // function : ClickOnApply()
207 //=================================================================================
208 bool BooleanGUI_Dialog::ClickOnApply()
214 // activate selection and connect selection manager
215 myGroup->PushButton1->click();
219 //=================================================================================
220 // function : reset()
222 //=================================================================================
223 void BooleanGUI_Dialog::reset()
225 myObjects = new GEOM::ListOfGO;
226 myObjects->length( 0 );
229 //=================================================================================
230 // function : singleSelection
231 // purpose : Performs single selection. Called from SelectionIntoArgument()
232 //=================================================================================
233 void BooleanGUI_Dialog::singleSelection()
235 myEditCurrentArgument->setText("");
237 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
239 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
240 QString aName = GEOMBase::GetName( aSelectedObject.get() );
241 myEditCurrentArgument->setText( aName );
244 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
245 myGeomGUI->getApp()->selectionMgr()->clearSelected();
246 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
247 this, SLOT(SelectionIntoArgument()));
249 if (myEditCurrentArgument == myGroup->LineEdit1) {
250 myObject1 = aSelectedObject;
251 if (!myGroup->PushButton2->isHidden() && !myObjects->length())
252 myGroup->PushButton2->click();
254 else if (myEditCurrentArgument == myGroup->LineEdit2) {
255 myObjects->length(1);
256 myObjects[0] = aSelectedObject.get();
258 myGroup->PushButton1->click();
262 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
263 else if (myEditCurrentArgument == myGroup->LineEdit2) reset();
267 //=================================================================================
268 // function : multipleSelection
269 // purpose : Performs multiple selection. Called from SelectionIntoArgument()
270 //=================================================================================
271 void BooleanGUI_Dialog::multipleSelection()
273 myEditCurrentArgument->setText( "" );
276 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
277 SALOME_ListIO aSelList;
278 aSelMgr->selectedObjects(aSelList);
279 myObjects->length(aSelList.Extent());
282 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
283 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
285 if ( !CORBA::is_nil( aSelectedObject ) ) {
286 myObjects[i++] = aSelectedObject;
290 myObjects->length( i );
292 myEditCurrentArgument->setText( GEOMBase::GetName( myObjects[0] ) );
293 } else if ( i > 0 ) {
294 myEditCurrentArgument->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
298 //=================================================================================
299 // function : SelectionIntoArgument()
300 // purpose : Called when selection is changed or on dialog initialization or activation
301 //=================================================================================
302 void BooleanGUI_Dialog::SelectionIntoArgument()
304 if ( myOperation == BooleanGUI::SECTION ||
305 (myOperation == BooleanGUI::CUT &&
306 myEditCurrentArgument == myGroup->LineEdit1)) {
315 //=================================================================================
316 // function : SetEditCurrentArgument()
318 //=================================================================================
319 void BooleanGUI_Dialog::SetEditCurrentArgument()
321 QPushButton* send = (QPushButton*)sender();
323 if (send == myGroup->PushButton1) {
324 myEditCurrentArgument = myGroup->LineEdit1;
326 if (!myGroup->PushButton2->isHidden()) {
327 myGroup->PushButton2->setDown(false);
328 myGroup->LineEdit2->setEnabled(false);
331 else if (send == myGroup->PushButton2) {
332 myEditCurrentArgument = myGroup->LineEdit2;
334 myGroup->PushButton1->setDown(false);
335 myGroup->LineEdit1->setEnabled(false);
339 myEditCurrentArgument->setEnabled(true);
340 myEditCurrentArgument->setFocus();
341 // after setFocus(), because it will be setDown(false) when loses focus
345 //=================================================================================
346 // function : ActivateThisDialog()
348 //=================================================================================
349 void BooleanGUI_Dialog::ActivateThisDialog()
351 GEOMBase_Skeleton::ActivateThisDialog();
353 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
354 this, SLOT( SelectionIntoArgument() ) );
358 //=================================================================================
359 // function : enterEvent()
360 // purpose : when mouse enter onto the QWidget
361 //=================================================================================
362 void BooleanGUI_Dialog::enterEvent (QEvent*)
364 if (!mainFrame()->GroupConstructors->isEnabled())
365 ActivateThisDialog();
368 //=================================================================================
369 // function : createOperation
371 //=================================================================================
372 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
374 return getGeomEngine()->GetIBooleanOperations(getStudyId());
377 //=================================================================================
378 // function : isValid
380 //=================================================================================
381 bool BooleanGUI_Dialog::isValid (QString&)
385 switch (myOperation) {
386 case BooleanGUI::FUSE:
387 case BooleanGUI::COMMON:
388 isOK = myObjects->length() > 1;
390 case BooleanGUI::CUT:
391 isOK = myObject1 && myObjects->length();
393 case BooleanGUI::SECTION:
394 isOK = myObject1 && (myObjects->length() == 1);
403 //=================================================================================
404 // function : execute
406 //=================================================================================
407 bool BooleanGUI_Dialog::execute (ObjectList& objects)
409 GEOM::GEOM_Object_var anObj;
411 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
412 const bool isCheckSelfInte = myGroup->CheckButton1->isChecked();
414 switch (myOperation) {
415 case BooleanGUI::FUSE:
416 anObj = anOper->MakeFuseList(myObjects, isCheckSelfInte);
418 case BooleanGUI::COMMON:
419 anObj = anOper->MakeCommonList(myObjects, isCheckSelfInte);
421 case BooleanGUI::CUT:
423 anOper->MakeCutList(myObject1.get(), myObjects, isCheckSelfInte);
425 case BooleanGUI::SECTION:
426 anObj = anOper->MakeBoolean
427 (myObject1.get(), myObjects[0], myOperation, isCheckSelfInte);
433 if (!anObj->_is_nil())
434 objects.push_back(anObj._retn());
439 //=================================================================================
440 // function : restoreSubShapes
442 //=================================================================================
443 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
444 SALOMEDS::SObject_ptr theSObject)
446 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
447 // empty list of arguments means that all arguments should be restored
448 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
449 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
450 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
451 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false