1 // Created on: 1997-04-14
2 // Created by: Olga KOULECHOVA
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
18 #include <BRep_Tool.hxx>
19 #include <BRepAlgoAPI_Common.hxx>
20 #include <BRepAlgoAPI_Section.hxx>
21 #include <BRepBuilderAPI.hxx>
22 #include <BRepBuilderAPI_MakeFace.hxx>
23 #include <BRepBuilderAPI_Transform.hxx>
24 #include <BRepExtrema_ExtCF.hxx>
25 #include <BRepExtrema_ExtPC.hxx>
26 #include <BRepExtrema_ExtPF.hxx>
27 #include <BRepFeat.hxx>
28 #include <BRepFeat_MakeLinearForm.hxx>
29 #include <BRepLib_MakeEdge.hxx>
30 #include <BRepLib_MakeFace.hxx>
31 #include <BRepLib_MakeVertex.hxx>
32 #include <BRepLib_MakeWire.hxx>
33 #include <BRepPrimAPI_MakeBox.hxx>
34 #include <BRepTools.hxx>
35 #include <BRepTools_Modifier.hxx>
36 #include <BRepTools_TrsfModification.hxx>
37 #include <BRepTools_WireExplorer.hxx>
38 #include <Geom_Curve.hxx>
39 #include <Geom_CylindricalSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_RectangularTrimmedSurface.hxx>
42 #include <Geom_Surface.hxx>
43 #include <Geom_TrimmedCurve.hxx>
47 #include <IntRes2d_IntersectionPoint.hxx>
48 #include <LocOpe_Gluer.hxx>
49 #include <LocOpe_LinearForm.hxx>
50 #include <Precision.hxx>
51 #include <Standard_ConstructionError.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Wire.hxx>
59 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
63 extern Standard_Boolean BRepFeat_GettraceFEAT();
64 extern Standard_Boolean BRepFeat_GettraceFEATRIB();
67 static void MajMap(const TopoDS_Shape&, // base
68 const LocOpe_LinearForm&,
69 TopTools_DataMapOfShapeListOfShape&, // myMap
70 TopoDS_Shape&, // myFShape
71 TopoDS_Shape&); // myLShape
73 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
75 TopTools_DataMapOfShapeShape&);
77 //=================================================================================================
79 void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
81 const Handle(Geom_Plane)& Plane,
84 const Standard_Integer Mode,
85 const Standard_Boolean Modify)
88 Standard_Boolean trc = BRepFeat_GettraceFEAT();
90 std::cout << "BRepFeat_MakeLinearForm::Init" << std::endl;
92 Standard_Boolean RevolRib = Standard_False;
96 // modify = 0 if there is no intention to make sliding
97 // = 1 if one tries to make sliding
98 Standard_Boolean Sliding = Modify;
111 myListOfEdges.Clear();
114 TopoDS_Shape aLocalShapeW = W.Oriented(TopAbs_FORWARD);
115 myWire = TopoDS::Wire(aLocalShapeW);
116 // myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
122 myFuse = Standard_False;
123 else // if(Mode == 1)
124 myFuse = Standard_True;
129 std::cout << " Fuse" << std::endl;
131 std::cout << " Cut" << std::endl;
135 // ---Determine Tolerance : max tolerance on parameters
136 myTol = Precision::Confusion();
139 exx.Init(myWire, TopAbs_VERTEX);
140 for (; exx.More(); exx.Next())
142 const Standard_Real& tol = BRep_Tool::Tolerance(TopoDS::Vertex(exx.Current()));
147 exx.Init(Sbase, TopAbs_VERTEX);
148 for (; exx.More(); exx.Next())
150 const Standard_Real& tol = BRep_Tool::Tolerance(TopoDS::Vertex(exx.Current()));
155 // ---Control of directions
156 // the wire should be in the rib
157 gp_Vec nulldir(0, 0, 0);
158 if (!myDir1.IsEqual(nulldir, myTol, myTol))
160 Standard_Real ang = myDir1.Angle(myDir);
165 std::cout << " Directions must be opposite" << std::endl;
167 myStatusError = BRepFeat_BadDirect;
175 // Rib is centre in the middle of translation
178 std::cout << " Rib is centre" << std::endl;
180 const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
182 T.SetTranslation(DirTranslation);
183 BRepBuilderAPI_Transform trf(T);
185 myWire = TopoDS::Wire(trf.Shape());
186 myDir = Direc - DirTranslation;
187 myDir1 = Direc1 - DirTranslation;
191 // ---Calculate bounding box
194 TopTools_ListOfShape theList;
198 gp_Pnt FirstCorner, LastCorner;
199 Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
202 BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
203 TopoDS_Solid BndBox = Bndbox.Solid();
205 // ---Construction of the face workplane (section bounding box)
206 BRepLib_MakeFace PlaneF(myPln->Pln(), -6. * myBnd, 6. * myBnd, -6. * myBnd, 6. * myBnd);
207 TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
209 BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
211 TopoDS_Shape PlaneSect = PlaneS.Shape();
212 EXP.Init(PlaneSect, TopAbs_WIRE);
213 TopoDS_Wire www = TopoDS::Wire(EXP.Current());
214 BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
215 TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
217 // ---Find support faces of the rib
218 TopoDS_Edge FirstEdge, LastEdge;
219 TopoDS_Face FirstFace, LastFace;
220 TopoDS_Vertex FirstVertex, LastVertex;
222 Standard_Boolean OnFirstFace = Standard_False;
223 Standard_Boolean OnLastFace = Standard_False;
224 Standard_Boolean PtOnFirstEdge = Standard_False;
225 Standard_Boolean PtOnLastEdge = Standard_False;
226 TopoDS_Edge OnFirstEdge, OnLastEdge;
227 OnFirstEdge.Nullify();
228 OnLastEdge.Nullify();
230 Standard_Boolean Data = ExtremeFaces(RevolRib,
250 std::cout << " No Extreme faces" << std::endl;
252 myStatusError = BRepFeat_NoExtFace;
257 // ---Proofing Point for the side of the wire to be filled - side material
258 gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd / 10., myPln);
260 // Standard_Real f, l;
262 // ---Control sliding valuable
263 // Many cases when the sliding is abandoned
264 Standard_Integer Concavite = 3; // a priori the profile is not concave
266 myFirstPnt = BRep_Tool::Pnt(FirstVertex);
267 myLastPnt = BRep_Tool::Pnt(LastVertex);
269 // SliList : list of faces concerned by the rib
270 TopTools_ListOfShape SliList;
271 SliList.Append(FirstFace);
277 std::cout << " Sliding" << std::endl;
279 Sliding = Standard_False;
280 Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
281 if (s->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
283 s = Handle(Geom_RectangularTrimmedSurface)::DownCast(s)->BasisSurface();
285 if (s->DynamicType() == STANDARD_TYPE(Geom_Plane)
286 || s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface))
288 // if plane or cylinder : sliding is possible
289 Sliding = Standard_True;
293 // Control only start and end points
294 // -> no control at the middle - improve
295 // Controle between Surface and segment between 2 limit points
296 // is too expensive - improve
299 gp_Pnt p1(myFirstPnt.X() + myDir.X(), myFirstPnt.Y() + myDir.Y(), myFirstPnt.Z() + myDir.Z());
300 BRepLib_MakeEdge ee1(myFirstPnt, p1);
301 BRepExtrema_ExtCF ext1(ee1, FirstFace);
302 if (ext1.NbExt() == 1
303 && ext1.SquareDistance(1)
304 <= BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace))
306 gp_Pnt p2(myLastPnt.X() + myDir.X(), myLastPnt.Y() + myDir.Y(), myLastPnt.Z() + myDir.Z());
307 BRepLib_MakeEdge ee2(myLastPnt, p2);
308 BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
309 if (ext2.NbExt() == 1
310 && ext2.SquareDistance(1)
311 <= BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace))
313 Sliding = Standard_True;
317 Sliding = Standard_False;
322 Sliding = Standard_False;
326 if (!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
330 gp_Pnt p1(myFirstPnt.X() + myDir1.X(),
331 myFirstPnt.Y() + myDir1.Y(),
332 myFirstPnt.Z() + myDir1.Z());
333 BRepLib_MakeEdge ee1(myFirstPnt, p1);
334 BRepExtrema_ExtCF ext1(ee1, FirstFace);
335 if (ext1.NbExt() == 1
336 && ext1.SquareDistance(1)
337 <= BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace))
339 gp_Pnt p2(myLastPnt.X() + myDir1.X(),
340 myLastPnt.Y() + myDir1.Y(),
341 myLastPnt.Z() + myDir1.Z());
342 BRepLib_MakeEdge ee2(myLastPnt, p2);
343 BRepExtrema_ExtCF ext2(ee2, LastFace);
344 if (ext2.NbExt() == 1
345 && ext2.SquareDistance(1)
346 <= BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace))
348 Sliding = Standard_True;
352 Sliding = Standard_False;
357 Sliding = Standard_False;
362 // Construct a great profile that goes till the bounding box
363 // -> by tangency with the first and the last edge of the Wire
364 // -> by normals to the support faces : statistically better
365 // Intersect everything to find the final profile
367 // ---case of sliding : construction of the profile face
372 std::cout << " still Sliding" << std::endl;
375 Standard_Boolean ProfileOK;
376 ProfileOK = SlidingProfile(Prof,
395 std::cout << "Not computable" << std::endl;
396 std::cout << "Face profile not computable" << std::endl;
399 myStatusError = BRepFeat_NoFaceProf;
404 // ---Propagation on faces of the initial shape
405 // to find the faces concerned by the rib
406 Standard_Boolean falseside = Standard_True;
407 Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
408 // Control if there is everything required to have the material at the proper side
409 if (falseside == Standard_False)
412 std::cout << "Verify plane and wire orientation" << std::endl;
414 myStatusError = BRepFeat_FalseSide;
420 // ---Generation of the base of the rib profile
424 TopoDS_Edge thePreviousEdge;
426 thePreviousEdge.Nullify();
428 // calculate the number of edges to fill the map
429 Standard_Integer counter = 1;
431 // ---case of sliding
432 if (Sliding && !myListOfEdges.IsEmpty())
434 BRepTools_WireExplorer EX1(myWire);
435 for (; EX1.More(); EX1.Next())
437 const TopoDS_Edge& E = EX1.Current();
438 if (!myLFMap.IsBound(E))
440 TopTools_ListOfShape theTmpList;
441 myLFMap.Bind(E, theTmpList);
443 if (E.IsSame(FirstEdge))
446 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
447 cc = new Geom_TrimmedCurve(cc, f, l);
449 if (!FirstEdge.IsSame(LastEdge))
451 pt = BRep_Tool::Pnt(TopExp::LastVertex(E, Standard_True));
456 Standard_Real fpar = IntPar(cc, myFirstPnt);
457 Standard_Real lpar = IntPar(cc, pt);
464 if (thePreviousEdge.IsNull())
466 BRepLib_MakeVertex v1(myFirstPnt);
467 BRepLib_MakeVertex v2(pt);
468 BRepLib_MakeEdge e(cc, v1, v2);
469 ee1 = TopoDS::Edge(e.Shape());
473 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge, Standard_True);
474 BRepLib_MakeVertex v2(pt);
476 BRepLib_MakeEdge e(cc, v1, v2);
477 ee1 = TopoDS::Edge(e.Shape());
479 TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
480 ee1 = TopoDS::Edge(aLocalShape);
481 // ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
483 theFV = TopExp::FirstVertex(ee1, Standard_True);
484 myLFMap(E).Append(ee1);
486 thePreviousEdge = ee1;
493 // Case of several edges
494 if (!FirstEdge.IsSame(LastEdge))
496 for (; EX1.More(); EX1.Next())
498 const TopoDS_Edge& E = EX1.Current();
499 if (!myLFMap.IsBound(E))
501 TopTools_ListOfShape thelist1;
502 myLFMap.Bind(E, thelist1);
506 if (!E.IsSame(LastEdge))
508 Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
509 TopoDS_Vertex v1, v2;
510 if (!thePreviousEdge.IsNull())
512 v1 = TopExp::LastVertex(thePreviousEdge, Standard_True);
513 v2 = TopExp::LastVertex(E, Standard_True);
517 // v1 = TopExp::LastVertex(E,Standard_True);
518 v1 = TopExp::FirstVertex(E, Standard_True);
519 v2 = TopExp::LastVertex(E, Standard_True);
521 BRepLib_MakeEdge E1(ccc, v1, v2);
522 TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
523 TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
524 E11 = TopoDS::Edge(aLocalShape);
525 // E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
526 thePreviousEdge = E11;
527 myLFMap(E).Append(E11);
530 theFV = TopExp::FirstVertex(E11, Standard_True);
535 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
536 gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E, Standard_True));
537 gp_Pnt pl = myLastPnt;
539 if (thePreviousEdge.IsNull())
541 BRepLib_MakeEdge e(cc, pf, pl);
542 ee = TopoDS::Edge(e.Shape());
546 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge, Standard_True);
547 BRepLib_MakeVertex v2(pl);
548 BRepLib_MakeEdge e(cc, v1, v2);
549 ee = TopoDS::Edge(e.Shape());
551 TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
552 ee = TopoDS::Edge(aLocalShape);
553 // ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
555 myLFMap(E).Append(ee);
557 theFV = TopExp::FirstVertex(ee, Standard_True);
558 thePreviousEdge = ee;
565 TopTools_ListIteratorOfListOfShape it(myListOfEdges);
566 Standard_Boolean FirstOK = Standard_False;
567 Standard_Boolean LastOK = Standard_False;
569 gp_Pnt theLastPnt = myLastPnt;
570 Standard_Integer sens = 0;
571 TopoDS_Edge theEdge, theLEdge, theFEdge;
572 Standard_Integer counter1 = counter;
573 TopTools_ListOfShape NewListOfEdges;
574 NewListOfEdges.Clear();
577 const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
580 Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
581 Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
582 if (edg.Orientation() == TopAbs_REVERSED)
585 fp = cc->Value(cc->FirstParameter());
586 lp = cc->Value(cc->LastParameter());
587 Standard_Real dist = fp.Distance(theLastPnt);
591 LastOK = Standard_True;
595 dist = lp.Distance(theLastPnt);
599 LastOK = Standard_True;
603 Standard_Integer FirstFlag = 0;
604 if (sens == 1 && lp.Distance(myFirstPnt) <= myTol)
606 FirstOK = Standard_True;
609 else if (sens == 2 && fp.Distance(myFirstPnt) <= myTol)
611 FirstOK = Standard_True;
618 Standard_Real fpar = cc->FirstParameter();
619 Standard_Real lpar = cc->LastParameter();
622 if (thePreviousEdge.IsNull())
624 BRepLib_MakeEdge e(cc, fpar, lpar);
625 eeee = TopoDS::Edge(e.Shape());
629 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge, Standard_True);
630 BB.UpdateVertex(v1, dist);
631 BRepLib_MakeVertex v2(cc->Value(lpar));
632 TopoDS_Vertex nv = v2.Vertex();
633 BRepLib_MakeEdge e(cc, v1, nv);
634 eeee = TopoDS::Edge(e.Shape());
639 if (thePreviousEdge.IsNull())
641 BRepLib_MakeVertex v1(cc->Value(fpar));
642 BRepLib_MakeEdge e(cc, v1, theFV);
643 eeee = TopoDS::Edge(e.Shape());
647 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge, Standard_True);
648 BRepLib_MakeEdge e(cc, v1, theFV);
649 eeee = TopoDS::Edge(e.Shape());
653 thePreviousEdge = eeee;
656 theFV = TopExp::FirstVertex(eeee, Standard_True);
658 NewListOfEdges.Append(edg);
663 theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge, Standard_True));
670 else if (FirstFlag == 2)
677 myListOfEdges.Remove(it);
678 it.Initialize(myListOfEdges);
679 LastOK = Standard_False;
685 Sliding = Standard_False;
691 TopTools_DataMapOfShapeListOfShape SlidMap;
694 if (Sliding && counter1 > counter)
696 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
697 TopExp_Explorer EX2(w, TopAbs_EDGE);
698 Standard_Integer ii = 0;
699 for (; EX2.More(); EX2.Next())
701 const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
703 if (ii >= counter && ii <= counter1)
705 it.Initialize(NewListOfEdges);
706 Standard_Integer jj = 0;
707 for (; it.More(); it.Next())
709 const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
711 if (jj == (ii - counter + 1))
713 itm.Initialize(mySlface);
714 for (; itm.More(); itm.Next())
716 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
717 const TopTools_ListOfShape& ledg = itm.Value();
718 TopTools_ListIteratorOfListOfShape itedg(ledg);
719 // Standard_Integer iiii = 0;
720 for (; itedg.More(); itedg.Next())
722 const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
725 if (!SlidMap.IsBound(fac))
727 TopTools_ListOfShape thelist2;
728 SlidMap.Bind(fac, thelist2);
730 SlidMap(fac).Append(E);
744 // ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
748 BB.MakeFace(F, myPln, myTol);
749 w.Closed(BRep_Tool::IsClosed(w));
751 // BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
757 // ---Case without sliding : construction of the profile face
764 std::cout << " Sliding failure" << std::endl;
765 std::cout << " no Sliding" << std::endl;
769 Standard_Boolean ProfileOK;
770 ProfileOK = NoSlidingProfile(Prof,
792 std::cout << "Not computable" << std::endl;
793 std::cout << " Face profile not computable" << std::endl;
796 myStatusError = BRepFeat_NoFaceProf;
801 // ---Propagation on faces of the initial shape
802 // to find the faces concerned by the rib
803 Standard_Boolean falseside = Standard_True;
804 Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
805 // Control if there is everything required to have the material at the proper side
806 if (falseside == Standard_False)
809 std::cout << "Verify plane and wire orientation" << std::endl;
811 myStatusError = BRepFeat_FalseSide;
818 TopTools_ListIteratorOfListOfShape it;
819 it.Initialize(SliList);
823 BB.MakeShell(TopoDS::Shell(comp));
825 for (; it.More(); it.Next())
827 BB.Add(comp, it.Value());
829 comp.Closed(BRep_Tool::IsClosed(comp));
840 for (exp.Init(mySbase, TopAbs_FACE); exp.More(); exp.Next())
842 TopTools_ListOfShape thelist3;
843 myMap.Bind(exp.Current(), thelist3);
844 myMap(exp.Current()).Append(exp.Current());
848 //=======================================================================
850 // purpose : add des element de collage
851 //=======================================================================
853 void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E, const TopoDS_Face& F)
856 Standard_Boolean trc = BRepFeat_GettraceFEAT();
858 std::cout << "BRepFeat_MakeLinearForm::Add" << std::endl;
860 if (mySlface.IsEmpty())
863 for (exp.Init(mySbase, TopAbs_FACE); exp.More(); exp.Next())
865 if (exp.Current().IsSame(F))
872 throw Standard_ConstructionError();
875 if (!mySlface.IsBound(F))
877 TopTools_ListOfShape thelist;
878 mySlface.Bind(F, thelist);
880 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
881 for (; itl.More(); itl.Next())
883 if (itl.Value().IsSame(E))
890 mySlface(F).Append(E);
895 //=======================================================================
896 // function : Perform
897 // purpose : construction of rib from a profile and the initial shape
898 //=======================================================================
900 void BRepFeat_MakeLinearForm::Perform()
903 Standard_Boolean trc = BRepFeat_GettraceFEAT();
905 std::cout << "BRepFeat_MakeLinearForm::Perform()" << std::endl;
907 if (mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull())
911 std::cout << " Fields not initialized" << std::endl;
913 myStatusError = BRepFeat_NotInitialized;
918 gp_Vec nulldir(0, 0, 0);
920 Standard_Real Length = myDir.Magnitude() + myDir1.Magnitude();
924 if (!mySUntil.IsNull())
925 myPerfSelection = BRepFeat_SelectionU;
927 myPerfSelection = BRepFeat_NoSelection;
930 gp_Vec V = Length * dir;
932 LocOpe_LinearForm theForm;
934 if (myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
935 theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
937 theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
939 TopoDS_Shape VraiForm = theForm.Shape(); // primitive of the rib
941 myFacesForDraft.Append(theForm.FirstShape());
942 myFacesForDraft.Append(theForm.LastShape());
943 MajMap(myPbase, theForm, myMap, myFShape, myLShape); // management of descendants
945 TopExp_Explorer exx(myPbase, TopAbs_EDGE);
946 for (; exx.More(); exx.Next())
948 const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
949 if (!myMap.IsBound(e))
953 std::cout << " Sliding face not in Base shape" << std::endl;
955 myStatusError = BRepFeat_IncSlidFace;
962 SetGluedFaces(mySlface, theForm, myGluedF); // management of sliding faces
964 if (!myGluedF.IsEmpty() && !mySUntil.IsNull())
969 std::cout << "The case is not computable" << std::endl;
970 std::cout << " Glued faces not empty and Until shape not null" << std::endl;
973 myStatusError = BRepFeat_InvShape;
982 TopExp_Explorer expr(mySbase, TopAbs_FACE);
983 char nom1[20], nom2[20];
984 Standard_Integer ii = 0;
985 for(; expr.More(); expr.Next()) {
987 Sprintf(nom1, "faceinitial_%d", ii);
988 DBRep::Set(nom1, expr.Current());
989 Standard_Integer jj = 0;
990 const TopTools_ListOfShape& list = Modified(expr.Current());
991 TopTools_ListIteratorOfListOfShape ite(list);
992 for(; ite.More(); ite.Next()) {
994 Sprintf(nom2, "facemodifie_%d_%d", ii, jj);
995 DBRep::Set(nom2, ite.Value());
999 expr.Init(myWire, TopAbs_EDGE);
1001 for(; expr.More(); expr.Next()) {
1003 Sprintf(nom1, "edgeinitial_%d", ii);
1004 DBRep::Set(nom1, expr.Current());
1005 Standard_Integer jj = 0;
1006 const TopTools_ListOfShape& genf = Generated(expr.Current());
1007 TopTools_ListIteratorOfListOfShape ite(genf);
1008 for(; ite.More(); ite.Next()) {
1010 Sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
1011 DBRep::Set(nom2, ite.Value());
1017 //=======================================================================
1018 // function : Propagate
1019 // purpose : propagation on faces of the initial shape, find
1020 // faces concerned by the rib
1021 //=======================================================================
1022 Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
1023 const TopoDS_Face& fac,
1024 const gp_Pnt& Firstpnt,
1025 const gp_Pnt& Lastpnt,
1026 Standard_Boolean& falseside)
1029 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
1031 std::cout << "BRepFeat_MakeLinearForm::Propagate" << std::endl;
1033 gp_Pnt Firstpoint = Firstpnt;
1034 gp_Pnt Lastpoint = Lastpnt;
1036 Standard_Boolean result = Standard_True;
1037 TopoDS_Face CurrentFace, saveFace;
1038 CurrentFace = TopoDS::Face(SliList.First());
1039 saveFace = CurrentFace;
1041 Standard_Boolean LastOK = Standard_False, FirstOK = Standard_False;
1042 Standard_Boolean v1OK = Standard_False, v2OK = Standard_False;
1043 TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
1045 BRepAlgoAPI_Section sect(fac, CurrentFace, Standard_False);
1047 sect.Approximation(Standard_True);
1053 Standard_Real t1 = 0., t2 = 0.;
1054 Standard_Boolean c1f, c2f, c1l, c2l;
1056 for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next())
1058 ec = TopoDS::Edge(Ex.Current());
1059 v1 = TopExp::FirstVertex(ec, Standard_True);
1060 v2 = TopExp::LastVertex(ec, Standard_True);
1061 p1 = BRep_Tool::Pnt(v1);
1062 p2 = BRep_Tool::Pnt(v2);
1063 t1 = BRep_Tool::Tolerance(v1);
1064 t2 = BRep_Tool::Tolerance(v2);
1065 c1f = p1.Distance(Firstpoint) <= t1;
1066 c2f = p2.Distance(Firstpoint) <= t2;
1067 c1l = p1.Distance(Lastpoint) <= t1;
1068 c2l = p2.Distance(Lastpoint) <= t2;
1069 if (c1f || c2f || c1l || c2l)
1073 v1OK = Standard_True;
1075 v2OK = Standard_True;
1077 FirstOK = Standard_True;
1079 LastOK = Standard_True;
1086 falseside = Standard_False;
1087 return Standard_False;
1089 TopTools_ListOfShape thelist;
1090 mySlface.Bind(CurrentFace, thelist);
1091 mySlface(CurrentFace).Append(eb);
1093 myListOfEdges.Clear();
1094 myListOfEdges.Append(eb);
1096 // two points are on the same face.
1097 if (LastOK && FirstOK)
1102 TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1103 TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1105 TopoDS_Edge FirstEdge;
1108 TopoDS_Vertex Vprevious;
1112 while (!(LastOK && FirstOK))
1125 // find edge connected to v1 or v2:
1126 for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next())
1128 const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1130 BRepExtrema_ExtPC projF(Vprevious, rfe);
1132 if (projF.IsDone() && projF.NbExt() >= 1)
1134 Standard_Real dist2min = RealLast();
1135 Standard_Integer index = 0;
1136 for (Standard_Integer sol = 1; sol <= projF.NbExt(); sol++)
1138 if (projF.SquareDistance(sol) <= dist2min)
1141 dist2min = projF.SquareDistance(sol);
1146 if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe))
1149 // If the edge is not perpendicular to the plane of the rib
1150 // it is required to set Sliding(result) to false.
1153 result = Standard_False;
1154 ve1 = TopExp::FirstVertex(rfe, Standard_True);
1155 ve2 = TopExp::LastVertex(rfe, Standard_True);
1156 BRepExtrema_ExtPF perp(ve1, fac);
1159 gp_Pnt pe1 = perp.Point(1);
1160 perp.Perform(ve2, fac);
1163 gp_Pnt pe2 = perp.Point(1);
1164 if (pe1.Distance(pe2) <= BRep_Tool::Tolerance(rfe))
1165 result = Standard_True;
1175 const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1176 TopTools_ListIteratorOfListOfShape It(L);
1178 for (; It.More(); It.Next())
1180 const TopoDS_Face& FF = TopoDS::Face(It.Value());
1181 if (!FF.IsSame(CurrentFace))
1188 BRepAlgoAPI_Section sectf(fac, CurrentFace, Standard_False);
1189 sectf.Approximation(Standard_True);
1193 for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next())
1195 edg1 = TopoDS::Edge(Ex.Current());
1196 v1 = TopExp::FirstVertex(edg1, Standard_True);
1197 v2 = TopExp::LastVertex(edg1, Standard_True);
1198 t1 = BRep_Tool::Tolerance(v1);
1199 t2 = BRep_Tool::Tolerance(v2);
1200 p1 = BRep_Tool::Pnt(v1);
1201 p2 = BRep_Tool::Pnt(v2);
1202 v1OK = p1.Distance(ptprev) <= t1;
1203 v2OK = p2.Distance(ptprev) <= t2;
1212 dp = p2.Distance(Firstpoint);
1215 FirstOK = Standard_True;
1216 BB.UpdateVertex(v2, dp);
1221 dp = p2.Distance(Lastpoint);
1224 LastOK = Standard_True;
1225 BB.UpdateVertex(v2, dp);
1233 dp = p1.Distance(Firstpoint);
1236 FirstOK = Standard_True;
1237 BB.UpdateVertex(v1, dp);
1242 dp = p1.Distance(Lastpoint);
1245 LastOK = Standard_True;
1246 BB.UpdateVertex(v1, dp);
1252 // end by chaining the section
1253 return Standard_False;
1255 TopTools_ListOfShape thelist1;
1256 mySlface.Bind(CurrentFace, thelist1);
1257 mySlface(CurrentFace).Append(edg1);
1258 myListOfEdges.Append(edg1);
1264 //=======================================================================
1265 // function : MajMap
1266 // purpose : management of descendants
1267 //=======================================================================
1269 static void MajMap(const TopoDS_Shape& theB,
1270 const LocOpe_LinearForm& theP,
1271 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1272 TopoDS_Shape& theFShape, // myFShape
1273 TopoDS_Shape& theLShape) // myLShape
1275 TopExp_Explorer exp(theP.FirstShape(), TopAbs_WIRE);
1278 theFShape = exp.Current();
1279 TopTools_ListOfShape thelist;
1280 theMap.Bind(theFShape, thelist);
1281 for (exp.Init(theP.FirstShape(), TopAbs_FACE); exp.More(); exp.Next())
1283 theMap(theFShape).Append(exp.Current());
1287 exp.Init(theP.LastShape(), TopAbs_WIRE);
1290 theLShape = exp.Current();
1291 TopTools_ListOfShape thelist1;
1292 theMap.Bind(theLShape, thelist1);
1293 for (exp.Init(theP.LastShape(), TopAbs_FACE); exp.More(); exp.Next())
1295 theMap(theLShape).Append(exp.Current());
1299 for (exp.Init(theB, TopAbs_EDGE); exp.More(); exp.Next())
1301 if (!theMap.IsBound(exp.Current()))
1303 TopTools_ListOfShape thelist2;
1304 theMap.Bind(exp.Current(), thelist2);
1305 theMap(exp.Current()) = theP.Shapes(exp.Current());
1310 //=======================================================================
1311 // function : SetGluedFaces
1312 // purpose : management of faces of gluing
1313 //=======================================================================
1315 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1316 LocOpe_LinearForm& thePrism,
1317 TopTools_DataMapOfShapeShape& theMap)
1320 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1321 if (!theSlmap.IsEmpty())
1323 for (; itm.More(); itm.Next())
1325 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1326 const TopTools_ListOfShape& ledg = itm.Value();
1327 TopTools_ListIteratorOfListOfShape it;
1328 for (it.Initialize(ledg); it.More(); it.Next())
1330 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1331 if (gfac.Extent() != 1)
1334 std::cout << "Pb SetGluedFace" << std::endl;
1337 theMap.Bind(gfac.First(), fac);