973c2be1 |
1 | // Copyright (c) 2013-2014 OPEN CASCADE SAS |
c151c0f1 |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
c151c0f1 |
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. |
c151c0f1 |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
c151c0f1 |
13 | |
14 | #include <Prs3d_WFShape.hxx> |
15 | |
16 | #include <Bnd_Box.hxx> |
17 | #include <BRepAdaptor_HSurface.hxx> |
18 | #include <BRepAdaptor_Curve.hxx> |
19 | #include <BRepBndLib.hxx> |
20 | #include <BRep_Tool.hxx> |
21 | #include <Graphic3d_Group.hxx> |
22 | #include <Graphic3d_AspectLine3d.hxx> |
23 | #include <Graphic3d_ArrayOfPolylines.hxx> |
a577aaab |
24 | #include <Graphic3d_ArrayOfPoints.hxx> |
c151c0f1 |
25 | #include <gp_Pnt.hxx> |
26 | #include <Poly_Connect.hxx> |
27 | #include <Poly_Triangulation.hxx> |
28 | #include <Poly_Array1OfTriangle.hxx> |
29 | #include <Poly_Polygon3D.hxx> |
30 | #include <Poly_PolygonOnTriangulation.hxx> |
9dba391d |
31 | #include <Prs3d.hxx> |
c151c0f1 |
32 | #include <Prs3d_Drawer.hxx> |
33 | #include <Prs3d_IsoAspect.hxx> |
34 | #include <Prs3d_PointAspect.hxx> |
35 | #include <Prs3d_NListIteratorOfListOfSequenceOfPnt.hxx> |
36 | #include <Prs3d_ShapeTool.hxx> |
37 | #include <Standard_ErrorHandler.hxx> |
38 | #include <TColgp_Array1OfPnt.hxx> |
39 | #include <TColgp_SequenceOfPnt.hxx> |
40 | #include <TopoDS_Edge.hxx> |
41 | #include <TopoDS.hxx> |
42 | #include <TopTools_HSequenceOfShape.hxx> |
43 | #include <TopTools_ListOfShape.hxx> |
44 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
45 | |
46 | namespace |
47 | { |
48 | |
49 | //! Compare two aspects |
50 | inline Standard_Boolean IsSame (const Handle(Graphic3d_AspectLine3d)& theUAspect, |
51 | const Handle(Graphic3d_AspectLine3d)& theVAspect) |
52 | { |
53 | Quantity_Color aCU, aCV; |
54 | Aspect_TypeOfLine aTlU, aTlV; |
55 | Standard_Real aWU, aWV; |
56 | theUAspect->Values (aCU, aTlU, aWU); |
57 | theVAspect->Values (aCV, aTlV, aWV); |
58 | return aCU == aCV |
59 | && aTlU == aTlV |
60 | && aWU == aWV; |
61 | } |
62 | |
63 | }; |
64 | |
65 | // ========================================================================= |
66 | // function: AddPolygon |
67 | // purpose : |
68 | // ========================================================================= |
69 | Standard_Boolean Prs3d_WFShape::AddPolygon (const TopoDS_Edge& theEdge, |
c151c0f1 |
70 | TColgp_SequenceOfPnt& thePoints) |
71 | { |
72 | TopLoc_Location aLocation; |
c151c0f1 |
73 | Handle(Poly_Polygon3D) aPolygon = BRep_Tool::Polygon3D (theEdge, aLocation); |
74 | if (!aPolygon.IsNull()) |
75 | { |
2c12770c |
76 | const TColgp_Array1OfPnt& aPoints = aPolygon->Nodes(); |
77 | Standard_Integer anIndex = aPoints.Lower(); |
78 | if (aLocation.IsIdentity()) |
c151c0f1 |
79 | { |
2c12770c |
80 | for (; anIndex <= aPoints.Upper(); ++anIndex) |
c151c0f1 |
81 | { |
2c12770c |
82 | thePoints.Append (aPoints.Value (anIndex)); |
c151c0f1 |
83 | } |
2c12770c |
84 | } |
85 | else |
86 | { |
87 | for (; anIndex <= aPoints.Upper(); ++anIndex) |
c151c0f1 |
88 | { |
2c12770c |
89 | thePoints.Append (aPoints.Value (anIndex).Transformed (aLocation)); |
c151c0f1 |
90 | } |
c151c0f1 |
91 | } |
2c12770c |
92 | return Standard_True; |
c151c0f1 |
93 | } |
94 | |
95 | Handle(Poly_Triangulation) aTriangulation; |
96 | Handle(Poly_PolygonOnTriangulation) aHIndices; |
97 | BRep_Tool::PolygonOnTriangulation (theEdge, aHIndices, aTriangulation, aLocation); |
98 | if (!aHIndices.IsNull()) |
99 | { |
2c12770c |
100 | const TColStd_Array1OfInteger& anIndices = aHIndices->Nodes(); |
c151c0f1 |
101 | |
2c12770c |
102 | Standard_Integer anIndex = anIndices.Lower(); |
103 | if (aLocation.IsIdentity()) |
104 | { |
105 | for (; anIndex <= anIndices.Upper(); ++anIndex) |
c151c0f1 |
106 | { |
6c1f47fd |
107 | thePoints.Append (aTriangulation->Node (anIndices (anIndex))); |
c151c0f1 |
108 | } |
2c12770c |
109 | } |
110 | else |
111 | { |
112 | for (; anIndex <= anIndices.Upper(); ++anIndex) |
c151c0f1 |
113 | { |
6c1f47fd |
114 | thePoints.Append (aTriangulation->Node (anIndices (anIndex)).Transformed (aLocation)); |
c151c0f1 |
115 | } |
c151c0f1 |
116 | } |
2c12770c |
117 | return Standard_True; |
c151c0f1 |
118 | } |
119 | return Standard_False; |
120 | } |
121 | |
122 | // ========================================================================= |
123 | // function: Add |
124 | // purpose : |
125 | // ========================================================================= |
126 | void Prs3d_WFShape::Add (const Handle (Prs3d_Presentation)& thePresentation, |
127 | const TopoDS_Shape& theShape, |
128 | const Handle (Prs3d_Drawer)& theDrawer) |
129 | { |
130 | if (theShape.IsNull()) |
131 | { |
132 | return; |
133 | } |
134 | |
53b15292 |
135 | Prs3d_ShapeTool aTool (theShape, theDrawer->VertexDrawMode() == Prs3d_VDM_All); |
c151c0f1 |
136 | TopTools_ListOfShape aLFree, aLUnFree, aLWire; |
137 | for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) |
138 | { |
139 | const TopoDS_Edge& anEdge = aTool.GetCurve(); |
140 | switch (aTool.Neighbours()) |
141 | { |
142 | case 0: aLWire.Append (anEdge); break; |
143 | case 1: aLFree.Append (anEdge); break; |
144 | default: aLUnFree.Append (anEdge); break; |
145 | } |
146 | } |
147 | |
9dba391d |
148 | Standard_Real aDeflection = Prs3d::GetDeflection(theShape, theDrawer); |
c151c0f1 |
149 | |
c151c0f1 |
150 | Prs3d_NListOfSequenceOfPnt anUIsoCurves; |
151 | Prs3d_NListOfSequenceOfPnt aVIsoCurves; |
152 | Prs3d_NListOfSequenceOfPnt aWireCurves; |
153 | Prs3d_NListOfSequenceOfPnt aFreeCurves; |
154 | Prs3d_NListOfSequenceOfPnt anUnFreeCurves; |
c151c0f1 |
155 | |
156 | const Standard_Integer anIsoU = theDrawer->UIsoAspect()->Number(); |
157 | const Standard_Integer anIsoV = theDrawer->VIsoAspect()->Number(); |
158 | |
159 | Standard_Boolean hasIsoU = anIsoU > 0; |
160 | Standard_Boolean hasIsoV = anIsoV > 0; |
161 | |
162 | if (IsSame (theDrawer->UIsoAspect()->Aspect(), |
163 | theDrawer->VIsoAspect()->Aspect())) |
164 | { |
165 | if (hasIsoU || hasIsoV) |
166 | { |
167 | BRepAdaptor_Surface aSurface; |
168 | for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) |
169 | { |
170 | if (aTool.HasSurface()) |
171 | { |
172 | if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) |
173 | { |
174 | aSurface.Initialize (aTool.GetFace()); |
175 | Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); |
176 | try |
177 | { |
178 | OCC_CATCH_SIGNALS |
179 | Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; |
180 | myFaceAlgo.Add (thePresentation, aHSurface, |
181 | hasIsoU, hasIsoV, |
182 | aDeflection, |
183 | anIsoU, anIsoV, |
184 | theDrawer, |
185 | aCurUIsoCurves); |
186 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
187 | for (anIt.Init (aCurUIsoCurves); anIt.More(); anIt.Next()) |
188 | { |
189 | anUIsoCurves.Append (anIt.Value()); |
190 | } |
191 | } |
192 | catch (Standard_Failure) |
193 | { |
194 | } |
195 | } |
196 | } |
197 | } |
198 | } |
199 | } |
200 | else |
201 | { |
202 | if (hasIsoU) |
203 | { |
204 | BRepAdaptor_Surface aSurface; |
205 | for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) |
206 | { |
207 | if (aTool.HasSurface()) |
208 | { |
209 | if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) |
210 | { |
211 | aSurface.Initialize (aTool.GetFace()); |
212 | Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); |
213 | try |
214 | { |
215 | OCC_CATCH_SIGNALS |
216 | Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; |
217 | myFaceAlgo.Add (thePresentation, aHSurface, |
218 | hasIsoU, Standard_False, |
219 | aDeflection, |
220 | anIsoU, 0, |
221 | theDrawer, |
222 | aCurUIsoCurves); |
223 | } |
224 | catch (Standard_Failure) |
225 | { |
0797d9d3 |
226 | #ifdef OCCT_DEBUG |
c151c0f1 |
227 | const TopoDS_Face& aFace = aSurface.Face(); |
228 | std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl; |
229 | #endif |
230 | } |
231 | } |
232 | } |
233 | } |
234 | } |
235 | if (hasIsoV) |
236 | { |
237 | BRepAdaptor_Surface aSurface; |
238 | for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) |
239 | { |
240 | if (aTool.HasSurface()) |
241 | { |
242 | if (!aTool.IsPlanarFace() || theDrawer->IsoOnPlane()) |
243 | { |
244 | aSurface.Initialize (aTool.GetFace()); |
245 | Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); |
246 | try |
247 | { |
248 | OCC_CATCH_SIGNALS |
249 | Prs3d_NListOfSequenceOfPnt aCurUIsoCurves; |
250 | myFaceAlgo.Add (thePresentation, aHSurface, |
251 | Standard_False, hasIsoV, |
252 | aDeflection, |
253 | 0, anIsoV, |
254 | theDrawer, |
255 | aCurUIsoCurves); |
256 | } |
257 | catch (Standard_Failure) |
258 | { |
0797d9d3 |
259 | #ifdef OCCT_DEBUG |
c151c0f1 |
260 | const TopoDS_Face& aFace = aSurface.Face(); |
261 | std::cout << "Problem with the face " << (void* ) &(*(aFace).TShape()) << std::endl; |
262 | #endif |
263 | } |
264 | } |
265 | } |
266 | } |
267 | } |
268 | } |
269 | |
270 | Standard_Integer aNbVertices = 0, aNbBounds = 0; |
271 | if (anUIsoCurves.Size() > 0) |
272 | { |
273 | aNbBounds = anUIsoCurves.Size(); |
274 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
275 | for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next()) |
276 | { |
e3a6386d |
277 | aNbVertices += anIt.Value()->Length(); |
c151c0f1 |
278 | } |
279 | Handle(Graphic3d_ArrayOfPolylines) anUIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
280 | for (anIt.Init (anUIsoCurves); anIt.More(); anIt.Next()) |
281 | { |
e3a6386d |
282 | const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value(); |
283 | anUIsoArray->AddBound (aPoints->Length()); |
284 | for (Standard_Integer anI = 1; anI <= aPoints->Length(); ++anI) |
c151c0f1 |
285 | { |
e3a6386d |
286 | anUIsoArray->AddVertex (aPoints->Value (anI)); |
c151c0f1 |
287 | } |
288 | } |
289 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
290 | aGroup->SetPrimitivesAspect (theDrawer->UIsoAspect()->Aspect()); |
291 | aGroup->AddPrimitiveArray (anUIsoArray); |
292 | } |
293 | |
e3a6386d |
294 | // NOTE: THIS BLOCK WILL NEVER EXECUTE AS aVIsoCurves IS NOT FILLED!! |
c151c0f1 |
295 | if (aVIsoCurves.Size() > 0) |
296 | { |
297 | aNbBounds = aVIsoCurves.Size(); |
298 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
299 | for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next()) |
300 | { |
e3a6386d |
301 | aNbVertices += anIt.Value()->Length(); |
c151c0f1 |
302 | } |
303 | Handle(Graphic3d_ArrayOfPolylines) VIsoArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
304 | for (anIt.Init (aVIsoCurves); anIt.More(); anIt.Next()) |
305 | { |
e3a6386d |
306 | const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value(); |
307 | VIsoArray->AddBound (aPoints->Length()); |
308 | for (int anI = 1; anI <= aPoints->Length(); anI++) |
c151c0f1 |
309 | { |
e3a6386d |
310 | VIsoArray->AddVertex (aPoints->Value (anI)); |
c151c0f1 |
311 | } |
312 | } |
313 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
314 | aGroup->SetPrimitivesAspect (theDrawer->VIsoAspect()->Aspect()); |
315 | aGroup->AddPrimitiveArray (VIsoArray); |
316 | } |
317 | |
318 | TopLoc_Location aLocation; |
319 | Standard_Integer anI, aJ, aN[3]; |
320 | |
c151c0f1 |
321 | TColgp_SequenceOfPnt aSurfPoints; |
322 | for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) |
323 | { |
5e1e45fc |
324 | if (!aTool.HasSurface()) |
c151c0f1 |
325 | { |
326 | Handle(Poly_Triangulation) T = aTool.CurrentTriangulation (aLocation); |
327 | if (!T.IsNull()) |
328 | { |
c151c0f1 |
329 | // Build the connect tool |
330 | Poly_Connect aPolyConnect (T); |
331 | |
332 | Standard_Integer aNbTriangles = T->NbTriangles(); |
333 | Standard_Integer aT[3]; |
334 | |
335 | // Count the free edges |
336 | Standard_Integer aNbFree = 0; |
337 | for (anI = 1; anI <= aNbTriangles; ++anI) |
338 | { |
339 | aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); |
340 | for (aJ = 0; aJ < 3; ++aJ) |
341 | { |
342 | if (aT[aJ] == 0) |
343 | { |
344 | ++aNbFree; |
345 | } |
346 | } |
347 | } |
348 | |
349 | // Allocate the arrays |
350 | TColStd_Array1OfInteger aFree (1, 2 * aNbFree); |
351 | Standard_Integer aNbInternal = (3 * aNbTriangles - aNbFree) / 2; |
352 | TColStd_Array1OfInteger anInternal (0, 2 * aNbInternal); |
353 | |
354 | Standard_Integer aFreeIndex = 1, anIntIndex = 1; |
c151c0f1 |
355 | for (anI = 1; anI <= aNbTriangles; ++anI) |
356 | { |
357 | aPolyConnect.Triangles (anI, aT[0], aT[1], aT[2]); |
6c1f47fd |
358 | T->Triangle (anI).Get (aN[0], aN[1], aN[2]); |
c151c0f1 |
359 | for (aJ = 0; aJ < 3; aJ++) |
360 | { |
361 | Standard_Integer k = (aJ + 1) % 3; |
362 | if (aT[aJ] == 0) |
363 | { |
364 | aFree (aFreeIndex) = aN[aJ]; |
365 | aFree (aFreeIndex + 1) = aN[k]; |
366 | aFreeIndex += 2; |
367 | } |
368 | // internal edge if this triangle has a lower index than the adjacent |
369 | else if (anI < aT[aJ]) |
370 | { |
371 | anInternal (anIntIndex) = aN[aJ]; |
372 | anInternal (anIntIndex + 1) = aN[k]; |
373 | anIntIndex += 2; |
374 | } |
375 | } |
376 | } |
377 | |
378 | if (!aTool.HasSurface()) |
379 | { |
380 | // free edges |
381 | Standard_Integer aFreeHalfNb = aFree.Length() / 2; |
382 | for (anI = 1; anI <= aFreeHalfNb; ++anI) |
383 | { |
6c1f47fd |
384 | gp_Pnt aPoint1 = T->Node (aFree (2 * anI - 1)).Transformed (aLocation); |
385 | gp_Pnt aPoint2 = T->Node (aFree (2 * anI )).Transformed (aLocation); |
c151c0f1 |
386 | aSurfPoints.Append (aPoint1); |
387 | aSurfPoints.Append (aPoint2); |
388 | } |
389 | } |
c151c0f1 |
390 | } |
391 | } |
392 | } |
393 | if (aSurfPoints.Length() > 0) |
394 | { |
395 | aNbVertices = aSurfPoints.Length(); |
396 | aNbBounds = (Standard_Integer)aNbVertices / 2; |
397 | Handle(Graphic3d_ArrayOfPolylines) aSurfArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
398 | for (anI = 1; anI <= aNbVertices; anI += 2) |
399 | { |
400 | aSurfArray->AddBound (2); |
401 | aSurfArray->AddVertex (aSurfPoints.Value (anI)); |
402 | aSurfArray->AddVertex (aSurfPoints.Value (anI + 1)); |
403 | } |
404 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
5e1e45fc |
405 | aGroup->SetPrimitivesAspect (theDrawer->FreeBoundaryAspect()->Aspect()); |
c151c0f1 |
406 | aGroup->AddPrimitiveArray (aSurfArray); |
407 | } |
408 | |
409 | TopTools_ListIteratorOfListOfShape anIt; |
410 | if (theDrawer->WireDraw()) |
411 | { |
412 | // Wire (without any neighbour) |
c151c0f1 |
413 | for (anIt.Initialize(aLWire); anIt.More(); anIt.Next()) |
414 | { |
415 | const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); |
416 | try |
417 | { |
418 | OCC_CATCH_SIGNALS |
e3a6386d |
419 | const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt; |
2c12770c |
420 | if (!AddPolygon (anEdge, aPoints->ChangeSequence())) |
c151c0f1 |
421 | { |
422 | if (BRep_Tool::IsGeometric (anEdge)) |
423 | { |
424 | BRepAdaptor_Curve aCurve (anEdge); |
425 | myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, |
e3a6386d |
426 | aPoints->ChangeSequence(), Standard_False); |
c151c0f1 |
427 | aWireCurves.Append (aPoints); |
428 | } |
429 | } |
430 | else |
431 | { |
432 | aWireCurves.Append (aPoints); |
433 | } |
434 | } |
435 | catch (Standard_Failure) |
436 | { |
0797d9d3 |
437 | #ifdef OCCT_DEBUG |
c151c0f1 |
438 | std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; |
439 | #endif |
440 | } |
441 | } |
442 | } |
443 | |
444 | if (theDrawer->FreeBoundaryDraw()) |
445 | { |
446 | // aFree boundaries; |
447 | for (anIt.Initialize (aLFree); anIt.More(); anIt.Next()) |
448 | { |
449 | const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); |
450 | if (!BRep_Tool::Degenerated (anEdge)) |
451 | { |
452 | try |
453 | { |
454 | OCC_CATCH_SIGNALS |
e3a6386d |
455 | const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt; |
2c12770c |
456 | if (!AddPolygon (anEdge, aPoints->ChangeSequence())) |
c151c0f1 |
457 | { |
458 | if (BRep_Tool::IsGeometric (anEdge)) |
459 | { |
460 | BRepAdaptor_Curve aCurve (anEdge); |
461 | myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, |
e3a6386d |
462 | aPoints->ChangeSequence(), Standard_False); |
c151c0f1 |
463 | aFreeCurves.Append (aPoints); |
464 | } |
465 | } |
466 | else |
467 | { |
468 | aFreeCurves.Append (aPoints); |
469 | } |
470 | } |
471 | catch (Standard_Failure) |
472 | { |
0797d9d3 |
473 | #ifdef OCCT_DEBUG |
c151c0f1 |
474 | std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; |
475 | #endif |
476 | } |
477 | } |
478 | } |
479 | } |
480 | |
481 | if (theDrawer->UnFreeBoundaryDraw()) |
482 | { |
483 | // Unfree boundaries; |
484 | for (anIt.Initialize (aLUnFree); anIt.More(); anIt.Next()) |
485 | { |
486 | const TopoDS_Edge& anEdge = TopoDS::Edge (anIt.Value()); |
487 | try |
488 | { |
489 | OCC_CATCH_SIGNALS |
e3a6386d |
490 | const Handle(TColgp_HSequenceOfPnt)& aPoints = new TColgp_HSequenceOfPnt; |
2c12770c |
491 | if (!AddPolygon (anEdge, aPoints->ChangeSequence())) |
c151c0f1 |
492 | { |
493 | if (BRep_Tool::IsGeometric (anEdge)) |
494 | { |
495 | BRepAdaptor_Curve aCurve (anEdge); |
e3a6386d |
496 | myCurveAlgo.Add (thePresentation, aCurve, aDeflection, theDrawer, aPoints->ChangeSequence(), Standard_False); |
c151c0f1 |
497 | anUnFreeCurves.Append (aPoints); |
498 | } |
499 | } |
500 | else |
501 | { |
502 | anUnFreeCurves.Append (aPoints); |
503 | } |
504 | } |
505 | catch (Standard_Failure) |
506 | { |
0797d9d3 |
507 | #ifdef OCCT_DEBUG |
c151c0f1 |
508 | std::cout << "probleme sur aLocation'edge " << (void* ) &(*(anEdge).TShape()) << std::endl; |
509 | #endif |
510 | } |
511 | } |
512 | } |
513 | |
514 | if (aWireCurves.Size() > 0) |
515 | { |
516 | aNbBounds = aWireCurves.Size(); |
517 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
518 | for (anIt.Init (aWireCurves); anIt.More(); anIt.Next()) |
519 | { |
e3a6386d |
520 | aNbVertices += anIt.Value()->Length(); |
c151c0f1 |
521 | } |
522 | Handle(Graphic3d_ArrayOfPolylines) WireArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
523 | for (anIt.Init (aWireCurves); anIt.More(); anIt.Next()) |
524 | { |
e3a6386d |
525 | const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value(); |
526 | WireArray->AddBound (aPoints->Length()); |
527 | for (anI = 1; anI <= aPoints->Length(); ++anI) |
c151c0f1 |
528 | { |
e3a6386d |
529 | WireArray->AddVertex (aPoints->Value (anI)); |
c151c0f1 |
530 | } |
531 | } |
532 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
533 | aGroup->SetPrimitivesAspect (theDrawer->WireAspect()->Aspect()); |
534 | aGroup->AddPrimitiveArray (WireArray); |
535 | } |
536 | |
537 | if (aFreeCurves.Size() > 0) |
538 | { |
539 | aNbBounds = aFreeCurves.Size(); |
540 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
541 | for (anIt.Init (aFreeCurves); anIt.More(); anIt.Next()) |
542 | { |
e3a6386d |
543 | aNbVertices += anIt.Value()->Length(); |
c151c0f1 |
544 | } |
545 | Handle(Graphic3d_ArrayOfPolylines) aFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
546 | for (anIt.Init(aFreeCurves); anIt.More(); anIt.Next()) |
547 | { |
e3a6386d |
548 | const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value(); |
549 | aFreeArray->AddBound (aPoints->Length()); |
550 | for (anI = 1; anI <= aPoints->Length(); ++anI) |
c151c0f1 |
551 | { |
e3a6386d |
552 | aFreeArray->AddVertex (aPoints->Value (anI)); |
c151c0f1 |
553 | } |
554 | } |
555 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
556 | aGroup->SetPrimitivesAspect (theDrawer->FreeBoundaryAspect()->Aspect()); |
557 | aGroup->AddPrimitiveArray (aFreeArray); |
558 | } |
559 | |
560 | if (anUnFreeCurves.Size() > 0) |
561 | { |
562 | aNbBounds = anUnFreeCurves.Size(); |
563 | Prs3d_NListIteratorOfListOfSequenceOfPnt anIt; |
564 | for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next()) |
565 | { |
e3a6386d |
566 | aNbVertices += anIt.Value()->Length(); |
c151c0f1 |
567 | } |
568 | Handle(Graphic3d_ArrayOfPolylines) anUnFreeArray = new Graphic3d_ArrayOfPolylines (aNbVertices, aNbBounds); |
569 | for (anIt.Init (anUnFreeCurves); anIt.More(); anIt.Next()) |
570 | { |
e3a6386d |
571 | const Handle(TColgp_HSequenceOfPnt)& aPoints = anIt.Value(); |
572 | anUnFreeArray->AddBound (aPoints->Length()); |
573 | for (anI = 1; anI <= aPoints->Length(); ++anI) |
c151c0f1 |
574 | { |
e3a6386d |
575 | anUnFreeArray->AddVertex (aPoints->Value (anI)); |
c151c0f1 |
576 | } |
577 | } |
578 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
579 | aGroup->SetPrimitivesAspect (theDrawer->UnFreeBoundaryAspect()->Aspect()); |
580 | aGroup->AddPrimitiveArray (anUnFreeArray); |
581 | } |
582 | |
583 | // Points |
e3a6386d |
584 | TColgp_SequenceOfPnt aShapePoints; |
c151c0f1 |
585 | for (aTool.InitVertex(); aTool.MoreVertex(); aTool.NextVertex()) |
586 | { |
587 | aShapePoints.Append (BRep_Tool::Pnt (aTool.GetVertex())); |
588 | } |
589 | |
590 | aNbVertices = aShapePoints.Length(); |
591 | if (aNbVertices > 0) |
592 | { |
a577aaab |
593 | Handle(Graphic3d_ArrayOfPoints) aPointArray = new Graphic3d_ArrayOfPoints (aNbVertices); |
c151c0f1 |
594 | for (anI = 1; anI <= aNbVertices; ++anI) |
595 | { |
a577aaab |
596 | aPointArray->AddVertex (aShapePoints.Value (anI)); |
c151c0f1 |
597 | } |
598 | |
599 | Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePresentation); |
600 | aGroup->SetPrimitivesAspect (theDrawer->PointAspect()->Aspect()); |
a577aaab |
601 | aGroup->AddPrimitiveArray (aPointArray); |
c151c0f1 |
602 | } |
603 | } |
604 | |
605 | // ========================================================================= |
606 | // function: PickCurve |
607 | // purpose : |
608 | // ========================================================================= |
609 | Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickCurve |
610 | (const Quantity_Length theX, |
611 | const Quantity_Length theY, |
612 | const Quantity_Length theZ, |
613 | const Quantity_Length theDistance, |
614 | const TopoDS_Shape& theShape, |
615 | const Handle (Prs3d_Drawer)& theDrawer) |
616 | { |
617 | Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape(); |
618 | Prs3d_ShapeTool aTool (theShape); |
619 | for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) |
620 | { |
621 | Bnd_Box aBndBox = aTool.CurveBound(); |
622 | aBndBox.Enlarge (theDistance); |
623 | if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) |
624 | { |
625 | if (myCurveAlgo.Match (theX, theY, theZ, theDistance, |
626 | BRepAdaptor_Curve (aTool.GetCurve()), theDrawer)) |
627 | { |
628 | Standard_Boolean isContain = Standard_False; |
629 | for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) |
630 | { |
631 | if (aSeq->Value (anI) == (aTool.GetCurve())) |
632 | { |
633 | isContain = Standard_True; |
634 | break; |
635 | } |
636 | } |
637 | if (!isContain) |
638 | { |
639 | aSeq->Append (aTool.GetCurve()); |
640 | } |
641 | } |
642 | } |
643 | } |
644 | return aSeq; |
645 | } |
646 | |
647 | // ========================================================================= |
648 | // function: PickPatch |
649 | // purpose : |
650 | // ========================================================================= |
651 | Handle(TopTools_HSequenceOfShape) Prs3d_WFShape::PickPatch |
652 | (const Quantity_Length theX, |
653 | const Quantity_Length theY, |
654 | const Quantity_Length theZ, |
655 | const Quantity_Length theDistance, |
656 | const TopoDS_Shape& theShape, |
657 | const Handle(Prs3d_Drawer)& theDrawer) |
658 | { |
659 | Handle(TopTools_HSequenceOfShape) aSeq = new TopTools_HSequenceOfShape(); |
660 | Prs3d_ShapeTool aTool (theShape); |
661 | |
662 | Standard_Boolean aRba1 = theDrawer->UIsoAspect()->Number() != 0; |
663 | Standard_Boolean aRba2 = theDrawer->VIsoAspect()->Number() != 0; |
664 | Standard_Boolean isContain; |
665 | |
666 | if (aRba1 || aRba2) |
667 | { |
668 | BRepAdaptor_Surface aSurface; |
669 | for (aTool.InitFace(); aTool.MoreFace(); aTool.NextFace()) |
670 | { |
671 | Bnd_Box aBndBox = aTool.FaceBound(); |
672 | aBndBox.Enlarge (theDistance); |
673 | if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) |
674 | { |
675 | aSurface.Initialize (aTool.GetFace()); |
676 | Handle(BRepAdaptor_HSurface) aHSurface = new BRepAdaptor_HSurface (aSurface); |
677 | if (myFaceAlgo.Match (theX, theY, theZ, theDistance, aHSurface, theDrawer)) |
678 | { |
679 | isContain = Standard_False; |
680 | for (Standard_Integer anI = 1; anI <= aSeq->Length(); ++anI) |
681 | { |
682 | if (aSeq->Value (anI) == (aTool.GetFace())) |
683 | { |
684 | isContain = Standard_True; |
685 | break; |
686 | } |
687 | } |
688 | if (!isContain) |
689 | { |
690 | aSeq->Append (aTool.GetFace()); |
691 | } |
692 | } |
693 | } |
694 | } |
695 | } |
696 | |
697 | for (aTool.InitCurve(); aTool.MoreCurve(); aTool.NextCurve()) |
698 | { |
699 | Bnd_Box aBndBox = aTool.CurveBound(); |
700 | aBndBox.Enlarge (theDistance); |
701 | if (!aBndBox.IsOut (gp_Pnt (theX, theY, theZ))) |
702 | { |
703 | if (myCurveAlgo.Match (theX, theY, theZ, theDistance, |
704 | BRepAdaptor_Curve(aTool.GetCurve()), theDrawer)) |
705 | { |
706 | Handle(TopTools_HSequenceOfShape) aSurface = aTool.FacesOfEdge(); |
707 | for (Standard_Integer anI = 1; anI <= aSurface->Length(); ++anI) |
708 | { |
709 | isContain = Standard_False; |
710 | for (Standard_Integer aJ = 1; aJ <= aSeq->Length(); ++aJ) |
711 | { |
712 | if (aSeq->Value (aJ) == (aSurface->Value (anI))) |
713 | { |
714 | isContain = Standard_True; |
715 | break; |
716 | } |
717 | } |
718 | if (!isContain) |
719 | { |
720 | aSeq->Append (aSurface->Value (anI)); |
721 | } |
722 | } |
723 | } |
724 | } |
725 | } |
726 | return aSeq; |
727 | } |