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