1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Standard_OStream.hxx>
22 #include <GEOM_Object_i.hh>
23 //#include <GEOM_Gen_i.hh>
24 #include <GEOM_ISubShape.hxx>
25 #include <GEOMImpl_Types.hxx>
27 #include "utilities.h"
32 #include <Utils_ExceptHandlers.hxx>
33 #include <TDF_Tool.hxx>
34 #include <TDF_Label.hxx>
35 #include <TCollection_AsciiString.hxx>
37 #include <BRepTools_ShapeSet.hxx>
38 #include <BRepTools.hxx>
42 #pragma warning( disable:4786 )
45 //=============================================================================
49 //=============================================================================
51 GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine,
52 Handle(GEOM_Object) theImpl)
53 : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
57 //=============================================================================
61 //=============================================================================
63 GEOM_Object_i::~GEOM_Object_i()
65 GEOM_Engine::GetEngine()->RemoveObject(_impl);
69 //=============================================================================
73 //=============================================================================
74 char* GEOM_Object_i::GetEntry()
76 const TDF_Label& aLabel = _impl->GetEntry();
77 TCollection_AsciiString anEntry;
78 TDF_Tool::Entry(aLabel, anEntry);
79 const char* anEntstr = anEntry.ToCString();
80 return CORBA::string_dup(anEntstr);
83 //=============================================================================
87 //=============================================================================
88 CORBA::Long GEOM_Object_i::GetStudyID()
90 return _impl->GetDocID();
94 //=============================================================================
98 //=============================================================================
99 CORBA::Long GEOM_Object_i::GetType()
101 return _impl->GetType();
104 //=============================================================================
108 //=============================================================================
109 GEOM::shape_type GEOM_Object_i::GetShapeType()
111 TopoDS_Shape _geom = _impl->GetValue();
112 if(_geom.IsNull()) return GEOM::SHAPE;
113 return (GEOM::shape_type)_geom.ShapeType();
116 //=============================================================================
120 //=============================================================================
121 void GEOM_Object_i::SetName(const char* theName)
123 _impl->SetName(theName);
127 //=============================================================================
131 //=============================================================================
132 char* GEOM_Object_i::GetName()
134 char* aName = _impl->GetName();
136 return aName; // this is already copy of pointer (see implementation of _impl)
140 //=============================================================================
144 //=============================================================================
145 void GEOM_Object_i::SetColor(const SALOMEDS::Color& theColor)
147 _impl->SetColor(theColor);
151 //=============================================================================
155 //=============================================================================
156 SALOMEDS::Color GEOM_Object_i::GetColor()
158 return _impl->GetColor();
162 //=============================================================================
166 //=============================================================================
167 void GEOM_Object_i::SetAutoColor(CORBA::Boolean theAutoColor)
169 _impl->SetAutoColor(theAutoColor);
173 //=============================================================================
177 //=============================================================================
178 CORBA::Boolean GEOM_Object_i::GetAutoColor()
180 return _impl->GetAutoColor();
184 //=============================================================================
188 //=============================================================================
189 void GEOM_Object_i::SetStudyEntry(const char* theEntry)
191 _impl->SetAuxData(theEntry);
195 //=============================================================================
199 //=============================================================================
200 char* GEOM_Object_i::GetStudyEntry()
202 TCollection_AsciiString anEntry = _impl->GetAuxData();
203 if(!anEntry.IsEmpty()) return CORBA::string_dup(anEntry.ToCString());
204 return CORBA::string_dup("");
208 //=============================================================================
212 //=============================================================================
213 GEOM::ListOfGO* GEOM_Object_i::GetDependency()
215 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
218 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
219 if (aSeq.IsNull()) return aList._retn();
220 int aLength = aSeq->Length();
221 if (aLength == 0) return aList._retn();
223 aList->length(aLength);
225 TCollection_AsciiString anEntry;
227 for (int i = 1; i<=aLength; i++) {
228 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
229 if (anObj.IsNull()) continue;
230 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
231 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
235 return aList._retn();
238 //=============================================================================
242 //=============================================================================
243 GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
245 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
248 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
249 if (aSeq.IsNull()) return aList._retn();
250 int aLength = aSeq->Length();
251 if (aLength == 0) return aList._retn();
253 aList->length(aLength);
255 TCollection_AsciiString anEntry;
257 for (int i = 1; i<=aLength; i++) {
258 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
259 if (anObj.IsNull()) continue;
260 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
261 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
265 return aList._retn();
268 //=================================================================================
269 // function : GetShapeStream
270 // Transfer resulting shape to client as sequence of bytes
271 //client can extract shape from stream using BrepTools::Read function
272 //=================================================================================
273 SALOMEDS::TMPFile* GEOM_Object_i::GetShapeStream()
275 TopoDS_Shape aShape = _impl->GetValue();
277 if(aShape.IsNull()) return NULL;
279 ostrstream streamShape;
280 //Write TopoDS_Shape in ASCII format to the stream
281 BRepTools::Write(aShape, streamShape);
282 //Returns the number of bytes that have been stored in the stream's buffer.
283 int size = streamShape.pcount();
284 char* buf = new char [size];
285 //Get pointer on internal character array in ostrstream
286 char* valueOfStream = streamShape.str();
287 //Create copy of ostrstream content
288 memcpy(buf, valueOfStream, size);
289 //Allow automatic deletion of ostrstream content
290 streamShape.rdbuf()->freeze(0);
292 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
293 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
294 return SeqFile._retn();
299 //=======================================================================
300 //function : getShape
301 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
302 //=======================================================================
303 CORBA::LongLong GEOM_Object_i::getShape() {
304 _geom = _impl->GetValue();
305 return ((CORBA::LongLong)(&_geom));
308 //=============================================================================
312 //=============================================================================
313 GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
315 GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
317 if(!_impl->IsMainShape()) {
318 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
319 if(aFunction.IsNull()) return anIndices._retn();
320 GEOM_ISubShape ISS(aFunction);
321 Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
322 if(anArray.IsNull() || anArray->Length() < 1) return anIndices._retn();
323 anIndices->length(anArray->Length());
324 for(int i=1; i<=anArray->Length(); i++) anIndices[i-1] = anArray->Value(i);
327 anIndices->length(0);
330 return anIndices._retn();
334 //=============================================================================
338 //=============================================================================
339 GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
341 GEOM::GEOM_Object_var obj;
342 if(!_impl->IsMainShape()) {
343 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
344 if(aFunction.IsNull()) return obj._retn();
345 GEOM_ISubShape ISS(aFunction);
347 aFunction = ISS.GetMainShape();
348 if(aFunction.IsNull()) return obj._retn();
349 TDF_Label aLabel = aFunction->GetOwnerEntry();
350 if(aLabel.IsNull()) return obj._retn();
351 TCollection_AsciiString anEntry;
352 TDF_Tool::Entry(aLabel, anEntry);
353 return GEOM::GEOM_Object::_duplicate(_engine->GetObject(_impl->GetDocID(), anEntry.ToCString()));
359 bool GEOM_Object_i::IsShape()
361 return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER;