Salome HOME
54ea7d019348351a884e5b882e33bc100f9722b2
[modules/geom.git] / src / TransformationGUI / TransformationGUI.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   : TransformationGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 using namespace std;
30 #include "TransformationGUI.h"
31
32 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33
34 #include "TransformationGUI_MultiTranslationDlg.h"   // Method MULTI TRANSLATION
35 #include "TransformationGUI_MultiRotationDlg.h"      // Method MULTI ROTATION
36 #include "TransformationGUI_TranslationDlg.h"        // Method TRANSLATION
37 #include "TransformationGUI_RotationDlg.h"           // Method ROTATION
38 #include "TransformationGUI_MirrorDlg.h"             // Method MIRROR
39 #include "TransformationGUI_ScaleDlg.h"              // Method SCALE
40
41 //=======================================================================
42 // function : TransformationGUI()
43 // purpose  : Constructor
44 //=======================================================================
45 TransformationGUI::TransformationGUI() :
46   QObject()
47 {
48   myGeomBase = new GEOMBase();
49   myGeomGUI = GEOMContext::GetGeomGUI();
50   myGeom = myGeomGUI->myComponentGeom;
51 }
52
53
54 //=======================================================================
55 // function : ~TransformationGUI()
56 // purpose  : Destructor
57 //=======================================================================
58 TransformationGUI::~TransformationGUI()
59 {
60 }
61
62
63 //=======================================================================
64 // function : OnGUIEvent()
65 // purpose  : 
66 //=======================================================================
67 bool TransformationGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
68 {
69   TransformationGUI* myTransformationGUI = new TransformationGUI();
70   myTransformationGUI->myGeomGUI->EmitSignalDeactivateDialog();
71   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
72
73   switch (theCommandID)
74     {
75     case 5021: // TRANSLATION
76       { 
77         TransformationGUI_TranslationDlg *aDlg = new TransformationGUI_TranslationDlg(parent, "", myTransformationGUI, Sel);
78         break;
79       }
80     case 5022: // ROTATION
81       { 
82         TransformationGUI_RotationDlg *aDlg = new TransformationGUI_RotationDlg(parent, "", myTransformationGUI, Sel);
83         break;
84       }
85     case 5023: // MIRROR
86       { 
87         TransformationGUI_MirrorDlg *aDlg = new TransformationGUI_MirrorDlg(parent, "", myTransformationGUI, Sel);
88         break;
89       }
90     case 5024: // SCALE
91       { 
92         TransformationGUI_ScaleDlg *aDlg = new TransformationGUI_ScaleDlg(parent, "", myTransformationGUI, Sel );
93         break;
94       }
95     case 5025: // MULTI TRANSLATION
96       { 
97         TransformationGUI_MultiTranslationDlg *aDlg = new TransformationGUI_MultiTranslationDlg(parent, "", myTransformationGUI, Sel);
98         break;
99       }
100     case 5026: // MULTI ROTATION
101       { 
102         TransformationGUI_MultiRotationDlg *aDlg = new TransformationGUI_MultiRotationDlg(parent, "", myTransformationGUI, Sel);
103         break;
104       }
105     default:
106       {
107         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
108         break;
109       }
110     }
111   return true;
112 }
113
114
115 //=================================================================================
116 // function : MakeTranslationAndDisplay()
117 // purpose  : Translate a shape
118 //=================================================================================
119 void TransformationGUI::MakeTranslationAndDisplay(GEOM::GEOM_Shape_ptr Shape, gp_Vec V)
120 {
121   try {
122     GEOM::GEOM_Shape_var result = myGeom->MakeTranslation(Shape, V.X(), V.Y(), V.Z());
123     if(result->_is_nil()) {
124       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
125       return;
126     }
127     result->NameType(Shape->NameType());
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 : MakeRotationAndDisplay()
140 // purpose  :
141 //=======================================================================================
142 void TransformationGUI::MakeRotationAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc,
143                                                const gp_Dir dir, const Standard_Real angle)
144 {
145   try {
146     const GEOM::AxisStruct axis = myGeom->MakeAxisStruct(loc.X(), loc.Y(), loc.Z(),
147                                                          dir.X(), dir.Y(), dir.Z());
148     GEOM::GEOM_Shape_var result = myGeom->MakeRotation(Shape, axis, angle);
149     if(result->_is_nil()) {
150       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
151       return ;
152     }
153     result->NameType(Shape->NameType());
154     if(myGeomBase->Display(result))
155       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
156   }
157   catch(const SALOME::SALOME_Exception& S_ex) {
158     QtCatchCorbaException(S_ex);
159   }  
160   return;
161 }
162
163
164 //=====================================================================================
165 // function : MakeMirrorAndDisplay()
166 // purpose  :
167 //=====================================================================================
168 void TransformationGUI::MakeMirrorAndDisplay(GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2)
169 {
170   try {
171     GEOM::GEOM_Shape_var result = myGeom->MakeMirrorByPlane(Shape1, Shape2);
172     if(result->_is_nil()) {
173       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
174       return;
175     }  
176     result->NameType(Shape1->NameType());
177     if(myGeomBase->Display(result))
178       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
179   }
180   catch(const SALOME::SALOME_Exception& S_ex) {
181     QtCatchCorbaException(S_ex);
182   }
183   return;
184 }
185
186
187 //=====================================================================================
188 // function : MakeScaleAndDisplay()
189 // purpose  :
190 //=====================================================================================
191 void TransformationGUI::MakeScaleAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Pnt centralPoint,
192                                             const Standard_Real factor)
193 {
194   try {
195     GEOM::PointStruct P = myGeom->MakePointStruct(centralPoint.X(), centralPoint.Y(), centralPoint.Z());
196     GEOM::GEOM_Shape_var result = myGeom->MakeScaleTransform(Shape, P, factor);
197     result->NameType(Shape->NameType());
198     if(myGeomBase->Display(result))
199       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
200     else 
201       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
202   }
203   catch(const SALOME::SALOME_Exception& S_ex) {
204     QtCatchCorbaException(S_ex);
205   }
206   return;
207 }
208
209
210 //=================================================================================
211 // function : MakeMultiTranslation1DAndDisplay()
212 // purpose  : Multi-Translate a shape
213 //=================================================================================
214 void TransformationGUI::MakeMultiTranslation1DAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir,
215                                                          const double Step, const short NbTimes) 
216 {
217   try {
218     GEOM::PointStruct d = myGeom->MakePointStruct(Dir.X(), Dir.Y(), Dir.Z());
219     GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
220
221     GEOM::GEOM_Shape_var result = myGeom->MakeMultiTranslation1D(Shape, dstruct, Step, NbTimes);
222     if(result->_is_nil()) {
223       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
224       return;
225     }
226     result->NameType(tr("GEOM_COMPOUND"));
227     if(myGeomBase->Display(result))
228       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
229   }  
230   catch(const SALOME::SALOME_Exception& S_ex) {
231     QtCatchCorbaException(S_ex);
232   }
233   return;
234 }
235
236
237 //=================================================================================
238 // function : MakeMultiTranslation2DAndDisplay()
239 // purpose  : Multi-Translate a shape
240 //=================================================================================
241 void TransformationGUI::MakeMultiTranslation2DAndDisplay(GEOM::GEOM_Shape_ptr Shape,
242                                                          const gp_Dir Dir1,const double Step1, const short NbTimes1,
243                                                          const gp_Dir Dir2, const double Step2, const short NbTimes2) 
244 {
245   try {
246     GEOM::PointStruct d1 = myGeom->MakePointStruct(Dir1.X(), Dir1.Y(), Dir1.Z());
247     GEOM::DirStruct dstruct1 = myGeom->MakeDirection(d1);
248     GEOM::PointStruct d2 = myGeom->MakePointStruct(Dir2.X(), Dir2.Y(), Dir2.Z());
249     GEOM::DirStruct dstruct2 = myGeom->MakeDirection(d2);
250
251     GEOM::GEOM_Shape_var result = myGeom->MakeMultiTranslation2D(Shape, dstruct1, Step1, NbTimes1,
252                                                                  dstruct2, Step2, NbTimes2);
253     if(result->_is_nil()) {
254       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
255       return;
256     }
257     result->NameType(tr("GEOM_COMPOUND"));
258     if(myGeomBase->Display(result))
259       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
260   }  
261   catch(const SALOME::SALOME_Exception& S_ex) {
262     QtCatchCorbaException(S_ex);
263   }
264   return;
265 }
266
267
268 //=================================================================================
269 // function : MakeMultiRotation1DAndDisplay()
270 // purpose  : Multi-Rotate a shape
271 //=================================================================================
272 void TransformationGUI::MakeMultiRotation1DAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, 
273                                                       const gp_Pnt Loc, const short NbTimes) 
274 {
275   try {
276     GEOM::PointStruct d = myGeom->MakePointStruct(Dir.X(), Dir.Y(), Dir.Z());
277     GEOM::DirStruct dstruct = myGeom->MakeDirection(d) ;
278     GEOM::PointStruct pstruct = myGeom->MakePointStruct(Loc.X(), Loc.Y(), Loc.Z());
279
280     GEOM::GEOM_Shape_var result = myGeom->MakeMultiRotation1D(Shape, dstruct, pstruct, NbTimes);
281     if(result->_is_nil()) {
282       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
283       return;
284     }
285     result->NameType(tr("GEOM_COMPOUND"));
286     if(myGeomBase->Display(result))
287       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
288   }  
289   catch(const SALOME::SALOME_Exception& S_ex) {
290     QtCatchCorbaException(S_ex);
291   }
292   return;
293 }
294
295
296 //=================================================================================
297 // function : MakeMultiRotation2DAndDisplay()
298 // purpose  : Multi-Rotate a shape
299 //=================================================================================
300 void TransformationGUI::MakeMultiRotation2DAndDisplay(GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir,
301                                                       const gp_Pnt Loc, const double Ang, const short NbTimes1,
302                                                 const double Step, const short NbTimes2) 
303 {
304   try {
305     GEOM::PointStruct d = myGeom->MakePointStruct(Dir.X(), Dir.Y(), Dir.Z());
306     GEOM::DirStruct dstruct = myGeom->MakeDirection(d);
307     GEOM::PointStruct pstruct = myGeom->MakePointStruct(Loc.X(), Loc.Y(), Loc.Z());
308
309     GEOM::GEOM_Shape_var result = myGeom->MakeMultiRotation2D(Shape, dstruct, pstruct, 
310                                                               Ang, NbTimes1, Step, NbTimes2);
311     if(result->_is_nil()) {
312       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
313       return;
314     }
315     result->NameType(tr("GEOM_COMPOUND"));
316     if(myGeomBase->Display(result))
317       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
318   }  
319   catch(const SALOME::SALOME_Exception& S_ex) {
320     QtCatchCorbaException(S_ex);
321   }
322   return;
323 }
324
325
326 //=====================================================================================
327 // EXPORTED METHODS
328 //=====================================================================================
329 extern "C"
330 {
331   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
332   {return TransformationGUI::OnGUIEvent(theCommandID, parent);}
333 }