3 #include "GEOM_Object_i.hh"
4 #include "GEOM_Gen_i.hh"
5 #include "GEOM_ISubShape.hxx"
6 #include "GEOMImpl_Types.hxx"
10 #include "Utils_ExceptHandlers.hxx"
11 #include <TDF_Tool.hxx>
12 #include <TDF_Label.hxx>
13 #include <TCollection_AsciiString.hxx>
18 #include <BRepTools_ShapeSet.hxx>
19 #include <BRepTools.hxx>
22 //=============================================================================
26 //=============================================================================
28 GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine,
29 Handle(GEOM_Object) theImpl)
30 :SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
32 thePOA->activate_object(this);
35 //=============================================================================
39 //=============================================================================
41 GEOM_Object_i::~GEOM_Object_i()
45 //=============================================================================
49 //=============================================================================
50 char* GEOM_Object_i::GetEntry()
52 const TDF_Label& aLabel = _impl->GetEntry();
53 TCollection_AsciiString anEntry;
54 TDF_Tool::Entry(aLabel, anEntry);
55 return CORBA::string_dup(anEntry.ToCString());
58 //=============================================================================
62 //=============================================================================
63 CORBA::Long GEOM_Object_i::GetStudyID()
65 return _impl->GetDocID();
69 //=============================================================================
73 //=============================================================================
74 CORBA::Long GEOM_Object_i::GetType()
76 return _impl->GetType();
79 //=============================================================================
83 //=============================================================================
84 GEOM::shape_type GEOM_Object_i::GetShapeType()
86 TopoDS_Shape _geom = _impl->GetValue();
87 if(_geom.IsNull()) return GEOM::SHAPE;
88 return (GEOM::shape_type)_geom.ShapeType();
91 //=============================================================================
95 //=============================================================================
96 void GEOM_Object_i::SetName(const char* theName)
98 _impl->SetName(theName);
102 //=============================================================================
106 //=============================================================================
107 char* GEOM_Object_i::GetName()
109 char* aName = _impl->GetName();
110 if(aName) return strdup(aName);
114 //=============================================================================
118 //=============================================================================
119 void GEOM_Object_i::SetStudyEntry(const char* theEntry)
121 _impl->SetAuxData(theEntry);
125 //=============================================================================
129 //=============================================================================
130 char* GEOM_Object_i::GetStudyEntry()
132 char* anEntry = _impl->GetAuxData();
133 if(anEntry) return strdup(anEntry);
138 //=============================================================================
142 //=============================================================================
143 GEOM::ListOfGO* GEOM_Object_i::GetDependency()
145 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
148 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
149 if (aSeq.IsNull()) return aList._retn();
150 int aLength = aSeq->Length();
151 if (aLength == 0) return aList._retn();
153 aList->length(aLength);
155 TCollection_AsciiString anEntry;
157 for (int i = 1; i<=aLength; i++) {
158 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
159 if (anObj.IsNull()) continue;
160 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
161 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
165 return aList._retn();
168 //=============================================================================
172 //=============================================================================
173 GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
175 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
178 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
179 if (aSeq.IsNull()) return aList._retn();
180 int aLength = aSeq->Length();
181 if (aLength == 0) return aList._retn();
183 aList->length(aLength);
185 TCollection_AsciiString anEntry;
187 for (int i = 1; i<=aLength; i++) {
188 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
189 if (anObj.IsNull()) continue;
190 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
191 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
195 return aList._retn();
198 //=================================================================================
199 // function : GetShapeStream
200 // Transfer resulting shape to client as sequence of bytes
201 //client can extract shape from stream using BrepTools::Read function
202 //=================================================================================
203 SALOMEDS::TMPFile* GEOM_Object_i::GetShapeStream()
205 TopoDS_Shape aShape = _impl->GetValue();
207 if(aShape.IsNull()) return NULL;
209 ostrstream streamShape;
210 //Write TopoDS_Shape in ASCII format to the stream
211 BRepTools::Write(aShape, streamShape);
212 //Returns the number of bytes that have been stored in the stream's buffer.
213 int size = streamShape.pcount();
214 char* buf = new char [size];
215 //Get pointer on internal character array in ostrstream
216 char* valueOfStream = streamShape.str();
217 //Create copy of ostrstream content
218 memcpy(buf, valueOfStream, size);
219 //Allow automatic deletion of ostrstream content
220 streamShape.rdbuf()->freeze(0);
222 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
223 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
224 return SeqFile._retn();
229 //=======================================================================
230 //function : getShape
231 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
232 //=======================================================================
233 long GEOM_Object_i::getShape() {
234 _geom = _impl->GetValue();
235 return((long)(&_geom));
238 //=============================================================================
242 //=============================================================================
243 GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
245 GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
247 if(!_impl->IsMainShape()) {
248 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
249 if(aFunction.IsNull()) return anIndices._retn();
250 GEOM_ISubShape ISS(aFunction);
251 Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
252 if(anArray.IsNull() || anArray->Length() < 1) return anIndices._retn();
253 anIndices->length(anArray->Length());
254 for(int i=1; i<=anArray->Length(); i++) anIndices[i-1] = anArray->Value(i);
257 anIndices->length(0);
260 return anIndices._retn();
264 //=============================================================================
268 //=============================================================================
269 GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
271 GEOM::GEOM_Object_var obj;
272 if(!_impl->IsMainShape()) {
273 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
274 if(aFunction.IsNull()) return obj._retn();
275 GEOM_ISubShape ISS(aFunction);
277 aFunction = ISS.GetMainShape();
278 if(aFunction.IsNull()) return obj._retn();
279 TDF_Label aLabel = aFunction->GetOwnerEntry();
280 if(aLabel.IsNull()) return obj._retn();
281 TCollection_AsciiString anEntry;
282 TDF_Tool::Entry(aLabel, anEntry);
283 return GEOM::GEOM_Object::_duplicate(_engine->GetObject(_impl->GetDocID(), anEntry.ToCString()));
289 bool GEOM_Object_i::IsShape()
291 return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER;