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_Builder.hxx>
29 #include <LocOpe_LinearForm.hxx>
30 #include <LocOpe_Gluer.hxx>
31 #include <LocOpe_FindEdges.hxx>
39 #include <gp_Vec2d.hxx>
40 #include <gp_Pnt2d.hxx>
42 #include <Geom_Curve.hxx>
44 #include <Geom2d_Curve.hxx>
45 #include <Geom2d_Line.hxx>
47 #include <Geom_Plane.hxx>
48 #include <Geom_Surface.hxx>
49 #include <Geom_CylindricalSurface.hxx>
50 #include <Geom_RectangularTrimmedSurface.hxx>
52 #include <Geom_TrimmedCurve.hxx>
53 #include <GeomProjLib.hxx>
55 #include <Geom2d_Curve.hxx>
56 #include <Geom2d_Curve.hxx>
58 #include <TColgp_SequenceOfPnt.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <IntRes2d_IntersectionPoint.hxx>
63 #include <BRepTools_WireExplorer.hxx>
65 #include <BRep_Tool.hxx>
66 #include <BRep_Builder.hxx>
68 #include <TopExp_Explorer.hxx>
71 #include <TopTools_MapOfShape.hxx>
72 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
73 #include <TopTools_ListOfShape.hxx>
74 #include <TopTools_ListIteratorOfListOfShape.hxx>
75 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
76 #include <TopTools_MapIteratorOfMapOfShape.hxx>
77 #include <TopOpeBRepBuild_HBuilder.hxx>
78 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
80 #include <TColgp_Array1OfPnt.hxx>
82 #include <TColGeom_Array1OfCurve.hxx>
85 #include <TopoDS_Shape.hxx>
86 #include <TopoDS_Face.hxx>
88 #include <BRepLib_MakeVertex.hxx>
89 #include <BRepLib_MakeEdge.hxx>
90 #include <BRepLib_MakeFace.hxx>
92 #include <BRepTools.hxx>
94 #include <BRepBuilderAPI.hxx>
95 #include <BRepPrimAPI_MakeBox.hxx>
96 #include <BRepBuilderAPI_MakeFace.hxx>
98 //modified by NIZNHY-PKV Fri Mar 22 16:51:33 2002 f
99 //#include <BRepAlgo_Section.hxx>
100 //#include <BRepAlgo_Common.hxx>
101 #include <BRepAlgoAPI_Section.hxx>
102 #include <BRepAlgoAPI_Common.hxx>
103 //modified by NIZNHY-PKV Fri Mar 22 16:51:35 2002 t
105 #include <BRepExtrema_ExtPC.hxx>
106 #include <BRepExtrema_ExtPF.hxx>
107 #include <BRepExtrema_ExtCF.hxx>
109 #include <BRepTools_Modifier.hxx>
110 #include <BRepTools_TrsfModification.hxx>
112 #include <Standard_ConstructionError.hxx>
114 #include <Precision.hxx>
116 #include <GeomLProp_CLProps.hxx>
118 #include <BRepBuilderAPI_Transform.hxx>
119 #include <BRepLib_MakeWire.hxx>
120 //#include <DbgTools.hxx>
123 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
124 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEATRIB();
127 static void MajMap(const TopoDS_Shape&, // base
128 const LocOpe_LinearForm&,
129 TopTools_DataMapOfShapeListOfShape&, // myMap
130 TopoDS_Shape&, // myFShape
131 TopoDS_Shape&); // myLShape
133 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
135 TopTools_DataMapOfShapeShape&);
137 //=======================================================================
140 //=======================================================================
142 void BRepFeat_MakeLinearForm::Init(const TopoDS_Shape& Sbase,
143 const TopoDS_Wire& W,
144 const Handle(Geom_Plane)& Plane,
146 const gp_Vec& Direc1,
147 const Standard_Integer Mode,
148 const Standard_Boolean Modify)
151 Standard_Boolean trc = BRepFeat_GettraceFEAT();
152 if (trc) cout << "BRepFeat_MakeLinearForm::Init" << endl;
154 Standard_Boolean RevolRib = Standard_False;
158 // modify = 0 if there is no intention to make sliding
159 // = 1 if one tries to make sliding
160 Standard_Boolean Sliding = Modify;
173 myListOfEdges.Clear();
176 TopoDS_Shape aLocalShape = W.Oriented(TopAbs_FORWARD);
177 myWire = TopoDS::Wire(aLocalShape);
178 // myWire = TopoDS::Wire(W.Oriented(TopAbs_FORWARD));
184 myFuse = Standard_False;
185 else // if(Mode == 1)
186 myFuse = Standard_True;
189 if (myFuse) cout << " Fuse" << endl;
190 if (!myFuse) cout << " Cut" << endl;
195 // ---Determine Tolerance : max tolerance on parameters
196 myTol = Precision::Confusion();
199 exx.Init(myWire, TopAbs_VERTEX);
200 for(; exx.More(); exx.Next()) {
201 const Standard_Real& tol = BRep_Tool::
202 Tolerance(TopoDS::Vertex(exx.Current()));
203 if(tol > myTol) myTol = tol;
206 exx.Init(Sbase, TopAbs_VERTEX);
207 for(; exx.More(); exx.Next()) {
208 const Standard_Real& tol = BRep_Tool::
209 Tolerance(TopoDS::Vertex(exx.Current()));
210 if(tol > myTol) myTol = tol;
213 // ---Control of directions
214 // the wire should be in the rib
215 gp_Vec nulldir(0, 0, 0);
216 if(!myDir1.IsEqual(nulldir, myTol, myTol)) {
217 Standard_Real ang = myDir1.Angle(myDir);
220 if (trc) cout << " Directions must be opposite" << endl;
222 myStatusError = BRepFeat_BadDirect;
229 // Rib is centre in the middle of translation
231 if (trc) cout << " Rib is centre" << endl;
233 const gp_Vec& DirTranslation = (Direc + Direc1) * 0.5;
235 T.SetTranslation(DirTranslation);
236 BRepBuilderAPI_Transform trf(T);
238 myWire = TopoDS::Wire(trf.Shape());
239 myDir = Direc - DirTranslation;
240 myDir1 = Direc1 - DirTranslation;
244 // ---Calculate bounding box
247 TopTools_ListOfShape theList;
251 gp_Pnt FirstCorner, LastCorner;
252 Standard_Real bnd = HeightMax(mySbase, U, FirstCorner, LastCorner);
255 BRepPrimAPI_MakeBox Bndbox(FirstCorner, LastCorner);
256 TopoDS_Solid BndBox = Bndbox.Solid();
259 // ---Construction of the face workplane (section bounding box)
260 BRepLib_MakeFace PlaneF(myPln->Pln(), -6.*myBnd,
261 6.*myBnd, -6.*myBnd, 6.*myBnd);
262 TopoDS_Face PlaneFace = TopoDS::Face(PlaneF.Shape());
264 //modified by NIZNHY-PKV Fri Mar 22 16:49:28 2002 f
265 //BRepAlgo_Common PlaneS(BndBox, PlaneFace);
266 BRepAlgoAPI_Common PlaneS(BndBox, PlaneFace);
267 //modified by NIZNHY-PKV Fri Mar 22 16:49:39 2002 t
269 TopoDS_Shape PlaneSect = PlaneS.Shape();
270 EXP.Init(PlaneSect, TopAbs_WIRE);
271 TopoDS_Wire www = TopoDS::Wire(EXP.Current());
272 BRepLib_MakeFace Bndface(myPln->Pln(), www, Standard_True);
273 TopoDS_Face BndFace = TopoDS::Face(Bndface.Shape());
276 // ---Find support faces of the rib
277 TopoDS_Edge FirstEdge, LastEdge;
278 TopoDS_Face FirstFace, LastFace;
279 TopoDS_Vertex FirstVertex, LastVertex;
281 Standard_Boolean OnFirstFace = Standard_False;
282 Standard_Boolean OnLastFace = Standard_False;
283 Standard_Boolean PtOnFirstEdge = Standard_False;
284 Standard_Boolean PtOnLastEdge = Standard_False;
285 TopoDS_Edge OnFirstEdge, OnLastEdge;
286 OnFirstEdge.Nullify();
287 OnLastEdge.Nullify();
289 Standard_Boolean Data = ExtremeFaces(RevolRib, myBnd, myPln, FirstEdge, LastEdge,
290 FirstFace, LastFace, FirstVertex,
291 LastVertex, OnFirstFace, OnLastFace,
292 PtOnFirstEdge, PtOnLastEdge,
293 OnFirstEdge, OnLastEdge);
297 if (trc) cout << " No Extreme faces" << endl;
299 myStatusError = BRepFeat_NoExtFace;
305 // ---Proofing Point for the side of the wire to be filled - side material
306 gp_Pnt CheckPnt = CheckPoint(FirstEdge, bnd/10., myPln);
308 // Standard_Real f, l;
310 // ---Control sliding valuable
311 // Many cases when the sliding is abandoned
312 Standard_Integer Concavite = 3; // a priori the profile is not concave
314 myFirstPnt = BRep_Tool::Pnt(FirstVertex);
315 myLastPnt = BRep_Tool::Pnt(LastVertex);
317 // SliList : list of faces concerned by the rib
318 TopTools_ListOfShape SliList;
319 SliList.Append(FirstFace);
321 if(Sliding) { // sliding
323 if (trc) cout << " Sliding" << endl;
325 Standard_Boolean Sliding = Standard_False;
326 Handle(Geom_Surface) s = BRep_Tool::Surface(FirstFace);
327 if (s->DynamicType() ==
328 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
329 s = Handle(Geom_RectangularTrimmedSurface)::
330 DownCast(s)->BasisSurface();
332 if(s->DynamicType() == STANDARD_TYPE(Geom_Plane) ||
333 s->DynamicType() == STANDARD_TYPE(Geom_CylindricalSurface)) {
334 // if plane or cylinder : sliding is possible
335 Sliding = Standard_True;
339 // Control only start and end points
340 // -> no control at the middle - improve
341 // Controle between Surface and segment between 2 limit points
342 // is too expensive - improve
344 gp_Pnt p1(myFirstPnt.X()+myDir.X(),myFirstPnt.Y()+myDir.Y(),
345 myFirstPnt.Z()+myDir.Z());
346 BRepLib_MakeEdge ee1(myFirstPnt, p1);
347 BRepExtrema_ExtCF ext1(ee1, FirstFace);
348 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
349 gp_Pnt p2(myLastPnt.X()+myDir.X(),myLastPnt.Y()+myDir.Y(),
350 myLastPnt.Z()+myDir.Z());
351 BRepLib_MakeEdge ee2(myLastPnt, p2);
352 BRepExtrema_ExtCF ext2(ee2, LastFace); // ExtCF : curves and surfaces
353 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
354 Sliding = Standard_True;
357 Sliding = Standard_False;
361 Sliding = Standard_False;
365 if(!myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion())) {
367 gp_Pnt p1(myFirstPnt.X()+myDir1.X(),myFirstPnt.Y()+myDir1.Y(),
368 myFirstPnt.Z()+myDir1.Z());
369 BRepLib_MakeEdge ee1(myFirstPnt, p1);
370 BRepExtrema_ExtCF ext1(ee1, FirstFace);
371 if(ext1.NbExt() == 1 && ext1.SquareDistance(1)<=BRep_Tool::Tolerance(FirstFace) * BRep_Tool::Tolerance(FirstFace)) {
372 gp_Pnt p2(myLastPnt.X()+myDir1.X(),myLastPnt.Y()+myDir1.Y(),
373 myLastPnt.Z()+myDir1.Z());
374 BRepLib_MakeEdge ee2(myLastPnt, p2);
375 BRepExtrema_ExtCF ext2(ee2, LastFace);
376 if(ext2.NbExt() == 1 && ext2.SquareDistance(1)<=BRep_Tool::Tolerance(LastFace) * BRep_Tool::Tolerance(LastFace)) {
377 Sliding = Standard_True;
380 Sliding = Standard_False;
384 Sliding = Standard_False;
390 // Construct a great profile that goes till the bounding box
391 // -> by tangency with the first and the last edge of the Wire
392 // -> by normals to the support faces : statistically better
393 // Intersect everything to find the final profile
396 // ---case of sliding : construction of the profile face
399 if (trc) cout << " still Sliding" << endl;
402 Standard_Boolean ProfileOK;
403 ProfileOK = SlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,BndFace,CheckPnt,
404 FirstFace,LastFace,FirstVertex,LastVertex,
409 cout << "Not computable" << endl;
410 if (trc) cout << "Face profile not computable" << endl;
412 myStatusError = BRepFeat_NoFaceProf;
418 // ---Propagation on faces of the initial shape
419 // to find the faces concerned by the rib
420 Standard_Boolean falseside = Standard_True;
421 Sliding = Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
422 // Control if there is everything required to have the material at the proper side
423 if(falseside == Standard_False) {
425 cout << "Verify plane and wire orientation" << endl;
427 myStatusError = BRepFeat_FalseSide;
434 // ---Generation of the base of the rib profile
438 TopoDS_Edge thePreviousEdge;
440 thePreviousEdge.Nullify();
442 // calculate the number of edges to fill the map
443 Standard_Integer counter = 1;
445 // ---case of sliding
446 if(Sliding && !myListOfEdges.IsEmpty()) {
447 BRepTools_WireExplorer EX1(myWire);
448 for(; EX1.More(); EX1.Next()) {
449 const TopoDS_Edge& E = EX1.Current();
450 if(!myLFMap.IsBound(E)) {
451 TopTools_ListOfShape theTmpList;
452 myLFMap.Bind(E, theTmpList );
454 if(E.IsSame(FirstEdge)) {
456 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
457 cc = new Geom_TrimmedCurve(cc, f, l);
459 if(!FirstEdge.IsSame(LastEdge)) {
460 pt = BRep_Tool::Pnt(TopExp::LastVertex(E,Standard_True));
464 Standard_Real fpar = IntPar(cc, myFirstPnt);
465 Standard_Real lpar = IntPar(cc, pt);
466 Handle(Geom_Curve) ccc;
468 ccc = Handle(Geom_Curve)::DownCast(cc->Reversed());
473 if(thePreviousEdge.IsNull()) {
474 BRepLib_MakeVertex v1(myFirstPnt);
475 BRepLib_MakeVertex v2(pt);
476 BRepLib_MakeEdge e(cc, v1, v2);
477 ee1 = TopoDS::Edge(e.Shape());
480 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
481 BRepLib_MakeVertex v2(pt);
483 BRepLib_MakeEdge e(cc, v1, v2);
484 ee1 = TopoDS::Edge(e.Shape());
486 TopoDS_Shape aLocalShape = ee1.Oriented(E.Orientation());
487 ee1 = TopoDS::Edge(aLocalShape);
488 // ee1 = TopoDS::Edge(ee1.Oriented(E.Orientation()));
489 if(counter == 1) theFV = TopExp::FirstVertex(ee1,Standard_True);
490 myLFMap(E).Append(ee1);
492 thePreviousEdge = ee1;
499 // Case of several edges
500 if(!FirstEdge.IsSame(LastEdge)) {
501 for(; EX1.More(); EX1.Next()) {
502 const TopoDS_Edge& E = EX1.Current();
503 if(!myLFMap.IsBound(E)) {
504 TopTools_ListOfShape thelist1;
505 myLFMap.Bind(E, thelist1);
509 if(!E.IsSame(LastEdge)) {
510 Handle(Geom_Curve) ccc = BRep_Tool::Curve(E, f, l);
511 TopoDS_Vertex v1, v2;
512 if(!thePreviousEdge.IsNull()) {
513 v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
514 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);
529 if(counter == 1) theFV = TopExp::FirstVertex(E11,Standard_True);
534 Handle(Geom_Curve) cc = BRep_Tool::Curve(E, f, l);
535 gp_Pnt pf = BRep_Tool::Pnt(TopExp::FirstVertex(E,Standard_True));
536 gp_Pnt pl = myLastPnt;
538 if(thePreviousEdge.IsNull()) {
539 BRepLib_MakeEdge e(cc, pf , pl);
540 ee = TopoDS::Edge(e.Shape());
543 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
544 BRepLib_MakeVertex v2(pl);
545 BRepLib_MakeEdge e(cc, v1, v2);
546 ee = TopoDS::Edge(e.Shape());
548 TopoDS_Shape aLocalShape = ee.Oriented(E.Orientation());
549 ee = TopoDS::Edge(aLocalShape);
550 // ee = TopoDS::Edge(ee.Oriented(E.Orientation()));
552 myLFMap(E).Append(ee);
553 if(counter == 1) theFV = TopExp::FirstVertex(ee,Standard_True);
554 thePreviousEdge = ee;
561 TopTools_ListIteratorOfListOfShape it(myListOfEdges);
562 Standard_Boolean FirstOK = Standard_False;
563 Standard_Boolean LastOK = Standard_False;
565 gp_Pnt theLastPnt = myLastPnt;
566 Standard_Integer sens = 0;
567 TopoDS_Edge theEdge, theLEdge, theFEdge;
568 Standard_Integer counter1 = counter;
569 TopTools_ListOfShape NewListOfEdges;
570 NewListOfEdges.Clear();
572 const TopoDS_Edge& edg = TopoDS::Edge(it.Value());
575 Handle(Geom_Curve) ccc = BRep_Tool::Curve(edg, f, l);
576 Handle(Geom_TrimmedCurve) cc = new Geom_TrimmedCurve(ccc, f, l);
577 if ( edg.Orientation() == TopAbs_REVERSED) cc->Reverse();
579 fp = cc->Value(cc->FirstParameter());
580 lp = cc->Value(cc->LastParameter());
581 Standard_Real dist = fp.Distance(theLastPnt);
584 LastOK = Standard_True;
587 dist = lp.Distance(theLastPnt);
590 LastOK = Standard_True;
594 Standard_Integer FirstFlag = 0;
595 if(sens==1 && lp.Distance(myFirstPnt) <= myTol) {
596 FirstOK = Standard_True;
599 else if(sens==2 && fp.Distance(myFirstPnt) <= myTol) {
600 FirstOK = Standard_True;
606 Standard_Real fpar = cc->FirstParameter();
607 Standard_Real lpar = cc->LastParameter();
609 if(thePreviousEdge.IsNull()) {
610 BRepLib_MakeEdge e(cc, fpar, lpar);
611 eeee = TopoDS::Edge(e.Shape());
614 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
615 BB.UpdateVertex(v1, dist);
616 BRepLib_MakeVertex v2(cc->Value(lpar));
617 TopoDS_Vertex nv=v2.Vertex();
618 BRepLib_MakeEdge e(cc, v1, nv);
619 eeee = TopoDS::Edge(e.Shape());
623 if(thePreviousEdge.IsNull()) {
624 BRepLib_MakeVertex v1(cc->Value(fpar));
625 BRepLib_MakeEdge e(cc, v1, theFV);
626 eeee = TopoDS::Edge(e.Shape());
629 const TopoDS_Vertex& v1 = TopExp::LastVertex(thePreviousEdge,Standard_True);
630 BRepLib_MakeEdge e(cc, v1, theFV);
631 eeee = TopoDS::Edge(e.Shape());
635 thePreviousEdge = eeee;
637 if(counter == 1) theFV = TopExp::FirstVertex(eeee,Standard_True);
639 NewListOfEdges.Append(edg);
644 theLastPnt = BRep_Tool::Pnt(TopExp::LastVertex(theEdge,Standard_True));
650 else if(FirstFlag == 2) {
655 myListOfEdges.Remove(it);
656 it.Initialize(myListOfEdges);
657 LastOK = Standard_False;
659 else if(it.More()) it.Next();
661 Sliding = Standard_False;
668 TopTools_DataMapOfShapeListOfShape SlidMap;
671 if(Sliding && counter1 > counter) {
672 TopTools_ListIteratorOfListOfShape it;
673 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm;
674 TopExp_Explorer EX2(w, TopAbs_EDGE);
675 Standard_Integer ii = 0;
676 for(; EX2.More(); EX2.Next()) {
677 const TopoDS_Edge& E = TopoDS::Edge(EX2.Current());
679 if(ii >= counter && ii <= counter1) {
680 it.Initialize(NewListOfEdges);
681 Standard_Integer jj = 0;
682 for(; it.More(); it.Next()) {
683 const TopoDS_Edge& e2 = TopoDS::Edge(it.Value());
685 if(jj== (ii - counter +1)) {
686 itm.Initialize(mySlface);
687 for(; itm.More(); itm.Next()) {
688 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
689 const TopTools_ListOfShape& ledg = itm.Value();
690 TopTools_ListIteratorOfListOfShape itedg(ledg);
691 //Standard_Integer iiii = 0;
692 for(; itedg.More(); itedg.Next()) {
693 const TopoDS_Edge& e1 = TopoDS::Edge(itedg.Value());
695 if(!SlidMap.IsBound(fac)) {
696 TopTools_ListOfShape thelist2;
697 SlidMap.Bind(fac, thelist2);
699 SlidMap(fac).Append(E);
713 // ---Arguments of LocOpe_LinearForm : arguments of the prism sliding
716 BB.MakeFace(F, myPln, myTol);
718 // BRepLib_MakeFace F(myPln->Pln(),w, Standard_True);
725 // ---Case without sliding : construction of the profile face
729 if (Modify) cout << " Sliding failure" << endl;
730 cout << " no Sliding" << endl;
734 Standard_Boolean ProfileOK;
735 ProfileOK = NoSlidingProfile(Prof,RevolRib,myTol,Concavite,myPln,
736 bnd,BndFace,CheckPnt,
737 FirstFace,LastFace,FirstVertex,LastVertex,
738 FirstEdge,LastEdge,OnFirstFace,OnLastFace);
742 cout << "Not computable" << endl;
743 if (trc) cout << " Face profile not computable" << endl;
745 myStatusError = BRepFeat_NoFaceProf;
751 // ---Propagation on faces of the initial shape
752 // to find the faces concerned by the rib
753 Standard_Boolean falseside = Standard_True;
754 Propagate(SliList, Prof, myFirstPnt, myLastPnt, falseside);
755 // Control if there is everything required to have the material at the proper side
756 if(falseside == Standard_False) {
758 cout << "Verify plane and wire orientation" << endl;
760 myStatusError = BRepFeat_FalseSide;
767 TopTools_ListIteratorOfListOfShape it;
768 it.Initialize(SliList);
773 BB.MakeShell(TopoDS::Shell(comp));
775 for(; it.More(); it.Next()) {
776 BB.Add(comp, it.Value());
788 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
789 TopTools_ListOfShape thelist3;
790 myMap.Bind(exp.Current(), thelist3);
791 myMap(exp.Current()).Append(exp.Current());
796 //=======================================================================
798 //purpose : add des element de collage
799 //=======================================================================
801 void BRepFeat_MakeLinearForm::Add(const TopoDS_Edge& E,
802 const TopoDS_Face& F)
805 Standard_Boolean trc = BRepFeat_GettraceFEAT();
806 if (trc) cout << "BRepFeat_MakeLinearForm::Add" << endl;
808 if(mySlface.IsEmpty()) {
810 for (exp.Init(mySbase,TopAbs_FACE);exp.More();exp.Next()) {
811 if (exp.Current().IsSame(F)) {
816 Standard_ConstructionError::Raise();
819 if (!mySlface.IsBound(F)) {
820 TopTools_ListOfShape thelist;
821 mySlface.Bind(F, thelist);
823 TopTools_ListIteratorOfListOfShape itl(mySlface(F));
824 for (; itl.More();itl.Next()) {
825 if (itl.Value().IsSame(E)) {
830 mySlface(F).Append(E);
837 //=======================================================================
839 //purpose : construction of rib from a profile and the initial shape
840 //=======================================================================
842 void BRepFeat_MakeLinearForm::Perform()
845 Standard_Boolean trc = BRepFeat_GettraceFEAT();
846 if (trc) cout << "BRepFeat_MakeLinearForm::Perform()" << endl;
848 if(mySbase.IsNull() || mySkface.IsNull() || myPbase.IsNull()) {
850 if (trc) cout << " Fields not initialized" << endl;
852 myStatusError = BRepFeat_NotInitialized;
857 gp_Vec nulldir(0, 0, 0);
859 Standard_Real Length = myDir.Magnitude() + myDir1.Magnitude();
863 if(!mySUntil.IsNull())
864 myPerfSelection = BRepFeat_SelectionU;
866 myPerfSelection = BRepFeat_NoSelection;
869 gp_Vec V = Length*dir;
871 LocOpe_LinearForm theForm;
873 if(myDir1.IsEqual(nulldir, Precision::Confusion(), Precision::Confusion()))
874 theForm.Perform(myPbase, V, myFirstPnt, myLastPnt);
876 theForm.Perform(myPbase, V, myDir1, myFirstPnt, myLastPnt);
878 TopoDS_Shape VraiForm = theForm.Shape(); // primitive of the rib
880 myFacesForDraft.Append(theForm.FirstShape());
881 myFacesForDraft.Append(theForm.LastShape());
882 MajMap(myPbase,theForm,myMap,myFShape,myLShape); // management of descendants
884 TopExp_Explorer exx(myPbase, TopAbs_EDGE);
885 for(; exx.More(); exx.Next()) {
886 const TopoDS_Edge& e = TopoDS::Edge(exx.Current());
887 if(!myMap.IsBound(e)) {
889 if (trc) cout << " Sliding face not in Base shape" << endl;
891 myStatusError = BRepFeat_IncSlidFace;
898 SetGluedFaces(mySlface, theForm, myGluedF); // management of sliding faces
900 if(!myGluedF.IsEmpty() && !mySUntil.IsNull()) {
902 cout << "The case is not computable" << endl;
903 if (trc) cout << " Glued faces not empty and Until shape not null" << endl;
905 myStatusError = BRepFeat_InvShape;
914 TopExp_Explorer expr(mySbase, TopAbs_FACE);
915 char nom1[20], nom2[20];
916 Standard_Integer ii = 0;
917 for(; expr.More(); expr.Next()) {
919 sprintf(nom1, "faceinitial_%d", ii);
920 DBRep::Set(nom1, expr.Current());
921 Standard_Integer jj = 0;
922 const TopTools_ListOfShape& list = Modified(expr.Current());
923 TopTools_ListIteratorOfListOfShape ite(list);
924 for(; ite.More(); ite.Next()) {
926 sprintf(nom2, "facemodifie_%d_%d", ii, jj);
927 DBRep::Set(nom2, ite.Value());
931 expr.Init(myWire, TopAbs_EDGE);
933 for(; expr.More(); expr.Next()) {
935 sprintf(nom1, "edgeinitial_%d", ii);
936 DBRep::Set(nom1, expr.Current());
937 Standard_Integer jj = 0;
938 const TopTools_ListOfShape& genf = Generated(expr.Current());
939 TopTools_ListIteratorOfListOfShape ite(genf);
940 for(; ite.More(); ite.Next()) {
942 sprintf(nom2, "egdegeneree_%d_%d", ii, jj);
943 DBRep::Set(nom2, ite.Value());
949 //=======================================================================
950 //function : Propagate
951 //purpose : propagation on faces of the initial shape, find
952 // faces concerned by the rib
953 //=======================================================================
954 Standard_Boolean BRepFeat_MakeLinearForm::Propagate(TopTools_ListOfShape& SliList,
955 const TopoDS_Face& fac,
956 const gp_Pnt& Firstpnt,
957 const gp_Pnt& Lastpnt,
958 Standard_Boolean& falseside)
961 Standard_Boolean trc = BRepFeat_GettraceFEATRIB();
962 if (trc) cout << "BRepFeat_MakeLinearForm::Propagate" << endl;
964 gp_Pnt Firstpoint = Firstpnt;
965 gp_Pnt Lastpoint = Lastpnt;
967 Standard_Boolean result = Standard_True;
968 TopoDS_Face CurrentFace, saveFace;
969 CurrentFace = TopoDS::Face(SliList.First());
970 saveFace = CurrentFace;
972 Standard_Boolean LastOK = Standard_False, FirstOK= Standard_False;
973 Standard_Boolean v1OK = Standard_False, v2OK= Standard_False;
974 TopoDS_Vertex v1, v2, v3, v4, ve1, ve2;
976 //modified by NIZNHY-PKV Fri Mar 22 16:50:24 2002 f
977 //BRepAlgo_Section sect (fac, CurrentFace, Standard_False);
978 BRepAlgoAPI_Section sect (fac, CurrentFace, Standard_False);
979 //modified by NIZNHY-PKV Fri Mar 22 16:50:32 2002 t
981 sect.Approximation(Standard_True);
988 Standard_Real t1 = 0., t2 = 0.;
990 Standard_Real t1, t2;
992 Standard_Boolean c1f, c2f, c1l, c2l;
994 for (Ex.Init(sect.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
995 ec = TopoDS::Edge(Ex.Current());
996 v1 = TopExp::FirstVertex(ec,Standard_True);
997 v2 = TopExp::LastVertex(ec,Standard_True);
998 p1 = BRep_Tool::Pnt(v1);
999 p2 = BRep_Tool::Pnt(v2);
1000 t1 = BRep_Tool::Tolerance(v1);
1001 t2 = BRep_Tool::Tolerance(v2);
1002 c1f = p1.Distance(Firstpoint)<=t1;
1003 c2f = p2.Distance(Firstpoint)<=t2;
1004 c1l = p1.Distance(Lastpoint)<=t1;
1005 c2l = p2.Distance(Lastpoint)<=t2;
1006 if (c1f || c2f || c1l|| c2l) {
1008 if (c1f || c1l) v1OK=Standard_True;
1009 if (c2f || c2l) v2OK=Standard_True;
1010 if (c1f || c2f) FirstOK=Standard_True;
1011 if (c1l || c2l) LastOK=Standard_True;
1017 falseside = Standard_False;
1018 return Standard_False;
1020 TopTools_ListOfShape thelist;
1021 mySlface.Bind(CurrentFace, thelist);
1022 mySlface(CurrentFace).Append(eb);
1024 myListOfEdges.Clear();
1025 myListOfEdges.Append(eb);
1027 // two points are on the same face.
1028 if(LastOK && FirstOK) {
1032 TopTools_IndexedDataMapOfShapeListOfShape mapedges;
1033 TopExp::MapShapesAndAncestors(mySbase, TopAbs_EDGE, TopAbs_FACE, mapedges);
1035 TopoDS_Edge FirstEdge;
1038 TopoDS_Vertex Vprevious;
1040 Standard_Real tvp, dp;
1042 while (!(LastOK && FirstOK)) {
1054 // find edge connected to v1 or v2:
1055 for (ex.Init(CurrentFace, TopAbs_EDGE); ex.More(); ex.Next()) {
1056 const TopoDS_Edge& rfe = TopoDS::Edge(ex.Current());
1058 BRepExtrema_ExtPC projF(Vprevious, rfe);
1060 if(projF.IsDone() && projF.NbExt() >=1) {
1061 Standard_Real dist2min = RealLast();
1062 Standard_Integer index = 0;
1063 for (Standard_Integer sol =1 ; sol <= projF.NbExt(); sol++) {
1064 if (projF.SquareDistance(sol) <= dist2min) {
1066 dist2min = projF.SquareDistance(sol);
1070 if (dist2min <= BRep_Tool::Tolerance(rfe) * BRep_Tool::Tolerance(rfe)) {
1072 // If the edge is not perpendicular to the plane of the rib
1073 // it is required to set Sliding(result) to false.
1075 result=Standard_False;
1076 ve1 = TopExp::FirstVertex(rfe,Standard_True);
1077 ve2 = TopExp::LastVertex(rfe,Standard_True);
1078 BRepExtrema_ExtPF perp(ve1, fac);
1079 if (perp.IsDone()) {
1080 gp_Pnt pe1=perp.Point(1);
1081 perp.Perform(ve2, fac);
1082 if (perp.IsDone()) {
1083 gp_Pnt pe2=perp.Point(1);
1084 if (pe1.Distance(pe2)<=BRep_Tool::Tolerance(rfe))
1085 result=Standard_True;
1095 const TopTools_ListOfShape& L = mapedges.FindFromKey(FirstEdge);
1096 TopTools_ListIteratorOfListOfShape It(L);
1098 for (; It.More(); It.Next()) {
1099 const TopoDS_Face& FF = TopoDS::Face(It.Value());
1100 if (!FF.IsSame(CurrentFace)) {
1106 //modified by NIZNHY-PKV Fri Mar 22 16:50:53 2002 f
1107 //BRepAlgo_Section sectf (fac, CurrentFace, Standard_False);
1108 BRepAlgoAPI_Section sectf (fac, CurrentFace, Standard_False);
1109 //modified by NIZNHY-PKV Fri Mar 22 16:51:03 2002 t
1110 sectf.Approximation(Standard_True);
1114 for (Ex.Init(sectf.Shape(), TopAbs_EDGE); Ex.More(); Ex.Next()) {
1115 edg1 = TopoDS::Edge(Ex.Current());
1116 v1=TopExp::FirstVertex(edg1,Standard_True);
1117 v2=TopExp::LastVertex(edg1,Standard_True);
1118 t1 = BRep_Tool::Tolerance(v1);
1119 t2 = BRep_Tool::Tolerance(v2);
1120 p1 = BRep_Tool::Pnt(v1);
1121 p2 = BRep_Tool::Pnt(v2);
1122 v1OK = p1.Distance(ptprev)<=t1;
1123 v2OK = p2.Distance(ptprev)<=t2;
1124 if (v1OK || v2OK) break;
1129 dp = p2.Distance(Firstpoint);
1131 FirstOK = Standard_True;
1132 BB.UpdateVertex(v2, dp);
1136 dp = p2.Distance(Lastpoint);
1138 LastOK = Standard_True;
1139 BB.UpdateVertex(v2, dp);
1145 dp = p1.Distance(Firstpoint);
1147 FirstOK = Standard_True;
1148 BB.UpdateVertex(v1, dp);
1152 dp = p1.Distance(Lastpoint);
1154 LastOK = Standard_True;
1155 BB.UpdateVertex(v1, dp);
1160 // end by chaining the section
1161 return Standard_False;
1163 TopTools_ListOfShape thelist1;
1164 mySlface.Bind(CurrentFace, thelist1);
1165 mySlface(CurrentFace).Append(edg1);
1166 myListOfEdges.Append(edg1);
1173 //=======================================================================
1175 //purpose : management of descendants
1176 //=======================================================================
1178 static void MajMap(const TopoDS_Shape& theB,
1179 const LocOpe_LinearForm& theP,
1180 TopTools_DataMapOfShapeListOfShape& theMap, // myMap
1181 TopoDS_Shape& theFShape, // myFShape
1182 TopoDS_Shape& theLShape) // myLShape
1184 TopExp_Explorer exp(theP.FirstShape(),TopAbs_WIRE);
1186 theFShape = exp.Current();
1187 TopTools_ListOfShape thelist;
1188 theMap.Bind(theFShape, thelist);
1189 for (exp.Init(theP.FirstShape(),TopAbs_FACE);exp.More();exp.Next()) {
1190 theMap(theFShape).Append(exp.Current());
1194 exp.Init(theP.LastShape(),TopAbs_WIRE);
1196 theLShape = exp.Current();
1197 TopTools_ListOfShape thelist1;
1198 theMap.Bind(theLShape, thelist1);
1199 for (exp.Init(theP.LastShape(),TopAbs_FACE);exp.More();exp.Next()) {
1200 theMap(theLShape).Append(exp.Current());
1204 for (exp.Init(theB,TopAbs_EDGE); exp.More(); exp.Next()) {
1205 if (!theMap.IsBound(exp.Current())) {
1207 const TopoDS_Edge& e =
1209 TopoDS::Edge(exp.Current());
1210 TopTools_ListOfShape thelist2;
1211 theMap.Bind(exp.Current(), thelist2);
1212 theMap(exp.Current()) = theP.Shapes(exp.Current());
1217 //=======================================================================
1218 //function : SetGluedFaces
1219 //purpose : management of faces of gluing
1220 //=======================================================================
1222 static void SetGluedFaces(const TopTools_DataMapOfShapeListOfShape& theSlmap,
1223 LocOpe_LinearForm& thePrism,
1224 TopTools_DataMapOfShapeShape& theMap)
1227 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(theSlmap);
1228 if(!theSlmap.IsEmpty()) {
1229 for (; itm.More(); itm.Next()) {
1230 const TopoDS_Face& fac = TopoDS::Face(itm.Key());
1231 const TopTools_ListOfShape& ledg = itm.Value();
1232 TopTools_ListIteratorOfListOfShape it;
1233 for (it.Initialize(ledg); it.More(); it.Next()) {
1234 const TopTools_ListOfShape& gfac = thePrism.Shapes(it.Value());
1235 if (gfac.Extent() != 1) {
1237 cout << "Pb SetGluedFace" << endl;
1240 theMap.Bind(gfac.First(),fac);