1 // Created on: 1996-10-02
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <LocOpe_SplitDrafts.ixx>
25 #include <TopExp_Explorer.hxx>
26 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
28 #include <BRep_Builder.hxx>
29 #include <BRep_Tool.hxx>
31 #include <BRepTools_Substitution.hxx>
33 #include <LocOpe_WiresOnShape.hxx>
34 #include <LocOpe_Spliter.hxx>
35 #include <LocOpe_SplitShape.hxx>
36 #include <LocOpe_FindEdges.hxx>
37 #include <LocOpe_BuildShape.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Edge.hxx>
43 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
44 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
46 #include <IntAna_QuadQuadGeo.hxx>
47 #include <IntCurveSurface_HInter.hxx>
48 #include <IntCurveSurface_IntersectionPoint.hxx>
49 #include <IntCurveSurface_IntersectionSegment.hxx>
50 #include <GeomInt_IntSS.hxx>
51 #include <Extrema_ExtPC.hxx>
52 #include <GeomAdaptor_HCurve.hxx>
53 #include <GeomAdaptor_HSurface.hxx>
54 #include <GeomAdaptor_Curve.hxx>
55 #include <GeomAdaptor_Surface.hxx>
57 #include <Geom_Surface.hxx>
58 #include <Geom_RectangularTrimmedSurface.hxx>
59 #include <Geom_Plane.hxx>
60 #include <Geom_Curve.hxx>
61 #include <Geom_TrimmedCurve.hxx>
62 #include <Geom_Line.hxx>
64 #include <Geom2d_Curve.hxx>
65 #include <Geom2d_Line.hxx>
66 #include <gp_Pnt2d.hxx>
67 #include <gp_Vec2d.hxx>
69 #include <GeomFill_Pipe.hxx>
71 #include <GProp_GProps.hxx>
73 #include <Standard_ConstructionError.hxx>
77 #include <Precision.hxx>
78 #include <BRepGProp.hxx>
81 static Standard_Boolean NewPlane(const TopoDS_Face&,
87 const Standard_Boolean);
89 static void MakeFace(TopoDS_Face&,
90 TopTools_ListOfShape&);
92 static TopoDS_Edge NewEdge(const TopoDS_Edge&,
94 const Handle(Geom_Surface)&,
96 const TopoDS_Vertex&);
99 static Standard_Boolean Contains(const TopTools_ListOfShape&,
100 const TopoDS_Shape&);
103 //=======================================================================
106 //=======================================================================
108 void LocOpe_SplitDrafts::Init(const TopoDS_Shape& S)
115 //=======================================================================
118 //=======================================================================
120 void LocOpe_SplitDrafts::Perform(const TopoDS_Face& F,
121 const TopoDS_Wire& W,
124 const Standard_Real Angle)
126 Perform(F,W,Extr,NPl,Angle,Extr,NPl,Angle,Standard_True,Standard_False);
130 //=======================================================================
133 //=======================================================================
135 void LocOpe_SplitDrafts::Perform(const TopoDS_Face& F,
136 const TopoDS_Wire& W,
139 const Standard_Real Angleg,
142 const Standard_Real Angled,
143 const Standard_Boolean ModLeft,
144 const Standard_Boolean ModRight)
151 if (myShape.IsNull() || F.IsNull() || W.IsNull()) {
152 Standard_NullObject::Raise();
155 if (!ModLeft && !ModRight) {
156 Standard_ConstructionError::Raise();
159 TopAbs_Orientation OriF = TopAbs_FORWARD;
161 Standard_Boolean FinS = Standard_False;
162 TopExp_Explorer exp,exp2;
163 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
164 const TopoDS_Shape& fac = exp.Current();
165 TopTools_ListOfShape thelist;
166 myMap.Bind(fac, thelist);
168 OriF = fac.Orientation();
169 FinS = Standard_True;
174 cout << "LocOpe_SplitDrafts:!Fins Standard_ConstructionError::Raise()" << endl;
175 Standard_ConstructionError::Raise();
178 gp_Pln NewPlg,NewPld;
179 gp_Ax1 NormalFg,NormalFd;
180 TopoDS_Shape aLocalFace = F.Oriented(OriF);
182 if (!NewPlane(TopoDS::Face(aLocalFace),
183 Extrg,NPlg,Angleg,NewPlg,NormalFg,ModLeft) ||
184 !NewPlane(TopoDS::Face(aLocalFace),
185 Extrd,NPld,Angled,NewPld,NormalFd,ModRight)) {
186 // if (!NewPlane(TopoDS::Face(F.Oriented(OriF)),
187 // Extrg,NPlg,Angleg,NewPlg,NormalFg,ModLeft) ||
188 // !NewPlane(TopoDS::Face(F.Oriented(OriF)),
189 // Extrd,NPld,Angled,NewPld,NormalFd,ModRight)) {
194 TopTools_ListIteratorOfListOfShape itl;
197 Handle(Geom_Surface) NewSg = new Geom_Plane(NewPlg);
198 Handle(Geom_Surface) NewSd = new Geom_Plane(NewPld);
199 Handle(Geom_Line) theLinePipe = new Geom_Line(NormalFg); // ou NormalFd
200 GeomInt_IntSS i2s(NewSg,NewSd,Precision::Confusion());
202 TopTools_MapOfShape theMap;
203 Handle(GeomAdaptor_HCurve) HAC = new GeomAdaptor_HCurve;
204 GeomAdaptor_Curve AC;
205 Handle(GeomAdaptor_HSurface) HAS = new GeomAdaptor_HSurface;
206 GeomAdaptor_Surface AS;
207 IntCurveSurface_HInter intcs;
209 TopoDS_Wire theW = W;
210 if (i2s.IsDone() && i2s.NbLines() > 0) {
211 // on split le wire" << endl;
213 GeomFill_Pipe thePipe;
214 thePipe.GenerateParticularCase(Standard_True);
215 thePipe.Init(theLinePipe,i2s.Line(1));
216 thePipe.Perform(Standard_True);
218 Handle(Geom_Surface) Spl = thePipe.Surface();
222 LocOpe_SplitShape splw(W);
224 for (exp.Init(W,TopAbs_EDGE); exp.More(); exp.Next()) {
225 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
226 if (theMap.Add(edg)) {
229 Handle(Geom_Curve) C = BRep_Tool::Curve(edg,f,l);
232 intcs.Perform(HAC,HAS);
233 if (!intcs.IsDone()) {
234 continue; // voir ce qu`on peut faire de mieux
237 if (intcs.NbSegments() >= 2) {
238 continue; // Not yet implemented...and probably never"
241 if (intcs.NbSegments() == 1) {
242 const IntCurveSurface_IntersectionPoint& P1 =
243 intcs.Segment(1).FirstPoint();
244 const IntCurveSurface_IntersectionPoint& P2 =
245 intcs.Segment(1).SecondPoint();
246 const gp_Pnt& pf = P1.Pnt();
247 const gp_Pnt& pl = P2.Pnt();
249 TopExp::Vertices(edg,Vf,Vl);
250 gp_Pnt Pf = BRep_Tool::Pnt(Vf);
251 gp_Pnt Pl = BRep_Tool::Pnt(Vl);
252 Standard_Real Tolf = BRep_Tool::Tolerance(Vf);
253 Standard_Real Toll = BRep_Tool::Tolerance(Vl);
257 Standard_Real dff = pf.SquareDistance(Pf);
258 Standard_Real dfl = pf.SquareDistance(Pl);
259 Standard_Real dlf = pl.SquareDistance(Pf);
260 Standard_Real dll = pl.SquareDistance(Pl);
262 if ((dff <= Tolf && dll <= Toll) ||
263 (dlf <= Tolf && dfl <= Toll)) {
267 // on segmente edg en pf et pl
268 TopoDS_Vertex Vnewf,Vnewl;
269 B.MakeVertex(Vnewf,pf,Precision::Confusion());
270 B.MakeVertex(Vnewl,pl,Precision::Confusion());
271 if (P1.W() >= f && P1.W() <= l &&
272 P2.W() >= f && P2.W() <= l) {
273 splw.Add(Vnewf,P1.W(),edg);
274 splw.Add(Vnewl,P2.W(),edg);
281 else if (intcs.NbPoints() != 0) {
283 TopExp::Vertices(edg,Vf,Vl);
284 gp_Pnt Pf = BRep_Tool::Pnt(Vf);
285 gp_Pnt Pl = BRep_Tool::Pnt(Vl);
286 Standard_Real Tolf = BRep_Tool::Tolerance(Vf);
287 Standard_Real Toll = BRep_Tool::Tolerance(Vl);
291 for (Standard_Integer i = 1; i <= intcs.NbPoints(); i++) {
292 const IntCurveSurface_IntersectionPoint& Pi = intcs.Point(i);
293 const gp_Pnt& pi = Pi.Pnt();
294 Standard_Real dif = pi.SquareDistance(Pf);
295 Standard_Real dil = pi.SquareDistance(Pl);
298 else if (dil <= Toll) {
301 if (Pi.W() >= f && Pi.W() <= l) {
303 B.MakeVertex(Vnew,pi,Precision::Confusion());
304 splw.Add(Vnew,Pi.W(),edg);
312 const TopTools_ListOfShape& lres = splw.DescendantShapes(W);
313 if (lres.Extent() != 1) {
317 if (!W.IsSame(lres.First())) {
319 theW = TopoDS::Wire(lres.First());
322 for (exp.ReInit(); exp.More(); exp.Next()) {
323 if (!myMap.IsBound(exp.Current())) {
324 TopTools_ListOfShape thelist1;
325 myMap.Bind(exp.Current(), thelist1);
326 for (itl.Initialize(splw.DescendantShapes(exp.Current()));
327 itl.More(); itl.Next()) {
328 myMap(exp.Current()).Append(itl.Value());
330 for (exp2.Init(exp.Current(),TopAbs_VERTEX);exp2.More();exp2.Next()) {
331 if (!myMap.IsBound(exp2.Current())) {
332 TopTools_ListOfShape thelist2;
333 myMap.Bind(exp2.Current(), thelist2);
334 myMap(exp2.Current()).Append(exp2.Current());
341 for (exp.Init(W,TopAbs_EDGE); exp.More(); exp.Next()) {
342 if (!myMap.IsBound(exp.Current())) {
343 TopTools_ListOfShape thelist3;
344 myMap.Bind(exp.Current(), thelist3);
345 myMap(exp.Current()).Append(exp.Current());
346 for (exp2.Init(exp.Current(),TopAbs_VERTEX);exp2.More();exp2.Next()) {
347 if (!myMap.IsBound(exp2.Current())) {
348 TopTools_ListOfShape thelist4;
349 myMap.Bind(exp2.Current(), thelist4);
350 myMap(exp2.Current()).Append(exp2.Current());
357 // On split la face par le wire
359 Handle(LocOpe_WiresOnShape) WonS = new LocOpe_WiresOnShape(myShape);
360 LocOpe_Spliter Spls(myShape);
363 // JAG Le code suivant marchera apres integration de thick0
364 // LocOpe_FindEdges fined(W,F);
365 // for (fined.InitIterator(); fined.More(); fined.Next()) {
366 // WonS->Bind(fined.EdgeFrom(),fined.EdgeTo());
370 if (!Spls.IsDone()) {
374 TopoDS_Shape Res = Spls.ResultingShape();
375 const TopTools_ListOfShape& theLeft = Spls.DirectLeft();
378 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next()) {
379 const TopoDS_Shape& fac = exp.Current();
380 for (itl.Initialize(Spls.DescendantShapes(fac)); itl.More(); itl.Next()) {
381 myMap(fac).Append(itl.Value());
385 TopTools_DataMapOfShapeShape MapW;
386 for (exp.Init(theW,TopAbs_EDGE); exp.More(); exp.Next()) {
387 if (!MapW.IsBound(exp.Current())) {
388 MapW.Bind(exp.Current(),TopoDS_Shape());
389 for (exp2.Init(exp.Current(),TopAbs_VERTEX); exp2.More(); exp2.Next()) {
390 if (!MapW.IsBound(exp2.Current())) {
391 MapW.Bind(exp2.Current(),TopoDS_Shape());
400 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
401 TopExp::MapShapesAndAncestors(Res,TopAbs_EDGE,TopAbs_FACE,theMapEF);
403 // On stocke les geometries potentiellement generees par les edges
404 TopTools_IndexedDataMapOfShapeShape MapEV; // genere
405 TopTools_DataMapOfShapeListOfShape MapSg,MapSd; // image a gauche et a droite
407 Standard_Integer Nbedges,index;
408 for (itl.Initialize(myMap(F)); itl.More(); itl.Next()) {
409 const TopoDS_Shape& fac = TopoDS::Face(itl.Value());
410 for (exp.Init(fac,TopAbs_EDGE); exp.More(); exp.Next()) {
411 const TopoDS_Shape& edg = exp.Current();
412 if (MapEV.FindIndex(edg) != 0) {
415 if (MapW.IsBound(edg)) { // edge du wire initial
418 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(edg),Loc,f,l);
419 if (C->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) {
420 C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
422 C = Handle(Geom_Curve)::
423 DownCast(C->Transformed(Loc.Transformation()));
425 GeomFill_Pipe thePipe;
426 thePipe.GenerateParticularCase(Standard_True);
427 thePipe.Init(theLinePipe,C);
428 thePipe.Perform(Standard_True);
430 Handle(Geom_Surface) thePS = thePipe.Surface();
431 if (thePS->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
432 thePS = Handle(Geom_RectangularTrimmedSurface)::DownCast(thePS)
437 B.MakeFace(NewFace,thePS,Precision::Confusion());
438 MapEV.Add(edg,NewFace);
440 else { // on recupere la face.
441 index = theMapEF.FindIndex(edg);
442 if (theMapEF(index).Extent() != 2) {
446 if (theMapEF(index).First().IsSame(fac)) {
447 MapEV.Add(edg,theMapEF(index).Last());
450 MapEV.Add(edg,theMapEF(index).First());
457 TopTools_DataMapOfShapeShape MapSonS;
459 Nbedges = MapEV.Extent();
460 for (index = 1; index <= Nbedges; index++) {
461 for (exp.Init(MapEV.FindKey(index),TopAbs_VERTEX);
462 exp.More(); exp.Next()) {
463 const TopoDS_Vertex& vtx = TopoDS::Vertex(exp.Current());
464 if (MapEV.FindIndex(vtx)!= 0) {
468 // Localisation du vertex :
469 // - entre 2 edges d`origine : on recupere l`edge qui n`est
471 // - entre 2 edges du wire : droite
472 // - mixte : intersection de surfaces
473 for ( j = 1; j<=Nbedges; j++) {
477 for (exp2.Init(MapEV.FindKey(j),TopAbs_VERTEX);
478 exp2.More(); exp2.Next()) {
479 const TopoDS_Shape& vtx2 = exp2.Current();
480 if (vtx2.IsSame(vtx)) {
488 Standard_Integer Choice = 0;
489 const TopoDS_Shape& edg1 = MapEV.FindKey(index);
492 edg2 = MapEV.FindKey(j);
497 if (MapW.IsBound(edg1)) {
498 if (j>Nbedges) { // doit correspondre a edge ferme
499 Choice = 2; // droite
501 else if (MapW.IsBound(MapEV.FindKey(j))) {
502 Choice = 2; // droite
509 if (j>Nbedges) { // doit correspondre a edge ferme
510 Choice = 1; // edge a retrouver
512 else if (!MapW.IsBound(MapEV.FindKey(j))) {
513 Choice = 1; // edge a retrouver
519 Handle(Geom_Curve) Newc;
520 Handle(Geom2d_Curve) newCs1,newCs2;
521 Standard_Real knownp=0;
526 for (exp2.Init(Res,TopAbs_EDGE); exp2.More(); exp2.Next()) {
527 if (exp2.Current().IsSame(edg1) || exp2.Current().IsSame(edg2)) {
530 // for (TopExp_Explorer exp3(exp2.Current().Oriented(TopAbs_FORWARD),
531 TopExp_Explorer exp3(exp2.Current().Oriented(TopAbs_FORWARD),
533 for ( ; exp3.More(); exp3.Next()) {
534 if (exp3.Current().IsSame(vtx)) {
545 Newc = BRep_Tool::Curve(TopoDS::Edge(exp2.Current()),Loc,f,l);
546 Newc = Handle(Geom_Curve)::DownCast
547 (Newc->Transformed(Loc.Transformation()));
548 Ebind = TopoDS::Edge(exp2.Current());
549 knownp = BRep_Tool::Parameter(vtx,Ebind);
551 else { // droite ??? il vaudrait mieux sortir
554 // gp_Lin theLine(NormalFg);
555 // theLine.Translate(NormalF.Location(),BRep_Tool::Pnt(vtx));
556 // Newc = new Geom_Line(theLine);
563 gp_Lin theLine(NormalFg);
564 theLine.Translate(NormalFg.Location(),BRep_Tool::Pnt(vtx));
565 Newc = new Geom_Line(theLine);
571 const TopoDS_Face& F1 = TopoDS::Face(MapEV.FindFromKey(edg1));
572 const TopoDS_Face& F2 = TopoDS::Face(MapEV.FindFromKey(edg2));
573 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1);
574 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2);
575 Standard_Boolean AppS1 = Standard_False;
576 Standard_Boolean AppS2 = Standard_False;
577 if (S1->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
578 AppS1 = Standard_True;
580 if (S2->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
581 AppS2 = Standard_True;
583 i2s.Perform(S1,S2,Precision::Confusion(),Standard_True,AppS1,AppS2);
584 if (!i2s.IsDone() || i2s.NbLines() <= 0) {
588 Standard_Real pmin=0, Dist2, Dist2Min, Glob2Min = RealLast();
589 GeomAdaptor_Curve TheCurve;
591 Standard_Integer i,imin,k;
592 gp_Pnt pv = BRep_Tool::Pnt(vtx);
594 for (i=1; i<= i2s.NbLines(); i++) {
595 TheCurve.Load(i2s.Line(i));
596 Extrema_ExtPC myExtPC(pv,TheCurve);
598 if (myExtPC.IsDone()) {
600 Standard_Real thepmin = TheCurve.FirstParameter();
601 myExtPC.TrimmedSquareDistances(Dist2Min,Dist2,p1b,p2b);
602 if (Dist2 < Dist2Min) {
603 thepmin = TheCurve.LastParameter();
605 for (k=1; k<=myExtPC.NbExt(); k++) {
606 Dist2 = myExtPC.SquareDistance(k);
607 if (Dist2 < Dist2Min) {
609 thepmin = myExtPC.Point(k).Parameter();
613 if (Dist2Min < Glob2Min) {
624 Newc = i2s.Line(imin);
627 newCs1 = i2s.LineOnS1(imin);
630 newCs2 = i2s.LineOnS2(imin);
637 // Determination des vertex par intersection sur Plg ou/et Pld
641 Standard_Integer nbfois = 2;
642 TopoDS_Vertex vtx1,vtx2;
643 Standard_Real p1=0,p2=0;
644 Standard_Boolean IsLeft=Standard_False;
646 // edge retrouve : on ne fait qu`une seule intersection
647 // il faut utiliser Plg ou Pld
649 Standard_Integer indedgf = theMapEF.FindIndex(edg1);
650 for (itl.Initialize(theMapEF(indedgf)); itl.More(); itl.Next()) {
651 if (Contains(myMap(F),itl.Value())) {
652 if (Contains(theLeft,itl.Value())) {
654 IsLeft = Standard_True;
658 IsLeft = Standard_False;
668 cout << "LocOpe_SplitDrafts: betite probleme "<< endl;
677 for (Standard_Integer it = 1; it<=nbfois; it++) {
683 intcs.Perform(HAC,HAS);
684 if (!intcs.IsDone()) {
685 return; // voir ce qu`on peut faire de mieux
687 Standard_Integer imin = 1;
688 Standard_Real delta = Abs(knownp - intcs.Point(1).W());
689 for (Standard_Integer i = 2; i<= intcs.NbPoints(); i++) {
690 Standard_Real newdelta = Abs(knownp - intcs.Point(i).W());
691 if (newdelta < delta) {
697 B.MakeVertex(vtx1,intcs.Point(imin).Pnt(),Precision::Confusion());
698 p1 = intcs.Point(imin).W();
702 B.MakeVertex(vtx2,intcs.Point(imin).Pnt(),Precision::Confusion());
703 p2 = intcs.Point(imin).W();
706 if (Abs(p1-p2) > Precision::PConfusion()) {
708 B.MakeEdge(NewEdge,Newc,Precision::Confusion());
710 B.Add(NewEdge,vtx1.Oriented(TopAbs_FORWARD));
711 B.Add(NewEdge,vtx2.Oriented(TopAbs_REVERSED));
714 B.Add(NewEdge,vtx1.Oriented(TopAbs_REVERSED));
715 B.Add(NewEdge,vtx2.Oriented(TopAbs_FORWARD));
717 B.UpdateVertex(vtx1,p1,NewEdge,Precision::Confusion());
718 B.UpdateVertex(vtx2,p2,NewEdge,Precision::Confusion());
719 if (!newCs1.IsNull()) {
720 B.UpdateEdge(NewEdge,newCs1,
721 TopoDS::Face(MapEV.FindFromKey(edg1)),
722 Precision::Confusion());
725 if (!newCs2.IsNull()) {
726 B.UpdateEdge(NewEdge,newCs2,
727 TopoDS::Face(MapEV.FindFromKey(edg2)),
728 Precision::Confusion());
732 MapEV.Add(vtx,NewEdge);
735 TopoDS_Shape aLocalEdge = Ebind.EmptyCopied();
736 TopoDS_Edge NE = TopoDS::Edge(aLocalEdge);
737 // TopoDS_Edge NE = TopoDS::Edge(Ebind.EmptyCopied());
738 for (exp2.Init(Ebind,TopAbs_VERTEX); exp2.More(); exp2.Next()) {
739 const TopoDS_Vertex& thevtx = TopoDS::Vertex(exp2.Current());
740 if (thevtx.IsSame(vtx)) {
741 B.Add(NE,vtx1.Oriented(thevtx.Orientation()));
742 B.UpdateVertex(vtx1,p1,NE,Precision::Confusion());
746 Standard_Real theprm = BRep_Tool::Parameter(thevtx,Ebind);
747 B.UpdateVertex(thevtx,theprm,NE,BRep_Tool::Tolerance(thevtx));
750 MapSonS.Bind(Ebind,NE.Oriented(TopAbs_FORWARD));
752 TopTools_ListOfShape thelist5;
753 MapSg.Bind(vtx, thelist5);
754 MapSg(vtx).Append(vtx1);
757 TopTools_ListOfShape thelist6;
758 MapSd.Bind(vtx, thelist6);
759 MapSd(vtx).Append(vtx1);
763 TopTools_ListOfShape thelist7, thelist8;
764 MapSg.Bind(vtx, thelist7);
765 MapSd.Bind(vtx, thelist8);
766 MapSg(vtx).Append(vtx1);
767 MapSd(vtx).Append(vtx2);
771 MapEV.Add(vtx,vtx2); // on peut avoir vtx2 = vtx si choix == 1
774 TopTools_ListOfShape thelist9;
775 MapSg.Bind(vtx, thelist9);
776 MapSg(vtx).Append(vtx);
779 TopTools_ListOfShape thelist10;
780 MapSd.Bind(vtx, thelist10);
781 MapSd(vtx).Append(vtx);
785 TopTools_ListOfShape thelist11, thelist12;
786 MapSg.Bind(vtx, thelist11);
787 MapSd.Bind(vtx, thelist12);
788 MapSg(vtx).Append(vtx2);
789 MapSd(vtx).Append(vtx2);
797 for (exp.Init(theW,TopAbs_EDGE); exp.More(); exp.Next()) {
798 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
799 if (!theMap.Add(edg)) { // precaution sans doute inutile...
802 Standard_Integer indedg = MapEV.FindIndex(edg);
803 TopoDS_Face& GenF = TopoDS::Face(MapEV(indedg));
804 TopTools_ListOfShape thelist13, thelist14;
805 MapSg.Bind(edg, thelist13); // genere a gauche
806 MapSd.Bind(edg, thelist14); // genere a droite
808 TopoDS_Shape aLocalEdge = edg.Oriented(TopAbs_FORWARD);
809 TopExp::Vertices(TopoDS::Edge(aLocalEdge),Vf,Vl);
810 // TopExp::Vertices(TopoDS::Edge(edg.Oriented(TopAbs_FORWARD)),Vf,Vl);
811 TopoDS_Shape Gvf = MapEV.FindFromKey(Vf);
812 TopoDS_Shape Gvl = MapEV.FindFromKey(Vl);
814 /* Le code suivant est OK. On essaie de l`ameliorer
816 if (Gvf.ShapeType() == TopAbs_VERTEX &&
817 Gvl.ShapeType() == TopAbs_VERTEX) {
818 // en fait on doit pouvoir avoir 1 face a 2 cotes...
819 if (Gvf.IsSame(Vf)) {
821 MapSg(edg).Append(edg.Oriented(TopAbs_FORWARD));
822 MapSd(edg).Append(edg.Oriented(TopAbs_FORWARD));
825 TopoDS_Edge NewEdg = NewEdge(edg,
828 TopoDS::Vertex(Gvl));
829 if (NewEdg.IsNull()) {
833 MapSg(edg).Append(NewEdg);
834 MapSd(edg).Append(NewEdg);
837 else if (Gvf.ShapeType() == TopAbs_VERTEX ||
838 Gvl.ShapeType() == TopAbs_VERTEX) { // face triangulaire
839 TopoDS_Vertex Vfd,Vld,Vfg,Vlg;
840 if (Gvf.ShapeType() == TopAbs_VERTEX) {
841 Vfg = TopoDS::Vertex(Gvf);
843 Vlg = TopoDS::Vertex(MapSg(Vl).First());
844 Vld = TopoDS::Vertex(MapSd(Vl).First());
847 Vlg = TopoDS::Vertex(Gvl);
849 Vfg = TopoDS::Vertex(MapSg(Vf).First());
850 Vfd = TopoDS::Vertex(MapSd(Vf).First());
853 TopoDS_Edge NewEdgg = NewEdge(edg,GenF,NewSg,Vfg,Vlg);
854 if (NewEdgg.IsNull()) {
858 TopoDS_Edge NewEdgd = NewEdge(edg,GenF,NewSd,Vfd,Vld);
859 if (NewEdgg.IsNull()) {
862 MapSg(edg).Append(NewEdgg);
863 MapSd(edg).Append(NewEdgd);
865 TopTools_ListOfShape theedges;
866 theedges.Append(NewEdgg);
867 theedges.Append(NewEdgd);
868 if (Gvf.ShapeType() == TopAbs_EDGE) {
869 theedges.Append(Gvf);
871 else {//if (Gvl.ShapeType() == TopAbs_EDGE) {
872 theedges.Append(Gvl);
874 MakeFace(GenF,theedges);
878 // une face a 4 cotes
879 TopoDS_Vertex Vfd,Vld,Vfg,Vlg;
881 Vfg = TopoDS::Vertex(MapSg(Vf).First());
882 Vfd = TopoDS::Vertex(MapSd(Vf).First());
883 Vlg = TopoDS::Vertex(MapSg(Vl).First());
884 Vld = TopoDS::Vertex(MapSd(Vl).First());
886 TopoDS_Vertex VVf1,VVl1,VVf2,VVl2;
887 TopExp::Vertices(TopoDS::Edge(Gvf.Oriented(TopAbs_FORWARD)),VVf1,VVl1);
888 TopExp::Vertices(TopoDS::Edge(Gvl.Oriented(TopAbs_FORWARD)),VVf2,VVl2);
890 TopoDS_Edge NewEdgg = NewEdge(edg,GenF,NewSg,Vfg,Vlg);
891 if (NewEdgg.IsNull()) {
895 TopoDS_Edge NewEdgd = NewEdge(edg,GenF,NewSd,Vfd,Vld);
896 if (NewEdgd.IsNull()) {
900 if ((VVf1.IsSame(Vfg) && VVf2.IsSame(Vlg)) ||
901 (VVf1.IsSame(Vfd) && VVf2.IsSame(Vld))) {
903 MapSg(edg).Append(NewEdgg);
904 MapSd(edg).Append(NewEdgd);
906 TopTools_ListOfShape theedges;
907 theedges.Append(NewEdgg);
908 theedges.Append(NewEdgd);
909 theedges.Append(Gvf);
910 theedges.Append(Gvl);
912 MakeFace(GenF,theedges);
917 cout << "Pb d'analyse" << endl;
925 TopoDS_Vertex Vfd,Vld,Vfg,Vlg;
926 if (Gvf.ShapeType() == TopAbs_VERTEX) {
927 Vfg = TopoDS::Vertex(Gvf);
931 Vfg = TopoDS::Vertex(MapSg(Vf).First());
932 Vfd = TopoDS::Vertex(MapSd(Vf).First());
934 if (Gvl.ShapeType() == TopAbs_VERTEX) {
935 Vlg = TopoDS::Vertex(Gvl);
939 Vlg = TopoDS::Vertex(MapSg(Vl).First());
940 Vld = TopoDS::Vertex(MapSd(Vl).First());
943 TopoDS_Edge NewEdgg = NewEdge(edg,GenF,NewSg,Vfg,Vlg);
944 if (NewEdgg.IsNull()) {
948 TopoDS_Edge NewEdgd = NewEdge(edg,GenF,NewSd,Vfd,Vld);
949 if (NewEdgg.IsNull()) {
953 Standard_Boolean isedg = Standard_False;
954 if (Gvf.ShapeType() == TopAbs_VERTEX &&
955 Gvl.ShapeType() == TopAbs_VERTEX) {
956 // edg ou face a 2 cotes
958 // Comparaison NewEdgg et NewEdgd
959 Standard_Real fg,lg,fd,ld;
960 Handle(Geom_Curve) Cg = BRep_Tool::Curve(NewEdgg,fg,lg);
961 Handle(Geom_Curve) Cd = BRep_Tool::Curve(NewEdgd,fd,ld);
962 Standard_Real prmg = (fg+lg)/2.;
963 Standard_Real prmd = (fd+ld)/2.;
964 gp_Pnt pg = Cg->Value(prmg);
965 gp_Pnt pd = Cd->Value(prmd);
966 Standard_Real Tol = Max(BRep_Tool::Tolerance(NewEdgg),
967 BRep_Tool::Tolerance(NewEdgg));
968 if (pg.SquareDistance(pd) <= Tol*Tol) {
969 isedg = Standard_True;
970 // raffinement pour essayer de partager l`edge de depart...
971 Standard_Boolean modified = Standard_True;
972 if (Gvf.IsSame(Vf) && Gvl.IsSame(Vl)) {
973 // Comparaison avec l`edge de depart
974 Cd = BRep_Tool::Curve(edg,fd,ld);
976 pd = Cd->Value(prmd);
977 Tol = Max(BRep_Tool::Tolerance(NewEdgg),
978 BRep_Tool::Tolerance(edg));
979 if (pg.SquareDistance(pd) <= Tol*Tol) {
980 modified = Standard_False;
986 MapSg(edg).Append(edg);
987 MapSd(edg).Append(edg);
991 MapSg(edg).Append(NewEdgg);
992 MapSd(edg).Append(NewEdgg);
998 // face a 2 ou 3 ou 4 cotes
999 MapSg(edg).Append(NewEdgg);
1000 MapSd(edg).Append(NewEdgd);
1002 TopTools_ListOfShape theedges;
1003 theedges.Append(NewEdgg);
1004 theedges.Append(NewEdgd);
1005 if (Gvf.ShapeType() == TopAbs_EDGE) {
1006 theedges.Append(Gvf);
1008 if (Gvl.ShapeType() == TopAbs_EDGE) {
1009 theedges.Append(Gvl);
1011 MakeFace(GenF,theedges);
1018 TopTools_MapOfShape mapedgadded;
1019 TopTools_ListOfShape thefaces;
1021 for (itl.Initialize(myMap(F)); itl.More(); itl.Next()) {
1022 const TopoDS_Face& fac = TopoDS::Face(itl.Value());
1024 TopoDS_Face DrftFace; // elle est FORWARD
1025 Standard_Boolean IsLeft;
1026 if (Contains(theLeft,fac)) {
1027 B.MakeFace(DrftFace,NewSg,BRep_Tool::Tolerance(fac));
1028 IsLeft = Standard_True;
1031 B.MakeFace(DrftFace,NewSd,BRep_Tool::Tolerance(fac));
1032 IsLeft = Standard_False;
1035 TopExp_Explorer exp3;
1036 for (exp3.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
1037 exp3.More(); exp3.Next()) {
1038 const TopoDS_Shape& wir = exp3.Current();
1039 TopoDS_Wire NewWireOnF;
1040 B.MakeWire(NewWireOnF);
1041 for (exp.Init(wir.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1042 exp.More(); exp.Next()) {
1043 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
1044 if (!theMap.Add(edg)) { // precaution sans doute inutile...
1047 if (MapW.IsBound(edg)) { // edge du wire d`origine
1048 TopTools_ListIteratorOfListOfShape itld;
1049 TopAbs_Orientation ored = edg.Orientation();
1051 itld.Initialize(MapSg(edg));
1054 itld.Initialize(MapSd(edg));
1056 for (; itld.More(); itld.Next()) {
1057 if (itld.Value().Orientation() == TopAbs_REVERSED) {
1058 ored = TopAbs::Reverse(ored);
1060 TopoDS_Shape aLocalEdge = itld.Value().Oriented(ored);
1061 B.Add(NewWireOnF,TopoDS::Edge(aLocalEdge));
1062 // B.Add(NewWireOnF,TopoDS::Edge(itld.Value().Oriented(ored)));
1066 Handle(Geom_Surface) NewS;
1073 Standard_Integer indedg = MapEV.FindIndex(edg);
1074 const TopoDS_Face& GenF = TopoDS::Face(MapEV(indedg));
1075 TopoDS_Vertex Vf,Vl;
1076 TopoDS_Shape aLocalEdge = edg.Oriented(TopAbs_FORWARD);
1077 TopExp::Vertices(TopoDS::Edge(aLocalEdge),Vf,Vl);
1078 // TopExp::Vertices(TopoDS::Edge(edg.Oriented(TopAbs_FORWARD)),Vf,Vl);
1079 TopoDS_Shape Gvf = MapEV.FindFromKey(Vf);
1080 TopoDS_Shape Gvl = MapEV.FindFromKey(Vl);
1081 if (Gvf.ShapeType() == TopAbs_VERTEX &&
1082 Gvl.ShapeType() == TopAbs_VERTEX) {
1083 if (!Gvf.IsSame(Vf) || !Gvl.IsSame(Vl)) {
1084 TopoDS_Edge NewEdg = NewEdge(edg,GenF,NewS,
1085 TopoDS::Vertex(Gvf),
1086 TopoDS::Vertex(Gvl));
1087 if (NewEdg.IsNull()) {
1091 MapSonS.Bind(edg,NewEdg);
1093 if (NewEdg.Orientation() == TopAbs_REVERSED) {
1094 NewEdg.Orientation(TopAbs::Reverse(edg.Orientation()));
1097 NewEdg.Orientation(edg.Orientation());
1099 B.Add(NewWireOnF,NewEdg);
1102 B.Add(NewWireOnF,edg);
1106 TopoDS_Vertex Vff,Vll;
1107 if (Gvf.ShapeType() == TopAbs_VERTEX) {
1108 Vff = TopoDS::Vertex(Gvf);
1112 Vff = TopoDS::Vertex(MapSg(Vf).First());
1115 Vff = TopoDS::Vertex(MapSd(Vf).First());
1118 if (Gvl.ShapeType() == TopAbs_VERTEX) {
1119 Vll = TopoDS::Vertex(Gvl);
1123 Vll = TopoDS::Vertex(MapSg(Vl).First());
1126 Vll = TopoDS::Vertex(MapSd(Vl).First());
1130 TopoDS_Edge NewEdg = NewEdge(edg,GenF,NewS,Vff,Vll);
1131 if (NewEdg.IsNull()) {
1135 if (!MapW.IsBound(Vf) && !MapW.IsBound(Vl)) {
1136 MapSonS.Bind(edg,NewEdg);
1138 // else if (MapW.IsBound(Vf) && MapW.IsBound(Vl)) {
1143 if (MapW.IsBound(Vf)) {
1144 if (Gvf.ShapeType() != TopAbs_EDGE ||
1145 mapedgadded.Contains(Gvf)) {
1146 MapSonS.Bind(edg,NewEdg);
1151 B.Add(NewWir,NewEdg);
1153 TopoDS_Vertex Vf2,Vl2;
1154 TopExp::Vertices(TopoDS::Edge(Gvf),Vf2,Vl2);
1156 //TopAbs_Orientation ornw = NewEdg.Orientation();
1158 // ici bug orientation : voir tspdrft6
1160 // if ((ornw == TopAbs_FORWARD && Vl2.IsSame(Vff)) ||
1161 // (ornw == TopAbs_REVERSED && Vl2.IsSame(Vll))) {
1162 if (Vl2.IsSame(Vff)) {
1163 B.Add(NewWir,Gvf.Oriented(TopAbs_FORWARD));
1166 B.Add(NewWir,Gvf.Oriented(TopAbs_REVERSED));
1168 mapedgadded.Add(Gvf);
1169 MapSonS.Bind(edg,NewWir); // NewWire est FORWARD
1173 if (Gvl.ShapeType() != TopAbs_EDGE ||
1174 mapedgadded.Contains(Gvl)) {
1175 MapSonS.Bind(edg,NewEdg);
1180 B.Add(NewWir,NewEdg);
1182 TopoDS_Vertex Vf2,Vl2;
1183 TopExp::Vertices(TopoDS::Edge(Gvl),Vf2,Vl2);
1185 //TopAbs_Orientation ornw = NewEdg.Orientation();
1187 // ici bug orientation : voir tspdrft6
1189 // if ((ornw == TopAbs_FORWARD && Vl2.IsSame(Vff)) ||
1190 // (ornw == TopAbs_REVERSED && Vl2.IsSame(Vll))) {
1191 if (Vf2.IsSame(Vll)) {
1192 B.Add(NewWir,Gvl.Oriented(TopAbs_FORWARD));
1195 B.Add(NewWir,Gvl.Oriented(TopAbs_REVERSED));
1197 mapedgadded.Add(Gvl);
1198 MapSonS.Bind(edg,NewWir); // NewWire est FORWARD
1202 if (NewEdg.Orientation() == TopAbs_REVERSED) {
1203 NewEdg.Orientation(TopAbs::Reverse(edg.Orientation()));
1206 NewEdg.Orientation(edg.Orientation());
1208 B.Add(NewWireOnF,NewEdg);
1212 B.Add(DrftFace,NewWireOnF.Oriented(wir.Orientation()));
1214 thefaces.Append(DrftFace);
1217 BRepTools_Substitution theSubs;
1218 TopTools_DataMapIteratorOfDataMapOfShapeShape itdmss;
1219 for (itdmss.Initialize(MapSonS);
1220 itdmss.More(); itdmss.Next()) {
1221 TopTools_ListOfShape lsubs;
1222 for (exp.Init(itdmss.Value(),TopAbs_EDGE); exp.More(); exp.Next()) {
1223 lsubs.Append(exp.Current());
1225 theSubs.Substitute(itdmss.Key(),lsubs);
1228 // on reconstruit les faces
1229 for (exp.Init(Res,TopAbs_FACE); exp.More(); exp.Next()) {
1230 if (Contains(myMap(F),exp.Current())) {
1233 theSubs.Build(exp.Current());
1236 // Stockage des descendants
1237 // for (TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdmsls(myMap);
1238 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itdmsls(myMap) ;
1239 for ( ; itdmsls.More(); itdmsls.Next()) {
1240 if (itdmsls.Key().ShapeType() == TopAbs_EDGE) {
1241 TopTools_ListOfShape thedesc;
1243 for (itl.Initialize(itdmsls.Value());itl.More(); itl.Next()) {
1244 if (theMap.Add(MapW(itl.Value()))) {
1245 thedesc.Append(MapW(itl.Value()));
1248 myMap(itdmsls.Key()) = thedesc;
1250 else if (itdmsls.Key().IsSame(F)) {
1252 for (itl.Initialize(thefaces); itl.More(); itl.Next()) {
1253 myMap(F).Append(itl.Value());
1257 TopTools_ListOfShape thedesc;
1259 for (itl.Initialize(itdmsls.Value());itl.More(); itl.Next()) {
1260 if (theSubs.IsCopied(itl.Value())) {
1261 if (theSubs.Copy(itl.Value()).Extent() != 1) {
1263 cout << "Invalid number of descendant" << endl;
1268 if (theMap.Add(theSubs.Copy(itl.Value()).First())) {
1269 thedesc.Append(theSubs.Copy(itl.Value()).First());
1273 else if (theMap.Add(itl.Value())) {
1274 thedesc.Append(itl.Value());
1277 myMap(itdmsls.Key()) = thedesc;
1283 for (itdmsls.Initialize(myMap);itdmsls.More(); itdmsls.Next()) {
1284 for (itl.Initialize(itdmsls.Value());itl.More(); itl.Next()) {
1285 if (itl.Value().ShapeType() == TopAbs_FACE &&
1286 theMap.Add(itl.Value())) {
1287 thefaces.Append(itl.Value());
1291 LocOpe_BuildShape BS(thefaces);
1292 myResult = BS.Shape();
1296 //=======================================================================
1299 //=======================================================================
1301 const TopoDS_Shape& LocOpe_SplitDrafts::Shape () const
1303 if (myResult.IsNull()) {
1304 StdFail_NotDone::Raise();
1309 //=======================================================================
1310 //function : ShapesFromShape
1312 //=======================================================================
1314 const TopTools_ListOfShape& LocOpe_SplitDrafts::ShapesFromShape
1315 (const TopoDS_Shape& S) const
1317 if (myResult.IsNull()) {
1318 StdFail_NotDone::Raise();
1324 //=======================================================================
1325 //function : NewPlane
1327 //=======================================================================
1329 static Standard_Boolean NewPlane(const TopoDS_Face& F,
1331 const gp_Pln& Neutr,
1332 const Standard_Real Ang,
1335 const Standard_Boolean Modify)
1339 // Determination du nouveau plan incline
1340 Handle(Geom_Surface) S = BRep_Tool::Surface(F);
1341 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
1342 S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
1344 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
1346 return Standard_False;
1349 gp_Pln Plorig = P->Pln();
1352 NormalF = Newpl.Axis();
1353 if ((Newpl.Direct() && F.Orientation() == TopAbs_REVERSED) ||
1354 (!Newpl.Direct() && F.Orientation() == TopAbs_FORWARD)) {
1357 return Standard_True;
1361 Standard_Real Theta;
1363 IntAna_QuadQuadGeo i2pl(Plorig,Neutr,
1364 Precision::Angular(),Precision::Confusion());
1366 if (i2pl.IsDone() && i2pl.TypeInter() == IntAna_Line) {
1367 gp_Lin LinInters = i2pl.Line(1);
1368 gp_Dir nx = LinInters.Direction();
1369 NormalF = Plorig.Axis();
1370 gp_Dir ny = NormalF.Direction().Crossed(nx);
1371 Standard_Real a = Extr.Dot(nx);
1372 if (Abs(a) <=1-Precision::Angular()) {
1373 Standard_Real b = Extr.Dot(ny);
1374 Standard_Real c = Extr.Dot(NormalF.Direction());
1375 Standard_Boolean direct(Plorig.Direct());
1376 TopAbs_Orientation Oris = F.Orientation();
1377 if ((direct && Oris == TopAbs_REVERSED) ||
1378 (!direct && Oris == TopAbs_FORWARD)) {
1383 Standard_Real denom = Sqrt(1-a*a);
1384 Standard_Real Sina = Sin(Ang);
1385 if (denom>Abs(Sina)) {
1386 Standard_Real phi = ATan2(b/denom,c/denom);
1387 Standard_Real theta0 = ACos(Sina/denom);
1388 Theta = theta0 - phi;
1389 if (Cos(Theta) <0.) {
1390 Theta = -theta0 -phi;
1392 Axe = LinInters.Position();
1393 Newpl = Plorig.Rotated(Axe,Theta);
1394 return Standard_True;
1398 cout << "fin newplane return standard_false" << endl;
1399 return Standard_False;
1403 //=======================================================================
1404 //function : MakeFace
1406 //=======================================================================
1408 static void MakeFace(TopoDS_Face& F,
1409 TopTools_ListOfShape& ledg)
1412 // ledg est une liste d'edge
1416 // Verification de l`existence des p-curves. Celles qui manquent
1417 // correspondent necessairement a des isos (et meme des iso u).
1420 // for (TopTools_ListIteratorOfListOfShape itl(ledg);
1421 TopTools_ListIteratorOfListOfShape itl(ledg) ;
1422 for ( ; itl.More(); itl.Next()) {
1423 TopoDS_Edge& edg = TopoDS::Edge(itl.Value());
1424 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edg,F,f,l);
1426 BRep_Tool::Range(edg,f,l);
1427 TopoDS_Vertex V1,V2;
1428 TopExp::Vertices(edg,V1,V2);
1429 TopTools_ListIteratorOfListOfShape itl2;
1430 for (itl2.Initialize(ledg);
1431 itl2.More(); itl2.Next()) {
1432 const TopoDS_Edge& edg2 = TopoDS::Edge(itl2.Value());
1433 if (edg2.IsSame(edg)) {
1436 TopoDS_Vertex Vp1,Vp2;
1437 TopExp::Vertices(edg2,Vp1,Vp2);
1438 if (Vp1.IsSame(V1) || Vp2.IsSame(V1) ||
1439 Vp1.IsSame(V2) || Vp2.IsSame(V2)) {
1440 Standard_Real f2,l2;
1441 Handle(Geom2d_Curve) C22d = BRep_Tool::CurveOnSurface(edg2,F,f2,l2);
1442 if (!C22d.IsNull()) {
1444 if (Vp1.IsSame(V1)) {
1445 pt2d = C22d->Value(f2);
1446 pt2d.SetY(pt2d.Y()-f);
1448 else if (Vp2.IsSame(V1)) {
1449 pt2d = C22d->Value(l2);
1450 pt2d.SetY(pt2d.Y()-f);
1452 else if (Vp1.IsSame(V2)) {
1453 pt2d = C22d->Value(f2);
1454 pt2d.SetY(pt2d.Y()-l);
1456 else if (Vp2.IsSame(V2)) {
1457 pt2d = C22d->Value(l2);
1458 pt2d.SetY(pt2d.Y()-l);
1460 C2d = new Geom2d_Line(pt2d,gp::DY2d());
1461 B.UpdateEdge(edg,C2d,F,BRep_Tool::Tolerance(edg));
1467 cout << "Ca merde violemment" << endl;
1472 TopTools_ListOfShape lwires;
1473 Standard_Boolean alldone = ledg.IsEmpty();
1477 TopoDS_Shape aLocalShape = ledg.First();
1478 const TopoDS_Edge& edg = TopoDS::Edge(aLocalShape);
1479 // const TopoDS_Edge& edg = TopoDS::Edge(ledg.First());
1480 TopoDS_Vertex VFirst,VLast;
1481 if (edg.Orientation() == TopAbs_FORWARD) {
1482 TopExp::Vertices(edg,VFirst,VLast);
1485 TopExp::Vertices(edg,VLast,VFirst);
1489 // on suppose VFirst et VLast non nuls
1490 Standard_Boolean wdone = (ledg.IsEmpty() || VFirst.IsSame(VLast));
1492 TopoDS_Vertex VF,VL;
1494 TopAbs_Orientation oredg = TopAbs_FORWARD;
1496 for (itl.Initialize(ledg); itl.More(); itl.Next()) {
1497 const TopoDS_Edge& edg2 = TopoDS::Edge(itl.Value());
1498 TopoDS_Shape aLocalShape = edg2.Oriented(TopAbs_FORWARD);
1499 TopExp::Vertices(TopoDS::Edge(aLocalShape),VF,VL);
1500 // TopExp::Vertices(TopoDS::Edge(edg2.Oriented(TopAbs_FORWARD)),VF,VL);
1501 if (VF.IsSame(VLast)) {
1503 oredg = TopAbs_FORWARD;
1506 else if (VL.IsSame(VFirst)) {
1508 oredg = TopAbs_FORWARD;
1511 else if (VF.IsSame(VFirst)) {
1513 oredg = TopAbs_REVERSED;
1516 else if (VL.IsSame(VLast)) {
1518 oredg = TopAbs_REVERSED;
1524 wdone = Standard_True;
1527 TopoDS_Shape aLocalShape = itl.Value().Oriented(oredg);
1528 B.Add(Wnew,TopoDS::Edge(aLocalShape));
1529 // B.Add(Wnew,TopoDS::Edge(itl.Value().Oriented(oredg)));
1531 wdone = (ledg.IsEmpty() || VFirst.IsSame(VLast));
1534 lwires.Append(Wnew);
1535 alldone = ledg.IsEmpty();
1541 F.Orientation(TopAbs_FORWARD);
1542 for (itl.Initialize(lwires); itl.More(); itl.Next()) {
1543 TopoDS_Shape aLocalShape = F.EmptyCopied();
1544 TopoDS_Face NewFace = TopoDS::Face(aLocalShape);
1545 // TopoDS_Face NewFace = TopoDS::Face(F.EmptyCopied());
1546 B.Add(NewFace,itl.Value());
1548 BRepGProp::SurfaceProperties(NewFace,GP);
1549 if (GP.Mass() < 0) {
1550 itl.Value().Reverse();
1553 if (lwires.Extent() == 1) {
1554 B.Add(F,lwires.First());
1557 cout << "Not yet implemented : nbwire >= 2" << endl;
1563 //=======================================================================
1564 //function : Contains
1566 //=======================================================================
1568 static Standard_Boolean Contains(const TopTools_ListOfShape& ll,
1569 const TopoDS_Shape& s)
1571 TopTools_ListIteratorOfListOfShape itl;
1572 for (itl.Initialize(ll); itl.More(); itl.Next()) {
1573 if (itl.Value().IsSame(s)) {
1574 return Standard_True;
1577 return Standard_False;
1582 //=======================================================================
1583 //function : Contains
1585 //=======================================================================
1587 static TopoDS_Edge NewEdge(const TopoDS_Edge& edg,
1588 const TopoDS_Face& F,
1589 const Handle(Geom_Surface)& NewS,
1590 const TopoDS_Vertex& V1,
1591 const TopoDS_Vertex& V2)
1594 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F);
1595 Standard_Boolean AppS1 = Standard_False;
1596 if (S1->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
1597 AppS1 = Standard_True;
1601 GeomInt_IntSS i2s(S1,NewS,Precision::Confusion(),Standard_True,AppS1);
1602 if (!i2s.IsDone() || i2s.NbLines() <= 0) {
1607 // Standard_Real pmin, Dist, DistMin;
1608 Standard_Real Dist2, Dist2Min;
1609 Standard_Real prmf=0,prml=0;
1610 GeomAdaptor_Curve TheCurve;
1612 Standard_Integer i,imin,k;
1613 gp_Pnt pvf = BRep_Tool::Pnt(V1);
1614 gp_Pnt pvl = BRep_Tool::Pnt(V2);
1616 for (i=1; i<= i2s.NbLines(); i++) {
1617 TheCurve.Load(i2s.Line(i));
1618 Extrema_ExtPC myExtPC(pvf,TheCurve);
1620 if (myExtPC.IsDone()) {
1622 Standard_Real thepmin = TheCurve.FirstParameter();
1623 myExtPC.TrimmedSquareDistances(Dist2Min,Dist2,p1b,p2b);
1624 if (Dist2 < Dist2Min && !TheCurve.IsPeriodic()) {
1626 thepmin = TheCurve.LastParameter();
1628 for (k=1; k<=myExtPC.NbExt(); k++) {
1629 Dist2 = myExtPC.SquareDistance(k);
1630 if (Dist2 < Dist2Min) {
1632 thepmin = myExtPC.Point(k).Parameter();
1636 if (Dist2Min <= Precision::SquareConfusion()) {
1638 myExtPC.Perform(pvl);
1639 if (myExtPC.IsDone()) {
1640 thepmin = TheCurve.LastParameter();
1641 myExtPC.TrimmedSquareDistances(Dist2,Dist2Min,p1b,p2b);
1642 if (Dist2 < Dist2Min && !TheCurve.IsClosed()) {
1644 thepmin = TheCurve.FirstParameter();
1646 for (k=1; k<=myExtPC.NbExt(); k++) {
1647 Dist2 = myExtPC.SquareDistance(k);
1648 if (Dist2 < Dist2Min) {
1650 thepmin = myExtPC.Point(k).Parameter();
1654 if (Dist2Min <= Precision::SquareConfusion()) {
1663 if (i <= i2s.NbLines()) {
1664 Standard_Boolean rev = Standard_False;
1665 TopoDS_Vertex Vf = V1;
1666 TopoDS_Vertex Vl = V2;
1667 Handle(Geom_Curve) Cimg = i2s.Line(i);
1668 Handle(Geom2d_Curve) Cimg2d;
1670 Cimg2d = i2s.LineOnS1(i);
1673 if (Cimg->IsPeriodic()) {
1675 Standard_Real period = Cimg->Period();
1676 Standard_Real imf = Cimg->FirstParameter();
1677 Standard_Real iml = Cimg->LastParameter();
1680 BRep_Tool::Range(edg,f,l);
1681 Standard_Real delt = l-f;
1682 Standard_Real delt1 = Abs(prml-prmf);
1683 Standard_Real delt2 = Abs(period-delt1);
1685 if (delt1 == 0 || delt2 == 0) {
1692 if (Abs(delt1-delt) > Abs(delt2-delt)) {
1693 // le bon ecart est delt2...
1711 else if (Abs(delt1-delt) < Abs(delt2-delt)) {
1712 if (prmf >= iml && prml >= iml) {
1716 else if (prmf <= imf && prml <= imf) {
1721 else { // egalite; on priveligie l'ordre f,l
1725 if (prmf >= iml && prml >= iml) {
1729 else if (prmf <= imf && prml <= imf) {
1736 Standard_Real ptol = Precision::PConfusion();
1737 if (prmf < imf - ptol || prmf > iml + ptol ||
1738 prml < imf - ptol || prml > iml + ptol) {
1739 cout << "Ca ne va pas aller" << endl;
1746 if (S1->IsUPeriodic()) {
1748 Standard_Real speriod = S1->UPeriod();
1749 // Standard_Real f,l;
1751 pf = Cimg2d->Value(prmf);
1752 pl = Cimg2d->Value(prml);
1754 Standard_Real Uf = pf.X();
1755 Standard_Real Ul = pl.X();
1756 Standard_Real ptra = 0.0;
1758 Standard_Real Ustart = Min(Uf,Ul);
1759 while (Ustart < -Precision::PConfusion()) {
1763 while (Ustart > speriod - Precision::PConfusion()) {
1768 Cimg2d->Translate(gp_Vec2d(ptra,0.));
1774 Vf.Orientation(TopAbs_FORWARD);
1775 Vl.Orientation(TopAbs_REVERSED);
1778 Vf.Orientation(TopAbs_REVERSED);
1779 Vl.Orientation(TopAbs_FORWARD);
1780 rev = Standard_True;;
1783 B.MakeEdge(NewEdg,Cimg,Precision::Confusion());
1787 B.UpdateVertex(Vf,prmf,NewEdg,Precision::Confusion());
1788 B.UpdateVertex(Vl,prml,NewEdg,Precision::Confusion());
1790 B.UpdateEdge(NewEdg,Cimg2d,F,Precision::Confusion());
1795 NewEdg.Orientation(TopAbs_REVERSED);