Salome HOME
65e51b9a8b28dea629dc3f9760534e685e240992
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3dFactory.cc
1 // Copyright (C) 2007-2011  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.cc
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27 //
28 #include "VISU_ColoredPrs3dFactory.hh"
29 #include "VISU_ColoredPrs3dCache_i.hh"
30
31 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
32 #define NO_CAS_CATCH
33 #endif
34
35 #include <Standard_Failure.hxx>
36
37 #ifdef NO_CAS_CATCH
38 #include <Standard_ErrorHandler.hxx>
39 #endif
40
41 #ifdef _DEBUG_
42 //static int MYDEBUG = 0;
43 //#define _DEXCEPT_
44 #else
45 //static int MYDEBUG = 0;
46 #endif
47
48 using namespace std;
49
50 namespace VISU
51 {
52   //----------------------------------------------------------------------------
53   bool
54   CreatColoredPrs3d(ColoredPrs3d_i* theColoredPrs3d,
55                     Result_i* theResult,
56                     const std::string& theMeshName, 
57                     VISU::Entity theEntity,
58                     const std::string& theFieldName, 
59                     CORBA::Long theIteration)
60   {
61 #ifndef _DEXCEPT_
62     try{
63 #ifdef NO_CAS_CATCH
64       OCC_CATCH_SIGNALS;
65 #endif
66 #endif
67       theColoredPrs3d->SetCResult(theResult);
68       theColoredPrs3d->SetMeshName(theMeshName.c_str());
69       theColoredPrs3d->SetEntity(theEntity);
70       theColoredPrs3d->SetFieldName(theFieldName.c_str());
71       theColoredPrs3d->SetTimeStampNumber(theIteration);
72       if(theColoredPrs3d->Apply(false))
73         return true;
74 #ifndef _DEXCEPT_
75     }catch(Standard_Failure) {
76       Handle(Standard_Failure) aFail = Standard_Failure::Caught();
77       INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
78     }catch(std::exception& exc){
79       INFOS("Follow exception was occured :\n"<<exc.what());
80     }catch(...){
81       INFOS("Unknown exception was occured!");
82     }
83 #endif
84     return false;
85   }
86
87
88   //----------------------------------------------------------------------------
89   VISU::ColoredPrs3d_i*
90   CreatePrs3d_i(VISUType theType,
91                 SALOMEDS::Study_ptr theStudy,
92                 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
93   {
94     switch(theType){
95     case TSCALARMAP:
96       return VISU::CreatePrs3dByEnum<TSCALARMAP>(theStudy, thePublishInStudyMode);
97     case TGAUSSPOINTS:
98       return VISU::CreatePrs3dByEnum<TGAUSSPOINTS>(theStudy, thePublishInStudyMode);
99     case TDEFORMEDSHAPE:
100       return VISU::CreatePrs3dByEnum<TDEFORMEDSHAPE>(theStudy, thePublishInStudyMode);
101     case TSCALARMAPONDEFORMEDSHAPE:
102     case TDEFORMEDSHAPEANDSCALARMAP:
103       return VISU::CreatePrs3dByEnum<TDEFORMEDSHAPEANDSCALARMAP>(theStudy, thePublishInStudyMode);
104     case TISOSURFACES:
105       return VISU::CreatePrs3dByEnum<TISOSURFACES>(theStudy, thePublishInStudyMode);
106     case TSTREAMLINES:
107       return VISU::CreatePrs3dByEnum<TSTREAMLINES>(theStudy, thePublishInStudyMode);
108     case TPLOT3D:
109       return VISU::CreatePrs3dByEnum<TPLOT3D>(theStudy, thePublishInStudyMode);
110     case TCUTPLANES:
111       return VISU::CreatePrs3dByEnum<TCUTPLANES>(theStudy, thePublishInStudyMode);
112     case TCUTLINES:
113       return VISU::CreatePrs3dByEnum<TCUTLINES>(theStudy, thePublishInStudyMode);
114     case TCUTSEGMENT:
115       return VISU::CreatePrs3dByEnum<TCUTSEGMENT>(theStudy, thePublishInStudyMode);
116     case TVECTORS:
117       return VISU::CreatePrs3dByEnum<TVECTORS>(theStudy, thePublishInStudyMode);
118     }
119     return NULL;
120   }
121
122
123   //----------------------------------------------------------------------------
124   VISU::ColoredPrs3dCache::EnlargeType
125   GetRequiredCacheMemory(VISU::VISUType theType,
126                          VISU::Result_ptr theResult, 
127                          const std::string& theMeshName, 
128                          VISU::Entity theEntity,
129                          const std::string& theFieldName, 
130                          CORBA::Long theIteration,
131                          CORBA::Float& theUsedMemory,
132                          CORBA::Float& theRequiredMemory)
133   {
134     VISU::ColoredPrs3dCache::EnlargeType anEnlargeType = VISU::ColoredPrs3dCache::NO_ENLARGE;
135     if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
136       VISU::ColoredPrs3dHolder::BasicInput anInput;
137       anInput.myResult = VISU::Result::_duplicate(theResult);
138       anInput.myMeshName = theMeshName.c_str();
139       anInput.myEntity = theEntity;
140       anInput.myFieldName = theFieldName.c_str();
141       anInput.myTimeStampNumber = theIteration;
142       
143       SALOMEDS::Study_var aStudy = aResult->GetStudyDocument();
144       VISU::ColoredPrs3dCache_var aCache = ColoredPrs3dCache_i::GetInstance(aStudy);
145
146       theUsedMemory = aCache->GetMemorySize();
147       anEnlargeType = aCache->GetRequiredMemory(theType, anInput, theRequiredMemory);
148     }
149     return anEnlargeType;
150   }
151
152
153   //----------------------------------------------------------------------------
154   VISU::ColoredPrs3d_i*
155   CreateHolder2GetDeviceByEnum(VISU::VISUType theType,
156                                VISU::Result_ptr theResult, 
157                                const std::string& theMeshName, 
158                                VISU::Entity theEntity,
159                                const std::string& theFieldName, 
160                                CORBA::Long theIteration,
161                                VISU::ColoredPrs3dCache::EnlargeType theEnlargeType,
162                                CORBA::Float theRequiredMemory)
163   {
164     VISU::ColoredPrs3d_i* aColoredPrs3d = NULL;
165     if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(theResult).in())){
166       VISU::ColoredPrs3dHolder::BasicInput anInput;
167       anInput.myResult = VISU::Result::_duplicate(theResult);
168       anInput.myMeshName = theMeshName.c_str();
169       anInput.myEntity = theEntity;
170       anInput.myFieldName = theFieldName.c_str();
171       anInput.myTimeStampNumber = theIteration;
172       
173       SALOMEDS::Study_var aStudy = aResult->GetStudyDocument();
174       VISU::ColoredPrs3dCache_var aCache = ColoredPrs3dCache_i::GetInstance(aStudy);
175
176       if( theEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
177         aCache->SetLimitedMemory( theRequiredMemory );
178
179       VISU::ColoredPrs3dHolder_var aHolder = aCache->CreateHolder(theType, anInput);
180       
181       if( CORBA::is_nil(aHolder) )
182         return NULL;
183       
184       VISU::ColoredPrs3d_var aPrs3d = aHolder->GetDevice();
185       aColoredPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>(GetServant(aPrs3d).in());
186     }
187     return aColoredPrs3d;
188   }
189   
190   
191   //----------------------------------------------------------------------------
192   size_t
193   CheckIsPossible(VISU::VISUType theType,
194                   const VISU::ColoredPrs3dHolder::BasicInput& theInput,
195                   bool theMemoryCheck)
196   {
197     size_t aMemory = 0;
198     switch(theType){
199     case TSCALARMAP:
200       aMemory = CheckIsPossible<TSCALARMAP>(theInput, theMemoryCheck);
201       break;
202     case TGAUSSPOINTS:
203       aMemory = CheckIsPossible<TGAUSSPOINTS>(theInput, theMemoryCheck);
204       break;
205     case TDEFORMEDSHAPE:
206       aMemory = CheckIsPossible<TDEFORMEDSHAPE>(theInput, theMemoryCheck);
207       break;
208     case TSCALARMAPONDEFORMEDSHAPE:
209     case TDEFORMEDSHAPEANDSCALARMAP:
210       aMemory = CheckIsPossible<TDEFORMEDSHAPEANDSCALARMAP>(theInput, theMemoryCheck);
211       break;
212     case TISOSURFACES:
213       aMemory = CheckIsPossible<TISOSURFACES>(theInput, theMemoryCheck);
214       break;
215     case TSTREAMLINES:
216       aMemory = CheckIsPossible<TSTREAMLINES>(theInput, theMemoryCheck);
217       break;
218     case TPLOT3D:
219       aMemory = CheckIsPossible<TPLOT3D>(theInput, theMemoryCheck);
220       break;
221     case TCUTPLANES:
222       aMemory = CheckIsPossible<TCUTPLANES>(theInput, theMemoryCheck);
223       break;
224     case TCUTLINES:
225       aMemory = CheckIsPossible<TCUTLINES>(theInput, theMemoryCheck);
226       break;
227     case TCUTSEGMENT:
228       aMemory = CheckIsPossible<TCUTSEGMENT>(theInput, theMemoryCheck);
229       break;
230     case TVECTORS:
231       aMemory = CheckIsPossible<TVECTORS>(theInput, theMemoryCheck);
232       break;
233     }
234     return aMemory;
235   }
236
237
238   //----------------------------------------------------------------------------
239 }