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