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
30 #include <BRepTools_ShapeSet.hxx>
31 #include "GEOM_Shape_i.hh"
32 #include "SALOME_NamingService.hxx"
34 #include <BRepTools.hxx>
38 //=================================================================================
39 // function : GEOM_Shape_i() constructor (no arguments)
40 // purpose : for what now ?
41 //=================================================================================
42 GEOM_Shape_i::GEOM_Shape_i() { }
46 //=================================================================================
47 // function : constructor
48 // purpose : constructor for servant creation
49 //=================================================================================
50 GEOM_Shape_i::GEOM_Shape_i(TopoDS_Shape geom,
52 GEOM::GEOM_Gen_ptr engine,
53 const GEOM::GEOM_Shape::ListOfSubShapeID& index,
74 //=================================================================================
75 // function : destructor
76 // purpose : deleting the internal geometry structure
77 //=================================================================================
78 GEOM_Shape_i::~GEOM_Shape_i() { delete &_geom; }
81 //=================================================================================
82 // function : Name (set method)
83 // purpose : to set the attribute 'name' of this shape.
84 // : WARNING : Register to naming service actually removed !
85 //=================================================================================
86 void GEOM_Shape_i::Name(const char* name) {
88 GEOM::GEOM_Shape_ptr g = GEOM::GEOM_Shape::_narrow(_this());
90 // Removed declaration of shapes to naming service
91 //SALOME_NamingService * ns = new SALOME_NamingService(_orb);
92 //ns->Register(g, _name);
96 //=================================================================================
97 // function : Name (get method)
98 // purpose : to get the attribute 'name' of this shape
99 //=================================================================================
100 char* GEOM_Shape_i::Name() { return strdup(_name); }
102 //=================================================================================
103 // function : MainName (set method)
104 // purpose : to set the attribute 'name' of this mainshape.
105 //=================================================================================
106 void GEOM_Shape_i::MainName(const char* name) {
107 _mainname = strdup(name);
111 //=================================================================================
112 // function : MainName (get method)
113 // purpose : to get the attribute 'name' of this shape
114 //=================================================================================
115 char* GEOM_Shape_i::MainName() { return strdup(_mainname); }
117 //=================================================================================
118 // function : IsMainShape (get method)
119 // purpose : return 'true' if this is a main shape (not a sub shape)
120 //=================================================================================
121 bool GEOM_Shape_i::IsMainShape() { return _ismain ; }
124 //=================================================================================
125 // function : IsMainShape (set method)
126 // purpose : to set the property 'ismain' true or false of this shape
127 //=================================================================================
128 void GEOM_Shape_i::IsMainShape(const bool abool) { _ismain = abool ; }
131 //=================================================================================
132 // function : ShapeId
133 // purpose : to get the id of this shape from GEOM (OCAF entry)
134 //=================================================================================
135 char* GEOM_Shape_i::ShapeId() { return strdup(_shapeid) ; }
138 //=================================================================================
139 // function : ShapeId (set method)
140 // purpose : to set the id of this shape in GEOM/OCAF doc
141 //=================================================================================
142 void GEOM_Shape_i::ShapeId(const char * shapeid) { _shapeid = strdup(shapeid) ; }
146 //=================================================================================
147 // function : StudyShapeId (get method)
148 // purpose : to get the id of this shape from the study document (OCAF entry)
149 //=================================================================================
150 char* GEOM_Shape_i::StudyShapeId() { return strdup(_studyshapeid) ; }
153 //=================================================================================
154 // function : StudyShapeId (set method)
155 // purpose : to set the id of this shape in the Study document (OCAF entry)
156 //=================================================================================
157 void GEOM_Shape_i::StudyShapeId(const char * studyshapeid)
158 { _studyshapeid = strdup(studyshapeid) ; }
162 //=================================================================================
163 // function : Index (get method)
164 // purpose : to get the index of this sub shape in its main shape
165 //=================================================================================
166 GEOM::GEOM_Shape::ListOfSubShapeID* GEOM_Shape_i::Index() {
167 unsigned int _length = _index.length();
168 GEOM::GEOM_Shape::ListOfSubShapeID_var _list = new GEOM::GEOM_Shape::ListOfSubShapeID;
169 _list->length(_length);
171 for (unsigned int ind = 0; ind < _length; ind++) {
172 _list[ind] = _index[ind];
175 return _list._retn() ;
179 //=================================================================================
180 // function : Index (set method)
181 // purpose : to set the index of this sub shape (in a main shape)
182 //=================================================================================
183 void GEOM_Shape_i::Index(const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfSubShapeID)
184 { _index = ListOfSubShapeID ; }
187 //=================================================================================
188 // function : ShapeType (get method)
189 // purpose : to get the topological type of this shape as defined in enum of IDL file
190 //=================================================================================
191 GEOM::shape_type GEOM_Shape_i::ShapeType() { return _shapetype ; }
194 //=================================================================================
195 // function : SetType (set method)
196 // purpose : to set the topological type of this shape (see GetType)
197 //=================================================================================
198 void GEOM_Shape_i::ShapeType(GEOM::shape_type sht) { _shapetype = sht ; }
201 //=================================================================================
202 // function : NameType (set method)
203 // purpose : to set the attribute 'nametype' of this shape.
204 //=================================================================================
205 void GEOM_Shape_i::NameType(const char* name) {
208 //=================================================================================
209 // function : NameType (get method)
210 // purpose : to get the attribute 'nametype' of this shape
211 //=================================================================================
212 char* GEOM_Shape_i::NameType() { return strdup(_nametype); }
214 //=================================================================================
215 // function : GetShapeStream
216 // Transfer resulting shape to client as sequence of bytes
217 //client can extract shape from stream using BrepTools::Read function
218 //=================================================================================
219 GEOM::GEOM_Shape::TMPFile* GEOM_Shape_i::GetShapeStream()
221 ostrstream streamShape;
222 //Write TopoDS_Shape in ASCII format to the stream
223 BRepTools::Write(_geom, streamShape);
224 //Returns the number of bytes that have been stored in the stream's buffer.
225 int size = streamShape.pcount();
226 char* buf = new char [size];
227 //Get pointer on internal character array in ostrstream
228 char* valueOfStream = streamShape.str();
229 //Create copy of ostrstream content
230 memcpy(buf, valueOfStream, size);
231 //Allow automatic deletion of ostrstream content
232 streamShape.rdbuf()->freeze(0);
234 CORBA::Octet* OctetBuf = (CORBA::Octet*)buf;
235 GEOM::GEOM_Shape::TMPFile_var SeqFile = new GEOM::GEOM_Shape::TMPFile(size,size,OctetBuf,1);
236 return SeqFile._retn();
240 //=======================================================================
242 //purpose : return generator engine
243 //=======================================================================
245 GEOM::GEOM_Gen_ptr GEOM_Shape_i::Engine()