Salome HOME
NRI : First integration.
[modules/geom.git] / src / GEOM / GEOM_Shape_i.cc
1 using namespace std;
2 // File :      GEOM_Shape_i.cc
3 // Created :   
4 // Author :    Lucien PIGNOLONI
5 // Project :   SALOME
6 // Copyright : OPEN CASCADE
7 // $Header$
8
9 #include <BRepTools_ShapeSet.hxx>
10 #include "GEOM_Shape_i.hh"
11 #include "SALOME_NamingService.hxx"
12 #include <fstream.h>
13 #include <BRepTools.hxx>
14
15
16
17 //=================================================================================
18 // function : GEOM_Shape_i() constructor (no arguments)
19 // purpose  : for what now ?
20 //=================================================================================
21 GEOM_Shape_i::GEOM_Shape_i() { }
22
23
24
25 //=================================================================================
26 // function : constructor
27 // purpose  : constructor for servant creation
28 //=================================================================================
29 GEOM_Shape_i::GEOM_Shape_i(TopoDS_Shape geom,
30                            CORBA::ORB_ptr orb,
31                            GEOM::GEOM_Gen_ptr engine,
32                            const GEOM::GEOM_Shape::ListOfSubShapeID& index,
33                            GEOM::shape_type sht,
34                            bool ismain) {
35   _geom = geom;
36   _orb = orb;
37   _engine = engine;
38   _shapetype = sht ;
39   _ismain = ismain;
40   _index = index ;
41
42   _shapeid = "";
43   _studyshapeid = "";
44
45   _name = "";
46   _mainname ="";
47   _nametype ="";
48
49 }
50
51
52
53 //=================================================================================
54 // function : destructor
55 // purpose  : deleting the internal geometry structure
56 //=================================================================================
57 GEOM_Shape_i::~GEOM_Shape_i() { delete &_geom; }
58
59
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) {
66   _name = strdup(name);
67   GEOM::GEOM_Shape_ptr g = GEOM::GEOM_Shape::_narrow(_this());
68
69   // Removed declaration of shapes to naming service
70   //SALOME_NamingService * ns = new SALOME_NamingService(_orb);
71   //ns->Register(g, _name);
72 }
73
74
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); }
80
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);
87 }
88
89
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); }
95
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 ; }
101
102
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 ; }
108
109
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) ; }
115
116
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) ; }
122
123
124
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) ; }
130
131
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) ; }
138
139
140
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);
149
150   for (unsigned int ind = 0; ind < _length; ind++) {
151     _list[ind] = _index[ind];
152   }
153
154   return _list._retn() ; 
155 }
156
157
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 ; }
164
165
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 ; }
171
172
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 ; }
178
179
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) {
185 }
186
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); }
192
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()
199 {
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);
212
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();
216
217 }
218
219 //=======================================================================
220 //function : Engine
221 //purpose  : return generator engine
222 //=======================================================================
223
224 GEOM::GEOM_Gen_ptr GEOM_Shape_i::Engine()
225 {
226   return _engine;
227 }