Salome HOME
Initial version
[modules/gui.git] / src / OBJECT / SALOME_Actor.h
1 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
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   : SALOME_Actor.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef SALOME_ACTOR_H
30 #define SALOME_ACTOR_H
31
32 #include "SALOME_InteractiveObject.hxx" // INCLUDES "using namespace std"
33 #ifndef _Handle_SALOME_InteractiveObject_HeaderFile
34 #include "Handle_SALOME_InteractiveObject.hxx"
35 #endif
36
37 #include <vtkLODActor.h> // INCLUDES "stdio.h"
38 #include <vtkProperty.h> 
39
40 // to overcome the conflict between std::ostream and io::ostream 
41 // the following variable must be defined:
42 // VTK_USE_ANSI_STDLIB
43
44 #include <vector>
45
46 class vtkCell;
47 class vtkDataSet;
48 class vtkPolyData;
49 class vtkCamera;
50 class vtkProperty;
51
52 class VTKViewer_Transform;
53 class VTKViewer_GeometryFilter;
54 class VTKViewer_TransformFilter;
55 class VTKViewer_PassThroughFilter;
56
57 extern int SALOME_POINT_SIZE;
58
59 #ifdef WNT
60 #define SALOME_OBJECT_EXPORT __declspec (dllexport)
61 #else
62 #define SALOME_OBJECT_EXPORT
63 #endif
64
65 #include <VTKViewer_Actor.h>
66
67 class SALOME_OBJECT_EXPORT SALOME_Actor : public VTKViewer_Actor {
68  public:
69   static SALOME_Actor* New();
70
71   vtkTypeMacro(SALOME_Actor,vtkLODActor);
72
73   virtual Standard_Boolean hasIO() { return !myIO.IsNull(); }
74   virtual const Handle(SALOME_InteractiveObject)& getIO() { return myIO; } 
75   virtual void setIO(const Handle(SALOME_InteractiveObject)& io) { myIO = io; }
76
77   virtual const char* getName() { return myName.c_str(); }
78   virtual void setName(const char* theName){
79     if(hasIO()) myIO->setName(theName);
80     myName = theName;
81   }
82
83   // To generate highlight automaticaly
84   virtual bool hasHighlight() { return false; } 
85   virtual void highlight(bool theHighlight) { myIsHighlighted = theHighlight; }  
86   virtual bool isHighlighted() { return myIsHighlighted; }
87
88   virtual void SetOpacity(float theOpacity);
89   virtual float GetOpacity();
90
91   virtual void SetColor(float r,float g,float b);
92   virtual void GetColor(float& r,float& g,float& b);
93   void SetColor(const float theRGB[3]){ 
94     SetColor(theRGB[0],theRGB[1],theRGB[2]);
95   }
96
97   vtkSetObjectMacro(PreviewProperty,vtkProperty);
98
99   virtual void SetPreSelected(bool thePreselect = false) { myIsPreselected = thePreselect;}
100
101
102   // Used to obtain all dependent actors
103   virtual void GetChildActors(vtkActorCollection*) {};
104   
105   virtual void AddToRender(vtkRenderer* theRenderer); 
106   virtual void RemoveFromRender(vtkRenderer* theRenderer);
107
108
109   // For selection mapping purpose
110   virtual int GetNodeObjId(int theVtkID) { return theVtkID;}
111   virtual float* GetNodeCoord(int theObjID);
112
113   virtual int GetElemObjId(int theVtkID) { return theVtkID;}
114   virtual vtkCell* GetElemCell(int theObjID);
115
116   virtual int GetObjDimension( const int theObjId );
117
118   virtual void SetMapper(vtkMapper* theMapper); 
119   virtual vtkDataSet* GetInput(); 
120
121
122   virtual void SetTransform(VTKViewer_Transform* theTransform); 
123   virtual unsigned long int GetMTime();
124
125   virtual void SetRepresentation(int theMode);
126   virtual int GetRepresentation();
127
128   virtual int getDisplayMode();
129   virtual void setDisplayMode(int theMode);
130
131   // Infinitive means actor without size (point for example),
132   // which is not taken into account in calculation of boundaries of the scene
133   void SetInfinitive(bool theIsInfinite) { myIsInfinite = theIsInfinite; }
134   virtual bool IsInfinitive();
135     
136   void SetResolveCoincidentTopology(bool theIsResolve);
137   void SetPolygonOffsetParameters(float factor, float units);
138   void GetPolygonOffsetParameters(float& factor, float& units);
139
140   virtual void Render(vtkRenderer *, vtkMapper *);
141
142   virtual float GetShrinkFactor() { return 1.0;}
143
144   virtual bool IsShrunkable() { return false;}
145   virtual bool IsShrunk() { return false;}
146
147   virtual void SetShrink() {} 
148   virtual void UnShrink() {}
149
150   virtual bool IsSetCamera() const { return false; }
151   virtual bool IsResizable() const { return false; }
152   virtual void SetSize( const float ) {}
153   virtual void SetCamera( vtkCamera* ) {}
154
155  protected:
156   bool myIsResolveCoincidentTopology;
157   float myPolygonOffsetFactor;
158   float myPolygonOffsetUnits;
159
160   Handle(SALOME_InteractiveObject) myIO;
161   std::string myName;
162
163   vtkProperty *PreviewProperty;
164   bool myIsPreselected;
165
166   float myOpacity;
167   bool myIsHighlighted;
168   int myDisplayMode;
169   bool myIsInfinite;
170
171   bool myStoreMapping;
172   VTKViewer_GeometryFilter *myGeomFilter;
173   VTKViewer_TransformFilter *myTransformFilter;
174   std::vector<VTKViewer_PassThroughFilter*> myPassFilter;
175
176   int myRepresentation;
177   vtkProperty *myProperty;
178
179   void InitPipeLine(vtkMapper* theMapper); 
180
181   SALOME_Actor();
182   ~SALOME_Actor();
183 };
184
185
186 #endif // SALOME_ACTOR_H
187