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