1 // File: BRepFeat_MakeLinearForm.cxx
2 // Created: Mon Apr 14 13:34:46 1997
3 // Author: Olga KOULECHOVA
4 // <opt@langdox.paris1.matra-dtv.fr>
7 #include <BRepFeat_MakeLinearForm.ixx>
9 #include <BRepFeat.hxx>
12 #include <LocOpe_Builder.hxx>
13 #include <LocOpe_LinearForm.hxx>
14 #include <LocOpe_Gluer.hxx>
15 #include <LocOpe_FindEdges.hxx>
23 #include <gp_Vec2d.hxx>
24 #include <gp_Pnt2d.hxx>
26 #include <Geom_Curve.hxx>
28 #include <Geom2d_Curve.hxx>
29 #include <Geom2d_Line.hxx>
31 #include <Geom_Plane.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Geom_CylindricalSurface.hxx>
34 #include <Geom_RectangularTrimmedSurface.hxx>
36 #include <Geom_TrimmedCurve.hxx>
37 #include <GeomProjLib.hxx>
39 #include <Geom2d_Curve.hxx>
40 #include <Geom2d_Curve.hxx>
42 #include <TColgp_SequenceOfPnt.hxx>
44 #include <TColStd_Array1OfReal.hxx>
45 #include <IntRes2d_IntersectionPoint.hxx>
47 #include <BRepTools_WireExplorer.hxx>
49 #include <BRep_Tool.hxx>
50 #include <BRep_Builder.hxx>
52 #include <TopExp_Explorer.hxx>
55 #include <TopTools_MapOfShape.hxx>
56 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
60 #include <TopTools_MapIteratorOfMapOfShape.hxx>
61 #include <TopOpeBRepBuild_HBuilder.hxx>
62 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
64 #include <TColgp_Array1OfPnt.hxx>
66 #include <TColGeom_Array1OfCurve.hxx>
69 #include <TopoDS_Shape.hxx>
70 #include <TopoDS_Face.hxx>
72 #include <BRepLib_MakeVertex.hxx>
73 #include <BRepLib_MakeEdge.hxx>
74 #include <BRepLib_MakeFace.hxx>
76 #include <BRepTools.hxx>
78 #include <BRepBuilderAPI.hxx>
79 #include <BRepPrimAPI_MakeBox.hxx>
80 #include <BRepBuilderAPI_MakeFace.hxx>
82 //modified by NIZNHY-PKV Fri Mar 22 16:51:33 2002 f
83 //#include <BRepAlgo_Section.hxx>
84 //#include <BRepAlgo_Common.hxx>
85 #include <BRepAlgoAPI_Section.hxx>
86 #include <BRepAlgoAPI_Common.hxx>
87 //modified by NIZNHY-PKV Fri Mar 22 16:51:35 2002 t
89 #include <BRepExtrema_ExtPC.hxx>
90 #include <BRepExtrema_ExtPF.hxx>
91 #include <BRepExtrema_ExtCF.hxx>
93 #include <BRepTools_Modifier.hxx>
94 #include <BRepTools_TrsfModification.hxx>
96 #include <Standard_ConstructionError.hxx>
98 #include <Precision.hxx>
100 #include <GeomLProp_CLProps.hxx>
102 #include <BRepBuilderAPI_Transform.hxx>
103 #include <BRepLib_MakeWire.hxx>
104 //#include <DbgTools.hxx>
107 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
108 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEATRIB();
111 static void MajMap(const TopoDS_Shape&, // base
112 const LocOpe_LinearForm&,
113 TopTools_DataMapOfShapeListOfShape&, // myMap
114 TopoDS_Shape&, // myFShape
115 TopoDS_Shape&); // myLShape
117 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
119 TopTools_DataMapOfShapeShape&);
121 //=======================================================================
124 //=======================================================================
126 void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
127 const TopoDS_Wire& W,
128 const Handle(Geom_Plane)& Plane,
130 const gp_Vec& Direc1,
131 const Standard_Integer Mode,
132 const Standard_Boolean Modify)
135 Standard_Boolean trc = BRepFeat_GettraceFEAT();
136 if (trc) cout << "BRepFeat_MakeLinearForm::Init" << endl;
138 Standard_Boolean RevolRib = Standard_False;
142 // modify = 0 if there is no intention to make sliding
143 // = 1 if one tries to make sliding
144 Standard_Boolean Sliding = Modify;
157 myListOfEdges.Clear();
160 TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
161 myWire = TopoDS::Wire(aLocalShape);
162 // myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
168 myFuse = Standard_False;
169 else // if(Mode == 1)
170 myFuse = Standard_True;
173 if (myFuse) cout << " Fuse" << endl;
174 if (!myFuse) cout << " Cut" << endl;
179 // ---Determine Tolerance : max tolerance on parameters
180 myTol = Precision::Confusion();
183 exx.Init(myWire, TopAbs_VERTEX);
184 for(; exx.More(); exx.Next()) {
185 const Standard_Real& tol = BRep_Tool::
186 Tolerance(TopoDS::Vertex(exx.Current()));
187 if(tol > myTol) myTol = tol;
190 exx.Init(Sbase, TopAbs_VERTEX);
191 for(; exx.More(); exx.Next()) {
192 const Standard_Real& tol = BRep_Tool::
193 Tolerance(TopoDS::Vertex(exx.Current()));
194 if(tol > myTol) myTol = tol;
197 // ---Control of directions
198 // the wire should be in the rib
199 gp_Vec nulldir(0, 0, 0);
200 if(!myDir1.IsEqual(nulldir, myTol, myTol)) {
201 Standard_Real ang = myDir1.Angle(myDir);
204 if (trc) cout << " Directions must be opposite" << endl;
206 myStatusError = BRepFeat_BadDirect;
213 // Rib is centre in the middle of translation
215 if (trc) cout << " Rib is centre" << endl;
217 const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
219 T.SetTranslation(DirTranslation);
220 BRepBuilderAPI_Transform trf(T);
222 myWire = TopoDS::Wire(trf.Shape());
223 myDir = Direc - DirTranslation;
224 myDir1 = Direc1 - DirTranslation;
228 // ---Calculate bounding box
231 TopTools_ListOfShape theList;
235 gp_Pnt FirstCorner, LastCorner;
236 Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
239 BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
240 TopoDS_Solid BndBox = Bndbox.Solid();
243 // ---Construction of the face workplane (section bounding box)
244 BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd,
245 6.*myBnd, -6.*myBnd, 6.*myBnd);
246 TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
248 //modified by NIZNHY-PKV Fri Mar 22 16:49:28 2002 f
249 //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
250 BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
251 //modified by NIZNHY-PKV Fri Mar 22 16:49:39 2002 t
253 TopoDS_Shape PlaneSect = PlaneS.Shape();
254 EXP.Init(PlaneSect, TopAbs_WIRE);
255 TopoDS_Wire www = TopoDS::Wire(EXP.Current());
256 BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
257 TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
260 // ---Find support faces of the rib
261 TopoDS_Edge FirstEdge, LastEdge;
262 TopoDS_Face FirstFace, LastFace;
263 TopoDS_Vertex FirstVertex, LastVertex;
265 Standard_Boolean OnFirstFace = Standard_False;
266 Standard_Boolean OnLastFace = Standard_False;
267 Standard_Boolean PtOnFirstEdge = Standard_False;
268 Standard_Boolean PtOnLastEdge = Standard_False;
269 TopoDS_Edge OnFirstEdge, OnLastEdge;
270 OnFirstEdge.Nullify();
271 OnLastEdge.Nullify();
273 Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge,
274 FirstFace, LastFace, FirstVertex,
275 LastVertex, OnFirstFace, OnLastFace,
276 PtOnFirstEdge, PtOnLastEdge,
277 OnFirstEdge, OnLastEdge);
281 if (trc) cout << " No Extreme faces" << endl;
283 myStatusError = BRepFeat_NoExtFace;
289 // ---Proofing Point for the side of the wire to be filled - side material
290 gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
292 // Standard_Real f, l;
294 // ---Control sliding valuable
295 // Many cases when the sliding is abandoned
296 Standard_Integer Concavite = 3; // a priori the profile is not concave
298 myFirstPnt = BRep_Tool::Pnt(FirstVertex);
299 myLastPnt = BRep_Tool::Pnt(LastVertex);
301 // SliList : list of faces concerned by the rib
302 TopTools_ListOfShape SliList;
303 SliList.Append(FirstFace);
305 if(Sliding) { // sliding
307 if (trc) cout << " Sliding" << endl;
309 Standard_Boolean Sliding = Standard_False;
310 Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
311 if (s->DynamicType() ==
312 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
313 s = Handle(Geom_RectangularTrimmedSurface)::
314 DownCast(s)->BasisSurface();
316 if(s->DynamicType() == STANDARD_TYPE(Geom_Plane) ||
317 s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
318 // if plane or cylinder : sliding is possible
319 Sliding = Standard_True;
323 // Control only start and end points
324 // -> no control at the middle - improve
325 // Controle between Surface and segment between 2 limit points
326 // is too expensive - improve
328 gp_Pnt p1(myFirstPnt.X()+myDir.X(),myFirstPnt.Y()+myDir.Y(),
329 myFirstPnt.Z()+myDir.Z());
330 BRepLib_MakeEdge ee1(myFirstPnt, p1);
331 BRepExtrema_ExtCF ext1(ee1, FirstFace);
332 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
333 gp_Pnt p2(myLastPnt.X()+myDir.X(),myLastPnt.Y()+myDir.Y(),
334 myLastPnt.Z()+myDir.Z());
335 BRepLib_MakeEdge ee2(myLastPnt, p2);
336 BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
337 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
338 Sliding = Standard_True;
341 Sliding = Standard_False;
345 Sliding = Standard_False;
349 if(!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) {
351 gp_Pnt p1(myFirstPnt.X()+myDir1.X(),myFirstPnt.Y()+myDir1.Y(),
352 myFirstPnt.Z()+myDir1.Z());
353 BRepLib_MakeEdge ee1(myFirstPnt, p1);
354 BRepExtrema_ExtCF ext1(ee1, FirstFace);
355 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
356 gp_Pnt p2(myLastPnt.X()+myDir1.X(),myLastPnt.Y()+myDir1.Y(),
357 myLastPnt.Z()+myDir1.Z());
358 BRepLib_MakeEdge ee2(myLastPnt, p2);
359 BRepExtrema_ExtCF ext2(ee2, LastFace);
360 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
361 Sliding = Standard_True;
364 Sliding = Standard_False;
368 Sliding = Standard_False;
374 // Construct a great profile that goes till the bounding box
375 // -> by tangency with the first and the last edge of the Wire
376 // -> by normals to the support faces : statistically better
377 // Intersect everything to find the final profile
380 // ---case of sliding : construction of the profile face
383 if (trc) cout << " still Sliding" << endl;
386 Standard_Boolean ProfileOK;
387 ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
388 FirstFace,LastFace,FirstVertex,LastVertex,
393 cout << "Not computable" << endl;
394 if (trc) cout << "Face profile not computable" << endl;
396 myStatusError = BRepFeat_NoFaceProf;
402 // ---Propagation on faces of the initial shape
403 // to find the faces concerned by the rib
404 Standard_Boolean falseside = Standard_True;
405 Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
406 // Control if there is everything required to have the material at the proper side
407 if(falseside == Standard_False) {
409 cout << "Verify plane and wire orientation" << endl;
411 myStatusError = BRepFeat_FalseSide;
418 // ---Generation of the base of the rib profile
422 TopoDS_Edge thePreviousEdge;
424 thePreviousEdge.Nullify();
426 // calculate the number of edges to fill the map
427 Standard_Integer counter = 1;
429 // ---case of sliding
430 if(Sliding && !myListOfEdges.IsEmpty()) {
431 BRepTools_WireExplorer EX1(myWire);
432 for(; EX1.More(); EX1.Next()) {
433 const TopoDS_Edge& E = EX1.Current();
434 if(!myLFMap.IsBound(E)) {
435 TopTools_ListOfShape theTmpList;
436 myLFMap.Bind(E, theTmpList );
438 if(E.IsSame(FirstEdge)) {
440 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
441 cc = new Geom_TrimmedCurve(cc, f, l);
443 if(!FirstEdge.IsSame(LastEdge)) {
444 pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
448 Standard_Real fpar = IntPar(cc, myFirstPnt);
449 Standard_Real lpar = IntPar(cc, pt);
450 Handle(Geom_Curve) ccc;
452 ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
457 if(thePreviousEdge.IsNull()) {
458 BRepLib_MakeVertex v1(myFirstPnt);
459 BRepLib_MakeVertex v2(pt);
460 BRepLib_MakeEdge e(cc, v1, v2);
461 ee1 = TopoDS::Edge(e.Shape());
464 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
465 BRepLib_MakeVertex v2(pt);
467 BRepLib_MakeEdge e(cc, v1, v2);
468 ee1 = TopoDS::Edge(e.Shape());
470 TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
471 ee1 = TopoDS::Edge(aLocalShape);
472 // ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
473 if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
474 myLFMap(E).Append(ee1);
476 thePreviousEdge = ee1;
483 // Case of several edges
484 if(!FirstEdge.IsSame(LastEdge)) {
485 for(; EX1.More(); EX1.Next()) {
486 const TopoDS_Edge& E = EX1.Current();
487 if(!myLFMap.IsBound(E)) {
488 TopTools_ListOfShape thelist1;
489 myLFMap.Bind(E, thelist1);
493 if(!E.IsSame(LastEdge)) {
494 Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
495 TopoDS_Vertex v1, v2;
496 if(!thePreviousEdge.IsNull()) {
497 v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
498 v2 = TopExp::LastVertex(E,Standard_True);
501 // v1 = TopExp::LastVertex(E,Standard_True);
502 v1 = TopExp::FirstVertex(E,Standard_True);
503 v2 = TopExp::LastVertex(E,Standard_True);
505 BRepLib_MakeEdge E1(ccc, v1, v2);
506 TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
507 TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
508 E11 = TopoDS::Edge(aLocalShape);
509 // E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
510 thePreviousEdge = E11;
511 myLFMap(E).Append(E11);
513 if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
518 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
519 gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
520 gp_Pnt pl = myLastPnt;
522 if(thePreviousEdge.IsNull()) {
523 BRepLib_MakeEdge e(cc, pf , pl);
524 ee = TopoDS::Edge(e.Shape());
527 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
528 BRepLib_MakeVertex v2(pl);
529 BRepLib_MakeEdge e(cc, v1, v2);
530 ee = TopoDS::Edge(e.Shape());
532 TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
533 ee = TopoDS::Edge(aLocalShape);
534 // ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
536 myLFMap(E).Append(ee);
537 if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
538 thePreviousEdge = ee;
545 TopTools_ListIteratorOfListOfShape it(myListOfEdges);
546 Standard_Boolean FirstOK = Standard_False;
547 Standard_Boolean LastOK = Standard_False;
549 gp_Pnt theLastPnt = myLastPnt;
550 Standard_Integer sens = 0;
551 TopoDS_Edge theEdge, theLEdge, theFEdge;
552 Standard_Integer counter1 = counter;
553 TopTools_ListOfShape NewListOfEdges;
554 NewListOfEdges.Clear();
556 const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
559 Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
560 Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
561 if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
563 fp = cc->Value(cc->FirstParameter());
564 lp = cc->Value(cc->LastParameter());
565 Standard_Real dist = fp.Distance(theLastPnt);
568 LastOK = Standard_True;
571 dist = lp.Distance(theLastPnt);
574 LastOK = Standard_True;
578 Standard_Integer FirstFlag = 0;
579 if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
580 FirstOK = Standard_True;
583 else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
584 FirstOK = Standard_True;
590 Standard_Real fpar = cc->FirstParameter();
591 Standard_Real lpar = cc->LastParameter();
593 if(thePreviousEdge.IsNull()) {
594 BRepLib_MakeEdge e(cc, fpar, lpar);
595 eeee = TopoDS::Edge(e.Shape());
598 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
599 BB.UpdateVertex(v1, dist);
600 BRepLib_MakeVertex v2(cc->Value(lpar));
601 TopoDS_Vertex nv=v2.Vertex();
602 BRepLib_MakeEdge e(cc, v1, nv);
603 eeee = TopoDS::Edge(e.Shape());
607 if(thePreviousEdge.IsNull()) {
608 BRepLib_MakeVertex v1(cc->Value(fpar));
609 BRepLib_MakeEdge e(cc, v1, theFV);
610 eeee = TopoDS::Edge(e.Shape());
613 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
614 BRepLib_MakeEdge e(cc, v1, theFV);
615 eeee = TopoDS::Edge(e.Shape());
619 thePreviousEdge = eeee;
621 if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
623 NewListOfEdges.Append(edg);
626 Standard_Real dist1 =
628 theLastPnt.Distance(myLastPnt);
632 theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
638 else if(FirstFlag == 2) {
643 myListOfEdges.Remove(it);
644 it.Initialize(myListOfEdges);
645 LastOK = Standard_False;
647 else if(it.More()) it.Next();
649 Sliding = Standard_False;
656 TopTools_DataMapOfShapeListOfShape SlidMap;
659 if(Sliding && counter1 > counter) {
660 TopTools_ListIteratorOfListOfShape it;
661 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
662 TopExp_Explorer EX2(w, TopAbs_EDGE);
663 Standard_Integer ii = 0;
664 for(; EX2.More(); EX2.Next()) {
665 const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
667 if(ii >= counter && ii <= counter1) {
668 it.Initialize(NewListOfEdges);
669 Standard_Integer jj = 0;
670 for(; it.More(); it.Next()) {
671 const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
673 if(jj== (ii - counter +1)) {
674 itm.Initialize(mySlface);
675 for(; itm.More(); itm.Next()) {
676 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
677 const TopTools_ListOfShape& ledg = itm.Value();
678 TopTools_ListIteratorOfListOfShape itedg(ledg);
679 //Standard_Integer iiii = 0;
680 for(; itedg.More(); itedg.Next()) {
681 const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
683 if(!SlidMap.IsBound(fac)) {
684 TopTools_ListOfShape thelist2;
685 SlidMap.Bind(fac, thelist2);
687 SlidMap(fac).Append(E);
701 // ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
704 BB.MakeFace(F, myPln, myTol);
706 // BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
713 // ---Case without sliding : construction of the profile face
717 if (Modify) cout << " Sliding failure" << endl;
718 cout << " no Sliding" << endl;
722 Standard_Boolean ProfileOK;
723 ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
724 bnd,BndFace,CheckPnt,
725 FirstFace,LastFace,FirstVertex,LastVertex,
726 FirstEdge,LastEdge,OnFirstFace,OnLastFace);
730 cout << "Not computable" << endl;
731 if (trc) cout << " Face profile not computable" << endl;
733 myStatusError = BRepFeat_NoFaceProf;
739 // ---Propagation on faces of the initial shape
740 // to find the faces concerned by the rib
741 Standard_Boolean falseside = Standard_True;
742 Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
743 // Control if there is everything required to have the material at the proper side
744 if(falseside == Standard_False) {
746 cout << "Verify plane and wire orientation" << endl;
748 myStatusError = BRepFeat_FalseSide;
755 TopTools_ListIteratorOfListOfShape it;
756 it.Initialize(SliList);
761 BB.MakeShell(TopoDS::Shell(comp));
763 for(; it.More(); it.Next()) {
764 BB.Add(comp, it.Value());
776 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
777 TopTools_ListOfShape thelist3;
778 myMap.Bind(exp.Current(), thelist3);
779 myMap(exp.Current()).Append(exp.Current());
784 //=======================================================================
786 //purpose : add des element de collage
787 //=======================================================================
789 void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E,
790 const TopoDS_Face& F)
793 Standard_Boolean trc = BRepFeat_GettraceFEAT();
794 if (trc) cout << "BRepFeat_MakeLinearForm::Add" << endl;
796 if(mySlface.IsEmpty()) {
798 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
799 if (exp.Current().IsSame(F)) {
804 Standard_ConstructionError::Raise();
807 if (!mySlface.IsBound(F)) {
808 TopTools_ListOfShape thelist;
809 mySlface.Bind(F, thelist);
811 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
812 for (; itl.More();itl.Next()) {
813 if (itl.Value().IsSame(E)) {
818 mySlface(F).Append(E);
825 //=======================================================================
827 //purpose : construction of rib from a profile and the initial shape
828 //=======================================================================
830 void BRepFeat_MakeLinearForm::Perform()
833 Standard_Boolean trc = BRepFeat_GettraceFEAT();
834 if (trc) cout << "BRepFeat_MakeLinearForm::Perform()" << endl;
836 if(mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull()) {
838 if (trc) cout << " Fields not initialized" << endl;
840 myStatusError = BRepFeat_NotInitialized;
845 gp_Vec nulldir(0, 0, 0);
847 Standard_Real Length = myDir.Magnitude() + myDir1.Magnitude();
851 if(!mySUntil.IsNull())
852 myPerfSelection = BRepFeat_SelectionU;
854 myPerfSelection = BRepFeat_NoSelection;
857 gp_Vec V = Length*dir;
859 LocOpe_LinearForm theForm;
861 if(myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
862 theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
864 theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
866 TopoDS_Shape VraiForm = theForm.Shape(); // primitive of the rib
868 myFacesForDraft.Append(theForm.FirstShape());
869 myFacesForDraft.Append(theForm.LastShape());
870 MajMap(myPbase,theForm,myMap,myFShape,myLShape); // management of descendants
872 TopExp_Explorer exx(myPbase, TopAbs_EDGE);
873 for(; exx.More(); exx.Next()) {
874 const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
875 if(!myMap.IsBound(e)) {
877 if (trc) cout << " Sliding face not in Base shape" << endl;
879 myStatusError = BRepFeat_IncSlidFace;
886 SetGluedFaces(mySlface, theForm, myGluedF); // management of sliding faces
888 if(!myGluedF.IsEmpty() && !mySUntil.IsNull()) {
890 cout << "The case is not computable" << endl;
891 if (trc) cout << " Glued faces not empty and Until shape not null" << endl;
893 myStatusError = BRepFeat_InvShape;
902 TopExp_Explorer expr(mySbase, TopAbs_FACE);
903 char nom1[20], nom2[20];
904 Standard_Integer ii = 0;
905 for(; expr.More(); expr.Next()) {
907 sprintf(nom1, "faceinitial_%d", ii);
908 DBRep::Set(nom1, expr.Current());
909 Standard_Integer jj = 0;
910 const TopTools_ListOfShape& list = Modified(expr.Current());
911 TopTools_ListIteratorOfListOfShape ite(list);
912 for(; ite.More(); ite.Next()) {
914 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
915 DBRep::Set(nom2, ite.Value());
919 expr.Init(myWire, TopAbs_EDGE);
921 for(; expr.More(); expr.Next()) {
923 sprintf(nom1, "edgeinitial_%d", ii);
924 DBRep::Set(nom1, expr.Current());
925 Standard_Integer jj = 0;
926 const TopTools_ListOfShape& genf = Generated(expr.Current());
927 TopTools_ListIteratorOfListOfShape ite(genf);
928 for(; ite.More(); ite.Next()) {
930 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
931 DBRep::Set(nom2, ite.Value());
937 //=======================================================================
938 //function : Propagate
939 //purpose : propagation on faces of the initial shape, find
940 // faces concerned by the rib
941 //=======================================================================
942 Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
943 const TopoDS_Face& fac,
944 const gp_Pnt& Firstpnt,
945 const gp_Pnt& Lastpnt,
946 Standard_Boolean& falseside)
949 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
950 if (trc) cout << "BRepFeat_MakeLinearForm::Propagate" << endl;
952 gp_Pnt Firstpoint = Firstpnt;
953 gp_Pnt Lastpoint = Lastpnt;
955 Standard_Boolean result = Standard_True;
956 TopoDS_Face CurrentFace, saveFace;
957 CurrentFace = TopoDS::Face(SliList.First());
958 saveFace = CurrentFace;
960 Standard_Boolean LastOK = Standard_False, FirstOK= Standard_False;
961 Standard_Boolean v1OK = Standard_False, v2OK= Standard_False;
962 TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
964 //modified by NIZNHY-PKV Fri Mar 22 16:50:24 2002 f
965 //BRepAlgo_Section sect (fac, CurrentFace, Standard_False);
966 BRepAlgoAPI_Section sect (fac, CurrentFace, Standard_False);
967 //modified by NIZNHY-PKV Fri Mar 22 16:50:32 2002 t
969 sect.Approximation(Standard_True);
976 Standard_Real t1 = 0., t2 = 0.;
978 Standard_Real t1, t2;
980 Standard_Boolean c1f, c2f, c1l, c2l;
982 for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
983 ec = TopoDS::Edge(Ex.Current());
984 v1 = TopExp::FirstVertex(ec,Standard_True);
985 v2 = TopExp::LastVertex(ec,Standard_True);
986 p1 = BRep_Tool::Pnt(v1);
987 p2 = BRep_Tool::Pnt(v2);
988 t1 = BRep_Tool::Tolerance(v1);
989 t2 = BRep_Tool::Tolerance(v2);
990 c1f = p1.Distance(Firstpoint)<=t1;
991 c2f = p2.Distance(Firstpoint)<=t2;
992 c1l = p1.Distance(Lastpoint)<=t1;
993 c2l = p2.Distance(Lastpoint)<=t2;
994 if (c1f || c2f || c1l|| c2l) {
996 if (c1f || c1l) v1OK=Standard_True;
997 if (c2f || c2l) v2OK=Standard_True;
998 if (c1f || c2f) FirstOK=Standard_True;
999 if (c1l || c2l) LastOK=Standard_True;
1005 falseside = Standard_False;
1006 return Standard_False;
1008 TopTools_ListOfShape thelist;
1009 mySlface.Bind(CurrentFace, thelist);
1010 mySlface(CurrentFace).Append(eb);
1012 myListOfEdges.Clear();
1013 myListOfEdges.Append(eb);
1015 // two points are on the same face.
1016 if(LastOK && FirstOK) {
1020 TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1021 TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1023 TopoDS_Edge FirstEdge;
1026 TopoDS_Vertex Vprevious;
1028 Standard_Real tvp, dp;
1030 while (!(LastOK && FirstOK)) {
1042 // find edge connected to v1 or v2:
1043 for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next()) {
1044 const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1046 BRepExtrema_ExtPC projF(Vprevious, rfe);
1048 if(projF.IsDone() && projF.NbExt() >=1) {
1049 Standard_Real dist2min = RealLast();
1050 Standard_Integer index = 0;
1051 for (Standard_Integer sol =1 ; sol <= projF.NbExt(); sol++) {
1052 if (projF.SquareDistance(sol) <= dist2min) {
1054 dist2min = projF.SquareDistance(sol);
1058 if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe)) {
1060 // If the edge is not perpendicular to the plane of the rib
1061 // it is required to set Sliding(result) to false.
1063 result=Standard_False;
1064 ve1 = TopExp::FirstVertex(rfe,Standard_True);
1065 ve2 = TopExp::LastVertex(rfe,Standard_True);
1066 BRepExtrema_ExtPF perp(ve1, fac);
1067 if (perp.IsDone()) {
1068 gp_Pnt pe1=perp.Point(1);
1069 perp.Perform(ve2, fac);
1070 if (perp.IsDone()) {
1071 gp_Pnt pe2=perp.Point(1);
1072 if (pe1.Distance(pe2)<=BRep_Tool::Tolerance(rfe))
1073 result=Standard_True;
1083 const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1084 TopTools_ListIteratorOfListOfShape It(L);
1086 for (; It.More(); It.Next()) {
1087 const TopoDS_Face& FF = TopoDS::Face(It.Value());
1088 if (!FF.IsSame(CurrentFace)) {
1094 //modified by NIZNHY-PKV Fri Mar 22 16:50:53 2002 f
1095 //BRepAlgo_Section sectf (fac, CurrentFace, Standard_False);
1096 BRepAlgoAPI_Section sectf (fac, CurrentFace, Standard_False);
1097 //modified by NIZNHY-PKV Fri Mar 22 16:51:03 2002 t
1098 sectf.Approximation(Standard_True);
1102 for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
1103 edg1 = TopoDS::Edge(Ex.Current());
1104 v1=TopExp::FirstVertex(edg1,Standard_True);
1105 v2=TopExp::LastVertex(edg1,Standard_True);
1106 t1 = BRep_Tool::Tolerance(v1);
1107 t2 = BRep_Tool::Tolerance(v2);
1108 p1 = BRep_Tool::Pnt(v1);
1109 p2 = BRep_Tool::Pnt(v2);
1110 v1OK = p1.Distance(ptprev)<=t1;
1111 v2OK = p2.Distance(ptprev)<=t2;
1112 if (v1OK || v2OK) break;
1117 dp = p2.Distance(Firstpoint);
1119 FirstOK = Standard_True;
1120 BB.UpdateVertex(v2, dp);
1124 dp = p2.Distance(Lastpoint);
1126 LastOK = Standard_True;
1127 BB.UpdateVertex(v2, dp);
1133 dp = p1.Distance(Firstpoint);
1135 FirstOK = Standard_True;
1136 BB.UpdateVertex(v1, dp);
1140 dp = p1.Distance(Lastpoint);
1142 LastOK = Standard_True;
1143 BB.UpdateVertex(v1, dp);
1148 // end by chaining the section
1149 return Standard_False;
1152 // Standard_Boolean isnb=
1154 TopTools_ListOfShape thelist1;
1156 Standard_Boolean isnb=
1158 mySlface.Bind(CurrentFace, thelist1);
1159 mySlface(CurrentFace).Append(edg1);
1160 myListOfEdges.Append(edg1);
1167 //=======================================================================
1169 //purpose : management of descendants
1170 //=======================================================================
1172 static void MajMap(const TopoDS_Shape& theB,
1173 const LocOpe_LinearForm& theP,
1174 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1175 TopoDS_Shape& theFShape, // myFShape
1176 TopoDS_Shape& theLShape) // myLShape
1178 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1180 theFShape = exp.Current();
1181 TopTools_ListOfShape thelist;
1182 theMap.Bind(theFShape, thelist);
1183 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1184 theMap(theFShape).Append(exp.Current());
1188 exp.Init(theP.LastShape(),TopAbs_WIRE);
1190 theLShape = exp.Current();
1191 TopTools_ListOfShape thelist1;
1192 theMap.Bind(theLShape, thelist1);
1193 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1194 theMap(theLShape).Append(exp.Current());
1198 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1199 if (!theMap.IsBound(exp.Current())) {
1201 const TopoDS_Edge& e =
1203 TopoDS::Edge(exp.Current());
1204 TopTools_ListOfShape thelist2;
1205 theMap.Bind(exp.Current(), thelist2);
1206 theMap(exp.Current()) = theP.Shapes(exp.Current());
1211 //=======================================================================
1212 //function : SetGluedFaces
1213 //purpose : management of faces of gluing
1214 //=======================================================================
1216 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1217 LocOpe_LinearForm& thePrism,
1218 TopTools_DataMapOfShapeShape& theMap)
1221 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1222 if(!theSlmap.IsEmpty()) {
1223 for (; itm.More(); itm.Next()) {
1224 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1225 const TopTools_ListOfShape& ledg = itm.Value();
1226 TopTools_ListIteratorOfListOfShape it;
1227 for (it.Initialize(ledg); it.More(); it.Next()) {
1228 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1229 if (gfac.Extent() != 1) {
1231 cout << "Pb SetGluedFace" << endl;
1234 theMap.Bind(gfac.First(),fac);