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