Salome HOME
untabify
[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
48 #include <QList>
49
50 #include <list>
51
52 #include <SALOMEconfig.h>
53 #include CORBA_CLIENT_HEADER(GEOM_Gen)
54
55 #define GEOM_ALLOBJECTS -1 // Selection of all objects is activated
56 #define GEOM_PREVIEW    -2 // Definition for preview selection
57 #define GEOM_ALLSHAPES  -3 // Selection of all shapes is activated
58 #define GEOM_ALLGEOM    -4 // Selection of all geom objects is activated
59
60 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
61
62 class TColStd_MapOfInteger;
63 class LightApp_SelectionMgr;
64 class SalomeApp_Study;
65 class SalomeApp_Application;
66 class SUIT_SelectionFilter;
67 class Handle_GEOM_AISShape;
68 //class SALOME_Selection;
69
70 class GEOMGUI_EXPORT GEOM_Displayer : public LightApp_Displayer
71 {
72
73 public:
74   /* Constructor */
75   GEOM_Displayer( SalomeApp_Study* app );
76   /* Destructor */
77   virtual ~GEOM_Displayer();
78
79   virtual bool canBeDisplayed( const QString& /*entry*/, const QString& /*viewer_type*/ ) const;
80
81   /* Display/Erase object methods */
82   void          Display   ( const Handle(SALOME_InteractiveObject)& theIO,
83                             const bool updateViewer = true,
84                             SALOME_View* theViewFrame = 0 );
85
86   // This overloaded Display() method can be useful for operations
87   // not using dialog boxes.
88   void          Display   ( GEOM::GEOM_Object_ptr theObj,
89                             const bool updateViewer = true );
90
91   void          Redisplay ( const Handle(SALOME_InteractiveObject)& theIO,
92                             const bool updateViewer = true );
93
94   void          Erase     ( const Handle(SALOME_InteractiveObject)& theIO,
95                             const bool forced = false,
96                             const bool updateViewer = true,
97                             SALOME_View* theViewFrame = 0 );
98
99   void          Erase     ( GEOM::GEOM_Object_ptr theObj,
100                             const bool forced = false,
101                             const bool updateViewer = true );
102
103   void          EraseWithChildren(const Handle(SALOME_InteractiveObject)& theIO,
104                                   const bool eraseOnlyChildren = false);
105
106   /* Display/Erase list of objects methods */
107
108   void          Display   ( const SALOME_ListIO& theIOList,
109                             const bool updateViewer = true );
110
111   void          Erase     ( const SALOME_ListIO& theIOList,
112                             const bool forced = false,
113                             const bool updateViewer = true );
114
115   void          Redisplay ( const SALOME_ListIO& theIOList,
116                             const bool updateViewer = true );
117
118   /* build presentation accordint to the current viewer type*/
119   SALOME_Prs*   BuildPrs  ( GEOM::GEOM_Object_ptr );
120   SALOME_Prs*   BuildPrs  ( const TopoDS_Shape& );
121
122   /* Set color for shape displaying. If it is equal -1 then default color is used.
123      Available values are from Quantity_NameOfColor enumeration */
124   void          SetColor  ( const int );
125   void          UnsetColor();
126   int           GetColor  () const;
127   bool          HasColor  () const;
128   
129   /* Set texture for shape displaying. */
130   void          SetTexture  ( const std::string& );
131   bool          HasTexture  () const;
132   std::string   GetTexture  () const;
133
134   /* Set width for shape displaying. If it is equal -1 then default width is used. */
135   void          SetWidth  ( const double );
136   void          UnsetWidth();
137   double        GetWidth  () const;
138   bool          HasWidth  () const;
139
140   /* Set width for iso-lines displaying. If it is equal -1 then default width is used. */
141   void          SetIsosWidth  ( const int );
142   int           GetIsosWidth  () const;
143   bool          HasIsosWidth  () const;
144   
145   /* Set display mode shape displaying. If it is equal -1 then display mode is used. */
146   int           SetDisplayMode( const int );
147   int           GetDisplayMode() const;
148   int           UnsetDisplayMode();
149   bool          HasDisplayMode() const;
150
151   /* Sets name - for temporary objects only */
152   void          SetName( const char* theName );
153   void          UnsetName();
154
155   /* Reimplemented from SALOME_Displayer */
156   virtual void  Update( SALOME_OCCPrs* );
157   virtual void  Update( SALOME_VTKPrs* );
158   virtual void  BeforeDisplay( SALOME_View*, const SALOME_OCCPrs* );
159   virtual void  AfterDisplay ( SALOME_View*, const SALOME_OCCPrs* );
160
161   /* This methos is used for activisation/deactivisation of objects to be displayed*/
162   void          SetToActivate( const bool );
163   bool          ToActivate() const;
164
165   /* Activate/Deactivate selection*/
166   void         LocalSelection( const Handle(SALOME_InteractiveObject)&, const int );
167   void         LocalSelection( const SALOME_ListIO& theIOList, const int );
168   void         GlobalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
169   void         GlobalSelection( const TColStd_MapOfInteger&, const bool = false, const QList<int>* = 0 );
170
171   SalomeApp_Study* getStudy() const;
172
173   static SALOMEDS::Color getUniqueColor( const QList<SALOMEDS::Color>& );
174   static SALOMEDS::Color getPredefinedUniqueColor();
175
176   /*Get color of the geom object*/
177   static SALOMEDS::Color getColor(GEOM::GEOM_Object_var aGeomObject, bool& hasColor);
178
179   /* Get minimum or maximum enclosed shape type */
180   static int getMinMaxShapeType( const TopoDS_Shape& shape, bool ismin );
181
182   /* Check if the object is a vertex or a compound of vertices */
183   static bool isCompoundOfVertices( const TopoDS_Shape& theShape );
184
185
186   /* Builds presentation of not published object */
187   virtual SALOME_Prs* buildSubshapePresentation(const TopoDS_Shape& aShape,
188                                                 const QString&,
189                                                 SALOME_View* = 0);
190
191 protected:
192   /* internal methods */
193   /* Builds presentation according to the current viewer type */
194   virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
195
196   /* Sets interactive object */
197   void        setIO( const Handle(SALOME_InteractiveObject)& theIO );
198
199   /* Sets shape */
200   void        setShape( const TopoDS_Shape& theShape );
201
202   /* Resets internal data */
203   void        internalReset();
204
205   void        clearTemporary( LightApp_SelectionMgr* theSelMgr );
206
207   SUIT_SelectionFilter* getFilter( const int theMode );
208   SUIT_SelectionFilter* getComplexFilter( const QList<int>* );
209
210   Quantity_Color qColorFromResources( const QString&, const QColor& );
211   QColor         colorFromResources( const QString&, const QColor& );
212   void           updateShapeProperties( const Handle(GEOM_AISShape)&, bool );
213   void           updateActorProperties( GEOM_Actor*, bool );
214
215   PropMap getObjectProperties( SalomeApp_Study*, const QString&, SALOME_View* = 0 );
216   PropMap getDefaultPropertyMap();
217   
218 protected:
219   Handle(SALOME_InteractiveObject) myIO;
220   TopoDS_Shape                     myShape;
221   std::string                      myName;
222   std::string                      myTexture;
223   int                              myType;
224   SALOME_View*                     myViewFrame;
225
226   // Attributes
227   Quantity_Color                   myShadingColor;
228   int                              myColor;
229   double                           myWidth;
230   int                              myIsosWidth;
231   bool                             myToActivate;
232   int                              myDisplayMode;
233   bool                             myHasDisplayMode;
234   Aspect_TypeOfMarker              myTypeOfMarker;
235   double                           myScaleOfMarker;
236
237 private:
238   SalomeApp_Application* myApp;
239   friend class GEOM_Swig;
240 };
241
242 #endif // GEOM_DISPLAYER_H
243