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_2Sel(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 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
122 layout->setMargin(0); layout->setSpacing(6);
123 layout->addWidget(myGroup);
124 /***************************************************************/
127 mainFrame()->CheckBoxPreview->setChecked( false );
128 mainFrame()->CheckBoxPreview->hide();
134 //=================================================================================
135 // function : ~BooleanGUI_Dialog()
136 // purpose : Destroys the object and frees any allocated resources
137 //=================================================================================
138 BooleanGUI_Dialog::~BooleanGUI_Dialog()
142 //=================================================================================
145 //=================================================================================
146 void BooleanGUI_Dialog::Init()
148 mainFrame()->GroupBoxPublish->show();
151 myEditCurrentArgument = myGroup->LineEdit1;
153 myGroup->LineEdit1->setText("");
154 myGroup->LineEdit2->setText("");
158 // signals and slots connections
159 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
160 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
162 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
164 if (!myGroup->PushButton2->isHidden()) {
165 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
168 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
169 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
171 initName(mainFrame()->GroupConstructors->title());
173 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
174 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
175 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
177 mainFrame()->RadioButton1->setFocus();
179 globalSelection(GEOM_ALLSHAPES);
181 myGroup->PushButton1->click();
182 SelectionIntoArgument();
186 //=================================================================================
187 // function : ClickOnOk()
189 //=================================================================================
190 void BooleanGUI_Dialog::ClickOnOk()
192 setIsApplyAndClose( true );
197 //=================================================================================
198 // function : ClickOnApply()
200 //=================================================================================
201 bool BooleanGUI_Dialog::ClickOnApply()
207 // activate selection and connect selection manager
208 myGroup->PushButton1->click();
212 //=================================================================================
213 // function : reset()
215 //=================================================================================
216 void BooleanGUI_Dialog::reset()
218 myObjects = new GEOM::ListOfGO;
219 myObjects->length( 0 );
222 //=================================================================================
223 // function : singleSelection
224 // purpose : Performs single selection. Called from SelectionIntoArgument()
225 //=================================================================================
226 void BooleanGUI_Dialog::singleSelection()
228 myEditCurrentArgument->setText("");
230 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
232 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
233 QString aName = GEOMBase::GetName( aSelectedObject.get() );
234 myEditCurrentArgument->setText( aName );
237 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
238 myGeomGUI->getApp()->selectionMgr()->clearSelected();
239 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
240 this, SLOT(SelectionIntoArgument()));
242 if (myEditCurrentArgument == myGroup->LineEdit1) {
243 myObject1 = aSelectedObject;
244 if (!myGroup->PushButton2->isHidden() && !myObjects->length())
245 myGroup->PushButton2->click();
247 else if (myEditCurrentArgument == myGroup->LineEdit2) {
248 myObjects->length(1);
249 myObjects[0] = aSelectedObject.get();
251 myGroup->PushButton1->click();
255 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
256 else if (myEditCurrentArgument == myGroup->LineEdit2) reset();
260 //=================================================================================
261 // function : multipleSelection
262 // purpose : Performs multiple selection. Called from SelectionIntoArgument()
263 //=================================================================================
264 void BooleanGUI_Dialog::multipleSelection()
266 myEditCurrentArgument->setText( "" );
269 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
270 SALOME_ListIO aSelList;
271 aSelMgr->selectedObjects(aSelList);
272 myObjects->length(aSelList.Extent());
275 for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
276 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
278 if ( !CORBA::is_nil( aSelectedObject ) ) {
279 myObjects[i++] = aSelectedObject;
283 myObjects->length( i );
285 myEditCurrentArgument->setText( GEOMBase::GetName( myObjects[0] ) );
286 } else if ( i > 0 ) {
287 myEditCurrentArgument->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
291 //=================================================================================
292 // function : SelectionIntoArgument()
293 // purpose : Called when selection is changed or on dialog initialization or activation
294 //=================================================================================
295 void BooleanGUI_Dialog::SelectionIntoArgument()
297 if ( myOperation == BooleanGUI::SECTION ||
298 (myOperation == BooleanGUI::CUT &&
299 myEditCurrentArgument == myGroup->LineEdit1)) {
308 //=================================================================================
309 // function : SetEditCurrentArgument()
311 //=================================================================================
312 void BooleanGUI_Dialog::SetEditCurrentArgument()
314 QPushButton* send = (QPushButton*)sender();
316 if (send == myGroup->PushButton1) {
317 myEditCurrentArgument = myGroup->LineEdit1;
319 if (!myGroup->PushButton2->isHidden()) {
320 myGroup->PushButton2->setDown(false);
321 myGroup->LineEdit2->setEnabled(false);
324 else if (send == myGroup->PushButton2) {
325 myEditCurrentArgument = myGroup->LineEdit2;
327 myGroup->PushButton1->setDown(false);
328 myGroup->LineEdit1->setEnabled(false);
332 myEditCurrentArgument->setEnabled(true);
333 myEditCurrentArgument->setFocus();
334 // after setFocus(), because it will be setDown(false) when loses focus
338 //=================================================================================
339 // function : ActivateThisDialog()
341 //=================================================================================
342 void BooleanGUI_Dialog::ActivateThisDialog()
344 GEOMBase_Skeleton::ActivateThisDialog();
346 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
347 this, SLOT( SelectionIntoArgument() ) );
351 //=================================================================================
352 // function : enterEvent()
353 // purpose : when mouse enter onto the QWidget
354 //=================================================================================
355 void BooleanGUI_Dialog::enterEvent (QEvent*)
357 if (!mainFrame()->GroupConstructors->isEnabled())
358 ActivateThisDialog();
361 //=================================================================================
362 // function : createOperation
364 //=================================================================================
365 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
367 return getGeomEngine()->GetIBooleanOperations(getStudyId());
370 //=================================================================================
371 // function : isValid
373 //=================================================================================
374 bool BooleanGUI_Dialog::isValid (QString&)
378 switch (myOperation) {
379 case BooleanGUI::FUSE:
380 case BooleanGUI::COMMON:
381 isOK = myObjects->length() > 1;
383 case BooleanGUI::CUT:
384 isOK = myObject1 && myObjects->length();
386 case BooleanGUI::SECTION:
387 isOK = myObject1 && (myObjects->length() == 1);
396 //=================================================================================
397 // function : execute
399 //=================================================================================
400 bool BooleanGUI_Dialog::execute (ObjectList& objects)
402 GEOM::GEOM_Object_var anObj;
404 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
406 switch (myOperation) {
407 case BooleanGUI::FUSE:
408 anObj = anOper->MakeFuseList(myObjects);
410 case BooleanGUI::COMMON:
411 anObj = anOper->MakeCommonList(myObjects);
413 case BooleanGUI::CUT:
414 anObj = anOper->MakeCutList(myObject1.get(), myObjects);
416 case BooleanGUI::SECTION:
417 anObj = anOper->MakeBoolean(myObject1.get(), myObjects[0], myOperation);
423 if (!anObj->_is_nil())
424 objects.push_back(anObj._retn());
429 //=================================================================================
430 // function : restoreSubShapes
432 //=================================================================================
433 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
434 SALOMEDS::SObject_ptr theSObject)
436 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
437 // empty list of arguments means that all arguments should be restored
438 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
439 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
440 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
441 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false