1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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 : GroupGUI_BooleanDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "GroupGUI_BooleanDlg.h"
30 #include <GeometryGUI.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SalomeApp_Application.h>
36 #include <LightApp_SelectionMgr.h>
38 #include <GEOMImpl_Types.hxx>
40 //=================================================================================
41 // class : GroupGUI_BooleanDlg()
42 // purpose : Constructs a GroupGUI_BooleanDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 GroupGUI_BooleanDlg::GroupGUI_BooleanDlg (const int theOperation, GeometryGUI* theGeometryGUI,
48 QWidget* parent, bool modal, Qt::WindowFlags fl)
49 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl),
50 myOperation(theOperation)
53 QString aTitle, aCaption;
54 switch (myOperation) {
56 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_FUSE")));
57 aTitle = tr("GEOM_UNION");
58 aCaption = tr("GEOM_UNION_TITLE");
59 setHelpFileName("work_with_groups_page.html#union_groups_anchor");
62 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_COMMON")));
63 aTitle = tr("GEOM_INTERSECT");
64 aCaption = tr("GEOM_INTERSECT_TITLE");
65 setHelpFileName("work_with_groups_page.html#intersect_groups_anchor");
68 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_CUT")));
69 aTitle = tr("GEOM_CUT");
70 aCaption = tr("GEOM_CUT_TITLE");
71 setHelpFileName("work_with_groups_page.html#cut_groups_anchor");
74 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
76 setWindowTitle(aCaption);
78 /***************************************************************/
79 mainFrame()->GroupConstructors->setTitle(aTitle);
80 mainFrame()->RadioButton1->setIcon(image0);
81 mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
82 mainFrame()->RadioButton2->close();
83 mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
84 mainFrame()->RadioButton3->close();
86 myGroup = new DlgRef_2Sel (centralWidget());
88 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
89 if (myOperation == CUT) {
90 myGroup->TextLabel1->setText(tr("GEOM_MAIN_GROUPS"));
91 myGroup->TextLabel2->setText(tr("GEOM_TOOL_GROUPS"));
94 myGroup->TextLabel1->setText(tr("GEOM_GROUPS").arg(1));
95 myGroup->TextLabel2->hide();
96 myGroup->PushButton2->hide();
97 myGroup->LineEdit2->hide();
100 myGroup->PushButton1->setIcon(image1);
101 myGroup->PushButton2->setIcon(image1);
102 myGroup->LineEdit1->setReadOnly(true);
103 myGroup->LineEdit2->setReadOnly(true);
105 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
106 layout->setMargin(0); layout->setSpacing(6);
107 layout->addWidget(myGroup);
108 /***************************************************************/
114 //=================================================================================
115 // function : ~GroupGUI_BooleanDlg()
116 // purpose : Destroys the object and frees any allocated resources
117 //=================================================================================
118 GroupGUI_BooleanDlg::~GroupGUI_BooleanDlg()
122 //=================================================================================
125 //=================================================================================
126 void GroupGUI_BooleanDlg::Init()
129 myEditCurrentArgument = myGroup->LineEdit1;
131 myGroup->LineEdit1->setText("");
132 myGroup->LineEdit2->setText("");
133 myListShapes.length( 0 );
134 myListTools.length( 0 );
136 // signals and slots connections
137 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
138 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
140 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
143 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
144 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
146 initName(mainFrame()->GroupConstructors->title());
148 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
149 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
150 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
152 mainFrame()->RadioButton1->setFocus();
154 globalSelection(GEOM_GROUP);
156 myGroup->PushButton1->click();
157 SelectionIntoArgument();
161 //=================================================================================
162 // function : ClickOnOk()
164 //=================================================================================
165 void GroupGUI_BooleanDlg::ClickOnOk()
167 setIsApplyAndClose(true);
172 //=================================================================================
173 // function : ClickOnApply()
175 //=================================================================================
176 bool GroupGUI_BooleanDlg::ClickOnApply()
182 // activate selection and connect selection manager
183 myGroup->PushButton1->click();
187 //=================================================================================
188 // function : SelectionIntoArgument()
189 // purpose : Called when selection is changed or on dialog initialization or activation
190 //=================================================================================
191 void GroupGUI_BooleanDlg::SelectionIntoArgument()
193 myEditCurrentArgument->setText("");
195 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
196 SALOME_ListIO aSelList;
197 aSelMgr->selectedObjects(aSelList);
199 QString aString = "";
200 GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
202 if (myEditCurrentArgument == myGroup->LineEdit1) {
203 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
205 else if ( myEditCurrentArgument == myGroup->LineEdit2 ) {
206 GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
209 myEditCurrentArgument->setText(aString);
212 //=================================================================================
213 // function : SetEditCurrentArgument()
215 //=================================================================================
216 void GroupGUI_BooleanDlg::SetEditCurrentArgument()
218 QPushButton* send = (QPushButton*)sender();
220 if (send == myGroup->PushButton1) {
221 myEditCurrentArgument = myGroup->LineEdit1;
223 myGroup->PushButton2->setDown(false);
224 myGroup->LineEdit2->setEnabled(false);
226 else if (send == myGroup->PushButton2) {
227 myEditCurrentArgument = myGroup->LineEdit2;
229 myGroup->PushButton1->setDown(false);
230 myGroup->LineEdit1->setEnabled(false);
234 myEditCurrentArgument->setEnabled(true);
235 myEditCurrentArgument->setFocus();
236 // after setFocus(), because it will be setDown(false) when loses focus
240 //=================================================================================
241 // function : ActivateThisDialog()
243 //=================================================================================
244 void GroupGUI_BooleanDlg::ActivateThisDialog()
246 GEOMBase_Skeleton::ActivateThisDialog();
248 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
249 this, SLOT(SelectionIntoArgument()));
252 //=================================================================================
253 // function : enterEvent()
254 // purpose : when mouse enter onto the QWidget
255 //=================================================================================
256 void GroupGUI_BooleanDlg::enterEvent (QEvent*)
258 if (!mainFrame()->GroupConstructors->isEnabled())
259 ActivateThisDialog();
262 //=================================================================================
263 // function : createOperation
265 //=================================================================================
266 GEOM::GEOM_IOperations_ptr GroupGUI_BooleanDlg::createOperation()
268 return getGeomEngine()->GetIGroupOperations();
271 //=================================================================================
272 // function : isValid
274 //=================================================================================
275 bool GroupGUI_BooleanDlg::isValid (QString&)
277 return (myListShapes.length() > 0);
280 //=================================================================================
281 // function : execute
283 //=================================================================================
284 bool GroupGUI_BooleanDlg::execute (ObjectList& objects)
286 GEOM::GEOM_Object_var anObj;
288 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
289 switch (myOperation) {
291 anObj = anOper->UnionListOfGroups(myListShapes);
294 anObj = anOper->IntersectListOfGroups(myListShapes);
297 anObj = anOper->CutListOfGroups(myListShapes, myListTools);
302 if (!anObj->_is_nil())
303 objects.push_back(anObj._retn());
308 //================================================================
309 // Function : getFather
310 // Purpose : Get father object for object to be added in study
311 // (called with addInStudy method)
312 //================================================================
313 GEOM::GEOM_Object_ptr GroupGUI_BooleanDlg::getFather(GEOM::GEOM_Object_ptr theObj)
315 GEOM::GEOM_Object_var aFatherObj;
316 if (theObj->GetType() == GEOM_GROUP) {
317 GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
318 aFatherObj = anOper->GetMainShape(theObj);
320 return aFatherObj._retn();
323 //=================================================================================
324 // function : getSourceObjects
325 // purpose : virtual method to get source objects
326 //=================================================================================
327 QList<GEOM::GeomObjPtr> GroupGUI_BooleanDlg::getSourceObjects()
329 QList<GEOM::GeomObjPtr> res;
330 for ( CORBA::ULong i = 0; i < myListShapes.length(); i++) {
331 GEOM::GeomObjPtr aGeomObjPtr(myListShapes[i]);
334 for ( CORBA::ULong i = 0; i < myListTools.length(); i++) {
335 GEOM::GeomObjPtr aGeomObjPtr(myListTools[i]);