]> SALOME platform Git repositories - modules/geom.git/blob - src/TransformationGUI/TransformationGUI.cxx
Salome HOME
Fix memory leaks
[modules/geom.git] / src / TransformationGUI / TransformationGUI.cxx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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_ListIO.hxx>
41
42 #include "TransformationGUI_ExtensionDlg.h"          // Method EXTENSION
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_ProjectionDlg.h"         // Method PROJECTION
51 #include "TransformationGUI_PositionDlg.h"           // Method POSITION
52
53 //=======================================================================
54 // function : TransformationGUI()
55 // purpose  : Constructor
56 //=======================================================================
57 TransformationGUI::TransformationGUI( GeometryGUI* parent )
58   : 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   case GEOMOp::OpTranslate:      // TRANSLATION
85     aDlg = new TransformationGUI_TranslationDlg( getGeometryGUI(), parent );
86     break;
87   case GEOMOp::OpRotate:         // ROTATION
88     aDlg = new TransformationGUI_RotationDlg( getGeometryGUI(), parent );
89     break;
90   case GEOMOp::OpChangeLoc:      // POSITION
91     aDlg = new TransformationGUI_PositionDlg( getGeometryGUI(), parent );
92     break;
93   case GEOMOp::OpMirror:         // MIRROR
94     aDlg = new TransformationGUI_MirrorDlg( getGeometryGUI(), parent );
95     break;
96   case GEOMOp::OpScale:          // SCALE
97     aDlg = new TransformationGUI_ScaleDlg( getGeometryGUI(), parent );
98     break;
99   case GEOMOp::OpOffset:         // OFFSET
100     aDlg = new TransformationGUI_OffsetDlg( getGeometryGUI(), parent );
101     break;
102   case GEOMOp::OpProjection:     // PROJECTION
103     aDlg = new TransformationGUI_ProjectionDlg( getGeometryGUI(), parent );
104     break;
105   case GEOMOp::OpMultiTranslate: // MULTI TRANSLATION
106     aDlg = new TransformationGUI_MultiTranslationDlg( getGeometryGUI(), parent );
107     break;
108   case GEOMOp::OpMultiRotate:    // MULTI ROTATION
109     aDlg = new TransformationGUI_MultiRotationDlg( getGeometryGUI(), parent );
110     break;
111   case GEOMOp::OpReimport:       // RELOAD IMPORTED SHAPE
112     {
113       SalomeApp_Study* anAppStudy = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
114
115       GEOM::GEOM_ITransformOperations_var anOp =
116         GeometryGUI::GetGeomGen()->GetITransformOperations(anAppStudy->id());
117       if (anOp->_is_nil()) return false;
118
119       GEOM_Displayer aDisp (anAppStudy);
120       SUIT_Desktop* desk = app->desktop();
121       QList<SUIT_ViewWindow*> wnds = desk->windows();
122
123       LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
124       SALOME_ListIO aSelList;
125       aSelMgr->selectedObjects(aSelList);
126
127       SALOME_ListIteratorOfListIO aSelIt (aSelList);
128       for (; aSelIt.More(); aSelIt.Next()) {
129         Handle(SALOME_InteractiveObject) io = aSelIt.Value();
130         GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( io );
131         if ( !CORBA::is_nil( aGeomObj ) ) {
132           anOp->RecomputeObject(aGeomObj);
133
134           SUIT_ViewWindow* wnd;
135           QListIterator<SUIT_ViewWindow*> it (wnds);
136           while (it.hasNext() && (wnd = it.next()))
137           {
138             if (SUIT_ViewManager* vman = wnd->getViewManager()) {
139               if (SUIT_ViewModel* vmodel = vman->getViewModel()) {
140                 if (SALOME_View* view = dynamic_cast<SALOME_View*>(vmodel)) {
141                   if (view->isVisible(io)) {
142                     aDisp.Erase(io, true, false, view);
143                     getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer( getGeometryGUI()->getApp()->orb()->object_to_string( aGeomObj.in() ) );
144                     aDisp.Display(io, true, view);
145                   }
146                   // ? Redisplay subshapes ?
147                 }
148               }
149             }
150           }
151         }
152       } // for (; aSelIt.More(); aSelIt.Next())
153     }
154     break;
155   case GEOMOp::OpExtension:     // EXTENSION
156     aDlg = new TransformationGUI_ExtensionDlg( getGeometryGUI(), parent );
157     break;
158   default:
159     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
160     break;
161   }
162
163   if ( aDlg != NULL )
164     aDlg->show();
165
166   return true;
167 }
168
169
170 //=====================================================================================
171 // EXPORTED METHODS
172 //=====================================================================================
173 extern "C"
174 {
175 #ifdef WIN32
176   __declspec( dllexport )
177 #endif
178   GEOMGUI* GetLibGUI( GeometryGUI* parent )
179   {
180     return new TransformationGUI( parent );
181   }
182 }