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