Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / TransformationGUI / TransformationGUI.cxx
1 // Copyright (C) 2007-2012  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
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_ListIteratorOfListIO.hxx>
41
42 #include "TransformationGUI_MultiTranslationDlg.h"   // Method MULTI TRANSLATION
43 #include "TransformationGUI_MultiRotationDlg.h"      // Method MULTI ROTATION
44 #include "TransformationGUI_TranslationDlg.h"        // Method TRANSLATION
45 #include "TransformationGUI_RotationDlg.h"           // Method ROTATION
46 #include "TransformationGUI_MirrorDlg.h"             // Method MIRROR
47 #include "TransformationGUI_ScaleDlg.h"              // Method SCALE
48 #include "TransformationGUI_OffsetDlg.h"             // Method OFFSET
49 #include "TransformationGUI_ProjectionDlg.h"         // Method PROJECTION
50 #include "TransformationGUI_PositionDlg.h"           // Method POSITION
51
52 //=======================================================================
53 // function : TransformationGUI()
54 // purpose  : Constructor
55 //=======================================================================
56 TransformationGUI::TransformationGUI( GeometryGUI* parent )
57   : GEOMGUI( parent )
58 {
59 }
60
61 //=======================================================================
62 // function : ~TransformationGUI()
63 // purpose  : Destructor
64 //=======================================================================
65 TransformationGUI::~TransformationGUI()
66 {
67 }
68
69
70 //=======================================================================
71 // function : OnGUIEvent()
72 // purpose  : 
73 //=======================================================================
74 bool TransformationGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
75 {
76   SalomeApp_Application* app = getGeometryGUI()->getApp();
77   if ( !app ) return false;
78
79   getGeometryGUI()->EmitSignalDeactivateDialog();
80   QDialog* aDlg = NULL;
81
82   switch ( theCommandID ) {
83   case GEOMOp::OpTranslate:      // TRANSLATION
84     aDlg = new TransformationGUI_TranslationDlg( getGeometryGUI(), parent );
85     break;
86   case GEOMOp::OpRotate:         // ROTATION
87     aDlg = new TransformationGUI_RotationDlg( getGeometryGUI(), parent );
88     break;
89   case GEOMOp::OpChangeLoc:      // POSITION
90     aDlg = new TransformationGUI_PositionDlg( getGeometryGUI(), parent );
91     break;
92   case GEOMOp::OpMirror:         // MIRROR
93     aDlg = new TransformationGUI_MirrorDlg( getGeometryGUI(), parent );
94     break;
95   case GEOMOp::OpScale:          // SCALE
96     aDlg = new TransformationGUI_ScaleDlg( getGeometryGUI(), parent );
97     break;
98   case GEOMOp::OpOffset:         // OFFSET
99     aDlg = new TransformationGUI_OffsetDlg( getGeometryGUI(), parent );
100     break;
101   case GEOMOp::OpProjection:     // PROJECTION
102     aDlg = new TransformationGUI_ProjectionDlg( getGeometryGUI(), parent );
103     break;
104   case GEOMOp::OpMultiTranslate: // MULTI TRANSLATION
105     aDlg = new TransformationGUI_MultiTranslationDlg( getGeometryGUI(), parent );
106     break;
107   case GEOMOp::OpMultiRotate:    // MULTI ROTATION
108     aDlg = new TransformationGUI_MultiRotationDlg( getGeometryGUI(), parent );
109     break;
110   case GEOMOp::OpReimport:       // 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       QList<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         GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( io );
130         if ( !CORBA::is_nil( aGeomObj ) ) {
131           anOp->RecomputeObject(aGeomObj);
132
133           SUIT_ViewWindow* wnd;
134           QListIterator<SUIT_ViewWindow*> it (wnds);
135           while (it.hasNext() && (wnd = it.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, true, false, view);
142                     getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer( getGeometryGUI()->getApp()->orb()->object_to_string( aGeomObj.in() ) );
143                     aDisp.Display(io, true, view);
144                   }
145                   // ? Redisplay subshapes ?
146                 }
147               }
148             }
149           }
150         }
151       } // for (; aSelIt.More(); aSelIt.Next())
152     }
153     break;
154   default:
155     app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
156     break;
157   }
158
159   if ( aDlg != NULL )
160     aDlg->show();
161
162   return true;
163 }
164
165
166 //=====================================================================================
167 // EXPORTED METHODS
168 //=====================================================================================
169 extern "C"
170 {
171 #ifdef WNT
172   __declspec( dllexport )
173 #endif
174   GEOMGUI* GetLibGUI( GeometryGUI* parent )
175   {
176     return new TransformationGUI( parent );
177   }
178 }