3 #include "GEOM_Object_i.hh"
4 #include "GEOM_Gen_i.hh"
5 #include "GEOM_ISubShape.hxx"
9 #include "Utils_ExceptHandlers.hxx"
10 #include <TDF_Tool.hxx>
11 #include <TDF_Label.hxx>
12 #include <TCollection_AsciiString.hxx>
17 #include <BRepTools_ShapeSet.hxx>
18 #include <BRepTools.hxx>
21 //=============================================================================
25 //=============================================================================
27 GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine,
28 Handle(GEOM_Object) theImpl)
29 :SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
31 thePOA->activate_object(this);
34 //=============================================================================
38 //=============================================================================
40 GEOM_Object_i::~GEOM_Object_i()
44 //=============================================================================
48 //=============================================================================
49 char* GEOM_Object_i::GetEntry()
51 const TDF_Label& aLabel = _impl->GetEntry();
52 TCollection_AsciiString anEntry;
53 TDF_Tool::Entry(aLabel, anEntry);
54 return CORBA::string_dup(anEntry.ToCString());
57 //=============================================================================
61 //=============================================================================
62 CORBA::Long GEOM_Object_i::GetStudyID()
64 return _impl->GetDocID();
68 //=============================================================================
72 //=============================================================================
73 CORBA::Long GEOM_Object_i::GetType()
75 return _impl->GetType();
78 //=============================================================================
82 //=============================================================================
83 GEOM::shape_type GEOM_Object_i::GetShapeType()
85 TopoDS_Shape _geom = _impl->GetValue();
86 if(_geom.IsNull()) return GEOM::SHAPE;
87 return (GEOM::shape_type)_geom.ShapeType();
90 //=============================================================================
94 //=============================================================================
95 void GEOM_Object_i::SetName(const char* theName)
97 _impl->SetName(theName);
101 //=============================================================================
105 //=============================================================================
106 char* GEOM_Object_i::GetName()
108 char* aName = _impl->GetName();
109 if(aName) return strdup(aName);
113 //=============================================================================
117 //=============================================================================
118 void GEOM_Object_i::SetStudyEntry(const char* theEntry)
120 _impl->SetAuxData(theEntry);
124 //=============================================================================
128 //=============================================================================
129 char* GEOM_Object_i::GetStudyEntry()
131 char* anEntry = _impl->GetAuxData();
132 if(anEntry) return strdup(anEntry);
137 //=============================================================================
141 //=============================================================================
142 GEOM::ListOfGO* GEOM_Object_i::GetDependency()
144 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
147 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
148 if (aSeq.IsNull()) return aList._retn();
149 int aLength = aSeq->Length();
150 if (aLength == 0) return aList._retn();
152 aList->length(aLength);
154 TCollection_AsciiString anEntry;
156 for (int i = 1; i<=aLength; i++) {
157 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
158 if (anObj.IsNull()) continue;
159 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
160 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
164 return aList._retn();
167 //=============================================================================
171 //=============================================================================
172 GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
174 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
177 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
178 if (aSeq.IsNull()) return aList._retn();
179 int aLength = aSeq->Length();
180 if (aLength == 0) return aList._retn();
182 aList->length(aLength);
184 TCollection_AsciiString anEntry;
186 for (int i = 1; i<=aLength; i++) {
187 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
188 if (anObj.IsNull()) continue;
189 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
190 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
194 return aList._retn();
197 //=================================================================================
198 // function : GetShapeStream
199 // Transfer resulting shape to client as sequence of bytes
200 //client can extract shape from stream using BrepTools::Read function
201 //=================================================================================
202 SALOMEDS::TMPFile* GEOM_Object_i::GetShapeStream()
204 TopoDS_Shape aShape = _impl->GetValue();
206 if(aShape.IsNull()) return NULL;
208 ostrstream streamShape;
209 //Write TopoDS_Shape in ASCII format to the stream
210 BRepTools::Write(aShape, streamShape);
211 //Returns the number of bytes that have been stored in the stream's buffer.
212 int size = streamShape.pcount();
213 char* buf = new char [size];
214 //Get pointer on internal character array in ostrstream
215 char* valueOfStream = streamShape.str();
216 //Create copy of ostrstream content
217 memcpy(buf, valueOfStream, size);
218 //Allow automatic deletion of ostrstream content
219 streamShape.rdbuf()->freeze(0);
221 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
222 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
223 return SeqFile._retn();
228 //=======================================================================
229 //function : getShape
230 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
231 //=======================================================================
232 long GEOM_Object_i::getShape() {
233 _geom = _impl->GetValue();
234 return((long)(&_geom));
237 //=============================================================================
241 //=============================================================================
242 GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
244 GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
246 if(!_impl->IsMainShape()) {
247 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
248 if(aFunction.IsNull()) return anIndices._retn();
249 GEOM_ISubShape ISS(aFunction);
250 Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
251 if(anArray.IsNull() || anArray->Length() < 1) return anIndices._retn();
252 anIndices->length(anArray->Length());
253 for(int i=1; i<=anArray->Length(); i++) anIndices[i-1] = anArray->Value(i);
256 anIndices->length(0);
259 return anIndices._retn();
263 //=============================================================================
267 //=============================================================================
268 GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
270 GEOM::GEOM_Object_var obj;
271 if(!_impl->IsMainShape()) {
272 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
273 if(aFunction.IsNull()) return obj._retn();
274 GEOM_ISubShape ISS(aFunction);
276 aFunction = ISS.GetMainShape();
277 if(aFunction.IsNull()) return obj._retn();
278 TDF_Label aLabel = aFunction->GetOwnerEntry();
279 if(aLabel.IsNull()) return obj._retn();
280 TCollection_AsciiString anEntry;
281 TDF_Tool::Entry(aLabel, anEntry);
282 return GEOM::GEOM_Object::_duplicate(_engine->GetObject(_impl->GetDocID(), anEntry.ToCString()));