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