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