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