Salome HOME
Debug algorithms and hypotheses assignment
[modules/smesh.git] / src / OBJECT / SMESH_ActorDef.h
1 //  SMESH OBJECT : interactive object for SMESH visualization
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_ActorDef.h
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef SMESH_ACTORDEF_H
30 #define SMESH_ACTORDEF_H
31
32 #include "SMESH_Actor.h"
33 #include "SMESH_Object.h"
34
35 #include <vtkSmartPointer.h>
36
37 template <class T>
38 class TVTKSmartPtr: public vtkSmartPointer<T>
39 {
40 public:
41   TVTKSmartPtr() {}
42   TVTKSmartPtr(T* r, bool theIsOwner = false): vtkSmartPointer<T>(r) { 
43     if(r && theIsOwner) 
44       r->Delete();
45   }
46   TVTKSmartPtr& operator()(T* r, bool theIsOwner = false){ 
47     vtkSmartPointer<T>::operator=(r); 
48     if(r && theIsOwner) 
49       r->Delete();
50     return *this;
51   }
52   TVTKSmartPtr& operator=(T* r){ vtkSmartPointer<T>::operator=(r); return *this;}
53   T* Get() const { return this->GetPointer();}
54 };
55
56
57 class vtkProperty;
58 class vtkShrinkFilter;
59 class vtkPolyDataMapper;
60 class vtkUnstructuredGrid;
61 class vtkMergeFilter;
62 class vtkPolyData;
63
64 class vtkMapper;
65 class vtkActor2D;
66 class vtkMaskPoints;
67 class vtkCellCenters;
68 class vtkLabeledDataMapper;
69 class vtkSelectVisiblePoints;
70
71 class vtkScalarBarActor;
72 class vtkLookupTable;
73
74 class vtkPlane;
75 class vtkImplicitBoolean;
76
77 class vtkTimeStamp;
78
79 class SMESH_DeviceActor;
80
81
82 class SMESH_ActorDef : public SMESH_Actor{
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(float theValue);
104   virtual float GetOpacity();
105
106   virtual void SetSufaceColor(float r,float g,float b);
107   virtual void GetSufaceColor(float& r,float& g,float& b);
108
109   virtual void SetBackSufaceColor(float r,float g,float b);
110   virtual void GetBackSufaceColor(float& r,float& g,float& b);
111
112   virtual void SetEdgeColor(float r,float g,float b);
113   virtual void GetEdgeColor(float& r,float& g,float& b);
114
115   virtual void SetNodeColor(float r,float g,float b);
116   virtual void GetNodeColor(float& r,float& g,float& b);
117
118   virtual void SetHighlightColor(float r,float g,float b);
119   virtual void GetHighlightColor(float& r,float& g,float& b);
120
121   virtual void SetPreHighlightColor(float r,float g,float b);
122   virtual void GetPreHighlightColor(float& r,float& g,float& b);
123  
124   virtual float GetLineWidth();
125   virtual void SetLineWidth(float theVal);
126
127   virtual void SetNodeSize(float size) ;
128   virtual float GetNodeSize() ;
129
130   virtual int GetNodeObjId(int theVtkID);
131   virtual float* 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 float* GetBounds();
150   virtual void SetTransform(VTKViewer_Transform* theTransform); 
151
152   virtual vtkUnstructuredGrid* GetUnstructuredGrid();
153   virtual vtkDataSet* GetInput();
154   virtual vtkMapper* GetMapper();
155
156   virtual float GetShrinkFactor();
157   virtual void SetShrinkFactor(float 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 SetControlMode(eControl theMode);
171   virtual eControl GetControlMode(){ return myControlMode;}
172
173   virtual vtkScalarBarActor* GetScalarBarActor(){ return myScalarBarActor;}
174
175   virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane);
176   virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane);
177
178   virtual void RemoveAllClippingPlanes();
179   virtual vtkIdType GetNumberOfClippingPlanes();
180   virtual vtkPlane* GetClippingPlane(vtkIdType theID);
181   virtual vtkIdType AddClippingPlane(vtkPlane* thePlane); 
182
183   virtual TVisualObjPtr GetObject() { return myVisualObj;}
184
185   virtual void SetControlsPrecision( const long p ) { myControlsPrecision = p; }
186   virtual long GetControlsPrecision() const { return myControlsPrecision; }
187
188   virtual void UpdateScalarBar();
189   
190  protected:
191   void SetControlMode(eControl theMode, bool theCheckEntityMode);
192   void SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed);
193   bool IsImplicitFunctionUsed() const;
194
195   TVisualObjPtr myVisualObj;
196   vtkTimeStamp* myTimeStamp;
197
198   vtkScalarBarActor* myScalarBarActor;
199   vtkLookupTable* myLookupTable;
200
201   vtkProperty* mySurfaceProp;
202   vtkProperty* myBackSurfaceProp;
203   vtkProperty* myEdgeProp;
204   vtkProperty* myNodeProp;
205
206   SMESH_DeviceActor* myBaseActor;
207   SMESH_DeviceActor* myNodeActor;
208   SMESH_DeviceActor* myPickableActor;
209
210   vtkProperty* myHighlightProp;
211   vtkProperty* myPreselectProp;
212   SMESH_DeviceActor* myHighlitableActor;
213
214   eControl myControlMode;
215   SMESH_DeviceActor* my2DActor;
216   SMESH_DeviceActor* my3DActor;
217   SMESH_DeviceActor* myControlActor;
218
219   vtkProperty* my1DProp;
220   SMESH_DeviceActor* my1DActor;
221   vtkProperty* my1DExtProp;
222   SMESH_DeviceActor* my1DExtActor;
223
224   unsigned int myEntityMode;
225   unsigned int myEntityState;
226   bool myIsPointsVisible;
227
228   bool myIsShrinkable;
229   bool myIsShrunk;
230   
231   bool myIsPointsLabeled;
232   vtkUnstructuredGrid* myPointsNumDataSet;
233   vtkActor2D *myPointLabels;
234   vtkMaskPoints* myPtsMaskPoints;
235   vtkLabeledDataMapper* myPtsLabeledDataMapper;
236   vtkSelectVisiblePoints* myPtsSelectVisiblePoints;
237
238   bool myIsCellsLabeled;
239   vtkUnstructuredGrid* myCellsNumDataSet;
240   vtkActor2D *myCellsLabels;
241   vtkMaskPoints* myClsMaskPoints;
242   vtkCellCenters* myCellCenters;
243   vtkLabeledDataMapper* myClsLabeledDataMapper;
244   vtkSelectVisiblePoints* myClsSelectVisiblePoints;
245
246   vtkImplicitBoolean* myImplicitBoolean;
247   typedef TVTKSmartPtr<vtkPlane> TPlanePtr;
248   typedef std::vector<TPlanePtr> TCippingPlaneCont;
249   TCippingPlaneCont myCippingPlaneCont;
250   long myControlsPrecision;
251
252   SMESH_ActorDef();
253   ~SMESH_ActorDef();
254
255   bool Init(TVisualObjPtr theVisualObj, 
256             const char* theEntry, 
257             const char* theName,
258             int theIsClear);
259
260   void SetIsShrunkable(bool theShrunkable);
261   void UpdateHighlight();
262   void Update();
263
264  private:
265   // hide the two parameter Render() method from the user and the compiler.
266   virtual void Render(vtkRenderer *, vtkMapper *) {};
267   virtual void ShallowCopy(vtkProp *prop);
268   virtual void SetMapper(vtkMapper *);
269   static SMESH_ActorDef* New();
270
271   // Not implemented.
272   SMESH_ActorDef(const SMESH_ActorDef&);  
273   void operator=(const SMESH_ActorDef&);
274 };
275
276
277 #endif //SMESH_ACTORDEF_H