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("");
138 myObject1 = myObject2 = GEOM::GEOM_Object::_nil();
140 // signals and slots connections
141 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
144 connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145 connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
148 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
151 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
153 initName(mainFrame()->GroupConstructors->title());
155 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
156 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
157 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
159 mainFrame()->RadioButton1->setFocus();
161 globalSelection(GEOM_ALLSHAPES);
163 myGroup->PushButton1->click();
164 SelectionIntoArgument();
168 //=================================================================================
169 // function : ClickOnOk()
171 //=================================================================================
172 void BooleanGUI_Dialog::ClickOnOk()
178 //=================================================================================
179 // function : ClickOnApply()
181 //=================================================================================
182 bool BooleanGUI_Dialog::ClickOnApply()
188 // activate selection and connect selection manager
189 myGroup->PushButton1->click();
193 //=================================================================================
194 // function : SelectionIntoArgument()
195 // purpose : Called when selection is changed or on dialog initialization or activation
196 //=================================================================================
197 void BooleanGUI_Dialog::SelectionIntoArgument()
199 myEditCurrentArgument->setText("");
201 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
202 SALOME_ListIO aSelList;
203 aSelMgr->selectedObjects(aSelList);
205 if (aSelList.Extent() != 1) {
206 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1 = GEOM::GEOM_Object::_nil();
207 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2 = GEOM::GEOM_Object::_nil();
212 Standard_Boolean aRes = Standard_False;
213 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
214 if (!CORBA::is_nil(aSelectedObject) && aRes && GEOMBase::IsShape(aSelectedObject))
216 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
219 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
220 myGeomGUI->getApp()->selectionMgr()->clearSelected();
221 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
222 this, SLOT(SelectionIntoArgument()));
224 if (myEditCurrentArgument == myGroup->LineEdit1) {
225 myObject1 = aSelectedObject;
226 if (myObject2->_is_nil())
227 myGroup->PushButton2->click();
229 else if (myEditCurrentArgument == myGroup->LineEdit2) {
230 myObject2 = aSelectedObject;
231 if (myObject1->_is_nil())
232 myGroup->PushButton1->click();
237 //=================================================================================
238 // function : SetEditCurrentArgument()
240 //=================================================================================
241 void BooleanGUI_Dialog::SetEditCurrentArgument()
243 QPushButton* send = (QPushButton*)sender();
245 if (send == myGroup->PushButton1) {
246 myEditCurrentArgument = myGroup->LineEdit1;
248 myGroup->PushButton2->setDown(false);
249 myGroup->LineEdit2->setEnabled(false);
251 else if (send == myGroup->PushButton2) {
252 myEditCurrentArgument = myGroup->LineEdit2;
254 myGroup->PushButton1->setDown(false);
255 myGroup->LineEdit1->setEnabled(false);
259 myEditCurrentArgument->setEnabled(true);
260 myEditCurrentArgument->setFocus();
261 // after setFocus(), because it will be setDown(false) when loses focus
265 //=================================================================================
266 // function : LineEditReturnPressed()
268 //=================================================================================
269 void BooleanGUI_Dialog::LineEditReturnPressed()
271 QLineEdit* send = (QLineEdit*)sender();
272 if (send == myGroup->LineEdit1 || send == myGroup->LineEdit2) {
273 myEditCurrentArgument = send;
274 GEOMBase_Skeleton::LineEditReturnPressed();
278 //=================================================================================
279 // function : ActivateThisDialog()
281 //=================================================================================
282 void BooleanGUI_Dialog::ActivateThisDialog()
284 GEOMBase_Skeleton::ActivateThisDialog();
286 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
287 this, SLOT( SelectionIntoArgument() ) );
291 //=================================================================================
292 // function : enterEvent()
293 // purpose : when mouse enter onto the QWidget
294 //=================================================================================
295 void BooleanGUI_Dialog::enterEvent (QEvent*)
297 if (!mainFrame()->GroupConstructors->isEnabled())
298 ActivateThisDialog();
301 //=================================================================================
302 // function : createOperation
304 //=================================================================================
305 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
307 return getGeomEngine()->GetIBooleanOperations(getStudyId());
310 //=================================================================================
311 // function : isValid
313 //=================================================================================
314 bool BooleanGUI_Dialog::isValid (QString&)
316 //Handle(SALOME_InteractiveObject) IO = firstIObject();
317 //Standard_Boolean testResult;
318 //GEOM::GEOM_Object_var anObject = GEOMBase::ConvertIOinGEOMObject(IO, testResult);
319 //if (!testResult || anObject->_is_nil())
322 return !CORBA::is_nil(myObject1) && !CORBA::is_nil(myObject2);
325 //=================================================================================
326 // function : execute
328 //=================================================================================
329 bool BooleanGUI_Dialog::execute (ObjectList& objects)
331 GEOM::GEOM_Object_var anObj;
333 GEOM::GEOM_IBooleanOperations_var anOper = GEOM::GEOM_IBooleanOperations::_narrow(getOperation());
334 anObj = anOper->MakeBoolean(myObject1, myObject2, myOperation);
335 if (!anObj->_is_nil())
336 objects.push_back(anObj._retn());
341 //=================================================================================
342 // function : restoreSubShapes
344 //=================================================================================
345 void BooleanGUI_Dialog::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
346 SALOMEDS::SObject_ptr theSObject)
348 if (mainFrame()->CheckBoxRestoreSS->isChecked()) {
349 // empty list of arguments means that all arguments should be restored
350 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
351 /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
352 /*theInheritFirstArg=*/myOperation == BooleanGUI::CUT,
353 mainFrame()->CheckBoxAddPrefix->isChecked()); // ? false