Salome HOME
Merge remote-tracking branch 'origin/master' into rnc/t_shape_plugin
[modules/geom.git] / src / OBJECT / GEOM_Actor.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 OBJECT : interactive object for Geometry entities visualization
24 //  File   : GEOM_Actor.h
25 //  Author : Christophe ATTANASIO
26 //  Module : GEOM
27 //
28 #ifndef GEOM_ACTOR_H
29 #define GEOM_ACTOR_H
30
31 #include "GEOM_OBJECT_defs.hxx"
32 #include "GEOM_SmartPtr.h"
33
34 #include <SALOME_Actor.h>
35
36 #include <TopoDS_Shape.hxx>
37 #include <vtkSmartPointer.h>
38
39 class vtkCamera;
40
41 class GEOM_VertexSource;
42 typedef GEOM_SmartPtr<GEOM_VertexSource> PVertexSource;
43
44 class GEOM_EdgeSource;
45 typedef GEOM_SmartPtr<GEOM_EdgeSource> PEdgeSource;
46
47 class GEOM_WireframeFace;
48 typedef GEOM_SmartPtr<GEOM_WireframeFace> PWFaceSource;
49
50 class GEOM_ShadingFace;
51 typedef GEOM_SmartPtr<GEOM_ShadingFace> PSFaceSource;
52
53 class vtkRenderer;
54
55 class vtkAppendPolyData;
56 typedef GEOM_SmartPtr<vtkAppendPolyData> PAppendFilter;
57
58 class GEOM_OBJECT_EXPORT GEOM_Actor: public SALOME_Actor
59 {
60 public:
61   vtkTypeMacro(GEOM_Actor,SALOME_Actor);
62   static GEOM_Actor* New();
63
64   void SetShape(const TopoDS_Shape& theShape,
65                 float theDeflection,
66                 bool theIsVector = false);
67
68   void SetDeflection(float theDeflection);
69   float GetDeflection() const{ return myDeflection;}
70
71   void AddToRender(vtkRenderer* theRenderer);
72   void RemoveFromRender(vtkRenderer* theRenderer);
73
74   enum EDisplayMode{ eWireframe, eShading, eShadingWithEdges = eShading + 2 };
75
76 /*   void SetDisplayMode(EDisplayMode theMode);  */
77 /*   EDisplayMode GetDisplayMode() const { return myDisplayMode;}  */
78
79   void SetSelected(bool theIsSelected);
80   bool IsSelected() const { return myIsSelected;}
81
82   // OLD METHODS
83   // Properties
84   void SetHighlightProperty(vtkProperty* Prop);
85   void SetWireframeProperty(vtkProperty* Prop);
86   void SetShadingProperty(vtkProperty* Prop);
87
88   vtkProperty* GetWireframeProperty();
89   vtkProperty* GetShadingProperty();
90   vtkProperty* GetIsolatedEdgeProperty();
91   vtkProperty* GetVertexProperty();
92   vtkProperty* GetStandaloneVertexProperty();
93   vtkProperty* GetSharedEdgeProperty();
94   vtkProperty* GetFaceEdgeProperty();
95
96   void setDeflection(double adef);
97   virtual void setDisplayMode(int thenewmode);
98
99   // Description:
100   // This causes the actor to be rendered. It, in turn, will render the actor's
101   // property and then mapper.
102   virtual void Render(vtkRenderer *, vtkMapper *);
103   // Description:
104   // Release any graphics resources that are being consumed by this actor.
105   // The parameter window could be used to determine which graphic
106   // resources to release.
107   void ReleaseGraphicsResources(vtkWindow *);
108   const TopoDS_Shape& getTopo();
109   void setInputShape(const TopoDS_Shape& ashape, double adef1,
110                      int imode, bool isVector = false);
111   double getDeflection();
112   double isVector();
113
114   // SubShape
115   void SubShapeOn();
116   void SubShapeOff();
117
118   // Highlight
119   virtual void highlight(bool theHighlight);
120   virtual bool hasHighlight() { return true; }
121
122   void ShallowCopy(vtkProp *prop);
123
124   // Opacity
125   void SetOpacity(double opa);
126   double GetOpacity();
127
128   // Color (same to all sub-actors/display modes)
129   void SetColor(double r,  double g,  double b);
130   void GetColor(double& r, double& g, double& b);
131   // Color of points
132   void SetPointColor(double r, double g, double b);
133   // Color of standalone edges, wires, vectors
134   void SetIsolatedEdgeColor(double r, double g, double b);
135   // Color of shared edges
136   void SetSharedEdgeColor(double r, double g, double b);
137   // Color of free edges
138   void SetFreeEdgeColor(double r, double g, double b);
139   // Color of edges in shading+edges display mode
140   void SetEdgesInShadingColor(double r, double g, double b);
141   // Color of iso-lines
142   void SetIsosColor(double r, double g, double b);
143
144
145   // Material
146   void SetMaterial(std::vector<vtkProperty*> theProps);
147   vtkProperty* GetFrontMaterial();
148   vtkProperty* GetBackMaterial();
149   virtual bool IsInfinitive();
150
151   // overloaded functions
152   //! To map current selection to VTK representation
153   virtual
154   void
155   Highlight(bool theHighlight);
156
157   //----------------------------------------------------------------------------
158   //! To process prehighlight (called from #SVTK_InteractorStyle)
159   virtual
160   bool
161   PreHighlight(vtkInteractorStyle* theInteractorStyle,
162                SVTK_SelectionEvent* theSelectionEvent,
163                bool theIsHighlight);
164
165   //! To process highlight (called from #SVTK_InteractorStyle)
166   virtual
167   bool
168   Highlight(vtkInteractorStyle* theInteractorStyle,
169             SVTK_SelectionEvent* theSelectionEvent,
170             bool theIsHighlight);
171
172   //! Visibility management
173   virtual
174   void
175   SetVisibility( int );
176
177   //! IsoLines management
178   // theNb[0] - number of U lines
179   // theNb[1] - number of V lines
180   virtual
181   void
182   SetNbIsos(const int theNb[2]);
183
184   virtual
185   void
186   GetNbIsos(int &theNbU,int &theNbV);
187   
188   virtual 
189   void SetIsosWidth(const int width);
190
191   int GetIsosWidth() const;
192
193   virtual void SetWidth(const int width);
194
195   int GetWidth() const;
196   
197   //! Vector mode management
198   virtual
199   void
200   SetVectorMode(const bool theMode);
201
202   virtual
203   bool
204   GetVectorMode();
205
206   //! Vertices mode management
207   virtual
208   void
209   SetVerticesMode(const bool theMode);
210
211   virtual
212   bool
213   GetVerticesMode();
214
215 protected:
216   void SetModified();
217
218   void GetMatrix(vtkCamera* theCam, vtkMatrix4x4 *result);
219
220   GEOM_Actor();
221   ~GEOM_Actor();
222
223 private:
224   TopoDS_Shape myShape;
225   bool isOnlyVertex;
226
227   float myDeflection;
228   bool myIsForced;
229
230   //  EDisplayMode myDisplayMode;
231   bool myIsSelected;
232   bool myVectorMode;
233   bool myVerticesMode;
234
235   PDeviceActor myVertexActor;
236   PVertexSource myVertexSource;
237
238   PDeviceActor myStandaloneVertexActor;
239   PVertexSource myStandaloneVertexSource;
240
241   PDeviceActor myIsolatedEdgeActor;
242   PEdgeSource myIsolatedEdgeSource;
243
244   PDeviceActor myOneFaceEdgeActor;
245   PEdgeSource myOneFaceEdgeSource;
246
247   PDeviceActor mySharedEdgeActor;
248   PEdgeSource mySharedEdgeSource;
249
250   PDeviceActor myWireframeFaceActor;
251   PWFaceSource myWireframeFaceSource;
252
253   PDeviceActor myShadingFaceActor;
254   PSFaceSource myShadingFaceSource;
255
256   PDeviceActor myHighlightActor;
257   vtkSmartPointer<vtkProperty>  myHighlightProp;
258   vtkSmartPointer<vtkProperty>  myPreHighlightProp;
259   vtkSmartPointer<vtkProperty>  myShadingFaceProp;
260   vtkSmartPointer<vtkProperty>  myShadingBackFaceProp;
261
262   PAppendFilter myAppendFilter;
263   PPolyGeomPainterDataMapper myPolyDataMapper;
264
265   virtual void SetMapper(vtkMapper*);
266
267   GEOM_Actor(const GEOM_Actor&);
268   void operator=(const GEOM_Actor&);
269
270   double myEdgesInWireframeColor[3];
271   double myEdgesInShadingColor[3];
272   double myIsolatedEdgeColor[3];
273   double mySharedEdgeColor[3];
274   double myOneFaceEdgeColor[3];
275 };
276
277 #endif //GEOM_ACTOR_H
278
279