]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI_PipeDlg.cxx
Salome HOME
SALOME PAL V1_4_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.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 using namespace std;
30 #include "GenerationGUI_PipeDlg.h"
31
32 #include <TopoDS_Edge.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <BRepOffsetAPI_MakePipe.hxx>
35 #if OCC_VERSION_MAJOR >= 5
36 #include <BRepAlgo.hxx>
37 #else
38 #include <BRepAlgoAPI.hxx>
39 #endif
40
41 //=================================================================================
42 // class    : GenerationGUI_PipeDlg()
43 // purpose  : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the 
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
49   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 {
51   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
52   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53
54   setCaption(tr("GEOM_PIPE_TITLE"));
55
56   /***************************************************************/
57   GroupConstructors->setTitle(tr("GEOM_PIPE"));
58   RadioButton1->setPixmap(image0);
59   RadioButton2->close(TRUE);
60   RadioButton3->close(TRUE);
61
62   GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
63   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
65   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
66   GroupPoints->PushButton1->setPixmap(image1);
67   GroupPoints->PushButton2->setPixmap(image1);
68
69   Layout1->addWidget(GroupPoints, 1, 0);
70   /***************************************************************/
71
72   /* Initialisations */
73   myGenerationGUI = theGenerationGUI;
74   Init();
75 }
76
77
78 //=================================================================================
79 // function : ~GenerationGUI_PipeDlg()
80 // purpose  : Destroys the object and frees any allocated resources
81 //=================================================================================
82 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
83 {
84   /* no need to delete child widgets, Qt does it all for us */
85 }
86
87
88 //=================================================================================
89 // function : Init()
90 // purpose  :
91 //=================================================================================
92 void GenerationGUI_PipeDlg::Init()
93 {
94   /* init variables */
95   myEditCurrentArgument = GroupPoints->LineEdit1;
96
97   myOkShape1 = myOkShape2 = false;
98
99   /* signals and slots connections */
100   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
102
103   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
104   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
105
106   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
108   
109   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
110
111   /* displays Dialog */
112   GroupPoints->show();
113   this->show();
114
115   return;
116 }
117
118
119 //=================================================================================
120 // function : ClickOnOk()
121 // purpose  :
122 //=================================================================================
123 void GenerationGUI_PipeDlg::ClickOnOk()
124 {
125   this->ClickOnApply();
126   ClickOnCancel();
127   return;
128 }
129
130
131 //=================================================================================
132 // function : ClickOnAply()
133 // purpose  :
134 //=================================================================================
135 void GenerationGUI_PipeDlg::ClickOnApply()
136 {
137   QAD_Application::getDesktop()->putInfo(tr(""));
138   if (mySimulationTopoDs.IsNull())
139     return;
140   myGeomBase->EraseSimulationShape();
141   mySimulationTopoDs.Nullify();
142
143   if(myOkShape1 && myOkShape2)    
144     myGenerationGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1);
145
146   return;
147 }
148
149
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose  : Called when selection has changed
153 //=================================================================================
154 void GenerationGUI_PipeDlg::SelectionIntoArgument()
155 {
156   myGeomBase->EraseSimulationShape();
157   mySimulationTopoDs.Nullify();
158   myEditCurrentArgument->setText("");
159   QString aString = ""; /* name of selection */
160   
161   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
162   if(nbSel != 1) {
163     if(myEditCurrentArgument == GroupPoints->LineEdit1)
164       myOkShape1 = false;
165     else if(myEditCurrentArgument == GroupPoints->LineEdit2)
166       myOkShape2 = false;
167     return;
168   }
169   
170   // nbSel == 1
171   TopoDS_Shape S; 
172   Standard_Boolean testResult;
173   Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
174   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
175     return;
176   
177   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
178     myOkShape1 = false;
179     if(S.ShapeType() != TopAbs_COMPSOLID && S.ShapeType() != TopAbs_COMPOUND && S.ShapeType() != TopAbs_SOLID && S.ShapeType() != TopAbs_SHAPE) {
180       myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
181       if(!testResult)
182         return;
183       myEditCurrentArgument->setText(aString);
184       myOkShape1 = true;
185       myShape1 = S;
186     }
187   }
188   else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
189     myOkShape2 = false;
190     if(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE ) {
191       myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
192       if(!testResult)
193         return;
194       myEditCurrentArgument->setText(aString);
195       myOkShape2 = true;
196       myShape2 = S;
197     }
198   }
199
200   if(myOkShape1 && myOkShape2)
201     this->MakePipeSimulationAndDisplay();
202   return;
203 }
204
205
206 //=================================================================================
207 // function : SetEditCurrentArgument()
208 // purpose  :
209 //=================================================================================
210 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
211 {
212   QPushButton* send = (QPushButton*)sender();
213
214   if(send == GroupPoints->PushButton1) {
215     GroupPoints->LineEdit1->setFocus();
216     myEditCurrentArgument = GroupPoints->LineEdit1;
217   }
218   else if(send == GroupPoints->PushButton2) {
219     GroupPoints->LineEdit2->setFocus();
220     myEditCurrentArgument = GroupPoints->LineEdit2;
221   }
222   this->SelectionIntoArgument();
223
224   return;
225 }
226
227
228 //=================================================================================
229 // function : LineEditReturnPressed()
230 // purpose  :
231 //=================================================================================
232 void GenerationGUI_PipeDlg::LineEditReturnPressed()
233 {
234   QLineEdit* send = (QLineEdit*)sender();
235   if(send == GroupPoints->LineEdit1)
236     myEditCurrentArgument = GroupPoints->LineEdit1;
237   else if (send == GroupPoints->LineEdit2)
238     myEditCurrentArgument = GroupPoints->LineEdit2;
239   else
240     return;
241
242   GEOMBase_Skeleton::LineEditReturnPressed();
243   return;
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     return;
255   this->ActivateThisDialog();
256   return;
257 }
258
259
260 //=================================================================================
261 // function : ActivateThisDialog()
262 // purpose  :
263 //=================================================================================
264 void GenerationGUI_PipeDlg::ActivateThisDialog()
265 {
266   GEOMBase_Skeleton::ActivateThisDialog();
267   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
268   if(!mySimulationTopoDs.IsNull())
269     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
270   return;
271 }
272
273
274 //=================================================================================
275 // function : MakeMirrorSimulationAndDisplay()
276 // purpose  : S1 is a shape and S2 a mirror.
277 //=================================================================================
278 void GenerationGUI_PipeDlg::MakePipeSimulationAndDisplay()
279 {
280   myGeomBase->EraseSimulationShape();
281   mySimulationTopoDs.Nullify();
282   
283   try {
284     TopoDS_Wire aWire;
285
286     if(myShape2.ShapeType() == TopAbs_WIRE) 
287       aWire = TopoDS::Wire(myShape2);
288     else if(myShape2.ShapeType() == TopAbs_EDGE) {
289       TopoDS_Edge aEdge = TopoDS::Edge(myShape2);
290       aWire = BRepBuilderAPI_MakeWire(aEdge);
291     }
292
293     TopoDS_Shape tds = BRepOffsetAPI_MakePipe(aWire,myShape1);
294 #if OCC_VERSION_MAJOR >= 5
295     if(BRepAlgo::IsValid(tds)) 
296 #else
297     if(BRepAlgoAPI::IsValid(tds)) 
298 #endif
299     {
300       //Draw Pipe
301       mySimulationTopoDs = tds;
302       myGeomBase->DisplaySimulationShape(mySimulationTopoDs); 
303     }
304   }
305   catch(Standard_Failure) {
306     MESSAGE("Exception catched in MakePipeSimulationAndDisplay");
307     return;
308   }
309   return;
310 }