1 // Copyright (C) 2007-2010 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 //=================================================================================
40 // class : BooleanGUI_Dialog()
41 // purpose : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 BooleanGUI_Dialog::BooleanGUI_Dialog (const int theOperation, GeometryGUI* theGeometryGUI,
47 QWidget* parent, bool modal, Qt::WindowFlags fl)
48 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
49 myOperation(theOperation)
52 QString aTitle, aCaption;
53 switch (myOperation) {
54 case BooleanGUI::COMMON:
55 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
56 aTitle = tr("GEOM_COMMON");
57 aCaption = tr("GEOM_COMMON_TITLE");
58 setHelpFileName("common_operation_page.html");
61 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
62 aTitle = tr("GEOM_CUT");
63 aCaption = tr("GEOM_CUT_TITLE");
64 setHelpFileName("cut_operation_page.html");
66 case BooleanGUI::FUSE:
67 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
68 aTitle = tr("GEOM_FUSE");
69 aCaption = tr("GEOM_FUSE_TITLE");
70 setHelpFileName("fuse_operation_page.html");
72 case BooleanGUI::SECTION:
73 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_SECTION")));
74 aTitle = tr("GEOM_SECTION");
75 aCaption = tr("GEOM_SECTION_TITLE");
76 setHelpFileName("section_opeartion_page.html");
79 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
81 setWindowTitle(aCaption);
83 /***************************************************************/
84 mainFrame()->GroupConstructors->setTitle(aTitle);
85 mainFrame()->RadioButton1->setIcon(image0);
86 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
87 mainFrame()->RadioButton2->close();
88 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
89 mainFrame()->RadioButton3->close();
91 myGroup = new DlgRef_2Sel(centralWidget());
93 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
94 if (myOperation != BooleanGUI::CUT) {
95 myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg(1));
96 myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg(2));
99 myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
100 myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
103 myGroup->PushButton1->setIcon(image1);
104 myGroup->PushButton2->setIcon(image1);
105 myGroup->LineEdit1->setReadOnly(true);
106 myGroup->LineEdit2->setReadOnly(true);
108 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
109 layout->setMargin(0); layout->setSpacing(6);
110 layout->addWidget(myGroup);
111 /***************************************************************/
117 //=================================================================================
118 // function : ~BooleanGUI_Dialog()
119 // purpose : Destroys the object and frees any allocated resources
120 //=================================================================================
121 BooleanGUI_Dialog::~BooleanGUI_Dialog()
125 //=================================================================================
128 //=================================================================================
129 void BooleanGUI_Dialog::Init()
131 mainFrame()->GroupBoxPublish->show();
134 myEditCurrentArgument = myGroup->LineEdit1;
136 myGroup->LineEdit1->setText("");
137 myGroup->LineEdit2->setText("");
141 // signals and slots connections
142 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
143 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
145 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
146 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
149 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
151 initName(mainFrame()->GroupConstructors->title());
153 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
154 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
155 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
157 mainFrame()->RadioButton1->setFocus();
159 globalSelection(GEOM_ALLSHAPES);
161 myGroup->PushButton1->click();
162 SelectionIntoArgument();
166 //=================================================================================
167 // function : ClickOnOk()
169 //=================================================================================
170 void BooleanGUI_Dialog::ClickOnOk()
176 //=================================================================================
177 // function : ClickOnApply()
179 //=================================================================================
180 bool BooleanGUI_Dialog::ClickOnApply()
186 // activate selection and connect selection manager
187 myGroup->PushButton1->click();
191 //=================================================================================
192 // function : SelectionIntoArgument()
193 // purpose : Called when selection is changed or on dialog initialization or activation
194 //=================================================================================
195 void BooleanGUI_Dialog::SelectionIntoArgument()
197 myEditCurrentArgument->setText("");
199 GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_SHAPE );
201 if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
202 QString aName = GEOMBase::GetName( aSelectedObject.get() );
203 myEditCurrentArgument->setText( aName );
206 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
207 myGeomGUI->getApp()->selectionMgr()->clearSelected();
208 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
209 this, SLOT(SelectionIntoArgument()));
211 if (myEditCurrentArgument == myGroup->LineEdit1) {
212 myObject1 = aSelectedObject;
214 myGroup->PushButton2->click();
216 else if (myEditCurrentArgument == myGroup->LineEdit2) {
217 myObject2 = aSelectedObject;
219 myGroup->PushButton1->click();
223 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
224 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
228 //=================================================================================
229 // function : SetEditCurrentArgument()
231 //=================================================================================
232 void BooleanGUI_Dialog::SetEditCurrentArgument()
234 QPushButton* send = (QPushButton*)sender();
236 if (send == myGroup->PushButton1) {
237 myEditCurrentArgument = myGroup->LineEdit1;
239 myGroup->PushButton2->setDown(false);
240 myGroup->LineEdit2->setEnabled(false);
242 else if (send == myGroup->PushButton2) {
243 myEditCurrentArgument = myGroup->LineEdit2;
245 myGroup->PushButton1->setDown(false);
246 myGroup->LineEdit1->setEnabled(false);
250 myEditCurrentArgument->setEnabled(true);
251 myEditCurrentArgument->setFocus();
252 // after setFocus(), because it will be setDown(false) when loses focus
256 //=================================================================================
257 // function : ActivateThisDialog()
259 //=================================================================================
260 void BooleanGUI_Dialog::ActivateThisDialog()
262 GEOMBase_Skeleton::ActivateThisDialog();
264 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
265 this, SLOT( SelectionIntoArgument() ) );
269 //=================================================================================
270 // function : enterEvent()
271 // purpose : when mouse enter onto the QWidget
272 //=================================================================================
273 void BooleanGUI_Dialog::enterEvent (QEvent*)
275 if (!mainFrame()->GroupConstructors->isEnabled())
276 ActivateThisDialog();
279 //=================================================================================
280 // function : createOperation
282 //=================================================================================
283 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
285 return getGeomEngine()->GetIBooleanOperations(getStudyId());
288 //=================================================================================
289 // function : isValid
291 //=================================================================================
292 bool BooleanGUI_Dialog::isValid (QString&)
294 return myObject1 && myObject2;
297 //=================================================================================
298 // function : execute
300 //=================================================================================
301 bool BooleanGUI_Dialog::execute (ObjectList& objects)
303 GEOM::GEOM_Object_var anObj;
305 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
306 anObj = anOper->MakeBoolean(myObject1.get(), myObject2.get(), myOperation);
307 if (!anObj->_is_nil())
308 objects.push_back(anObj._retn());
313 //=================================================================================
314 // function : restoreSubShapes
316 //=================================================================================
317 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
318 SALOMEDS::SObject_ptr theSObject)
320 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
321 // empty list of arguments means that all arguments should be restored
322 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
323 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
324 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
325 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false