]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_I/VISU_ColoredPrs3dHolder_i.cc
Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISU_I / VISU_ColoredPrs3dHolder_i.cc
1 //  Copyright (C) 2007-2010  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_ColoredPrs3dHolder_i.cc
25 //  Author : Oleg UVAROV
26 //  Module : VISU
27 //
28 #include "VISU_ColoredPrs3dHolder_i.hh"
29
30 #include "VISU_ColoredPrs3dCache_i.hh"
31 #include "VISU_ColoredPrs3d_i.hh"
32
33 #include "SALOME_Event.h"
34
35 using namespace VISU;
36 using namespace std;
37
38 #ifdef _DEBUG_
39 static int MYDEBUG = 0;
40 #else
41 static int MYDEBUG = 0;
42 #endif
43
44 using namespace std;
45
46 //---------------------------------------------------------------
47 int VISU::ColoredPrs3dHolder_i::myNbHolders = 0;
48
49 //---------------------------------------------------------------
50 QString 
51 VISU::ColoredPrs3dHolder_i
52 ::GenerateName() 
53
54   return VISU::GenerateName("Holder",myNbHolders++);
55 }
56
57 //----------------------------------------------------------------------------
58 const string VISU::ColoredPrs3dHolder_i::myComment = "COLOREDPRS3DHOLDER";
59
60 const char* 
61 VISU::ColoredPrs3dHolder_i
62 ::GetComment() const 
63
64   return myComment.c_str();
65 }
66
67
68 //----------------------------------------------------------------------------
69 VISU::ColoredPrs3dHolder_i
70 ::ColoredPrs3dHolder_i(VISU::ColoredPrs3dCache_i& theCache) :
71   PrsObject_i(theCache.GetStudyDocument()),
72   myCache(theCache)
73 {
74   if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::ColoredPrs3dHolder_i - this = "<<this);
75 }
76
77
78 //----------------------------------------------------------------------------
79 VISU::ColoredPrs3dHolder_i
80 ::~ColoredPrs3dHolder_i() 
81 {
82   if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::~ColoredPrs3dHolder_i - this = "<<this);
83 }
84
85
86 //----------------------------------------------------------------------------
87 void
88 VISU::ColoredPrs3dHolder_i
89 ::PublishInStudy(const std::string& theName, 
90                  const std::string& theIconName, 
91                  const std::string& theComment)
92 {
93   SetName(theName, false);
94   CORBA::String_var anIOR = GetID();
95   std::string aFatherEntry = myCache.GetEntry();
96   CreateAttributes(GetStudyDocument(), 
97                    aFatherEntry, 
98                    theIconName, 
99                    anIOR.in(), 
100                    GetName(), 
101                    "", 
102                    theComment, 
103                    true);
104 }
105
106 //----------------------------------------------------------------------------
107 struct TApplyEvent: public SALOME_Event
108 {
109   VISU::ColoredPrs3dCache_i& myCache;
110   VISU::ColoredPrs3dHolder_i* myHolder;
111   VISU::ColoredPrs3d_i* myPrs3d;
112   VISU::ColoredPrs3dHolder::BasicInput myInput;
113   VISU::View3D_ptr myView3D;
114
115   typedef CORBA::Boolean TResult;
116   TResult myResult;
117
118   TApplyEvent(VISU::ColoredPrs3dCache_i& theCache,
119               VISU::ColoredPrs3dHolder_i* theHolder,
120               VISU::ColoredPrs3d_i* thePrs3d,
121               VISU::ColoredPrs3dHolder::BasicInput theInput,
122               VISU::View3D_ptr theView3D):
123     myCache(theCache),
124     myHolder(theHolder),
125     myPrs3d(thePrs3d),
126     myInput(theInput),
127     myView3D(theView3D)
128   {}
129
130   virtual
131   void
132   Execute()
133   {
134     myResult = myCache.UpdateLastVisitedPrs(myHolder, myPrs3d, myInput, myView3D);
135   }
136 };
137
138 //----------------------------------------------------------------------------
139 CORBA::Boolean 
140 VISU::ColoredPrs3dHolder_i
141 ::Apply(VISU::ColoredPrs3d_ptr thePrs3d,
142         const VISU::ColoredPrs3dHolder::BasicInput& theInput,
143         VISU::View3D_ptr theView3D)
144 {
145
146   VISU::ColoredPrs3d_i* aPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>( VISU::GetServant(thePrs3d).in() );
147   return ProcessEvent(new TApplyEvent(myCache, this, aPrs3d, theInput, theView3D));
148   //return myCache.UpdateLastVisitedPrs(this, aPrs3d, theInput, theView3D);
149 }
150
151 //----------------------------------------------------------------------------
152 VISU::ColoredPrs3d_i*
153 VISU::ColoredPrs3dHolder_i
154 ::GetPrs3dDevice()
155 {
156   try{
157     return myCache.GetLastVisitedPrs(this);
158   }catch(...){}
159
160   return NULL;
161 }
162
163
164 VISU::ColoredPrs3d_ptr
165 VISU::ColoredPrs3dHolder_i
166 ::GetDevice()
167 {
168   if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
169     return aDevice->_this();
170
171   return VISU::ColoredPrs3d::_nil();
172 }
173
174
175 //----------------------------------------------------------------------------
176 VISU::ColoredPrs3dHolder::TimeStampsRange*
177 VISU::ColoredPrs3dHolder_i
178 ::GetTimeStampsRange()
179 {
180   if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
181     return aDevice->GetTimeStampsRange();
182
183   return NULL;
184 }
185
186
187 //----------------------------------------------------------------------------
188 VISU::ColoredPrs3dHolder::BasicInput*
189 VISU::ColoredPrs3dHolder_i
190 ::GetBasicInput()
191 {
192   if( VISU::ColoredPrs3d_ptr aDevice = GetDevice() )
193   {
194     VISU::ColoredPrs3d_i* aPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>( VISU::GetServant(aDevice).in() );
195     if( aPrs3d )
196       return aPrs3d->GetBasicInput();
197   }
198
199   return NULL;
200 }
201
202
203 //----------------------------------------------------------------------------
204 VISU::ColoredPrs3dCache_ptr
205 VISU::ColoredPrs3dHolder_i
206 ::GetCache()
207 {
208   return myCache._this();
209 }
210
211
212 //----------------------------------------------------------------------------
213 CORBA::Float
214 VISU::ColoredPrs3dHolder_i
215 ::GetMemorySize()
216 {
217   return GetDevice()->GetMemorySize();
218 }
219
220
221 //----------------------------------------------------------------------------
222 VISU::VISUType
223 VISU::ColoredPrs3dHolder_i
224 ::GetPrsType()
225 {
226   return GetPrs3dDevice()->GetType();
227 }
228
229 //----------------------------------------------------------------------------
230 void
231 VISU::ColoredPrs3dHolder_i
232 ::RemoveFromStudy() 
233 {
234   myCache.RemoveHolder(this);
235   CORBA::String_var anIOR = GetID();
236   SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectIOR(anIOR.in());
237   VISU::RemoveFromStudy(aSObject, false);
238   Destroy();
239 }
240
241 //----------------------------------------------------------------------------
242 void
243 VISU::ColoredPrs3dHolder_i
244 ::ToStream(std::ostringstream& theStr) 
245 {
246   Storable::DataToStream( theStr, "myPrsType", GetPrsType() );
247   GetPrs3dDevice()->ToStream(theStr);
248 }
249
250 //---------------------------------------------------------------
251 VISU::Storable*
252 VISU::ColoredPrs3dHolder_i
253 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
254                  const Storable::TRestoringMap& theMap,
255                  const std::string& thePrefix,
256                  CORBA::Boolean theIsMultiFile)
257 {
258   using namespace VISU;
259   SALOMEDS::Study_var aStudy = theSObject->GetStudy();
260   VISUType aType = VISUType(Storable::FindValue(theMap,"myPrsType").toInt());
261   if(ColoredPrs3d_i* aColoredPrs3d = CreatePrs3d_i(aType, aStudy, ColoredPrs3d_i::EDoNotPublish)){
262     if(ColoredPrs3dCache_i* aCache = ColoredPrs3dCache_i::GetInstance_i(aStudy))
263       if(ColoredPrs3dHolder_i* aHolder = new ColoredPrs3dHolder_i(*aCache)){
264         // To postpone restoring of the device
265         aColoredPrs3d->SaveRestoringState(theSObject, theMap); 
266         CORBA::String_var anEntry = theSObject->GetID();
267         aCache->RegisterInHolder(aColoredPrs3d, anEntry.in());
268         return aHolder;
269       }
270   }
271   return NULL;
272 }