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