]> SALOME platform Git repositories - modules/geom.git/blob - src/GenerationGUI/GenerationGUI.cxx
Salome HOME
78bc4fdeb7bacf76a83607a3ed47bb18eb1991a7
[modules/geom.git] / src / GenerationGUI / GenerationGUI.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.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 using namespace std;
30 #include "GenerationGUI.h"
31
32 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33
34 #include "GenerationGUI_PrismDlg.h"     // Method PRISM
35 #include "GenerationGUI_RevolDlg.h"     // Method REVOL
36 #include "GenerationGUI_FillingDlg.h"   // Method FILLING
37 #include "GenerationGUI_PipeDlg.h"      // Method PIPE
38
39 //=======================================================================
40 // function : GenerationGUI()
41 // purpose  : Constructor
42 //=======================================================================
43 GenerationGUI::GenerationGUI() :
44   QObject()
45 {
46   myGeomBase = new GEOMBase();
47   myGeomGUI = GEOMContext::GetGeomGUI();
48   myGeom = myGeomGUI->myComponentGeom;
49 }
50
51
52 //=======================================================================
53 // function : ~GenerationGUI()
54 // purpose  : Destructor
55 //=======================================================================
56 GenerationGUI::~GenerationGUI()
57 {
58 }
59
60
61 //=======================================================================
62 // function : OnGUIEvent()
63 // purpose  : 
64 //=======================================================================
65 bool GenerationGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
66 {
67   GenerationGUI* myGenerationGUI = new GenerationGUI();
68   myGenerationGUI->myGeomGUI->EmitSignalDeactivateDialog();
69   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
70
71   switch (theCommandID)
72     {
73     case 4031: // PRISM
74       { 
75         GenerationGUI_PrismDlg *aDlg = new GenerationGUI_PrismDlg(parent, "", myGenerationGUI, Sel);
76         break;
77       }
78     case 4032: // REVOL
79       { 
80         GenerationGUI_RevolDlg *aDlg = new GenerationGUI_RevolDlg(parent, "", myGenerationGUI, Sel);
81         break;
82       }
83     case 4033: // FILLING
84       { 
85         GenerationGUI_FillingDlg *aDlg = new GenerationGUI_FillingDlg(parent, "", myGenerationGUI, Sel);
86         break;
87       }
88     case 4034: // PIPE
89       { 
90         GenerationGUI_PipeDlg *aDlg = new  GenerationGUI_PipeDlg(parent, "", myGenerationGUI, Sel);
91         break;
92       }
93     default:
94       {
95         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
96         break;
97       }
98     }
99   return true;
100 }
101
102
103 //=======================================================================
104 // function : MakePrismAndDisplay()
105 // purpose  : P1 and P2 is to define a vector for prism
106 //=======================================================================
107 void GenerationGUI::MakePrismAndDisplay(GEOM::GEOM_Shape_ptr BaseShape, const gp_Pnt P1, const gp_Pnt P2)
108 {
109   try {
110     if(BaseShape->_is_nil()) {
111       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
112       return;
113     }
114
115     GEOM::PointStruct PS1 = myGeom->MakePointStruct(P1.X(), P1.Y(), P1.Z());
116     GEOM::PointStruct PS2 = myGeom->MakePointStruct(P2.X(), P2.Y(), P2.Z());
117     GEOM::GEOM_Shape_ptr result = myGeom->MakePrism(BaseShape, PS1, PS2);
118     if(result->_is_nil()) {
119       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
120       return;
121     }  
122
123     TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
124     Standard_CString type;
125     myGeomBase->GetShapeTypeString(S,type);
126     result->NameType(type);
127
128     if(myGeomBase->Display(result))
129       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
130   }
131   catch(const SALOME::SALOME_Exception& S_ex) {
132     QtCatchCorbaException(S_ex);
133   }
134   return;
135 }
136
137
138 //=======================================================================================
139 // function : MakeRevolutionAndDisplay()
140 // purpose  :
141 //=======================================================================================
142 void GenerationGUI::MakeRevolutionAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, const gp_Dir dir, const Standard_Real revolAngle)
143 {
144   try {
145     GEOM::AxisStruct axis = myGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(), dir.X(), dir.Y(), dir.Z());
146     GEOM::GEOM_Shape_ptr result = myGeom->MakeRevolution(Shape, axis, revolAngle) ;
147     if(result->_is_nil()) {
148       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
149       return;
150     }
151
152     TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
153     Standard_CString type;
154     myGeomBase->GetShapeTypeString(S,type);
155     result->NameType(type);
156
157     if(myGeomBase->Display(result))
158       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
159   }
160   catch(const SALOME::SALOME_Exception& S_ex) {
161     QtCatchCorbaException(S_ex);
162   }
163   return;
164 }
165
166
167 //=====================================================================================
168 // function : MakeFillingAndDisplay()
169 // purpose  :
170 //=====================================================================================
171 void GenerationGUI::MakeFillingAndDisplay(GEOM::GEOM_Shape_ptr SectionShape, const short mindeg,
172                                           const short maxdeg, const double tol3d,
173                                           const double tol2d, const short nbiter)
174 {  
175   try {
176     GEOM::GEOM_Shape_ptr result = myGeom->MakeFilling(SectionShape, mindeg, maxdeg,
177                                                       tol3d, tol2d, nbiter);
178     if(result->_is_nil()) {
179       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
180       return;
181     }  
182
183     TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
184     Standard_CString type;
185     myGeomBase->GetShapeTypeString(S,type);
186     result->NameType(type);
187
188     if(myGeomBase->Display(result))
189       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
190     return;  
191   } 
192   catch(const SALOME::SALOME_Exception& S_ex) {
193     QtCatchCorbaException(S_ex);
194   }
195   return;
196 }
197
198
199 //=====================================================================================
200 // function : MakePipeAndDisplay()
201 // purpose  :
202 //=====================================================================================
203 void GenerationGUI::MakePipeAndDisplay(GEOM::GEOM_Shape_ptr aPath, GEOM::GEOM_Shape_ptr aBase) 
204 {
205   try {
206     GEOM::GEOM_Shape_ptr result = myGeom->MakePipe(aPath, aBase);
207     if (!result->_is_nil() && myGeomBase->Display(result)) {
208       TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
209       Standard_CString type;
210       myGeomBase->GetShapeTypeString(S,type);
211       result->NameType(type);
212
213       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
214     }
215     else {
216       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
217     }
218   }
219   catch (const SALOME::SALOME_Exception& S_ex) {
220     QtCatchCorbaException(S_ex);
221   }
222   return;
223 }
224
225
226 //=====================================================================================
227 // EXPORTED METHODS
228 //=====================================================================================
229 extern "C"
230 {
231   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
232   {return GenerationGUI::OnGUIEvent(theCommandID, parent);}
233 }