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