Salome HOME
Implementation '22873: EDF 8651 GEOM: Annotate shapes into the OCC viewer' issue
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.h
1 // Copyright (C) 2007-2016  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   : GEOM_Displayer.h
25 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 //
27 #ifndef GEOM_DISPLAYER_H
28 #define GEOM_DISPLAYER_H
29
30 #include "GEOM_GEOMGUI.hxx"
31 #include <GEOM_AISShape.hxx>
32
33 #include <SALOME_InteractiveObject.hxx>
34
35 class GEOM_Actor;
36 class SALOME_ListIO;
37 class SALOME_View;
38 class SALOME_Prs;
39 class SALOME_OCCPrs;
40 class SALOME_VTKPrs;
41 class SALOME_OCCViewType;
42
43 #include <TopoDS_Shape.hxx>
44 #include <Quantity_Color.hxx>
45 #include <LightApp_Displayer.h>
46 #include <LightApp_Study.h>
47 #include <Aspect_TypeOfMarker.hxx>
48 #if OCC_VERSION_MAJOR >= 7
49   #include <AIS_ColorScale.hxx>
50 #endif
51 #include <TCollection_AsciiString.hxx>
52 #include <TColStd_MapOfInteger.hxx>
53 #include <Basics_OCCTVersion.hxx>
54 #include <QList>
55
56 #include <list>
57
58 #include <SALOMEconfig.h>
59 #include CORBA_CLIENT_HEADER(GEOM_Gen)
60
61 #define GEOM_ALLOBJECTS -1 // Selection of all objects is activated
62 #define GEOM_PREVIEW    -2 // Definition for preview selection
63 #define GEOM_ALLSHAPES  -3 // Selection of all shapes is activated
64 #define GEOM_ALLGEOM    -4 // Selection of all geom objects is activated
65
66 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
67
68 class LightApp_SelectionMgr;
69 class SalomeApp_Study;
70 class SalomeApp_Application;
71 class SUIT_SelectionFilter;
72 class gp_Ax3;
73
74 class GEOMGUI_EXPORT GEOM_Displayer : public LightApp_Displayer
75 {
76
77 public:
78   /* Constructor */
79   GEOM_Displayer( SalomeApp_Study* app );
80   /* Destructor */
81   virtual ~GEOM_Displayer();
82
83   virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const;
84
85   /* Display/Erase object methods */
86   void          Display   ( const Handle(SALOME_InteractiveObject)& theIO,
87                             const bool updateViewer = true,
88                             SALOME_View* theViewFrame = 0 );
89
90   // This overloaded Display() method can be useful for operations
91   // not using dialog boxes.
92   void          Display   ( GEOM::GEOM_BaseObject_ptr theObj,
93                             const bool updateViewer = true );
94
95   void          Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
96                             const bool updateViewer = true,
97                             const bool checkActiveViewer = true );
98
99   void          Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
100                             const bool theUpdateViewer,
101                             SALOME_View* theViewFrame );
102
103   void          Erase     ( const Handle(SALOME_InteractiveObject)& theIO,
104                             const bool forced = false,
105                             const bool updateViewer = true,
106                             SALOME_View* theViewFrame = 0 );
107
108   void          Erase     ( GEOM::GEOM_BaseObject_ptr theObj,
109                             const bool forced = false,
110                             const bool updateViewer = true,
111                             SALOME_View* theViewFrame = 0);
112
113   void          EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
114                                   const bool eraseOnlyChildren = false);
115
116   /* Display/Erase list of objects methods */
117
118   void          Display   ( const SALOME_ListIO& theIOList,
119                             const bool updateViewer = true );
120
121   void          Erase     ( const SALOME_ListIO& theIOList,
122                             const bool forced = false,
123                             const bool updateViewer = true );
124
125   void          Redisplay ( const SALOME_ListIO& theIOList,
126                             const bool updateViewer = true,
127                             const bool checkActiveViewer = true );
128
129   void          Redisplay ( const SALOME_ListIO& theIOList,
130                             const bool theUpdateViewer,
131                             SALOME_View* theViewFrame );
132
133   /* Update visibility state */
134   void          UpdateVisibility( SALOME_View*, const SALOME_Prs*, bool );
135
136   /* build presentation accordint to the current viewer type*/
137   SALOME_Prs*   BuildPrs  ( GEOM::GEOM_Object_ptr );
138   SALOME_Prs*   BuildPrs  ( const TopoDS_Shape& );
139
140   /* Set color for shape displaying. If it is equal -1 then default color is used.
141      Available values are from Quantity_NameOfColor enumeration */
142   void          SetColor  ( const int );
143   void          UnsetColor();
144   int           GetColor  () const;
145   bool          HasColor  () const;
146
147   double        SetTransparency  ( const double );
148   double        UnsetTransparency();
149   double        GetTransparency  () const;
150   bool          HasTransparency  () const;
151   
152   /* Set texture for shape displaying. */
153   void          SetTexture  ( const std::string& );
154   bool          HasTexture  () const;
155   std::string   GetTexture  () const;
156
157   /* Set width for shape displaying. If it is equal -1 then default width is used. */
158   void          SetWidth  ( const double );
159   void          UnsetWidth();
160   double        GetWidth  () const;
161   bool          HasWidth  () const;
162
163   /* Set width for iso-lines displaying. If it is equal -1 then default width is used. */
164   void          SetIsosWidth  ( const int );
165   int           GetIsosWidth  () const;
166   bool          HasIsosWidth  () const;
167  
168   /* Set nb iso-libes for displaying. Use -1 to set default values. */
169   int           SetNbIsos( const int );
170   int           UnsetNbIsos();
171   int           GetNbIsos() const;
172   bool          HasNbIsos() const;
173   
174   /* Set color for iso-lines displaying. If it is equal -1 then default color is used.
175      Available values are from Quantity_NameOfColor enumeration */
176   int           SetIsosColor  ( const int );
177   int           UnsetIsosColor();
178   int           GetIsosColor  () const;
179   bool          HasIsosColor  () const;
180  
181   /* Set display mode shape displaying. If it is equal -1 then display mode is used. */
182   int           SetDisplayMode( const int );
183   int           GetDisplayMode() const;
184   int           UnsetDisplayMode();
185   bool          HasDisplayMode() const;
186
187   /* Sets name - for temporary objects only */
188   void          SetName( const char* theName );
189   void          UnsetName();
190
191   /* Reimplemented from SALOME_Displayer */
192   virtual void  Update( SALOME_OCCPrs* );
193   virtual void  Update( SALOME_VTKPrs* );
194   virtual void  BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* );
195   virtual void  AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* );
196   virtual void  BeforeErase  ( SALOME_View*, const SALOME_OCCPrs* );
197   virtual void  AfterErase   ( SALOME_View*, const SALOME_OCCPrs* );
198
199   /* This methos is used for activisation/deactivisation of objects to be displayed*/
200   void          SetToActivate( const bool );
201   bool          ToActivate() const;
202
203   /* Activate/Deactivate selection*/
204   void         LocalSelection( const Handle(SALOME_InteractiveObject)&, const std::list<int> );
205   void         LocalSelection( const Handle(SALOME_InteractiveObject)&, const int );
206   void         LocalSelection( const SALOME_ListIO& theIOList, const std::list<int> );
207   void         LocalSelection( const SALOME_ListIO& theIOList, const int );
208   void         GlobalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
209   void         GlobalSelection( const TColStd_MapOfInteger&, const bool = false, const QList<int>* = 0 );
210
211   SalomeApp_Study* getStudy() const;
212
213   static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
214   static SALOMEDS::Color getPredefinedUniqueColor();
215
216   /*Get color of the geom object*/
217   static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor);
218
219   /* Get minimum or maximum enclosed shape type */
220   static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin );
221
222   /* Check if the object is a vertex or a compound of vertices */
223   static bool isCompoundOfVertices( const TopoDS_Shape& theShape );
224
225
226   /* Builds presentation of not published object */
227   virtual SALOME_Prs* buildSubshapePresentation(const TopoDS_Shape& aShape,
228                                                 const QString&,
229                                                 SALOME_View* = 0);
230
231   /* Update visibility and parameters of the currently selected field step's color scale */
232   void UpdateColorScale( const bool theIsRedisplayFieldSteps = false, const bool updateViewer = true );
233
234 protected:
235   /* internal methods */
236   /* Builds presentation according to the current viewer type */
237   virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
238
239   /* Sets interactive object */
240   void        setIO( const Handle(SALOME_InteractiveObject)& theIO );
241
242   /* Sets shape */
243   void        setShape( const TopoDS_Shape& theShape );
244
245   /* Sets field step information */
246   void        setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
247                                 const int theFieldDimension,
248                                 const QList<QVariant>& theFieldStepData,
249                                 const TCollection_AsciiString& theFieldStepName,
250                                 const double theFieldStepRangeMin,
251                                 const double theFieldStepRangeMax );
252
253   /* Resets internal data */
254   void        internalReset();
255
256   void        clearTemporary( LightApp_SelectionMgr* theSelMgr );
257
258   SUIT_SelectionFilter* getFilter( const int theMode );
259   SUIT_SelectionFilter* getComplexFilter( const QList<int>* );
260
261   Quantity_Color qColorFromResources( const QString&, const QColor& );
262   QColor         colorFromResources( const QString&, const QColor& );
263   void           updateShapeProperties( const Handle(GEOM_AISShape)&, bool );
264   void           updateActorProperties( GEOM_Actor*, bool );
265   void           updateDimensions( const Handle(SALOME_InteractiveObject)&, SALOME_OCCPrs*, const gp_Ax3& );
266   void           updateShapeAnnotations( const Handle(SALOME_InteractiveObject)&, SALOME_OCCPrs*, const gp_Ax3& );
267
268   PropMap getObjectProperties( SalomeApp_Study*, const QString&, SALOME_View* = 0 );
269   PropMap getDefaultPropertyMap();
270
271   /* Methods for reading the field step information */
272   void            readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep );
273   QList<QVariant> groupFieldData( const QList<QVariant>& theFieldStepData,
274                                   const int theFieldNbComponents,
275                                   const bool theIsString,
276                                   double& theFieldStepRangeMin,
277                                   double& theFieldStepRangeMax );
278
279   // Note: the method is copied from Aspect_ColorScale class
280   static Standard_Integer HueFromValue( const Standard_Integer aValue,
281                                         const Standard_Integer aMin,
282                                         const Standard_Integer aMax );
283
284   // Note: the method is copied from Aspect_ColorScale class
285   static Standard_Boolean FindColor( const Standard_Real aValue, 
286                                      const Standard_Real aMin,
287                                      const Standard_Real aMax,
288                                      const Standard_Integer ColorsCount,
289                                      Quantity_Color& aColor );
290
291 protected:
292   Handle(SALOME_InteractiveObject) myIO;
293   TopoDS_Shape                     myShape;
294   GEOM::field_data_type            myFieldDataType;
295   int                              myFieldDimension;
296   QList<QVariant>                  myFieldStepData;
297   TCollection_AsciiString          myFieldStepName;
298   double                           myFieldStepRangeMin;
299   double                           myFieldStepRangeMax;
300   std::string                      myName;
301   std::string                      myTexture;
302   int                              myType;
303   SALOME_View*                     myViewFrame;
304 #if OCC_VERSION_MAJOR >= 7
305   Handle(AIS_ColorScale)           myColorScale;
306 #endif
307
308   // Attributes
309   Quantity_Color                   myShadingColor;
310   int                              myColor;
311   double                           myWidth;
312   int                              myIsosWidth;
313   int                              myNbIsos;
314   int                              myIsosColor;
315   bool                             myToActivate;
316   int                              myDisplayMode;
317   bool                             myHasDisplayMode;
318   Aspect_TypeOfMarker              myTypeOfMarker;
319   double                           myScaleOfMarker;
320   double                           myTransparency;
321   bool                             myIsRedisplayed;
322
323 private:
324   SalomeApp_Application* myApp;
325   friend class GEOM_Swig;
326 };
327
328 #endif // GEOM_DISPLAYER_H
329