b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | #include <Standard_ErrorHandler.hxx> |
20 | #include <Graphic3d_Group.hxx> |
21 | #include <Prs3d_IsoAspect.hxx> |
22 | #include <Prs3d_PointAspect.hxx> |
23 | #include <Bnd_Box.hxx> |
24 | #include <gp_Pnt.hxx> |
25 | #include <Poly_Triangulation.hxx> |
26 | #include <TColgp_Array1OfPnt.hxx> |
27 | #include <Poly_Array1OfTriangle.hxx> |
28 | #include <Graphic3d_Array1OfVertex.hxx> |
29 | #include <Poly_Polygon3D.hxx> |
30 | #include <Poly_PolygonOnTriangulation.hxx> |
31 | #include <TColStd_HArray1OfInteger.hxx> |
32 | #include <Prs3d_ShapeTool.hxx> |
33 | #include <BRepAdaptor_HSurface.hxx> |
34 | #include <BRepAdaptor_Curve.hxx> |
35 | #include <Graphic3d_AspectLine3d.hxx> |
7fd59977 |
36 | #include <Graphic3d_ArrayOfPolylines.hxx> |
37 | #include <Poly_Connect.hxx> |
38 | |
39 | #include <BRepBndLib.hxx> |
40 | #include <Precision.hxx> |
41 | #include <GCPnts_TangentialDeflection.hxx> |
42 | #include <GCPnts_UniformDeflection.hxx> |
43 | #include <gp_Circ.hxx> |
44 | #include <TColStd_Array1OfReal.hxx> |
45 | #include <TColgp_Array1OfPnt.hxx> |
46 | #include <BRep_Builder.hxx> |
47 | #include <BRep_Tool.hxx> |
48 | #include <TopTools_ListOfShape.hxx> |
49 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
50 | #include <TopoDS_Edge.hxx> |
51 | #include <TopoDS_Vertex.hxx> |
52 | #include <TopoDS.hxx> |
53 | |
54 | #include <Prs3d_NListOfSequenceOfPnt.hxx> |
55 | #include <Prs3d_NListIteratorOfListOfSequenceOfPnt.hxx> |
56 | |
7fd59977 |
57 | static Standard_Boolean IsSame(const Handle(Graphic3d_AspectLine3d)& UAspect, |
58 | const Handle(Graphic3d_AspectLine3d)& VAspect) |
59 | { |
60 | Standard_Boolean same = Standard_True; |
61 | |
62 | Quantity_Color CU, CV; |
63 | Aspect_TypeOfLine TlU, TlV; |
64 | Standard_Real WU, WV; |
65 | |
66 | UAspect->Values(CU, TlU, WU); |
67 | VAspect->Values(CV, TlV, WV); |
68 | |
69 | if (CU != CV || TlU != TlV || WU != WV) { |
70 | same = Standard_False; |
71 | } |
72 | |
73 | return same; |
74 | } |
75 | |
76 | |
77 | static Standard_Boolean AddPolygon(const TopoDS_Edge& E, |
b8ddfc2f |
78 | Handle(Graphic3d_Group)& TheGroup, |
79 | const Standard_Real deflection, |
80 | const Handle (Prs3d_Drawer)& , |
81 | TColgp_SequenceOfPnt& Pnts) |
7fd59977 |
82 | { |
83 | TopLoc_Location l; |
7fd59977 |
84 | Standard_Real fi, la; |
7fd59977 |
85 | Handle(Geom_Curve) CC3d = BRep_Tool::Curve(E, fi, la); |
b8ddfc2f |
86 | Handle(Poly_Polygon3D) Polyg = BRep_Tool::Polygon3D(E, l); |
7fd59977 |
87 | |
b8ddfc2f |
88 | if (!Polyg.IsNull()) { |
89 | if ((Polyg->Deflection() <= deflection) || CC3d.IsNull()) { |
7fd59977 |
90 | const TColgp_Array1OfPnt& Points = Polyg->Nodes(); |
b8ddfc2f |
91 | Standard_Integer po = Points.Lower(); |
7fd59977 |
92 | if (l.IsIdentity()) { |
b8ddfc2f |
93 | for (; po <= Points.Upper(); po++) |
94 | Pnts.Append(Points.Value(po)); |
7fd59977 |
95 | } |
96 | else { |
b8ddfc2f |
97 | for (; po <= Points.Upper(); po++) |
98 | Pnts.Append(Points.Value(po).Transformed(l)); |
7fd59977 |
99 | } |
b8ddfc2f |
100 | return Standard_True; |
7fd59977 |
101 | } |
102 | } |
103 | |
104 | Handle(Poly_Triangulation) Tr; |
105 | Handle(Poly_PolygonOnTriangulation) HIndices; |
106 | BRep_Tool::PolygonOnTriangulation(E, HIndices, Tr, l); |
107 | if (!HIndices.IsNull()) { |
b8ddfc2f |
108 | if ((HIndices->Deflection() <= deflection) || CC3d.IsNull()) { |
7fd59977 |
109 | const TColStd_Array1OfInteger& Indices = HIndices->Nodes(); |
110 | const TColgp_Array1OfPnt& Nodes = Tr->Nodes(); |
7fd59977 |
111 | |
b8ddfc2f |
112 | Standard_Integer po = Indices.Lower(); |
7fd59977 |
113 | if (l.IsIdentity()) { |
b8ddfc2f |
114 | for (; po <= Indices.Upper(); po++) |
115 | Pnts.Append(Nodes(Indices(po))); |
7fd59977 |
116 | } |
117 | else { |
b8ddfc2f |
118 | for (; po <= Indices.Upper(); po++) |
119 | Pnts.Append(Nodes(Indices(po)).Transformed(l)); |
7fd59977 |
120 | } |
b8ddfc2f |
121 | return Standard_True; |
7fd59977 |
122 | } |
123 | } |
b8ddfc2f |
124 | return Standard_False; |
7fd59977 |
125 | } |
126 | |
127 | |
7fd59977 |
128 | //========================================================================= |
129 | // function: Add |
130 | // purpose |
131 | //========================================================================= |
132 | void Prs3d_WFShape::Add(const Handle (Prs3d_Presentation)& aPresentation, |
133 | const TopoDS_Shape& aShape, |
134 | const Handle (Prs3d_Drawer)& aDrawer) |
135 | { |
136 | if (aShape.IsNull()) return; |
137 | |
7fd59977 |
138 | Prs3d_ShapeTool Tool(aShape); |
139 | TopTools_ListOfShape LFree, LUnFree, LWire; |
140 | for (Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()) |
141 | { |
142 | const TopoDS_Edge& E = Tool.GetCurve(); |
143 | switch (Tool.Neighbours()) |
144 | { |
145 | case 0: LWire.Append(E); break; |
146 | case 1: LFree.Append(E); break; |
147 | default: LUnFree.Append(E); |
148 | } |
149 | } |
7fd59977 |
150 | |
151 | Standard_Real aDeflection; |
152 | if (aDrawer->TypeOfDeflection() == Aspect_TOD_RELATIVE) |
153 | { |
154 | // On calcule la fleche en fonction des min max globaux de la piece: |
155 | Bnd_Box B; |
156 | BRepBndLib::Add(aShape, B); |
157 | if ( ! B.IsVoid() ) |
158 | { |
159 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; |
160 | B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
161 | aDeflection = Max (aXmax-aXmin, Max (aYmax-aYmin, aZmax-aZmin)) * |
162 | aDrawer->DeviationCoefficient(); |
163 | } |
164 | else |
165 | aDeflection = aDrawer->MaximalChordialDeviation(); |
166 | } |
167 | else |
168 | aDeflection = aDrawer->MaximalChordialDeviation(); |
169 | |
7fd59977 |
170 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); |
171 | |
172 | Prs3d_NListOfSequenceOfPnt UIsoCurves; |
173 | Prs3d_NListOfSequenceOfPnt VIsoCurves; |
174 | Prs3d_NListOfSequenceOfPnt WireCurves; |
175 | Prs3d_NListOfSequenceOfPnt FreeCurves; |
176 | Prs3d_NListOfSequenceOfPnt UnFreeCurves; |
177 | TColgp_SequenceOfPnt ShapePoints; |
178 | |
179 | if (IsSame(aDrawer->UIsoAspect()->Aspect(), aDrawer->VIsoAspect()->Aspect())) |
180 | { |
181 | const Standard_Integer isoU = aDrawer->UIsoAspect()->Number(); |
182 | const Standard_Integer isoV = aDrawer->VIsoAspect()->Number(); |
7fd59977 |
183 | if (isoU || isoV) |
184 | { |
7fd59977 |
185 | BRepAdaptor_Surface S; |
186 | for (Tool.InitFace();Tool.MoreFace();Tool.NextFace()) |
187 | { |
188 | if (Tool.HasSurface()) |
189 | { |
190 | if (!Tool.IsPlanarFace() || aDrawer->IsoOnPlane()) |
191 | { |
192 | S.Initialize(Tool.GetFace()); |
193 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
194 | try { |
195 | OCC_CATCH_SIGNALS |
196 | Prs3d_NListOfSequenceOfPnt CurUIsoCurves; |
197 | FacePresentation::Add(aPresentation, HS, |
198 | isoU, isoV, |
199 | aDeflection, |
200 | isoU, isoV, |
201 | aDrawer, |
202 | CurUIsoCurves); |
203 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
204 | for( It.Init(CurUIsoCurves); It.More(); It.Next()) |
205 | UIsoCurves.Append(It.Value()); |
206 | } |
207 | catch (Standard_Failure) |
208 | { |
7fd59977 |
209 | } |
210 | } |
211 | } |
212 | } |
7fd59977 |
213 | } |
7fd59977 |
214 | } |
215 | else |
216 | { |
217 | const Standard_Integer isoU = aDrawer->UIsoAspect()->Number(); |
218 | const Standard_Integer isoV = aDrawer->VIsoAspect()->Number(); |
7fd59977 |
219 | if (isoU) |
220 | { |
7fd59977 |
221 | BRepAdaptor_Surface S; |
222 | for (Tool.InitFace();Tool.MoreFace();Tool.NextFace()) |
223 | { |
224 | if (Tool.HasSurface()) |
225 | { |
226 | if (!Tool.IsPlanarFace() || aDrawer->IsoOnPlane()) |
227 | { |
228 | S.Initialize(Tool.GetFace()); |
229 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
230 | try |
231 | { |
232 | OCC_CATCH_SIGNALS |
233 | Prs3d_NListOfSequenceOfPnt CurUIsoCurves; |
234 | FacePresentation::Add(aPresentation, HS, |
235 | isoU, Standard_False, |
236 | aDeflection, |
237 | isoU, 0, |
238 | aDrawer, |
239 | CurUIsoCurves); |
240 | } |
241 | catch (Standard_Failure) |
242 | { |
243 | #ifdef DEB |
244 | const TopoDS_Face& FF = S.Face(); |
245 | cout <<"probleme pour les isos de la face "<< (void*) &(*(FF).TShape()) << endl; |
246 | #endif |
247 | } |
248 | } |
249 | } |
250 | } |
7fd59977 |
251 | } |
7fd59977 |
252 | if (isoV) |
253 | { |
7fd59977 |
254 | BRepAdaptor_Surface S; |
255 | for (Tool.InitFace();Tool.MoreFace();Tool.NextFace()) |
256 | { |
257 | if (Tool.HasSurface()) |
258 | { |
259 | if (!Tool.IsPlanarFace() || aDrawer->IsoOnPlane()) |
260 | { |
261 | S.Initialize(Tool.GetFace()); |
262 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
263 | try |
264 | { |
265 | OCC_CATCH_SIGNALS |
266 | Prs3d_NListOfSequenceOfPnt CurUIsoCurves; |
267 | FacePresentation::Add(aPresentation, HS, |
268 | Standard_False, isoV, |
269 | aDeflection, |
270 | 0, isoV, |
271 | aDrawer, |
272 | CurUIsoCurves); |
273 | } |
274 | catch (Standard_Failure) |
275 | { |
276 | #ifdef DEB |
277 | const TopoDS_Face& FF = S.Face(); |
278 | cout <<"probleme pour les isos de la face "<< (void*) &(*(FF).TShape()) << endl; |
279 | #endif |
280 | } |
281 | } |
282 | } |
283 | } |
7fd59977 |
284 | } |
7fd59977 |
285 | } |
286 | Standard_Integer nbVertices = 0, nbBounds = 0; |
287 | |
b8ddfc2f |
288 | if(UIsoCurves.Size() > 0) { |
289 | nbBounds = UIsoCurves.Size(); |
290 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
291 | for( It.Init(UIsoCurves); It.More(); It.Next()) |
292 | nbVertices += It.Value().Length(); |
293 | Handle(Graphic3d_ArrayOfPolylines) UIsoArray = |
294 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
295 | for( It.Init(UIsoCurves); It.More(); It.Next()) { |
296 | TColgp_SequenceOfPnt Pnts; |
297 | Pnts.Assign(It.Value()); |
298 | UIsoArray->AddBound(Pnts.Length()); |
299 | for(int i=1; i<=Pnts.Length(); i++) |
300 | UIsoArray->AddVertex(Pnts.Value(i)); |
301 | } |
302 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
303 | TheGroup->SetPrimitivesAspect(aDrawer->UIsoAspect()->Aspect()); |
304 | TheGroup->AddPrimitiveArray(UIsoArray); |
305 | } |
7fd59977 |
306 | |
b8ddfc2f |
307 | if(VIsoCurves.Size() > 0) { |
308 | nbBounds = VIsoCurves.Size(); |
309 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
310 | for( It.Init(VIsoCurves); It.More(); It.Next()) |
311 | nbVertices += It.Value().Length(); |
312 | Handle(Graphic3d_ArrayOfPolylines) VIsoArray = |
313 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
314 | for( It.Init(VIsoCurves); It.More(); It.Next()) { |
315 | TColgp_SequenceOfPnt Pnts; |
316 | Pnts.Assign(It.Value()); |
317 | VIsoArray->AddBound(Pnts.Length()); |
318 | for(int i=1; i<=Pnts.Length(); i++) |
319 | VIsoArray->AddVertex(Pnts.Value(i)); |
7fd59977 |
320 | } |
b8ddfc2f |
321 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
322 | TheGroup->SetPrimitivesAspect(aDrawer->VIsoAspect()->Aspect()); |
323 | TheGroup->AddPrimitiveArray(VIsoArray); |
7fd59977 |
324 | } |
325 | |
7fd59977 |
326 | gp_Pnt P; |
327 | TopLoc_Location l; |
328 | Graphic3d_Vertex V1, V2; |
329 | Standard_Integer i, j, n[3]; |
330 | |
331 | Standard_Boolean DispTriangles = Standard_False; |
332 | const char* var = getenv("DEBUG_TRIANGLES"); |
333 | if (var != 0L) { |
334 | DispTriangles = (atol(var) != 0); |
335 | } |
336 | |
337 | TColgp_SequenceOfPnt SurfPnts; |
338 | for (Tool.InitFace();Tool.MoreFace();Tool.NextFace()) |
339 | { |
340 | if (!Tool.HasSurface() || DispTriangles) |
341 | { |
342 | Handle(Poly_Triangulation) T = Tool.CurrentTriangulation(l); |
343 | if (!T.IsNull()) |
344 | { |
345 | const TColgp_Array1OfPnt& Nodes = T->Nodes(); |
346 | // Build the connect tool |
347 | Poly_Connect pc(T); |
348 | |
349 | Standard_Integer nFree, nInternal, nbTriangles = T->NbTriangles(); |
350 | Standard_Integer t[3]; |
351 | |
352 | // count the free edges |
353 | nFree = 0; |
354 | for (i = 1; i <= nbTriangles; i++) { |
355 | pc.Triangles(i,t[0],t[1],t[2]); |
356 | for (j = 0; j < 3; j++) |
357 | if (t[j] == 0) nFree++; |
358 | } |
359 | |
360 | // allocate the arrays |
361 | TColStd_Array1OfInteger Free(1,2*nFree); |
362 | nInternal = (3*nbTriangles - nFree) / 2; |
363 | TColStd_Array1OfInteger Internal(0,2*nInternal); |
364 | |
365 | Standard_Integer fr = 1, in = 1; |
366 | const Poly_Array1OfTriangle& triangles = T->Triangles(); |
367 | for (i = 1; i <= nbTriangles; i++) { |
368 | pc.Triangles(i,t[0],t[1],t[2]); |
369 | triangles(i).Get(n[0],n[1],n[2]); |
370 | for (j = 0; j < 3; j++) { |
371 | Standard_Integer k = (j+1) % 3; |
372 | if (t[j] == 0) { |
373 | Free(fr) = n[j]; |
374 | Free(fr+1) = n[k]; |
375 | fr += 2; |
376 | } |
377 | // internal edge if this triangle has a lower index than the adjacent |
378 | else if (i < t[j]) { |
379 | Internal(in) = n[j]; |
380 | Internal(in+1) = n[k]; |
381 | in += 2; |
382 | } |
383 | } |
384 | } |
385 | |
386 | if(!Tool.HasSurface()) { |
387 | // free edges |
388 | Standard_Integer nn; |
389 | nn = Free.Length() / 2; |
390 | for (i = 1; i <= nn; i++) { |
391 | gp_Pnt P1 = Nodes(Free(2*i-1)).Transformed(l); |
392 | gp_Pnt P2 = Nodes(Free(2*i)).Transformed(l); |
393 | SurfPnts.Append(P1); |
394 | SurfPnts.Append(P2); |
7fd59977 |
395 | } |
396 | } |
397 | if(DispTriangles) { |
398 | for (i = 1; i <= nInternal; i++) { |
399 | gp_Pnt P1 = Nodes(Internal(2*i-1)).Transformed(l); |
400 | gp_Pnt P2 = Nodes(Internal(2*i)).Transformed(l); |
401 | SurfPnts.Append(P1); |
402 | SurfPnts.Append(P2); |
7fd59977 |
403 | } |
404 | } |
405 | } |
406 | } |
407 | } |
b8ddfc2f |
408 | if(SurfPnts.Length()>0){ |
7fd59977 |
409 | nbVertices = SurfPnts.Length(); |
410 | nbBounds = (Standard_Integer)nbVertices / 2; |
411 | Handle(Graphic3d_ArrayOfPolylines) SurfArray = |
412 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
413 | for(i=1; i<=nbVertices; i+=2) { |
414 | SurfArray->AddBound(2); |
415 | SurfArray->AddVertex(SurfPnts.Value(i)); |
416 | SurfArray->AddVertex(SurfPnts.Value(i+1)); |
417 | } |
418 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
b8ddfc2f |
419 | if(DispTriangles && Tool.HasSurface()) |
7fd59977 |
420 | TheGroup->SetPrimitivesAspect(aDrawer->UIsoAspect()->Aspect()); |
b8ddfc2f |
421 | else |
7fd59977 |
422 | TheGroup->SetPrimitivesAspect(aDrawer->FreeBoundaryAspect()->Aspect()); |
7fd59977 |
423 | TheGroup->AddPrimitiveArray(SurfArray); |
7fd59977 |
424 | } |
425 | TopTools_ListIteratorOfListOfShape It; |
426 | |
427 | if (aDrawer->WireDraw()) |
428 | { |
429 | // Wire (without any neighbour) |
430 | TheGroup->SetPrimitivesAspect(aDrawer->WireAspect()->Aspect()); |
7fd59977 |
431 | for (It.Initialize(LWire); It.More(); It.Next()) { |
432 | const TopoDS_Edge& E = TopoDS::Edge(It.Value()); |
433 | try |
434 | { |
435 | OCC_CATCH_SIGNALS |
436 | TColgp_SequenceOfPnt Pnts; |
437 | if (!AddPolygon(E, TheGroup, aDeflection, aDrawer, Pnts)) { |
438 | if (BRep_Tool::IsGeometric(E)) { |
439 | BRepAdaptor_Curve C(E); |
b8ddfc2f |
440 | CurvePresentation::Add(aPresentation, C, aDeflection, aDrawer, Pnts, Standard_False); |
7fd59977 |
441 | WireCurves.Append(Pnts); |
442 | } |
443 | } |
444 | else |
445 | WireCurves.Append(Pnts); |
446 | } |
447 | catch(Standard_Failure) |
448 | { |
449 | #ifdef DEB |
450 | cout <<"probleme sur l'edge "<< (void*) &(*(E).TShape()) << endl; |
451 | #endif |
452 | } |
453 | } |
7fd59977 |
454 | } |
455 | |
7fd59977 |
456 | if (aDrawer->FreeBoundaryDraw()) |
457 | { |
458 | // Free boundaries; |
7fd59977 |
459 | for (It.Initialize(LFree); It.More(); It.Next()) { |
460 | const TopoDS_Edge& E = TopoDS::Edge(It.Value()); |
461 | if (!BRep_Tool::Degenerated(E)) { |
462 | try { |
463 | OCC_CATCH_SIGNALS |
464 | TColgp_SequenceOfPnt Pnts; |
465 | if (!AddPolygon(E, TheGroup, aDeflection, aDrawer, Pnts)) { |
466 | if (BRep_Tool::IsGeometric(E)) { |
467 | BRepAdaptor_Curve C(E); |
b8ddfc2f |
468 | CurvePresentation::Add(aPresentation, C, aDeflection, aDrawer, Pnts, Standard_False); |
7fd59977 |
469 | FreeCurves.Append(Pnts); |
470 | } |
471 | } |
472 | else |
473 | FreeCurves.Append(Pnts); |
474 | } |
475 | catch(Standard_Failure) |
476 | { |
477 | #ifdef DEB |
478 | cout <<"probleme sur l'edge "<< (void*) &(*(E).TShape()) << endl; |
479 | #endif |
480 | } |
481 | } |
482 | } |
7fd59977 |
483 | } |
484 | |
7fd59977 |
485 | if (aDrawer->UnFreeBoundaryDraw()) { |
486 | |
487 | // Unfree boundaries; |
488 | |
7fd59977 |
489 | for (It.Initialize(LUnFree); It.More(); It.Next()) { |
490 | const TopoDS_Edge& E = TopoDS::Edge(It.Value()); |
491 | try |
492 | { |
493 | OCC_CATCH_SIGNALS |
494 | TColgp_SequenceOfPnt Pnts; |
495 | if (!AddPolygon(E, TheGroup, aDeflection, aDrawer, Pnts)) { |
496 | if (BRep_Tool::IsGeometric(E)) { |
497 | BRepAdaptor_Curve C(E); |
b8ddfc2f |
498 | CurvePresentation::Add(aPresentation, C, aDeflection, aDrawer, Pnts, Standard_False); |
7fd59977 |
499 | UnFreeCurves.Append(Pnts); |
500 | } |
501 | } |
502 | else |
503 | UnFreeCurves.Append(Pnts); |
504 | } |
505 | catch(Standard_Failure) |
506 | { |
507 | #ifdef DEB |
508 | cout <<"probleme sur l'edge "<< (void*) &(*(E).TShape()) << endl; |
509 | #endif |
510 | } |
511 | } |
7fd59977 |
512 | } |
513 | |
b8ddfc2f |
514 | if(WireCurves.Size() > 0) { |
515 | nbBounds = WireCurves.Size(); |
516 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
517 | for( It.Init(WireCurves); It.More(); It.Next()) |
518 | nbVertices += It.Value().Length(); |
519 | Handle(Graphic3d_ArrayOfPolylines) WireArray = |
520 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
521 | for( It.Init(WireCurves); It.More(); It.Next()) { |
522 | TColgp_SequenceOfPnt Pnts; |
523 | Pnts.Assign(It.Value()); |
524 | WireArray->AddBound(Pnts.Length()); |
525 | for(i=1; i<=Pnts.Length(); i++) |
526 | WireArray->AddVertex(Pnts.Value(i)); |
527 | } |
528 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
529 | TheGroup->SetPrimitivesAspect(aDrawer->WireAspect()->Aspect()); |
530 | TheGroup->AddPrimitiveArray(WireArray); |
7fd59977 |
531 | } |
b8ddfc2f |
532 | if(FreeCurves.Size() > 0) { |
533 | nbBounds = FreeCurves.Size(); |
534 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
535 | for( It.Init(FreeCurves); It.More(); It.Next()) |
536 | nbVertices += It.Value().Length(); |
537 | Handle(Graphic3d_ArrayOfPolylines) FreeArray = |
538 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
539 | for( It.Init(FreeCurves); It.More(); It.Next()) { |
540 | TColgp_SequenceOfPnt Pnts; |
541 | Pnts.Assign(It.Value()); |
542 | FreeArray->AddBound(Pnts.Length()); |
543 | for(i=1; i<=Pnts.Length(); i++) |
544 | FreeArray->AddVertex(Pnts.Value(i)); |
545 | } |
546 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
547 | TheGroup->SetPrimitivesAspect(aDrawer->FreeBoundaryAspect()->Aspect()); |
548 | TheGroup->AddPrimitiveArray(FreeArray); |
549 | } |
550 | if(UnFreeCurves.Size() > 0) { |
551 | nbBounds = UnFreeCurves.Size(); |
552 | Prs3d_NListIteratorOfListOfSequenceOfPnt It; |
553 | for( It.Init(UnFreeCurves); It.More(); It.Next()) |
554 | nbVertices += It.Value().Length(); |
555 | Handle(Graphic3d_ArrayOfPolylines) UnFreeArray = |
556 | new Graphic3d_ArrayOfPolylines(nbVertices,nbBounds); |
557 | for( It.Init(UnFreeCurves); It.More(); It.Next()) { |
558 | TColgp_SequenceOfPnt Pnts; |
559 | Pnts.Assign(It.Value()); |
560 | UnFreeArray->AddBound(Pnts.Length()); |
561 | for(i=1; i<=Pnts.Length(); i++) |
562 | UnFreeArray->AddVertex(Pnts.Value(i)); |
563 | } |
564 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
565 | TheGroup->SetPrimitivesAspect(aDrawer->UnFreeBoundaryAspect()->Aspect()); |
566 | TheGroup->AddPrimitiveArray(UnFreeArray); |
7fd59977 |
567 | } |
b8ddfc2f |
568 | |
569 | // Points |
570 | for(Tool.InitVertex();Tool.MoreVertex();Tool.NextVertex()) |
571 | ShapePoints.Append(BRep_Tool::Pnt(Tool.GetVertex())); |
7fd59977 |
572 | |
573 | nbVertices = ShapePoints.Length(); |
b8ddfc2f |
574 | if(nbVertices > 0) { |
7fd59977 |
575 | Graphic3d_Array1OfVertex PointArray(1, nbVertices); |
576 | for(i=1; i<=nbVertices; i++) |
577 | PointArray.SetValue(i, Graphic3d_Vertex(ShapePoints.Value(i).X(), ShapePoints.Value(i).Y(), ShapePoints.Value(i).Z())); |
578 | |
579 | Handle(Graphic3d_Group) TheGroup = Prs3d_Root::NewGroup(aPresentation); |
580 | TheGroup->SetPrimitivesAspect(aDrawer->PointAspect()->Aspect()); |
7fd59977 |
581 | TheGroup->MarkerSet(PointArray); |
7fd59977 |
582 | } |
7fd59977 |
583 | } |
584 | |
585 | |
586 | |
587 | |
588 | //========================================================================= |
589 | // function: PickCurve |
590 | // purpose |
591 | //========================================================================= |
592 | Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickCurve |
593 | (const Quantity_Length X, |
594 | const Quantity_Length Y, |
595 | const Quantity_Length Z, |
596 | const Quantity_Length aDistance, |
597 | const TopoDS_Shape& aShape, |
598 | const Handle (Prs3d_Drawer)& aDrawer) |
599 | { |
600 | Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape; |
601 | Prs3d_ShapeTool Tool(aShape); |
602 | Standard_Integer i; |
603 | Standard_Boolean contain; |
604 | |
605 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
606 | Bnd_Box B = Tool.CurveBound(); |
607 | B.Enlarge(aDistance); |
608 | if ( ! B.IsOut(gp_Pnt(X,Y,Z))) { |
609 | if(CurvePresentation::Match(X,Y,Z,aDistance,BRepAdaptor_Curve(Tool.GetCurve()),aDrawer)) { |
610 | contain = Standard_False; |
611 | for (i = 1; i <= aSeq->Length(); i++) { |
612 | if (aSeq->Value(i) == (Tool.GetCurve())) { |
613 | contain = Standard_True; |
614 | break; |
615 | } |
616 | } |
617 | if (!contain) aSeq->Append(Tool.GetCurve()); |
618 | } |
619 | } |
620 | } |
621 | return aSeq; |
622 | } |
623 | |
624 | |
625 | //========================================================================= |
626 | // function: PickPatch |
627 | // purpose |
628 | //========================================================================= |
629 | Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickPatch |
630 | (const Quantity_Length X, |
631 | const Quantity_Length Y, |
632 | const Quantity_Length Z, |
633 | const Quantity_Length aDistance, |
634 | const TopoDS_Shape& aShape, |
635 | const Handle(Prs3d_Drawer)& aDrawer) { |
636 | |
637 | Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape; |
638 | Prs3d_ShapeTool Tool(aShape); |
639 | |
640 | Standard_Boolean rba1 = aDrawer->UIsoAspect()->Number() != 0; |
641 | Standard_Boolean rba2 = aDrawer->VIsoAspect()->Number() != 0; |
642 | Standard_Integer i, j; |
643 | Standard_Boolean contain; |
644 | |
645 | if ( rba1 || rba2 ) { |
646 | BRepAdaptor_Surface S; |
647 | for(Tool.InitFace();Tool.MoreFace();Tool.NextFace()){ |
648 | Bnd_Box B = Tool.FaceBound(); |
649 | B.Enlarge(aDistance); |
650 | if ( ! B.IsOut(gp_Pnt(X,Y,Z))) { |
651 | S.Initialize(Tool.GetFace()); |
652 | Handle(BRepAdaptor_HSurface) HS = new BRepAdaptor_HSurface(S); |
653 | if(FacePresentation::Match |
654 | (X,Y,Z,aDistance, HS, aDrawer)){ |
655 | contain = Standard_False; |
656 | for (i = 1; i <= aSeq->Length(); i++) { |
657 | if (aSeq->Value(i) == (Tool.GetFace())) { |
658 | contain = Standard_True; |
659 | break; |
660 | } |
661 | } |
662 | if (!contain) aSeq->Append(Tool.GetFace()); |
663 | } |
664 | } |
665 | } |
666 | } |
667 | |
668 | for(Tool.InitCurve();Tool.MoreCurve();Tool.NextCurve()){ |
669 | Bnd_Box B = Tool.CurveBound(); |
670 | B.Enlarge(aDistance); |
671 | if ( ! B.IsOut(gp_Pnt(X,Y,Z))) { |
672 | if(CurvePresentation::Match(X,Y,Z,aDistance,BRepAdaptor_Curve(Tool.GetCurve()),aDrawer)) { |
673 | Handle(TopTools_HSequenceOfShape) aS = Tool.FacesOfEdge(); |
674 | for (i=1; i<= aS->Length(); i ++) { |
675 | contain = Standard_False; |
676 | for (j = 1; j <= aSeq->Length(); j++) { |
677 | if (aSeq->Value(j) == (aS->Value(i))) { |
678 | contain = Standard_True; |
679 | break; |
680 | } |
681 | } |
682 | if (!contain) aSeq->Append(aS->Value(i)); |
683 | } |
684 | } |
685 | } |
686 | } |
687 | return aSeq; |
688 | } |