1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File : VISU_ColoredPrs3dHolder_i.cc
25 // Author : Oleg UVAROV
28 #include "VISU_ColoredPrs3dHolder_i.hh"
30 #include "VISU_ColoredPrs3dCache_i.hh"
31 #include "VISU_ColoredPrs3d_i.hh"
33 #include "SALOME_Event.h"
39 static int MYDEBUG = 0;
41 static int MYDEBUG = 0;
46 //---------------------------------------------------------------
47 int VISU::ColoredPrs3dHolder_i::myNbHolders = 0;
49 //---------------------------------------------------------------
51 VISU::ColoredPrs3dHolder_i
54 return VISU::GenerateName("Holder",myNbHolders++);
57 //----------------------------------------------------------------------------
58 const string VISU::ColoredPrs3dHolder_i::myComment = "COLOREDPRS3DHOLDER";
61 VISU::ColoredPrs3dHolder_i
64 return myComment.c_str();
68 //----------------------------------------------------------------------------
69 VISU::ColoredPrs3dHolder_i
70 ::ColoredPrs3dHolder_i(VISU::ColoredPrs3dCache_i& theCache) :
71 PrsObject_i(theCache.GetStudyDocument()),
74 if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::ColoredPrs3dHolder_i - this = "<<this);
78 //----------------------------------------------------------------------------
79 VISU::ColoredPrs3dHolder_i
80 ::~ColoredPrs3dHolder_i()
82 if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::~ColoredPrs3dHolder_i - this = "<<this);
86 //----------------------------------------------------------------------------
88 VISU::ColoredPrs3dHolder_i
89 ::PublishInStudy(const std::string& theName,
90 const std::string& theIconName,
91 const std::string& theComment)
93 SetName(theName, false);
94 CORBA::String_var anIOR = GetID();
95 std::string aFatherEntry = myCache.GetEntry();
96 CreateAttributes(GetStudyDocument(),
106 //----------------------------------------------------------------------------
107 struct TApplyEvent: public SALOME_Event
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;
115 typedef CORBA::Boolean TResult;
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):
134 myResult = myCache.UpdateLastVisitedPrs(myHolder, myPrs3d, myInput, myView3D);
138 //----------------------------------------------------------------------------
140 VISU::ColoredPrs3dHolder_i
141 ::Apply(VISU::ColoredPrs3d_ptr thePrs3d,
142 const VISU::ColoredPrs3dHolder::BasicInput& theInput,
143 VISU::View3D_ptr theView3D)
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);
151 //----------------------------------------------------------------------------
152 VISU::ColoredPrs3d_i*
153 VISU::ColoredPrs3dHolder_i
157 return myCache.GetLastVisitedPrs(this);
164 VISU::ColoredPrs3d_ptr
165 VISU::ColoredPrs3dHolder_i
168 if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
169 return aDevice->_this();
171 return VISU::ColoredPrs3d::_nil();
175 //----------------------------------------------------------------------------
176 VISU::ColoredPrs3dHolder::TimeStampsRange*
177 VISU::ColoredPrs3dHolder_i
178 ::GetTimeStampsRange()
180 if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
181 return aDevice->GetTimeStampsRange();
187 //----------------------------------------------------------------------------
188 VISU::ColoredPrs3dHolder::BasicInput*
189 VISU::ColoredPrs3dHolder_i
192 if( VISU::ColoredPrs3d_ptr aDevice = GetDevice() )
194 VISU::ColoredPrs3d_i* aPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>( VISU::GetServant(aDevice).in() );
196 return aPrs3d->GetBasicInput();
203 //----------------------------------------------------------------------------
204 VISU::ColoredPrs3dCache_ptr
205 VISU::ColoredPrs3dHolder_i
208 return myCache._this();
212 //----------------------------------------------------------------------------
214 VISU::ColoredPrs3dHolder_i
217 return GetDevice()->GetMemorySize();
221 //----------------------------------------------------------------------------
223 VISU::ColoredPrs3dHolder_i
226 return GetPrs3dDevice()->GetType();
229 //----------------------------------------------------------------------------
231 VISU::ColoredPrs3dHolder_i
234 myCache.RemoveHolder(this);
235 CORBA::String_var anIOR = GetID();
236 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectIOR(anIOR.in());
237 VISU::RemoveFromStudy(aSObject, false);
241 //----------------------------------------------------------------------------
243 VISU::ColoredPrs3dHolder_i
244 ::ToStream(std::ostringstream& theStr)
246 Storable::DataToStream( theStr, "myPrsType", GetPrsType() );
247 GetPrs3dDevice()->ToStream(theStr);
250 //---------------------------------------------------------------
252 VISU::ColoredPrs3dHolder_i
253 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
254 const Storable::TRestoringMap& theMap,
255 const std::string& thePrefix,
256 CORBA::Boolean theIsMultiFile)
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());