973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
42cf5bc1 |
14 | |
15 | #include <gp_XYZ.hxx> |
7fd59977 |
16 | #include <IGESBasic_HArray1OfHArray1OfIGESEntity.hxx> |
42cf5bc1 |
17 | #include <IGESBasic_HArray1OfHArray1OfInteger.hxx> |
18 | #include <IGESData_HArray1OfIGESEntity.hxx> |
19 | #include <IGESData_IGESEntity.hxx> |
20 | #include <IGESSolid_EdgeList.hxx> |
21 | #include <IGESSolid_Face.hxx> |
7fd59977 |
22 | #include <IGESSolid_HArray1OfFace.hxx> |
42cf5bc1 |
23 | #include <IGESSolid_HArray1OfLoop.hxx> |
7fd59977 |
24 | #include <IGESSolid_HArray1OfShell.hxx> |
42cf5bc1 |
25 | #include <IGESSolid_HArray1OfVertexList.hxx> |
26 | #include <IGESSolid_Loop.hxx> |
27 | #include <IGESSolid_ManifoldSolid.hxx> |
28 | #include <IGESSolid_Shell.hxx> |
29 | #include <IGESSolid_TopoBuilder.hxx> |
30 | #include <IGESSolid_VertexList.hxx> |
7fd59977 |
31 | #include <Interface_Macros.hxx> |
42cf5bc1 |
32 | #include <Standard_DomainError.hxx> |
33 | #include <TColgp_HArray1OfXYZ.hxx> |
34 | #include <TColStd_HArray1OfInteger.hxx> |
7fd59977 |
35 | |
b311480e |
36 | IGESSolid_TopoBuilder::IGESSolid_TopoBuilder () { Clear(); } |
7fd59977 |
37 | |
38 | void IGESSolid_TopoBuilder::Clear () |
39 | { |
40 | thesolid = new IGESSolid_ManifoldSolid; |
41 | thevoids = new TColStd_HSequenceOfTransient(); |
42 | thevflag = new TColStd_HSequenceOfInteger(); |
43 | theshell = new IGESSolid_Shell; |
44 | thefaces = new TColStd_HSequenceOfTransient(); |
45 | thefflag = new TColStd_HSequenceOfInteger(); |
46 | theface.Nullify(); |
47 | theinner = new TColStd_HSequenceOfTransient(); |
48 | theloop.Nullify(); |
49 | theetype = new TColStd_HSequenceOfInteger(); |
50 | thee3d = new TColStd_HSequenceOfInteger(); |
51 | theeflag = new TColStd_HSequenceOfInteger(); |
52 | theeuv = new TColStd_HSequenceOfTransient(); |
53 | theisol = new TColStd_HSequenceOfInteger(); |
54 | thecuruv = new TColStd_HSequenceOfTransient(); |
55 | theiso = new TColStd_HSequenceOfTransient(); |
56 | theedgel = new IGESSolid_EdgeList; |
57 | thecur3d = new TColStd_HSequenceOfTransient(); |
58 | thevstar = new TColStd_HSequenceOfInteger(); |
59 | thevend = new TColStd_HSequenceOfInteger(); |
60 | thevertl = new IGESSolid_VertexList; |
61 | thepoint = new TColgp_HSequenceOfXYZ(); |
62 | } |
63 | |
64 | void IGESSolid_TopoBuilder::AddVertex (const gp_XYZ& val) |
65 | { thepoint->Append(val); } |
66 | |
67 | Standard_Integer IGESSolid_TopoBuilder::NbVertices () const |
68 | { return thepoint->Length(); } |
69 | |
70 | const gp_XYZ& IGESSolid_TopoBuilder::Vertex |
71 | (const Standard_Integer num) const |
72 | { return thepoint->Value(num); } |
73 | |
74 | Handle(IGESSolid_VertexList) IGESSolid_TopoBuilder::VertexList () const |
75 | { return thevertl; } |
76 | |
77 | |
78 | void IGESSolid_TopoBuilder::AddEdge |
79 | (const Handle(IGESData_IGESEntity)& curve, |
80 | const Standard_Integer vstart, const Standard_Integer vend) |
81 | { |
82 | if (curve.IsNull() || vstart <= 0 || vend <= 0 || |
83 | vstart > thepoint->Length() || vend > thepoint->Length()) |
9775fa61 |
84 | throw Standard_DomainError("IGESSolid_TopoBuilder : AddEdge"); |
7fd59977 |
85 | thecur3d->Append (curve); |
86 | thevstar->Append (vstart); |
87 | thevend->Append (vend); |
88 | } |
89 | |
90 | Standard_Integer IGESSolid_TopoBuilder::NbEdges () const |
91 | { return thecur3d->Length(); } |
92 | |
93 | void IGESSolid_TopoBuilder::Edge |
94 | (const Standard_Integer num, |
95 | Handle(IGESData_IGESEntity)& curve, |
96 | Standard_Integer& vstart, Standard_Integer& vend) const |
97 | { |
98 | if (num <= 0 || num > thecur3d->Length()) return; |
99 | curve = GetCasted(IGESData_IGESEntity,thecur3d->Value(num)); |
100 | vstart = thevstar->Value(num); |
101 | vend = thevend->Value(num); |
102 | } |
103 | |
104 | Handle(IGESSolid_EdgeList) IGESSolid_TopoBuilder::EdgeList () const |
105 | { return theedgel; } |
106 | |
107 | void IGESSolid_TopoBuilder::EndLists () |
108 | { |
109 | Standard_Integer i,nb; |
110 | Handle(TColgp_HArray1OfXYZ) vert; |
111 | Handle(IGESData_HArray1OfIGESEntity) curves; |
112 | Handle(IGESSolid_HArray1OfVertexList) estart, eend; |
113 | Handle(TColStd_HArray1OfInteger) nstart, nend; |
114 | |
115 | nb = thepoint->Length(); |
116 | if (nb > 0) { |
117 | vert = new TColgp_HArray1OfXYZ (1,nb); |
118 | for (i = 1; i <= nb; i ++) vert->SetValue (i, thepoint->Value(i)); |
119 | } |
120 | thevertl->Init (vert); |
121 | |
122 | nb = thecur3d->Length(); |
123 | if (nb > 0) { |
124 | curves = new IGESData_HArray1OfIGESEntity (1,nb); |
125 | nstart = new TColStd_HArray1OfInteger (1,nb); nstart->Init(0); |
126 | nend = new TColStd_HArray1OfInteger (1,nb); nend->Init(0); |
127 | estart = new IGESSolid_HArray1OfVertexList (1,nb); |
128 | eend = new IGESSolid_HArray1OfVertexList (1,nb); |
129 | for (i = 1; i <= nb; i ++) { |
130 | curves->SetValue |
131 | (i,GetCasted(IGESData_IGESEntity,thecur3d->Value(i))); |
132 | nstart->SetValue (i,thevstar->Value(i)); |
133 | nend->SetValue (i,thevend->Value(i)); |
134 | estart->SetValue (i,thevertl); |
135 | estart->SetValue (i,thevertl); |
136 | } |
137 | } |
138 | theedgel->Init (curves,estart,nstart,eend,nend); |
139 | } |
140 | |
141 | void IGESSolid_TopoBuilder::MakeLoop () |
142 | { |
143 | theloop = new IGESSolid_Loop; |
144 | theetype->Clear(); thee3d->Clear(); theeflag->Clear(); |
145 | theeuv->Clear(); theisol->Clear(); |
146 | } |
147 | |
148 | void IGESSolid_TopoBuilder::MakeEdge |
149 | (const Standard_Integer edgetype, const Standard_Integer edge3d, |
150 | const Standard_Integer orientation) |
151 | { |
152 | if (edge3d <= 0 || edge3d > thecur3d->Length()) |
9775fa61 |
153 | throw Standard_DomainError("IGESSolid_TopoBuilder : MakeEdge"); |
7fd59977 |
154 | theetype->Append (edgetype); |
155 | thee3d->Append (edge3d); |
156 | theeflag->Append (orientation); |
157 | thecuruv->Clear(); theisol->Clear(); |
158 | } |
159 | |
160 | void IGESSolid_TopoBuilder::AddCurveUV |
161 | (const Handle(IGESData_IGESEntity)& curve, const Standard_Integer iso) |
162 | { |
163 | if (curve.IsNull() || thee3d->IsEmpty()) |
9775fa61 |
164 | throw Standard_DomainError("IGESSolid_TopoBuilder : AddCurveUV"); |
7fd59977 |
165 | thecuruv->Append(curve); |
166 | theisol->Append(iso); |
167 | } |
168 | |
169 | void IGESSolid_TopoBuilder::EndEdge () |
170 | { |
171 | // transformer thecuruv,theiso en array et le mettre dans theeuv |
172 | Handle(IGESData_HArray1OfIGESEntity) curuv; |
173 | Handle(TColStd_HArray1OfInteger) iso; |
174 | if (!thecuruv->IsEmpty()) { |
175 | Standard_Integer i, nb = thecuruv->Length(); |
176 | curuv = new IGESData_HArray1OfIGESEntity (1,nb); |
177 | iso = new TColStd_HArray1OfInteger (1,nb); iso->Init(0); |
178 | for (i = 1; i <= nb; i ++) { |
179 | curuv->SetValue (i, GetCasted(IGESData_IGESEntity,thecuruv->Value(i))); |
180 | iso->SetValue (i, theisol->Value(i)); |
181 | } |
182 | } |
183 | theeuv->Append(curuv); |
184 | } |
185 | |
186 | void IGESSolid_TopoBuilder::EndLoop () |
187 | { |
188 | Handle(TColStd_HArray1OfInteger) etypes, e3d, eflags, enbuv, eiso; |
189 | Handle(IGESData_HArray1OfIGESEntity) edges, curves; |
190 | Handle(IGESBasic_HArray1OfHArray1OfInteger) isol; |
191 | Handle(IGESBasic_HArray1OfHArray1OfIGESEntity) curvl; |
192 | Standard_Integer i, nb; //szv#4:S4163:12Mar99 nbuv not needed |
193 | nb = thee3d->Length(); |
194 | if (nb > 0) { |
195 | etypes = new TColStd_HArray1OfInteger (1,nb); |
196 | e3d = new TColStd_HArray1OfInteger (1,nb); |
197 | eflags = new TColStd_HArray1OfInteger (1,nb); |
198 | enbuv = new TColStd_HArray1OfInteger (1,nb); |
199 | edges = new IGESData_HArray1OfIGESEntity (1,nb); |
200 | curvl = new IGESBasic_HArray1OfHArray1OfIGESEntity (1,nb); |
201 | isol = new IGESBasic_HArray1OfHArray1OfInteger (1,nb); |
202 | |
203 | for (i = 1; i <= nb; i ++) { |
204 | etypes->SetValue (i, theetype->Value(i)); |
205 | e3d->SetValue (i, thee3d->Value(i)); |
206 | eflags->SetValue (i, theeflag->Value(i)); |
207 | enbuv->SetValue (i,0); |
208 | edges->SetValue (i,theedgel); |
209 | curves = GetCasted(IGESData_HArray1OfIGESEntity,thecuruv->Value(i)); |
210 | if (!curves.IsNull()) { |
211 | //nbuv = curves->Length(); //szv#4:S4163:12Mar99 not needed |
212 | enbuv->SetValue (i,nb); |
213 | curvl->SetValue (i,curves); |
214 | isol->SetValue (i,GetCasted(TColStd_HArray1OfInteger,theiso->Value(i))); |
215 | } |
216 | } |
217 | } |
218 | theloop->Init (etypes,edges,e3d,eflags,enbuv, isol,curvl); |
219 | } |
220 | |
221 | |
222 | void IGESSolid_TopoBuilder::MakeFace |
223 | (const Handle(IGESData_IGESEntity)& surface) |
224 | { |
225 | if (surface.IsNull()) |
9775fa61 |
226 | throw Standard_DomainError("IGESSolid_TopoBuilder : MakeFace"); |
7fd59977 |
227 | thesurf = surface; |
dde68833 |
228 | theouter = Standard_False; |
7fd59977 |
229 | theinner->Clear(); |
230 | theface = new IGESSolid_Face; |
231 | } |
232 | |
233 | void IGESSolid_TopoBuilder::SetOuter () |
234 | { |
235 | EndLoop(); |
dde68833 |
236 | theouter = Standard_True; |
7fd59977 |
237 | theinner->Append (theloop); |
238 | theloop.Nullify(); |
239 | } |
240 | |
241 | void IGESSolid_TopoBuilder::AddInner () |
242 | { |
243 | EndLoop(); |
244 | theinner->Append (theloop); |
245 | theloop.Nullify(); |
246 | } |
247 | |
248 | void IGESSolid_TopoBuilder::EndFace (const Standard_Integer orientation) |
249 | { |
250 | Handle(IGESSolid_HArray1OfLoop) loops; |
251 | Standard_Integer i, nb = theinner->Length(); |
252 | if (nb > 0) { |
253 | loops = new IGESSolid_HArray1OfLoop (1,nb); |
254 | for (i = 1; i <= nb; i ++) loops->SetValue |
255 | (i, GetCasted(IGESSolid_Loop,theinner->Value(i))); |
256 | } |
257 | theface->Init (thesurf,theouter,loops); |
258 | thefaces->Append(theface); |
259 | thefflag->Append(orientation); |
260 | } |
261 | |
262 | |
263 | void IGESSolid_TopoBuilder::MakeShell () |
264 | { |
265 | theshell = new IGESSolid_Shell; |
266 | thefaces->Clear(); |
267 | thefflag->Clear(); |
268 | } |
269 | |
270 | void IGESSolid_TopoBuilder::EndShell () |
271 | { |
272 | Handle(IGESSolid_HArray1OfFace) faces; |
273 | Handle(TColStd_HArray1OfInteger) flags; |
274 | Standard_Integer i, nb = thefaces->Length(); |
275 | if (nb > 0) { |
276 | faces = new IGESSolid_HArray1OfFace ( 1,nb); |
277 | flags = new TColStd_HArray1OfInteger (1,nb); flags->Init(0); |
278 | for (i = 1; i <= nb; i ++) { |
279 | faces->SetValue (i,GetCasted(IGESSolid_Face,thefaces->Value(i))); |
280 | flags->SetValue (i, thefflag->Value(i)); |
281 | } |
282 | } |
283 | theshell->Init (faces,flags); |
284 | } |
285 | |
286 | void IGESSolid_TopoBuilder::EndSimpleShell () |
287 | { EndShell(); EndLists(); } |
288 | |
289 | void IGESSolid_TopoBuilder::SetMainShell |
290 | (const Standard_Integer orientation) |
291 | { |
292 | EndShell(); |
293 | themains = theshell; |
dde68833 |
294 | themflag = orientation != 0; |
7fd59977 |
295 | theshell.Nullify(); |
296 | } |
297 | |
298 | void IGESSolid_TopoBuilder::AddVoidShell |
299 | (const Standard_Integer orientation) |
300 | { |
301 | EndShell(); |
302 | thevoids->Append (theshell); |
303 | thevflag->Append (orientation); |
304 | theshell.Nullify(); |
305 | } |
306 | |
307 | |
308 | void IGESSolid_TopoBuilder::EndSolid () |
309 | { |
310 | EndLists(); |
311 | Handle(IGESSolid_HArray1OfShell) shells; |
312 | Handle(TColStd_HArray1OfInteger) flags; |
313 | Standard_Integer i, nb = thevoids->Length(); |
314 | if (nb > 0) { |
315 | shells = new IGESSolid_HArray1OfShell (1,nb); |
316 | flags = new TColStd_HArray1OfInteger (1,nb); flags->Init(0); |
317 | for (i = 1; i <= nb; i ++) { |
318 | shells->SetValue (i,GetCasted(IGESSolid_Shell,thevoids->Value(i))); |
319 | flags->SetValue (i,thevflag->Value(i)); |
320 | } |
321 | } |
322 | thesolid->Init (themains,themflag, shells,flags); |
323 | } |
324 | |
325 | Handle(IGESSolid_Shell) IGESSolid_TopoBuilder::Shell () const |
326 | { return theshell; } |
327 | |
328 | Handle(IGESSolid_ManifoldSolid) IGESSolid_TopoBuilder::Solid () const |
329 | { return thesolid; } |