1 #include <Standard_OStream.hxx>
3 #include <GEOM_Object_i.hh>
4 //#include <GEOM_Gen_i.hh>
5 #include <GEOM_ISubShape.hxx>
6 #include <GEOMImpl_Types.hxx>
13 #include <Utils_ExceptHandlers.hxx>
14 #include <TDF_Tool.hxx>
15 #include <TDF_Label.hxx>
16 #include <TCollection_AsciiString.hxx>
18 #include <BRepTools_ShapeSet.hxx>
19 #include <BRepTools.hxx>
23 #pragma warning( disable:4786 )
26 //=============================================================================
30 //=============================================================================
32 GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine,
33 Handle(GEOM_Object) theImpl)
34 : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
36 thePOA->activate_object(this);
39 //=============================================================================
43 //=============================================================================
45 GEOM_Object_i::~GEOM_Object_i()
49 //=============================================================================
53 //=============================================================================
54 char* GEOM_Object_i::GetEntry()
56 const TDF_Label& aLabel = _impl->GetEntry();
57 TCollection_AsciiString anEntry;
58 TDF_Tool::Entry(aLabel, anEntry);
59 return CORBA::string_dup(anEntry.ToCString());
62 //=============================================================================
66 //=============================================================================
67 CORBA::Long GEOM_Object_i::GetStudyID()
69 return _impl->GetDocID();
73 //=============================================================================
77 //=============================================================================
78 CORBA::Long GEOM_Object_i::GetType()
80 return _impl->GetType();
83 //=============================================================================
87 //=============================================================================
88 GEOM::shape_type GEOM_Object_i::GetShapeType()
90 TopoDS_Shape _geom = _impl->GetValue();
91 if(_geom.IsNull()) return GEOM::SHAPE;
92 return (GEOM::shape_type)_geom.ShapeType();
95 //=============================================================================
99 //=============================================================================
100 void GEOM_Object_i::SetName(const char* theName)
102 _impl->SetName(theName);
106 //=============================================================================
110 //=============================================================================
111 char* GEOM_Object_i::GetName()
113 char* aName = _impl->GetName();
114 if(aName) return strdup(aName);
118 //=============================================================================
122 //=============================================================================
123 void GEOM_Object_i::SetStudyEntry(const char* theEntry)
125 _impl->SetAuxData(theEntry);
129 //=============================================================================
133 //=============================================================================
134 char* GEOM_Object_i::GetStudyEntry()
136 TCollection_AsciiString anEntry = _impl->GetAuxData();
137 if(!anEntry.IsEmpty()) return strdup(anEntry.ToCString());
142 //=============================================================================
146 //=============================================================================
147 GEOM::ListOfGO* GEOM_Object_i::GetDependency()
149 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
152 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
153 if (aSeq.IsNull()) return aList._retn();
154 int aLength = aSeq->Length();
155 if (aLength == 0) return aList._retn();
157 aList->length(aLength);
159 TCollection_AsciiString anEntry;
161 for (int i = 1; i<=aLength; i++) {
162 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
163 if (anObj.IsNull()) continue;
164 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
165 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
169 return aList._retn();
172 //=============================================================================
176 //=============================================================================
177 GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
179 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
182 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
183 if (aSeq.IsNull()) return aList._retn();
184 int aLength = aSeq->Length();
185 if (aLength == 0) return aList._retn();
187 aList->length(aLength);
189 TCollection_AsciiString anEntry;
191 for (int i = 1; i<=aLength; i++) {
192 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
193 if (anObj.IsNull()) continue;
194 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
195 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
199 return aList._retn();
202 //=================================================================================
203 // function : GetShapeStream
204 // Transfer resulting shape to client as sequence of bytes
205 //client can extract shape from stream using BrepTools::Read function
206 //=================================================================================
207 SALOMEDS::TMPFile* GEOM_Object_i::GetShapeStream()
209 TopoDS_Shape aShape = _impl->GetValue();
211 if(aShape.IsNull()) return NULL;
213 ostrstream streamShape;
214 //Write TopoDS_Shape in ASCII format to the stream
215 BRepTools::Write(aShape, streamShape);
216 //Returns the number of bytes that have been stored in the stream's buffer.
217 int size = streamShape.pcount();
218 char* buf = new char [size];
219 //Get pointer on internal character array in ostrstream
220 char* valueOfStream = streamShape.str();
221 //Create copy of ostrstream content
222 memcpy(buf, valueOfStream, size);
223 //Allow automatic deletion of ostrstream content
224 streamShape.rdbuf()->freeze(0);
226 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
227 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
228 return SeqFile._retn();
233 //=======================================================================
234 //function : getShape
235 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
236 //=======================================================================
237 long GEOM_Object_i::getShape() {
238 _geom = _impl->GetValue();
239 return((long)(&_geom));
242 //=============================================================================
246 //=============================================================================
247 GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
249 GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
251 if(!_impl->IsMainShape()) {
252 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
253 if(aFunction.IsNull()) return anIndices._retn();
254 GEOM_ISubShape ISS(aFunction);
255 Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
256 if(anArray.IsNull() || anArray->Length() < 1) return anIndices._retn();
257 anIndices->length(anArray->Length());
258 for(int i=1; i<=anArray->Length(); i++) anIndices[i-1] = anArray->Value(i);
261 anIndices->length(0);
264 return anIndices._retn();
268 //=============================================================================
272 //=============================================================================
273 GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
275 GEOM::GEOM_Object_var obj;
276 if(!_impl->IsMainShape()) {
277 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
278 if(aFunction.IsNull()) return obj._retn();
279 GEOM_ISubShape ISS(aFunction);
281 aFunction = ISS.GetMainShape();
282 if(aFunction.IsNull()) return obj._retn();
283 TDF_Label aLabel = aFunction->GetOwnerEntry();
284 if(aLabel.IsNull()) return obj._retn();
285 TCollection_AsciiString anEntry;
286 TDF_Tool::Entry(aLabel, anEntry);
287 return GEOM::GEOM_Object::_duplicate(_engine->GetObject(_impl->GetDocID(), anEntry.ToCString()));
293 bool GEOM_Object_i::IsShape()
295 return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER;