2 // File : GEOM_Shape_i.cc
4 // Author : Lucien PIGNOLONI
6 // Copyright : OPEN CASCADE
9 #include <BRepTools_ShapeSet.hxx>
10 #include "GEOM_Shape_i.hh"
11 #include "SALOME_NamingService.hxx"
13 #include <BRepTools.hxx>
17 //=================================================================================
18 // function : GEOM_Shape_i() constructor (no arguments)
19 // purpose : for what now ?
20 //=================================================================================
21 GEOM_Shape_i::GEOM_Shape_i() { }
25 //=================================================================================
26 // function : constructor
27 // purpose : constructor for servant creation
28 //=================================================================================
29 GEOM_Shape_i::GEOM_Shape_i(TopoDS_Shape geom,
31 GEOM::GEOM_Gen_ptr engine,
32 const GEOM::GEOM_Shape::ListOfSubShapeID& index,
53 //=================================================================================
54 // function : destructor
55 // purpose : deleting the internal geometry structure
56 //=================================================================================
57 GEOM_Shape_i::~GEOM_Shape_i() { delete &_geom; }
60 //=================================================================================
61 // function : Name (set method)
62 // purpose : to set the attribute 'name' of this shape.
63 // : WARNING : Register to naming service actually removed !
64 //=================================================================================
65 void GEOM_Shape_i::Name(const char* name) {
67 GEOM::GEOM_Shape_ptr g = GEOM::GEOM_Shape::_narrow(_this());
69 // Removed declaration of shapes to naming service
70 //SALOME_NamingService * ns = new SALOME_NamingService(_orb);
71 //ns->Register(g, _name);
75 //=================================================================================
76 // function : Name (get method)
77 // purpose : to get the attribute 'name' of this shape
78 //=================================================================================
79 char* GEOM_Shape_i::Name() { return strdup(_name); }
81 //=================================================================================
82 // function : MainName (set method)
83 // purpose : to set the attribute 'name' of this mainshape.
84 //=================================================================================
85 void GEOM_Shape_i::MainName(const char* name) {
86 _mainname = strdup(name);
90 //=================================================================================
91 // function : MainName (get method)
92 // purpose : to get the attribute 'name' of this shape
93 //=================================================================================
94 char* GEOM_Shape_i::MainName() { return strdup(_mainname); }
96 //=================================================================================
97 // function : IsMainShape (get method)
98 // purpose : return 'true' if this is a main shape (not a sub shape)
99 //=================================================================================
100 bool GEOM_Shape_i::IsMainShape() { return _ismain ; }
103 //=================================================================================
104 // function : IsMainShape (set method)
105 // purpose : to set the property 'ismain' true or false of this shape
106 //=================================================================================
107 void GEOM_Shape_i::IsMainShape(const bool abool) { _ismain = abool ; }
110 //=================================================================================
111 // function : ShapeId
112 // purpose : to get the id of this shape from GEOM (OCAF entry)
113 //=================================================================================
114 char* GEOM_Shape_i::ShapeId() { return strdup(_shapeid) ; }
117 //=================================================================================
118 // function : ShapeId (set method)
119 // purpose : to set the id of this shape in GEOM/OCAF doc
120 //=================================================================================
121 void GEOM_Shape_i::ShapeId(const char * shapeid) { _shapeid = strdup(shapeid) ; }
125 //=================================================================================
126 // function : StudyShapeId (get method)
127 // purpose : to get the id of this shape from the study document (OCAF entry)
128 //=================================================================================
129 char* GEOM_Shape_i::StudyShapeId() { return strdup(_studyshapeid) ; }
132 //=================================================================================
133 // function : StudyShapeId (set method)
134 // purpose : to set the id of this shape in the Study document (OCAF entry)
135 //=================================================================================
136 void GEOM_Shape_i::StudyShapeId(const char * studyshapeid)
137 { _studyshapeid = strdup(studyshapeid) ; }
141 //=================================================================================
142 // function : Index (get method)
143 // purpose : to get the index of this sub shape in its main shape
144 //=================================================================================
145 GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Shape_i::Index() {
146 unsigned int _length = _index.length();
147 GEOM::GEOM_Shape::ListOfSubShapeID_var _list = new GEOM::GEOM_Shape::ListOfSubShapeID;
148 _list->length(_length);
150 for (unsigned int ind = 0; ind < _length; ind++) {
151 _list[ind] = _index[ind];
154 return _list._retn() ;
158 //=================================================================================
159 // function : Index (set method)
160 // purpose : to set the index of this sub shape (in a main shape)
161 //=================================================================================
162 void GEOM_Shape_i::Index(const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSubShapeID)
163 { _index = ListOfSubShapeID ; }
166 //=================================================================================
167 // function : ShapeType (get method)
168 // purpose : to get the topological type of this shape as defined in enum of IDL file
169 //=================================================================================
170 GEOM::shape_type GEOM_Shape_i::ShapeType() { return _shapetype ; }
173 //=================================================================================
174 // function : SetType (set method)
175 // purpose : to set the topological type of this shape (see GetType)
176 //=================================================================================
177 void GEOM_Shape_i::ShapeType(GEOM::shape_type sht) { _shapetype = sht ; }
180 //=================================================================================
181 // function : NameType (set method)
182 // purpose : to set the attribute 'nametype' of this shape.
183 //=================================================================================
184 void GEOM_Shape_i::NameType(const char* name) {
187 //=================================================================================
188 // function : NameType (get method)
189 // purpose : to get the attribute 'nametype' of this shape
190 //=================================================================================
191 char* GEOM_Shape_i::NameType() { return strdup(_nametype); }
193 //=================================================================================
194 // function : GetShapeStream
195 // Transfer resulting shape to client as sequence of bytes
196 //client can extract shape from stream using BrepTools::Read function
197 //=================================================================================
198 GEOM::GEOM_Shape::TMPFile* GEOM_Shape_i::GetShapeStream()
200 ostrstream streamShape;
201 //Write TopoDS_Shape in ASCII format to the stream
202 BRepTools::Write(_geom, streamShape);
203 //Returns the number of bytes that have been stored in the stream's buffer.
204 int size = streamShape.pcount();
205 char* buf = new char [size];
206 //Get pointer on internal character array in ostrstream
207 char* valueOfStream = streamShape.str();
208 //Create copy of ostrstream content
209 memcpy(buf, valueOfStream, size);
210 //Allow automatic deletion of ostrstream content
211 streamShape.rdbuf()->freeze(0);
213 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
214 GEOM::GEOM_Shape::TMPFile_var SeqFile = new GEOM::GEOM_Shape::TMPFile(size,size,OctetBuf,1);
215 return SeqFile._retn();
219 //=======================================================================
221 //purpose : return generator engine
222 //=======================================================================
224 GEOM::GEOM_Gen_ptr GEOM_Shape_i::Engine()