]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Tools.h
Salome HOME
Improvement Bug PAL10652
[modules/visu.git] / src / VISUGUI / VisuGUI_Tools.h
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2005  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_Tools.h
25 //  Author : Sergey Anikin
26 //  Module : VISU
27
28 #ifndef VisuGUI_Tools_HeaderFile
29 #define VisuGUI_Tools_HeaderFile
30
31 #include "SALOME_InteractiveObject.hxx"
32
33 #include "VISUConfig.hh"
34
35 #include "SalomeApp_Module.h"
36 #include "SalomeApp_Application.h"
37
38 #include "SALOMEDSClient_Study.hxx"
39
40 #include "SALOMEconfig.h"
41 #include CORBA_SERVER_HEADER(MED_Gen)
42
43 class SUIT_Desktop;
44 class SUIT_ViewWindow;
45 class VISU_Actor;
46 class SVTK_ViewWindow;
47 class SPlot2d_Viewer;
48 class SPlot2d_Curve;
49 class Plot2d_ViewFrame;
50 class CAM_Module;
51 class LightApp_SelectionMgr;
52 class SalomeApp_Study;
53 class VisuGUI;
54
55 namespace VISU {
56   class Prs3d_i;
57   class Result_i;
58   class Table_i;
59   class Curve_i;
60   class Container_i;
61
62   typedef std::vector<SVTK_ViewWindow*> TViewWindows;
63
64   SUIT_Desktop*                        GetDesktop(const CAM_Module* theModule);
65   SalomeApp_Study*                     GetAppStudy(const CAM_Module* theModule);
66   _PTR(Study)                          GetCStudy(const SalomeApp_Study* theStudy);
67
68   bool                                 IsStudyLocked( _PTR(Study) theStudy );
69   bool                                 CheckLock( _PTR(Study) theStudy );
70
71   inline void                          UpdateObjBrowser(SalomeApp_Module* theModule,
72                                                         bool updateDataModel = true);
73
74   VISU_Gen_i*                          GetVisuGen(const CAM_Module* theModule);
75   SALOME_MED::MED_Gen_var              GetMEDEngine();
76
77   VISU::Storable::TRestoringMap        getMapOfValue(_PTR(SObject) theSObject);
78   QString                              getValue(_PTR(SObject) theSObject, QString theKey);
79
80   // Selection
81   LightApp_SelectionMgr*               GetSelectionMgr(const SalomeApp_Module* theModule);
82   CORBA::Object_var                    GetSelectedObj(const SalomeApp_Study* theStudy,
83                                                       const QString& theEntry,
84                                                       VISU::Storable::TRestoringMap* theMap = NULL);
85   CORBA::Object_var                    GetSelectedObj(const SalomeApp_Module* theModule,
86                                                       Handle(SALOME_InteractiveObject)* theIO = NULL,
87                                                       VISU::Storable::TRestoringMap* theMap = NULL);
88   VISU::Prs3d_i*                       GetPrsToModify(const SalomeApp_Module* theModule,
89                                                       Handle(SALOME_InteractiveObject)* theIO = NULL,
90                                                       VISU::Storable::TRestoringMap* theMap = NULL);
91
92   void                                 Add(LightApp_SelectionMgr* theSelectionMgr,
93                                            const Handle(SALOME_InteractiveObject)& theIO);
94   void                                 Remove(LightApp_SelectionMgr* theSelectionMgr,
95                                               const Handle(SALOME_InteractiveObject)& theIO);
96
97   bool                                 IsRemovableSelected(const SalomeApp_Module* theModule);
98
99   // Display/Erase
100   void                                 ErasePrs(const SalomeApp_Module* theModule,
101                                                 CORBA::Object_ptr theObject,
102                                                 bool theUpdate = true);
103   void                                 DeleteSObject(SalomeApp_Module* theModule,
104                                                      _PTR(Study)       theStudy,
105                                                      _PTR(SObject)     theSObject);
106   void                                 DeletePrs3d(SalomeApp_Module* theModule,
107                                                    VISU::Prs3d_i* thePrs,
108                                                    const Handle(SALOME_InteractiveObject)& theIO);
109   void                                 ErasePrs3d(const SalomeApp_Module* theModule,
110                                                   VISU::Prs3d_i* thePrs);
111
112   // Presentation management
113   void ChangeRepresentation (const SalomeApp_Module* theModule,
114                              VISU::PresentationType  theType);
115
116   void SetShading ( const SalomeApp_Module* theModule, bool theOn = true );
117
118   // SObject type
119   bool                                 CheckTimeStamp(const SalomeApp_Module* theModule,
120                                                       _PTR(SObject)&          theSObject,
121                                                       Handle(SALOME_InteractiveObject)* theIO = NULL);
122   VISU::Result_i*                      CheckResult(const SalomeApp_Module* theModule,
123                                                    _PTR(SObject) theSource,
124                                                    VISU::Result_var& theResult);
125   inline bool                          IsSObjectTable(_PTR(SObject) theSObject);
126
127   // Views
128   SUIT_ViewWindow*                     GetActiveView(const SalomeApp_Module* theModule,
129                                                      QString theType = QString::null);
130
131   // VTK View
132   TViewWindows                         GetViews(const SalomeApp_Module* theModule);
133   SVTK_ViewWindow*                     GetViewWindow(const SalomeApp_Module* theModule,
134                                                      const bool theCreate = false );
135   SVTK_ViewWindow*                     GetViewWindow();
136
137   VISU_Actor*                          PublishInView(const SalomeApp_Module* theModule,
138                                                      VISU::Prs3d_i* thePrs);
139   VISU_Actor*                          UpdateViewer(const SalomeApp_Module* theModule,
140                                                     VISU::Prs3d_i* thePrs,
141                                                     bool theDispOnly = false);
142
143   /*!
144    * \brief Repaint all SVTK view windows, where the given object is displayed.
145    * \param theModule  - is used to access application.
146    * \param theIObject - is supposed to be selected (is highlighted in this method).
147    */
148   void                                 RepaintViewWindows(const SalomeApp_Module* theModule,
149                                                           const Handle(SALOME_InteractiveObject)& theIObject);
150
151   VISU_Actor*                          FindActor(SVTK_ViewWindow* theViewWindow,
152                                                  const char* theEntry);
153   VISU_Actor*                          FindActor(SVTK_ViewWindow* theViewWindow,
154                                                  VISU::Prs3d_i* thePrs);
155   void                                 RecreateActor(const SalomeApp_Module* theModule,
156                                                      VISU::Prs3d_i* thePrs);
157
158   /*!
159    * \brief Advanced FitAll, sets view projection in accordance with current view contents
160    *
161    * If common bounding box of all actors in \a theViewWindow has
162    * at least one small side, then corresponding projection will be set
163    * (Top, Left or Front), else 3D projection will be used.
164    *
165    * \param theViewWindow - the view to perform FitAll in.
166    */
167   void                                 SetFitAll(SVTK_ViewWindow* theViewWindow);
168
169   // Plot2d View
170   SPlot2d_Viewer*                      GetPlot2dViewer(const SalomeApp_Module* theModule,
171                                                        const bool theCreate = false);
172   void                                 PlotTable( const SalomeApp_Module* theModule,
173                                                   VISU::Table_i* table,
174                                                   int theDisplaying );
175   void                                 PlotCurve( const SalomeApp_Module* theModule,
176                                                   VISU::Curve_i* curve,
177                                                   int theDisplaying );
178   void                                 PlotContainer( const SalomeApp_Module* theModule,
179                                                       VISU::Container_i* container,
180                                                       int theDisplaying );
181   void                                 CreatePlot( SalomeApp_Module* theModule,
182                                                    _PTR(SObject) theSobj );
183
184   void                                 UpdateCurve( VISU::Curve_i*,
185                                                     Plot2d_ViewFrame* frame,
186                                                     SPlot2d_Curve*,
187                                                     int theDisplaying );
188   //parameter frame may be 0, in this case there is only update without display/erase 
189
190   // Others
191   void CreateMesh (const SalomeApp_Module* theModule,
192                    const Handle(SALOME_InteractiveObject)& theIO);
193
194   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
195                                             const Handle(SALOME_InteractiveObject)& theIO);
196   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
197                                             _PTR(SObject) theObject);
198   
199   int GetFreePositionOfDefaultScalarBar(VisuGUI* theModule);
200   void AddScalarBarPosition(VisuGUI* theModule,VISU::Prs3d_i* thePrs3d, int pos);
201   void RemoveScalarBarPosition(VisuGUI* theModule,VISU::Prs3d_i* thePrs3d);
202   void RemoveScalarBarPosition(VisuGUI* theModule,SVTK_ViewWindow* vw,VISU::Prs3d_i* thePrs3d);
203   void RemoveScalarBarPosition(VisuGUI* theModule,CORBA::Object_ptr theObject);
204 }
205
206 bool VISU::IsSObjectTable( _PTR(SObject) theSObject )
207 {
208   if ( theSObject ) {
209     _PTR(GenericAttribute) anAttr;
210     if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
211       return true;
212     if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
213       return true;
214   }
215   return false;
216 }
217
218 void VISU::UpdateObjBrowser(SalomeApp_Module* theModule,
219                             bool updateDataModel)
220 {
221   theModule->updateObjBrowser(updateDataModel);
222   theModule->getApp()->updateActions();
223 }
224
225 #endif