]> SALOME platform Git repositories - modules/geom.git/blob - src/GroupGUI/GroupGUI_BooleanDlg.cxx
Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / GroupGUI / GroupGUI_BooleanDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : GroupGUI_BooleanDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "GroupGUI_BooleanDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <SUIT_Session.h>
33 #include <SUIT_ResourceMgr.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36
37 #include <GEOMImpl_Types.hxx>
38
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)
50 {
51   QPixmap image0;
52   QString aTitle, aCaption;
53   switch (myOperation) {
54   case UNION:
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");
59     break;
60   case INTERSECT:
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");
65     break;
66   case CUT:
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");
71     break;
72   }
73   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
74
75   setWindowTitle(aCaption);
76
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();
84
85   myGroup = new DlgRef_2Sel (centralWidget());
86
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"));
91   }
92   else {
93     myGroup->TextLabel1->setText(tr("GEOM_GROUPS").arg(1));
94     myGroup->TextLabel2->hide();
95     myGroup->PushButton2->hide();
96     myGroup->LineEdit2->hide();
97   }
98
99   myGroup->PushButton1->setIcon(image1);
100   myGroup->PushButton2->setIcon(image1);
101   myGroup->LineEdit1->setReadOnly(true);
102   myGroup->LineEdit2->setReadOnly(true);
103
104   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
105   layout->setMargin(0); layout->setSpacing(6);
106   layout->addWidget(myGroup);
107   /***************************************************************/
108
109   // Initialisation
110   Init();
111 }
112
113 //=================================================================================
114 // function : ~GroupGUI_BooleanDlg()
115 // purpose  : Destroys the object and frees any allocated resources
116 //=================================================================================
117 GroupGUI_BooleanDlg::~GroupGUI_BooleanDlg()
118 {
119 }
120
121 //=================================================================================
122 // function : Init()
123 // purpose  :
124 //=================================================================================
125 void GroupGUI_BooleanDlg::Init()
126 {
127   // init variables
128   myEditCurrentArgument = myGroup->LineEdit1;
129
130   myGroup->LineEdit1->setText("");
131   myGroup->LineEdit2->setText("");
132   myListShapes.length( 0 );
133   myListTools.length( 0 );
134
135   // signals and slots connections
136   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
137   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
138
139   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141
142   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
143            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144
145   initName(mainFrame()->GroupConstructors->title());
146
147   setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
148   setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
149   setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
150
151   mainFrame()->RadioButton1->setFocus();
152
153   globalSelection(GEOM_GROUP);
154
155   myGroup->PushButton1->click();
156   SelectionIntoArgument();
157   resize(100,100);
158 }
159
160 //=================================================================================
161 // function : ClickOnOk()
162 // purpose  :
163 //=================================================================================
164 void GroupGUI_BooleanDlg::ClickOnOk()
165 {
166   setIsApplyAndClose(true);
167   if (ClickOnApply())
168     ClickOnCancel();
169 }
170
171 //=================================================================================
172 // function : ClickOnApply()
173 // purpose  :
174 //=================================================================================
175 bool GroupGUI_BooleanDlg::ClickOnApply()
176 {
177   if (!onAccept())
178     return false;
179
180   initName();
181   // activate selection and connect selection manager
182   myGroup->PushButton1->click();
183   return true;
184 }
185
186 //=================================================================================
187 // function : SelectionIntoArgument()
188 // purpose  : Called when selection is changed or on dialog initialization or activation
189 //=================================================================================
190 void GroupGUI_BooleanDlg::SelectionIntoArgument()
191 {
192   myEditCurrentArgument->setText("");
193
194   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
195   SALOME_ListIO aSelList;
196   aSelMgr->selectedObjects(aSelList);
197
198   QString aString = "";
199   GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
200
201   if (myEditCurrentArgument == myGroup->LineEdit1) {
202     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
203   }
204   else if ( myEditCurrentArgument == myGroup->LineEdit2 ) {
205     GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListTools, true);
206   }
207
208   myEditCurrentArgument->setText(aString);
209 }
210
211 //=================================================================================
212 // function : SetEditCurrentArgument()
213 // purpose  :
214 //=================================================================================
215 void GroupGUI_BooleanDlg::SetEditCurrentArgument()
216 {
217   QPushButton* send = (QPushButton*)sender();
218
219   if (send == myGroup->PushButton1) {
220     myEditCurrentArgument = myGroup->LineEdit1;
221
222     myGroup->PushButton2->setDown(false);
223     myGroup->LineEdit2->setEnabled(false);
224   }
225   else if (send == myGroup->PushButton2) {
226     myEditCurrentArgument = myGroup->LineEdit2;
227
228     myGroup->PushButton1->setDown(false);
229     myGroup->LineEdit1->setEnabled(false);
230   }
231
232   // enable line edit
233   myEditCurrentArgument->setEnabled(true);
234   myEditCurrentArgument->setFocus();
235   // after setFocus(), because it will be setDown(false) when loses focus
236   send->setDown(true);
237 }
238
239 //=================================================================================
240 // function : ActivateThisDialog()
241 // purpose  :
242 //=================================================================================
243 void GroupGUI_BooleanDlg::ActivateThisDialog()
244 {
245   GEOMBase_Skeleton::ActivateThisDialog();
246
247   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
248            this, SLOT(SelectionIntoArgument()));
249 }
250
251 //=================================================================================
252 // function : enterEvent()
253 // purpose  : when mouse enter onto the QWidget
254 //=================================================================================
255 void GroupGUI_BooleanDlg::enterEvent (QEvent*)
256 {
257   if (!mainFrame()->GroupConstructors->isEnabled())
258     ActivateThisDialog();
259 }
260
261 //=================================================================================
262 // function : createOperation
263 // purpose  :
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr GroupGUI_BooleanDlg::createOperation()
266 {
267   return getGeomEngine()->GetIGroupOperations(getStudyId());
268 }
269
270 //=================================================================================
271 // function : isValid
272 // purpose  :
273 //=================================================================================
274 bool GroupGUI_BooleanDlg::isValid (QString&)
275 {
276   return (myListShapes.length() > 0);
277 }
278
279 //=================================================================================
280 // function : execute
281 // purpose  :
282 //=================================================================================
283 bool GroupGUI_BooleanDlg::execute (ObjectList& objects)
284 {
285   GEOM::GEOM_Object_var anObj;
286
287   GEOM::GEOM_IGroupOperations_var anOper = GEOM::GEOM_IGroupOperations::_narrow(getOperation());
288   switch (myOperation) {
289   case UNION:
290     anObj = anOper->UnionListOfGroups(myListShapes);
291     break;
292   case INTERSECT:
293     anObj = anOper->IntersectListOfGroups(myListShapes);
294     break;
295   case CUT:
296     anObj = anOper->CutListOfGroups(myListShapes, myListTools);
297     break;
298   default:
299     ;
300   }
301   if (!anObj->_is_nil())
302     objects.push_back(anObj._retn());
303
304   return true;
305 }
306
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)
313 {
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);
318   }
319   return aFatherObj._retn();
320 }