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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GroupGUI_BooleanDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GroupGUI_BooleanDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : GroupGUI_BooleanDlg()
41 // purpose : Constructs a GroupGUI_BooleanDlg 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 GroupGUI_BooleanDlg::GroupGUI_BooleanDlg (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) {
55 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
56 aTitle = tr("GEOM_UNION");
57 aCaption = tr("GEOM_UNION_TITLE");
58 setHelpFileName("work_with_groups_page.html#union_groups_anchor");
61 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
62 aTitle = tr("GEOM_INTERSECT");
63 aCaption = tr("GEOM_INTERSECT_TITLE");
64 setHelpFileName("work_with_groups_page.html#intersect_groups_anchor");
67 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
68 aTitle = tr("GEOM_CUT");
69 aCaption = tr("GEOM_CUT_TITLE");
70 setHelpFileName("work_with_groups_page.html#cut_groups_anchor");
73 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
75 setWindowTitle(aCaption);
77 /***************************************************************/
78 mainFrame()->GroupConstructors->setTitle(aTitle);
79 mainFrame()->RadioButton1->setIcon(image0);
80 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
81 mainFrame()->RadioButton2->close();
82 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
83 mainFrame()->RadioButton3->close();
85 myGroup = new DlgRef_2Sel (centralWidget());
87 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
88 if (myOperation == CUT) {
89 myGroup->TextLabel1->setText(tr("GEOM_MAIN_GROUPS"));
90 myGroup->TextLabel2->setText(tr("GEOM_TOOL_GROUPS"));
93 myGroup->TextLabel1->setText(tr("GEOM_GROUPS").arg(1));
94 myGroup->TextLabel2->hide();
95 myGroup->PushButton2->hide();
96 myGroup->LineEdit2->hide();
99 myGroup->PushButton1->setIcon(image1);
100 myGroup->PushButton2->setIcon(image1);
101 myGroup->LineEdit1->setReadOnly(true);
102 myGroup->LineEdit2->setReadOnly(true);
104 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
105 layout->setMargin(0); layout->setSpacing(6);
106 layout->addWidget(myGroup);
107 /***************************************************************/
113 //=================================================================================
114 // function : ~GroupGUI_BooleanDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 GroupGUI_BooleanDlg::~GroupGUI_BooleanDlg()
121 //=================================================================================
124 //=================================================================================
125 void GroupGUI_BooleanDlg::Init()
128 myEditCurrentArgument = myGroup->LineEdit1;
130 myGroup->LineEdit1->setText("");
131 myGroup->LineEdit2->setText("");
132 myListShapes.length( 0 );
133 myListTools.length( 0 );
135 // signals and slots connections
136 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
139 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
142 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
143 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
145 initName(mainFrame()->GroupConstructors->title());
147 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
148 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
149 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
151 mainFrame()->RadioButton1->setFocus();
153 globalSelection(GEOM_GROUP);
155 myGroup->PushButton1->click();
156 SelectionIntoArgument();
160 //=================================================================================
161 // function : ClickOnOk()
163 //=================================================================================
164 void GroupGUI_BooleanDlg::ClickOnOk()
166 setIsApplyAndClose(true);
171 //=================================================================================
172 // function : ClickOnApply()
174 //=================================================================================
175 bool GroupGUI_BooleanDlg::ClickOnApply()
181 // activate selection and connect selection manager
182 myGroup->PushButton1->click();
186 //=================================================================================
187 // function : SelectionIntoArgument()
188 // purpose : Called when selection is changed or on dialog initialization or activation
189 //=================================================================================
190 void GroupGUI_BooleanDlg::SelectionIntoArgument()
192 myEditCurrentArgument->setText("");
194 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
195 SALOME_ListIO aSelList;
196 aSelMgr->selectedObjects(aSelList);
198 QString aString = "";
199 GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
201 if (myEditCurrentArgument == myGroup->LineEdit1) {
202 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
204 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) {
205 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
208 myEditCurrentArgument->setText(aString);
211 //=================================================================================
212 // function : SetEditCurrentArgument()
214 //=================================================================================
215 void GroupGUI_BooleanDlg::SetEditCurrentArgument()
217 QPushButton* send = (QPushButton*)sender();
219 if (send == myGroup->PushButton1) {
220 myEditCurrentArgument = myGroup->LineEdit1;
222 myGroup->PushButton2->setDown(false);
223 myGroup->LineEdit2->setEnabled(false);
225 else if (send == myGroup->PushButton2) {
226 myEditCurrentArgument = myGroup->LineEdit2;
228 myGroup->PushButton1->setDown(false);
229 myGroup->LineEdit1->setEnabled(false);
233 myEditCurrentArgument->setEnabled(true);
234 myEditCurrentArgument->setFocus();
235 // after setFocus(), because it will be setDown(false) when loses focus
239 //=================================================================================
240 // function : ActivateThisDialog()
242 //=================================================================================
243 void GroupGUI_BooleanDlg::ActivateThisDialog()
245 GEOMBase_Skeleton::ActivateThisDialog();
247 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
248 this, SLOT(SelectionIntoArgument()));
251 //=================================================================================
252 // function : enterEvent()
253 // purpose : when mouse enter onto the QWidget
254 //=================================================================================
255 void GroupGUI_BooleanDlg::enterEvent (QEvent*)
257 if (!mainFrame()->GroupConstructors->isEnabled())
258 ActivateThisDialog();
261 //=================================================================================
262 // function : createOperation
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr GroupGUI_BooleanDlg::createOperation()
267 return getGeomEngine()->GetIGroupOperations(getStudyId());
270 //=================================================================================
271 // function : isValid
273 //=================================================================================
274 bool GroupGUI_BooleanDlg::isValid (QString&)
276 return (myListShapes.length() > 0);
279 //=================================================================================
280 // function : execute
282 //=================================================================================
283 bool GroupGUI_BooleanDlg::execute (ObjectList& objects)
285 GEOM::GEOM_Object_var anObj;
287 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
288 switch (myOperation) {
290 anObj = anOper->UnionListOfGroups(myListShapes);
293 anObj = anOper->IntersectListOfGroups(myListShapes);
296 anObj = anOper->CutListOfGroups(myListShapes, myListTools);
301 if (!anObj->_is_nil())
302 objects.push_back(anObj._retn());
307 //================================================================
308 // Function : getFather
309 // Purpose : Get father object for object to be added in study
310 // (called with addInStudy method)
311 //================================================================
312 GEOM::GEOM_Object_ptr GroupGUI_BooleanDlg::getFather(GEOM::GEOM_Object_ptr theObj)
314 GEOM::GEOM_Object_var aFatherObj;
315 if (theObj->GetType() == GEOM_GROUP) {
316 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
317 aFatherObj = anOper->GetMainShape(theObj);
319 return aFatherObj._retn();