]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
0bc5e05f1b3311df218b36b5bb0f995d390447ee
[modules/geom.git] / src / GenerationGUI / GenerationGUI_PipeDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  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 // File   : GenerationGUI_PipeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
24 //
25
26 #include "GenerationGUI_PipeDlg.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 <TopoDS_Shape.hxx>
38 #include <TopoDS.hxx>
39 #include <TopExp.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42
43 #include <GEOMImpl_Types.hxx>
44
45 //=================================================================================
46 // class    : GenerationGUI_PipeDlg()
47 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
48 //            name 'name' and widget flags set to 'f'.
49 //            The dialog will by default be modeless, unless you set 'modal' to
50 //            TRUE to construct a modal dialog.
51 //=================================================================================
52 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
53                                               bool modal, Qt::WindowFlags fl)
54   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
55 {
56   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE")));
57   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
59
60   setWindowTitle(tr("GEOM_PIPE_TITLE"));
61
62   /***************************************************************/
63   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
64   mainFrame()->RadioButton1->setIcon(image0);
65   mainFrame()->RadioButton2->setIcon(image2);
66   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
67   mainFrame()->RadioButton3->close();
68
69   GroupPoints = new DlgRef_3Sel(centralWidget());
70
71   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
72   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
73   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
74   GroupPoints->TextLabel3->setText(tr("GEOM_VECTOR"));
75   GroupPoints->PushButton1->setIcon(image1);
76   GroupPoints->PushButton2->setIcon(image1);
77   GroupPoints->PushButton3->setIcon(image1);
78
79   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
80   layout->setMargin(0); layout->setSpacing(6);
81   layout->addWidget(GroupPoints);
82   /***************************************************************/
83
84   setHelpFileName("create_extrusion_alongpath_page.html");
85
86   // Initialisation
87   Init();
88 }
89
90 //=================================================================================
91 // function : ~GenerationGUI_PipeDlg()
92 // purpose  : Destroys the object and frees any allocated resources
93 //=================================================================================
94 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
95 {
96   // no need to delete child widgets, Qt does it all for us
97 }
98
99 //=================================================================================
100 // function : Init()
101 // purpose  :
102 //=================================================================================
103 void GenerationGUI_PipeDlg::Init()
104 {
105   // init variables
106   GroupPoints->LineEdit1->setReadOnly(true);
107   GroupPoints->LineEdit2->setReadOnly(true);
108   GroupPoints->LineEdit3->setReadOnly(true);
109
110   GroupPoints->LineEdit1->setText("");
111   GroupPoints->LineEdit2->setText("");
112   GroupPoints->LineEdit3->setText("");
113   myBase = myPath = myVec = GEOM::GEOM_Object::_nil();
114   myOkBase = myOkPath = myOkVec = false;
115
116   // signals and slots connections
117   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
119
120   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
121
122   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125
126   connect(GroupPoints->LineEdit1,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127   connect(GroupPoints->LineEdit2,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
128   connect(GroupPoints->LineEdit3,   SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129
130   initName(tr("GEOM_PIPE"));
131
132   GroupPoints->TextLabel3->hide();
133   GroupPoints->PushButton3->hide();
134   GroupPoints->LineEdit3->hide();
135   ConstructorsClicked(0);
136
137   GroupPoints->PushButton1->click();
138   SelectionIntoArgument();
139 }
140
141 //=================================================================================
142 // function : ConstructorsClicked()
143 // purpose  : Radio button management
144 //=================================================================================
145 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
146 {
147   erasePreview();
148
149   switch (constructorId)
150   {
151     case 0:
152     {
153       GroupPoints->TextLabel3->hide();
154       GroupPoints->PushButton3->hide();
155       GroupPoints->LineEdit3->hide();
156       break;
157     }
158     case 1:
159     {
160       GroupPoints->TextLabel3->show();
161       GroupPoints->PushButton3->show();
162       GroupPoints->LineEdit3->show();
163       break;
164     }
165   }
166
167   displayPreview();
168 }
169
170 //=================================================================================
171 // function : ClickOnOk()
172 // purpose  :
173 //=================================================================================
174 void GenerationGUI_PipeDlg::ClickOnOk()
175 {
176   if (ClickOnApply())
177     ClickOnCancel();
178 }
179
180 //=================================================================================
181 // function : ClickOnApply()
182 // purpose  :
183 //=================================================================================
184 bool GenerationGUI_PipeDlg::ClickOnApply()
185 {
186   if (!onAccept())
187     return false;
188
189   initName();
190   if ( getConstructorId() != 1 )
191         ConstructorsClicked( getConstructorId() );
192   // activate selection and connect selection manager
193   GroupPoints->PushButton1->click();
194   return true;
195 }
196
197 //=================================================================================
198 // function : SelectionIntoArgument()
199 // purpose  : Called when selection is changed or on dialog initialization or activation
200 //=================================================================================
201 void GenerationGUI_PipeDlg::SelectionIntoArgument()
202 {
203   erasePreview();
204   myEditCurrentArgument->setText("");
205   if      (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
206   else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
207   else if (myEditCurrentArgument == GroupPoints->LineEdit3) myOkVec  = false;
208
209   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
210   SALOME_ListIO aSelList;
211   aSelMgr->selectedObjects(aSelList);
212
213   if (aSelList.Extent() != 1)
214     return;
215
216   // nbSel == 1
217   Standard_Boolean testResult = Standard_False;
218   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
219
220   if (!testResult || aSelectedObject->_is_nil())
221     return;
222
223   TopoDS_Shape S;
224   if (!GEOMBase::GetShape(aSelectedObject, S))
225     return;
226
227   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
228     if (S.ShapeType() == TopAbs_COMPSOLID ||
229         S.ShapeType() == TopAbs_COMPOUND ||
230         S.ShapeType() == TopAbs_SOLID ||
231         S.ShapeType() == TopAbs_SHAPE)
232       return;
233     if ( getConstructorId() == 1 && 
234          (S.ShapeType() == TopAbs_SHELL || 
235           S.ShapeType() == TopAbs_VERTEX))
236       return;
237
238     myBase = aSelectedObject;
239     myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
240     myOkBase = true;
241     if (!myOkPath)
242       GroupPoints->PushButton2->click();
243     else if (!myOkVec)
244       GroupPoints->PushButton3->click();
245   }
246   else if (myEditCurrentArgument == GroupPoints->LineEdit2 || 
247            myEditCurrentArgument == GroupPoints->LineEdit3) {
248     myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
249     bool myOk = false;
250     QString aName = GEOMBase::GetName(aSelectedObject);
251
252     if (aSelectedObject != myBase) {
253       TColStd_IndexedMapOfInteger aMap;
254       aSelMgr->GetIndexes(aSelList.First(), aMap);
255       if (aMap.Extent() == 1) {
256         int anIndex = aMap(1);
257         aName.append(":edge_" + QString::number(anIndex));
258
259         //Find SubShape Object in Father
260         GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
261
262         if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
263           GEOM::GEOM_IShapesOperations_var aShapesOp =
264             getGeomEngine()->GetIShapesOperations(getStudyId());
265           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
266           myOk = true;
267         }
268         else { // get Object from study
269           aSelectedObject = aFindedObject;
270           myOk = true;
271         }
272       }
273       else {
274         myOk = true;
275         if (S.ShapeType() != TopAbs_EDGE) {
276           aSelectedObject = GEOM::GEOM_Object::_nil();
277           aName = "";
278           myOk = false;
279         }
280       }
281       if (myEditCurrentArgument == GroupPoints->LineEdit2) {
282         myPath = aSelectedObject;
283         myOkPath = myOk;
284       }
285       else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
286         myVec = aSelectedObject;
287         myOkVec = myOk;
288       }
289     }
290     myEditCurrentArgument->setText(aName);
291     if (myOkPath) {
292       if (!myOkBase)
293         GroupPoints->PushButton1->click();
294       else if (!myOkVec)
295         GroupPoints->PushButton3->click();
296     }
297     else if (myOkVec) {
298       if (!myOkBase)
299         GroupPoints->PushButton1->click();
300       else if (!myOkPath)
301         GroupPoints->PushButton2->click();
302     }
303   }
304
305   // clear selection
306   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
307   myGeomGUI->getApp()->selectionMgr()->clearSelected();
308   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
309           this, SLOT(SelectionIntoArgument()));
310
311   displayPreview();
312 }
313
314 //=================================================================================
315 // function : SetEditCurrentArgument()
316 // purpose  :
317 //=================================================================================
318 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
319 {
320   QPushButton* send = (QPushButton*)sender();
321
322   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
323   globalSelection(GEOM_ALLSHAPES);
324   GroupPoints->PushButton1->setDown(false);
325   GroupPoints->PushButton2->setDown(false);
326   GroupPoints->PushButton3->setDown(false);
327   GroupPoints->LineEdit1->setEnabled(false);
328   GroupPoints->LineEdit2->setEnabled(false);
329   GroupPoints->LineEdit3->setEnabled(false);
330   if (send == GroupPoints->PushButton1) {
331     myEditCurrentArgument = GroupPoints->LineEdit1;
332   }
333   else if (send == GroupPoints->PushButton2) {
334     myEditCurrentArgument = GroupPoints->LineEdit2;
335
336     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
337   }
338   else if(send == GroupPoints->PushButton3) {
339     myEditCurrentArgument = GroupPoints->LineEdit3;
340
341     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
342   }
343   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
344           this, SLOT(SelectionIntoArgument()));
345
346   // enable line edit
347   myEditCurrentArgument->setEnabled(true);
348   myEditCurrentArgument->setFocus();
349   // after setFocus(), because it will be setDown(false) when loses focus
350   send->setDown(true);
351
352   // seems we need it only to avoid preview disappearing, caused by selection mode change
353   displayPreview();
354 }
355
356 //=================================================================================
357 // function : LineEditReturnPressed()
358 // purpose  :
359 //=================================================================================
360 void GenerationGUI_PipeDlg::LineEditReturnPressed()
361 {
362   QLineEdit* send = (QLineEdit*)sender();
363   if (send == GroupPoints->LineEdit1 ||
364       send == GroupPoints->LineEdit2 ||
365       send == GroupPoints->LineEdit3) {
366     myEditCurrentArgument = send;
367     GEOMBase_Skeleton::LineEditReturnPressed();
368   }
369 }
370
371 //=================================================================================
372 // function : ActivateThisDialog()
373 // purpose  :
374 //=================================================================================
375 void GenerationGUI_PipeDlg::ActivateThisDialog()
376 {
377   GEOMBase_Skeleton::ActivateThisDialog();
378
379   // reinit, because some selected objects could be removed
380   Init();
381 }
382
383 //=================================================================================
384 // function : enterEvent()
385 // purpose  : when mouse enter onto the QWidget
386 //=================================================================================
387 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
388 {
389   if (!mainFrame()->GroupConstructors->isEnabled())
390     ActivateThisDialog();
391 }
392
393 //=================================================================================
394 // function : createOperation
395 // purpose  :
396 //=================================================================================
397 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
398 {
399   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
400 }
401
402 //=================================================================================
403 // function : isValid
404 // purpose  :
405 //=================================================================================
406 bool GenerationGUI_PipeDlg::isValid (QString&)
407 {
408   switch ( getConstructorId() ) {
409   case 0 :
410     return myOkBase && myOkPath;
411   case 1 :
412     return myOkBase && myOkPath && myOkVec;
413   }
414 }
415
416 //=================================================================================
417 // function : execute
418 // purpose  :
419 //=================================================================================
420 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
421 {
422   GEOM::GEOM_Object_var anObj;
423
424   switch ( getConstructorId() ) {
425   case 0 :
426     anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakePipe(myBase, myPath);
427     break;
428   case 1 :
429     anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->
430       MakePipeBiNormalAlongVector(myBase, myPath, myVec);
431     break;
432   }
433
434   if (!anObj->_is_nil())
435     objects.push_back(anObj._retn());
436
437   return true;
438 }
439
440 //=================================================================================
441 // function : addSubshapeToStudy
442 // purpose  : virtual method to add new SubObjects if local selection
443 //=================================================================================
444 void GenerationGUI_PipeDlg::addSubshapesToStudy()
445 {
446   QMap<QString, GEOM::GEOM_Object_var> objMap;
447
448   objMap[GroupPoints->LineEdit2->text()] = myPath;
449
450   addSubshapesToFather(objMap);
451 }