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