Salome HOME
Fix remarks related to the "0021757: EDF 1829 : Activate bring to front action on...
[modules/geom.git] / src / GEOMGUI / GEOM_Displayer.h
1 // Copyright (C) 2007-2013  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.
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
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 SALOME_Selection;
70
71 class GEOMGUI_EXPORT GEOM_Displayer : public LightApp_Displayer
72 {
73
74 public:
75   /* Constructor */
76   GEOM_Displayer( SalomeApp_Study* app );
77   /* Destructor */
78   virtual ~GEOM_Displayer();
79
80   virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const;
81
82   /* Display/Erase object methods */
83   void          Display   ( const Handle(SALOME_InteractiveObject)& theIO,
84                             const bool updateViewer = true,
85                             SALOME_View* theViewFrame = 0 );
86
87   // This overloaded Display() method can be useful for operations
88   // not using dialog boxes.
89   void          Display   ( GEOM::GEOM_BaseObject_ptr theObj,
90                             const bool updateViewer = true );
91
92   void          Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
93                             const bool updateViewer = true,
94                             const bool checkActiveViewer = true );
95
96   void          Erase     ( const Handle(SALOME_InteractiveObject)& theIO,
97                             const bool forced = false,
98                             const bool updateViewer = true,
99                             SALOME_View* theViewFrame = 0 );
100
101   void          Erase     ( GEOM::GEOM_BaseObject_ptr theObj,
102                             const bool forced = false,
103                             const bool updateViewer = true );
104
105   void          EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
106                                   const bool eraseOnlyChildren = false);
107
108   /* Display/Erase list of objects methods */
109
110   void          Display   ( const SALOME_ListIO& theIOList,
111                             const bool updateViewer = true );
112
113   void          Erase     ( const SALOME_ListIO& theIOList,
114                             const bool forced = false,
115                             const bool updateViewer = true );
116
117   void          Redisplay ( const SALOME_ListIO& theIOList,
118                             const bool updateViewer = true,
119                             const bool checkActiveViewer = true );
120
121   /* build presentation accordint to the current viewer type*/
122   SALOME_Prs*   BuildPrs  ( GEOM::GEOM_Object_ptr );
123   SALOME_Prs*   BuildPrs  ( const TopoDS_Shape& );
124
125   /* Set color for shape displaying. If it is equal -1 then default color is used.
126      Available values are from Quantity_NameOfColor enumeration */
127   void          SetColor  ( const int );
128   void          UnsetColor();
129   int           GetColor  () const;
130   bool          HasColor  () const;
131   
132   /* Set texture for shape displaying. */
133   void          SetTexture  ( const std::string& );
134   bool          HasTexture  () const;
135   std::string   GetTexture  () const;
136
137   /* Set width for shape displaying. If it is equal -1 then default width is used. */
138   void          SetWidth  ( const double );
139   void          UnsetWidth();
140   double        GetWidth  () const;
141   bool          HasWidth  () const;
142
143   /* Set width for iso-lines displaying. If it is equal -1 then default width is used. */
144   void          SetIsosWidth  ( const int );
145   int           GetIsosWidth  () const;
146   bool          HasIsosWidth  () const;
147   
148   /* Set display mode shape displaying. If it is equal -1 then display mode is used. */
149   int           SetDisplayMode( const int );
150   int           GetDisplayMode() const;
151   int           UnsetDisplayMode();
152   bool          HasDisplayMode() const;
153
154   /* Sets name - for temporary objects only */
155   void          SetName( const char* theName );
156   void          UnsetName();
157
158   /* Reimplemented from SALOME_Displayer */
159   virtual void  Update( SALOME_OCCPrs* );
160   virtual void  Update( SALOME_VTKPrs* );
161   virtual void  BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* );
162   virtual void  AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* );
163   virtual void  AfterErase   ( SALOME_View*, const SALOME_OCCPrs* );
164
165   /* This methos is used for activisation/deactivisation of objects to be displayed*/
166   void          SetToActivate( const bool );
167   bool          ToActivate() const;
168
169   /* Activate/Deactivate selection*/
170   void         LocalSelection( const Handle(SALOME_InteractiveObject)&, const int );
171   void         LocalSelection( const SALOME_ListIO& theIOList, const int );
172   void         GlobalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
173   void         GlobalSelection( const TColStd_MapOfInteger&, const bool = false, const QList<int>* = 0 );
174
175   SalomeApp_Study* getStudy() const;
176
177   static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
178   static SALOMEDS::Color getPredefinedUniqueColor();
179
180   /*Get color of the geom object*/
181   static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor);
182
183   /* Get minimum or maximum enclosed shape type */
184   static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin );
185
186   /* Check if the object is a vertex or a compound of vertices */
187   static bool isCompoundOfVertices( const TopoDS_Shape& theShape );
188
189
190   /* Builds presentation of not published object */
191   virtual SALOME_Prs* buildSubshapePresentation(const TopoDS_Shape& aShape,
192                                                 const QString&,
193                                                 SALOME_View* = 0);
194
195   /* Update visibility and parameters of the currently selected field step's color scale */
196   void UpdateColorScale( const bool theIsRedisplayFieldSteps = false, const bool updateViewer = true );
197
198 protected:
199   /* internal methods */
200   /* Builds presentation according to the current viewer type */
201   virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
202
203   /* Sets interactive object */
204   void        setIO( const Handle(SALOME_InteractiveObject)& theIO );
205
206   /* Sets shape */
207   void        setShape( const TopoDS_Shape& theShape );
208
209   /* Sets field step information */
210   void        setFieldStepInfo( const GEOM::field_data_type theFieldDataType,
211                                 const int theFieldDimension,
212                                 const QList<QVariant>& theFieldStepData,
213                                 const TCollection_AsciiString& theFieldStepName,
214                                 const double theFieldStepRangeMin,
215                                 const double theFieldStepRangeMax );
216
217   /* Resets internal data */
218   void        internalReset();
219
220   void        clearTemporary( LightApp_SelectionMgr* theSelMgr );
221
222   SUIT_SelectionFilter* getFilter( const int theMode );
223   SUIT_SelectionFilter* getComplexFilter( const QList<int>* );
224
225   Quantity_Color qColorFromResources( const QString&, const QColor& );
226   QColor         colorFromResources( const QString&, const QColor& );
227   void           updateShapeProperties( const Handle(GEOM_AISShape)&, bool );
228   void           updateActorProperties( GEOM_Actor*, bool );
229
230   PropMap getObjectProperties( SalomeApp_Study*, const QString&, SALOME_View* = 0 );
231   PropMap getDefaultPropertyMap();
232
233   /* Methods for reading the field step information */
234   void            readFieldStepInfo( GEOM::GEOM_FieldStep_var theGeomFieldStep );
235   QList<QVariant> groupFieldData( const QList<QVariant>& theFieldStepData,
236                                   const int theFieldNbComponents,
237                                   const bool theIsString,
238                                   double& theFieldStepRangeMin,
239                                   double& theFieldStepRangeMax );
240
241   // Note: the method is copied from Aspect_ColorScale class
242   static Standard_Integer HueFromValue( const Standard_Integer aValue,
243                                         const Standard_Integer aMin,
244                                         const Standard_Integer aMax );
245
246   // Note: the method is copied from Aspect_ColorScale class
247   static Standard_Boolean FindColor( const Standard_Real aValue, 
248                                      const Standard_Real aMin,
249                                      const Standard_Real aMax,
250                                      const Standard_Integer ColorsCount,
251                                      Quantity_Color& aColor );
252
253 protected:
254   Handle(SALOME_InteractiveObject) myIO;
255   TopoDS_Shape                     myShape;
256   GEOM::field_data_type            myFieldDataType;
257   int                              myFieldDimension;
258   QList<QVariant>                  myFieldStepData;
259   TCollection_AsciiString          myFieldStepName;
260   double                           myFieldStepRangeMin;
261   double                           myFieldStepRangeMax;
262   std::string                      myName;
263   std::string                      myTexture;
264   int                              myType;
265   SALOME_View*                     myViewFrame;
266
267   // Attributes
268   Quantity_Color                   myShadingColor;
269   int                              myColor;
270   double                           myWidth;
271   int                              myIsosWidth;
272   bool                             myToActivate;
273   int                              myDisplayMode;
274   bool                             myHasDisplayMode;
275   Aspect_TypeOfMarker              myTypeOfMarker;
276   double                           myScaleOfMarker;
277
278 private:
279   SalomeApp_Application* myApp;
280   friend class GEOM_Swig;
281 };
282
283 #endif // GEOM_DISPLAYER_H
284