]> SALOME platform Git repositories - modules/geom.git/blob - src/OperationGUI/OperationGUI_GetSharedShapesDlg.cxx
Salome HOME
Issue 0021055: EDF 1602 STUDY: Object browser reactualisation when creating an object
[modules/geom.git] / src / OperationGUI / OperationGUI_GetSharedShapesDlg.cxx
1 //  Copyright (C) 2007-2010  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   : OperationGUI_GetSharedShapesDlg.cxx
24 //  Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
25
26 #include "OperationGUI_GetSharedShapesDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <GEOMImpl_Types.hxx>
33
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_MessageBox.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40
41 #include <TopoDS_Iterator.hxx>
42 #include <TopoDS_Shape.hxx>
43
44 //=================================================================================
45 // class    : OperationGUI_GetSharedShapesDlg()
46 // purpose  : Constructs a OperationGUI_GetSharedShapesDlg which is a child of 'parent', with the
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 OperationGUI_GetSharedShapesDlg::OperationGUI_GetSharedShapesDlg
52 (GeometryGUI* theGeometryGUI, QWidget* parent)
53   : GEOMBase_Skeleton(theGeometryGUI, parent, false)
54 {
55   SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
56   QPixmap image0(aResMgr->loadPixmap("GEOM", tr("ICON_DLG_SHARED_SHAPES")));
57   QPixmap image2(aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
58
59   setWindowTitle(tr("GEOM_SHARED_SHAPES_TITLE"));
60
61   /***************************************************************/
62   mainFrame()->GroupConstructors->setTitle(tr("GEOM_GET_SHARED_SHAPES"));
63   mainFrame()->RadioButton1->setIcon(image0);
64   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
65   mainFrame()->RadioButton2->close();
66   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67   mainFrame()->RadioButton3->close();
68
69   GroupPoints = new DlgRef_2Sel1List1Check(centralWidget());
70   GroupPoints->GroupBox1->setTitle(tr("GEOM_SHARED_SHAPES_INPUT"));
71   GroupPoints->TextLabel1->setText(tr("GEOM_SHAPES"));
72   GroupPoints->TextLabel2->hide();
73   GroupPoints->TextLabel3->setText(tr("GEOM_SUBSHAPE_TYPE"));
74   GroupPoints->PushButton1->setIcon(image2);
75   GroupPoints->PushButton2->hide();
76   GroupPoints->LineEdit1->setReadOnly(true);
77   GroupPoints->LineEdit2->hide();
78   GroupPoints->LineEdit1->setEnabled(true);
79   GroupPoints->CheckButton1->hide();
80
81   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
82   layout->setMargin(0); layout->setSpacing(6);
83   layout->addWidget(GroupPoints);
84
85   /***************************************************************/
86
87   setHelpFileName("shared_shapes_page.html");
88
89   Init();
90 }
91
92 //=================================================================================
93 // function : ~OperationGUI_GetSharedShapesDlg()
94 // purpose  : Destroys the object and frees any allocated resources
95 //=================================================================================
96 OperationGUI_GetSharedShapesDlg::~OperationGUI_GetSharedShapesDlg()
97 {
98   // no need to delete child widgets, Qt does it all for us
99 }
100
101 //=================================================================================
102 // function : Init()
103 // purpose  :
104 //=================================================================================
105 void OperationGUI_GetSharedShapesDlg::Init()
106 {
107   /* type for sub shape selection */
108   GroupPoints->ComboBox1->addItem(tr("GEOM_SOLID"));
109   GroupPoints->ComboBox1->addItem(tr("GEOM_SHELL"));
110   GroupPoints->ComboBox1->addItem(tr("GEOM_FACE"));
111   GroupPoints->ComboBox1->addItem(tr("GEOM_WIRE"));
112   GroupPoints->ComboBox1->addItem(tr("GEOM_EDGE"));
113   GroupPoints->ComboBox1->addItem(tr("GEOM_VERTEX"));
114
115   GroupPoints->ComboBox1->setCurrentIndex(0);
116
117   showOnlyPreviewControl();
118
119   /* signals and slots connections */
120   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
121   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
122
123   connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
124
125   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126
127   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128
129   connect(GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(ComboTextChanged()));
130
131   connect(myGeomGUI->getApp()->selectionMgr(),
132            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
133
134   //initName(getNewObjectName());
135   initName(getPrefixByType());
136
137   ConstructorsClicked(0);
138   GroupPoints->PushButton1->click();
139 }
140
141 //=================================================================================
142 // function : ConstructorsClicked()
143 // purpose  : Radio button management
144 //=================================================================================
145 void OperationGUI_GetSharedShapesDlg::ConstructorsClicked (int constructorId)
146 {
147   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
148   globalSelection();
149
150   myListShapes.length(0);
151
152   GroupPoints->ComboBox1->setCurrentIndex(0);
153   GroupPoints->PushButton1->setDown(true);
154
155   myEditCurrentArgument = GroupPoints->LineEdit1;
156   GroupPoints->LineEdit1->clear();
157
158   qApp->processEvents();
159   updateGeometry();
160   resize(minimumSizeHint());
161
162   myEditCurrentArgument->setFocus();
163   connect(myGeomGUI->getApp()->selectionMgr(),
164           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
165   SelectionIntoArgument();
166 }
167
168 //=================================================================================
169 // function : ClickOnOk()
170 // purpose  :
171 //=================================================================================
172 void OperationGUI_GetSharedShapesDlg::ClickOnOk()
173 {
174   setIsApplyAndClose( true );
175   if (ClickOnApply())
176     ClickOnCancel();
177 }
178
179 //=================================================================================
180 // function : ClickOnApply()
181 // purpose  :
182 //=================================================================================
183 bool OperationGUI_GetSharedShapesDlg::ClickOnApply()
184 {
185   if (!onAccept())
186     return false;
187
188   //initName(getNewObjectName());
189   initName(getPrefixByType());
190
191   return true;
192 }
193
194 //=================================================================================
195 // function : SelectionIntoArgument()
196 // purpose  : Called when selection as changed or other case
197 //=================================================================================
198 void OperationGUI_GetSharedShapesDlg::SelectionIntoArgument()
199 {
200   myEditCurrentArgument->setText("");
201   QString aString = "";
202
203   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
204   SALOME_ListIO aSelList;
205   aSelMgr->selectedObjects(aSelList);
206
207   int nbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aString, true);
208
209   if (nbSel < 1) {
210     myListShapes.length(0);
211   }
212
213   GEOMBase::ConvertListOfIOInListOfGO(aSelList, myListShapes, true);
214   if (!myListShapes.length())
215     return;
216
217   myEditCurrentArgument->setText(aString);
218   processPreview();
219 }
220
221 //=================================================================================
222 // function : SetEditCurrentArgument()
223 // purpose  :
224 //=================================================================================
225 void OperationGUI_GetSharedShapesDlg::SetEditCurrentArgument()
226 {
227   QPushButton* send = (QPushButton*)sender();
228
229   if (send == GroupPoints->PushButton1) {
230     myEditCurrentArgument = GroupPoints->LineEdit1;
231     GroupPoints->LineEdit1->setEnabled(true);
232   }
233
234   globalSelection(GEOM_ALLSHAPES);
235
236   myEditCurrentArgument->setFocus();
237   SelectionIntoArgument();
238   send->setDown(true);
239 }
240
241 //=================================================================================
242 // function : ActivateThisDialog()
243 // purpose  :
244 //=================================================================================
245 void OperationGUI_GetSharedShapesDlg::ActivateThisDialog()
246 {
247   GEOMBase_Skeleton::ActivateThisDialog();
248   connect(myGeomGUI->getApp()->selectionMgr(),
249           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
250
251   ConstructorsClicked(getConstructorId());
252   processPreview();
253 }
254
255 //=================================================================================
256 // function : enterEvent()
257 // purpose  :
258 //=================================================================================
259 void OperationGUI_GetSharedShapesDlg::enterEvent(QEvent*)
260 {
261   if (!mainFrame()->GroupConstructors->isEnabled())
262     this->ActivateThisDialog();
263 }
264
265 //=======================================================================
266 //function : ComboTextChanged
267 //purpose  :
268 //=======================================================================
269 void OperationGUI_GetSharedShapesDlg::ComboTextChanged()
270 {
271   //initName(getNewObjectName());
272   initName(getPrefixByType());
273   processPreview();
274 }
275
276 //=================================================================================
277 // function : GetType()
278 // purpose  :
279 //=================================================================================
280 int OperationGUI_GetSharedShapesDlg::GetType() const
281 {
282   int aLimit = GroupPoints->ComboBox1->currentIndex();
283
284   switch (aLimit) {
285   case 0:  aLimit = GEOM::SOLID ; break;
286   case 1:  aLimit = GEOM::SHELL ; break;
287   case 2:  aLimit = GEOM::FACE  ; break;
288   case 3:  aLimit = GEOM::WIRE  ; break;
289   case 4:  aLimit = GEOM::EDGE  ; break;
290   case 5:  aLimit = GEOM::VERTEX; break;
291   default: aLimit = GEOM::SHAPE ;
292   }
293
294   return aLimit;
295 }
296
297 //=================================================================================
298 // function : createOperation
299 // purpose  :
300 //=================================================================================
301 GEOM::GEOM_IOperations_ptr OperationGUI_GetSharedShapesDlg::createOperation()
302 {
303   return getGeomEngine()->GetIShapesOperations(getStudyId());
304 }
305
306 //=================================================================================
307 // function : isValid
308 // purpose  :
309 //=================================================================================
310 bool OperationGUI_GetSharedShapesDlg::isValid (QString& msg)
311 {
312   if (myListShapes.length() < 2) {
313     msg = tr("MSG_SHARED_SHAPES_TOO_FEW_SHAPES");
314     return false;
315   }
316   return true;
317 }
318
319 //=================================================================================
320 // function : execute
321 // purpose  :
322 //=================================================================================
323 bool OperationGUI_GetSharedShapesDlg::execute (ObjectList& objects)
324 {
325   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow(getOperation());
326   GEOM::ListOfGO_var aList = anOper->GetSharedShapesMulti(myListShapes, GetType());
327
328   if (!aList->length())
329     return false;
330
331   if (aList->length() > 1)
332     myMainFrame->ResultName->setText(getPrefixByType());
333
334   for (int i = 0, n = aList->length(); i < n; i++)
335     objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
336
337   return objects.size();
338 }
339
340 //================================================================
341 // Function : getFather
342 // Purpose  : Get father object for object to be added in study
343 //            ( called with addInStudy method )
344 //================================================================
345 GEOM::GEOM_Object_ptr OperationGUI_GetSharedShapesDlg::getFather (GEOM::GEOM_Object_ptr)
346 {
347   if (myListShapes.length() > 0)
348     //return myListShapes[0]._retn();
349     return myListShapes[0];
350   return NULL;
351 }
352
353 //================================================================
354 // Function : getPrefixByType
355 // Purpose  :
356 //================================================================
357 QString OperationGUI_GetSharedShapesDlg::getPrefixByType () const
358 {
359   QString aPref;
360
361   int aLimit = GroupPoints->ComboBox1->currentIndex();
362
363   switch (aLimit) {
364   case 0:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SOLID")) ; break;
365   case 1:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHELL")) ; break;
366   case 2:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_FACE"))  ; break;
367   case 3:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_WIRE"))  ; break;
368   case 4:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_EDGE"))  ; break;
369   case 5:  aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_VERTEX")); break;
370   default: aPref = tr("GEOM_SHARED_SHAPE").arg(tr("GEOM_SHAPE")) ;
371   }
372
373   return aPref;
374 }