1 // Copyright (C) 2007-2008 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
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File : VISU_ColoredPrs3dHolder_i.cc
24 // Author : Oleg UVAROV
27 #include "VISU_ColoredPrs3dHolder_i.hh"
29 #include "VISU_ColoredPrs3dCache_i.hh"
30 #include "VISU_ColoredPrs3d_i.hh"
32 #include "SALOME_Event.h"
38 static int MYDEBUG = 0;
40 static int MYDEBUG = 0;
45 //---------------------------------------------------------------
46 int VISU::ColoredPrs3dHolder_i::myNbHolders = 0;
48 //---------------------------------------------------------------
50 VISU::ColoredPrs3dHolder_i
53 return VISU::GenerateName("Holder",myNbHolders++);
56 //----------------------------------------------------------------------------
57 const string VISU::ColoredPrs3dHolder_i::myComment = "COLOREDPRS3DHOLDER";
60 VISU::ColoredPrs3dHolder_i
63 return myComment.c_str();
67 //----------------------------------------------------------------------------
68 VISU::ColoredPrs3dHolder_i
69 ::ColoredPrs3dHolder_i(VISU::ColoredPrs3dCache_i& theCache) :
70 PrsObject_i(theCache.GetStudyDocument()),
73 if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::ColoredPrs3dHolder_i - this = "<<this);
77 //----------------------------------------------------------------------------
78 VISU::ColoredPrs3dHolder_i
79 ::~ColoredPrs3dHolder_i()
81 if(MYDEBUG) MESSAGE("ColoredPrs3dHolder_i::~ColoredPrs3dHolder_i - this = "<<this);
85 //----------------------------------------------------------------------------
87 VISU::ColoredPrs3dHolder_i
88 ::PublishInStudy(const std::string& theName,
89 const std::string& theIconName,
90 const std::string& theComment)
92 SetName(theName, false);
93 CORBA::String_var anIOR = GetID();
94 std::string aFatherEntry = myCache.GetEntry();
95 CreateAttributes(GetStudyDocument(),
105 //----------------------------------------------------------------------------
106 struct TApplyEvent: public SALOME_Event
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;
114 typedef CORBA::Boolean TResult;
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):
133 myResult = myCache.UpdateLastVisitedPrs(myHolder, myPrs3d, myInput, myView3D);
137 //----------------------------------------------------------------------------
139 VISU::ColoredPrs3dHolder_i
140 ::Apply(VISU::ColoredPrs3d_ptr thePrs3d,
141 const VISU::ColoredPrs3dHolder::BasicInput& theInput,
142 VISU::View3D_ptr theView3D)
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);
150 //----------------------------------------------------------------------------
151 VISU::ColoredPrs3d_i*
152 VISU::ColoredPrs3dHolder_i
156 return myCache.GetLastVisitedPrs(this);
163 VISU::ColoredPrs3d_ptr
164 VISU::ColoredPrs3dHolder_i
167 if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
168 return aDevice->_this();
170 return VISU::ColoredPrs3d::_nil();
174 //----------------------------------------------------------------------------
175 VISU::ColoredPrs3dHolder::TimeStampsRange*
176 VISU::ColoredPrs3dHolder_i
177 ::GetTimeStampsRange()
179 if( VISU::ColoredPrs3d_i* aDevice = GetPrs3dDevice() )
180 return aDevice->GetTimeStampsRange();
186 //----------------------------------------------------------------------------
187 VISU::ColoredPrs3dHolder::BasicInput*
188 VISU::ColoredPrs3dHolder_i
191 if( VISU::ColoredPrs3d_ptr aDevice = GetDevice() )
193 VISU::ColoredPrs3d_i* aPrs3d = dynamic_cast<VISU::ColoredPrs3d_i*>( VISU::GetServant(aDevice).in() );
195 return aPrs3d->GetBasicInput();
202 //----------------------------------------------------------------------------
203 VISU::ColoredPrs3dCache_ptr
204 VISU::ColoredPrs3dHolder_i
207 return myCache._this();
211 //----------------------------------------------------------------------------
213 VISU::ColoredPrs3dHolder_i
216 return GetDevice()->GetMemorySize();
220 //----------------------------------------------------------------------------
222 VISU::ColoredPrs3dHolder_i
225 return GetPrs3dDevice()->GetType();
228 //----------------------------------------------------------------------------
230 VISU::ColoredPrs3dHolder_i
233 myCache.RemoveHolder(this);
234 CORBA::String_var anIOR = GetID();
235 SALOMEDS::SObject_var aSObject = GetStudyDocument()->FindObjectIOR(anIOR.in());
236 VISU::RemoveFromStudy(aSObject, false);
240 //----------------------------------------------------------------------------
242 VISU::ColoredPrs3dHolder_i
243 ::ToStream(std::ostringstream& theStr)
245 Storable::DataToStream( theStr, "myPrsType", GetPrsType() );
246 GetPrs3dDevice()->ToStream(theStr);
249 //---------------------------------------------------------------
251 VISU::ColoredPrs3dHolder_i
252 ::StorableEngine(SALOMEDS::SObject_ptr theSObject,
253 const Storable::TRestoringMap& theMap,
254 const std::string& thePrefix,
255 CORBA::Boolean theIsMultiFile)
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());