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