]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[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
71   setCaption(tr("GEOM_PIPE_TITLE"));
72
73   /***************************************************************/
74   GroupConstructors->setTitle(tr("GEOM_PIPE"));
75   RadioButton1->setPixmap(image0);
76   RadioButton2->close(TRUE);
77   RadioButton3->close(TRUE);
78
79   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
80   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
81   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
82   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
83   GroupPoints->PushButton1->setPixmap(image1);
84   GroupPoints->PushButton2->setPixmap(image1);
85   GroupPoints->LineEdit1->setReadOnly( true );
86   GroupPoints->LineEdit2->setReadOnly( true );
87
88   Layout1->addWidget(GroupPoints, 2, 0);
89   /***************************************************************/
90
91   setHelpFileName("create_extrusion_alongpath_page.html");
92
93   /* Initialisations */
94   Init();
95 }
96
97
98 //=================================================================================
99 // function : ~GenerationGUI_PipeDlg()
100 // purpose  : Destroys the object and frees any allocated resources
101 //=================================================================================
102 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
103 {
104   /* no need to delete child widgets, Qt does it all for us */
105 }
106
107
108 //=================================================================================
109 // function : Init()
110 // purpose  :
111 //=================================================================================
112 void GenerationGUI_PipeDlg::Init()
113 {
114   /* init variables */
115   myEditCurrentArgument = GroupPoints->LineEdit1;
116   GroupPoints->LineEdit1->setReadOnly( true );
117   GroupPoints->LineEdit2->setReadOnly( true );
118
119   myOkBase = myOkPath = false;
120
121   /* signals and slots connections */
122   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
123   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124
125   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
126   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
127
128   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
129   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
130   
131   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
132           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
133
134   initName(tr("GEOM_PIPE"));
135
136   //  globalSelection( GEOM_ALLSHAPES );
137 }
138
139
140 //=================================================================================
141 // function : ClickOnOk()
142 // purpose  :
143 //=================================================================================
144 void GenerationGUI_PipeDlg::ClickOnOk()
145 {
146   if ( ClickOnApply() )
147     ClickOnCancel();
148 }
149
150
151 //=================================================================================
152 // function : ClickOnAply()
153 // purpose  :
154 //=================================================================================
155 bool GenerationGUI_PipeDlg::ClickOnApply()
156 {
157   if ( !onAccept() )
158     return false;
159
160   initName();
161   return true;
162 }
163
164
165 //=================================================================================
166 // function : SelectionIntoArgument()
167 // purpose  : Called when selection has changed
168 //=================================================================================
169 void GenerationGUI_PipeDlg::SelectionIntoArgument()
170 {
171   erasePreview();
172   myEditCurrentArgument->setText("");
173   
174   if(IObjectCount() != 1) {
175     if(myEditCurrentArgument == GroupPoints->LineEdit1)
176       myOkBase = false;
177     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
178       myOkPath = false;
179     return;
180   }
181   
182   // nbSel == 1
183   Standard_Boolean testResult = Standard_False;
184   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
185     
186   if (!testResult)
187     return;
188   
189   TopoDS_Shape S;
190   
191   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
192     myOkBase = false;
193     
194     if(!GEOMBase::GetShape(aSelectedObject, S) ||
195        S.ShapeType() == TopAbs_COMPSOLID || 
196        S.ShapeType() == TopAbs_COMPOUND || 
197        S.ShapeType() == TopAbs_SOLID || 
198        S.ShapeType() == TopAbs_SHAPE) 
199       return;
200     
201     myBase = aSelectedObject;
202     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
203     myOkBase = true;
204   }
205   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
206     myOkPath = false;
207     
208     if( !GEOMBase::GetShape(aSelectedObject, S) ) 
209       return;
210
211     QString aName = GEOMBase::GetName( aSelectedObject );
212     
213     if ( testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase)
214       {
215         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
216         TColStd_IndexedMapOfInteger aMap;
217
218         aSelMgr->GetIndexes( firstIObject(), aMap );
219         if ( aMap.Extent() == 1 )
220           {
221             int anIndex = aMap( 1 );
222             aName.append( ":edge_" + QString::number( anIndex ) );
223
224             //Find SubShape Object in Father
225             GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
226             
227             if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
228               GEOM::GEOM_IShapesOperations_var aShapesOp =
229                 getGeomEngine()->GetIShapesOperations( getStudyId() );
230               myPath = aShapesOp->GetSubShape(aSelectedObject, anIndex);
231               myOkPath = true;
232             }
233             else {  // get Object from study
234               myPath = aFindedObject;
235               myOkPath = true;
236             }
237           }
238         else {
239           myOkPath = true;
240           if (S.ShapeType() != TopAbs_EDGE) {
241             aSelectedObject = GEOM::GEOM_Object::_nil();
242             aName = "";
243             myOkPath = false;
244           }
245           myPath = aSelectedObject;
246         }
247       }
248     myEditCurrentArgument->setText( aName );
249   }
250   
251   displayPreview();
252 }
253
254
255 //=================================================================================
256 // function : SetEditCurrentArgument()
257 // purpose  :
258 //=================================================================================
259 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
260 {
261   QPushButton* send = (QPushButton*)sender();
262   globalSelection();
263
264   if(send == GroupPoints->PushButton1) {
265     GroupPoints->LineEdit1->setFocus();
266     globalSelection( GEOM_ALLSHAPES );
267     myEditCurrentArgument = GroupPoints->LineEdit1;
268   }
269   else if(send == GroupPoints->PushButton2) {
270     GroupPoints->LineEdit2->setFocus();
271     myEditCurrentArgument = GroupPoints->LineEdit2;
272     globalSelection();
273     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
274   }
275   SelectionIntoArgument();
276 }
277
278
279 //=================================================================================
280 // function : LineEditReturnPressed()
281 // purpose  :
282 //=================================================================================
283 void GenerationGUI_PipeDlg::LineEditReturnPressed()
284 {
285   QLineEdit* send = (QLineEdit*)sender();
286   if(send == GroupPoints->LineEdit1 ||
287      send == GroupPoints->LineEdit2)
288     {
289       myEditCurrentArgument = send;
290       GEOMBase_Skeleton::LineEditReturnPressed();
291     }
292 }
293
294
295 //=================================================================================
296 // function : enterEvent()
297 // purpose  : when mouse enter onto the QWidget
298 //=================================================================================
299 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
300 {
301   if ( !GroupConstructors->isEnabled() )
302     ActivateThisDialog();
303 }
304
305
306 //=================================================================================
307 // function : ActivateThisDialog()
308 // purpose  :
309 //=================================================================================
310 void GenerationGUI_PipeDlg::ActivateThisDialog()
311 {
312   GEOMBase_Skeleton::ActivateThisDialog();
313   globalSelection( GEOM_ALLSHAPES );
314   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
315           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
316   displayPreview();
317 }
318
319
320 //=================================================================================
321 // function : createOperation
322 // purpose  :
323 //=================================================================================
324 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
325 {
326   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
327 }
328
329 //=================================================================================
330 // function : isValid
331 // purpose  :
332 //=================================================================================
333 bool GenerationGUI_PipeDlg::isValid( QString& )
334 {
335   return myOkBase && myOkPath;
336 }
337
338 //=================================================================================
339 // function : execute
340 // purpose  :
341 //=================================================================================
342 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
343 {
344   GEOM::GEOM_Object_var anObj;
345
346   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
347     getOperation() )->MakePipe( myBase, myPath );
348
349   if ( !anObj->_is_nil() )
350     objects.push_back( anObj._retn() );
351
352   return true;
353 }
354
355 //=================================================================================
356 // function : addSubshapeToStudy
357 // purpose  : virtual method to add new SubObjects if local selection
358 //=================================================================================
359 void GenerationGUI_PipeDlg::addSubshapesToStudy()
360 {
361   QMap<QString, GEOM::GEOM_Object_var> objMap;
362
363   objMap[GroupPoints->LineEdit2->text()] = myPath;
364
365   addSubshapesToFather( objMap );
366 }
367