Salome HOME
Update copyright info (2010->2011)
[modules/smesh.git] / src / OBJECT / SMESH_ActorDef.h
1 //  Copyright (C) 2007-2011  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 //  SMESH OBJECT : interactive object for SMESH visualization
24 //  File   : SMESH_ActorDef.h
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //
28 #ifndef SMESH_ACTORDEF_H
29 #define SMESH_ACTORDEF_H
30
31 #include "SMESH_Actor.h"
32 #include "SMESH_Object.h"
33
34 #include <vtkSmartPointer.h>
35
36 template <class T>
37 class TVTKSmartPtr: public vtkSmartPointer<T>
38 {
39 public:
40   TVTKSmartPtr() {}
41   TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer<T>(r) { 
42     if(r && theIsOwner) 
43       r->Delete();
44   }
45   TVTKSmartPtr& operator()(T* r, bool theIsOwner = false){ 
46     vtkSmartPointer<T>::operator=(r); 
47     if(r && theIsOwner) 
48       r->Delete();
49     return *this;
50   }
51   TVTKSmartPtr& operator=(T* r){ vtkSmartPointer<T>::operator=(r); return *this;}
52   T* Get() const { return this->GetPointer();}
53 };
54
55
56 class vtkProperty;
57 class vtkShrinkFilter;
58 class vtkPolyDataMapper;
59 class vtkUnstructuredGrid;
60 class vtkMergeFilter;
61 class vtkPolyData;
62
63 class vtkMapper;
64 class vtkActor2D;
65 class vtkMaskPoints;
66 class vtkLabeledDataMapper;
67 class vtkSelectVisiblePoints;
68
69 class vtkScalarBarActor;
70 class vtkLookupTable;
71
72 class vtkPlane;
73 class vtkImplicitBoolean;
74
75 class vtkTimeStamp;
76
77 class VTKViewer_CellCenters;
78
79 class SMESH_DeviceActor;
80
81
82 class SMESH_ActorDef : public SMESH_Actor
83 {
84   friend class SMESH_VisualObj;
85   friend class SMESH_Actor;
86
87  public:
88   vtkTypeMacro(SMESH_ActorDef,SMESH_Actor);
89   
90   virtual void ReleaseGraphicsResources(vtkWindow *renWin);
91   virtual int RenderOpaqueGeometry(vtkViewport *viewport);
92   virtual int RenderTranslucentGeometry(vtkViewport *viewport);
93   virtual void Render(vtkRenderer *ren);
94
95   virtual void AddToRender(vtkRenderer* theRenderer); 
96   virtual void RemoveFromRender(vtkRenderer* theRenderer);
97
98   virtual bool hasHighlight() { return true; }  
99   virtual void highlight(bool theHighlight);  
100   virtual void SetPreSelected(bool thePreselect = false);
101
102   virtual bool IsInfinitive();  
103
104   virtual void SetOpacity(vtkFloatingPointType theValue);
105   virtual vtkFloatingPointType GetOpacity();
106
107   virtual void SetSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
108   virtual void GetSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
109
110   virtual void SetBackSufaceColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
111   virtual void GetBackSufaceColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
112
113   virtual void SetEdgeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
114   virtual void GetEdgeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
115
116   virtual void SetNodeColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
117   virtual void GetNodeColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
118
119   virtual void Set0DColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
120   virtual void Get0DColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
121
122   virtual void SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
123   virtual void GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
124
125   virtual void SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b);
126   virtual void GetPreHighlightColor(vtkFloatingPointType& r,vtkFloatingPointType& g,vtkFloatingPointType& b);
127  
128   virtual vtkFloatingPointType GetLineWidth();
129   virtual void SetLineWidth(vtkFloatingPointType theVal);
130
131   virtual void Set0DSize(vtkFloatingPointType size);
132   virtual vtkFloatingPointType Get0DSize();
133
134   virtual int GetNodeObjId(int theVtkID);
135   virtual vtkFloatingPointType* GetNodeCoord(int theObjID);
136
137   virtual int GetElemObjId(int theVtkID);
138   virtual vtkCell* GetElemCell(int theObjID);
139
140   virtual int GetObjDimension( const int theObjId );
141
142   virtual void SetVisibility(int theMode);
143   void SetVisibility(int theMode, bool theIsUpdateRepersentation);
144
145   virtual void SetRepresentation(int theMode);
146   
147   virtual unsigned int GetEntityMode() const { return myEntityMode;}
148   virtual void SetEntityMode(unsigned int theMode);
149
150   virtual void SetPointRepresentation(bool theIsPointsVisible);
151   virtual bool GetPointRepresentation();
152
153   virtual vtkFloatingPointType* GetBounds();
154   virtual void SetTransform(VTKViewer_Transform* theTransform); 
155
156   virtual vtkUnstructuredGrid* GetUnstructuredGrid();
157   virtual vtkDataSet* GetInput();
158   virtual vtkMapper* GetMapper();
159
160   virtual vtkFloatingPointType GetShrinkFactor();
161   virtual void SetShrinkFactor(vtkFloatingPointType theValue);
162
163   virtual bool IsShrunkable() { return myIsShrinkable;}
164   virtual bool IsShrunk() { return myIsShrunk;}
165   virtual void SetShrink(); 
166   virtual void UnShrink(); 
167
168   virtual void SetPointsLabeled(bool theIsPointsLabeled);
169   virtual bool GetPointsLabeled(){ return myIsPointsLabeled;}
170
171   virtual void SetCellsLabeled(bool theIsCellsLabeled);
172   virtual bool GetCellsLabeled(){ return myIsCellsLabeled;}
173
174   virtual void SetFacesOriented(bool theIsFacesOriented);
175   virtual bool GetFacesOriented();
176
177   virtual void SetFacesOrientationColor(vtkFloatingPointType theColor[3]);
178   virtual void GetFacesOrientationColor(vtkFloatingPointType theColor[3]);
179
180   virtual void SetFacesOrientationScale(vtkFloatingPointType theScale);
181   virtual vtkFloatingPointType GetFacesOrientationScale();
182
183   virtual void SetFacesOrientation3DVectors(bool theState);
184   virtual bool GetFacesOrientation3DVectors();
185
186   virtual void SetControlMode(eControl theMode);
187   virtual eControl GetControlMode(){ return myControlMode;}
188
189   virtual vtkScalarBarActor* GetScalarBarActor(){ return myScalarBarActor;}
190
191   virtual void SetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType theDist, vtkPlane* thePlane);
192   virtual void GetPlaneParam(vtkFloatingPointType theDir[3], vtkFloatingPointType& theDist, vtkPlane* thePlane);
193
194   virtual void RemoveAllClippingPlanes();
195   virtual vtkIdType GetNumberOfClippingPlanes();
196   virtual vtkPlane* GetClippingPlane(vtkIdType theID);
197   virtual vtkIdType AddClippingPlane(vtkPlane* thePlane); 
198
199   virtual TVisualObjPtr GetObject() { return myVisualObj;}
200
201   virtual void SetControlsPrecision( const long p ) { myControlsPrecision = p; }
202   virtual long GetControlsPrecision() const { return myControlsPrecision; }
203
204   virtual void UpdateScalarBar();
205
206
207   virtual void SetQuadratic2DRepresentation(EQuadratic2DRepresentation);
208   virtual EQuadratic2DRepresentation GetQuadratic2DRepresentation();
209   
210   virtual void SetMarkerStd( VTK::MarkerType, VTK::MarkerScale );
211   virtual void SetMarkerTexture( int, VTK::MarkerTexture );
212
213  protected:
214   void SetControlMode(eControl theMode, bool theCheckEntityMode);
215   void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
216   bool IsImplicitFunctionUsed() const;
217
218   TVisualObjPtr myVisualObj;
219   vtkTimeStamp* myTimeStamp;
220
221   vtkScalarBarActor* myScalarBarActor;
222   vtkLookupTable* myLookupTable;
223
224   vtkProperty* mySurfaceProp;
225   vtkProperty* myBackSurfaceProp;
226   vtkProperty* myEdgeProp;
227   vtkProperty* myNodeProp;
228
229   SMESH_DeviceActor* myBaseActor;
230   SMESH_DeviceActor* myNodeActor;
231   SMESH_DeviceActor* myPickableActor;
232
233   vtkProperty* myHighlightProp;
234   vtkProperty* myPreselectProp;
235   SMESH_DeviceActor* myHighlitableActor;
236
237   eControl myControlMode;
238   vtkProperty* my2DExtProp;
239   SMESH_DeviceActor* my2DActor;
240   SMESH_DeviceActor* my2DExtActor;
241   SMESH_DeviceActor* my3DActor;
242   SMESH_DeviceActor* myControlActor;
243
244   vtkProperty* myNodeExtProp;
245   SMESH_DeviceActor* myNodeExtActor;
246
247   vtkProperty* my1DProp;
248   SMESH_DeviceActor* my1DActor;
249   vtkProperty* my1DExtProp;
250   SMESH_DeviceActor* my1DExtActor;
251
252   vtkProperty* my0DProp;
253   SMESH_DeviceActor* my0DActor;
254   vtkProperty* my0DExtProp;
255   SMESH_DeviceActor* my0DExtActor;
256
257   unsigned int myEntityMode;
258   unsigned int myEntityState;
259   bool myIsPointsVisible;
260
261   bool myIsShrinkable;
262   bool myIsShrunk;
263   
264   bool myIsPointsLabeled;
265   vtkUnstructuredGrid* myPointsNumDataSet;
266   vtkActor2D *myPointLabels;
267   vtkMaskPoints* myPtsMaskPoints;
268   vtkLabeledDataMapper* myPtsLabeledDataMapper;
269   vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
270
271   bool myIsCellsLabeled;
272   vtkUnstructuredGrid* myCellsNumDataSet;
273   vtkActor2D *myCellsLabels;
274   vtkMaskPoints* myClsMaskPoints;
275   VTKViewer_CellCenters* myCellCenters;
276   vtkLabeledDataMapper* myClsLabeledDataMapper;
277   vtkSelectVisiblePoints* myClsSelectVisiblePoints;
278
279   vtkImplicitBoolean* myImplicitBoolean;
280   typedef TVTKSmartPtr<vtkPlane> TPlanePtr;
281   typedef std::vector<TPlanePtr> TCippingPlaneCont;
282   TCippingPlaneCont myCippingPlaneCont;
283   long myControlsPrecision;
284
285   bool myIsFacesOriented;
286
287   VTK::MarkerTexture myMarkerTexture;
288
289   SMESH_ActorDef();
290   ~SMESH_ActorDef();
291
292   bool Init(TVisualObjPtr theVisualObj, 
293             const char* theEntry, 
294             const char* theName,
295             int theIsClear);
296
297   void SetIsShrunkable(bool theShrunkable);
298   void UpdateHighlight();
299   void Update();
300
301  private:
302   // hide the two parameter Render() method from the user and the compiler.
303   virtual void Render(vtkRenderer *, vtkMapper *) {};
304   virtual void ShallowCopy(vtkProp *prop);
305   virtual void SetMapper(vtkMapper *);
306   static SMESH_ActorDef* New();
307
308   // Not implemented.
309   SMESH_ActorDef(const SMESH_ActorDef&);  
310   void operator=(const SMESH_ActorDef&);
311 };
312
313
314 #endif //SMESH_ACTORDEF_H