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