]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipePathDlg.cxx
Salome HOME
Merge from V6_main 13/12/2012
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipePathDlg.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   : GenerationGUI_PipePathDlg.cxx
24
25 #include "GenerationGUI_PipePathDlg.h"
26
27 #include <DlgRef.h>
28 #include <GeometryGUI.h>
29 #include <GEOMBase.h>
30
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TColStd_MapOfInteger.hxx>
43
44 #include <GEOMImpl_Types.hxx>
45
46 //=================================================================================
47 // class    : GenerationGUI_PipePathDlg()
48 // purpose  : Constructs a GenerationGUI_PipePathDlg which is a child of 'parent', with the
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            TRUE to construct a modal dialog.
52 //=================================================================================
53 GenerationGUI_PipePathDlg::GenerationGUI_PipePathDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
54                                                       bool modal, Qt::WindowFlags fl)
55   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
56 {
57   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_PATH")));
58   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
59
60   setWindowTitle(tr("GEOM_PIPE_PATH_TITLE"));
61
62   /***************************************************************/
63   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE_PATH"));
64   mainFrame()->RadioButton1->setIcon(image0);
65   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
66   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67   mainFrame()->RadioButton2->close();
68   mainFrame()->RadioButton3->close();
69
70   GroupPoints = new DlgRef_3Sel1Check(centralWidget());
71
72   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
73   GroupPoints->TextLabel1->setText(tr("GEOM_PIPE_LIKE_SHAPE"));
74   GroupPoints->TextLabel2->setText(tr("GEOM_PIPE_BASE1_OBJECT"));
75   GroupPoints->TextLabel3->setText(tr("GEOM_PIPE_BASE2_OBJECT"));
76   GroupPoints->PushButton1->setIcon(image1);
77   GroupPoints->PushButton2->setIcon(image1);
78   GroupPoints->PushButton3->setIcon(image1);
79   GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
80
81   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
82   layout->setMargin(0);
83   layout->setSpacing(6);
84   layout->addWidget(GroupPoints);
85   /***************************************************************/
86
87   setHelpFileName("create_pipe_path_page.html");
88
89   // Initialisation
90   Init();
91 }
92
93 //=================================================================================
94 // function : ~GenerationGUI_PipePathDlg()
95 // purpose  : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_PipePathDlg::~GenerationGUI_PipePathDlg()
98 {
99   // no need to delete child widgets, Qt does it all for us
100 }
101
102 //=================================================================================
103 // function : Init()
104 // purpose  :
105 //=================================================================================
106 void GenerationGUI_PipePathDlg::Init()
107 {
108   // init variables
109   GroupPoints->LineEdit1->setReadOnly(true);
110   GroupPoints->LineEdit2->setReadOnly(true);
111   GroupPoints->LineEdit3->setReadOnly(true);
112
113   GroupPoints->LineEdit1->setText("");
114   GroupPoints->LineEdit2->setText("");
115   GroupPoints->LineEdit3->setText("");
116
117   myShape.nullify();
118
119   GroupPoints->CheckButton1->setEnabled(false);
120
121   showOnlyPreviewControl();
122
123   // signals and slots connections
124   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
125   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
126
127   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
128   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
129   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
130
131   connect(GroupPoints->CheckButton1,   SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
132
133   initName(tr("GEOM_PIPE_PATH"));
134
135   updateGeometry();
136   resize(100,100);
137
138   GroupPoints->PushButton1->click();
139   SelectionIntoArgument();
140 }
141
142 //=================================================================================
143 // function : SelectionBittonClicked()
144 // purpose  : Selection type Radio button management
145 //=================================================================================
146 void GenerationGUI_PipePathDlg::SelectionTypeButtonClicked()
147 {
148   globalSelection();
149   if (GroupPoints->CheckButton1->isChecked()) {
150     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
151   }
152   else {
153     TColStd_MapOfInteger aMap;
154     aMap.Add(GEOM_FACE);
155     aMap.Add(GEOM_WIRE);
156     aMap.Add(GEOM_EDGE);
157     globalSelection(aMap);
158   }
159   processPreview();
160 }
161
162 //=================================================================================
163 // function : ClickOnOk()
164 // purpose  :
165 //=================================================================================
166 void GenerationGUI_PipePathDlg::ClickOnOk()
167 {
168   setIsApplyAndClose(true);
169   if (ClickOnApply())
170     ClickOnCancel();
171 }
172
173 //=================================================================================
174 // function : ClickOnApply()
175 // purpose  :
176 //=================================================================================
177 bool GenerationGUI_PipePathDlg::ClickOnApply()
178 {
179   if (!onAccept())
180     return false;
181
182   initName();
183   // activate selection and connect selection manager
184   GroupPoints->PushButton1->click();
185   return true;
186 }
187
188 //=================================================================================
189 // function : SelectionIntoArgument()
190 // purpose  : Called when selection is changed or on dialog initialization or activation
191 //=================================================================================
192 void GenerationGUI_PipePathDlg::SelectionIntoArgument()
193 {
194   erasePreview();
195   myEditCurrentArgument->setText("");
196
197   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
198     QList<TopAbs_ShapeEnum> types;
199     types << TopAbs_SOLID << TopAbs_SHELL << TopAbs_FACE;
200     myShape = getSelected(types);
201     if (myShape) {
202       QString aName = GEOMBase::GetName(myShape.get());
203       myEditCurrentArgument->setText(aName);
204       if (myBase1Objects.isEmpty())
205         GroupPoints->PushButton2->click();
206       else if (myBase2Objects.isEmpty())
207         GroupPoints->PushButton3->click();
208     }
209   }
210   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
211     myBase1Objects.clear();
212     QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
213     for (int i = 0; i < objects.count(); i++) {
214       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
215      if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
216         myBase1Objects << objects[i];
217     }
218     int nbObj = myBase1Objects.count();
219     if (nbObj) {
220       QString aName =
221         nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase1Objects[0].get());
222       myEditCurrentArgument->setText(aName);
223     }
224   }
225   else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
226     myBase2Objects.clear();
227     QList<GEOM::GeomObjPtr> objects = getSelected(TopAbs_SHAPE, -1);
228     for (int i = 0; i < objects.count(); i++) {
229       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
230       if (GEOM::FACE <= stype && stype <= GEOM::EDGE)
231         myBase2Objects << objects[i];
232     }
233     int nbObj = myBase2Objects.count();
234     if (nbObj) {
235       QString aName =
236         nbObj > 1 ? QString("%1_objects").arg(nbObj) : GEOMBase::GetName(myBase2Objects[0].get());
237       myEditCurrentArgument->setText(aName);
238     }
239   }
240
241   processPreview();
242 }
243
244 //=================================================================================
245 // function : SetEditCurrentArgument()
246 // purpose  :
247 //=================================================================================
248 void GenerationGUI_PipePathDlg::SetEditCurrentArgument()
249 {
250   QPushButton* send = (QPushButton*)sender();
251
252   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
253
254   globalSelection(GEOM_ALLSHAPES);
255
256   GroupPoints->PushButton1->setDown(false);
257   GroupPoints->PushButton2->setDown(false);
258   GroupPoints->PushButton3->setDown(false);
259   GroupPoints->LineEdit1->setEnabled(false);
260   GroupPoints->LineEdit2->setEnabled(false);
261   GroupPoints->LineEdit3->setEnabled(false);
262
263   if (send == GroupPoints->PushButton1) {
264     myEditCurrentArgument = GroupPoints->LineEdit1;
265     GroupPoints->CheckButton1->setEnabled(false);
266   }
267   else if (send == GroupPoints->PushButton2) {
268     myEditCurrentArgument = GroupPoints->LineEdit2;
269
270     if (GroupPoints->CheckButton1->isChecked()) {
271       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
272     }
273     else {
274       TColStd_MapOfInteger aMap;
275       aMap.Add(GEOM_FACE);
276       aMap.Add(GEOM_WIRE);
277       aMap.Add(GEOM_EDGE);
278       globalSelection(aMap);
279     }
280     GroupPoints->CheckButton1->setEnabled(true);
281   }
282   else if (send == GroupPoints->PushButton3) {
283     myEditCurrentArgument = GroupPoints->LineEdit3;
284
285     if (GroupPoints->CheckButton1->isChecked()) {
286       localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
287     }
288     else {
289       TColStd_MapOfInteger aMap;
290       aMap.Add(GEOM_FACE);
291       aMap.Add(GEOM_WIRE);
292       aMap.Add(GEOM_EDGE);
293       globalSelection(aMap);
294     }
295     GroupPoints->CheckButton1->setEnabled(true);
296   }
297   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
298           this, SLOT(SelectionIntoArgument()));
299
300   // enable line edit
301   myEditCurrentArgument->setEnabled(true);
302   myEditCurrentArgument->setFocus();
303   // after setFocus(), because it will be setDown(false) when loses focus
304   send->setDown(true);
305
306   // seems we need it only to avoid preview disappearing, caused by selection mode change
307   processPreview();
308 }
309
310 //=================================================================================
311 // function : ActivateThisDialog()
312 // purpose  :
313 //=================================================================================
314 void GenerationGUI_PipePathDlg::ActivateThisDialog()
315 {
316   GEOMBase_Skeleton::ActivateThisDialog();
317
318   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
319           this, SLOT(SelectionIntoArgument()));
320
321   GroupPoints->PushButton1->click();
322   SelectionIntoArgument();
323 }
324
325 //=================================================================================
326 // function : enterEvent()
327 // purpose  : when mouse enter onto the QWidget
328 //=================================================================================
329 void GenerationGUI_PipePathDlg::enterEvent (QEvent*)
330 {
331   if (!mainFrame()->GroupConstructors->isEnabled())
332     ActivateThisDialog();
333 }
334
335 //=================================================================================
336 // function : createOperation
337 // purpose  :
338 //=================================================================================
339 GEOM::GEOM_IOperations_ptr GenerationGUI_PipePathDlg::createOperation()
340 {
341   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
342 }
343
344 //=================================================================================
345 // function : isValid
346 // purpose  :
347 //=================================================================================
348 bool GenerationGUI_PipePathDlg::isValid (QString&)
349 {
350   bool ok = myShape && !myBase1Objects.isEmpty() && !myBase2Objects.isEmpty();
351   return ok;
352 }
353
354 //=================================================================================
355 // function : execute
356 // purpose  :
357 //=================================================================================
358 bool GenerationGUI_PipePathDlg::execute (ObjectList& objects)
359 {
360   GEOM::ListOfGO_var aBase1 = new GEOM::ListOfGO();
361   GEOM::ListOfGO_var aBase2 = new GEOM::ListOfGO();
362
363   aBase1->length(myBase1Objects.count());
364   aBase2->length(myBase2Objects.count());
365
366   int i;
367   for (i = 0; i < myBase1Objects.count(); i++)
368     aBase1[i] = myBase1Objects[i].copy();
369   for (i = 0; i < myBase2Objects.count(); i++)
370     aBase2[i] = myBase2Objects[i].copy();
371
372   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
373   GEOM::GEOM_Object_var anObj = anOper->RestorePathEdges(myShape.get(), aBase1.in(), aBase2.in());
374     
375   if (!anObj->_is_nil())
376     objects.push_back(anObj._retn());
377
378   return true;
379 }
380
381 //=================================================================================
382 // function : addSubshapeToStudy
383 // purpose  : virtual method to add new SubObjects if local selection
384 //=================================================================================
385 void GenerationGUI_PipePathDlg::addSubshapesToStudy()
386 {
387   int i;
388   for (i = 0; i < myBase1Objects.count(); i++)
389     GEOMBase::PublishSubObject(myBase1Objects[i].get());
390   for (i = 0; i < myBase2Objects.count(); i++)
391     GEOMBase::PublishSubObject(myBase2Objects[i].get());
392 }