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