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