Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3dCache_i.hh
1 //  Copyright (C) 2007-2010  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 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : VISU_ColoredPrs3dCache_i.hh
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27 //
28 #ifndef VISU_ColoredPrs3dCache_i_HeaderFile
29 #define VISU_ColoredPrs3dCache_i_HeaderFile
30
31 #include "VISU_I.hxx"
32
33 #include "VISU_ColoredPrs3dFactory.hh"
34
35 #include "SALOME_GenericObjPointer.hh"
36
37 namespace VISU
38 {
39   class Result_i;
40   class ColoredPrs3d_i;
41   class ColoredPrs3dHolder_i;
42
43   struct TPrs3dPtr: SALOME::GenericObjPtr<ColoredPrs3d_i>
44   {
45     typedef SALOME::GenericObjPtr<ColoredPrs3d_i> TSuperClass;
46  
47     //! Initialize smart pointer to NULL.
48     TPrs3dPtr():
49       TSuperClass()
50     {}
51
52     //! Initialize smart pointer to given object (TSGenericObj must be complete).
53     TPrs3dPtr(ColoredPrs3d_i* thePointer):
54       TSuperClass(thePointer)
55     {}
56
57     /*! 
58       Initialize smart pointer with a new reference to the same object
59       referenced by given smart pointer.
60      */
61     TPrs3dPtr(const TPrs3dPtr& thePointer):
62       TSuperClass(thePointer)
63     {}
64
65
66     /*! 
67       Assign object to reference.  This removes any reference to an old
68       object.
69     */
70     TPrs3dPtr& 
71     operator=(const TPrs3dPtr& thePointer)
72     {
73       TSuperClass::operator=(thePointer);
74       return *this;
75     }
76
77     /*! 
78       Assign object to reference.  This removes any reference to an old
79       object.
80     */
81     TPrs3dPtr& 
82     operator=(ColoredPrs3d_i* thePointer)
83     {
84       TSuperClass::operator=(thePointer);
85       return *this;
86     }
87
88     //! Get the contained pointer.
89     ColoredPrs3d_i* 
90     get() const
91     {
92       ColoredPrs3d_i* aColoredPrs3d = TSuperClass::get();
93       // To implement postponed restoring of the presentation
94       if(aColoredPrs3d)
95         aColoredPrs3d->InitFromRestoringState();
96       return aColoredPrs3d;
97     }
98   };
99
100   typedef std::deque<TPrs3dPtr> TLastVisitedPrsList;
101
102   typedef std::string THolderEntry;
103   typedef std::map<THolderEntry,TLastVisitedPrsList> TColoredPrs3dHolderMap;
104
105   /*!
106    * This interface is responsible for memory management of 3d presentations.
107    * One cache corresponds to one study.
108    */
109   class VISU_I_EXPORT ColoredPrs3dCache_i : public virtual POA_VISU::ColoredPrs3dCache,
110                               public virtual SALOME::GenericObj_i,
111                               public virtual RemovableObject_i
112   {
113     ColoredPrs3dCache_i();
114     ColoredPrs3dCache_i(const ColoredPrs3dCache_i&);
115   public:
116     //----------------------------------------------------------------------------
117     //! A constructor to create an instance of the class
118     explicit
119     ColoredPrs3dCache_i(SALOMEDS::Study_ptr theStudy,
120                         bool thePublishInStudy = true);
121
122     virtual
123     ~ColoredPrs3dCache_i();
124
125     //----------------------------------------------------------------------------
126     /*! Creates ColoredPrs3dHolder */
127     virtual
128     VISU::ColoredPrs3dHolder_ptr
129     CreateHolder(VISU::VISUType theType,
130                  const VISU::ColoredPrs3dHolder::BasicInput& theInput);
131
132     //----------------------------------------------------------------------------
133     /*! Gets a memory which is required to create a holder. */
134     virtual
135     VISU::ColoredPrs3dCache::EnlargeType
136     GetRequiredMemory(VISU::VISUType theType,
137                       const VISU::ColoredPrs3dHolder::BasicInput& theInput,
138                       CORBA::Float& theRequiredMemory);
139
140     //----------------------------------------------------------------------------
141     //! Sets a memory mode.
142     virtual
143     void
144     SetMemoryMode(VISU::ColoredPrs3dCache::MemoryMode theMode);
145
146     virtual
147     VISU::ColoredPrs3dCache::MemoryMode
148     GetMemoryMode();
149
150     //----------------------------------------------------------------------------
151     //! Sets a memory size for limited mode.
152     virtual
153     void
154     SetLimitedMemory(CORBA::Float theMemorySize);
155
156     virtual
157     CORBA::Float
158     GetLimitedMemory();
159
160     virtual
161     CORBA::Float
162     GetMemorySize();
163
164     virtual
165     CORBA::Float
166     GetDeviceMemorySize();
167
168     //----------------------------------------------------------------------------
169     virtual 
170     VISU::VISUType 
171     GetType() 
172     {
173       return VISU::TCOLOREDPRS3DCACHE; 
174     }
175
176     virtual
177     void
178     RemoveFromStudy();
179
180     static
181     std::string
182     GetFolderName();
183
184     virtual
185     const char* 
186     GetComment() const;
187
188     virtual
189     void
190     ToStream(std::ostringstream&);
191
192     virtual
193     Storable*
194     Restore(SALOMEDS::SObject_ptr theSObject,
195             const Storable::TRestoringMap& theMap);
196
197     static
198     Storable*
199     StorableEngine(SALOMEDS::SObject_ptr theSObject,
200                    const Storable::TRestoringMap& theMap,
201                    const std::string& thePrefix,
202                    CORBA::Boolean theIsMultiFile);
203
204     //----------------------------------------------------------------------------
205     //! Finds or creates instance of the ColoredPrs3dCache in the given SALOMEDS::Study
206     static
207     VISU::ColoredPrs3dCache_i*
208     GetInstance_i(SALOMEDS::Study_ptr theStudy);
209
210     static
211     VISU::ColoredPrs3dCache_ptr
212     GetInstance(SALOMEDS::Study_ptr theStudy);
213
214     //! Creates corresponding ColoredPrs3d instance and apply the BasicInput
215     VISU::ColoredPrs3d_i*
216     CreateColoredPrs3d(VISU::VISUType theType,
217                        VISU::ColoredPrs3dHolder::BasicInput theInput);
218
219     //! Registers the given ColoredPrs3d instance for the ColoredPrs3dHolder
220     VISU::ColoredPrs3d_i*
221     RegisterInHolder(VISU::ColoredPrs3d_i* thePrs3d,
222                      const std::string& theHolderEntry);
223
224     //! Creates and registers corresponding ColoredPrs3d instance for the ColoredPrs3dHolder
225     VISU::ColoredPrs3d_i*
226     CreatePrs(VISU::VISUType theType,
227               VISU::ColoredPrs3dHolder::BasicInput theInput,
228               VISU::ColoredPrs3dHolder_i* theHolder);
229
230     TLastVisitedPrsList&
231     GetLastVisitedPrsList(VISU::ColoredPrs3dHolder_i* theHolder);
232
233     TPrs3dPtr
234     GetLastVisitedPrs(VISU::ColoredPrs3dHolder_i* theHolder);
235
236     bool
237     UpdateLastVisitedPrs(VISU::ColoredPrs3dHolder_i* theHolder,
238                          VISU::ColoredPrs3d_i* thePrs,
239                          const VISU::ColoredPrs3dHolder::BasicInput& theInput,
240                          VISU::View3D_ptr theView3D);
241
242     //! Unregister the holder instance from cache
243     void
244     RemoveHolder(VISU::ColoredPrs3dHolder_i* theHolder);
245
246   public:
247     static const std::string myComment;
248
249   protected:
250     //----------------------------------------------------------------------------
251     virtual int
252     IsPossible(VISU::VISUType theType,
253                const VISU::ColoredPrs3dHolder::BasicInput& theInput,
254                float& theMemoryToClear,
255                const std::string theHolderEntry);
256
257     TPrs3dPtr
258     FindPrsByInput(TLastVisitedPrsList& theLastVisitedPrsList,
259                    const VISU::ColoredPrs3dHolder::BasicInput& theInput);
260
261     //----------------------------------------------------------------------------
262     void
263     ClearCache(float theMemory = 0);
264
265     bool
266     ClearMemory(CORBA::Float theRequiredMemory, 
267                 const std::string& theHolderEntry);
268
269     void
270     PrintCache();
271
272   private:
273     CORBA::Float myLimitedMemory;
274     VISU::ColoredPrs3dCache::MemoryMode myMemoryMode;
275
276     TColoredPrs3dHolderMap myHolderMap; 
277   };
278
279
280   //----------------------------------------------------------------------------
281 }
282
283 #endif