]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
Merge with PAL/SALOME 2.1.0d
[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   globalSelection( GEOM_ALLSHAPES );
121 }
122
123
124 //=================================================================================
125 // function : ClickOnOk()
126 // purpose  :
127 //=================================================================================
128 void GenerationGUI_PipeDlg::ClickOnOk()
129 {
130   if ( ClickOnApply() )
131     ClickOnCancel();
132 }
133
134
135 //=================================================================================
136 // function : ClickOnAply()
137 // purpose  :
138 //=================================================================================
139 bool GenerationGUI_PipeDlg::ClickOnApply()
140 {
141   if ( !onAccept() )
142     return false;
143
144   initName();
145   return true;
146 }
147
148
149 //=================================================================================
150 // function : SelectionIntoArgument()
151 // purpose  : Called when selection has changed
152 //=================================================================================
153 void GenerationGUI_PipeDlg::SelectionIntoArgument()
154 {
155   erasePreview();
156   myEditCurrentArgument->setText("");
157   
158   if(mySelection->IObjectCount() != 1) {
159     if(myEditCurrentArgument == GroupPoints->LineEdit1)
160       myOkBase = false;
161     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
162       myOkPath = false;
163     return;
164   }
165   
166   // nbSel == 1
167   Standard_Boolean testResult = Standard_False;
168   GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
169     
170   if (!testResult)
171     return;
172   
173   TopoDS_Shape S;
174   
175   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
176     myOkBase = false;
177     
178     if(!GEOMBase::GetShape(aSelectedObject, S) ||
179        S.ShapeType() == TopAbs_COMPSOLID || 
180        S.ShapeType() == TopAbs_COMPOUND || 
181        S.ShapeType() == TopAbs_SOLID || 
182        S.ShapeType() == TopAbs_SHAPE) 
183       return;
184     
185     myBase = aSelectedObject;
186     myOkBase = true;
187   }
188   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
189     myOkPath = false;
190     
191     if(!GEOMBase::GetShape(aSelectedObject, S) ||
192        !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) ) 
193       return;
194     
195     myPath = aSelectedObject;
196     myOkPath = true;
197   }
198   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
199   
200   displayPreview();
201 }
202
203
204 //=================================================================================
205 // function : SetEditCurrentArgument()
206 // purpose  :
207 //=================================================================================
208 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
209 {
210   QPushButton* send = (QPushButton*)sender();
211
212   if(send == GroupPoints->PushButton1) {
213     GroupPoints->LineEdit1->setFocus();
214     myEditCurrentArgument = GroupPoints->LineEdit1;
215   }
216   else if(send == GroupPoints->PushButton2) {
217     GroupPoints->LineEdit2->setFocus();
218     myEditCurrentArgument = GroupPoints->LineEdit2;
219   }
220   SelectionIntoArgument();
221 }
222
223
224 //=================================================================================
225 // function : LineEditReturnPressed()
226 // purpose  :
227 //=================================================================================
228 void GenerationGUI_PipeDlg::LineEditReturnPressed()
229 {
230   QLineEdit* send = (QLineEdit*)sender();
231   if(send == GroupPoints->LineEdit1 ||
232      send == GroupPoints->LineEdit2)
233     {
234       myEditCurrentArgument = send;
235       GEOMBase_Skeleton::LineEditReturnPressed();
236     }
237 }
238
239
240 //=================================================================================
241 // function : enterEvent()
242 // purpose  : when mouse enter onto the QWidget
243 //=================================================================================
244 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
245 {
246   if ( !GroupConstructors->isEnabled() )
247     ActivateThisDialog();
248 }
249
250
251 //=================================================================================
252 // function : ActivateThisDialog()
253 // purpose  :
254 //=================================================================================
255 void GenerationGUI_PipeDlg::ActivateThisDialog()
256 {
257   GEOMBase_Skeleton::ActivateThisDialog();
258   globalSelection( GEOM_ALLSHAPES );
259   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
260   displayPreview();
261 }
262
263
264 //=================================================================================
265 // function : createOperation
266 // purpose  :
267 //=================================================================================
268 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
269 {
270   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
271 }
272
273 //=================================================================================
274 // function : isValid
275 // purpose  :
276 //=================================================================================
277 bool GenerationGUI_PipeDlg::isValid( QString& )
278 {
279   return myOkBase && myOkPath;
280 }
281
282 //=================================================================================
283 // function : execute
284 // purpose  :
285 //=================================================================================
286 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
287 {
288   GEOM::GEOM_Object_var anObj;
289
290   anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
291     getOperation() )->MakePipe( myBase, myPath );
292
293   if ( !anObj->_is_nil() )
294     objects.push_back( anObj._retn() );
295
296   return true;
297 }
298
299
300