1 // GEOM GEOM : implementaion of GEOM_Gen.idl and GEOM_Shape.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOM_Shape_i.cc
25 // Author : Lucien PIGNOLONI
32 #include <BRepTools_ShapeSet.hxx>
33 #include <BRepTools.hxx>
35 #include "GEOM_Shape_i.hh"
36 #include "SALOME_NamingService.hxx"
41 //=================================================================================
42 // function : GEOM_Shape_i() constructor (no arguments)
43 // purpose : for what now ?
44 //=================================================================================
45 GEOM_Shape_i::GEOM_Shape_i() { }
49 //=================================================================================
50 // function : constructor
51 // purpose : constructor for servant creation
52 //=================================================================================
53 GEOM_Shape_i::GEOM_Shape_i(TopoDS_Shape geom,
55 GEOM::GEOM_Gen_ptr engine,
56 const GEOM::GEOM_Shape::ListOfSubShapeID& index,
77 //=================================================================================
78 // function : destructor
79 // purpose : deleting the internal geometry structure
80 //=================================================================================
81 GEOM_Shape_i::~GEOM_Shape_i() { delete &_geom; }
84 //=================================================================================
85 // function : Name (set method)
86 // purpose : to set the attribute 'name' of this shape.
87 // : WARNING : Register to naming service actually removed !
88 //=================================================================================
89 void GEOM_Shape_i::Name(const char* name) {
90 _name = CORBA::string_dup(name);
91 GEOM::GEOM_Shape_ptr g = GEOM::GEOM_Shape::_narrow(_this());
93 // Removed declaration of shapes to naming service
94 //SALOME_NamingService * ns = new SALOME_NamingService(_orb);
95 //ns->Register(g, _name);
99 //=================================================================================
100 // function : Name (get method)
101 // purpose : to get the attribute 'name' of this shape
102 //=================================================================================
103 char* GEOM_Shape_i::Name() { return CORBA::string_dup(_name); }
105 //=================================================================================
106 // function : MainName (set method)
107 // purpose : to set the attribute 'name' of this mainshape.
108 //=================================================================================
109 void GEOM_Shape_i::MainName(const char* name) {
110 _mainname = CORBA::string_dup(name);
114 //=================================================================================
115 // function : MainName (get method)
116 // purpose : to get the attribute 'name' of this shape
117 //=================================================================================
118 char* GEOM_Shape_i::MainName() { return CORBA::string_dup(_mainname); }
120 //=================================================================================
121 // function : IsMainShape (get method)
122 // purpose : return 'true' if this is a main shape (not a sub shape)
123 //=================================================================================
124 bool GEOM_Shape_i::IsMainShape() { return _ismain ; }
127 //=================================================================================
128 // function : IsMainShape (set method)
129 // purpose : to set the property 'ismain' true or false of this shape
130 //=================================================================================
131 void GEOM_Shape_i::IsMainShape(const bool abool) { _ismain = abool ; }
134 //=================================================================================
135 // function : ShapeId
136 // purpose : to get the id of this shape from GEOM (OCAF entry)
137 //=================================================================================
138 char* GEOM_Shape_i::ShapeId() { return CORBA::string_dup(_shapeid) ; }
141 //=================================================================================
142 // function : ShapeId (set method)
143 // purpose : to set the id of this shape in GEOM/OCAF doc
144 //=================================================================================
145 void GEOM_Shape_i::ShapeId(const char * shapeid) { _shapeid = CORBA::string_dup(shapeid) ; }
149 //=================================================================================
150 // function : StudyShapeId (get method)
151 // purpose : to get the id of this shape from the study document (OCAF entry)
152 //=================================================================================
153 char* GEOM_Shape_i::StudyShapeId() { return CORBA::string_dup(_studyshapeid) ; }
156 //=================================================================================
157 // function : StudyShapeId (set method)
158 // purpose : to set the id of this shape in the Study document (OCAF entry)
159 //=================================================================================
160 void GEOM_Shape_i::StudyShapeId(const char * studyshapeid)
161 { _studyshapeid = CORBA::string_dup(studyshapeid) ; }
165 //=================================================================================
166 // function : Index (get method)
167 // purpose : to get the index of this sub shape in its main shape
168 //=================================================================================
169 GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Shape_i::Index() {
170 unsigned int _length = _index.length();
171 GEOM::GEOM_Shape::ListOfSubShapeID_var _list = new GEOM::GEOM_Shape::ListOfSubShapeID;
172 _list->length(_length);
174 for (unsigned int ind = 0; ind < _length; ind++) {
175 _list[ind] = _index[ind];
178 return _list._retn() ;
182 //=================================================================================
183 // function : Index (set method)
184 // purpose : to set the index of this sub shape (in a main shape)
185 //=================================================================================
186 void GEOM_Shape_i::Index(const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSubShapeID)
187 { _index = ListOfSubShapeID ; }
190 //=================================================================================
191 // function : ShapeType (get method)
192 // purpose : to get the topological type of this shape as defined in enum of IDL file
193 //=================================================================================
194 GEOM::shape_type GEOM_Shape_i::ShapeType() { return _shapetype ; }
197 //=================================================================================
198 // function : SetType (set method)
199 // purpose : to set the topological type of this shape (see GetType)
200 //=================================================================================
201 void GEOM_Shape_i::ShapeType(GEOM::shape_type sht) { _shapetype = sht ; }
204 //=================================================================================
205 // function : NameType (set method)
206 // purpose : to set the attribute 'nametype' of this shape.
207 //=================================================================================
208 void GEOM_Shape_i::NameType(const char* name) {
211 //=================================================================================
212 // function : NameType (get method)
213 // purpose : to get the attribute 'nametype' of this shape
214 //=================================================================================
215 char* GEOM_Shape_i::NameType() { return CORBA::string_dup(_nametype); }
217 //=================================================================================
218 // function : GetShapeStream
219 // Transfer resulting shape to client as sequence of bytes
220 //client can extract shape from stream using BrepTools::Read function
221 //=================================================================================
222 GEOM::GEOM_Shape::TMPFile* GEOM_Shape_i::GetShapeStream()
224 ostrstream streamShape;
225 //Write TopoDS_Shape in ASCII format to the stream
226 BRepTools::Write(_geom, streamShape);
227 //Returns the number of bytes that have been stored in the stream's buffer.
228 int size = streamShape.pcount();
229 char* buf = new char [size];
230 //Get pointer on internal character array in ostrstream
231 char* valueOfStream = streamShape.str();
232 //Create copy of ostrstream content
233 memcpy(buf, valueOfStream, size);
234 //Allow automatic deletion of ostrstream content
235 streamShape.rdbuf()->freeze(0);
237 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
238 GEOM::GEOM_Shape::TMPFile_var SeqFile = new GEOM::GEOM_Shape::TMPFile(size,size,OctetBuf,1);
239 return SeqFile._retn();
243 //=======================================================================
245 //purpose : return generator engine
246 //=======================================================================
248 GEOM::GEOM_Gen_ptr GEOM_Shape_i::Engine()
253 //=======================================================================
254 //function : getShape
255 //purpose : return the TopoDS_Shape when client and servant are colocated, be careful
256 //=======================================================================
258 long GEOM_Shape_i::getShape() {
259 return((long)(&_geom));