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