Salome HOME
3da2f8d8d14ba34bab6dec09503bbf318fe07781
[modules/geom.git] / TransformationGUI.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : TransformationGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "TransformationGUI.h"
28
29 #include <GEOMBase.h>
30 #include <GeometryGUI.h>
31 #include "GeometryGUI_Operations.h"
32
33 #include <SUIT_Desktop.h>
34 #include <SUIT_ViewModel.h>
35 #include <SUIT_ViewWindow.h>
36 #include <SUIT_ViewManager.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Study.h>
40 #include <SALOME_ListIteratorOfListIO.hxx>
41
42 #include "TransformationGUI_MultiTranslationDlg.h"   // Method MULTI TRANSLATION
43 #include "TransformationGUI_MultiRotationDlg.h"      // Method MULTI ROTATION
44 #include "TransformationGUI_TranslationDlg.h"        // Method TRANSLATION
45 #include "TransformationGUI_RotationDlg.h"           // Method ROTATION
46 #include "TransformationGUI_MirrorDlg.h"             // Method MIRROR
47 #include "TransformationGUI_ScaleDlg.h"              // Method SCALE
48 #include "TransformationGUI_OffsetDlg.h"             // Method OFFSET
49 #include "TransformationGUI_PositionDlg.h"           // Method POSITION
50
51 //=======================================================================
52 // function : TransformationGUI()
53 // purpose  : Constructor
54 //=======================================================================
55 TransformationGUI::TransformationGUI( GeometryGUI* parent )
56   : GEOMGUI( parent )
57 {
58 }
59
60 //=======================================================================
61 // function : ~TransformationGUI()
62 // purpose  : Destructor
63 //=======================================================================
64 TransformationGUI::~TransformationGUI()
65 {
66 }
67
68
69 //=======================================================================
70 // function : OnGUIEvent()
71 // purpose  : 
72 //=======================================================================
73 bool TransformationGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
74 {
75   SalomeApp_Application* app = getGeometryGUI()->getApp();
76   if ( !app ) return false;
77
78   getGeometryGUI()->EmitSignalDeactivateDialog();
79   QDialog* aDlg = NULL;
80
81   switch ( theCommandID ) {
82   case GEOMOp::OpTranslate:      // TRANSLATION
83     aDlg = new TransformationGUI_TranslationDlg( getGeometryGUI(), parent );
84     break;
85   case GEOMOp::OpRotate:         // ROTATION
86     aDlg = new TransformationGUI_RotationDlg( getGeometryGUI(), parent );
87     break;
88   case GEOMOp::OpChangeLoc:      // POSITION
89     aDlg = new TransformationGUI_PositionDlg( getGeometryGUI(), parent );
90     break;
91   case GEOMOp::OpMirror:         // MIRROR
92     aDlg = new TransformationGUI_MirrorDlg( getGeometryGUI(), parent );
93     break;
94   case GEOMOp::OpScale:          // SCALE
95     aDlg = new TransformationGUI_ScaleDlg( getGeometryGUI(), parent );
96     break;
97   case GEOMOp::OpOffset:         // OFFSET
98     aDlg = new TransformationGUI_OffsetDlg( getGeometryGUI(), parent );
99     break;
100   case GEOMOp::OpMultiTranslate: // MULTI TRANSLATION
101     aDlg = new TransformationGUI_MultiTranslationDlg( getGeometryGUI(), parent );
102     break;
103   case GEOMOp::OpMultiRotate:    // MULTI ROTATION
104     aDlg = new TransformationGUI_MultiRotationDlg( getGeometryGUI(), parent );
105     break;
106   case GEOMOp::OpReimport:       // RELOAD IMPORTED SHAPE
107     {
108       SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
109
110       GEOM::GEOM_ITransformOperations_var anOp =
111         GeometryGUI::GetGeomGen()->GetITransformOperations(anAppStudy->id());
112       if (anOp->_is_nil()) return false;
113
114       GEOM_Displayer aDisp (anAppStudy);
115       SUIT_Desktop* desk = app->desktop();
116       QList<SUIT_ViewWindow*> wnds = desk->windows();
117
118       LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
119       SALOME_ListIO aSelList;
120       aSelMgr->selectedObjects(aSelList);
121
122       SALOME_ListIteratorOfListIO aSelIt (aSelList);
123       for (; aSelIt.More(); aSelIt.Next()) {
124         Handle(SALOME_InteractiveObject) io = aSelIt.Value();
125         Standard_Boolean testResult = Standard_False;
126         GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject(io, testResult);
127         if (testResult) {
128           anOp->RecomputeObject(aGeomObj);
129
130           SUIT_ViewWindow* wnd;
131           QListIterator<SUIT_ViewWindow*> it (wnds);
132           while (it.hasNext() && (wnd = it.next()))
133           {
134             if (SUIT_ViewManager* vman = wnd->getViewManager()) {
135               if (SUIT_ViewModel* vmodel = vman->getViewModel()) {
136                 if (SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel)) {
137                   if (view->isVisible(io)) {
138                     aDisp.Erase(io, false, false, view);
139                     aDisp.Display(io, true, view);
140                   }
141                   // ? Redisplay subshapes ?
142                 }
143               }
144             }
145           }
146         }
147       } // for (; aSelIt.More(); aSelIt.Next())
148     }
149     break;
150   default:
151     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
152     break;
153   }
154
155   if ( aDlg != NULL )
156     aDlg->show();
157
158   return true;
159 }
160
161
162 //=====================================================================================
163 // EXPORTED METHODS
164 //=====================================================================================
165 extern "C"
166 {
167 #ifdef WNT
168   __declspec( dllexport )
169 #endif
170   GEOMGUI* GetLibGUI( GeometryGUI* parent )
171   {
172     return new TransformationGUI( parent );
173   }
174 }