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