Version: 6.3.1

src/VISU_I/VISU_ColoredPrs3dFactory.hh

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  VISU OBJECT : interactive object for VISU entities implementation
00024 //  File   : VISU_ColoredPrs3dCache_i.hh
00025 //  Author : Oleg UVAROV
00026 //  Module : VISU
00027 //
00028 #ifndef VISU_ColoredPrs3dFactory_HeaderFile
00029 #define VISU_ColoredPrs3dFactory_HeaderFile
00030 
00031 #include "SALOMEconfig.h"
00032 #include CORBA_SERVER_HEADER(VISU_Gen)
00033 #include CORBA_SERVER_HEADER(SALOMEDS)
00034 
00035 #include "VISU_I.hxx"
00036 #include "SALOME_GenericObjPointer.hh"
00037 #include "VISU_DeformedShapeAndScalarMap_i.hh"
00038 #include "VISU_Plot3D_i.hh"
00039 #include "VISU_GaussPoints_i.hh"
00040 #include "VISU_StreamLines_i.hh"
00041 #include "VISU_Vectors_i.hh"
00042 #include "VISU_CutLines_i.hh"
00043 #include "VISU_CutSegment_i.hh"
00044 #include "VISU_CutPlanes_i.hh"
00045 #include "VISU_DeformedShape_i.hh"
00046 #include "VISU_IsoSurfaces_i.hh"
00047 #include "VISU_ScalarMap_i.hh"
00048 #include "VISU_ColoredPrs3d_i.hh"
00049 #include "VISU_Result_i.hh"
00050 #include "VISU_TypeList.hxx"
00051 
00052 namespace VISU
00053 {
00054   namespace TL
00055   {
00056     //----------------------------------------------------------------------------
00057     typedef TList<DeformedShapeAndScalarMap_i,
00058             TList<DeformedShapeAndScalarMap_i,
00059             TList<DeformedShape_i,
00060                TList<StreamLines_i,
00061                      TList<GaussPoints_i,
00062                         TList<ScalarMap_i,
00063                            TList<IsoSurfaces_i,
00064                               TList<CutPlanes_i,
00065                                     TList<CutLines_i,
00066                                        TList<CutSegment_i,
00067                                           TList<Vectors_i,
00068                                              TList<Plot3D_i, 
00069                                                    TNullType> > > > > > > > > > > >
00070     TColoredPrs3dTypeList;
00071     
00072 
00073     typedef TList<TInt2Type<TSCALARMAPONDEFORMEDSHAPE>,
00074             TList<TInt2Type<TDEFORMEDSHAPEANDSCALARMAP>,
00075             TList<TInt2Type<TDEFORMEDSHAPE>, 
00076                TList<TInt2Type<TSTREAMLINES>,
00077                      TList<TInt2Type<TGAUSSPOINTS>,
00078                         TList<TInt2Type<TSCALARMAP>,
00079                            TList<TInt2Type<TISOSURFACES>,
00080                               TList<TInt2Type<TCUTPLANES>,
00081                                     TList<TInt2Type<TCUTLINES>,
00082                                        TList<TInt2Type<TCUTSEGMENT>,
00083                                           TList<TInt2Type<TVECTORS>,
00084                                              TList<TInt2Type<TPLOT3D>, 
00085                                                    TNullType> > > > > > > > > > > >
00086     TColoredPrs3dEnumList;
00087     
00088 
00089     //----------------------------------------------------------------------------
00090     template <unsigned int type_enum>
00091     struct TColoredEnum2Type
00092     {
00093       typedef typename TTypeAt<TColoredPrs3dTypeList, TIndexOf<TColoredPrs3dEnumList, TInt2Type<type_enum> >::value >::TResult TResult;
00094     };
00095     
00096     //----------------------------------------------------------------------------
00097     template <class T>
00098     struct TColoredType2Enum
00099     {
00100       typedef typename TTypeAt<TColoredPrs3dEnumList, TIndexOf<TColoredPrs3dTypeList, T>::value >::TResult TResult;
00101     };
00102 
00103   }
00104 
00105   //----------------------------------------------------------------------------
00106   template<typename TPrs3d_i> 
00107   ColoredPrs3d_i*
00108   CreatePrs3dByType(SALOMEDS::Study_ptr theStudy,
00109               ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
00110   {
00111     if(!theStudy->GetProperties()->IsLocked()){
00112       typedef typename TPrs3d_i::TInterface TPrs3d;
00113       if(TPrs3d_i* aPresent = new TPrs3d_i(thePublishInStudyMode)){
00114      return aPresent;
00115       }
00116     }
00117     return NULL;
00118   }
00119 
00120 
00121   //----------------------------------------------------------------------------
00122   template<unsigned int type_enum> 
00123   ColoredPrs3d_i*
00124   CreatePrs3dByEnum(SALOMEDS::Study_ptr theStudy,
00125               ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
00126   {
00127     typedef typename TL::TColoredEnum2Type<type_enum>::TResult TColoredPrs3d;
00128     return CreatePrs3dByType<TColoredPrs3d>(theStudy,
00129                              thePublishInStudyMode);
00130   };
00131 
00132 
00133   //----------------------------------------------------------------------------
00134   ColoredPrs3d_i*
00135   CreatePrs3d_i(VISUType theType,
00136           SALOMEDS::Study_ptr theStudy,
00137           ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode);
00138   
00139   
00140   //----------------------------------------------------------------------------
00141   bool VISU_I_EXPORT
00142   CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
00143               Result_i* theResult,
00144               const std::string& theMeshName, 
00145               VISU::Entity theEntity,
00146               const std::string& theFieldName, 
00147               CORBA::Long theIteration);
00148 
00149 
00150   //----------------------------------------------------------------------------
00151   //Create 3D collored Presentation Of Different Types
00152   template<typename TPrs3d_i> TPrs3d_i*
00153   CreatePrs3d(Result_ptr theResult, 
00154            const std::string& theMeshName, 
00155            VISU::Entity theEntity,
00156            const std::string& theFieldName, 
00157            CORBA::Long theTimeStampNumber)
00158   {
00159     typedef typename TPrs3d_i::TInterface TPrs3d;
00160     typename TPrs3d::_var_type aPrs3d;
00161 
00162     if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
00163       SALOMEDS::Study_var aStudy = aResult->GetStudyDocument();
00164       if(aStudy->GetProperties()->IsLocked()) 
00165      return NULL;
00166     
00167       if(TPrs3d_i::IsPossible(aResult, theMeshName, theEntity, theFieldName, theTimeStampNumber, true)){
00168      TPrs3d_i* aPresent = new TPrs3d_i(ColoredPrs3d_i::EPublishUnderTimeStamp);
00169      
00170      if(CreatColoredPrs3d(aPresent, aResult, theMeshName, theEntity, theFieldName, theTimeStampNumber))
00171        return aPresent;
00172      
00173      aPresent->_remove_ref();
00174       }
00175     }
00176     return NULL;
00177   }
00178 
00179 
00180   //----------------------------------------------------------------------------
00181   template<typename TPrs3d_i> 
00182   typename TPrs3d_i::TInterface::_var_type
00183   Prs3dOnField(Result_ptr theResult, 
00184             const std::string& theMeshName, 
00185             VISU::Entity theEntity,
00186             const std::string& theFieldName, 
00187             CORBA::Long theTimeStampNumber)
00188   {
00189     if(TPrs3d_i* aPrs3d = CreatePrs3d<TPrs3d_i>(theResult,
00190                               theMeshName,
00191                               theEntity,
00192                               theFieldName,
00193                               theTimeStampNumber))
00194       return aPrs3d->_this();
00195     typedef typename TPrs3d_i::TInterface TPrs3d;
00196     return TPrs3d::_nil();
00197   }
00198 
00199 
00200   //----------------------------------------------------------------------------
00202   VISU_I_EXPORT VISU::ColoredPrs3dCache::EnlargeType
00203   GetRequiredCacheMemory(VISU::VISUType theType,
00204                 VISU::Result_ptr theResult, 
00205                 const std::string& theMeshName, 
00206                 VISU::Entity theEntity,
00207                 const std::string& theFieldName, 
00208                 CORBA::Long theTimeStampNumber,
00209                 CORBA::Float& theUsedMemory,
00210                 CORBA::Float& theRequiredMemory);
00211 
00212 
00213   //----------------------------------------------------------------------------
00215   template<class TColoredPrs3d_i> 
00216   VISU::ColoredPrs3dCache::EnlargeType
00217   GetRequiredCacheMemory(VISU::Result_ptr theResult, 
00218                 const std::string& theMeshName, 
00219                 VISU::Entity theEntity,
00220                 const std::string& theFieldName, 
00221                 CORBA::Long theTimeStampNumber,
00222                 CORBA::Float& theUsedMemory,
00223                 CORBA::Float& theRequiredMemory)
00224   {
00225     typedef typename TL::TColoredType2Enum<TColoredPrs3d_i>::TResult TEnum;
00226     VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value);
00227     return GetRequiredCacheMemory(aColoredPrs3dType,
00228                       theResult, 
00229                       theMeshName, 
00230                       theEntity,
00231                       theFieldName, 
00232                       theTimeStampNumber,
00233                       theUsedMemory,
00234                       theRequiredMemory);
00235   }
00236 
00237 
00238   //----------------------------------------------------------------------------
00240   VISU_I_EXPORT ColoredPrs3d_i*
00241   CreateHolder2GetDeviceByEnum(VISU::VISUType theType,
00242                       VISU::Result_ptr theResult, 
00243                       const std::string& theMeshName, 
00244                       VISU::Entity theEntity,
00245                       const std::string& theFieldName, 
00246                       CORBA::Long theTimeStampNumber,
00247                       VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
00248                       CORBA::Float theRequiredMemory);
00249     
00250   
00251   //----------------------------------------------------------------------------
00253   template<class TColoredPrs3d_i> 
00254   TColoredPrs3d_i*
00255   CreateHolder2GetDeviceByType(VISU::Result_ptr theResult, 
00256                       const std::string& theMeshName, 
00257                       VISU::Entity theEntity,
00258                       const std::string& theFieldName, 
00259                       CORBA::Long theTimeStampNumber,
00260                       VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
00261                       CORBA::Float theRequiredMemory)
00262   {
00263     typedef typename TL::TColoredType2Enum<TColoredPrs3d_i>::TResult TEnum;
00264     VISU::VISUType aColoredPrs3dType = VISU::VISUType(TEnum::value);
00265     ColoredPrs3d_i* aColoredPrs3d = CreateHolder2GetDeviceByEnum(aColoredPrs3dType,
00266                                          theResult, 
00267                                          theMeshName, 
00268                                          theEntity,
00269                                          theFieldName, 
00270                                          theTimeStampNumber,
00271                                          theEnlargeType,
00272                                          theRequiredMemory);
00273     return dynamic_cast<TColoredPrs3d_i*>(aColoredPrs3d);
00274   }
00275 
00276 
00277   //----------------------------------------------------------------------------
00278   template<unsigned int colored_prs3d_type_enum>
00279   struct TSameAsFactory
00280   {
00281     typedef typename TL::TColoredEnum2Type<colored_prs3d_type_enum>::TResult TColoredPrs3d;
00282 
00283     void
00284     Copy(ColoredPrs3d_i* theColoredPrs3dFrom, ColoredPrs3d_i* theColoredPrs3dTo)
00285     {
00286       theColoredPrs3dTo->SetCResult(theColoredPrs3dFrom->GetCResult());
00287       theColoredPrs3dTo->SetMeshName(theColoredPrs3dFrom->GetCMeshName().c_str());
00288       theColoredPrs3dTo->SetEntity(theColoredPrs3dFrom->GetEntity());
00289       theColoredPrs3dTo->SetFieldName(theColoredPrs3dFrom->GetCFieldName().c_str());
00290       theColoredPrs3dTo->SetTimeStampNumber(theColoredPrs3dFrom->GetTimeStampNumber());
00291       theColoredPrs3dTo->SameAs(theColoredPrs3dFrom);
00292     }
00293 
00294     SALOME::GenericObjPtr<TColoredPrs3d>
00295     Create(ColoredPrs3d_i* theColoredPrs3d,
00296         ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode,
00297         bool theCreateAsTemporalObject = true)
00298     {
00299       SALOME::GenericObjPtr<TColoredPrs3d> aSameColoredPrs3d(new TColoredPrs3d(thePublishInStudyMode));
00300       Copy(theColoredPrs3d, aSameColoredPrs3d);
00301       if ( theCreateAsTemporalObject )
00302      aSameColoredPrs3d->UnRegister();
00303       return aSameColoredPrs3d;
00304     }
00305   };
00306 
00307   //----------------------------------------------------------------------------
00309   VISU_I_EXPORT size_t
00310   CheckIsPossible(VISU::VISUType theType,
00311             const VISU::ColoredPrs3dHolder::BasicInput& theInput,
00312             bool theMemoryCheck);
00313     
00314   //----------------------------------------------------------------------------
00316   template<unsigned int colored_prs3d_type_enum> 
00317   size_t
00318   CheckIsPossible(const VISU::ColoredPrs3dHolder::BasicInput& theInput,
00319             bool theMemoryCheck)
00320   {
00321     VISU::Result_i* aResult = dynamic_cast<VISU::Result_i*>( VISU::GetServant(theInput.myResult).in() );
00322     std::string aMeshName = theInput.myMeshName.in();
00323     VISU::Entity anEntity = theInput.myEntity;
00324     std::string aFieldName = theInput.myFieldName.in();
00325     CORBA::Long aTimeStampNumber = theInput.myTimeStampNumber;
00326 
00327     typedef typename VISU::TL::TColoredEnum2Type<colored_prs3d_type_enum>::TResult TColoredPrs3d;
00328     return TColoredPrs3d::IsPossible(aResult,
00329                          aMeshName,
00330                          anEntity,
00331                          aFieldName,
00332                          aTimeStampNumber,
00333                          theMemoryCheck);
00334   }
00335 
00336   //----------------------------------------------------------------------------
00337 }
00338 
00339 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS