Salome HOME
Fix for bug PAL9160 ( No shading on visualizations ).
[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 CAM_Module;
49 class SalomeApp_SelectionMgr;
50 class SalomeApp_Study;
51
52 namespace VISU {
53   class Prs3d_i;
54   class Result_i;
55   class Table_i;
56   class Curve_i;
57   class Container_i;
58
59   typedef std::vector<SVTK_ViewWindow*> TViewWindows;
60
61   SUIT_Desktop*                        GetDesktop(const CAM_Module* theModule);
62   SalomeApp_Study*                     GetAppStudy(const CAM_Module* theModule);
63   _PTR(Study)                          GetCStudy(const SalomeApp_Study* theStudy);
64
65   bool                                 IsStudyLocked( _PTR(Study) theStudy );
66   bool                                 CheckLock( _PTR(Study) theStudy );
67
68   inline void                          UpdateObjBrowser(SalomeApp_Module* theModule,
69                                                         bool updateDataModel = true);
70
71   VISU_Gen_i*                          GetVisuGen(const CAM_Module* theModule);
72   SALOME_MED::MED_Gen_var              GetMEDEngine();
73
74   VISU::Storable::TRestoringMap        getMapOfValue(_PTR(SObject) theSObject);
75   QString                              getValue(_PTR(SObject) theSObject, QString theKey);
76
77   // Selection
78   SalomeApp_SelectionMgr*              GetSelectionMgr(const SalomeApp_Module* theModule);
79   CORBA::Object_var                    GetSelectedObj(const SalomeApp_Study* theStudy,
80                                                       const QString& theEntry,
81                                                       VISU::Storable::TRestoringMap* theMap = NULL);
82   CORBA::Object_var                    GetSelectedObj(const SalomeApp_Module* theModule,
83                                                       Handle(SALOME_InteractiveObject)* theIO = NULL,
84                                                       VISU::Storable::TRestoringMap* theMap = NULL);
85   VISU::Prs3d_i*                       GetPrsToModify(const SalomeApp_Module* theModule,
86                                                       Handle(SALOME_InteractiveObject)* theIO = NULL,
87                                                       VISU::Storable::TRestoringMap* theMap = NULL);
88
89   void                                 Add(SalomeApp_SelectionMgr* theSelectionMgr,
90                                            const Handle(SALOME_InteractiveObject)& theIO);
91   void                                 Remove(SalomeApp_SelectionMgr* theSelectionMgr,
92                                               const Handle(SALOME_InteractiveObject)& theIO);
93
94   bool                                 IsRemovableSelected(const SalomeApp_Module* theModule);
95
96   // Display/Erase
97   void                                 ErasePrs(const SalomeApp_Module* theModule,
98                                                 CORBA::Object_ptr theObject,
99                                                 bool theUpdate = true);
100   void                                 DeleteSObject(SalomeApp_Module* theModule,
101                                                      _PTR(Study)       theStudy,
102                                                      _PTR(SObject)     theSObject);
103   void                                 DeletePrs3d(SalomeApp_Module* theModule,
104                                                    VISU::Prs3d_i* thePrs,
105                                                    const Handle(SALOME_InteractiveObject)& theIO);
106   void                                 ErasePrs3d(const SalomeApp_Module* theModule,
107                                                   VISU::Prs3d_i* thePrs);
108
109   // Presentation management
110   void ChangeRepresentation (const SalomeApp_Module* theModule,
111                              VISU::PresentationType  theType);
112
113   void SetShading ( const SalomeApp_Module* theModule, bool theOn = true );
114
115   // SObject type
116   bool                                 CheckTimeStamp(const SalomeApp_Module* theModule,
117                                                       _PTR(SObject)&          theSObject,
118                                                       Handle(SALOME_InteractiveObject)* theIO = NULL);
119   VISU::Result_i*                      CheckResult(const SalomeApp_Module* theModule,
120                                                    _PTR(SObject) theSource,
121                                                    VISU::Result_var& theResult);
122   inline bool                          IsSObjectTable(_PTR(SObject) theSObject);
123
124   // Views
125   SUIT_ViewWindow*                     GetActiveView(const SalomeApp_Module* theModule,
126                                                      QString theType = QString::null);
127
128   // VTK View
129   TViewWindows                         GetViews(const SalomeApp_Module* theModule);
130   SVTK_ViewWindow*                     GetViewWindow(const SalomeApp_Module* theModule,
131                                                      const bool theCreate = false );
132   SVTK_ViewWindow*                     GetViewWindow();
133
134   VISU_Actor*                          PublishInView(const SalomeApp_Module* theModule,
135                                                      VISU::Prs3d_i* thePrs);
136   VISU_Actor*                          UpdateViewer(const SalomeApp_Module* theModule,
137                                                     VISU::Prs3d_i* thePrs,
138                                                     bool theDispOnly = false);
139
140   /*!
141    * \brief Repaint all SVTK view windows, where the given object is displayed.
142    * \param theModule  - is used to access application.
143    * \param theIObject - is supposed to be selected (is highlighted in this method).
144    */
145   void                                 RepaintViewWindows(const SalomeApp_Module* theModule,
146                                                           const Handle(SALOME_InteractiveObject)& theIObject);
147
148   VISU_Actor*                          FindActor(SVTK_ViewWindow* theViewWindow,
149                                                  const char* theEntry);
150   VISU_Actor*                          FindActor(SVTK_ViewWindow* theViewWindow,
151                                                  VISU::Prs3d_i* thePrs);
152   void                                 RecreateActor(const SalomeApp_Module* theModule,
153                                                      VISU::Prs3d_i* thePrs);
154
155   /*!
156    * \brief Advanced FitAll, sets view projection in accordance with current view contents
157    *
158    * If common bounding box of all actors in \a theViewWindow has
159    * at least one small side, then corresponding projection will be set
160    * (Top, Left or Front), else 3D projection will be used.
161    *
162    * \param theViewWindow - the view to perform FitAll in.
163    */
164   void                                 SetFitAll(SVTK_ViewWindow* theViewWindow);
165
166   // Plot2d View
167   SPlot2d_Viewer*                      GetPlot2dViewer(const SalomeApp_Module* theModule,
168                                                        const bool theCreate = false);
169   void                                 PlotTable( const SalomeApp_Module* theModule,
170                                                   VISU::Table_i* table,
171                                                   int theDisplaying );
172   void                                 PlotCurve( const SalomeApp_Module* theModule,
173                                                   VISU::Curve_i* curve,
174                                                   int theDisplaying );
175   void                                 PlotContainer( const SalomeApp_Module* theModule,
176                                                       VISU::Container_i* container,
177                                                       int theDisplaying );
178   void                                 CreatePlot( SalomeApp_Module* theModule,
179                                                    _PTR(SObject) theSobj );
180
181   // Others
182   void CreateMesh (const SalomeApp_Module* theModule,
183                    const Handle(SALOME_InteractiveObject)& theIO);
184
185   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
186                                             const Handle(SALOME_InteractiveObject)& theIO);
187   std::vector<VISU::Prs3d_i*> GetPrs3dList (const SalomeApp_Module* theModule,
188                                             _PTR(SObject) theObject);
189 }
190
191 bool VISU::IsSObjectTable( _PTR(SObject) theSObject )
192 {
193   if ( theSObject ) {
194     _PTR(GenericAttribute) anAttr;
195     if (theSObject->FindAttribute( anAttr, "AttributeTableOfInteger" ))
196       return true;
197     if (theSObject->FindAttribute( anAttr, "AttributeTableOfReal" ))
198       return true;
199   }
200   return false;
201 }
202
203 void VISU::UpdateObjBrowser(SalomeApp_Module* theModule,
204                             bool updateDataModel)
205 {
206   theModule->updateObjBrowser(updateDataModel);
207   theModule->getApp()->updateActions();
208 }
209
210 #endif