1 // Created on: 1997-04-14
2 // Created by: Olga KOULECHOVA
3 // Copyright (c) 1997-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 <BRepFeat_MakeLinearForm.ixx>
25 #include <BRepFeat.hxx>
28 #include <LocOpe_LinearForm.hxx>
29 #include <LocOpe_Gluer.hxx>
30 #include <LocOpe_FindEdges.hxx>
38 #include <gp_Vec2d.hxx>
39 #include <gp_Pnt2d.hxx>
41 #include <Geom_Curve.hxx>
43 #include <Geom2d_Curve.hxx>
44 #include <Geom2d_Line.hxx>
46 #include <Geom_Plane.hxx>
47 #include <Geom_Surface.hxx>
48 #include <Geom_CylindricalSurface.hxx>
49 #include <Geom_RectangularTrimmedSurface.hxx>
51 #include <Geom_TrimmedCurve.hxx>
52 #include <GeomProjLib.hxx>
54 #include <Geom2d_Curve.hxx>
55 #include <Geom2d_Curve.hxx>
57 #include <TColgp_SequenceOfPnt.hxx>
59 #include <TColStd_Array1OfReal.hxx>
60 #include <IntRes2d_IntersectionPoint.hxx>
62 #include <BRepTools_WireExplorer.hxx>
64 #include <BRep_Tool.hxx>
65 #include <BRep_Builder.hxx>
67 #include <TopExp_Explorer.hxx>
70 #include <TopTools_MapOfShape.hxx>
71 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
72 #include <TopTools_ListOfShape.hxx>
73 #include <TopTools_ListIteratorOfListOfShape.hxx>
74 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
75 #include <TopTools_MapIteratorOfMapOfShape.hxx>
76 #include <TopOpeBRepBuild_HBuilder.hxx>
77 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
79 #include <TColgp_Array1OfPnt.hxx>
81 #include <TColGeom_Array1OfCurve.hxx>
84 #include <TopoDS_Shape.hxx>
85 #include <TopoDS_Face.hxx>
87 #include <BRepLib_MakeVertex.hxx>
88 #include <BRepLib_MakeEdge.hxx>
89 #include <BRepLib_MakeFace.hxx>
91 #include <BRepTools.hxx>
93 #include <BRepBuilderAPI.hxx>
94 #include <BRepPrimAPI_MakeBox.hxx>
95 #include <BRepBuilderAPI_MakeFace.hxx>
97 //modified by NIZNHY-PKV Fri Mar 22 16:51:33 2002 f
98 //#include <BRepAlgo_Section.hxx>
99 //#include <BRepAlgo_Common.hxx>
100 #include <BRepAlgoAPI_Section.hxx>
101 #include <BRepAlgoAPI_Common.hxx>
102 //modified by NIZNHY-PKV Fri Mar 22 16:51:35 2002 t
104 #include <BRepExtrema_ExtPC.hxx>
105 #include <BRepExtrema_ExtPF.hxx>
106 #include <BRepExtrema_ExtCF.hxx>
108 #include <BRepTools_Modifier.hxx>
109 #include <BRepTools_TrsfModification.hxx>
111 #include <Standard_ConstructionError.hxx>
113 #include <Precision.hxx>
115 #include <GeomLProp_CLProps.hxx>
117 #include <BRepBuilderAPI_Transform.hxx>
118 #include <BRepLib_MakeWire.hxx>
119 //#include <DbgTools.hxx>
122 extern Standard_Boolean BRepFeat_GettraceFEAT();
123 extern Standard_Boolean BRepFeat_GettraceFEATRIB();
126 static void MajMap(const TopoDS_Shape&, // base
127 const LocOpe_LinearForm&,
128 TopTools_DataMapOfShapeListOfShape&, // myMap
129 TopoDS_Shape&, // myFShape
130 TopoDS_Shape&); // myLShape
132 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
134 TopTools_DataMapOfShapeShape&);
136 //=======================================================================
139 //=======================================================================
141 void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
142 const TopoDS_Wire& W,
143 const Handle(Geom_Plane)& Plane,
145 const gp_Vec& Direc1,
146 const Standard_Integer Mode,
147 const Standard_Boolean Modify)
150 Standard_Boolean trc = BRepFeat_GettraceFEAT();
151 if (trc) cout << "BRepFeat_MakeLinearForm::Init" << endl;
153 Standard_Boolean RevolRib = Standard_False;
157 // modify = 0 if there is no intention to make sliding
158 // = 1 if one tries to make sliding
159 Standard_Boolean Sliding = Modify;
172 myListOfEdges.Clear();
175 TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
176 myWire = TopoDS::Wire(aLocalShape);
177 // myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
183 myFuse = Standard_False;
184 else // if(Mode == 1)
185 myFuse = Standard_True;
188 if (myFuse) cout << " Fuse" << endl;
189 if (!myFuse) cout << " Cut" << endl;
194 // ---Determine Tolerance : max tolerance on parameters
195 myTol = Precision::Confusion();
198 exx.Init(myWire, TopAbs_VERTEX);
199 for(; exx.More(); exx.Next()) {
200 const Standard_Real& tol = BRep_Tool::
201 Tolerance(TopoDS::Vertex(exx.Current()));
202 if(tol > myTol) myTol = tol;
205 exx.Init(Sbase, TopAbs_VERTEX);
206 for(; exx.More(); exx.Next()) {
207 const Standard_Real& tol = BRep_Tool::
208 Tolerance(TopoDS::Vertex(exx.Current()));
209 if(tol > myTol) myTol = tol;
212 // ---Control of directions
213 // the wire should be in the rib
214 gp_Vec nulldir(0, 0, 0);
215 if(!myDir1.IsEqual(nulldir, myTol, myTol)) {
216 Standard_Real ang = myDir1.Angle(myDir);
219 if (trc) cout << " Directions must be opposite" << endl;
221 myStatusError = BRepFeat_BadDirect;
228 // Rib is centre in the middle of translation
230 if (trc) cout << " Rib is centre" << endl;
232 const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
234 T.SetTranslation(DirTranslation);
235 BRepBuilderAPI_Transform trf(T);
237 myWire = TopoDS::Wire(trf.Shape());
238 myDir = Direc - DirTranslation;
239 myDir1 = Direc1 - DirTranslation;
243 // ---Calculate bounding box
246 TopTools_ListOfShape theList;
250 gp_Pnt FirstCorner, LastCorner;
251 Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
254 BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
255 TopoDS_Solid BndBox = Bndbox.Solid();
258 // ---Construction of the face workplane (section bounding box)
259 BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd,
260 6.*myBnd, -6.*myBnd, 6.*myBnd);
261 TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
263 //modified by NIZNHY-PKV Fri Mar 22 16:49:28 2002 f
264 //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
265 BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
266 //modified by NIZNHY-PKV Fri Mar 22 16:49:39 2002 t
268 TopoDS_Shape PlaneSect = PlaneS.Shape();
269 EXP.Init(PlaneSect, TopAbs_WIRE);
270 TopoDS_Wire www = TopoDS::Wire(EXP.Current());
271 BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
272 TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
275 // ---Find support faces of the rib
276 TopoDS_Edge FirstEdge, LastEdge;
277 TopoDS_Face FirstFace, LastFace;
278 TopoDS_Vertex FirstVertex, LastVertex;
280 Standard_Boolean OnFirstFace = Standard_False;
281 Standard_Boolean OnLastFace = Standard_False;
282 Standard_Boolean PtOnFirstEdge = Standard_False;
283 Standard_Boolean PtOnLastEdge = Standard_False;
284 TopoDS_Edge OnFirstEdge, OnLastEdge;
285 OnFirstEdge.Nullify();
286 OnLastEdge.Nullify();
288 Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge,
289 FirstFace, LastFace, FirstVertex,
290 LastVertex, OnFirstFace, OnLastFace,
291 PtOnFirstEdge, PtOnLastEdge,
292 OnFirstEdge, OnLastEdge);
296 if (trc) cout << " No Extreme faces" << endl;
298 myStatusError = BRepFeat_NoExtFace;
304 // ---Proofing Point for the side of the wire to be filled - side material
305 gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
307 // Standard_Real f, l;
309 // ---Control sliding valuable
310 // Many cases when the sliding is abandoned
311 Standard_Integer Concavite = 3; // a priori the profile is not concave
313 myFirstPnt = BRep_Tool::Pnt(FirstVertex);
314 myLastPnt = BRep_Tool::Pnt(LastVertex);
316 // SliList : list of faces concerned by the rib
317 TopTools_ListOfShape SliList;
318 SliList.Append(FirstFace);
320 if(Sliding) { // sliding
322 if (trc) cout << " Sliding" << endl;
324 Standard_Boolean Sliding = Standard_False;
325 Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
326 if (s->DynamicType() ==
327 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
328 s = Handle(Geom_RectangularTrimmedSurface)::
329 DownCast(s)->BasisSurface();
331 if(s->DynamicType() == STANDARD_TYPE(Geom_Plane) ||
332 s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
333 // if plane or cylinder : sliding is possible
334 Sliding = Standard_True;
338 // Control only start and end points
339 // -> no control at the middle - improve
340 // Controle between Surface and segment between 2 limit points
341 // is too expensive - improve
343 gp_Pnt p1(myFirstPnt.X()+myDir.X(),myFirstPnt.Y()+myDir.Y(),
344 myFirstPnt.Z()+myDir.Z());
345 BRepLib_MakeEdge ee1(myFirstPnt, p1);
346 BRepExtrema_ExtCF ext1(ee1, FirstFace);
347 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
348 gp_Pnt p2(myLastPnt.X()+myDir.X(),myLastPnt.Y()+myDir.Y(),
349 myLastPnt.Z()+myDir.Z());
350 BRepLib_MakeEdge ee2(myLastPnt, p2);
351 BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
352 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
353 Sliding = Standard_True;
356 Sliding = Standard_False;
360 Sliding = Standard_False;
364 if(!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) {
366 gp_Pnt p1(myFirstPnt.X()+myDir1.X(),myFirstPnt.Y()+myDir1.Y(),
367 myFirstPnt.Z()+myDir1.Z());
368 BRepLib_MakeEdge ee1(myFirstPnt, p1);
369 BRepExtrema_ExtCF ext1(ee1, FirstFace);
370 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
371 gp_Pnt p2(myLastPnt.X()+myDir1.X(),myLastPnt.Y()+myDir1.Y(),
372 myLastPnt.Z()+myDir1.Z());
373 BRepLib_MakeEdge ee2(myLastPnt, p2);
374 BRepExtrema_ExtCF ext2(ee2, LastFace);
375 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
376 Sliding = Standard_True;
379 Sliding = Standard_False;
383 Sliding = Standard_False;
389 // Construct a great profile that goes till the bounding box
390 // -> by tangency with the first and the last edge of the Wire
391 // -> by normals to the support faces : statistically better
392 // Intersect everything to find the final profile
395 // ---case of sliding : construction of the profile face
398 if (trc) cout << " still Sliding" << endl;
401 Standard_Boolean ProfileOK;
402 ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
403 FirstFace,LastFace,FirstVertex,LastVertex,
408 cout << "Not computable" << endl;
409 if (trc) cout << "Face profile not computable" << endl;
411 myStatusError = BRepFeat_NoFaceProf;
417 // ---Propagation on faces of the initial shape
418 // to find the faces concerned by the rib
419 Standard_Boolean falseside = Standard_True;
420 Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
421 // Control if there is everything required to have the material at the proper side
422 if(falseside == Standard_False) {
424 cout << "Verify plane and wire orientation" << endl;
426 myStatusError = BRepFeat_FalseSide;
433 // ---Generation of the base of the rib profile
437 TopoDS_Edge thePreviousEdge;
439 thePreviousEdge.Nullify();
441 // calculate the number of edges to fill the map
442 Standard_Integer counter = 1;
444 // ---case of sliding
445 if(Sliding && !myListOfEdges.IsEmpty()) {
446 BRepTools_WireExplorer EX1(myWire);
447 for(; EX1.More(); EX1.Next()) {
448 const TopoDS_Edge& E = EX1.Current();
449 if(!myLFMap.IsBound(E)) {
450 TopTools_ListOfShape theTmpList;
451 myLFMap.Bind(E, theTmpList );
453 if(E.IsSame(FirstEdge)) {
455 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
456 cc = new Geom_TrimmedCurve(cc, f, l);
458 if(!FirstEdge.IsSame(LastEdge)) {
459 pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
463 Standard_Real fpar = IntPar(cc, myFirstPnt);
464 Standard_Real lpar = IntPar(cc, pt);
465 Handle(Geom_Curve) ccc;
467 ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
472 if(thePreviousEdge.IsNull()) {
473 BRepLib_MakeVertex v1(myFirstPnt);
474 BRepLib_MakeVertex v2(pt);
475 BRepLib_MakeEdge e(cc, v1, v2);
476 ee1 = TopoDS::Edge(e.Shape());
479 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
480 BRepLib_MakeVertex v2(pt);
482 BRepLib_MakeEdge e(cc, v1, v2);
483 ee1 = TopoDS::Edge(e.Shape());
485 TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
486 ee1 = TopoDS::Edge(aLocalShape);
487 // ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
488 if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
489 myLFMap(E).Append(ee1);
491 thePreviousEdge = ee1;
498 // Case of several edges
499 if(!FirstEdge.IsSame(LastEdge)) {
500 for(; EX1.More(); EX1.Next()) {
501 const TopoDS_Edge& E = EX1.Current();
502 if(!myLFMap.IsBound(E)) {
503 TopTools_ListOfShape thelist1;
504 myLFMap.Bind(E, thelist1);
508 if(!E.IsSame(LastEdge)) {
509 Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
510 TopoDS_Vertex v1, v2;
511 if(!thePreviousEdge.IsNull()) {
512 v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
513 v2 = TopExp::LastVertex(E,Standard_True);
516 // v1 = TopExp::LastVertex(E,Standard_True);
517 v1 = TopExp::FirstVertex(E,Standard_True);
518 v2 = TopExp::LastVertex(E,Standard_True);
520 BRepLib_MakeEdge E1(ccc, v1, v2);
521 TopoDS_Edge E11 = TopoDS::Edge(E1.Shape());
522 TopoDS_Shape aLocalShape = E11.Oriented(E.Orientation());
523 E11 = TopoDS::Edge(aLocalShape);
524 // E11 = TopoDS::Edge(E11.Oriented(E.Orientation()));
525 thePreviousEdge = E11;
526 myLFMap(E).Append(E11);
528 if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
533 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
534 gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
535 gp_Pnt pl = myLastPnt;
537 if(thePreviousEdge.IsNull()) {
538 BRepLib_MakeEdge e(cc, pf , pl);
539 ee = TopoDS::Edge(e.Shape());
542 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
543 BRepLib_MakeVertex v2(pl);
544 BRepLib_MakeEdge e(cc, v1, v2);
545 ee = TopoDS::Edge(e.Shape());
547 TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
548 ee = TopoDS::Edge(aLocalShape);
549 // ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
551 myLFMap(E).Append(ee);
552 if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
553 thePreviousEdge = ee;
560 TopTools_ListIteratorOfListOfShape it(myListOfEdges);
561 Standard_Boolean FirstOK = Standard_False;
562 Standard_Boolean LastOK = Standard_False;
564 gp_Pnt theLastPnt = myLastPnt;
565 Standard_Integer sens = 0;
566 TopoDS_Edge theEdge, theLEdge, theFEdge;
567 Standard_Integer counter1 = counter;
568 TopTools_ListOfShape NewListOfEdges;
569 NewListOfEdges.Clear();
571 const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
574 Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
575 Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
576 if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
578 fp = cc->Value(cc->FirstParameter());
579 lp = cc->Value(cc->LastParameter());
580 Standard_Real dist = fp.Distance(theLastPnt);
583 LastOK = Standard_True;
586 dist = lp.Distance(theLastPnt);
589 LastOK = Standard_True;
593 Standard_Integer FirstFlag = 0;
594 if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
595 FirstOK = Standard_True;
598 else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
599 FirstOK = Standard_True;
605 Standard_Real fpar = cc->FirstParameter();
606 Standard_Real lpar = cc->LastParameter();
608 if(thePreviousEdge.IsNull()) {
609 BRepLib_MakeEdge e(cc, fpar, lpar);
610 eeee = TopoDS::Edge(e.Shape());
613 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
614 BB.UpdateVertex(v1, dist);
615 BRepLib_MakeVertex v2(cc->Value(lpar));
616 TopoDS_Vertex nv=v2.Vertex();
617 BRepLib_MakeEdge e(cc, v1, nv);
618 eeee = TopoDS::Edge(e.Shape());
622 if(thePreviousEdge.IsNull()) {
623 BRepLib_MakeVertex v1(cc->Value(fpar));
624 BRepLib_MakeEdge e(cc, v1, theFV);
625 eeee = TopoDS::Edge(e.Shape());
628 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
629 BRepLib_MakeEdge e(cc, v1, theFV);
630 eeee = TopoDS::Edge(e.Shape());
634 thePreviousEdge = eeee;
636 if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
638 NewListOfEdges.Append(edg);
643 theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
649 else if(FirstFlag == 2) {
654 myListOfEdges.Remove(it);
655 it.Initialize(myListOfEdges);
656 LastOK = Standard_False;
658 else if(it.More()) it.Next();
660 Sliding = Standard_False;
667 TopTools_DataMapOfShapeListOfShape SlidMap;
670 if(Sliding && counter1 > counter) {
671 TopTools_ListIteratorOfListOfShape it;
672 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
673 TopExp_Explorer EX2(w, TopAbs_EDGE);
674 Standard_Integer ii = 0;
675 for(; EX2.More(); EX2.Next()) {
676 const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
678 if(ii >= counter && ii <= counter1) {
679 it.Initialize(NewListOfEdges);
680 Standard_Integer jj = 0;
681 for(; it.More(); it.Next()) {
682 const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
684 if(jj== (ii - counter +1)) {
685 itm.Initialize(mySlface);
686 for(; itm.More(); itm.Next()) {
687 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
688 const TopTools_ListOfShape& ledg = itm.Value();
689 TopTools_ListIteratorOfListOfShape itedg(ledg);
690 //Standard_Integer iiii = 0;
691 for(; itedg.More(); itedg.Next()) {
692 const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
694 if(!SlidMap.IsBound(fac)) {
695 TopTools_ListOfShape thelist2;
696 SlidMap.Bind(fac, thelist2);
698 SlidMap(fac).Append(E);
712 // ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
715 BB.MakeFace(F, myPln, myTol);
717 // BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
724 // ---Case without sliding : construction of the profile face
728 if (Modify) cout << " Sliding failure" << endl;
729 cout << " no Sliding" << endl;
733 Standard_Boolean ProfileOK;
734 ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
735 bnd,BndFace,CheckPnt,
736 FirstFace,LastFace,FirstVertex,LastVertex,
737 FirstEdge,LastEdge,OnFirstFace,OnLastFace);
741 cout << "Not computable" << endl;
742 if (trc) cout << " Face profile not computable" << endl;
744 myStatusError = BRepFeat_NoFaceProf;
750 // ---Propagation on faces of the initial shape
751 // to find the faces concerned by the rib
752 Standard_Boolean falseside = Standard_True;
753 Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
754 // Control if there is everything required to have the material at the proper side
755 if(falseside == Standard_False) {
757 cout << "Verify plane and wire orientation" << endl;
759 myStatusError = BRepFeat_FalseSide;
766 TopTools_ListIteratorOfListOfShape it;
767 it.Initialize(SliList);
772 BB.MakeShell(TopoDS::Shell(comp));
774 for(; it.More(); it.Next()) {
775 BB.Add(comp, it.Value());
787 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
788 TopTools_ListOfShape thelist3;
789 myMap.Bind(exp.Current(), thelist3);
790 myMap(exp.Current()).Append(exp.Current());
795 //=======================================================================
797 //purpose : add des element de collage
798 //=======================================================================
800 void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E,
801 const TopoDS_Face& F)
804 Standard_Boolean trc = BRepFeat_GettraceFEAT();
805 if (trc) cout << "BRepFeat_MakeLinearForm::Add" << endl;
807 if(mySlface.IsEmpty()) {
809 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
810 if (exp.Current().IsSame(F)) {
815 Standard_ConstructionError::Raise();
818 if (!mySlface.IsBound(F)) {
819 TopTools_ListOfShape thelist;
820 mySlface.Bind(F, thelist);
822 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
823 for (; itl.More();itl.Next()) {
824 if (itl.Value().IsSame(E)) {
829 mySlface(F).Append(E);
836 //=======================================================================
838 //purpose : construction of rib from a profile and the initial shape
839 //=======================================================================
841 void BRepFeat_MakeLinearForm::Perform()
844 Standard_Boolean trc = BRepFeat_GettraceFEAT();
845 if (trc) cout << "BRepFeat_MakeLinearForm::Perform()" << endl;
847 if(mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull()) {
849 if (trc) cout << " Fields not initialized" << endl;
851 myStatusError = BRepFeat_NotInitialized;
856 gp_Vec nulldir(0, 0, 0);
858 Standard_Real Length = myDir.Magnitude() + myDir1.Magnitude();
862 if(!mySUntil.IsNull())
863 myPerfSelection = BRepFeat_SelectionU;
865 myPerfSelection = BRepFeat_NoSelection;
868 gp_Vec V = Length*dir;
870 LocOpe_LinearForm theForm;
872 if(myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
873 theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
875 theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
877 TopoDS_Shape VraiForm = theForm.Shape(); // primitive of the rib
879 myFacesForDraft.Append(theForm.FirstShape());
880 myFacesForDraft.Append(theForm.LastShape());
881 MajMap(myPbase,theForm,myMap,myFShape,myLShape); // management of descendants
883 TopExp_Explorer exx(myPbase, TopAbs_EDGE);
884 for(; exx.More(); exx.Next()) {
885 const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
886 if(!myMap.IsBound(e)) {
888 if (trc) cout << " Sliding face not in Base shape" << endl;
890 myStatusError = BRepFeat_IncSlidFace;
897 SetGluedFaces(mySlface, theForm, myGluedF); // management of sliding faces
899 if(!myGluedF.IsEmpty() && !mySUntil.IsNull()) {
901 cout << "The case is not computable" << endl;
902 if (trc) cout << " Glued faces not empty and Until shape not null" << endl;
904 myStatusError = BRepFeat_InvShape;
913 TopExp_Explorer expr(mySbase, TopAbs_FACE);
914 char nom1[20], nom2[20];
915 Standard_Integer ii = 0;
916 for(; expr.More(); expr.Next()) {
918 sprintf(nom1, "faceinitial_%d", ii);
919 DBRep::Set(nom1, expr.Current());
920 Standard_Integer jj = 0;
921 const TopTools_ListOfShape& list = Modified(expr.Current());
922 TopTools_ListIteratorOfListOfShape ite(list);
923 for(; ite.More(); ite.Next()) {
925 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
926 DBRep::Set(nom2, ite.Value());
930 expr.Init(myWire, TopAbs_EDGE);
932 for(; expr.More(); expr.Next()) {
934 sprintf(nom1, "edgeinitial_%d", ii);
935 DBRep::Set(nom1, expr.Current());
936 Standard_Integer jj = 0;
937 const TopTools_ListOfShape& genf = Generated(expr.Current());
938 TopTools_ListIteratorOfListOfShape ite(genf);
939 for(; ite.More(); ite.Next()) {
941 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
942 DBRep::Set(nom2, ite.Value());
948 //=======================================================================
949 //function : Propagate
950 //purpose : propagation on faces of the initial shape, find
951 // faces concerned by the rib
952 //=======================================================================
953 Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
954 const TopoDS_Face& fac,
955 const gp_Pnt& Firstpnt,
956 const gp_Pnt& Lastpnt,
957 Standard_Boolean& falseside)
960 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
961 if (trc) cout << "BRepFeat_MakeLinearForm::Propagate" << endl;
963 gp_Pnt Firstpoint = Firstpnt;
964 gp_Pnt Lastpoint = Lastpnt;
966 Standard_Boolean result = Standard_True;
967 TopoDS_Face CurrentFace, saveFace;
968 CurrentFace = TopoDS::Face(SliList.First());
969 saveFace = CurrentFace;
971 Standard_Boolean LastOK = Standard_False, FirstOK= Standard_False;
972 Standard_Boolean v1OK = Standard_False, v2OK= Standard_False;
973 TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
975 //modified by NIZNHY-PKV Fri Mar 22 16:50:24 2002 f
976 //BRepAlgo_Section sect (fac, CurrentFace, Standard_False);
977 BRepAlgoAPI_Section sect (fac, CurrentFace, Standard_False);
978 //modified by NIZNHY-PKV Fri Mar 22 16:50:32 2002 t
980 sect.Approximation(Standard_True);
986 Standard_Real t1 = 0., t2 = 0.;
987 Standard_Boolean c1f, c2f, c1l, c2l;
989 for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
990 ec = TopoDS::Edge(Ex.Current());
991 v1 = TopExp::FirstVertex(ec,Standard_True);
992 v2 = TopExp::LastVertex(ec,Standard_True);
993 p1 = BRep_Tool::Pnt(v1);
994 p2 = BRep_Tool::Pnt(v2);
995 t1 = BRep_Tool::Tolerance(v1);
996 t2 = BRep_Tool::Tolerance(v2);
997 c1f = p1.Distance(Firstpoint)<=t1;
998 c2f = p2.Distance(Firstpoint)<=t2;
999 c1l = p1.Distance(Lastpoint)<=t1;
1000 c2l = p2.Distance(Lastpoint)<=t2;
1001 if (c1f || c2f || c1l|| c2l) {
1003 if (c1f || c1l) v1OK=Standard_True;
1004 if (c2f || c2l) v2OK=Standard_True;
1005 if (c1f || c2f) FirstOK=Standard_True;
1006 if (c1l || c2l) LastOK=Standard_True;
1012 falseside = Standard_False;
1013 return Standard_False;
1015 TopTools_ListOfShape thelist;
1016 mySlface.Bind(CurrentFace, thelist);
1017 mySlface(CurrentFace).Append(eb);
1019 myListOfEdges.Clear();
1020 myListOfEdges.Append(eb);
1022 // two points are on the same face.
1023 if(LastOK && FirstOK) {
1027 TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1028 TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1030 TopoDS_Edge FirstEdge;
1033 TopoDS_Vertex Vprevious;
1035 Standard_Real tvp, dp;
1037 while (!(LastOK && FirstOK)) {
1049 // find edge connected to v1 or v2:
1050 for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next()) {
1051 const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1053 BRepExtrema_ExtPC projF(Vprevious, rfe);
1055 if(projF.IsDone() && projF.NbExt() >=1) {
1056 Standard_Real dist2min = RealLast();
1057 Standard_Integer index = 0;
1058 for (Standard_Integer sol =1 ; sol <= projF.NbExt(); sol++) {
1059 if (projF.SquareDistance(sol) <= dist2min) {
1061 dist2min = projF.SquareDistance(sol);
1065 if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe)) {
1067 // If the edge is not perpendicular to the plane of the rib
1068 // it is required to set Sliding(result) to false.
1070 result=Standard_False;
1071 ve1 = TopExp::FirstVertex(rfe,Standard_True);
1072 ve2 = TopExp::LastVertex(rfe,Standard_True);
1073 BRepExtrema_ExtPF perp(ve1, fac);
1074 if (perp.IsDone()) {
1075 gp_Pnt pe1=perp.Point(1);
1076 perp.Perform(ve2, fac);
1077 if (perp.IsDone()) {
1078 gp_Pnt pe2=perp.Point(1);
1079 if (pe1.Distance(pe2)<=BRep_Tool::Tolerance(rfe))
1080 result=Standard_True;
1090 const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1091 TopTools_ListIteratorOfListOfShape It(L);
1093 for (; It.More(); It.Next()) {
1094 const TopoDS_Face& FF = TopoDS::Face(It.Value());
1095 if (!FF.IsSame(CurrentFace)) {
1101 //modified by NIZNHY-PKV Fri Mar 22 16:50:53 2002 f
1102 //BRepAlgo_Section sectf (fac, CurrentFace, Standard_False);
1103 BRepAlgoAPI_Section sectf (fac, CurrentFace, Standard_False);
1104 //modified by NIZNHY-PKV Fri Mar 22 16:51:03 2002 t
1105 sectf.Approximation(Standard_True);
1109 for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
1110 edg1 = TopoDS::Edge(Ex.Current());
1111 v1=TopExp::FirstVertex(edg1,Standard_True);
1112 v2=TopExp::LastVertex(edg1,Standard_True);
1113 t1 = BRep_Tool::Tolerance(v1);
1114 t2 = BRep_Tool::Tolerance(v2);
1115 p1 = BRep_Tool::Pnt(v1);
1116 p2 = BRep_Tool::Pnt(v2);
1117 v1OK = p1.Distance(ptprev)<=t1;
1118 v2OK = p2.Distance(ptprev)<=t2;
1119 if (v1OK || v2OK) break;
1124 dp = p2.Distance(Firstpoint);
1126 FirstOK = Standard_True;
1127 BB.UpdateVertex(v2, dp);
1131 dp = p2.Distance(Lastpoint);
1133 LastOK = Standard_True;
1134 BB.UpdateVertex(v2, dp);
1140 dp = p1.Distance(Firstpoint);
1142 FirstOK = Standard_True;
1143 BB.UpdateVertex(v1, dp);
1147 dp = p1.Distance(Lastpoint);
1149 LastOK = Standard_True;
1150 BB.UpdateVertex(v1, dp);
1155 // end by chaining the section
1156 return Standard_False;
1158 TopTools_ListOfShape thelist1;
1159 mySlface.Bind(CurrentFace, thelist1);
1160 mySlface(CurrentFace).Append(edg1);
1161 myListOfEdges.Append(edg1);
1168 //=======================================================================
1170 //purpose : management of descendants
1171 //=======================================================================
1173 static void MajMap(const TopoDS_Shape& theB,
1174 const LocOpe_LinearForm& theP,
1175 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1176 TopoDS_Shape& theFShape, // myFShape
1177 TopoDS_Shape& theLShape) // myLShape
1179 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1181 theFShape = exp.Current();
1182 TopTools_ListOfShape thelist;
1183 theMap.Bind(theFShape, thelist);
1184 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1185 theMap(theFShape).Append(exp.Current());
1189 exp.Init(theP.LastShape(),TopAbs_WIRE);
1191 theLShape = exp.Current();
1192 TopTools_ListOfShape thelist1;
1193 theMap.Bind(theLShape, thelist1);
1194 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1195 theMap(theLShape).Append(exp.Current());
1199 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1200 if (!theMap.IsBound(exp.Current())) {
1202 const TopoDS_Edge& e =
1204 TopoDS::Edge(exp.Current());
1205 TopTools_ListOfShape thelist2;
1206 theMap.Bind(exp.Current(), thelist2);
1207 theMap(exp.Current()) = theP.Shapes(exp.Current());
1212 //=======================================================================
1213 //function : SetGluedFaces
1214 //purpose : management of faces of gluing
1215 //=======================================================================
1217 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1218 LocOpe_LinearForm& thePrism,
1219 TopTools_DataMapOfShapeShape& theMap)
1222 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1223 if(!theSlmap.IsEmpty()) {
1224 for (; itm.More(); itm.Next()) {
1225 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1226 const TopTools_ListOfShape& ledg = itm.Value();
1227 TopTools_ListIteratorOfListOfShape it;
1228 for (it.Initialize(ledg); it.More(); it.Next()) {
1229 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1230 if (gfac.Extent() != 1) {
1232 cout << "Pb SetGluedFace" << endl;
1235 theMap.Bind(gfac.First(),fac);