Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3dFactory.hh
1 // Copyright (C) 2007-2012  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_ColoredPrs3dFactory_HeaderFile
29 #define VISU_ColoredPrs3dFactory_HeaderFile
30
31 #include "SALOMEconfig.h"
32 #include CORBA_SERVER_HEADER(VISU_Gen)
33 #include CORBA_SERVER_HEADER(SALOMEDS)
34
35 #include "VISU_I.hxx"
36 #include "SALOME_GenericObjPointer.hh"
37 #include "VISU_DeformedShapeAndScalarMap_i.hh"
38 #include "VISU_Plot3D_i.hh"
39 #include "VISU_GaussPoints_i.hh"
40 #include "VISU_StreamLines_i.hh"
41 #include "VISU_Vectors_i.hh"
42 #include "VISU_CutLines_i.hh"
43 #include "VISU_CutSegment_i.hh"
44 #include "VISU_CutPlanes_i.hh"
45 #include "VISU_DeformedShape_i.hh"
46 #include "VISU_IsoSurfaces_i.hh"
47 #include "VISU_ScalarMap_i.hh"
48 #include "VISU_ColoredPrs3d_i.hh"
49 #include "VISU_Result_i.hh"
50 #include "VISU_TypeList.hxx"
51
52 namespace VISU
53 {
54   namespace TL
55   {
56     //----------------------------------------------------------------------------
57     typedef TList<DeformedShapeAndScalarMap_i,
58                   TList<DeformedShapeAndScalarMap_i,
59                   TList<DeformedShape_i,
60                         TList<StreamLines_i,
61                               TList<GaussPoints_i,
62                                     TList<ScalarMap_i,
63                                           TList<IsoSurfaces_i,
64                                                 TList<CutPlanes_i,
65                                                       TList<CutLines_i,
66                                                             TList<CutSegment_i,
67                                                                   TList<Vectors_i,
68                                                                         TList<Plot3D_i, 
69                                                                               TNullType> > > > > > > > > > > >
70     TColoredPrs3dTypeList;
71     
72
73     typedef TList<TInt2Type<TSCALARMAPONDEFORMEDSHAPE>,
74                   TList<TInt2Type<TDEFORMEDSHAPEANDSCALARMAP>,
75                   TList<TInt2Type<TDEFORMEDSHAPE>, 
76                         TList<TInt2Type<TSTREAMLINES>,
77                               TList<TInt2Type<TGAUSSPOINTS>,
78                                     TList<TInt2Type<TSCALARMAP>,
79                                           TList<TInt2Type<TISOSURFACES>,
80                                                 TList<TInt2Type<TCUTPLANES>,
81                                                       TList<TInt2Type<TCUTLINES>,
82                                                             TList<TInt2Type<TCUTSEGMENT>,
83                                                                   TList<TInt2Type<TVECTORS>,
84                                                                         TList<TInt2Type<TPLOT3D>, 
85                                                                               TNullType> > > > > > > > > > > >
86     TColoredPrs3dEnumList;
87     
88
89     //----------------------------------------------------------------------------
90     template <unsigned int type_enum>
91     struct TColoredEnum2Type
92     {
93       typedef typename TTypeAt<TColoredPrs3dTypeList, TIndexOf<TColoredPrs3dEnumList, TInt2Type<type_enum> >::value >::TResult TResult;
94     };
95     
96     //----------------------------------------------------------------------------
97     template <class T>
98     struct TColoredType2Enum
99     {
100       typedef typename TTypeAt<TColoredPrs3dEnumList, TIndexOf<TColoredPrs3dTypeList, T>::value >::TResult TResult;
101     };
102
103   }
104
105   //----------------------------------------------------------------------------
106   template<typename TPrs3d_i> 
107   ColoredPrs3d_i*
108   CreatePrs3dByType(SALOMEDS::Study_ptr theStudy,
109                     ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
110   {
111     if(!theStudy->GetProperties()->IsLocked()){
112       typedef typename TPrs3d_i::TInterface TPrs3d;
113       if(TPrs3d_i* aPresent = new TPrs3d_i(thePublishInStudyMode)){
114         return aPresent;
115       }
116     }
117     return NULL;
118   }
119
120
121   //----------------------------------------------------------------------------
122   template<unsigned int type_enum> 
123   ColoredPrs3d_i*
124   CreatePrs3dByEnum(SALOMEDS::Study_ptr theStudy,
125                     ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
126   {
127     typedef typename TL::TColoredEnum2Type<type_enum>::TResult TColoredPrs3d;
128     return CreatePrs3dByType<TColoredPrs3d>(theStudy,
129                                             thePublishInStudyMode);
130   };
131
132
133   //----------------------------------------------------------------------------
134   ColoredPrs3d_i*
135   CreatePrs3d_i(VISUType theType,
136                 SALOMEDS::Study_ptr theStudy,
137                 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode);
138   
139   
140   //----------------------------------------------------------------------------
141   bool VISU_I_EXPORT
142   CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
143                     Result_i* theResult,
144                     const std::string& theMeshName, 
145                     VISU::Entity theEntity,
146                     const std::string& theFieldName, 
147                     CORBA::Long theIteration);
148
149
150   //----------------------------------------------------------------------------
151   //Create 3D collored Presentation Of Different Types
152   template<typename TPrs3d_i> TPrs3d_i*
153   CreatePrs3d(Result_ptr theResult, 
154               const std::string& theMeshName, 
155               VISU::Entity theEntity,
156               const std::string& theFieldName, 
157               CORBA::Long theTimeStampNumber)
158   {
159     typedef typename TPrs3d_i::TInterface TPrs3d;
160     typename TPrs3d::_var_type aPrs3d;
161
162     if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
163       SALOMEDS::Study_var aStudy = aResult->GetStudyDocument();
164       if(aStudy->GetProperties()->IsLocked()) 
165         return NULL;
166     
167       if(TPrs3d_i::IsPossible(aResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, true)){
168         TPrs3d_i* aPresent = new TPrs3d_i(ColoredPrs3d_i::EPublishUnderTimeStamp);
169         
170         if(CreatColoredPrs3d(aPresent, aResult, theMeshName, theEntity, theFieldName, theTimeStampNumber))
171           return aPresent;
172         
173         aPresent->_remove_ref();
174       }
175     }
176     return NULL;
177   }
178
179
180   //----------------------------------------------------------------------------
181   template<typename TPrs3d_i> 
182   typename TPrs3d_i::TInterface::_var_type
183   Prs3dOnField(Result_ptr theResult, 
184                const std::string& theMeshName, 
185                VISU::Entity theEntity,
186                const std::string& theFieldName, 
187                CORBA::Long theTimeStampNumber)
188   {
189     if(TPrs3d_i* aPrs3d = CreatePrs3d<TPrs3d_i>(theResult,
190                                                 theMeshName,
191                                                 theEntity,
192                                                 theFieldName,
193                                                 theTimeStampNumber))
194       return aPrs3d->_this();
195     typedef typename TPrs3d_i::TInterface TPrs3d;
196     return TPrs3d::_nil();
197   }
198
199
200   //----------------------------------------------------------------------------
201   //! Gets the memory required for cache
202   VISU_I_EXPORT VISU::ColoredPrs3dCache::EnlargeType
203   GetRequiredCacheMemory(VISU::VISUType theType,
204                          VISU::Result_ptr theResult, 
205                          const std::string& theMeshName, 
206                          VISU::Entity theEntity,
207                          const std::string& theFieldName, 
208                          CORBA::Long theTimeStampNumber,
209                          CORBA::Float& theUsedMemory,
210                          CORBA::Float& theRequiredMemory);
211
212
213   //----------------------------------------------------------------------------
214   //! Gets the memory required for cache
215   template<class TColoredPrs3d_i> 
216   VISU::ColoredPrs3dCache::EnlargeType
217   GetRequiredCacheMemory(VISU::Result_ptr theResult, 
218                          const std::string& theMeshName, 
219                          VISU::Entity theEntity,
220                          const std::string& theFieldName, 
221                          CORBA::Long theTimeStampNumber,
222                          CORBA::Float& theUsedMemory,
223                          CORBA::Float& theRequiredMemory)
224   {
225     typedef typename TL::TColoredType2Enum<TColoredPrs3d_i>::TResult TEnum;
226     VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value);
227     return GetRequiredCacheMemory(aColoredPrs3dType,
228                                   theResult, 
229                                   theMeshName, 
230                                   theEntity,
231                                   theFieldName, 
232                                   theTimeStampNumber,
233                                   theUsedMemory,
234                                   theRequiredMemory);
235   }
236
237
238   //----------------------------------------------------------------------------
239   //! Creates ColoredPrs3dHolder by enumeration value and gets its first device
240   VISU_I_EXPORT ColoredPrs3d_i*
241   CreateHolder2GetDeviceByEnum(VISU::VISUType theType,
242                                VISU::Result_ptr theResult, 
243                                const std::string& theMeshName, 
244                                VISU::Entity theEntity,
245                                const std::string& theFieldName, 
246                                CORBA::Long theTimeStampNumber,
247                                VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
248                                CORBA::Float theRequiredMemory);
249     
250   
251   //----------------------------------------------------------------------------
252   //! Creates ColoredPrs3dHolder by type and gets its first device
253   template<class TColoredPrs3d_i> 
254   TColoredPrs3d_i*
255   CreateHolder2GetDeviceByType(VISU::Result_ptr theResult, 
256                                const std::string& theMeshName, 
257                                VISU::Entity theEntity,
258                                const std::string& theFieldName, 
259                                CORBA::Long theTimeStampNumber,
260                                VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
261                                CORBA::Float theRequiredMemory)
262   {
263     typedef typename TL::TColoredType2Enum<TColoredPrs3d_i>::TResult TEnum;
264     VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value);
265     ColoredPrs3d_i* aColoredPrs3d = CreateHolder2GetDeviceByEnum(aColoredPrs3dType,
266                                                                  theResult, 
267                                                                  theMeshName, 
268                                                                  theEntity,
269                                                                  theFieldName, 
270                                                                  theTimeStampNumber,
271                                                                  theEnlargeType,
272                                                                  theRequiredMemory);
273     return dynamic_cast<TColoredPrs3d_i*>(aColoredPrs3d);
274   }
275
276
277   //----------------------------------------------------------------------------
278   template<unsigned int colored_prs3d_type_enum>
279   struct TSameAsFactory
280   {
281     typedef typename TL::TColoredEnum2Type<colored_prs3d_type_enum>::TResult TColoredPrs3d;
282
283     void
284     Copy(ColoredPrs3d_i* theColoredPrs3dFrom, ColoredPrs3d_i* theColoredPrs3dTo)
285     {
286       theColoredPrs3dTo->SetCResult(theColoredPrs3dFrom->GetCResult());
287       theColoredPrs3dTo->SetMeshName(theColoredPrs3dFrom->GetCMeshName().c_str());
288       theColoredPrs3dTo->SetEntity(theColoredPrs3dFrom->GetEntity());
289       theColoredPrs3dTo->SetFieldName(theColoredPrs3dFrom->GetCFieldName().c_str());
290       theColoredPrs3dTo->SetTimeStampNumber(theColoredPrs3dFrom->GetTimeStampNumber());
291       theColoredPrs3dTo->SameAs(theColoredPrs3dFrom);
292     }
293
294     SALOME::GenericObjPtr<TColoredPrs3d>
295     Create(ColoredPrs3d_i* theColoredPrs3d,
296            ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode,
297            bool theCreateAsTemporalObject = true)
298     {
299       SALOME::GenericObjPtr<TColoredPrs3d> aSameColoredPrs3d(new TColoredPrs3d(thePublishInStudyMode));
300       Copy(theColoredPrs3d, aSameColoredPrs3d);
301       if ( theCreateAsTemporalObject )
302         aSameColoredPrs3d->UnRegister();
303       return aSameColoredPrs3d;
304     }
305   };
306
307   //----------------------------------------------------------------------------
308   //! Check is possible to create ColoredPrs3dHolder with the given input
309   VISU_I_EXPORT size_t
310   CheckIsPossible(VISU::VISUType theType,
311                   const VISU::ColoredPrs3dHolder::BasicInput& theInput,
312                   bool theMemoryCheck);
313     
314   //----------------------------------------------------------------------------
315   //! Check is possible to create ColoredPrs3dHolder with the given input
316   template<unsigned int colored_prs3d_type_enum> 
317   size_t
318   CheckIsPossible(const VISU::ColoredPrs3dHolder::BasicInput& theInput,
319                   bool theMemoryCheck)
320   {
321     VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>( VISU::GetServant(theInput.myResult).in() );
322     std::string aMeshName = theInput.myMeshName.in();
323     VISU::Entity anEntity = theInput.myEntity;
324     std::string aFieldName = theInput.myFieldName.in();
325     CORBA::Long aTimeStampNumber = theInput.myTimeStampNumber;
326
327     typedef typename VISU::TL::TColoredEnum2Type<colored_prs3d_type_enum>::TResult TColoredPrs3d;
328     return TColoredPrs3d::IsPossible(aResult,
329                                      aMeshName,
330                                      anEntity,
331                                      aFieldName,
332                                      aTimeStampNumber,
333                                      theMemoryCheck);
334   }
335
336   //----------------------------------------------------------------------------
337 }
338
339 #endif