1 // Copyright (C) 2007-2012 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>
39 // VSR 22/08/2012: issue 0021787: remove "Preview" button from BOP and Partition operations
40 // Comment next line to enable preview in BOP dialog box
43 //=================================================================================
44 // class : BooleanGUI_Dialog()
45 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
51 QWidget* parent, bool modal, Qt::WindowFlags fl)
52 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
53 myOperation(theOperation)
56 QString aTitle, aCaption;
57 switch (myOperation) {
58 case BooleanGUI::COMMON:
59 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
60 aTitle = tr("GEOM_COMMON");
61 aCaption = tr("GEOM_COMMON_TITLE");
62 setHelpFileName("common_operation_page.html");
65 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
66 aTitle = tr("GEOM_CUT");
67 aCaption = tr("GEOM_CUT_TITLE");
68 setHelpFileName("cut_operation_page.html");
70 case BooleanGUI::FUSE:
71 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
72 aTitle = tr("GEOM_FUSE");
73 aCaption = tr("GEOM_FUSE_TITLE");
74 setHelpFileName("fuse_operation_page.html");
76 case BooleanGUI::SECTION:
77 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
78 aTitle = tr("GEOM_SECTION");
79 aCaption = tr("GEOM_SECTION_TITLE");
80 setHelpFileName("section_opeartion_page.html");
83 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
85 setWindowTitle(aCaption);
87 /***************************************************************/
88 mainFrame()->GroupConstructors->setTitle(aTitle);
89 mainFrame()->RadioButton1->setIcon(image0);
90 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
91 mainFrame()->RadioButton2->close();
92 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
93 mainFrame()->RadioButton3->close();
95 myGroup = new DlgRef_2Sel(centralWidget());
97 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
98 if (myOperation != BooleanGUI::CUT) {
99 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
100 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
103 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
104 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
107 myGroup->PushButton1->setIcon(image1);
108 myGroup->PushButton2->setIcon(image1);
109 myGroup->LineEdit1->setReadOnly(true);
110 myGroup->LineEdit2->setReadOnly(true);
112 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
113 layout->setMargin(0); layout->setSpacing(6);
114 layout->addWidget(myGroup);
115 /***************************************************************/
118 mainFrame()->CheckBoxPreview->setChecked( false );
119 mainFrame()->CheckBoxPreview->hide();
125 //=================================================================================
126 // function : ~BooleanGUI_Dialog()
127 // purpose : Destroys the object and frees any allocated resources
128 //=================================================================================
129 BooleanGUI_Dialog::~BooleanGUI_Dialog()
133 //=================================================================================
136 //=================================================================================
137 void BooleanGUI_Dialog::Init()
139 mainFrame()->GroupBoxPublish->show();
142 myEditCurrentArgument = myGroup->LineEdit1;
144 myGroup->LineEdit1->setText("");
145 myGroup->LineEdit2->setText("");
149 // signals and slots connections
150 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
151 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
153 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
157 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
159 initName(mainFrame()->GroupConstructors->title());
161 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
162 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
163 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
165 mainFrame()->RadioButton1->setFocus();
167 globalSelection(GEOM_ALLSHAPES);
169 myGroup->PushButton1->click();
170 SelectionIntoArgument();
174 //=================================================================================
175 // function : ClickOnOk()
177 //=================================================================================
178 void BooleanGUI_Dialog::ClickOnOk()
180 setIsApplyAndClose( true );
185 //=================================================================================
186 // function : ClickOnApply()
188 //=================================================================================
189 bool BooleanGUI_Dialog::ClickOnApply()
195 // activate selection and connect selection manager
196 myGroup->PushButton1->click();
200 //=================================================================================
201 // function : SelectionIntoArgument()
202 // purpose : Called when selection is changed or on dialog initialization or activation
203 //=================================================================================
204 void BooleanGUI_Dialog::SelectionIntoArgument()
206 myEditCurrentArgument->setText("");
208 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
210 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
211 QString aName = GEOMBase::GetName( aSelectedObject.get() );
212 myEditCurrentArgument->setText( aName );
215 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
216 myGeomGUI->getApp()->selectionMgr()->clearSelected();
217 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
218 this, SLOT(SelectionIntoArgument()));
220 if (myEditCurrentArgument == myGroup->LineEdit1) {
221 myObject1 = aSelectedObject;
223 myGroup->PushButton2->click();
225 else if (myEditCurrentArgument == myGroup->LineEdit2) {
226 myObject2 = aSelectedObject;
228 myGroup->PushButton1->click();
232 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
233 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
238 //=================================================================================
239 // function : SetEditCurrentArgument()
241 //=================================================================================
242 void BooleanGUI_Dialog::SetEditCurrentArgument()
244 QPushButton* send = (QPushButton*)sender();
246 if (send == myGroup->PushButton1) {
247 myEditCurrentArgument = myGroup->LineEdit1;
249 myGroup->PushButton2->setDown(false);
250 myGroup->LineEdit2->setEnabled(false);
252 else if (send == myGroup->PushButton2) {
253 myEditCurrentArgument = myGroup->LineEdit2;
255 myGroup->PushButton1->setDown(false);
256 myGroup->LineEdit1->setEnabled(false);
260 myEditCurrentArgument->setEnabled(true);
261 myEditCurrentArgument->setFocus();
262 // after setFocus(), because it will be setDown(false) when loses focus
266 //=================================================================================
267 // function : ActivateThisDialog()
269 //=================================================================================
270 void BooleanGUI_Dialog::ActivateThisDialog()
272 GEOMBase_Skeleton::ActivateThisDialog();
274 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
275 this, SLOT( SelectionIntoArgument() ) );
279 //=================================================================================
280 // function : enterEvent()
281 // purpose : when mouse enter onto the QWidget
282 //=================================================================================
283 void BooleanGUI_Dialog::enterEvent (QEvent*)
285 if (!mainFrame()->GroupConstructors->isEnabled())
286 ActivateThisDialog();
289 //=================================================================================
290 // function : createOperation
292 //=================================================================================
293 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
295 return getGeomEngine()->GetIBooleanOperations(getStudyId());
298 //=================================================================================
299 // function : isValid
301 //=================================================================================
302 bool BooleanGUI_Dialog::isValid (QString&)
304 return myObject1 && myObject2;
307 //=================================================================================
308 // function : execute
310 //=================================================================================
311 bool BooleanGUI_Dialog::execute (ObjectList& objects)
313 GEOM::GEOM_Object_var anObj;
315 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
316 anObj = anOper->MakeBoolean(myObject1.get(), myObject2.get(), myOperation);
317 if (!anObj->_is_nil())
318 objects.push_back(anObj._retn());
323 //=================================================================================
324 // function : restoreSubShapes
326 //=================================================================================
327 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
328 SALOMEDS::SObject_ptr theSObject)
330 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
331 // empty list of arguments means that all arguments should be restored
332 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
333 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
334 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
335 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false