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