0022627: Change OCCT memory management defaults
[occt.git] / src / BRepFill / BRepFill_Evolved.cxx
CommitLineData
7fd59977 1// File: BRepFill_Evolved.cxx
2// Created: Mon Oct 3 14:36:06 1994
3// Author: Bruno DUMORTIER
4// <dub@fuegox>
5
6#include <BRepFill_Evolved.ixx>
7
8
9#include <Bnd_Box2d.hxx>
10#include <BndLib_Add2dCurve.hxx>
11#include <BRepFill_OffsetWire.hxx>
12#include <BRepAdaptor_Curve.hxx>
13#include <BRep_Builder.hxx>
14#include <BRepClass3d_SolidClassifier.hxx>
15#include <BRepLib.hxx>
16#include <BRepMAT2d_Explorer.hxx>
17#include <BRepFill_Pipe.hxx>
18#include <BRepFill_OffsetAncestors.hxx>
19#include <BRepAlgo_FaceRestrictor.hxx>
20#include <BRepLib_FindSurface.hxx>
21#include <BRepLib_MakeFace.hxx>
22#include <BRepLib_MakeWire.hxx>
23#include <BRepLib_MakeEdge.hxx>
24#include <BRepLib_MakeVertex.hxx>
25#include <BRepAlgo_Loop.hxx>
26#include <BRepSweep_Revol.hxx>
27#include <BRepSweep_Prism.hxx>
28#include <BRepTools.hxx>
29#include <BRepTools_WireExplorer.hxx>
30#include <BRepTools_TrsfModification.hxx>
31#include <BRepTools_Modifier.hxx>
32#include <BRep_Tool.hxx>
33#include <BRepAdaptor_Curve.hxx>
34#include <BRepLProp.hxx>
35
36#include <BRepMAT2d_LinkTopoBilo.hxx>
37#include <BRepMAT2d_BisectingLocus.hxx>
38#include <BRepMAT2d_Explorer.hxx>
39
40#include <GeomAPI.hxx>
41#include <Geom2dAdaptor_Curve.hxx>
42#include <Geom_Surface.hxx>
43#include <Geom_Plane.hxx>
44#include <Geom_Curve.hxx>
45#include <Geom_Line.hxx>
46#include <Geom_TrimmedCurve.hxx>
47#include <Geom2d_CartesianPoint.hxx>
48#include <Geom2d_Curve.hxx>
49#include <Geom2d_Line.hxx>
50#include <Geom2d_Circle.hxx>
51#include <Geom2d_TrimmedCurve.hxx>
52#include <Geom2d_Geometry.hxx>
53#include <GeomProjLib.hxx>
54#include <Geom_RectangularTrimmedSurface.hxx>
55#include <Geom2dAdaptor_Curve.hxx>
56
57#include <Geom2dAPI_ExtremaCurveCurve.hxx>
58#include <IntRes2d_IntersectionPoint.hxx>
59#include <Geom2dInt_GInter.hxx>
60
61#include <MAT2d_CutCurve.hxx>
62
63#include <MAT_Graph.hxx>
64#include <MAT_BasicElt.hxx>
65#include <MAT_Side.hxx>
66#include <MAT_Arc.hxx>
67#include <MAT_Node.hxx>
68#include <Bisector_Bisec.hxx>
69#include <Bisector_BisecAna.hxx>
70
71#include <TopoDS.hxx>
72#include <TopoDS_Wire.hxx>
73#include <TopoDS_Edge.hxx>
74#include <TopoDS_Compound.hxx>
75#include <TopoDS_Solid.hxx>
76#include <TopoDS_Iterator.hxx>
77#include <TopExp.hxx>
78#include <TopExp_Explorer.hxx>
79#include <TopTools_DataMapOfShapeShape.hxx>
80#include <TopTools_SequenceOfShape.hxx>
81#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
82#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
83#include <TopTools_ListIteratorOfListOfShape.hxx>
84#include <TopTools_DataMapOfShapeSequenceOfShape.hxx>
85#include <TopLoc_Location.hxx>
86#include <TopAbs.hxx>
87
88#include <gp.hxx>
89#include <gp_Ax1.hxx>
90#include <gp_Ax3.hxx>
91#include <gp_Dir.hxx>
92#include <gp_Pnt.hxx>
93#include <gp_Pln.hxx>
94#include <gp_Pnt2d.hxx>
95#include <gp_Trsf.hxx>
96#include <gp_Vec.hxx>
97#include <gp_Vec2d.hxx>
98#include <gp_Circ2d.hxx>
99
100#include <TColgp_SequenceOfPnt.hxx>
101#include <TColStd_SequenceOfReal.hxx>
102#include <BRepFill_TrimSurfaceTool.hxx>
103#include <BRepFill_DataMapOfNodeDataMapOfShapeShape.hxx>
104#include <BRepFill_DataMapOfShapeDataMapOfShapeListOfShape.hxx>
105#include <BRepFill_DataMapOfShapeSequenceOfReal.hxx>
106#include <BRepFill_DataMapOfShapeSequenceOfPnt.hxx>
107#include <BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape.hxx>
108#include <Precision.hxx>
109
110#include <Standard_ConstructionError.hxx>
111#include <Standard_NotImplemented.hxx>
112
113#ifdef DRAW
114#include <DBRep.hxx>
115#include <DrawTrSurf.hxx>
116#include <stdio.h>
117#endif
118
119#ifdef DEB
120static Standard_Boolean AffichGeom = Standard_False;
121static Standard_Boolean AffichEdge = Standard_False;
122static Standard_Integer NbFACES = 0;
123static Standard_Integer NbTRIMFACES = 0;
124static Standard_Integer NbVEVOS = 0;
125static Standard_Integer NbPROFILS = 0;
126static Standard_Integer NbEDGES = 0;
0d969553 127// POP for NT
7fd59977 128#ifndef WNT
129static char name[100];
130#endif
131#endif
132
133static const Standard_Real BRepFill_Confusion()
134{
135 Standard_Real Tol = 1.e-6;
136 return Tol;
137}
138
139static const TopoDS_Wire PutProfilAt (const TopoDS_Wire& ProfRef,
140 const gp_Ax3& AxeRef,
141 const TopoDS_Edge& E,
142 const TopoDS_Face& F,
143 const Standard_Boolean AtStart);
144
145static void TrimFace(const TopoDS_Face& Face,
146 TopTools_SequenceOfShape& TheEdges,
147 TopTools_SequenceOfShape& S);
148
149static void TrimEdge (const TopoDS_Edge& Edge,
150 const TopTools_SequenceOfShape& TheEdgesControle,
151 TopTools_SequenceOfShape& TheVer,
152 TColStd_SequenceOfReal& ThePar,
153 TopTools_SequenceOfShape& S);
154
155static TopAbs_Orientation OriEdgeInFace (const TopoDS_Edge& E,
156 const TopoDS_Face& F);
157
158static Standard_Integer PosOnFace (Standard_Real d1,
159 Standard_Real d2,
160 Standard_Real d3);
161
162static void ComputeIntervals (const TopTools_SequenceOfShape& VonF,
163 const TopTools_SequenceOfShape& VOnL,
164 const TColgp_SequenceOfPnt& ParOnF,
165 const TColgp_SequenceOfPnt& ParOnL,
166 const BRepFill_TrimSurfaceTool& Trim,
167 const Handle(Geom2d_Curve)& Bis,
168 const TopoDS_Vertex& VS,
169 const TopoDS_Vertex& VE,
170 TColStd_SequenceOfReal& FirstPar,
171 TColStd_SequenceOfReal& LastPar,
172 TopTools_SequenceOfShape& FirstV,
173 TopTools_SequenceOfShape& LastV );
174
175static Standard_Real DistanceToOZ (const TopoDS_Vertex& V);
176
177static Standard_Real Altitud (const TopoDS_Vertex& V);
178
179static Standard_Boolean DoubleOrNotInFace (const TopTools_SequenceOfShape& EC,
180 const TopoDS_Vertex& V);
181
182static void SimpleExpression (const Bisector_Bisec& B,
183 Handle(Geom2d_Curve)& Bis);
184
185static TopAbs_Orientation Relative (const TopoDS_Wire& W1,
186 const TopoDS_Wire& W2,
187 const TopoDS_Vertex& V,
188 Standard_Boolean& Commun);
189
190static void CutEdge (const TopoDS_Edge& E,
191 const TopoDS_Face& F,TopTools_ListOfShape& Cuts);
192
193static void CutEdgeProf (const TopoDS_Edge& E,
194 const Handle(Geom_Plane)& Plane,
195 const Handle(Geom2d_Line)& Line,
196 TopTools_ListOfShape& Cuts,
197 TopTools_DataMapOfShapeShape& MapVerRefMoved);
198
199static Standard_Integer VertexFromNode
200(const Handle(MAT_Node)& aNode,
201 const TopoDS_Edge& E,
202 const TopoDS_Vertex& VF,
203 const TopoDS_Vertex& VL,
204 BRepFill_DataMapOfNodeDataMapOfShapeShape& MapNodeVertex,
205 TopoDS_Vertex& VS);
206
207//=======================================================================
208//function : EdgeVertices
209//purpose :
210//=======================================================================
211
212static void EdgeVertices (const TopoDS_Edge& E,
213 TopoDS_Vertex& V1,
214 TopoDS_Vertex& V2)
215{
216 if (E.Orientation() == TopAbs_REVERSED) {
217 TopExp::Vertices(E,V2,V1);
218 }
219 else {
220 TopExp::Vertices(E,V1,V2);
221 }
222}
223
224//=======================================================================
225//function : BRepFill_Evolved
226//purpose :
227//=======================================================================
228
229BRepFill_Evolved::BRepFill_Evolved()
230:
231myIsDone (Standard_False),
232mySpineType(Standard_True)
233{
234}
235
236
237//=======================================================================
238//function : BRepFill_Evolved
239//purpose :
240//=======================================================================
241
242BRepFill_Evolved::BRepFill_Evolved(const TopoDS_Wire& Spine,
243 const TopoDS_Wire& Profile,
244 const gp_Ax3& AxeProf,
245 const GeomAbs_JoinType Join,
246 const Standard_Boolean Solid)
247
248: myIsDone(Standard_False)
249{
250 Perform( Spine, Profile, AxeProf, Join, Solid);
251}
252
253
254//=======================================================================
255//function : BRepFill_Evolved
256//purpose :
257//=======================================================================
258
259BRepFill_Evolved::BRepFill_Evolved(const TopoDS_Face& Spine,
260 const TopoDS_Wire& Profile,
261 const gp_Ax3& AxeProf,
262 const GeomAbs_JoinType Join,
263 const Standard_Boolean Solid)
264: myIsDone(Standard_False)
265{
266 Perform( Spine, Profile, AxeProf, Join, Solid);
267}
268
269//=======================================================================
270//function : IsVertical
271//purpose :
272//=======================================================================
273
274static Standard_Boolean IsVertical(const TopoDS_Edge& E)
275{
276 TopoDS_Vertex V1,V2;
277 TopExp::Vertices(E,V1,V2);
278 gp_Pnt P1 = BRep_Tool::Pnt(V1);
279 gp_Pnt P2 = BRep_Tool::Pnt(V2);
280
281 if ( Abs(P1.Y() - P2.Y()) < BRepFill_Confusion()) {
282 // It is a Line ?
283 TopLoc_Location Loc;
284 Standard_Real f,l;
285 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,Loc,f,l);
286 if ( GC->DynamicType() == STANDARD_TYPE(Geom_Line))
287 return Standard_True;
288 }
289 return Standard_False;
290}
291
292//=======================================================================
293//function : IsPlanar
294//purpose :
295//=======================================================================
296
297static Standard_Boolean IsPlanar(const TopoDS_Edge& E)
298{
299 TopoDS_Vertex V1,V2;
300 TopExp::Vertices(E,V1,V2);
301 gp_Pnt P1 = BRep_Tool::Pnt(V1);
302 gp_Pnt P2 = BRep_Tool::Pnt(V2);
303
304 if ( Abs(P1.Z() - P2.Z()) < BRepFill_Confusion()) {
305 // It is a Line ?
306 TopLoc_Location Loc;
307 Standard_Real f,l;
308 Handle(Geom_Curve) GC = BRep_Tool::Curve(E,Loc,f,l);
309 if ( GC->DynamicType() == STANDARD_TYPE(Geom_Line))
310 return Standard_True;
311 }
312 return Standard_False;
313
314}
315
316//=======================================================================
317//function : Side
0d969553 318//purpose : determine the position of the profil correspondingly to plane XOZ.
7fd59977 319// Return 1 : MAT_Left.
320// Return 2 : MAT_Left and Planar.
321// Return 3 : MAT_Left and Vertical.
322// Return 4 : MAT_Right.
323// Return 5 : MAT_Right and Planar.
324// Return 6 : MAT_Right and Vertical.
325//=======================================================================
326
327static Standard_Integer Side(const TopoDS_Wire& Profil,
328 const Standard_Real Tol)
329{
7fd59977 330 TopoDS_Vertex V1,V2;
0d969553
Y
331 // Rem : it is enough to test the first edge of the Wire.
332 // ( Correctly cut in PrepareProfil)
7fd59977 333 TopExp_Explorer Explo(Profil,TopAbs_EDGE);
334
335 Standard_Integer TheSide;
336 const TopoDS_Edge& E = TopoDS::Edge(Explo.Current());
337
338 TopExp::Vertices(E,V1,V2);
339 gp_Pnt P1 = BRep_Tool::Pnt(V1);
340 gp_Pnt P2 = BRep_Tool::Pnt(V2);
341
342 if ( P1.Y() < -Tol || P2.Y() < -Tol) TheSide = 4;
343 else TheSide = 1;
344 if (IsVertical(E)) TheSide+=2;
345 else if (IsPlanar(E)) TheSide++;
346 return TheSide;
347}
348
349
350//=======================================================================
351//function : Perform
352//purpose :
353//=======================================================================
354
355void BRepFill_Evolved::Perform(const TopoDS_Wire& Spine,
356 const TopoDS_Wire& Profile,
357 const gp_Ax3& AxeProf,
358 const GeomAbs_JoinType Join,
359 const Standard_Boolean Solid)
360{
361 mySpineType = Standard_False;
362 TopoDS_Face aFace = BRepLib_MakeFace(Spine,Standard_True);
363 PrivatePerform( aFace, Profile, AxeProf, Join, Solid);
364}
365
366//=======================================================================
367//function : Perform
368//purpose :
369//=======================================================================
370
371void BRepFill_Evolved::Perform(const TopoDS_Face& Spine,
372 const TopoDS_Wire& Profile,
373 const gp_Ax3& AxeProf,
374 const GeomAbs_JoinType Join,
375 const Standard_Boolean Solid)
376{
377 mySpineType = Standard_True;
378 PrivatePerform( Spine, Profile, AxeProf, Join, Solid);
379}
380
381//=======================================================================
382//function : PrivatePerform
383//purpose :
384//=======================================================================
385
386void BRepFill_Evolved::PrivatePerform(const TopoDS_Face& Spine,
387 const TopoDS_Wire& Profile,
388 const gp_Ax3& AxeProf,
389 const GeomAbs_JoinType Join,
390 const Standard_Boolean Solid)
391{
392 TopoDS_Shape aLocalShape = Spine.Oriented(TopAbs_FORWARD);
393 mySpine = TopoDS::Face(aLocalShape);
394// mySpine = TopoDS::Face(Spine.Oriented(TopAbs_FORWARD));
395 aLocalShape = Profile.Oriented(TopAbs_FORWARD);
396 myProfile = TopoDS::Wire(aLocalShape);
397// myProfile = TopoDS::Wire(Profile.Oriented(TopAbs_FORWARD));
398 myJoinType = Join;
399 myMap.Clear();
400
401 if (myJoinType > GeomAbs_Arc) {
402 Standard_NotImplemented::Raise();
403 }
404
405 TopTools_ListOfShape WorkProf;
406 TopoDS_Face WorkSpine;
407 TopTools_ListIteratorOfListOfShape WPIte;
408
409 //-------------------------------------------------------------------
0d969553 410 // Positioning of mySpine and myProfil in the workspace.
7fd59977 411 //-------------------------------------------------------------------
412 TopLoc_Location LSpine = FindLocation(mySpine);
413 gp_Trsf T;
414 T.SetTransformation(AxeProf);
415 TopLoc_Location LProfile (T);
416 TopLoc_Location InitLS = mySpine .Location();
417 TopLoc_Location InitLP = myProfile.Location();
418 TransformInitWork(LSpine,LProfile);
419
420 //------------------------------------------------------------------
0d969553 421 // projection of the profile and cut of the spine.
7fd59977 422 //------------------------------------------------------------------
423 TopTools_DataMapOfShapeShape MapProf, MapSpine;
424
425 PrepareProfile(WorkProf , MapProf);
426 PrepareSpine (WorkSpine, MapSpine);
427
428 Standard_Real Tol = BRepFill_Confusion();
429 Standard_Boolean YaLeft = Standard_False;
430 Standard_Boolean YaRight = Standard_False;
431 TopoDS_Wire SP;
432
433 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
434 SP = TopoDS::Wire(WPIte.Value());
435 if ( Side(SP,Tol) < 4) YaLeft = Standard_True;
436 else YaRight = Standard_True;
437 if (YaLeft && YaRight) break;
438 }
439
440 TopoDS_Face Face;
441 BRepMAT2d_BisectingLocus Locus;
442
443 //----------------------------------------------------------
0d969553
Y
444 // Initialisation of cut volevo.
445 // For each part of the profile create a volevo added to CutVevo
7fd59977 446 //----------------------------------------------------------
447 BRepFill_Evolved CutVevo;
448 TopoDS_Wire WP;
449 BRep_Builder BB;
450 BRepTools_WireExplorer WExp;
451
452 BB.MakeWire(WP);
453
454 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
455 for (WExp.Init(TopoDS::Wire(WPIte.Value())); WExp.More(); WExp.Next()) {
456 BB.Add(WP,WExp.Current());
457 }
458 }
459 CutVevo.SetWork(WorkSpine,WP);
460
461 BRepTools_Quilt Glue;
462 Standard_Integer CSide;
463
464 //---------------------------------
0d969553 465 // Construction of vevos to the left.
7fd59977 466 //---------------------------------
467 if (YaLeft) {
468 //-----------------------------------------------------
0d969553
Y
469 // Calculate the map of bisector locations at the left.
470 // and links Topology -> base elements of the map.
7fd59977 471 //-----------------------------------------------------
472 BRepMAT2d_Explorer Exp(WorkSpine);
473 Locus.Compute(Exp,1,MAT_Left);
474 BRepMAT2d_LinkTopoBilo Link(Exp,Locus);
475
476 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
477 SP = TopoDS::Wire(WPIte.Value());
478 CSide = Side(SP,Tol);
479 //-----------------------------------------------
0d969553 480 // Construction and adding of elementary volevo.
7fd59977 481 //-----------------------------------------------
482 BRepFill_Evolved Vevo;
483 if ( CSide == 1) {
484 Vevo.ElementaryPerform (WorkSpine, SP, Locus, Link, Join);
485 }
486 else if (CSide == 2) {
487 Vevo.PlanarPerform (WorkSpine, SP, Locus, Link, Join);
488 }
489 else if (CSide == 3) {
490 Vevo.VerticalPerform (WorkSpine, SP, Locus, Link, Join);
491 }
492 CutVevo.Add (Vevo, SP, Glue);
493 }
494 }
495
496 //---------------------------------
0d969553 497 // Construction of vevos to the right.
7fd59977 498 //---------------------------------
499 if (YaRight) {
500 //-----------------------------------
0d969553 501 // Decomposition of the face into wires.
7fd59977 502 //-----------------------------------
503 TopExp_Explorer SpineExp (WorkSpine, TopAbs_WIRE);
504 for ( ; SpineExp.More(); SpineExp.Next()) {
505 //----------------------------------------------
0d969553 506 // Calculate the map to the right of the current wire.
7fd59977 507 //----------------------------------------------
508 BRepLib_MakeFace B(gp_Pln(0.,0.,1.,0.));
509 TopoDS_Shape aLocalShape = SpineExp.Current().Reversed();
510 B.Add(TopoDS::Wire(aLocalShape));
511// B.Add(TopoDS::Wire(SpineExp.Current().Reversed()));
512 Face = B.Face();
513 BRepMAT2d_Explorer Exp(Face);
514 Locus.Compute(Exp,1,MAT_Left);
515 BRepMAT2d_LinkTopoBilo Link(Exp,Locus);
516
517 for (WPIte.Initialize(WorkProf); WPIte.More(); WPIte.Next()) {
518 SP = TopoDS::Wire(WPIte.Value());
519 CSide = Side(SP,Tol);
520 //-----------------------------------------------
0d969553 521 // Construction and adding of an elementary volevo
7fd59977 522 //-----------------------------------------------
523 BRepFill_Evolved Vevo;
524 if ( CSide == 4) {
525 Vevo.ElementaryPerform (Face, SP, Locus, Link, Join);
526 }
527 else if (CSide == 5) {
528 Vevo.PlanarPerform (Face, SP, Locus, Link, Join);
529 }
530 else if (CSide == 6) {
531 Vevo.VerticalPerform (Face, SP, Locus, Link, Join);
532 }
533 CutVevo.Add (Vevo, SP, Glue);
534 }
535 }
536 }
537
538 if (Solid) CutVevo.AddTopAndBottom(Glue);
539
540 //-------------------------------------------------------------------------
0d969553
Y
541 // Gluing of regularites on parallel edges generate4d by vertices of the
542 // cut of the profile.
7fd59977 543 //-------------------------------------------------------------------------
544 CutVevo.ContinuityOnOffsetEdge(WorkProf);
545
546 //-----------------------------------------------------------------
0d969553
Y
547 // construction of the shape via the quilt, ie:
548 // - sharing of topologies of elementary added volevos.
549 // - Orientation of faces correspondingly to each other.
7fd59977 550 //-----------------------------------------------------------------
551 TopoDS_Shape& SCV = CutVevo.ChangeShape();
552 SCV = Glue.Shells();
553 //------------------------------------------------------------------------
0d969553
Y
554 // Transfer of the map of generated elements and of the shape of Cutvevo
555 // in myMap and repositioning in the initial space.
7fd59977 556 //------------------------------------------------------------------------
557 Transfert (CutVevo, MapProf, MapSpine, LSpine.Inverted(), InitLS, InitLP);
558
0d969553 559 //Orientation of the solid.
7fd59977 560 if (Solid) MakeSolid();
561
562// modified by NIZHNY-EAP Mon Jan 24 11:26:48 2000 ___BEGIN___
563 BRepLib::UpdateTolerances(myShape,Standard_False);
564// modified by NIZHNY-EAP Mon Jan 24 11:26:50 2000 ___END___
565 myIsDone = Standard_True;
566}
567
568
569
570//=======================================================================
571//function : IsInversed
572//purpose :
573//=======================================================================
574
575static void IsInversed(const TopoDS_Shape& S,
576 const TopoDS_Edge& E1,
577 const TopoDS_Edge& E2,
578 Standard_Boolean* Inverse)
579{
580
581 Inverse[0] = Inverse[1] = 0;
582 if (S.ShapeType() != TopAbs_EDGE) return;
583
584 gp_Pnt P;
585 gp_Vec DS,DC1,DC2 ;
586 BRepAdaptor_Curve CS(TopoDS::Edge(S));
587 if (S.Orientation() == TopAbs_FORWARD) {
588 CS.D1(CS.FirstParameter(),P,DS);
589 }
590 else {
591 CS.D1(CS.LastParameter(),P,DS);
592 DS.Reverse();
593 }
594
595
596 if (!BRep_Tool::Degenerated(E1)) {
597 BRepAdaptor_Curve C1(TopoDS::Edge(E1));
598 if (E1.Orientation() == TopAbs_FORWARD) {
599 C1.D1(C1.FirstParameter(),P,DC1);
600 }
601 else {
602 C1.D1(C1.LastParameter(),P,DC1);
603 DC1.Reverse();
604 }
605 Inverse[0] = (DS.Dot(DC1) < 0.);
606 }
607 else Inverse[0] = 1;
608
609 if (!BRep_Tool::Degenerated(E2)) {
610 BRepAdaptor_Curve C2(TopoDS::Edge(E2));
611 if (E2.Orientation() == TopAbs_FORWARD) {
612 C2.D1(C2.FirstParameter(),P,DC2);
613 }
614 else {
615 C2.D1(C2.LastParameter(),P,DC2);
616 DC2.Reverse();
617 }
618 Inverse[1] = (DS.Dot(DC2) < 0.);
619 }
620 else Inverse[1] = 1;
621}
622
623//=======================================================================
624//function : SetWork
625//purpose :
626//=======================================================================
627
628void BRepFill_Evolved::SetWork(const TopoDS_Face& Sp,
629 const TopoDS_Wire& Pr)
630{
631 mySpine = Sp;
632 myProfile = Pr;
633}
634
635//=======================================================================
636//function : ConcaveSide
0d969553
Y
637//purpose : Determine if the pipes were at the side of the
638// concavity. In this case they can be closed.
639// WARNING: Not finished. Done only for circles.
7fd59977 640//=======================================================================
641
642static Standard_Boolean ConcaveSide(const TopoDS_Shape& S,
643 const TopoDS_Face& F)
644{
645
646 if (S.ShapeType() == TopAbs_VERTEX) return Standard_False;
647
648 if (S.ShapeType() == TopAbs_EDGE) {
649 Standard_Real f,l;
650 Handle(Geom2d_Curve) G2d =
651 BRep_Tool::CurveOnSurface(TopoDS::Edge(S),F,f,l);
652 Handle(Geom2d_Curve) G2dOC;
653
654 Geom2dAdaptor_Curve AC(G2d,f,l);
655 if ( AC.GetType() == GeomAbs_Circle) {
656 Standard_Boolean Direct = AC.Circle().IsDirect();
657 if (S.Orientation() == TopAbs_REVERSED) Direct = (!Direct);
658 return Direct;
659 }
660 }
661 return Standard_False;
662}
663
664//=======================================================================
665//function : ElementaryPerform
666//purpose :
667//=======================================================================
668
669void BRepFill_Evolved::ElementaryPerform (const TopoDS_Face& Sp,
670 const TopoDS_Wire& Pr,
671 const BRepMAT2d_BisectingLocus& Locus,
672 BRepMAT2d_LinkTopoBilo& Link,
673 const GeomAbs_JoinType Join)
674{
675
676#ifdef DRAW
677 if (AffichEdge) {
678 sprintf(name,"PROFIL_%d",++NbPROFILS);
679 DBRep::Set(name,Pr);
680 }
681#endif
682 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
683 mySpine = TopoDS::Face(aLocalShape);
684// mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
685 myProfile = Pr;
686 myMap.Clear();
687
688 BRep_Builder myBuilder;
689 myBuilder.MakeCompound(TopoDS::Compound(myShape));
690
691 //---------------------------------------------------------------------
0d969553
Y
692 // MapNodeVertex : associate to each node of the map (key1) and
693 // to each element of the profile (key2) a vertex (item).
694 // MapBis : a set of edges or vertexes (item) generated by
695 // a bisectrice on a face or an edge (key) of
696 // tubes or revolutions.
697 // MapVerPar : Map of parameters of vertices on parallel edges
698 // the list contained in MapVerPar (E) corresponds
699 // to parameters on E of vertices contained in MapBis(E);
700 // MapBS : links BasicElt of the map => Topology of the spine.
7fd59977 701 //---------------------------------------------------------------------
702
703
704 BRepFill_DataMapOfNodeDataMapOfShapeShape MapNodeVertex;
705 TopTools_DataMapOfShapeSequenceOfShape MapBis;
706 BRepFill_DataMapOfShapeSequenceOfReal MapVerPar;
707
708 TopTools_DataMapOfShapeShape EmptyMap;
709 TopTools_SequenceOfShape EmptySeq;
710 TopTools_ListOfShape EmptyList;
711 TColStd_SequenceOfReal EmptySeqOfReal;
712
0d969553 713 // mark of the profile.
7fd59977 714 gp_Ax3 AxeRef(gp_Pnt(0.,0.,0.),
715 gp_Dir(0.,0.,1.),
716 gp_Dir(1.,0.,0.));
717
718 //---------------------------------------------------------------
0d969553 719 // Construction of revolutions and tubes.
7fd59977 720 //---------------------------------------------------------------
721 BRepTools_WireExplorer ProfExp;
722 TopExp_Explorer FaceExp;
723 BRepTools_WireExplorer WireExp;
724
725 for (FaceExp.Init(mySpine,TopAbs_WIRE); FaceExp.More(); FaceExp.Next()){
726
727 for (WireExp.Init(TopoDS::Wire(FaceExp.Current())); WireExp.More();
728 WireExp.Next()) {
729
730 TopoDS_Edge CurrentEdge = WireExp.Current();
731 TopoDS_Vertex VFirst,VLast;
732 EdgeVertices(CurrentEdge,VFirst,VLast);
733
734 for (Link.Init(VLast); Link.More(); Link.Next()) {
0d969553
Y
735 //----------------------------.
736 //Construction of a Revolution
737 //----------------------------.
7fd59977 738 MakeRevol (CurrentEdge, VLast, AxeRef);
739 }
740
741 for (Link.Init(CurrentEdge); Link.More(); Link.Next()) {
742 //------------------------.
0d969553 743 //Construction of a Tube
7fd59977 744 //-------------------------
745 MakePipe (CurrentEdge, AxeRef);
746 }
747 }
748 }
749
750#ifdef DRAW
751 if (AffichEdge) {
0d969553 752 cout << " End Construction of geometric primitives"<<endl;
7fd59977 753 }
754#endif
755
756 TopoDS_Vertex VF,VL;
757
758 //---------------------------------------------------
0d969553 759 // Construction of edges associated to bissectrices.
7fd59977 760 //---------------------------------------------------
761 Handle(MAT_Arc) CurrentArc;
762 Handle(Geom2d_Curve) Bis, PCurve1, PCurve2 ;
763 Handle(Geom_Curve) CBis;
764 Standard_Boolean Reverse;
765 TopoDS_Edge CurrentEdge;
766 TopoDS_Shape S [2];
767 TopoDS_Face F [2];
768 TopoDS_Edge E [4];
769 TopLoc_Location L;
770 Standard_Integer k;
771
772 for (Standard_Integer i = 1; i <= Locus.Graph()->NumberOfArcs(); i++) {
773 CurrentArc = Locus.Graph()->Arc(i);
774 SimpleExpression(Locus.GeomBis(CurrentArc,Reverse), Bis);
775
0d969553
Y
776 //------------------------------------------------------------------
777 // Return elements of the spine corresponding to separate basicElts.
778 //------------------------------------------------------------------
7fd59977 779 S [0] = Link.GeneratingShape(CurrentArc->FirstElement());
780 S [1] = Link.GeneratingShape(CurrentArc->SecondElement());
781
782 Standard_Boolean Concave0 = ConcaveSide(S[0],mySpine);
783 Standard_Boolean Concave1 = ConcaveSide(S[1],mySpine);
784
785 TopTools_SequenceOfShape VOnF,VOnL;
786 TColgp_SequenceOfPnt ParOnF,ParOnL;
787
788 TopTools_DataMapOfShapeSequenceOfShape MapSeqVer;
789 BRepFill_DataMapOfShapeSequenceOfPnt MapSeqPar;
790
791 Standard_Integer vv = 0;
792 for(ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()) {
793 vv++;
0d969553
Y
794 //-----------------------------------------------
795 // Return two faces separated by the bissectrice.
796 //-----------------------------------------------
7fd59977 797 F [0] = TopoDS::Face(myMap(S[0])(ProfExp.Current()).First());
798 F [1] = TopoDS::Face(myMap(S[1])(ProfExp.Current()).First());
799
0d969553
Y
800 //------------------------------------
801 // Return parallel edges on each face.
802 //------------------------------------
7fd59977 803 TopoDS_Vertex VF,VL;
804
805 EdgeVertices(ProfExp.Current(),VF,VL);
806
807 E [0] = TopoDS::Edge(myMap(S[0])(VF).First());
808 E [1] = TopoDS::Edge(myMap(S[0])(VL).First());
809 E [2] = TopoDS::Edge(myMap(S[1])(VF).First());
810 E [3] = TopoDS::Edge(myMap(S[1])(VL).First());
811
812 Standard_Boolean Inv0[2];
813 Standard_Boolean Inv1[2];
814
815 Inv0[0] = Inv0[1] = Inv1[0]= Inv1[1] = 0;
816 if (Concave0) IsInversed(S[0],E[0],E[1],Inv0);
817 if (Concave1) IsInversed(S[1],E[2],E[3],Inv1);
818
819 //---------------------------------------------
0d969553 820 // Construction of geometries.
7fd59977 821 //---------------------------------------------
822 BRepFill_TrimSurfaceTool Trim (Bis,F[0],F[1],
823 E[0],E[2],Inv0[0],Inv1[0]);
824 //-----------------------------------------------------------
0d969553 825 //Construction of vertices corresponding to the node of the map
7fd59977 826 //-----------------------------------------------------------
827 TopoDS_Vertex VS,VE;
828 Handle(MAT_Node) Node1, Node2;
829
830 if (Reverse) {
831 Node1 = CurrentArc->SecondNode();
832 Node2 = CurrentArc->FirstNode();
833 }
834 else {
835 Node1 = CurrentArc->FirstNode();
836 Node2 = CurrentArc->SecondNode();
837 }
838 //--------------------------------------------------------
0d969553 839 // Particular case when the node is on a vertex of the spine.
7fd59977 840 //--------------------------------------------------------
841 if (Node1->OnBasicElt()) {
842 if (S[0].ShapeType() == TopAbs_VERTEX) {
843 Node1 = CurrentArc->FirstElement()->StartArc()->FirstNode();
844 }
845 else if (S[1].ShapeType() == TopAbs_VERTEX) {
846 Node1 = CurrentArc->SecondElement()->StartArc()->FirstNode();
847 }
848 }
0d969553 849 // End of particular case.
7fd59977 850
851 Standard_Integer
852 StartOnF = VertexFromNode(Node1,
853 TopoDS::Edge(ProfExp.Current()),
854 VF, VL ,
855 MapNodeVertex,VS);
856
857 Standard_Integer
858 EndOnF = VertexFromNode(Node2,
859 TopoDS::Edge(ProfExp.Current()),
860 VF, VL ,
861 MapNodeVertex,VE);
862
863 //-----------------------------------------------------------
0d969553 864 // Construction of vertices on edges parallel to the spine.
7fd59977 865 //-----------------------------------------------------------
866 if (!MapSeqVer.IsBound(VF)) {
867 if (Inv0 [0] || Inv1 [0]) {
868 ParOnF.Clear();
869 VOnF .Clear();
870 }
871 else {
872 Trim.IntersectWith(E [0], E [2], ParOnF);
873 VOnF .Clear();
874 for (Standard_Integer s = 1; s <= ParOnF.Length(); s++) {
875 TopoDS_Vertex VC;
876 myBuilder.MakeVertex (VC);
877 VOnF.Append(VC);
878 }
879 if (StartOnF == 1) {
880 VOnF .SetValue(1,VS);
881 }
882 if (EndOnF == 1) {
883 VOnF .SetValue(ParOnF.Length(),VE);
884 }
885 }
886 }
887 else {
888 ParOnF = MapSeqPar(VF);
889 VOnF = MapSeqVer(VF);
890 }
891
892 if (!MapSeqVer.IsBound(VL)) {
893 if (Inv0 [1] || Inv1 [1]) {
894 ParOnL.Clear();
895 VOnL .Clear();
896 }
897 else {
898 Trim.IntersectWith(E [1], E [3], ParOnL);
899 VOnL.Clear();
900 for (Standard_Integer s = 1; s <= ParOnL.Length(); s++) {
901 TopoDS_Vertex VC;
902 myBuilder.MakeVertex (VC);
903 VOnL.Append(VC);
904 }
905 if (StartOnF == 3) {
906 VOnL .SetValue(1,VS);
907 }
908 if (EndOnF == 3) {
909 VOnL .SetValue(ParOnL.Length(),VE);
910 }
911 }
912 }
913 else {
914 ParOnL = MapSeqPar(VL);
915 VOnL = MapSeqVer(VL);
916 }
917
0d969553
Y
918 //------------------------------------------------------
919 // Test if the Bissectrice is not projected on the face
920 //------------------------------------------------------
7fd59977 921 if ((StartOnF == 0) && (EndOnF == 0) &&
922 VOnL.IsEmpty() && VOnF.IsEmpty())
0d969553 923 // No trace of the bisectrice on the face.
7fd59977 924 continue;
925
926 if ((StartOnF == 0) && (EndOnF == 0) &&
927 (VOnL.Length() + VOnF.Length() == 1))
0d969553
Y
928 // the first or last node of the arc is on the edge
929 // but the arc is not on the face.
7fd59977 930 continue;
931
932 //---------------------------------------------------------
0d969553
Y
933 // determine the intervals of the bissectrice that are
934 // projected on F[0] and F[1].
7fd59977 935 //---------------------------------------------------------
936 TColStd_SequenceOfReal LastPar,FirstPar;
937 TopTools_SequenceOfShape FirstV,LastV;
938
939 ComputeIntervals (VOnF,VOnL,ParOnF,ParOnL,Trim,Bis,
940 VS,VE,FirstPar,LastPar,FirstV,LastV);
941
942 for (Standard_Integer Ti = 1; Ti <= FirstPar.Length(); Ti++) {
943 TopoDS_Vertex V1 = TopoDS::Vertex(FirstV.Value(Ti));
944 TopoDS_Vertex V2 = TopoDS::Vertex(LastV .Value(Ti));
945
946 GeomAbs_Shape Continuity;
947
948 Trim.Project(FirstPar.Value(Ti),LastPar.Value(Ti),
949 CBis,PCurve1,PCurve2,Continuity);
950
951 //-------------------------------------
0d969553 952 // Coding of the edge.
7fd59977 953 //-------------------------------------
954 myBuilder.MakeEdge(CurrentEdge, CBis,
955 BRepFill_Confusion());
956
957 myBuilder.UpdateVertex(V1,CBis->Value(CBis->FirstParameter()),
958 BRepFill_Confusion());
959 myBuilder.UpdateVertex(V2,CBis->Value(CBis->LastParameter()),
960 BRepFill_Confusion());
961
962 myBuilder.Add(CurrentEdge,V1.Oriented(TopAbs_FORWARD));
963 myBuilder.Add(CurrentEdge,V2.Oriented(TopAbs_REVERSED));
964
965 myBuilder.Range(CurrentEdge,
966 CBis->FirstParameter(),
967 CBis->LastParameter());
968 myBuilder.UpdateEdge(CurrentEdge,PCurve1,F[0],BRepFill_Confusion());
969 myBuilder.UpdateEdge(CurrentEdge,PCurve2,F[1],BRepFill_Confusion());
970
971 myBuilder.Continuity(CurrentEdge,F[0],F[1],Continuity);
972
973#ifdef DRAW
974 if (AffichEdge) {
975 sprintf(name,"ARCEDGE_%d_%d_%d",i,vv,Ti);
976 DBRep::Set(name,CurrentEdge);
977 }
978#endif
979 //-------------------------------------------
0d969553 980 // Storage of the edge for each of faces.
7fd59977 981 //-------------------------------------------
982 for (k = 0; k <= 1;k++) {
983 if (!MapBis.IsBound(F[k])) {
984 MapBis.Bind(F[k],EmptySeq);
985 }
986 }
987 //---------------------------------------------------------------
0d969553
Y
988 // orientation of the edge depends on the direction of the skin.
989 // skin => same orientation E[0] , inverted orientation E[2]
990 // if contreskin it is inverted.
7fd59977 991 //--------------------------------------------------------------
992 E[0].Orientation(OriEdgeInFace(E[0],F[0]));
993 E[2].Orientation(OriEdgeInFace(E[2],F[1]));
994
995 if (DistanceToOZ(VF) < DistanceToOZ(VL) ) {
0d969553 996 // Skin
7fd59977 997 MapBis(F[0]).Append(CurrentEdge.Oriented (E[0].Orientation()));
998 CurrentEdge.Orientation(TopAbs::Complement(E[2].Orientation()));
999 MapBis(F[1]).Append(CurrentEdge);
1000 }
1001 else {
0d969553 1002 //Contreskin
7fd59977 1003 MapBis(F[1]).Append(CurrentEdge.Oriented (E[2].Orientation()));
1004 CurrentEdge.Orientation(TopAbs::Complement(E[0].Orientation()));
1005 MapBis(F[0]).Append(CurrentEdge);
1006 }
1007 }
1008
1009 //----------------------------------------------
0d969553
Y
1010 // Storage of vertices on parallel edges.
1011 // fill MapBis and MapVerPar.
1012 // VOnF for E[0] and E[2].
1013 // VOnL for E[1] and E[3].
7fd59977 1014 //----------------------------------------------
1015 for (k = 0; k <= 2; k = k+2) {
1016 if ( !MapSeqVer.IsBound(VF)) {
1017 if (!VOnF.IsEmpty()) {
1018 if (!MapBis.IsBound(E[k])) {
1019 MapBis .Bind(E[k],EmptySeq);
1020 MapVerPar.Bind(E[k],EmptySeqOfReal);
1021 }
1022 for (Standard_Integer ii = 1; ii <= VOnF.Length(); ii++) {
1023 MapBis (E[k]).Append(VOnF.Value(ii));
1024 if (k == 0) MapVerPar (E[k]).Append(ParOnF.Value(ii).Y());
1025 else MapVerPar (E[k]).Append(ParOnF.Value(ii).Z());
1026 }
1027 }
1028 }
1029 }
1030
1031 for (k = 1; k <= 3; k = k+2) {
1032 if ( !MapSeqVer.IsBound(VL)) {
1033 if (!VOnL.IsEmpty()) {
1034 if (!MapBis.IsBound(E[k])) {
1035 MapBis .Bind(E[k],EmptySeq);
1036 MapVerPar.Bind(E[k],EmptySeqOfReal);
1037 }
1038 for (Standard_Integer ii = 1; ii <= VOnL.Length(); ii++) {
1039 MapBis(E[k]).Append(VOnL.Value(ii));
1040 if (k == 1) MapVerPar (E[k]).Append(ParOnL.Value(ii).Y());
1041 else MapVerPar (E[k]).Append(ParOnL.Value(ii).Z());
1042 }
1043 }
1044 }
1045 }
1046
1047 //----------------------------------------------------------------
0d969553
Y
1048 // Edge [1] of the current face will be Edge [0] of the next face.
1049 // => copy of VonL in VonF. To avoid creating the same vertices twice.
7fd59977 1050 //-----------------------------------------------------------------
1051
1052 MapSeqPar.Bind(VF,ParOnF);
1053 MapSeqVer.Bind(VF,VOnF);
1054 MapSeqPar.Bind(VL,ParOnL);
1055 MapSeqVer.Bind(VL,VOnL);
1056
1057 }
1058 }
1059
1060#ifdef DEB
1061 if (AffichEdge) {
0d969553 1062 cout << " End of Construction of edges and vertices on bissectrices"<<endl;
7fd59977 1063 }
1064#endif
1065
1066 //----------------------------------
0d969553 1067 // Construction of parallel edges.
7fd59977 1068 //----------------------------------
1069 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape ite1;
1070 TopoDS_Shape CurrentProf,PrecProf;
1071 TopoDS_Face CurrentFace;
1072 TopoDS_Shape CurrentSpine;
1073 TopoDS_Vertex VCF,VCL;
1074
1075 for (ite1.Initialize(myMap); ite1.More(); ite1.Next()) {
1076 CurrentSpine = ite1.Key();
1077
1078 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1079 CurrentProf = ProfExp.Current();
1080 EdgeVertices(TopoDS::Edge(CurrentProf),VCF,VCL);
1081 CurrentEdge = TopoDS::Edge(myMap(CurrentSpine)(VCF).First());
1082
1083 //-------------------------------------------------------------
0d969553
Y
1084 //RQ : Current Edge is oriented relatively to the face (oriented forward)
1085 // generated by edge CurrentProf .
7fd59977 1086 //-------------------------------------------------------------
1087 if (MapBis.IsBound(CurrentEdge)) {
1088
1089 //--------------------------------------------------------
0d969553
Y
1090 // Find if one of two faces connected to the edge
1091 // belongs to volevo. The edges on this face serve
1092 // to eliminate certain vertices that can appear twice
1093 // on the parallel edge. These Vertices corespond to the
1094 // nodes of the map.
7fd59977 1095 //---------------------------------------------------------
1096 TopoDS_Shape FaceControle;
1097 Standard_Boolean YaFace = Standard_True;
1098
1099 FaceControle = myMap(CurrentSpine)(CurrentProf).First();
1100 if (!MapBis.IsBound(FaceControle)){
1101 YaFace = Standard_False;
1102 if (!PrecProf.IsNull()) {
1103 FaceControle = myMap(CurrentSpine)(PrecProf).First();
1104 if (MapBis.IsBound(FaceControle)){
1105 YaFace = Standard_True;
1106 }
1107 }
1108 }
1109
1110 if (YaFace) {
1111 //------------------------------------------------------------
0d969553 1112 // No connected face in the volevo => no parallel edge.
7fd59977 1113 //------------------------------------------------------------
1114 TopTools_SequenceOfShape S;
1115 TrimEdge (CurrentEdge,
1116 MapBis (FaceControle),
1117 MapBis (CurrentEdge) ,
1118 MapVerPar(CurrentEdge) , S);
1119
1120 for ( k = 1; k <= S.Length(); k++) {
1121 myMap(CurrentSpine)(VCF).Append(S.Value(k));
1122
1123#ifdef DRAW
1124 if (AffichEdge) {
1125 sprintf(name,"PAREDGE_%d_%d",++NbEDGES,k);
1126 DBRep::Set(name,S.Value(k));
1127 }
1128#endif
1129 }
1130 }
1131 }
1132 PrecProf = CurrentProf;
1133 }
1134
1135 //------------------------------------------------------------
0d969553 1136 // Construction of the parallel edge from the last vertex of myProfile.
7fd59977 1137 //------------------------------------------------------------
1138 CurrentEdge = TopoDS::Edge(myMap(CurrentSpine)(VCL).First());
1139
1140 if (MapBis.IsBound(CurrentEdge)) {
1141 Standard_Boolean YaFace = Standard_True;
1142 TopoDS_Shape FaceControle;
1143
1144 FaceControle = myMap(CurrentSpine)(CurrentProf).First();
1145 if (!MapBis.IsBound(FaceControle)){
1146 YaFace = Standard_False;
1147 }
0d969553
Y
1148 // the number of element of the list allows to know
1149 // if the edges have already been done (closed profile) .
7fd59977 1150 if (YaFace && myMap(CurrentSpine)(VCL).Extent()<= 1) {
1151 TopTools_SequenceOfShape S;
1152 TrimEdge (CurrentEdge,
1153 MapBis (FaceControle),
1154 MapBis (CurrentEdge) ,
1155 MapVerPar(CurrentEdge) , S);
1156
1157 for ( k = 1; k <= S.Length(); k++) {
1158 myMap(CurrentSpine)(VCL).Append(S.Value(k));
1159
1160#ifdef DRAW
1161 if (AffichEdge) {
1162 sprintf(name,"PAREDGE_%d_%d",++NbEDGES,k);
1163 DBRep::Set(name,S.Value(k));
1164 }
1165#endif
1166 }
1167 }
1168 }
1169 }
1170
1171#ifdef DRAW
1172 if (AffichEdge) {
0d969553 1173 cout <<" End Construction of parallel edges "<<endl;
7fd59977 1174 }
1175#endif
1176
1177 //-------------------------------------------------------------------
0d969553 1178 // Cut faces by edges.
7fd59977 1179 //-------------------------------------------------------------------
1180 for (ite1.Initialize(myMap); ite1.More(); ite1.Next()) {
1181 CurrentSpine = ite1.Key();
1182
1183 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1184 CurrentProf = ProfExp.Current();
1185 CurrentFace = TopoDS::Face(myMap(CurrentSpine)(CurrentProf).First());
1186 myMap(CurrentSpine)(CurrentProf).Clear();
1187
1188 if (MapBis.IsBound(CurrentFace)) {
1189 //----------------------------------------------------------
0d969553
Y
1190 // If the face does not contain edges that can limit it
1191 // it does not appear in volevo.
1192 // cut of face by edges can generate many faces.
7fd59977 1193 //
0d969553
Y
1194 // Add edges generated on the edges parallel to the set
1195 // of edges that limit the face.
7fd59977 1196 //
1197 //------------------------------------------------------------
1198 EdgeVertices(TopoDS::Edge(CurrentProf),VCF,VCL);
1199
1200 TopTools_ListIteratorOfListOfShape itl;
1201 const TopTools_ListOfShape& LF = myMap(CurrentSpine)(VCF);
1202
1203 TopAbs_Orientation Ori = OriEdgeInFace(TopoDS::Edge(LF.First()),
1204 CurrentFace);
1205 for (itl.Initialize(LF), itl.Next(); itl.More(); itl.Next()) {
1206 TopoDS_Edge RE = TopoDS::Edge(itl.Value());
1207 MapBis(CurrentFace).Append(RE.Oriented(Ori));
1208 }
1209 const TopTools_ListOfShape& LL = myMap(CurrentSpine)(VCL);
1210 Ori = OriEdgeInFace(TopoDS::Edge(LL.First()),CurrentFace);
1211 for (itl.Initialize(LL), itl.Next() ; itl.More(); itl.Next()) {
1212 TopoDS_Edge RE = TopoDS::Edge(itl.Value());
1213 MapBis(CurrentFace).Append(RE.Oriented(Ori));
1214 }
1215
0d969553 1216 //Cut of the face.
7fd59977 1217 TopTools_SequenceOfShape S;
1218
1219 TrimFace (CurrentFace, MapBis(CurrentFace), S);
1220
1221 for (Standard_Integer ii = 1; ii <= S.Length(); ii++) {
1222 myBuilder.Add (myShape,S.Value(ii));
1223 myMap(CurrentSpine)(CurrentProf).Append(S.Value(ii));
1224 }
1225 }
1226 }
1227 //-----------------------------------------------------------------
0d969553
Y
1228 // Removal of first edge (edge of origin) from lists of myMap
1229 // corresponding to vertices of the profile.
7fd59977 1230 //-----------------------------------------------------------------
1231 TopExp_Explorer Explo(myProfile,TopAbs_VERTEX);
1232 TopTools_MapOfShape vmap;
1233
1234 for ( ; Explo.More(); Explo.Next()){
1235 if (vmap.Add(Explo.Current())) {
1236 myMap(CurrentSpine)(Explo.Current()).RemoveFirst();
1237 }
1238 }
1239 }
1240 myIsDone = Standard_True;
1241
1242#ifdef DRAW
1243 if (AffichEdge) {
0d969553 1244 cout <<" End of construction of an elementary volevo."<<endl;
7fd59977 1245 sprintf(name,"VEVO_%d",++NbVEVOS);
1246 DBRep::Set(name,myShape);
1247 }
1248#endif
1249}
1250
1251//=======================================================================
1252//function : PlanarPerform
1253//purpose :
1254//=======================================================================
1255
1256void BRepFill_Evolved::PlanarPerform (const TopoDS_Face& Sp,
1257 const TopoDS_Wire& Pr,
1258 const BRepMAT2d_BisectingLocus& Locus,
1259 BRepMAT2d_LinkTopoBilo& Link,
1260 const GeomAbs_JoinType Join)
1261{
1262 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
1263 mySpine = TopoDS::Face(aLocalShape);
1264// mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
1265 myProfile = Pr;
1266 myMap.Clear();
1267
1268 BRep_Builder B;
1269 B.MakeCompound(TopoDS::Compound(myShape));
1270
1271 BRepTools_WireExplorer ProfExp;
1272 TopExp_Explorer Exp,exp1,exp2;
1273 TopoDS_Shape Rest;
1274 TopTools_DataMapOfShapeListOfShape EmptyMap;
1275 TopTools_ListOfShape EmptyList;
1276 TopTools_DataMapOfShapeShape MapVP;
1277 BRepFill_OffsetWire Paral;
1278
1279 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1280 const TopoDS_Edge& E = ProfExp.Current();
1281 BRepAlgo_FaceRestrictor FR;
1282 BRepFill_OffsetAncestors OffAnc;
1283
1284 TopoDS_Vertex V[2];
1285 EdgeVertices(E,V[0],V[1]);
1286 Standard_Real Alt = Altitud(V[0]);
1287 Standard_Real Offset[2];
1288 Offset[0] = DistanceToOZ(V[0]);
1289 Offset[1] = DistanceToOZ(V[1]);
1290 Standard_Boolean IsMinV1 = ( Offset[0] < Offset[1]);
1291
1292 for (Standard_Integer i = 0; i <= 1; i++) {
1293 if (!MapVP.IsBound(V[i])) {
1294 //------------------------------------------------
0d969553 1295 // Calculate parallel lines corresponding to vertices.
7fd59977 1296 //------------------------------------------------
1297 Paral.PerformWithBiLo(mySpine,Offset[i],Locus,Link,Join,Alt);
1298 OffAnc.Perform(Paral);
1299 MapVP.Bind(V[i],Paral.Shape());
1300
1301 //-----------------------------
0d969553 1302 // Update myMap (.)(V[i])
7fd59977 1303 //-----------------------------
1304 for (Exp.Init(Paral.Shape(),TopAbs_EDGE);
1305 Exp.More();
1306 Exp.Next()) {
1307 const TopoDS_Edge& WC = TopoDS::Edge(Exp.Current());
1308 const TopoDS_Shape& GS = OffAnc.Ancestor(WC);
1309 if ( !myMap.IsBound(GS))
1310 myMap.Bind(GS, EmptyMap);
1311 if ( !myMap(GS).IsBound(V[i]))
1312 myMap(GS).Bind(V[i],Paral.GeneratedShapes(GS));
1313 }
1314 }
1315 TopoDS_Shape Rest = MapVP(V[i]);
1316
1317 Standard_Boolean ToReverse = Standard_False;
1318 if ( ( IsMinV1 && (i==1)) || (!IsMinV1 && (i==0)) )
1319 ToReverse = Standard_True;
1320
1321 if (!Rest.IsNull()) {
1322 if (Rest.ShapeType() == TopAbs_WIRE) {
1323 if ( ToReverse){
1324 TopoDS_Shape aLocalShape = Rest.Reversed();
1325 TopoDS_Wire aWire = TopoDS::Wire(aLocalShape);
1326 FR.Add(aWire);
1327 }
1328 else
1329 FR.Add(TopoDS::Wire(Rest));
1330 }
1331 else {
1332 for (Exp.Init(Rest,TopAbs_WIRE);Exp.More();Exp.Next()) {
1333 TopoDS_Wire WCop = TopoDS::Wire(Exp.Current());
1334 if ( ToReverse){
1335 TopoDS_Shape aLocalShape = WCop.Reversed();
1336 TopoDS_Wire bWire = TopoDS::Wire(aLocalShape);
1337// TopoDS_Wire bWire = TopoDS::Wire(WCop.Reversed());
1338 FR.Add(bWire);
1339 }
1340 else
1341 FR.Add(WCop);
1342 }
1343 }
1344 }
1345 }
1346#ifdef DRAW
1347 if (AffichEdge) {
1348 TopTools_DataMapIteratorOfDataMapOfShapeShape it(MapVP);
1349 Standard_Integer k = 0;
1350 for (; it.More(); it.Next()) {
1351 sprintf(name,"PARALI_%d",++k);
1352 DBRep::Set(name,it.Value());
1353 }
1354 }
1355#endif
1356
1357 //----------------------------------------------------
0d969553
Y
1358 // Construction of faces limited by parallels.
1359 // - set to the height of the support face.
7fd59977 1360 //----------------------------------------------------
1361 gp_Trsf T; T.SetTranslation(gp_Vec(0,0,Alt));
1362 TopLoc_Location LT(T);
1363 TopoDS_Shape aLocalShape = mySpine.Moved(LT);
1364 FR.Init(TopoDS::Face(aLocalShape));
1365// FR.Init(TopoDS::Face(mySpine.Moved(LT)));
1366 FR.Perform();
1367
1368 for ( ;FR.More(); FR.Next()) {
1369 const TopoDS_Face& F = FR.Current();
1370 B.Add(myShape,F);
1371 //---------------------------------------
0d969553 1372 // Update myMap(.)(E)
7fd59977 1373 //---------------------------------------
1374 for ( Exp.Init(F,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1375 const TopoDS_Edge& CE = TopoDS::Edge(Exp.Current());
1376 if (OffAnc.HasAncestor(CE)) {
1377 const TopoDS_Shape& InitE = OffAnc.Ancestor(CE);
1378 if ( !myMap.IsBound(InitE))
1379 myMap.Bind(InitE, EmptyMap);
1380 if ( !myMap(InitE).IsBound(E))
1381 myMap(InitE).Bind(E,EmptyList);
1382 myMap(InitE)(E).Append(F);
1383 }
1384 }
1385 }
0d969553 1386 } // End loop on profile.
7fd59977 1387}
1388
1389
1390//=======================================================================
1391//function : VerticalPerform
1392//purpose :
1393//=======================================================================
1394
1395void BRepFill_Evolved::VerticalPerform (const TopoDS_Face& Sp,
1396 const TopoDS_Wire& Pr,
1397 const BRepMAT2d_BisectingLocus& Locus,
1398 BRepMAT2d_LinkTopoBilo& Link,
1399 const GeomAbs_JoinType Join)
1400{
1401 TopoDS_Shape aLocalShape = Sp.Oriented(TopAbs_FORWARD);
1402 mySpine = TopoDS::Face(aLocalShape);
1403// mySpine = TopoDS::Face(Sp.Oriented(TopAbs_FORWARD));
1404 myProfile = Pr;
1405 myMap.Clear();
1406
1407 BRep_Builder B;
1408 B.MakeCompound(TopoDS::Compound(myShape));
1409
1410 BRepTools_WireExplorer ProfExp;
1411 TopExp_Explorer Exp;
1412 BRepFill_OffsetWire Paral;
1413 BRepFill_OffsetAncestors OffAnc;
1414 TopoDS_Vertex V1,V2;
1415
1416 Standard_Boolean First = Standard_True;
1417 TopoDS_Shape Base;
1418 TopTools_DataMapOfShapeListOfShape EmptyMap;
1419
1420 for (ProfExp.Init(myProfile); ProfExp.More(); ProfExp.Next()){
1421 const TopoDS_Edge& E = ProfExp.Current();
1422 EdgeVertices(E,V1,V2);
1423 Standard_Real Alt1 = Altitud(V1);
1424 Standard_Real Alt2 = Altitud(V2);
1425
1426 if (First) {
1427 Standard_Real Offset = DistanceToOZ(V1);
1428 if (Abs(Offset) < BRepFill_Confusion()) {
1429 Offset = 0.;
1430 }
1431 Paral.PerformWithBiLo(mySpine,Offset,Locus,Link,Join,Alt1);
1432 OffAnc.Perform(Paral);
1433 Base = Paral.Shape();
1434
1435 // MAJ myMap
1436 for (Exp.Init(Base,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1437 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1438 const TopoDS_Shape& AE = OffAnc.Ancestor(E);
1439 if (!myMap.IsBound(AE)) {
1440 myMap.Bind(AE,EmptyMap);
1441 }
1442 if (!myMap(AE).IsBound(V1)) {
1443 TopTools_ListOfShape L;
1444 myMap(AE).Bind(V1,L);
1445 }
1446 myMap(AE)(V1).Append(E);
1447 }
1448 First = Standard_False;
1449 }
1450
1451
1452#ifdef DRAW
1453 if (AffichEdge) {
1454 sprintf(name,"PARALI_%d",++NbVEVOS);
1455 DBRep::Set(name,Base);
1456 }
1457#endif
1458
1459 BRepSweep_Prism PS(Base,gp_Vec(0,0,Alt2 - Alt1),Standard_False);
1460#ifdef DRAW
1461 if (AffichEdge) {
1462 sprintf(name,"PRISM_%d",NbVEVOS);
1463 DBRep::Set(name,PS.Shape());
1464 }
1465#endif
1466
1467 Base = PS.LastShape();
1468
1469 for (Exp.Init(PS.Shape(),TopAbs_FACE); Exp.More(); Exp.Next()) {
1470 B.Add(myShape,Exp.Current());
1471 }
1472
1473 // MAJ myMap
1474 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape
1475 it(myMap);
1476
1477 for (; it.More(); it.Next()) {
1478 const TopTools_ListOfShape& LOF = it.Value()(V1);
1479 TopTools_ListIteratorOfListOfShape itLOF(LOF);
1480 if (!myMap(it.Key()).IsBound(V2)) {
1481 TopTools_ListOfShape L;
1482 myMap(it.Key()).Bind(V2,L);
1483 }
1484
1485 if (!myMap(it.Key()).IsBound(E)) {
1486 TopTools_ListOfShape L;
1487 myMap(it.Key()).Bind(E,L);
1488 }
1489
1490 for (; itLOF.More(); itLOF.Next()) {
1491 const TopoDS_Shape& OS = itLOF.Value();
1492 myMap(it.Key())(V2).Append(PS.LastShape(OS));
1493 myMap(it.Key())(E).Append(PS.Shape(OS));
1494 }
1495 }
1496 }
1497}
1498
1499//=======================================================================
1500//function : Bubble
0d969553 1501//purpose : Order the sequence of points by growing x.
7fd59977 1502//=======================================================================
1503
1504static void Bubble(TColStd_SequenceOfReal& Seq)
1505{
1506 Standard_Boolean Invert = Standard_True;
1507 Standard_Integer NbPoints = Seq.Length();
1508
1509 while (Invert) {
1510 Invert = Standard_False;
1511 for ( Standard_Integer i = 1; i < NbPoints; i++) {
1512 if ( Seq.Value(i+1) < Seq.Value(i)) {
1513 Seq.Exchange(i,i+1);
1514 Invert = Standard_True;
1515 }
1516 }
1517 }
1518}
1519
1520
1521//=======================================================================
1522//function : PrepareProfile
0d969553
Y
1523//purpose : - Projection of the profile on the working plane.
1524// - Cut of the profile at the extrema of distance from profile to axis Oz.
1525// - Isolate vertical and horizontal parts.
1526// - Reconstruction of wires starting from cut edges.
1527// New wires stored in <WorkProf> are always at the same
1528// side of axis OZ or mixed with it.
7fd59977 1529//=======================================================================
1530
1531void BRepFill_Evolved::PrepareProfile(TopTools_ListOfShape& WorkProf,
1532 TopTools_DataMapOfShapeShape& MapProf )
1533const
1534{
0d969553
Y
1535 // Supposedly the profile is located so that the only transformation
1536 // to be carried out is a projection on plane yOz.
7fd59977 1537
1538 // initialise the projection Plane and the Line to evaluate the extrema.
1539 Handle(Geom_Plane) Plane = new Geom_Plane(gp_Ax3(gp::YOZ()));
1540 Handle(Geom2d_Line) Line = new Geom2d_Line(gp::OY2d());
1541
0d969553 1542 // Map initial vertex -> projected vertex.
7fd59977 1543 TopTools_DataMapOfShapeShape MapVerRefMoved;
1544
1545 TopoDS_Vertex V1,V2,VRef1,VRef2;
1546 TopoDS_Wire W;
1547 BRep_Builder B;
1548 TopTools_ListOfShape WP;
1549 B.MakeWire(W);
1550 WP.Append(W);
1551
1552 BRepTools_WireExplorer Exp(myProfile) ;
1553
1554 while (Exp.More()) {
1555 TopTools_ListOfShape Cuts;
1556 Standard_Boolean NewWire = Standard_False;
1557 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1558
0d969553 1559 // Cut of the edge.
7fd59977 1560 CutEdgeProf (E ,Plane ,Line ,Cuts ,MapVerRefMoved);
1561
1562 EdgeVertices(E,VRef1,VRef2);
1563
1564 if ( Cuts.IsEmpty()) {
0d969553 1565 // Neither extrema nor intersections nor vertices on the axis.
7fd59977 1566 B.Add(W,E);
1567 MapProf.Bind(E,E);
1568 }
1569 else {
1570 while (!Cuts.IsEmpty()) {
1571 const TopoDS_Edge& NE = TopoDS::Edge(Cuts.First());
1572 MapProf.Bind(NE,E);
1573 EdgeVertices(NE,V1,V2);
1574 if (!MapProf.IsBound(V1)) MapProf.Bind(V1,E);
1575 if (!MapProf.IsBound(V2)) MapProf.Bind(V2,E);
1576
1577 B.Add(W,NE);
1578 Cuts.RemoveFirst();
1579
1580 if (DistanceToOZ(V2) < BRepFill_Confusion() &&
1581 DistanceToOZ(V1) > BRepFill_Confusion()) {
0d969553 1582 // NE ends on axis OZ => new wire
7fd59977 1583 if (Cuts.IsEmpty()) {
0d969553
Y
1584 // last part of the current edge
1585 // If it is not the last edge of myProfile
1586 // create a new wire.
7fd59977 1587 NewWire = Standard_True;
1588 }
1589 else {
0d969553 1590 // New wire.
7fd59977 1591 B.MakeWire(W);
1592 WP.Append(W);
1593 }
1594 }
1595 }
1596 }
1597 Exp.Next();
1598 if (Exp.More() && NewWire) {
1599 B.MakeWire(W);
1600 WP.Append(W);
1601 }
1602 }
1603
0d969553 1604 // In the list of Wires, find edges generating plane or vertical vevo.
7fd59977 1605 TopTools_ListIteratorOfListOfShape ite;
1606 TopoDS_Wire CurW,NW;
1607 TopExp_Explorer EW;
1608
1609
1610 for (ite.Initialize(WP); ite.More(); ite.Next()) {
1611 CurW = TopoDS::Wire(ite.Value());
1612 Standard_Boolean YaModif = Standard_False;
1613 for (EW.Init(CurW,TopAbs_EDGE); EW.More(); EW.Next()) {
1614 const TopoDS_Edge& EE = TopoDS::Edge(EW.Current());
1615 if (IsVertical(EE) || IsPlanar(EE)) {
1616 YaModif = Standard_True;
1617 break;
1618 }
1619 }
1620
1621 if (YaModif) {
1622 //Status = 0 for the begining
1623 // 3 vertical
1624 // 2 horizontal
1625 // 1 other
1626 Standard_Integer Status = 0;
1627
1628 for (EW.Init(CurW,TopAbs_EDGE); EW.More(); EW.Next()) {
1629 const TopoDS_Edge& EE = TopoDS::Edge(EW.Current());
1630 if (IsVertical(EE)) {
1631 if (Status != 3) {
1632 B.MakeWire(NW);
1633 WorkProf.Append(NW);
1634 Status = 3;
1635 }
1636 }
1637 else if (IsPlanar(EE)) {
1638 if (Status != 2) {
1639 B.MakeWire(NW);
1640 WorkProf.Append(NW);
1641 Status = 2;
1642 }
1643 }
1644 else if ( Status != 1) {
1645 B.MakeWire(NW);
1646 WorkProf.Append(NW);
1647 Status = 1;
1648 }
1649 B.Add(NW,EE);
1650 }
1651 }
1652 else {
1653 WorkProf.Append(CurW);
1654 }
1655 }
1656
0d969553 1657 //connect vertices modified in MapProf;
7fd59977 1658 TopTools_DataMapIteratorOfDataMapOfShapeShape gilbert(MapVerRefMoved);
1659 for ( ;gilbert.More() ;gilbert.Next()) {
1660 MapProf.Bind(gilbert.Value(),gilbert.Key());
1661 }
1662}
1663
1664
1665//=======================================================================
1666//function : PrepareSpine
1667//purpose :
1668//=======================================================================
1669
1670void BRepFill_Evolved::PrepareSpine(TopoDS_Face& WorkSpine,
1671 TopTools_DataMapOfShapeShape& MapSpine)
1672const
1673{
1674 BRep_Builder B;
1675 TopTools_ListOfShape Cuts;
1676 TopTools_ListIteratorOfListOfShape IteCuts;
1677 TopoDS_Vertex V1,V2;
1678
1679 TopLoc_Location L;
1680 const Handle(Geom_Surface)& S = BRep_Tool::Surface (mySpine,L);
1681 Standard_Real TolF = BRep_Tool::Tolerance(mySpine);
1682 B.MakeFace(WorkSpine,S,L,TolF);
1683
1684 for (TopoDS_Iterator IteF(mySpine) ; IteF.More(); IteF.Next()) {
1685
1686 TopoDS_Wire NW;
1687 B.MakeWire (NW);
1688
1689 for (TopoDS_Iterator IteW(IteF.Value()); IteW.More(); IteW.Next()) {
1690
1691 const TopoDS_Edge& E = TopoDS::Edge(IteW.Value());
1692 EdgeVertices(E,V1,V2);
1693 MapSpine.Bind(V1,V1);
1694 MapSpine.Bind(V2,V2);
1695 Cuts.Clear();
1696
0d969553 1697 // Cut
7fd59977 1698 CutEdge (E, mySpine, Cuts);
1699
1700 if (Cuts.IsEmpty()) {
1701 B.Add(NW,E);
1702 MapSpine.Bind(E,E);
1703 }
1704 else {
1705 for (IteCuts.Initialize(Cuts); IteCuts.More(); IteCuts.Next()) {
1706 const TopoDS_Edge& NE = TopoDS::Edge(IteCuts.Value());
1707 B.Add(NW,NE);
1708 MapSpine.Bind(NE,E);
1709 EdgeVertices(NE,V1,V2);
1710 if (!MapSpine.IsBound(V1)) MapSpine.Bind(V1,E);
1711 if (!MapSpine.IsBound(V2)) MapSpine.Bind(V2,E);
1712 }
1713 }
1714 }
1715 B.Add(WorkSpine, NW);
1716 }
1717
0d969553 1718 // Construct curves 3D of the spine
7fd59977 1719 BRepLib::BuildCurves3d(WorkSpine);
1720
1721#ifdef DRAW
1722 if (AffichEdge) {
1723 sprintf(name,"workspine");
1724 DBRep::Set(name,WorkSpine);
1725 }
1726#endif
1727
1728}
1729//=======================================================================
1730//function : GeneratedShapes
1731//purpose :
1732//=======================================================================
1733
1734const TopoDS_Shape& BRepFill_Evolved::Top() const
1735{
1736 return myTop;
1737}
1738
1739//=======================================================================
1740//function : GeneratedShapes
1741//purpose :
1742//=======================================================================
1743
1744const TopoDS_Shape& BRepFill_Evolved::Bottom() const
1745{
1746 return myBottom;
1747}
1748
1749//=======================================================================
1750//function : GeneratedShapes
1751//purpose :
1752//=======================================================================
1753
1754const TopTools_ListOfShape& BRepFill_Evolved::GeneratedShapes (
1755 const TopoDS_Shape& SpineShape,
1756 const TopoDS_Shape& ProfShape )
1757const
1758{
1759 if (myMap .IsBound(SpineShape) &&
1760 myMap(SpineShape).IsBound(ProfShape) ) {
1761 return myMap(SpineShape)(ProfShape);
1762 }
1763 else {
1764 static TopTools_ListOfShape Empty;
1765 return Empty;
1766 }
1767}
1768
1769//=======================================================================
1770//function : Generated
1771//purpose :
1772//=================================================================== ====
1773
1774BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& BRepFill_Evolved::Generated()
1775{
1776 return myMap;
1777}
1778
1779//=======================================================================
1780//function : Compare
1781//purpose :
1782//=======================================================================
1783
1784static TopAbs_Orientation Compare (const TopoDS_Edge& E1,
1785 const TopoDS_Edge& E2)
1786{
1787 TopAbs_Orientation OO = TopAbs_FORWARD;
1788 TopoDS_Vertex V1[2],V2[2];
1789 TopExp::Vertices (E1,V1[0],V1[1]);
1790 TopExp::Vertices (E2,V2[0],V2[1]);
1791 gp_Pnt P1 = BRep_Tool::Pnt(V1[0]);
1792 gp_Pnt P2 =BRep_Tool::Pnt(V2[0]);
1793 gp_Pnt P3 =BRep_Tool::Pnt(V2[1]);
1794 if (P1.Distance(P3) < P1.Distance(P2)) OO = TopAbs_REVERSED;
1795
1796 return OO;
1797}
1798
1799//=======================================================================
1800//function : Add
1801//purpose :
1802//=======================================================================
1803
1804void BRepFill_Evolved::Add( BRepFill_Evolved& Vevo,
1805 const TopoDS_Wire& Prof,
1806 BRepTools_Quilt& Glue)
1807
1808{
1809 BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& MapVevo = Vevo.Generated();
1810 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iteP;
1811 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
1812 TopoDS_Shape CurrentSpine, CurrentProf;
1813
1814 if (Vevo.Shape().IsNull()) return;
1815
1816 //-------------------------------------------------
0d969553 1817 // Find wires common to <me> and <Vevo>.
7fd59977 1818 //-------------------------------------------------
1819
1820 TopExp_Explorer ExProf;
1821 for (ExProf.Init(Prof,TopAbs_VERTEX); ExProf.More(); ExProf.Next()) {
1822 const TopoDS_Shape& VV = ExProf.Current();
1823 //---------------------------------------------------------------
0d969553
Y
1824 // Parse edges generated by VV in myMap if they existent
1825 // and Bind in Glue
7fd59977 1826 //---------------------------------------------------------------
1827
1828 //------------------------------------------------- -------------
0d969553
Y
1829 // Note: the curves of of reinforced edges are in the same direction
1830 // if one remains on the same edge.
1831 // if one passes from left to the right they are inverted.
7fd59977 1832 //------------------------------------------------- -------------
7fd59977 1833 Standard_Boolean Commun = Standard_False;
6e6cd5d9 1834 Relative(myProfile,Prof,
7fd59977 1835 TopoDS::Vertex(VV),
1836 Commun);
1837
1838 if (Commun) {
1839 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
1840 const TopoDS_Shape& SP = iteS.Key();
1841 if (iteS.Value().IsBound(VV) &&
1842 MapVevo.IsBound(SP) && MapVevo(SP).IsBound(VV)) {
1843
1844 const TopTools_ListOfShape& MyList = myMap(SP)(VV);
1845 const TopTools_ListOfShape& VevoList = Vevo.GeneratedShapes(SP,VV);
1846 TopTools_ListIteratorOfListOfShape MyIte (MyList);
1847 TopTools_ListIteratorOfListOfShape VevoIte(VevoList);
1848 for (; MyIte.More(); MyIte.Next(), VevoIte.Next()) {
1849 const TopoDS_Edge& ME = TopoDS::Edge(MyIte .Value());
1850 const TopoDS_Edge& VE = TopoDS::Edge(VevoIte.Value());
1851 TopAbs_Orientation OG = Compare(ME,VE);
1852 TopoDS_Shape aLocalShape = VE.Oriented (TopAbs_FORWARD);
1853 TopoDS_Shape aLocalShape2 = ME.Oriented (OG);
1854 Glue.Bind(TopoDS::Edge(aLocalShape),TopoDS::Edge(aLocalShape2));
1855// Glue.Bind(TopoDS::Edge(VE.Oriented (TopAbs_FORWARD)),
1856// TopoDS::Edge(ME.Oriented (OG)));
1857 }
1858 }
1859 }
1860 }
1861 }
1862 Glue.Add(Vevo.Shape());
1863
1864 //----------------------------------------------------------
0d969553 1865 // Add map of elements generate in Vevo in myMap.
7fd59977 1866 //----------------------------------------------------------
1867 TopTools_DataMapOfShapeListOfShape EmptyMap;
1868 TopTools_ListOfShape EmptyList;
1869
1870 for (iteS.Initialize(MapVevo); iteS.More() ; iteS.Next()) {
1871 CurrentSpine = iteS.Key();
1872 for (iteP.Initialize(MapVevo(CurrentSpine)); iteP.More(); iteP.Next()) {
1873 CurrentProf = iteP.Key();
1874 if (!myMap.IsBound(CurrentSpine)) {
1875 //------------------------------------------------
0d969553
Y
1876 // The element of spine is not yet present .
1877 // => previous profile not on the border.
7fd59977 1878 //-------------------------------------------------
1879 myMap.Bind(CurrentSpine,EmptyMap);
1880 }
1881 if (!myMap(CurrentSpine).IsBound(CurrentProf)) {
1882 myMap(CurrentSpine).Bind(CurrentProf,EmptyList);
1883 const TopTools_ListOfShape& GenShapes
1884 = MapVevo (CurrentSpine)(CurrentProf);
1885 TopTools_ListIteratorOfListOfShape itl (GenShapes);
1886 for (; itl.More(); itl.Next()) {
0d969553 1887 // during Glue.Add the shared shapes are recreated.
7fd59977 1888 if (Glue.IsCopied(itl.Value()))
1889 myMap(CurrentSpine)(CurrentProf).Append(Glue.Copy(itl.Value()));
1890 else
1891 myMap(CurrentSpine)(CurrentProf).Append(itl.Value());
1892 }
1893 }
1894 }
1895 }
1896}
1897
1898//=======================================================================
1899//function : ChangeShape
1900//purpose :
1901//=======================================================================
1902
1903TopoDS_Shape& BRepFill_Evolved::ChangeShape()
1904{
1905 return myShape;
1906}
1907
1908//=======================================================================
1909//function : Transfert
1910//purpose :
1911//=======================================================================
1912
1913void BRepFill_Evolved::Transfert( BRepFill_Evolved& Vevo,
1914 const TopTools_DataMapOfShapeShape& MapProf,
1915 const TopTools_DataMapOfShapeShape& MapSpine,
1916 const TopLoc_Location& LS,
1917 const TopLoc_Location& InitLS,
1918 const TopLoc_Location& InitLP)
1919{
0d969553
Y
1920 //----------------------------------------------------------------
1921 // Transfer the shape from Vevo in myShape and Reposition shapes.
1922 //----------------------------------------------------------------
7fd59977 1923 myShape = Vevo.Shape();
1924 mySpine .Location(InitLS);
1925 myProfile.Location(InitLP);
1926 myShape .Move (LS);
1927
1928 //
0d969553
Y
1929 // Expecting for better, the Same Parameter is forced here
1930 // ( Pb Sameparameter between YaPlanar and Tuyaux
7fd59977 1931 //
1932 BRep_Builder B;
1933 TopExp_Explorer ex(myShape,TopAbs_EDGE);
1934 while (ex.More()) {
1935 B.SameRange(TopoDS::Edge(ex.Current()), Standard_False);
1936 B.SameParameter(TopoDS::Edge(ex.Current()), Standard_False);
1937 BRepLib::SameParameter(TopoDS::Edge(ex.Current()));
1938 ex.Next();
1939 }
1940
1941
1942 //--------------------------------------------------------------
0d969553 1943 // Transfer of myMap of Vevo into myMap.
7fd59977 1944 //--------------------------------------------------------------
1945 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
1946 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iteP;
1947 TopTools_DataMapOfShapeListOfShape EmptyMap;
1948 TopTools_ListOfShape EmptyList;
1949 TopoDS_Shape InitialSpine, InitialProf;
1950
1951 BRepFill_DataMapOfShapeDataMapOfShapeListOfShape& MapVevo
1952 = Vevo.Generated();
1953
1954 for (iteS.Initialize(MapVevo); iteS.More(); iteS.Next()) {
1955 InitialSpine = MapSpine(iteS.Key());
1956 InitialSpine.Move(LS);
1957
1958 for (iteP.Initialize(MapVevo(iteS.Key())); iteP.More(); iteP.Next()) {
1959 InitialProf = MapProf (iteP.Key());
1960 InitialProf.Location(InitLP);
1961
1962 TopTools_ListOfShape& GenShapes =
1963 MapVevo.ChangeFind(iteS.Key()).ChangeFind(iteP.Key());
1964
1965 TopTools_ListIteratorOfListOfShape itl;
1966 for (itl.Initialize(GenShapes); itl.More(); itl.Next()) {
1967 itl.Value().Move(LS);
1968 }
1969
1970 if (!myMap.IsBound(InitialSpine)) {
1971 myMap.Bind(InitialSpine,EmptyMap);
1972 }
1973
1974 if (!myMap(InitialSpine).IsBound(InitialProf)) {
1975 myMap(InitialSpine).Bind(InitialProf,EmptyList);
1976 }
1977 myMap(InitialSpine)(InitialProf).Append(GenShapes);
1978 }
1979 }
1980 //--------------------------------------------------------------
0d969553 1981 // Transfer of Top and Bottom of Vevo in myTop and myBottom.
7fd59977 1982 //--------------------------------------------------------------
1983 myTop = Vevo.Top() ; myTop.Move(LS);
1984 myBottom = Vevo.Bottom(); myBottom.Move(LS);
1985}
1986
1987//=======================================================================
1988//function : IsDone
1989//purpose :
1990//=======================================================================
1991
1992Standard_Boolean BRepFill_Evolved::IsDone() const
1993{
1994 return myIsDone;
1995}
1996
1997//=======================================================================
1998//function : Shape
1999//purpose :
2000//=======================================================================
2001
2002const TopoDS_Shape& BRepFill_Evolved::Shape() const
2003{
2004 return myShape;
2005}
2006
2007//=======================================================================
2008//function : JoinType
2009//purpose :
2010//=======================================================================
2011
2012GeomAbs_JoinType BRepFill_Evolved::JoinType() const
2013{
2014 return myJoinType;
2015}
2016
2017//=======================================================================
2018//function : AddTopAndBottom
2019//purpose :
2020//=======================================================================
2021
2022void BRepFill_Evolved::AddTopAndBottom(BRepTools_Quilt& Glue)
2023{
0d969553 2024// return first and last vertex of the profile.
7fd59977 2025 TopoDS_Vertex V[2];
2026 TopExp::Vertices (myProfile,V[0],V[1]);
2027 if (V[0].IsSame(V[1])) return;
2028
2029 TopTools_ListIteratorOfListOfShape itL;
2030 Standard_Boolean ToReverse=Standard_False;
2031 for (Standard_Integer i = 0; i<=1; i++) {
2032
2033 BRepAlgo_Loop Loop;
0d969553 2034 // Construction of supports.
7fd59977 2035 gp_Pln S (0.,0.,1.,- Altitud(V[i]));
2036 TopoDS_Face F = BRepLib_MakeFace(S);
2037 Loop.Init(F);
2038
2039 TopExp_Explorer ExpSpine(mySpine,TopAbs_EDGE);
2040 TopTools_MapOfShape View;
2041
2042 for (; ExpSpine.More(); ExpSpine.Next()) {
2043 const TopoDS_Edge& ES = TopoDS::Edge(ExpSpine.Current());
2044 const TopTools_ListOfShape& L = GeneratedShapes(ES,V[i]);
2045 Standard_Boolean ComputeOrientation = 0;
2046
2047 for (itL.Initialize(L); itL.More(); itL.Next()) {
2048 const TopoDS_Edge& E = TopoDS::Edge(itL.Value());
2049
2050 if (!ComputeOrientation) {
2051 BRepAdaptor_Curve C1(ES);
2052 BRepAdaptor_Curve C2(E);
2053 Standard_Real f,l,fs,ls;
2054 BRep_Tool::Range(E ,f ,l);
2055 BRep_Tool::Range(ES,fs,ls);
2056 Standard_Real u = 0.3*f + 0.7*l;
2057 Standard_Real us = 0.3*fs + 0.7*ls;
2058 gp_Pnt P;
2059 gp_Vec V1,V2;
2060 C1.D1(us,P,V1); C2.D1(u,P,V2);
2061 ToReverse = (V1.Dot(V2) < 0.);
2062 ComputeOrientation = 1;
2063 }
2064
2065 TopAbs_Orientation Or = ES.Orientation();
2066 if (ToReverse) Or = TopAbs::Reverse(Or);
2067 TopoDS_Shape aLocalShape = E.Oriented(Or);
2068 Loop.AddConstEdge(TopoDS::Edge(aLocalShape));
2069// Loop.AddConstEdge(TopoDS::Edge(E.Oriented(Or)));
2070 }
2071 }
2072
2073 gp_Pnt PV = BRep_Tool::Pnt(V[i]);
2074 Standard_Boolean IsOut = PV.Y() < 0;
2075
2076 for (ExpSpine.Init(mySpine,TopAbs_VERTEX); ExpSpine.More(); ExpSpine.Next()) {
2077 const TopoDS_Vertex& ES = TopoDS::Vertex(ExpSpine.Current());
2078 if (View.Add(ES)) {
2079 const TopTools_ListOfShape& L = GeneratedShapes(ES,V[i]);
2080 for (itL.Initialize(L); itL.More(); itL.Next()) {
2081 const TopoDS_Edge& E = TopoDS::Edge(itL.Value());
2082 if (!BRep_Tool::Degenerated(E)){
0d969553
Y
2083 // the center of circle (ie vertex) is IN the cap if vertex IsOut
2084 // OUT !IsOut
7fd59977 2085 BRepAdaptor_Curve C(E);
2086 Standard_Real f,l;
2087 BRep_Tool::Range(E,f,l);
2088 Standard_Real u = 0.3*f + 0.7*l;
2089 gp_Pnt P = BRep_Tool::Pnt(ES);
2090 gp_Pnt PC;
2091 gp_Vec VC;
2092 C.D1(u,PC,VC);
2093 gp_Vec PPC(P,PC);
2094 gp_Vec Prod = PPC.Crossed(VC);
2095 if (IsOut) {
2096 ToReverse = Prod.Z() < 0.;
2097 }
2098 else {
2099 ToReverse = Prod.Z() > 0.;
2100 }
2101 TopAbs_Orientation Or = TopAbs_FORWARD;
2102 if (ToReverse) Or = TopAbs_REVERSED;
2103 TopoDS_Shape aLocalShape = E.Oriented(Or);
2104 Loop.AddConstEdge(TopoDS::Edge(aLocalShape));
2105// Loop.AddConstEdge(TopoDS::Edge(E.Oriented(Or)));
2106 }
2107 }
2108 }
2109 }
2110
2111 Loop.Perform();
2112 Loop.WiresToFaces();
2113 const TopTools_ListOfShape& L = Loop.NewFaces();
2114 TopTools_ListIteratorOfListOfShape itL(L);
2115
0d969553
Y
2116 // Maj of myTop and myBottom for the history
2117 // and addition of constructed faces.
7fd59977 2118 TopoDS_Compound Bouchon;
2119 BRep_Builder B;
2120 B.MakeCompound(Bouchon);
2121 Standard_Integer j = 0;
2122
2123 for (itL.Initialize(L); itL.More(); itL.Next()) {
2124 j++;
2125 Glue.Add(itL.Value());
2126 if (j ==1 && i == 0) myTop = itL.Value();
2127 if (j ==1 && i == 1) myBottom = itL.Value();
2128 B.Add(Bouchon,itL.Value());
2129 }
2130 if (i == 0 && j > 1) myTop = Bouchon;
2131 if (i == 1 && j > 1) myBottom = Bouchon;
2132 }
2133}
2134
2135//================================================================== =====
2136//function : MakePipe
2137//purpose :
2138//=======================================================================
2139
2140void BRepFill_Evolved::MakeSolid()
2141{
2142
2143 TopExp_Explorer exp(myShape,TopAbs_SHELL);
2144 Standard_Integer ish=0;
2145 TopoDS_Compound Res;
2146 TopoDS_Solid Sol;
2147 BRep_Builder B;
2148 B.MakeCompound(Res);
2149
2150 for (; exp.More(); exp.Next()) {
2151 TopoDS_Shape Sh = exp.Current();
2152 B.MakeSolid(Sol);
2153 B.Add(Sol,Sh);
2154 BRepClass3d_SolidClassifier SC(Sol);
2155 SC.PerformInfinitePoint(BRepFill_Confusion());
2156 if (SC.State() == TopAbs_IN) {
2157 B.MakeSolid(Sol);
2158 B.Add(Sol,Sh.Reversed());
2159 }
2160 B.Add(Res,Sol);
2161 ish++;
2162 }
2163 if (ish == 1) { myShape = Sol;}
2164 else { myShape = Res;}
2165
2166}
2167
2168//=======================================================================
2169//function : MakePipe
2170//purpose :
2171//=======================================================================
2172
2173void BRepFill_Evolved::MakePipe(const TopoDS_Edge& SE,
2174 const gp_Ax3& AxeRef)
2175{
2176 BRepTools_WireExplorer ProfExp;
2177 TopExp_Explorer FaceExp;
2178
2179 gp_Trsf trsf;
2180 if (Side(myProfile,BRepFill_Confusion()) > 3) { // side right
c6541a0c 2181 trsf.SetRotation(gp::OZ(),M_PI);
7fd59977 2182 }
2183 TopLoc_Location DumLoc (trsf);
2184 TopoDS_Shape aLocalShape = myProfile.Moved(DumLoc);
2185 TopoDS_Wire DummyProf =
2186 PutProfilAt (TopoDS::Wire(aLocalShape),
2187 AxeRef,SE,
2188 mySpine,Standard_True);
2189// TopoDS_Wire DummyProf =
2190// PutProfilAt (TopoDS::Wire(myProfile.Moved(DumLoc)),
2191// AxeRef,SE,
2192// mySpine,Standard_True);
2193
0d969553
Y
2194 // Copy of the profile to avoid the accumulation of
2195 // locations on the Edges of myProfile!
7fd59977 2196
2197 Handle(BRepTools_TrsfModification) TrsfMod
2198 = new BRepTools_TrsfModification(gp_Trsf());
2199 BRepTools_Modifier Modif(DummyProf,TrsfMod);
2200
2201 TopoDS_Wire GenProf = TopoDS::Wire(Modif.ModifiedShape(DummyProf));
2202
2203#ifdef DRAW
2204 if (AffichGeom) {
2205 sprintf(name,"EVOLBASE_%d",++NbFACES);
2206 DBRep::Set(name,SE);
2207 sprintf(name,"EVOLPROF_%d",NbFACES);
2208 DBRep::Set(name,GenProf);
2209 }
2210#endif
2211
2212// BRepFill_Pipe Pipe(BRepLib_MakeWire(SE),GenProf);
2213 BRepFill_Pipe Pipe = BRepFill_Pipe(BRepLib_MakeWire(SE),GenProf);
2214
2215#ifdef DRAW
2216 if (AffichGeom) {
2217 sprintf(name,"EVOL_%d",++NbFACES);
2218 DBRep::Set(name,Pipe.Shape());
2219 }
2220#endif
2221 //---------------------------------------------
0d969553 2222 // Arrangement of Tubes in myMap.
7fd59977 2223 //---------------------------------------------
2224
2225 BRepTools_WireExplorer GenProfExp;
2226 TopTools_ListOfShape L;
2227 TopoDS_Vertex VF,VL,VFG,VLG;
2228 Standard_Boolean FirstVertex = Standard_True;
2229 TopTools_DataMapOfShapeListOfShape P;
2230
2231 myMap.Bind(SE,P);
2232
2233 for (ProfExp.Init(myProfile),GenProfExp.Init(GenProf);
2234 ProfExp.More();
2235 ProfExp.Next(),GenProfExp.Next()) {
2236
2237 EdgeVertices(ProfExp .Current(),VF ,VL);
2238 EdgeVertices(GenProfExp.Current(),VFG,VLG);
2239
2240 if (FirstVertex) {
2241 myMap(SE).Bind(VF,L);
2242 myMap(SE)(VF).Append(Pipe.Edge(SE,VFG));
2243 FirstVertex = Standard_False;
2244 }
2245 myMap(SE).Bind(VL,L);
2246 myMap(SE)(VL).Append(Pipe.Edge(SE,VLG));
2247 myMap(SE).Bind(ProfExp.Current(),L);
2248 myMap(SE)(ProfExp.Current()).Append
2249 (Pipe.Face(SE,GenProfExp.Current()));
2250 }
2251}
2252
2253
2254//=======================================================================
2255//function : MakeRevol
2256//purpose :
2257//=======================================================================
2258
2259void BRepFill_Evolved::MakeRevol(const TopoDS_Edge& SE,
2260 const TopoDS_Vertex& VLast,
2261 const gp_Ax3& AxeRef)
2262{
2263 BRepTools_WireExplorer ProfExp;
2264 TopExp_Explorer FaceExp;
2265
2266 gp_Trsf trsf;
2267 if (Side(myProfile,BRepFill_Confusion()) > 3) { // side right
c6541a0c 2268 trsf.SetRotation(gp::OZ(),M_PI);
7fd59977 2269 }
2270 TopLoc_Location DumLoc (trsf);
2271 TopoDS_Shape aLocalShape = myProfile.Moved(DumLoc);
2272 TopoDS_Wire GenProf =
2273 PutProfilAt (TopoDS::Wire(aLocalShape),
2274 AxeRef,SE,
2275 mySpine,Standard_False);
2276// TopoDS_Wire GenProf =
2277// PutProfilAt (TopoDS::Wire(myProfile.Moved(DumLoc)),
2278// AxeRef,SE,
2279// mySpine,Standard_False);
2280
2281 gp_Ax1 AxeRev( BRep_Tool::Pnt(VLast), -gp::DZ());
2282
0d969553
Y
2283 // Position of the sewing on the edge of the spine
2284 // so that the bissectrices didn't cross the sewings.
7fd59977 2285 gp_Trsf dummy;
c6541a0c 2286 dummy.SetRotation(AxeRev, 1.5*M_PI);
7fd59977 2287 TopLoc_Location DummyLoc(dummy);
2288 GenProf.Move(DummyLoc);
2289
2290 BRepSweep_Revol Rev(GenProf,AxeRev,Standard_True);
2291
2292#ifdef DRAW
2293 if (AffichGeom) {
2294 sprintf(name,"EVOLBASE_%d",++NbFACES);
2295 char* Temp = name ;
2296 DrawTrSurf::Set(Temp,new Geom_Line(AxeRev));
2297// DrawTrSurf::Set(name,new Geom_Line(AxeRev));
2298 sprintf(name,"EVOLPROF_%d",NbFACES);
2299 DBRep::Set(name,GenProf);
2300
2301 sprintf(name,"EVOL_%d",NbFACES);
2302 DBRep::Set(name,Rev.Shape());
2303 }
2304#endif
2305 //--------------------------------------------
0d969553 2306 // Arrangement of revolutions in myMap.
7fd59977 2307 //---------------------------------------------
2308 BRepTools_WireExplorer GenProfExp;
2309 TopTools_ListOfShape L;
2310 TopoDS_Vertex VF,VL,VFG,VLG;
2311 Standard_Boolean FirstVertex = Standard_True;
2312 TopTools_DataMapOfShapeListOfShape R;
2313
2314 myMap.Bind(VLast,R);
2315
2316 for (ProfExp.Init(myProfile),GenProfExp.Init(GenProf);
2317 ProfExp.More();
2318 ProfExp.Next(),GenProfExp.Next()) {
2319
2320 EdgeVertices(ProfExp .Current(),VF ,VL);
2321 EdgeVertices(GenProfExp.Current(),VFG,VLG);
2322
2323 TopAbs_Orientation Or = GenProfExp.Current().Orientation();
2324
2325 if (FirstVertex) {
2326 myMap(VLast).Bind(VF,L);
2327 const TopoDS_Shape& RV = Rev.Shape(VFG);
2328// TopAbs_Orientation OO = TopAbs::Compose(RV.Orientation(),Or);
2329 TopAbs_Orientation OO = RV.Orientation();
2330 myMap(VLast)(VF).Append(RV.Oriented(OO));
2331 FirstVertex = Standard_False;
2332 }
2333 myMap(VLast).Bind(ProfExp.Current(),L);
2334 const TopoDS_Shape& RF = Rev.Shape(GenProfExp.Current());
2335 TopAbs_Orientation OO = TopAbs::Compose(RF.Orientation(),Or);
2336
2337 myMap(VLast)(ProfExp.Current()).Append(RF.Oriented(OO));
2338 myMap(VLast).Bind(VL,L);
2339 const TopoDS_Shape& RV = Rev.Shape(VLG);
2340// OO = TopAbs::Compose(RV.Orientation(),Or);
2341 OO = RV.Orientation();
2342 myMap(VLast)(VL).Append(RV.Oriented(OO));
2343 }
2344}
2345
2346//=======================================================================
2347//function : FindLocation
2348//purpose :
2349//=======================================================================
2350
2351TopLoc_Location BRepFill_Evolved::FindLocation(const TopoDS_Face& Face)
2352const
2353{
2354 TopLoc_Location L;
2355 Handle(Geom_Surface) S;
2356 S = BRep_Tool::Surface(Face, L);
2357
2358 if ( !S->IsKind(STANDARD_TYPE(Geom_Plane))) {
2359 BRepLib_FindSurface FS( Face, -1, Standard_True);
2360 if ( FS.Found()) {
2361 S = FS.Surface();
2362 L = FS.Location();
2363 }
2364 else
2365 Standard_NoSuchObject::Raise
2366 ("BRepFill_Evolved : The Face is not planar");
2367 }
2368
2369 if (!L.IsIdentity())
2370 S = Handle(Geom_Surface)::DownCast(S->Transformed(L.Transformation()));
2371
2372 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
2373 gp_Ax3 Axis = P->Position();
2374
2375 gp_Trsf T;
2376 gp_Ax3 AxeRef(gp_Pnt(0.,0.,0.),
2377 gp_Dir(0.,0.,1.),
2378 gp_Dir(1.,0.,0.));
2379 T.SetTransformation(AxeRef,Axis);
2380
2381 return TopLoc_Location(T);
2382}
2383
2384
2385//=======================================================================
2386//function : TransformInitWork
2387//purpose :
2388//=======================================================================
2389
2390void BRepFill_Evolved::TransformInitWork(const TopLoc_Location& LS,
2391 const TopLoc_Location& LP)
2392{
2393 mySpine.Move (LS);
2394 myProfile.Move(LP);
2395
2396#ifdef DRAW
2397 if (AffichEdge) {
2398 sprintf(name,"movedspine");
2399 TopoDS_Face SL = mySpine;
2400 DBRep::Set(name,SL);
2401 sprintf(name,"movedprofile");
2402 TopoDS_Wire PL = myProfile;
2403 DBRep::Set(name,PL);
2404 }
2405#endif
2406}
2407
2408
2409//=======================================================================
2410//function : ContinuityOnOffsetEdge
0d969553
Y
2411//purpose : Coding of regularities on edges parallel to CutVevo
2412// common to left and right parts of volevo.
7fd59977 2413//=======================================================================
2414void BRepFill_Evolved::ContinuityOnOffsetEdge (const TopTools_ListOfShape& WorkProf)
2415{
2416 BRepTools_WireExplorer WExp ;
2417 BRepFill_DataMapIteratorOfDataMapOfShapeDataMapOfShapeListOfShape iteS;
2418 TopoDS_Vertex VF,VL,V;
2419 TopoDS_Edge PrecE,CurE,FirstE;
2420 BRep_Builder B;
2421
2422
2423 WExp.Init(myProfile);
2424 FirstE = WExp.Current();
2425 PrecE = FirstE;
2426 EdgeVertices (FirstE, VF, V);
2427 if (WExp.More()) WExp.Next();
2428
2429 for (; WExp.More(); WExp.Next()) {
2430 CurE = WExp.Current();
2431 V = WExp.CurrentVertex();
2432
2433 if (DistanceToOZ(V) <= BRepFill_Confusion()) {
0d969553 2434 // the regularities are already coded on the edges of elementary volevos
7fd59977 2435 Standard_Real U1 = BRep_Tool::Parameter(V,CurE);
2436 Standard_Real U2 = BRep_Tool::Parameter(V,PrecE);
2437 BRepAdaptor_Curve Curve1(CurE);
2438 BRepAdaptor_Curve Curve2(PrecE);
2439 GeomAbs_Shape Continuity = BRepLProp::Continuity(Curve1,Curve2,U1,U2);
2440
2441 if (Continuity >=1) {
2442 //-----------------------------------------------------
0d969553 2443 //Code continuity for all edges generated by V.
7fd59977 2444 //-----------------------------------------------------
2445 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
2446 const TopoDS_Shape& SP = iteS.Key();
2447 if (myMap (SP).IsBound(V)
2448 && myMap (SP).IsBound(CurE) && myMap (SP).IsBound(PrecE)){
2449 if (!myMap(SP)(V) .IsEmpty() &&
2450 !myMap(SP)(CurE) .IsEmpty() &&
2451 !myMap(SP)(PrecE).IsEmpty() )
2452 B.Continuity (TopoDS::Edge(myMap(SP)(V) .First()),
2453 TopoDS::Face(myMap(SP)(CurE) .First()),
2454 TopoDS::Face(myMap(SP)(PrecE).First()),
2455 Continuity);
2456 }
2457 }
2458 }
2459 }
2460 PrecE = CurE;
2461 }
2462
2463 EdgeVertices (PrecE, V, VL);
2464
2465 if (VF.IsSame(VL)) {
0d969553 2466 //Closed profile.
7fd59977 2467 Standard_Real U1 = BRep_Tool::Parameter(VF,CurE);
2468 Standard_Real U2 = BRep_Tool::Parameter(VF,FirstE);
2469 BRepAdaptor_Curve Curve1(CurE);
2470 BRepAdaptor_Curve Curve2(FirstE);
2471 GeomAbs_Shape Continuity = BRepLProp::Continuity(Curve1,Curve2,U1,U2);
2472
2473 if (Continuity >=1) {
0d969553
Y
2474 //---------------------------------------------
2475 //Code continuity for all edges generated by V.
2476 //---------------------------------------------
7fd59977 2477 for (iteS.Initialize(myMap); iteS.More(); iteS.Next()) {
2478 const TopoDS_Shape& SP = iteS.Key();
2479 if (myMap (SP).IsBound(VF)
2480 && myMap (SP).IsBound(CurE) && myMap (SP).IsBound(FirstE)){
2481 if (!myMap(SP)(VF) .IsEmpty() &&
2482 !myMap(SP)(CurE) .IsEmpty() &&
2483 !myMap(SP)(FirstE).IsEmpty() )
2484 B.Continuity (TopoDS::Edge(myMap(SP)(VF) .First()),
2485 TopoDS::Face(myMap(SP)(CurE) .First()),
2486 TopoDS::Face(myMap(SP)(FirstE).First()),
2487 Continuity);
2488 }
2489 }
2490 }
2491 }
2492}
2493
2494//=======================================================================
2495//function : AddDegeneratedEdge
0d969553
Y
2496//purpose : degenerated edges can be missing in some face
2497// the missing degenerated edges have vertices corresponding
2498// to node of the map.
2499// Now it is enough to compare points UV of vertices
2500// on edges with a certain tolerance.
7fd59977 2501//=======================================================================
2502
2503static void AddDegeneratedEdge(TopoDS_Face& F,
2504 TopoDS_Wire& W)
2505{
2506 TopLoc_Location L;
2507 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
2508 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
2509 Handle(Geom_Surface) SB = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
2510 if (SB->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2511 return;
2512 }
2513 }
2514
2515 if (S->DynamicType() == STANDARD_TYPE(Geom_Plane)) {
2516 return;
2517 }
2518
2519
2520 BRep_Builder B;
2521 Standard_Real TolConf = 1.e-4;
2522
2523 Standard_Boolean Change = Standard_True;
2524
2525 while (Change) {
2526 Change = Standard_False;
2527 BRepTools_WireExplorer WE(W,F);
2528 gp_Pnt2d PF,PrevP,P1,P2;
2529 TopoDS_Vertex VF,V1,V2;
2530
2531 for (; WE.More(); WE.Next()) {
2532 const TopoDS_Edge& CE = WE.Current();
2533 EdgeVertices (CE,V1,V2);
2534 if (CE.Orientation() == TopAbs_REVERSED)
2535 BRep_Tool::UVPoints(CE, F, P2, P1);
2536 else
2537 BRep_Tool::UVPoints(CE, F, P1, P2);
2538 if (VF.IsNull()) {
2539 VF = V1;
2540 PF = P1;
2541 }
2542 else {
2543 if (!P1.IsEqual(PrevP,TolConf)) {
0d969553 2544 // degenerated edge to be inserted.
7fd59977 2545 Change = Standard_True;
2546 gp_Vec2d V(PrevP,P1);
2547 Handle(Geom2d_Line) C2d = new Geom2d_Line(PrevP,gp_Dir2d(V));
2548 Standard_Real f = 0, l = PrevP.Distance(P1);
2549 Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(C2d,f,l);
2550 TopoDS_Edge NE = BRepLib_MakeEdge(C2d,S);
2551 B.Degenerated(NE,Standard_True);
2552 B.Add(NE,V1.Oriented(TopAbs_FORWARD));
2553 B.Add(NE,V1.Oriented(TopAbs_REVERSED));
2554 B.Range(NE,f,l);
2555 B.Add(W,NE);
2556 break;
2557 }
2558 }
2559 PrevP = P2;
2560 }
0d969553 2561 if (!Change && VF.IsSame(V2)) { // closed
7fd59977 2562 if (!PF.IsEqual(P2,TolConf)) {
0d969553 2563 // Degenerated edge to be inserted.
7fd59977 2564 Change = Standard_True;
2565 gp_Vec2d V(P2,PF);
2566 Handle(Geom2d_Line) C2d = new Geom2d_Line(P2,gp_Dir2d(V));
2567 Standard_Real f = 0, l = P2.Distance(PF);
2568 Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(C2d,f,l);
2569 TopoDS_Edge NE = BRepLib_MakeEdge(C2d,S);
2570 B.Degenerated(NE,Standard_True);
2571 B.Add(NE,VF.Oriented(TopAbs_FORWARD));
2572 B.Add(NE,VF.Oriented(TopAbs_REVERSED));
2573 B.Range(NE,f,l);
2574 B.Add(W,NE);
2575 }
2576 }
2577 }
2578}
2579
2580//=======================================================================
2581//function : TrimFace
2582//purpose :
2583//=======================================================================
2584
2585void TrimFace(const TopoDS_Face& Face,
2586 TopTools_SequenceOfShape& TheEdges,
2587 TopTools_SequenceOfShape& S)
2588{
2589
2590#ifdef DRAW
2591 Standard_Integer NB = TheEdges.Length();
2592 if ( AffichEdge) {
2593 char name[100];
2594 cout << " TrimFace " << ++NbTRIMFACES;
0d969553 2595 cout << " : " << NB << " edges within the restriction" << endl;
7fd59977 2596 for ( Standard_Integer j = 1; j <= NB; j++) {
2597 sprintf(name,"TRIMEDGE_%d_%d",NbTRIMFACES,j);
2598 DBRep::Set(name,TopoDS::Edge(TheEdges.Value(j)));
2599 }
2600 }
2601#endif
2602
2603
2604 //--------------------------------------
0d969553 2605 // Creation of wires limiting faces.
7fd59977 2606 //--------------------------------------
2607 BRep_Builder TheBuilder;
2608
2609 Standard_Integer NbEdges;
2610 Standard_Boolean NewWire = Standard_True;
2611 Standard_Boolean AddEdge = Standard_False;
2612 TopoDS_Wire GoodWire;
2613
2614
2615 while ( !TheEdges.IsEmpty()) {
2616
2617 BRepLib_MakeWire MWire(TopoDS::Edge(TheEdges.First()));
2618 GoodWire = MWire.Wire();
2619 TheEdges.Remove(1);
2620 NbEdges = TheEdges.Length();
2621 NewWire = Standard_False;
2622
2623 while (!NewWire) {
2624 AddEdge = Standard_False;
2625
2626 for ( Standard_Integer i = 1; i <= NbEdges && !AddEdge; i++) {
2627 const TopoDS_Edge& E = TopoDS::Edge(TheEdges.Value(i));
2628 if ( BRep_Tool::Degenerated(E)) {
2629 TheEdges.Remove(i);
2630 AddEdge = Standard_True;
2631 NbEdges = TheEdges.Length();
2632 GoodWire = MWire.Wire();
2633 }
2634 else {
2635 MWire.Add(E);
2636 if ( MWire.Error() == BRepLib_WireDone) {
0d969553
Y
2637 // the connection is successful
2638 // it is removed from the sequence and one restarts from the beginning.
7fd59977 2639 TheEdges.Remove(i);
2640 AddEdge = Standard_True;
2641 NbEdges = TheEdges.Length();
2642 GoodWire = MWire.Wire();
2643 }
2644 }
2645 }
2646 NewWire = (!AddEdge);
2647 }
2648 TopoDS_Shape aLocalShape = Face.EmptyCopied();
2649 TopoDS_Face FaceCut = TopoDS::Face(aLocalShape);
2650// TopoDS_Face FaceCut = TopoDS::Face(Face.EmptyCopied());
2651 FaceCut.Orientation(TopAbs_FORWARD);
2652 BRepTools::Update (FaceCut);
2653 AddDegeneratedEdge (FaceCut,GoodWire);
2654 TheBuilder.Add (FaceCut,GoodWire);
2655 FaceCut.Orientation(Face.Orientation());
2656 S.Append(FaceCut);
2657 }
2658}
2659
2660
2661
2662//=======================================================================
2663//function : PutProfilAt
2664//purpose :
2665//=======================================================================
2666
2667const TopoDS_Wire PutProfilAt (const TopoDS_Wire& ProfRef,
2668 const gp_Ax3& AxeRef,
2669 const TopoDS_Edge& E,
2670 const TopoDS_Face& F,
2671 const Standard_Boolean AtStart)
2672{
2673 gp_Vec2d D1;
2674 gp_Pnt2d P;
2675 TopoDS_Wire Prof;
2676 Handle(Geom2d_Curve) C2d;
2677 Standard_Real First,Last;
2678
2679 C2d = BRep_Tool::CurveOnSurface(E,F,First,Last);
2680 if (C2d.IsNull()) {
2681 Standard_ConstructionError::Raise("ConstructionError in PutProfilAt");
2682 }
2683
2684 if (E.Orientation() == TopAbs_REVERSED) {
2685 if (!AtStart) C2d->D1(First,P,D1);else C2d->D1(Last,P,D1);
2686 D1.Reverse();
2687 }
2688 else {
2689 if (!AtStart) C2d->D1(Last,P,D1) ;else C2d->D1(First,P,D1);
2690 }
2691 gp_Pnt P3d(P.X() ,P.Y() ,0.);
2692 gp_Vec V3d(D1.X(),D1.Y(),0.);
2693
2694 gp_Ax3 Ax( P3d, gp::DZ(), V3d);
2695 gp_Trsf Trans;
2696 Trans.SetTransformation(Ax,AxeRef);
2697 TopoDS_Shape aLocalShape = ProfRef.Moved(TopLoc_Location(Trans));
2698 Prof = TopoDS::Wire(aLocalShape);
2699// Prof = TopoDS::Wire(ProfRef.Moved(TopLoc_Location(Trans)));
2700 return Prof;
2701}
2702
2703
2704//=======================================================================
2705//function : TrimEdge
2706//purpose :
2707//=======================================================================
2708
2709void TrimEdge (const TopoDS_Edge& Edge,
2710 const TopTools_SequenceOfShape& TheEdgesControle,
2711 TopTools_SequenceOfShape& TheVer,
2712 TColStd_SequenceOfReal& ThePar,
2713 TopTools_SequenceOfShape& S)
2714{
2715 Standard_Boolean Change = Standard_True;
2716 BRep_Builder TheBuilder;
2717 S.Clear();
0d969553
Y
2718 //------------------------------------------------------------
2719 // Parse two sequences depending on the parameter on the edge.
2720 //------------------------------------------------------------
7fd59977 2721 while (Change) {
2722 Change = Standard_False;
2723 for (Standard_Integer i = 1; i < ThePar.Length(); i++) {
2724 if (ThePar.Value(i) > ThePar.Value(i+1)) {
2725 ThePar.Exchange(i,i+1);
2726 TheVer.Exchange(i,i+1);
2727 Change = Standard_True;
2728 }
2729 }
2730 }
2731
2732 //----------------------------------------------------------
0d969553 2733 // If a vertex is not in the proofing point, it is removed.
7fd59977 2734 //----------------------------------------------------------
2735 if (!BRep_Tool::Degenerated(Edge)) {
2736 for (Standard_Integer k = 1; k <= TheVer.Length(); k ++) {
2737 if ( DoubleOrNotInFace (TheEdgesControle,
2738 TopoDS::Vertex(TheVer.Value(k)))) {
2739 TheVer.Remove(k);
2740 ThePar.Remove(k);
2741 k--;
2742 }
2743 }
2744 }
2745
2746 //-------------------------------------------------------------------
0d969553
Y
2747 // Processing of double vertices for non-degenerated edges.
2748 // If a vertex_double appears twice in the edges of control,
2749 // the vertex is eliminated .
2750 // otherwise its only representation is preserved.
7fd59977 2751 //-------------------------------------------------------------------
2752 if (!BRep_Tool::Degenerated(Edge)) {
2753 for (Standard_Integer k = 1; k < TheVer.Length(); k ++) {
2754 if (TheVer.Value(k).IsSame(TheVer.Value(k+1))) {
2755 TheVer.Remove(k+1);
2756 ThePar.Remove(k+1);
2757 if ( DoubleOrNotInFace (TheEdgesControle,
2758 TopoDS::Vertex(TheVer.Value(k)))) {
2759 TheVer.Remove(k);
2760 ThePar.Remove(k);
2761// k--;
2762 }
2763 k--;
2764 }
2765 }
2766 }
2767
2768 //-----------------------------------------------------------
0d969553
Y
2769 // Creation of edges.
2770 // the number of vertices should be even. The edges to be created leave
2771 // from a vertex with uneven index i to vertex i+1;
7fd59977 2772 //-----------------------------------------------------------
2773 for (Standard_Integer k = 1; k < TheVer.Length(); k = k+2) {
2774 TopoDS_Shape aLocalShape = Edge.EmptyCopied();
2775 TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape);
2776// TopoDS_Edge NewEdge = TopoDS::Edge(Edge.EmptyCopied());
2777
2778 if (NewEdge.Orientation() == TopAbs_REVERSED) {
2779 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_REVERSED));
2780 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_FORWARD));
2781 }
2782 else {
2783 TheBuilder.Add (NewEdge,TheVer.Value(k) .Oriented(TopAbs_FORWARD));
2784 TheBuilder.Add (NewEdge,TheVer.Value(k+1).Oriented(TopAbs_REVERSED));
2785 }
2786 TheBuilder.Range(NewEdge,ThePar.Value(k),ThePar.Value(k+1));
2787// modified by NIZHNY-EAP Wed Dec 22 12:09:48 1999 ___BEGIN___
2788 BRepLib::UpdateTolerances(NewEdge,Standard_False);
2789// modified by NIZHNY-EAP Wed Dec 22 13:34:19 1999 ___END___
2790 S.Append(NewEdge);
2791 }
2792}
2793
2794//=======================================================================
2795//function : ComputeIntervals
2796//purpose :
2797//=======================================================================
2798
2799void ComputeIntervals (const TopTools_SequenceOfShape& VOnF,
2800 const TopTools_SequenceOfShape& VOnL,
2801 const TColgp_SequenceOfPnt& ParOnF,
2802 const TColgp_SequenceOfPnt& ParOnL,
2803 const BRepFill_TrimSurfaceTool& Trim,
2804 const Handle(Geom2d_Curve)& Bis,
2805 const TopoDS_Vertex& VS,
2806 const TopoDS_Vertex& VE,
2807 TColStd_SequenceOfReal& FirstPar,
2808 TColStd_SequenceOfReal& LastPar,
2809 TopTools_SequenceOfShape& FirstV,
2810 TopTools_SequenceOfShape& LastV )
2811{
2812 Standard_Integer IOnF = 1,IOnL = 1;
2813 Standard_Real U1,U2;
2814 TopoDS_Shape V1,V2;
2815
2816 if (!VS.IsNull()) {
2817 U1 = Bis->FirstParameter();
2818 V1 = VS;
2819 }
2820 while ( IOnF <= VOnF.Length() || IOnL <= VOnL.Length()) {
2821 //---------------------------------------------------------
0d969553
Y
2822 // Return the smallest parameter on the bissectrice
2823 // correponding to the current positions IOnF,IOnL.
7fd59977 2824 //---------------------------------------------------------
2825 if ( IOnL > VOnL.Length() ||
2826 (IOnF <= VOnF.Length() &&
2827 ParOnF.Value(IOnF).X() < ParOnL.Value(IOnL).X())) {
2828
2829 U2 = ParOnF.Value(IOnF).X();
2830 V2 = VOnF .Value(IOnF);
2831 IOnF++;
2832 }
2833 else{
2834 U2 = ParOnL.Value(IOnL).X();
2835 V2 = VOnL .Value(IOnL);
2836 IOnL++;
2837 }
2838 //---------------------------------------------------------------------
0d969553
Y
2839 // When V2 and V1 are different the medium point P of the
2840 // interval is tested compared to the face. If P is in the face the interval
2841 // is valid.
7fd59977 2842 //---------------------------------------------------------------------
2843 if (!V1.IsNull() && !V2.IsSame(V1)) {
2844 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2845 if (Trim.IsOnFace(P)) {
2846 FirstPar.Append(U1); LastPar .Append(U2);
2847 FirstV. Append(V1); LastV .Append(V2);
2848 }
2849 }
2850 U1 = U2;
2851 V1 = V2;
2852 }
2853
2854 if (!VE.IsNull()) {
2855 U2 = Bis->LastParameter();
2856 V2 = VE;
2857 if (!V2.IsSame(V1)) {
2858 gp_Pnt2d P = Bis->Value((U2 + U1)*0.5);
2859 if (Trim.IsOnFace(P)) {
2860 FirstPar.Append(U1); LastPar .Append(U2);
2861 FirstV.Append (V1); LastV .Append(V2);
2862 }
2863 }
2864 }
2865
2866}
2867
2868//=======================================================================
2869//function : Relative
0d969553
Y
2870//purpose : Commun is true if two wires have V in common
2871// return FORWARD if the wires near the vertex are at
2872// the same side. otherwise REVERSED.
7fd59977 2873//=======================================================================
2874static TopAbs_Orientation Relative (const TopoDS_Wire& W1,
2875 const TopoDS_Wire& W2,
2876 const TopoDS_Vertex& V,
2877 Standard_Boolean& Commun)
2878{
2879 TopExp_Explorer Exp;
2880 TopoDS_Edge E1,E2;
2881 TopoDS_Vertex V1,V2;
2882
2883 for (Exp.Init(W1,TopAbs_EDGE); Exp.More(); Exp.Next()) {
2884 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
2885 TopExp::Vertices(E,V1,V2);
2886 if (V1.IsSame(V) || V2.IsSame(V)) {
2887 E1 = E;
2888 break;
2889 }
2890 }
2891 for (Exp.Init(W2,TopAbs_EDGE); Exp.More(); Exp.Next()) {
2892 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
2893 TopExp::Vertices(E,V1,V2);
2894 if (V1.IsSame(V) || V2.IsSame(V)) {
2895 E2 = E;
2896 break;
2897 }
2898 }
2899
2900 if (E1.IsNull() || E2.IsNull()) {
2901 Commun = Standard_False;
2902 return TopAbs_FORWARD;
2903 }
2904 Commun = Standard_True;
2905
2906 TopoDS_Wire WW1 = BRepLib_MakeWire(E1);
2907 TopoDS_Wire WW2 = BRepLib_MakeWire(E2);
2908 Standard_Real Tol = BRepFill_Confusion();
0d969553 2909 if (Side(WW1,Tol) < 4 && Side(WW2,Tol) < 4) // two to the left
7fd59977 2910 return TopAbs_FORWARD;
0d969553 2911 if (Side(WW1,Tol) > 4 && Side(WW2,Tol) > 4) // two to the right
7fd59977 2912 return TopAbs_FORWARD;
2913
2914 return TopAbs_REVERSED;
2915}
2916//=======================================================================
2917//function : OriEdgeInFace
2918//purpose :
2919//=======================================================================
2920
2921TopAbs_Orientation OriEdgeInFace (const TopoDS_Edge& E,
2922 const TopoDS_Face& F )
2923
2924{
7fd59977 2925 TopExp_Explorer Exp(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
2926
2927 for (; Exp.More() ;Exp.Next()) {
2928 if (Exp.Current().IsSame(E)) {
2929 return Exp.Current().Orientation();
2930 }
2931 }
2932 Standard_ConstructionError::Raise("BRepFill_Evolved::OriEdgeInFace");
2933 return E.Orientation();
2934}
2935
2936
2937
2938//=======================================================================
2939//function : IsOnFace
0d969553
Y
2940//purpose : Return the position of the point defined by d1
2941// in the face defined by d2 d3.
7fd59977 2942//
0d969553
Y
2943// 0 : the point is out of the face.
2944// 1 : the point is on edge corresponding to d2.
2945// 2 : the point is inside the face.
2946// 3 : the point is on edge corresponding to d3.
7fd59977 2947//=======================================================================
2948
2949Standard_Integer PosOnFace (Standard_Real d1,
2950 Standard_Real d2,
2951 Standard_Real d3)
2952{
2953 if (Abs(d1 - d2) <= BRepFill_Confusion())
2954 return 1;
2955 if (Abs(d1 - d3) <= BRepFill_Confusion())
2956 return 3;
2957
2958 if (d2 < d3) {
2959 if (d1 > (d2 + BRepFill_Confusion()) &&
2960 d1 < (d3 - BRepFill_Confusion()) )
2961 return 2;
2962 }
2963 else {
2964 if (d1 > (d3 + BRepFill_Confusion()) &&
2965 d1 < (d2 - BRepFill_Confusion()) )
2966 return 2;
2967 }
2968 return 0;
2969}
2970
2971//=======================================================================
2972//function : DoubleOrNotInFace
0d969553
Y
2973//purpose : Return True if V appears zero or two times in the sequence
2974// of edges EC
7fd59977 2975//=======================================================================
2976
2977Standard_Boolean DoubleOrNotInFace(const TopTools_SequenceOfShape& EC,
2978 const TopoDS_Vertex& V)
2979{
2980 Standard_Boolean Vu = Standard_False;
2981
2982 for (Standard_Integer i = 1; i <= EC.Length(); i++) {
2983 TopoDS_Vertex V1,V2;
2984 TopExp::Vertices(TopoDS::Edge(EC.Value(i)),V1,V2);
2985 if (V1.IsSame(V)) {
2986 if (Vu) return Standard_True;
2987 else Vu = Standard_True;
2988 }
2989 if (V2.IsSame(V)) {
2990 if (Vu) return Standard_True;
2991 else Vu = Standard_True;
2992 }
2993 }
2994 if (Vu) return Standard_False;
2995 else return Standard_True;
2996}
2997
2998
2999//=======================================================================
3000//function : DistanceToOZ
3001//purpose :
3002//=======================================================================
3003
3004Standard_Real DistanceToOZ (const TopoDS_Vertex& V)
3005{
3006 gp_Pnt PV3d = BRep_Tool::Pnt(V);
3007 return Abs(PV3d.Y());
3008}
3009
3010//=======================================================================
3011//function : Altitud
3012//purpose :
3013//=======================================================================
3014
3015Standard_Real Altitud (const TopoDS_Vertex& V)
3016{
3017 gp_Pnt PV3d = BRep_Tool::Pnt(V);
3018 return PV3d.Z();
3019}
3020
3021//=======================================================================
3022//function : SimpleExpression
3023//purpose :
3024//=======================================================================
3025
3026void SimpleExpression (const Bisector_Bisec& B,
3027 Handle(Geom2d_Curve)& Bis)
3028{
3029 Bis = B.Value();
3030
3031 Handle(Standard_Type) BT = Bis->DynamicType();
3032 if (BT == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
3033 Handle(Geom2d_TrimmedCurve) TrBis
3034 = Handle(Geom2d_TrimmedCurve)::DownCast(Bis);
3035 Handle(Geom2d_Curve) BasBis = TrBis->BasisCurve();
3036 BT = BasBis->DynamicType();
3037 if (BT == STANDARD_TYPE(Bisector_BisecAna)) {
3038 Bis = Handle(Bisector_BisecAna)::DownCast(BasBis)->Geom2dCurve();
3039 Bis = new Geom2d_TrimmedCurve (Bis,
3040 TrBis->FirstParameter(),
3041 TrBis->LastParameter());
3042 }
3043 }
3044}
3045
3046//=======================================================================
3047//function : CutEdgeProf
0d969553 3048//purpose : Projection and Cut of an edge at extrema of distance to axis OZ.
7fd59977 3049//=======================================================================
3050
3051void CutEdgeProf (const TopoDS_Edge& E,
3052 const Handle(Geom_Plane)& Plane,
3053 const Handle(Geom2d_Line)& Line,
3054 TopTools_ListOfShape& Cuts,
3055 TopTools_DataMapOfShapeShape& MapVerRefMoved)
3056{
3057 Cuts.Clear();
3058
3059 Standard_Real f,l;
3060 Handle(Geom_Curve) C;
3061 Handle(Geom_TrimmedCurve) CT;
3062 Handle(Geom2d_Curve) C2d;
3063 TopLoc_Location L;
3064
0d969553 3065 // Return the curve associated to each Edge
7fd59977 3066 C = BRep_Tool::Curve(E,L,f,l);
3067 CT = new Geom_TrimmedCurve(C,f,l);
3068 CT->Transform(L.Transformation());
3069
0d969553 3070 // project it in the plane and return the associated PCurve
7fd59977 3071 gp_Dir Normal = Plane->Pln().Axis().Direction();
3072 C =
3073 Handle(Geom_Curve)::DownCast(GeomProjLib::ProjectOnPlane(CT,Plane,
3074 Normal,
3075 Standard_False));
3076 C2d = GeomProjLib::Curve2d(C,Plane);
3077
0d969553 3078 // Calculate the extrema with the straight line
7fd59977 3079 TColStd_SequenceOfReal Seq;
3080
3081 Standard_Real U1 = -Precision::Infinite();
3082 Standard_Real U2 = Precision::Infinite();
3083 f= C2d->FirstParameter();
3084 l= C2d->LastParameter();
3085
3086 Bnd_Box2d B;
3087 Geom2dAdaptor_Curve AC2d(C2d);
3088 BndLib_Add2dCurve::Add(AC2d,BRepFill_Confusion(),B);
3089 Standard_Real xmin,xmax;
3090 B.Get(xmin,U1,xmax,U2);
3091
3092// modified by NIZHNY-EAP Wed Feb 2 16:32:37 2000 ___BEGIN___
3093 // no sense if C2 is normal to Line or really is a point
3094 if (U1 != U2) {
3095 Geom2dAPI_ExtremaCurveCurve Extrema(Line,C2d,U1-1.,U2+1.,f,l);
3096
3097 Standard_Integer i, Nb = Extrema.NbExtrema();
3098 for ( i = 1; i <= Nb; i++) {
3099 Extrema.Parameters(i,U1,U2);
3100 Seq.Append(U2);
3101 }
3102 }
3103// modified by NIZHNY-EAP Wed Feb 2 16:33:05 2000 ___END___
3104
3105 // On calcule les intersection avec Oy.
3106 Geom2dAdaptor_Curve ALine(Line);
3107 Standard_Real Tol = Precision::Intersection();
3108 Standard_Real TolC = 0.;
3109
3110 Geom2dInt_GInter Intersector(ALine,AC2d,TolC,Tol);
3111 Standard_Integer i, Nb = Intersector.NbPoints();
3112
3113 for ( i = 1; i <= Nb; i++) {
3114 Seq.Append(Intersector.Point(i).ParamOnSecond());
3115 }
3116
3117 // Compute the new edges.
3118 BRep_Builder Builder;
3119 TopoDS_Vertex VV,Vf,Vl,VRf,VRl;
3120 TopExp::Vertices(E,VRf,VRl);
3121
3122 if (!MapVerRefMoved.IsBound(VRf)) {
3123 Builder.MakeVertex(Vf,C->Value(f),BRep_Tool::Tolerance(VRf));
3124 MapVerRefMoved.Bind(VRf,Vf);
3125 }
3126 else {
3127 Vf = TopoDS::Vertex(MapVerRefMoved(VRf));
3128 }
3129
3130 if (!MapVerRefMoved.IsBound(VRl)) {
3131 Builder.MakeVertex(Vl,C->Value(l),BRep_Tool::Tolerance(VRl));
3132 MapVerRefMoved.Bind(VRl,Vl);
3133 }
3134 else {
3135 Vl = TopoDS::Vertex(MapVerRefMoved(VRl));
3136 }
3137
3138 if ( !Seq.IsEmpty()) {
3139
3140 Bubble(Seq);
3141
3142 Standard_Boolean Empty = Standard_False;
3143
3144 Standard_Real CurParam = f;
3145 Standard_Real Param;
3146
3147 while ( !Empty) {
3148 Param = Seq.First();
3149 Seq.Remove(1);
3150 Empty = Seq.IsEmpty();
3151 if (Abs( Param - CurParam) > BRepFill_Confusion() &&
3152 Abs( Param - l) > BRepFill_Confusion() ) {
3153
3154 VV = BRepLib_MakeVertex( C->Value(Param));
3155
3156 TopoDS_Edge EE = BRepLib_MakeEdge(C,Vf,VV);
3157 EE.Orientation(E.Orientation());
3158 if ( EE.Orientation() == TopAbs_FORWARD)
3159 Cuts.Append(EE);
3160 else
3161 Cuts.Prepend(EE);
3162
0d969553 3163 // reinitialize
7fd59977 3164 CurParam = Param;
3165 Vf = VV;
3166 }
3167 }
3168 }
3169
3170 TopoDS_Edge EE = BRepLib_MakeEdge(C,Vf,Vl);
3171 EE.Orientation(E.Orientation());
3172 if ( EE.Orientation() == TopAbs_FORWARD)
3173 Cuts.Append(EE);
3174 else
3175 Cuts.Prepend(EE);
3176}
3177
3178//=======================================================================
3179//function : CutEdge
0d969553
Y
3180//purpose : Cut an edge at thw extrema of curves and at points of inflexion.
3181// Closed circles are also cut in two.
3182// If <Cuts> are empty the edge is not modified.
3183// The first and the last vertex of the original edge
3184// belong to the first and last parts respectively.
7fd59977 3185//=======================================================================
3186void CutEdge (const TopoDS_Edge& E,
3187 const TopoDS_Face& F,
3188 TopTools_ListOfShape& Cuts)
3189{
3190 Cuts.Clear();
3191 MAT2d_CutCurve Cuter;
3192 Standard_Real f,l;
3193 Handle(Geom2d_Curve) C2d;
3194 Handle(Geom2d_TrimmedCurve) CT2d;
3195
3196 TopoDS_Vertex V1,V2,VF,VL;
3197 TopExp::Vertices (E,V1,V2);
3198 BRep_Builder B;
3199
3200 C2d = BRep_Tool::CurveOnSurface (E,F,f,l);
3201 CT2d = new Geom2d_TrimmedCurve(C2d,f,l);
3202
3203 if (CT2d->BasisCurve()->IsKind(STANDARD_TYPE(Geom2d_Circle)) &&
3204 E.Closed()) {
3205 //---------------------------
0d969553 3206 // Cut closed circle.
7fd59977 3207 //---------------------------
3208 Standard_Real m1 = (2*f + l)/3.;
3209 Standard_Real m2 = ( f + 2*l)/3.;
3210 gp_Pnt2d P1 = CT2d->Value(m1);
3211 gp_Pnt2d P2 = CT2d->Value(m2);
3212
3213 TopoDS_Vertex VL1 = BRepLib_MakeVertex(gp_Pnt(P1.X(), P1.Y(), 0.));
3214 TopoDS_Vertex VL2 = BRepLib_MakeVertex(gp_Pnt(P2.X(), P2.Y(), 0.));
3215 TopoDS_Shape aLocalShape1 = E.EmptyCopied();
3216 TopoDS_Shape aLocalShape2 = E.EmptyCopied();
3217 TopoDS_Shape aLocalShape3 = E.EmptyCopied();
3218 TopoDS_Edge FE = TopoDS::Edge(aLocalShape1);
3219 TopoDS_Edge ME = TopoDS::Edge(aLocalShape2);
3220 TopoDS_Edge LE = TopoDS::Edge(aLocalShape3);
3221// TopoDS_Edge FE = TopoDS::Edge(E.EmptyCopied());
3222// TopoDS_Edge ME = TopoDS::Edge(E.EmptyCopied());
3223// TopoDS_Edge LE = TopoDS::Edge(E.EmptyCopied());
3224
3225 FE.Orientation(TopAbs_FORWARD);
3226 ME.Orientation(TopAbs_FORWARD);
3227 LE.Orientation(TopAbs_FORWARD );
3228
3229 B.Add (FE,V1);
3230 B.Add (FE,VL1.Oriented(TopAbs_REVERSED));
3231 B.Range(FE, f, m1);
3232
3233 B.Add (ME,VL1.Oriented(TopAbs_FORWARD));
3234 B.Add (ME,VL2.Oriented(TopAbs_REVERSED));
3235 B.Range(ME, m1, m2);
3236
3237 B.Add (LE,VL2.Oriented(TopAbs_FORWARD));
3238 B.Add (LE,V2);
3239 B.Range(LE, m2, l);
3240
3241 Cuts.Append(FE.Oriented(E.Orientation()));
3242 Cuts.Append(ME.Oriented(E.Orientation()));
3243 Cuts.Append(LE.Oriented(E.Orientation()));
3244 //--------
0d969553 3245 // Return.
7fd59977 3246 //--------
3247 return;
3248 }
3249
3250 //-------------------------
0d969553 3251 // Cut of the curve.
7fd59977 3252 //-------------------------
3253 Cuter.Perform(CT2d);
3254
3255 if (Cuter.UnModified()) {
3256 //-----------------------------
0d969553 3257 // edge not modified => return.
7fd59977 3258 //-----------------------------
3259 return;
3260 }
3261 else {
0d969553
Y
3262 //------------------------
3263 // Creation of cut edges.
3264 //------------------------
7fd59977 3265 VF = V1;
3266
3267 for ( Standard_Integer k = 1; k <= Cuter.NbCurves(); k++) {
3268 Handle(Geom2d_TrimmedCurve)CC = Cuter.Value(k);
3269 if (k == Cuter.NbCurves()) {VL = V2;}
3270 else {
3271 gp_Pnt2d P = CC->Value(CC->LastParameter());
3272 VL = BRepLib_MakeVertex(gp_Pnt(P.X(), P.Y(), 0.));
3273 }
3274 TopoDS_Shape aLocalShape = E.EmptyCopied();
3275 TopoDS_Edge NE = TopoDS::Edge(aLocalShape);
3276// TopoDS_Edge NE = TopoDS::Edge(E.EmptyCopied());
3277 NE.Orientation(TopAbs_FORWARD);
3278 B.Add (NE,VF.Oriented(TopAbs_FORWARD));
3279 B.Add (NE,VL.Oriented(TopAbs_REVERSED));
3280 B.Range(NE,CC->FirstParameter(),CC->LastParameter());
3281 Cuts.Append(NE.Oriented(E.Orientation()));
3282 VF = VL;
3283 }
3284 }
3285}
3286
3287//=======================================================================
3288//function : VertexFromNode
0d969553
Y
3289//purpose : Test if the position of aNode correspondingly to the distance to OZ
3290// of vertices VF and VL. returns Status.
3291// if Status is different from 0 Returned
3292// the vertex corresponding to aNode is created.
7fd59977 3293//=======================================================================
3294
3295Standard_Integer VertexFromNode
3296(const Handle(MAT_Node)& aNode,
3297 const TopoDS_Edge& E,
3298 const TopoDS_Vertex& VF,
3299 const TopoDS_Vertex& VL,
3300 BRepFill_DataMapOfNodeDataMapOfShapeShape& MapNodeVertex,
3301 TopoDS_Vertex& VN)
3302{
3303 TopoDS_Shape ShapeOnNode;
3304 TopTools_DataMapOfShapeShape EmptyMap;
3305 Standard_Integer Status = 0;
3306 BRep_Builder B;
3307
3308 if (!aNode->Infinite()) {
3309 Status = PosOnFace(aNode->Distance(),
3310 DistanceToOZ(VF) , DistanceToOZ(VL));
3311 }
3312 if (Status == 2) ShapeOnNode = E;
3313 else if (Status == 1) ShapeOnNode = VF;
3314 else if (Status == 3) ShapeOnNode = VL;
3315
3316 if (!ShapeOnNode.IsNull()) {
0d969553
Y
3317 //-------------------------------------------------
3318 // the vertex will correspond to a node of the map
3319 //-------------------------------------------------
7fd59977 3320 if (MapNodeVertex.IsBound(aNode) &&
3321 MapNodeVertex(aNode).IsBound(ShapeOnNode)) {
3322 VN = TopoDS::Vertex
3323 (MapNodeVertex(aNode)(ShapeOnNode));
3324 }
3325 else {
3326 B.MakeVertex (VN);
3327 if (!MapNodeVertex.IsBound(aNode)) {
3328 MapNodeVertex.Bind(aNode,EmptyMap);
3329 }
3330 MapNodeVertex(aNode).Bind(ShapeOnNode,VN);
3331 }
3332 }
3333 return Status;
3334}
3335