0024624: Lost word in license statement in source files
[occt.git] / src / BRepToIGES / BRepToIGES_BRSolid.cxx
1 // Created on: 1995-01-30
2 // Created by: Marie Jose MARTZ
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepToIGES_BRSolid.ixx>
18 #include <BRepToIGES_BRShell.hxx>
19 #include <BRepToIGES_BRWire.hxx>
20
21 #include <BRep_Tool.hxx>
22 #include <BRepTools.hxx>
23
24 #include <IGESBasic_Group.hxx>
25 #include <IGESData_HArray1OfIGESEntity.hxx>
26 #include <IGESData_IGESEntity.hxx>
27
28 #include <Interface_Macros.hxx>
29
30 #include <TColStd_HSequenceOfTransient.hxx>
31
32
33 #include <TopoDS.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_CompSolid.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopoDS_Shell.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Wire.hxx>
43
44 #include <TopAbs_ShapeEnum.hxx>
45 #include <TopExp.hxx>
46 #include <TopExp_Explorer.hxx>
47
48
49 // At first only the geometry is translated (point, curve...)
50
51 //=============================================================================
52 // BRepToIGES_BRSolid
53 //=============================================================================
54
55 BRepToIGES_BRSolid::BRepToIGES_BRSolid()
56 {
57 }
58
59
60 //=============================================================================
61 // BRepToIGES_BRSolid
62 //=============================================================================
63
64 BRepToIGES_BRSolid::BRepToIGES_BRSolid
65 (const BRepToIGES_BREntity& BR)
66 : BRepToIGES_BREntity(BR)
67 {
68 }
69
70
71 //=============================================================================
72 // TransferSolid
73 //=============================================================================
74
75 Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferSolid(const TopoDS_Shape& start)
76 {
77   Handle(IGESData_IGESEntity) res;
78
79   if (start.IsNull())  return  res;
80
81   if (start.ShapeType() == TopAbs_SOLID) {
82     TopoDS_Solid M =  TopoDS::Solid(start);
83     res = TransferSolid(M);
84   }  
85   else if (start.ShapeType() == TopAbs_COMPSOLID) {
86     TopoDS_CompSolid C =  TopoDS::CompSolid(start);
87     res = TransferCompSolid(C);
88   }  
89   else if (start.ShapeType() == TopAbs_COMPOUND) {
90     TopoDS_Compound C =  TopoDS::Compound(start);
91     res = TransferCompound(C);
92   }  
93   else {
94     // error message
95   }  
96   return res;
97 }
98
99
100 //=============================================================================
101 // TransferSolid
102 // 
103 //=============================================================================
104
105 Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferSolid(const TopoDS_Solid& start)
106 {
107   Handle(IGESData_IGESEntity) res;
108   if ( start.IsNull()) return res;
109
110   TopExp_Explorer Ex;
111   Handle(IGESData_IGESEntity) IShell;
112   BRepToIGES_BRShell BS(*this);
113   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
114
115   for (Ex.Init(start,TopAbs_SHELL); Ex.More(); Ex.Next()) {
116     TopoDS_Shell S = TopoDS::Shell(Ex.Current());
117     if (S.IsNull()) {
118       AddWarning(start," an Shell is a null entity");
119     }
120     else {
121       IShell = BS.TransferShell(S);
122       if (!IShell.IsNull()) Seq->Append(IShell);
123     }
124   }
125
126
127   Standard_Integer nbshells = Seq->Length();
128   Handle(IGESData_HArray1OfIGESEntity) Tab;
129   if ( nbshells >= 1) {
130     Tab =  new IGESData_HArray1OfIGESEntity(1,nbshells);
131     for (Standard_Integer itab = 1; itab <= nbshells; itab++) {
132       Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
133       Tab->SetValue(itab,item);
134     }
135   }
136
137   if (nbshells == 1) {
138     res = IShell;
139   }
140   else {
141     Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
142     IGroup->Init(Tab);
143     res = IGroup;
144   }
145
146   SetShapeResult ( start, res );
147
148   return res;
149 }
150
151
152 //=============================================================================
153 // TransferCompSolid
154 //=============================================================================
155
156 Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferCompSolid(const TopoDS_CompSolid& start)
157 {
158   Handle(IGESData_IGESEntity) res;
159   if ( start.IsNull()) return res;
160
161   TopExp_Explorer Ex;
162   Handle(IGESData_IGESEntity) ISolid;
163   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
164
165   for (Ex.Init(start,TopAbs_SOLID); Ex.More(); Ex.Next()) {
166     TopoDS_Solid S = TopoDS::Solid(Ex.Current());
167     if (S.IsNull()) {
168       AddWarning(start," an Solid is a null entity");
169     }
170     else {
171       ISolid = TransferSolid(S);
172       if (!ISolid.IsNull()) Seq->Append(ISolid);
173     }
174   }
175
176
177   Standard_Integer nbsolids = Seq->Length();
178   Handle(IGESData_HArray1OfIGESEntity) Tab;
179   if ( nbsolids >= 1) {
180     Tab =  new IGESData_HArray1OfIGESEntity(1,nbsolids);
181     for (Standard_Integer itab = 1; itab <= nbsolids; itab++) {
182       Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
183       Tab->SetValue(itab,item);
184     }
185   }
186
187   if (nbsolids == 1) {
188     res = ISolid;
189   }
190   else {
191     Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
192     IGroup->Init(Tab);
193     res = IGroup;
194   }
195
196   SetShapeResult ( start, res );
197
198   return res;
199 }
200
201
202 //=============================================================================
203 // TransferCompound
204 //=============================================================================
205
206 Handle(IGESData_IGESEntity) BRepToIGES_BRSolid ::TransferCompound(const TopoDS_Compound& start)
207 {
208   Handle(IGESData_IGESEntity) res;
209   if ( start.IsNull()) return res;
210
211
212   TopExp_Explorer Ex;
213   Handle(IGESData_IGESEntity) IShape;
214   BRepToIGES_BRShell BS(*this);
215   BRepToIGES_BRWire BW(*this);
216   Handle(TColStd_HSequenceOfTransient) Seq = new TColStd_HSequenceOfTransient();
217
218   // take all Solids
219   for (Ex.Init(start, TopAbs_SOLID); Ex.More(); Ex.Next()) {
220     TopoDS_Solid S = TopoDS::Solid(Ex.Current());
221     if (S.IsNull()) {
222       AddWarning(start," a Solid is a null entity");
223     }
224     else {
225       IShape = TransferSolid(S);
226       if (!IShape.IsNull()) Seq->Append(IShape);
227     }
228   }
229
230   // take all isolated Shells 
231   for (Ex.Init(start, TopAbs_SHELL, TopAbs_SOLID); Ex.More(); Ex.Next()) {
232     TopoDS_Shell S = TopoDS::Shell(Ex.Current());
233     if (S.IsNull()) {
234       AddWarning(start," a Shell is a null entity");
235     }
236     else {
237       IShape = BS.TransferShell(S);
238       if (!IShape.IsNull()) Seq->Append(IShape);
239     }
240   }
241
242
243   // take all isolated Faces 
244   for (Ex.Init(start, TopAbs_FACE, TopAbs_SHELL); Ex.More(); Ex.Next()) {
245     TopoDS_Face S = TopoDS::Face(Ex.Current());
246     if (S.IsNull()) {
247       AddWarning(start," a Face is a null entity");
248     }
249     else {
250       IShape = BS.TransferFace(S);
251       if (!IShape.IsNull()) Seq->Append(IShape);
252     }
253   }
254
255
256   // take all isolated Wires 
257   for (Ex.Init(start, TopAbs_WIRE, TopAbs_FACE); Ex.More(); Ex.Next()) {
258     TopoDS_Wire S = TopoDS::Wire(Ex.Current());
259     if (S.IsNull()) {
260       AddWarning(start," a Wire is a null entity");
261     }
262     else {
263       IShape = BW.TransferWire(S);
264       if (!IShape.IsNull()) Seq->Append(IShape);
265     }
266   }
267
268
269   // take all isolated Edges 
270   for (Ex.Init(start, TopAbs_EDGE, TopAbs_WIRE); Ex.More(); Ex.Next()) {
271     TopoDS_Edge S = TopoDS::Edge(Ex.Current());
272     if (S.IsNull()) {
273       AddWarning(start," an Edge is a null entity");
274     }
275     else {
276       IShape = BW.TransferEdge(S, Standard_False);
277       if (!IShape.IsNull()) Seq->Append(IShape);
278     }
279   }
280
281
282   // take all isolated Vertices 
283   for (Ex.Init(start, TopAbs_VERTEX, TopAbs_EDGE); Ex.More(); Ex.Next()) {
284     TopoDS_Vertex S = TopoDS::Vertex(Ex.Current());
285     if (S.IsNull()) {
286       AddWarning(start," a Vertex is a null entity");
287     }
288     else {
289       IShape = BW.TransferVertex(S);
290       if (!IShape.IsNull()) Seq->Append(IShape);
291     }
292   }
293
294   // construct the group
295   Standard_Integer nbshapes = Seq->Length();
296   Handle(IGESData_HArray1OfIGESEntity) Tab;
297   if (nbshapes >=1) {
298     Tab =  new IGESData_HArray1OfIGESEntity(1,nbshapes);
299     for (Standard_Integer itab = 1; itab <= nbshapes; itab++) {
300       Handle(IGESData_IGESEntity) item = GetCasted(IGESData_IGESEntity, Seq->Value(itab));
301       Tab->SetValue(itab,item);
302     }
303   }
304
305   if (nbshapes == 1) {
306     res = IShape;
307   }
308   else {
309     Handle(IGESBasic_Group) IGroup = new IGESBasic_Group;
310     IGroup->Init(Tab);
311     res = IGroup;
312   }
313
314   SetShapeResult ( start, res );
315
316   return res;
317 }