Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 <BRepBuilderAPI_MakeWire.hxx>
40 #include <BRepOffsetAPI_MakePipe.hxx>
41 #if OCC_VERSION_MAJOR >= 5
42 #include <BRepAlgo.hxx>
43 #else
44 #include <BRepAlgoAPI.hxx>
45 #endif
46
47 #include "GEOMImpl_Types.hxx"
48
49 #include "utilities.h"
50
51 //=================================================================================
52 // class    : GenerationGUI_PipeDlg()
53 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the 
54 //            name 'name' and widget flags set to 'f'.
55 //            The dialog will by default be modeless, unless you set 'modal' to
56 //            TRUE to construct a modal dialog.
57 //=================================================================================
58 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59                                              const char* name, bool modal, WFlags fl)
60   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
62 {
63   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
64   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
65
66   setCaption(tr("GEOM_PIPE_TITLE"));
67
68   /***************************************************************/
69   GroupConstructors->setTitle(tr("GEOM_PIPE"));
70   RadioButton1->setPixmap(image0);
71   RadioButton2->close(TRUE);
72   RadioButton3->close(TRUE);
73
74   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
75   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
77   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
78   GroupPoints->PushButton1->setPixmap(image1);
79   GroupPoints->PushButton2->setPixmap(image1);
80   GroupPoints->LineEdit1->setReadOnly( true );
81   GroupPoints->LineEdit2->setReadOnly( true );
82
83   Layout1->addWidget(GroupPoints, 2, 0);
84   /***************************************************************/
85
86   setHelpFileName("pipe_creation.htm");
87
88   /* Initialisations */
89   Init();
90 }
91
92
93 //=================================================================================
94 // function : ~GenerationGUI_PipeDlg()
95 // purpose  : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
98 {
99   /* no need to delete child widgets, Qt does it all for us */
100 }
101
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void GenerationGUI_PipeDlg::Init()
108 {
109   /* init variables */
110   myEditCurrentArgument = GroupPoints->LineEdit1;
111   GroupPoints->LineEdit1->setReadOnly( true );
112   GroupPoints->LineEdit2->setReadOnly( true );
113
114   myOkBase = myOkPath = 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(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
122
123   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
125   
126   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
127           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
128
129   initName(tr("GEOM_PIPE"));
130
131   globalSelection( GEOM_ALLSHAPES );
132 }
133
134
135 //=================================================================================
136 // function : ClickOnOk()
137 // purpose  :
138 //=================================================================================
139 void GenerationGUI_PipeDlg::ClickOnOk()
140 {
141   if ( ClickOnApply() )
142     ClickOnCancel();
143 }
144
145
146 //=================================================================================
147 // function : ClickOnAply()
148 // purpose  :
149 //=================================================================================
150 bool GenerationGUI_PipeDlg::ClickOnApply()
151 {
152   if ( !onAccept() )
153     return false;
154
155   initName();
156   return true;
157 }
158
159
160 //=================================================================================
161 // function : SelectionIntoArgument()
162 // purpose  : Called when selection has changed
163 //=================================================================================
164 void GenerationGUI_PipeDlg::SelectionIntoArgument()
165 {
166   erasePreview();
167   myEditCurrentArgument->setText("");
168   
169   if(IObjectCount() != 1) {
170     if(myEditCurrentArgument == GroupPoints->LineEdit1)
171       myOkBase = false;
172     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
173       myOkPath = false;
174     return;
175   }
176   
177   // nbSel == 1
178   Standard_Boolean testResult = Standard_False;
179   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
180     
181   if (!testResult)
182     return;
183   
184   TopoDS_Shape S;
185   
186   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
187     myOkBase = false;
188     
189     if(!GEOMBase::GetShape(aSelectedObject, S) ||
190        S.ShapeType() == TopAbs_COMPSOLID || 
191        S.ShapeType() == TopAbs_COMPOUND || 
192        S.ShapeType() == TopAbs_SOLID || 
193        S.ShapeType() == TopAbs_SHAPE) 
194       return;
195     
196     myBase = aSelectedObject;
197     myOkBase = true;
198   }
199   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
200     myOkPath = false;
201     
202     if(!GEOMBase::GetShape(aSelectedObject, S) ||
203        !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) 
204       return;
205     
206     myPath = aSelectedObject;
207     myOkPath = true;
208   }
209   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
210   
211   displayPreview();
212 }
213
214
215 //=================================================================================
216 // function : SetEditCurrentArgument()
217 // purpose  :
218 //=================================================================================
219 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
220 {
221   QPushButton* send = (QPushButton*)sender();
222
223   if(send == GroupPoints->PushButton1) {
224     GroupPoints->LineEdit1->setFocus();
225     myEditCurrentArgument = GroupPoints->LineEdit1;
226   }
227   else if(send == GroupPoints->PushButton2) {
228     GroupPoints->LineEdit2->setFocus();
229     myEditCurrentArgument = GroupPoints->LineEdit2;
230   }
231   SelectionIntoArgument();
232 }
233
234
235 //=================================================================================
236 // function : LineEditReturnPressed()
237 // purpose  :
238 //=================================================================================
239 void GenerationGUI_PipeDlg::LineEditReturnPressed()
240 {
241   QLineEdit* send = (QLineEdit*)sender();
242   if(send == GroupPoints->LineEdit1 ||
243      send == GroupPoints->LineEdit2)
244     {
245       myEditCurrentArgument = send;
246       GEOMBase_Skeleton::LineEditReturnPressed();
247     }
248 }
249
250
251 //=================================================================================
252 // function : enterEvent()
253 // purpose  : when mouse enter onto the QWidget
254 //=================================================================================
255 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
256 {
257   if ( !GroupConstructors->isEnabled() )
258     ActivateThisDialog();
259 }
260
261
262 //=================================================================================
263 // function : ActivateThisDialog()
264 // purpose  :
265 //=================================================================================
266 void GenerationGUI_PipeDlg::ActivateThisDialog()
267 {
268   GEOMBase_Skeleton::ActivateThisDialog();
269   globalSelection( GEOM_ALLSHAPES );
270   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
271           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
272   displayPreview();
273 }
274
275
276 //=================================================================================
277 // function : createOperation
278 // purpose  :
279 //=================================================================================
280 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
281 {
282   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
283 }
284
285 //=================================================================================
286 // function : isValid
287 // purpose  :
288 //=================================================================================
289 bool GenerationGUI_PipeDlg::isValid( QString& )
290 {
291   return myOkBase && myOkPath;
292 }
293
294 //=================================================================================
295 // function : execute
296 // purpose  :
297 //=================================================================================
298 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
299 {
300   GEOM::GEOM_Object_var anObj;
301
302   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
303     getOperation() )->MakePipe( myBase, myPath );
304
305   if ( !anObj->_is_nil() )
306     objects.push_back( anObj._retn() );
307
308   return true;
309 }
310
311
312