Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI.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   : PrimitiveGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 using namespace std;
30 #include "PrimitiveGUI.h"
31
32 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33 #include <Precision.hxx>
34
35 #include "PrimitiveGUI_BoxDlg.h"      // Method BOX
36 #include "PrimitiveGUI_CylinderDlg.h" // Method CYLINDER
37 #include "PrimitiveGUI_SphereDlg.h"   // Method SPHERE
38 #include "PrimitiveGUI_TorusDlg.h"    // Method TORUS
39 #include "PrimitiveGUI_ConeDlg.h"     // Method CONE
40
41 //=======================================================================
42 // function : PrimitiveGUI()
43 // purpose  : Constructor
44 //=======================================================================
45 PrimitiveGUI::PrimitiveGUI() :
46   QObject()
47 {
48   myGeomBase = new GEOMBase();
49   myGeomGUI = GEOMContext::GetGeomGUI();
50   myGeom = myGeomGUI->myComponentGeom;
51 }
52
53
54 //=======================================================================
55 // function : ~PrimitiveGUI()
56 // purpose  : Destructor
57 //=======================================================================
58 PrimitiveGUI::~PrimitiveGUI()
59 {
60 }
61
62
63 //=======================================================================
64 // function : OnGUIEvent()
65 // purpose  : 
66 //=======================================================================
67 bool PrimitiveGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
68 {
69   PrimitiveGUI* aPrimitiveGUI = new PrimitiveGUI();
70   aPrimitiveGUI->myGeomGUI->EmitSignalDeactivateDialog();
71   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
72   switch (theCommandID)
73     {
74     case 4021: // BOX
75       {
76         PrimitiveGUI_BoxDlg* aDlg = new PrimitiveGUI_BoxDlg(parent, "", aPrimitiveGUI, Sel);
77         break;
78       }
79     case 4022: // CYLINDER
80       {
81         PrimitiveGUI_CylinderDlg* aDlg = new PrimitiveGUI_CylinderDlg(parent, "", aPrimitiveGUI, Sel);
82         break;
83       }
84     case 4023: // SPHERE
85       {
86         PrimitiveGUI_SphereDlg* aDlg = new PrimitiveGUI_SphereDlg(parent, "", aPrimitiveGUI, Sel);
87         break;
88       }
89     case 4024: // TORUS
90       {
91         PrimitiveGUI_TorusDlg* aDlg = new PrimitiveGUI_TorusDlg(parent, "", aPrimitiveGUI, Sel);
92         break;
93       }
94     case 4025: // CONE
95       {
96         PrimitiveGUI_ConeDlg* aDlg = new PrimitiveGUI_ConeDlg(parent, "", aPrimitiveGUI, Sel);
97         break;
98       }
99     default:
100       {
101         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
102         break;
103       }
104     }
105   return true;
106 }
107
108
109 //=======================================================================
110 // function : MakeBoxAndDisplay()
111 // purpose  : 
112 //=======================================================================
113 void PrimitiveGUI::MakeBoxAndDisplay(const gp_Pnt P1, const gp_Pnt P2)
114 {
115   try {
116     GEOM::GEOM_Shape_var box = myGeom->MakeBox(P1.X(), P1.Y(), P1.Z(), P2.X(), P2.Y(), P2.Z());
117     box->NameType(tr("GEOM_BOX"));
118     if(myGeomBase->Display(box))
119       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
120   }
121   catch(const SALOME::SALOME_Exception& S_ex) {
122     QtCatchCorbaException(S_ex);
123   }
124 }
125
126
127 //=====================================================================================
128 // function : MakeCylinderAndDisplay()
129 // purpose  :
130 //=====================================================================================
131 void PrimitiveGUI::MakeCylinderAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
132                                          const double Radius, const double aHeight)
133 {
134   try {
135     if(Radius <= Precision::Confusion() || aHeight <= Precision::Confusion())
136       return;
137
138     GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
139     GEOM::PointStruct d = myGeom->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
140     GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
141     
142     GEOM::GEOM_Shape_var result = myGeom->MakeCylinder(pstruct, dstruct, Radius, aHeight);
143     if (result->_is_nil()) {
144       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
145       return;
146     }
147     result->NameType(tr("GEOM_CYLINDER"));
148     if(myGeomBase->Display(result))
149       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
150   }
151   catch(const SALOME::SALOME_Exception& S_ex) {
152     QtCatchCorbaException(S_ex);
153   }
154   return;
155 }
156
157
158 //=====================================================================================
159 // function : MakeSphere()
160 // purpose  :
161 //=====================================================================================
162 void PrimitiveGUI::MakeSphereAndDisplay(const gp_Pnt aCenterPoint, const double aRadius)
163 {
164   try {
165     if(aRadius <= Precision::Confusion())
166       return;
167
168     GEOM::GEOM_Shape_ptr result = myGeom->MakeSphere(aCenterPoint.X(),aCenterPoint.Y(),aCenterPoint.Z(), aRadius);
169     result->NameType(tr("GEOM_SPHERE"));
170     if (myGeomBase->Display(result))
171       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
172   }
173   catch (const SALOME::SALOME_Exception& S_ex) {
174     QtCatchCorbaException(S_ex);
175   }
176   return;
177 }
178
179
180 //=====================================================================================
181 // function : MakeTorusAndDisplay()
182 // purpose  :
183 //=====================================================================================
184 void PrimitiveGUI::MakeTorusAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
185                                       const double Radius1, const double Radius2)
186 {
187   try {
188     if(Radius1 <= Precision::Confusion() || Radius2 <= Precision::Confusion())
189       return;
190     
191     GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
192     GEOM::PointStruct d = myGeom ->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
193     GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
194     
195     GEOM::GEOM_Shape_var result = myGeom->MakeTorus(pstruct, dstruct, Radius1, Radius2);
196     if(result->_is_nil()) {
197       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
198       return;
199     }
200     result->NameType(tr("GEOM_TORUS"));
201     if(myGeomBase->Display(result))
202       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
203   }
204   catch(const SALOME::SALOME_Exception& S_ex) {
205     QtCatchCorbaException(S_ex);
206   }
207   return;
208 }
209
210
211 //=====================================================================================
212 // function : MakeConeAndDisplay()
213 // purpose  :
214 //=====================================================================================
215 void PrimitiveGUI::MakeConeAndDisplay(const gp_Pnt BasePoint, const gp_Dir aDir,
216                                      const double Radius1, const double Radius2, const double aHeight)
217 {
218   try {
219     double myRadius2 = Radius2;
220     if(myRadius2 < Precision::Confusion())
221       myRadius2 = Precision::Confusion();
222     if(Radius1 <= Precision::Confusion() || aHeight <= Precision::Confusion())
223       return;
224
225     GEOM::PointStruct pstruct = myGeom->MakePointStruct(BasePoint.X(), BasePoint.Y(), BasePoint.Z());
226     GEOM::PointStruct d = myGeom->MakePointStruct(aDir.X(), aDir.Y(), aDir.Z());
227     GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
228
229     GEOM::GEOM_Shape_var result = myGeom->MakeCone(pstruct, dstruct, Radius1, myRadius2, aHeight);  
230     if(result->_is_nil()) {
231       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
232       return;
233     }
234     result->NameType(tr("GEOM_CONE"));
235     if(myGeomBase->Display(result))
236       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
237   } 
238   catch(const SALOME::SALOME_Exception& S_ex) {
239     QtCatchCorbaException(S_ex);
240   }
241   return;
242 }
243
244
245 //=====================================================================================
246 // EXPORTED METHODS
247 //=====================================================================================
248 extern "C"
249 {
250   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
251   {return PrimitiveGUI::OnGUIEvent(theCommandID, parent);}
252 }