Salome HOME
Update copyrights 2014.
[modules/geom.git] / src / GEOMGUI / GeometryGUI.h
1 // Copyright (C) 2007-2014  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   : GeometryGUI.h
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26
27 #ifndef GEOMETRYGUI_H
28 #define GEOMETRYGUI_H
29
30 #include "GEOM_GEOMGUI.hxx"
31
32 #include <Basics_OCCTVersion.hxx>
33
34 #include <SalomeApp_Module.h>
35
36 #include <GEOM_Client.hxx>
37 #include <SALOME_InteractiveObject.hxx>
38 #include <SALOMEDSClient.hxx>
39
40 #include "GEOMGUI.h"
41 #include "GEOMPluginGUI.h"
42
43 // QT Includes
44 #include <QMap>
45 #include <QPair>
46
47 // OCCT Includes
48 #include <gp_Ax3.hxx>
49
50 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
51 #include <TColStd_HArray1OfByte.hxx>
52 #else
53 #include <Graphic3d_HArray1OfBytes.hxx>
54 #endif
55
56 // IDL headers
57 #include "SALOMEconfig.h"
58 #include CORBA_CLIENT_HEADER(SALOMEDS)
59
60 #include <SALOME_ListIO.hxx>
61
62 class QDialog;
63 class QMenu;
64 class QAction;
65 class GEOMGUI_OCCSelector;
66 class LightApp_VTKSelector;
67 class LightApp_Selection;
68 class SUIT_ViewManager;
69 class SalomeApp_Study;
70 class GEOMGUI_CreationInfoWdg;
71
72 //=================================================================================
73 // class    : GeometryGUI
74 // purpose  :
75 //=================================================================================
76 class  GEOMGUI_EXPORT GeometryGUI : public SalomeApp_Module
77 {
78   Q_OBJECT;
79
80 public:
81   // Constructor
82   GeometryGUI();
83
84   // Destructor
85   ~GeometryGUI();
86
87   virtual LightApp_Displayer* displayer();
88   virtual void                initialize( CAM_Application* );
89   virtual QString             engineIOR() const;
90
91 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
92   static Handle(TColStd_HArray1OfByte) getTexture (SalomeApp_Study*, int, int&, int&);
93 #else
94   static Handle(Graphic3d_HArray1OfBytes) getTexture (SalomeApp_Study*, int, int&, int&);
95 #endif
96
97   static bool                 InitGeomGen();
98
99   static  GEOM::GEOM_Gen_var  GetGeomGen();
100
101   static CORBA::Object_var    ClientSObjectToObject (_PTR(SObject) theSObject);
102   static SALOMEDS::Study_var  ClientStudyToStudy (_PTR(Study) theStudy);
103
104   static void                 Modified( bool = true );
105
106   GEOM_Client&                GetShapeReader()    { static SHAPE_READER(myShapeReader);return myShapeReader; }
107
108   // Get active dialog box
109   QDialog*                    GetActiveDialogBox(){ return myActiveDialogBox; }
110   // Set active dialog box
111   void                        SetActiveDialogBox( QDialog* aDlg );
112
113   // Non modal dialog boxes management
114   void                        EmitSignalDeactivateDialog();
115   void                        EmitSignalCloseAllDialogs();
116   void                        EmitSignalDefaultStepValueChanged( double newVal );
117
118   // Process action
119   void                        OnGUIEvent( int id, const QVariant& theParam =  QVariant( QVariant::Invalid ) );
120   virtual bool                activateOperation( int actionId );
121   virtual bool                activateOperation( const QString& actionId );
122   virtual bool                activateOperation( const QString& actionId, const QString& plugin );
123
124   // The Working Plane management
125   void                        SetWorkingPlane( gp_Ax3 wp ) { myWorkingPlane = wp;   }
126   gp_Ax3                      GetWorkingPlane()            { return myWorkingPlane; }
127   void                        ActiveWorkingPlane();
128
129   virtual bool                renameObject( const QString&, const QString& );
130   virtual bool                renameAllowed( const QString& ) const;
131
132   virtual void                windows( QMap<int, int>& ) const;
133   virtual void                viewManagers( QStringList& ) const;
134
135   virtual void                contextMenuPopup( const QString&, QMenu*, QString& );
136   virtual void                createPreferences();
137   virtual void                preferencesChanged( const QString&, const QString& );
138   int                         getLocalSelectionMode() const;
139   void                        setLocalSelectionMode(const int mode);
140
141   virtual void storeVisualParameters  (int savePoint);
142   virtual void restoreVisualParameters(int savePoint);
143
144   QAction*                    getAction(const int id);
145
146   virtual void                message( const QString& msg);
147   static void                 ClearShapeBuffer( GEOM::GEOM_Object_ptr );
148   static GEOM::GEOM_Object_ptr
149                               GetObjectFromIOR( const QString& IOR );
150
151   static QString              GetIORFromObject( GEOM::GEOM_Object_ptr object );
152
153   virtual bool                isDraggable( const SUIT_DataObject* what ) const;
154   virtual bool                isDropAccepted( const SUIT_DataObject* where ) const;
155   virtual void                dropObjects( const DataObjectList& what, 
156                                            SUIT_DataObject* where,
157                                            const int row, Qt::DropAction action );
158
159 public slots:
160   virtual bool                deactivateModule( SUIT_Study* );
161   virtual bool                activateModule( SUIT_Study* );
162   virtual void                OnKeyPress  ( SUIT_ViewWindow*, QKeyEvent*   );
163   virtual void                OnMousePress( SUIT_ViewWindow*, QMouseEvent* );
164   virtual void                OnMouseMove ( SUIT_ViewWindow*, QMouseEvent* );
165   virtual void                OnMouseRelease ( SUIT_ViewWindow*, QMouseEvent* );
166
167 protected slots:
168   virtual void                onViewManagerAdded( SUIT_ViewManager* );
169   virtual void                onViewManagerRemoved( SUIT_ViewManager* );
170
171 private slots:
172   void                        OnGUIEvent();
173   void                        onWindowActivated( SUIT_ViewWindow* );
174   void                        onViewAboutToShow();
175   void                        OnSetMaterial( const QString& );
176   void                        updateMaterials();
177   void                        updateCreationInfo();
178   void                        onAutoBringToFront();
179   void                        updateFieldColorScale();
180
181 signals :
182   void                        SignalDeactivateActiveDialog();
183   void                        SignalCloseAllDialogs();
184   void                        SignalDefaultStepValueChanged( double newVal );
185
186 protected:
187   virtual LightApp_Selection* createSelection() const;
188
189 private:
190   GEOMGUI*                    getLibrary( const QString& libraryName );
191   GEOMPluginGUI*              getPluginLibrary( const QString& libraryName );
192   void                        createGeomAction( const int id, const QString& po_id,
193                                                 const QString& icon_id = QString(""),
194                                                 const int key = 0, const bool toggle = false,
195                                                 const QString& shortcutAction = QString() );
196   void                        createPopupItem( const int, const QString& clients, const QString& types,
197                                                const bool isSingle = false, const int isVisible = -1,
198                                                const bool isExpandAll = false, const bool isOCC = false,
199                                                const int parentId = -1 );
200   void                        addPluginActions();
201
202   void                        createOriginAndBaseVectors();
203
204 public:
205   static GEOM::GEOM_Gen_var   myComponentGeom;   // GEOM engine!!!
206
207 private:  
208
209 #if OCC_VERSION_LARGE > 0x06040000 // Porting to OCCT6.5.1
210   typedef QMap<long, Handle(TColStd_HArray1OfByte)> TextureMap;
211 #else
212   typedef QMap<long, Handle(Graphic3d_HArray1OfBytes)> TextureMap;
213 #endif
214
215   typedef QMap<long, TextureMap> StudyTextureMap;
216   typedef QMap<QString, GEOMGUI*> GUIMap;
217
218   typedef QPair<QString, QString> PluginAction;
219
220   GUIMap                      myGUIMap;          // GUI libraries map
221   QDialog*                    myActiveDialogBox; // active dialog box
222   gp_Ax3                      myWorkingPlane;
223   //QMap<int,QString>           myRules;           // popup rules
224   static StudyTextureMap      myTextureMap;      // texture map
225
226   QMap<int, PluginAction>      myPluginActions; // plugin actions
227   QMap<QString, QString>       myPluginLibs;    // plugin name to plugin client library
228
229   QList<GEOMGUI_OCCSelector*>  myOCCSelectors;
230   QList<LightApp_VTKSelector*> myVTKSelectors;
231
232   LightApp_Displayer*         myDisplayer;
233   int                         myLocalSelectionMode; //Select Only
234
235   GEOMGUI_CreationInfoWdg*    myCreationInfoWdg;
236   
237   SALOME_ListIO               myTopLevelIOList;               
238
239   friend class DisplayGUI;
240 };
241
242 #endif