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