Salome HOME
Merge from OCC_development_generic_2006
[modules/visu.git] / src / VISU_I / VISU_Prs3d_i.hh
1 //  VISU OBJECT : interactive object for VISU entities implementation
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 //  File   : VISU_PrsObject_i.hxx
24 //  Author : Alexey PETROV
25 //  Module : VISU
26
27 #ifndef VISU_Prs3d_i_HeaderFile
28 #define VISU_Prs3d_i_HeaderFile
29
30 #include "VISU_PrsObject_i.hh"
31
32 #include "VISU_ActorFactory.h"
33 #include "VISU_ConvertorDef.hxx"
34
35 #include "SALOME_GenericObj_i.hh"
36 #include "SALOME_InteractiveObject.hxx"
37
38 #include <boost/signals/signal0.hpp>
39 #include <vtkSmartPointer.h>
40
41 class VISU_PipeLine;
42 class VISU_Actor;
43
44 class vtkPlane;
45 class vtkActorCollection;
46 class vtkUnstructuredGrid;
47
48 namespace VISU
49 {
50   class Result_i;
51
52   //----------------------------------------------------------------------------
53   //! Base class for all VTK 3D presentations.
54   /*!
55     It is a root class for a middle level of VISU functionality.
56     Almost all functionality of the the class implemented through redirection 
57     external requestes to its VISU_PipeLine.
58     It define an interface and implement the following topics:
59     - provide persistent mechanism;
60     - implement basic actor management (CreateActor, UpdateActor, UpdateActors, RemoveActor and RemoveActors);
61     - implement common 3D functionality like "clipping planes" and offset.
62   */
63   class Prs3d_i :
64     public virtual POA_VISU::Prs3d,
65     public virtual SALOME::GenericObj_i,
66     public virtual TActorFactory,
67     public virtual PrsObject_i
68
69   {
70     Prs3d_i();
71     Prs3d_i(const Prs3d_i&);
72
73   public:
74     //----------------------------------------------------------------------------
75     //! A constructor to create a fresh instance of the class
76     explicit
77     Prs3d_i(Result_i* theResult,
78             bool theAddToStudy);
79
80     //! A constructor to restore an instance of the class
81     explicit
82     Prs3d_i(Result_i* theResult,
83             SALOMEDS::SObject_ptr theSObject);
84
85     //! To create a deep copy from another instance of the class
86     virtual
87     void
88     SameAs(const Prs3d_i* theOrigin);
89
90     virtual
91     ~Prs3d_i();
92
93     //----------------------------------------------------------------------------
94     //! To generate an unique type name for the class (used into persistent functionality)
95     virtual
96     const char* 
97     GetComment() const = 0;
98
99     //! To generate an unique name for the instance of the class
100     virtual
101     QString
102     GenerateName() = 0;
103
104     //! To restore paramters of the instance from Storable::TRestoringMap
105     virtual
106     Storable* 
107     Restore(const Storable::TRestoringMap& theMap);
108
109     //! To save paramters of the instance to std::ostringstream
110     virtual
111     void
112     ToStream(std::ostringstream& theStr);
113
114     //----------------------------------------------------------------------------
115     //! Get corresponding Result_i
116     Result_i* 
117     GetResult() const;
118
119     //! Get corresponding SALOMEDS::SObject
120     virtual
121     SALOMEDS::SObject_var 
122     GetSObject();
123
124     const std::string& 
125     GetMeshName() const;
126
127     //----------------------------------------------------------------------------
128     //! To update is internal state
129     virtual 
130     void
131     Update();
132
133     //! To remove the instance from study
134     virtual
135     void
136     RemoveFromStudy();
137
138     //----------------------------------------------------------------------------
139     //! Get corresponding VISU_PipeLine
140     VISU_PipeLine* 
141     GetPL();
142
143     //! Get input of the VISU_PipeLine
144     vtkUnstructuredGrid* 
145     GetInput();
146
147     //----------------------------------------------------------------------------
148     //! To define a way to create VTK representation of the instance
149     virtual 
150     VISU_Actor* 
151     CreateActor(const Handle(SALOME_InteractiveObject)& theIO = NULL) = 0;
152
153     //! To unregister the pointed actor
154     virtual 
155     void
156     RemoveActor(VISU_Actor* theActor);
157
158     //! To unregister all actors of the instance
159     virtual 
160     void
161     RemoveActors();
162
163     //! To update the pointed actor
164     virtual 
165     void
166     UpdateActor(VISU_Actor* theActor);
167
168     //! To update all actors of the instance
169     virtual 
170     void
171     UpdateActors();
172
173     //----------------------------------------------------------------------------
174     // Clipping planes
175     void
176     RemoveAllClippingPlanes();
177
178     bool
179     AddClippingPlane(vtkPlane* thePlane);
180
181     vtkIdType
182     GetNumberOfClippingPlanes() const;
183
184     vtkPlane* 
185     GetClippingPlane(vtkIdType theID) const;
186
187     void
188     SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane);
189
190     //----------------------------------------------------------------------------
191     void
192     GetBounds(float aBounds[6]);
193
194     void
195     SetOffset(const float* theOffsets);
196
197     virtual
198     void
199     SetOffset(float theDx, float theDy, float theDz);
200
201     void
202     GetOffset(float* theOffsets);
203
204     virtual
205     void
206     GetOffset(float& theDx, float& theDy, float& theDz);
207
208     //----------------------------------------------------------------------------
209   protected:
210     void
211     CreateActor(VISU_Actor* theActor, 
212                 const Handle(SALOME_InteractiveObject)& theIO = NULL);
213
214     virtual 
215     VISU_PipeLine* 
216     GetPipeLine();
217
218     //! To check dataset validity, throws std::exception if not valid
219     virtual
220     void
221     CheckDataSet();
222
223     bool myAddToStudy;
224     float myOffset[3];
225     Result_i *myResult;
226     VISU_PipeLine *myPipeLine;
227     SALOMEDS::SObject_var mySObject;
228     std::string myMeshName;
229
230     boost::signal0<void> myUpdateActorsSignal;
231     boost::signal0<void> myRemoveActorsFromRendererSignal;
232     vtkSmartPointer<vtkActorCollection> myActorCollection;
233
234   };
235
236   //----------------------------------------------------------------------------
237   Result_i* 
238   GetResult(SALOMEDS::SObject_ptr theSObject);
239
240   //----------------------------------------------------------------------------
241   template<class TPrs3d>
242   Storable* 
243   Restore(SALOMEDS::SObject_ptr theSObject,
244           const std::string& thePrefix,
245           const Storable::TRestoringMap& theMap)
246   {
247     VISU::Result_i* pResult = GetResult(theSObject);
248     if(pResult != NULL){
249       TPrs3d* pPrs3d = new TPrs3d(pResult,theSObject);
250       return pPrs3d->Restore(theMap);
251     }
252     return NULL;
253   }
254   //----------------------------------------------------------------------------
255 }
256
257 #endif