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