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)
35 : SALOME::GenericObj_i( thePOA ), _engine(theEngine), _impl(theImpl)
38 thePOA->activate_object(this);
41 //=============================================================================
45 //=============================================================================
47 GEOM_Object_i::~GEOM_Object_i()
51 //=============================================================================
55 //=============================================================================
56 char* GEOM_Object_i::GetEntry()
58 const TDF_Label& aLabel = _impl->GetEntry();
59 TCollection_AsciiString anEntry;
60 TDF_Tool::Entry(aLabel, anEntry);
61 return CORBA::string_dup(anEntry.ToCString());
64 //=============================================================================
68 //=============================================================================
69 CORBA::Long GEOM_Object_i::GetStudyID()
71 return _impl->GetDocID();
75 //=============================================================================
79 //=============================================================================
80 CORBA::Long GEOM_Object_i::GetType()
82 return _impl->GetType();
85 //=============================================================================
89 //=============================================================================
90 GEOM::shape_type GEOM_Object_i::GetShapeType()
92 TopoDS_Shape _geom = _impl->GetValue();
93 if(_geom.IsNull()) return GEOM::SHAPE;
94 return (GEOM::shape_type)_geom.ShapeType();
97 //=============================================================================
101 //=============================================================================
102 void GEOM_Object_i::SetName(const char* theName)
104 _impl->SetName(theName);
108 //=============================================================================
112 //=============================================================================
113 char* GEOM_Object_i::GetName()
115 char* aName = _impl->GetName();
116 if(aName) return strdup(aName);
120 //=============================================================================
124 //=============================================================================
125 void GEOM_Object_i::SetStudyEntry(const char* theEntry)
127 _impl->SetAuxData(theEntry);
131 //=============================================================================
135 //=============================================================================
136 char* GEOM_Object_i::GetStudyEntry()
138 TCollection_AsciiString anEntry = _impl->GetAuxData();
139 if(!anEntry.IsEmpty()) return strdup(anEntry.ToCString());
144 //=============================================================================
148 //=============================================================================
149 GEOM::ListOfGO* GEOM_Object_i::GetDependency()
151 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
154 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetAllDependency();
155 if (aSeq.IsNull()) return aList._retn();
156 int aLength = aSeq->Length();
157 if (aLength == 0) return aList._retn();
159 aList->length(aLength);
161 TCollection_AsciiString anEntry;
163 for (int i = 1; i<=aLength; i++) {
164 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
165 if (anObj.IsNull()) continue;
166 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
167 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
171 return aList._retn();
174 //=============================================================================
178 //=============================================================================
179 GEOM::ListOfGO* GEOM_Object_i::GetLastDependency()
181 GEOM::ListOfGO_var aList = new GEOM::ListOfGO();
184 Handle(TColStd_HSequenceOfTransient) aSeq = _impl->GetLastDependency();
185 if (aSeq.IsNull()) return aList._retn();
186 int aLength = aSeq->Length();
187 if (aLength == 0) return aList._retn();
189 aList->length(aLength);
191 TCollection_AsciiString anEntry;
193 for (int i = 1; i<=aLength; i++) {
194 Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast(aSeq->Value(i));
195 if (anObj.IsNull()) continue;
196 TDF_Tool::Entry(anObj->GetEntry(), anEntry);
197 GEOM::GEOM_Object_var obj = GEOM::GEOM_Object::_duplicate(_engine->GetObject(anObj->GetDocID(), anEntry.ToCString()));
201 return aList._retn();
204 //=================================================================================
205 // function : GetShapeStream
206 // Transfer resulting shape to client as sequence of bytes
207 //client can extract shape from stream using BrepTools::Read function
208 //=================================================================================
209 SALOMEDS::TMPFile* GEOM_Object_i::GetShapeStream()
211 TopoDS_Shape aShape = _impl->GetValue();
213 if(aShape.IsNull()) return NULL;
215 ostrstream streamShape;
216 //Write TopoDS_Shape in ASCII format to the stream
217 BRepTools::Write(aShape, streamShape);
218 //Returns the number of bytes that have been stored in the stream's buffer.
219 int size = streamShape.pcount();
220 char* buf = new char [size];
221 //Get pointer on internal character array in ostrstream
222 char* valueOfStream = streamShape.str();
223 //Create copy of ostrstream content
224 memcpy(buf, valueOfStream, size);
225 //Allow automatic deletion of ostrstream content
226 streamShape.rdbuf()->freeze(0);
228 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
229 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
230 return SeqFile._retn();
235 //=======================================================================
236 //function : getShape
237 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
238 //=======================================================================
239 long GEOM_Object_i::getShape() {
240 _geom = _impl->GetValue();
241 return((long)(&_geom));
244 //=============================================================================
248 //=============================================================================
249 GEOM::ListOfLong* GEOM_Object_i::GetSubShapeIndices()
251 GEOM::ListOfLong_var anIndices = new GEOM::ListOfLong;
253 if(!_impl->IsMainShape()) {
254 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
255 if(aFunction.IsNull()) return anIndices._retn();
256 GEOM_ISubShape ISS(aFunction);
257 Handle(TColStd_HArray1OfInteger) anArray = ISS.GetIndices();
258 if(anArray.IsNull() || anArray->Length() < 1) return anIndices._retn();
259 anIndices->length(anArray->Length());
260 for(int i=1; i<=anArray->Length(); i++) anIndices[i-1] = anArray->Value(i);
263 anIndices->length(0);
266 return anIndices._retn();
270 //=============================================================================
274 //=============================================================================
275 GEOM::GEOM_Object_ptr GEOM_Object_i::GetMainShape()
277 GEOM::GEOM_Object_var obj;
278 if(!_impl->IsMainShape()) {
279 Handle(GEOM_Function) aFunction = _impl->GetFunction(1); //Get SubShape function (always the first (and last) one)
280 if(aFunction.IsNull()) return obj._retn();
281 GEOM_ISubShape ISS(aFunction);
283 aFunction = ISS.GetMainShape();
284 if(aFunction.IsNull()) return obj._retn();
285 TDF_Label aLabel = aFunction->GetOwnerEntry();
286 if(aLabel.IsNull()) return obj._retn();
287 TCollection_AsciiString anEntry;
288 TDF_Tool::Entry(aLabel, anEntry);
289 return GEOM::GEOM_Object::_duplicate(_engine->GetObject(_impl->GetDocID(), anEntry.ToCString()));
295 bool GEOM_Object_i::IsShape()
297 return !_impl->GetValue().IsNull() && _impl->GetType() != GEOM_MARKER;