1 // Created on: 1996-09-04
2 // Created by: Olga PILLOT
3 // Copyright (c) 1996-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.
18 #include <BRep_Builder.hxx>
19 #include <BRep_Tool.hxx>
20 #include <BRepClass3d_SolidClassifier.hxx>
21 #include <BRepLib.hxx>
22 #include <BRepLib_MakeEdge.hxx>
23 #include <BRepLib_MakeFace.hxx>
24 #include <BRepLib_MakeVertex.hxx>
25 #include <BRepLib_MakeWire.hxx>
26 #include <BRepTools.hxx>
27 #include <BSplCLib.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom_Line.hxx>
30 #include <Geom_Plane.hxx>
31 #include <Geom_RectangularTrimmedSurface.hxx>
32 #include <Geom_Surface.hxx>
33 #include <Geom_TrimmedCurve.hxx>
40 #include <LocOpe_BuildShape.hxx>
41 #include <LocOpe_DPrism.hxx>
42 #include <Precision.hxx>
43 #include <Standard_ConstructionError.hxx>
44 #include <Standard_DomainError.hxx>
45 #include <Standard_NoSuchObject.hxx>
46 #include <StdFail_NotDone.hxx>
47 #include <TColgp_SequenceOfPnt.hxx>
49 #include <TopExp_Explorer.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopoDS_Face.hxx>
53 #include <TopoDS_Shape.hxx>
54 #include <TopTools.hxx>
55 #include <TopTools_DataMapOfShapeListOfShape.hxx>
56 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_MapOfShape.hxx>
62 extern Standard_Boolean BRepFeat_GettraceFEAT();
65 #define NECHANT 7 // voir BRepFeat.cxx
67 //=======================================================================
68 //function : LocOpe_DPrism
70 //=======================================================================
72 LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
73 const Standard_Real Height1,
74 const Standard_Real Height2,
75 const Standard_Real Angle):
80 myHeight = Height1 + Height2;
81 Standard_Real y = Height1*sin(Angle);
82 Standard_Real z = Height1*cos(Angle);
84 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
86 Standard_Real y1 = -Height2*sin(Angle);
87 Standard_Real z1 = -Height2*cos(Angle);
89 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0,y1,z1));
91 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
93 Standard_Real Umin,Umax,Vmin,Vmax;
99 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
100 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
103 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay, z));
104 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
111 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
112 Standard_Real Deltay1 = Max(Umax-Umin,Vmax-Vmin) + Abs(y1);
115 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, y1+Deltay1, z1));
116 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
118 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
120 myDPrism.Perform(mySpine,myProfile,gp::XOY());
123 if (myDPrism.IsDone()) {
124 LocOpe_BuildShape BS;
128 TopTools_ListOfShape lfaces,lcomplete;
132 TopTools_ListIteratorOfListOfShape it;
133 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
134 TopTools_MapOfShape View;
135 for (; ExpS.More(); ExpS.Next()) {
136 const TopoDS_Shape& ES = ExpS.Current();
137 const TopTools_ListOfShape& lffs =
138 myDPrism.GeneratedShapes(ES, myProfile1);
139 for (it.Initialize(lffs); it.More(); it.Next()) {
140 if (View.Add(it.Value()))
145 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
146 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
149 for ( i = 1; i<=theMapEF.Extent(); i++) {
150 if (theMapEF(i).Extent() == 1) {
151 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
152 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
154 TopoDS_Shape aLocalShape = fac.EmptyCopied();
155 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
156 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
158 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
159 exp.More(); exp.Next()) {
160 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
161 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
162 for ( ; exp2.More(); exp2.Next()) {
163 if (exp2.Current().IsSame(edg)) {
164 B.Add(newFace,exp.Current());
165 lfaces.Append(newFace);
166 lcomplete.Append(newFace);
179 myFirstShape = BS.Shape();
187 for (; ExpS.More(); ExpS.Next()) {
188 const TopoDS_Shape& ES = ExpS.Current();
189 const TopTools_ListOfShape& lfls =
190 myDPrism.GeneratedShapes(ES, myProfile3);
191 for (it.Initialize(lfls); it.More(); it.Next()) {
192 if (View.Add(it.Value()))
199 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
202 for (i = 1; i<=theMapEF.Extent(); i++) {
203 if (theMapEF(i).Extent() == 1) {
204 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
205 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
207 TopoDS_Shape aLocalShape = fac.EmptyCopied();
208 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
209 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
211 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
212 exp.More(); exp.Next()) {
213 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
214 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
215 for ( ; exp2.More(); exp2.Next()) {
216 if (exp2.Current().IsSame(edg)) {
217 B.Add(newFace,exp.Current());
218 lfaces.Append(newFace);
219 lcomplete.Append(newFace);
231 myLastShape = BS.Shape();
236 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
237 const TopoDS_Shape& ES = ExpS.Current();
238 const TopTools_ListOfShape& lffs =
239 myDPrism.GeneratedShapes(ES, myProfile2);
241 for (it.Initialize(lffs); it.More(); it.Next()) {
242 if (it.Value().ShapeType() == TopAbs_EDGE) {
247 TopoDS_Shape RemovedEdge = it.Value();
251 TopAbs_Orientation Orref = TopAbs_FORWARD;
253 for (it.Initialize(lffs); it.More(); it.Next()) {
254 if (it.Value().ShapeType() == TopAbs_FACE) {
255 exp.Init(it.Value().Oriented(TopAbs_FORWARD),TopAbs_WIRE);
256 const TopoDS_Shape theWire = exp.Current();
257 if (NewFace.IsNull()) {
258 Handle(Geom_Surface) S =
259 BRep_Tool::Surface(TopoDS::Face(it.Value()));
260 if (S->DynamicType() ==
261 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
262 S = Handle(Geom_RectangularTrimmedSurface)::
263 DownCast(S)->BasisSurface();
265 if (S->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
269 B.MakeFace(NewFace,S,BRep_Tool::
270 Tolerance(TopoDS::Face(it.Value())));
271 NewFace.Orientation(TopAbs_FORWARD);
272 Orref = theWire.Orientation();
273 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
274 exp.More(); exp.Next()) {
275 if (!exp.Current().IsSame(RemovedEdge)) {
276 B.Add(NewWire,exp.Current());
281 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
282 exp.More(); exp.Next()) {
283 if (!exp.Current().IsSame(RemovedEdge)) {
284 if (theWire.Orientation() != Orref) { // Les 2 faces planes ont des normales opposees
285 B.Add(NewWire,exp.Current());
288 B.Add(NewWire,exp.Current().Reversed());
295 if (!NewFace.IsNull()) {
296 B.Add(NewFace,NewWire.Oriented(Orref));
297 lcomplete.Append(NewFace);
298 TopTools_ListOfShape thelist;
299 myMap.Bind(ES, thelist);
300 myMap(ES).Append(NewFace);
303 for (it.Initialize(lffs); it.More(); it.Next()) {
304 if (View.Add(it.Value()) &&
305 it.Value().ShapeType() == TopAbs_FACE) {
306 lcomplete.Append(it.Value());
313 for (it.Initialize(lffs); it.More(); it.Next()) {
314 if (View.Add(it.Value()) && it.Value().ShapeType()
316 lcomplete.Append(it.Value());
321 TopExp_Explorer ExpS2;
322 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
323 const TopTools_ListOfShape& ls2 =
324 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
325 for (it.Initialize(ls2); it.More(); it.Next()) {
326 if (View.Add(it.Value()) && it.Value().ShapeType()
328 lcomplete.Append(it.Value());
334 BS.Perform(lcomplete);
336 BRepLib::UpdateTolerances(myRes);
342 //=======================================================================
343 //function : LocOpe_DPrism
345 //=======================================================================
347 LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
348 const Standard_Real Height,
349 const Standard_Real Angle):
354 Standard_Real y = Height*sin(Angle);
355 Standard_Real z = Height*cos(Angle);
357 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0, 0, 0));
358 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
359 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
361 Standard_Real Umin,Umax,Vmin,Vmax;
362 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
363 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
366 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay,z));
367 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
369 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, Deltay,0));
370 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
372 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
373 myDPrism.Perform(mySpine,myProfile,gp::XOY());
376 if (myDPrism.IsDone()) {
377 LocOpe_BuildShape BS;
381 TopTools_ListOfShape lfaces,lcomplete;
385 TopTools_ListIteratorOfListOfShape it;
386 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
387 TopTools_MapOfShape View;
388 for (; ExpS.More(); ExpS.Next()) {
389 const TopoDS_Shape& ES = ExpS.Current();
390 const TopTools_ListOfShape& lffs =
391 myDPrism.GeneratedShapes(ES, myProfile1);
392 for (it.Initialize(lffs); it.More(); it.Next()) {
393 if (View.Add(it.Value()))
398 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
399 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
402 for ( i = 1; i<=theMapEF.Extent(); i++) {
403 if (theMapEF(i).Extent() == 1) {
404 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
405 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
407 TopoDS_Shape aLocalShape = fac.EmptyCopied();
408 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
409 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
411 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
412 exp.More(); exp.Next()) {
413 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
414 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
415 for ( ; exp2.More(); exp2.Next()) {
416 if (exp2.Current().IsSame(edg)) {
417 B.Add(newFace,exp.Current());
418 lfaces.Append(newFace);
419 lcomplete.Append(newFace);
432 myFirstShape = BS.Shape();
440 for (; ExpS.More(); ExpS.Next()) {
441 const TopoDS_Shape& ES = ExpS.Current();
442 const TopTools_ListOfShape& lfls =
443 myDPrism.GeneratedShapes(ES, myProfile3);
444 for (it.Initialize(lfls); it.More(); it.Next()) {
445 if (View.Add(it.Value()))
452 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
455 for (i = 1; i<=theMapEF.Extent(); i++) {
456 if (theMapEF(i).Extent() == 1) {
457 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
458 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
460 TopoDS_Shape aLocalShape = fac.EmptyCopied();
461 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
462 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
464 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
465 exp.More(); exp.Next()) {
466 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
467 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
468 for ( ; exp2.More(); exp2.Next()) {
469 if (exp2.Current().IsSame(edg)) {
470 B.Add(newFace,exp.Current());
471 lfaces.Append(newFace);
472 lcomplete.Append(newFace);
484 myLastShape = BS.Shape();
488 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
489 const TopoDS_Shape& ES = ExpS.Current();
490 const TopTools_ListOfShape& ls =
491 myDPrism.GeneratedShapes(ES, myProfile2);
492 for (it.Initialize(ls); it.More(); it.Next()) {
493 if (View.Add(it.Value())) {
494 lcomplete.Append(it.Value());
497 TopExp_Explorer ExpS2;
498 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
499 const TopTools_ListOfShape& ls2 =
500 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
501 for (it.Initialize(ls2); it.More(); it.Next()) {
502 if (View.Add(it.Value()) && it.Value().
503 ShapeType() == TopAbs_FACE) {
504 lcomplete.Append(it.Value());
510 BS.Perform(lcomplete);
512 BRepLib::UpdateTolerances(myRes);
518 //=======================================================================
521 //=======================================================================
523 Standard_Boolean LocOpe_DPrism::IsDone() const
525 return myDPrism.IsDone();
529 //=======================================================================
532 //=======================================================================
534 const TopoDS_Shape& LocOpe_DPrism::Shape () const
536 if (!myDPrism.IsDone()) {
537 throw StdFail_NotDone();
543 //=======================================================================
546 //=======================================================================
548 const TopoDS_Shape& LocOpe_DPrism::Spine () const
553 //=======================================================================
556 //=======================================================================
558 const TopoDS_Shape& LocOpe_DPrism::Profile () const
564 //=======================================================================
565 //function : FirstShape
567 //=======================================================================
569 const TopoDS_Shape& LocOpe_DPrism::FirstShape () const
574 //=======================================================================
575 //function : LastShape
577 //=======================================================================
579 const TopoDS_Shape& LocOpe_DPrism::LastShape () const
585 //=======================================================================
588 //=======================================================================
590 const TopTools_ListOfShape&
591 LocOpe_DPrism::Shapes (const TopoDS_Shape& S)const
593 if (!myDPrism.IsDone()) {
594 throw StdFail_NotDone();
596 if (myMap.IsBound(S)) {
600 return myDPrism.GeneratedShapes(S,myProfile2);
605 //=======================================================================
608 //=======================================================================
610 void LocOpe_DPrism::Curves(TColGeom_SequenceOfCurve& Scurves) const
612 // Retrieves dy and dz with myProfile2
614 TopExp::Vertices(myProfile2,V1,V2);
615 gp_Pnt P1 = BRep_Tool::Pnt(V1);
616 gp_Pnt P2 = BRep_Tool::Pnt(V2);
617 Standard_Real dy = P2.Y() - P1.Y();
618 Standard_Real dz = P2.Z() - P1.Z();
620 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
621 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
622 S = Handle(Geom_RectangularTrimmedSurface)::
623 DownCast(S)->BasisSurface();
626 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
628 throw Standard_ConstructionError();
631 gp_Pln P = PP->Pln();
632 gp_Dir Normale(P.Axis().Direction());
637 TopTools_MapOfShape theMap;
638 TopExp_Explorer exp(mySpine.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
640 Handle(Geom_Curve) C;
641 Standard_Real f,l,prm;
644 for (; exp.More(); exp.Next()) {
645 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
646 if (!theMap.Add(edg)) {
649 if (!BRep_Tool::Degenerated(edg)) {
650 C = BRep_Tool::Curve(edg,Loc,f,l);
651 C = Handle(Geom_Curve)::
652 DownCast(C->Transformed(Loc.Transformation()));
653 Standard_Real u1 = -2*Abs(myHeight);
654 Standard_Real u2 = 2*Abs(myHeight);
656 for (i=0; i<=NECHANT; i++) {
657 prm = ((NECHANT-i)*f+i*l)/NECHANT;
661 if (exp.Current().Orientation() == TopAbs_REVERSED) {
665 gp_Dir locy = Normale.Crossed(d1);
666 gp_Vec ldir = dy*locy.XYZ() + dz*Normale.XYZ();
667 gp_Lin lin(pt, ldir);
668 Handle(Geom_Line) Lin = new Geom_Line(lin);
669 Handle(Geom_TrimmedCurve) trlin =
670 new Geom_TrimmedCurve(Lin, u1, u2, Standard_True);
671 Scurves.Append(trlin);
678 //=======================================================================
679 //function : BarycCurve
681 //=======================================================================
683 Handle(Geom_Curve) LocOpe_DPrism::BarycCurve() const
686 TopExp::Vertices(myProfile2,V1,V2);
687 gp_Pnt P1 = BRep_Tool::Pnt(V1);
688 gp_Pnt P2 = BRep_Tool::Pnt(V2);
689 Standard_Real dz = P2.Z() - P1.Z();
691 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
692 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
693 S = Handle(Geom_RectangularTrimmedSurface)::
694 DownCast(S)->BasisSurface();
697 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
699 throw Standard_ConstructionError();
702 gp_Pln P = PP->Pln();
703 gp_Dir Normale(P.Axis().Direction());
707 if (mySpine.Orientation() == TopAbs_REVERSED) {
709 Standard_Boolean trc = BRepFeat_GettraceFEAT();
711 cout << "LocOpe_DPrism::BarycCurve()" << endl;
712 cout << " Reversed Spine orientation" << endl;
715 // Normale.Reverse(); //cts20871
717 gp_Vec Vec = dz*Normale.XYZ();
719 gp_Pnt bar(0., 0., 0.);
720 TColgp_SequenceOfPnt spt;
721 if(!myFirstShape.IsNull()) {
722 LocOpe::SampleEdges(myFirstShape,spt);
725 LocOpe::SampleEdges(mySpine,spt);
727 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
728 const gp_Pnt& pvt = spt(jj);
729 bar.ChangeCoord() += pvt.XYZ();
731 bar.ChangeCoord().Divide(spt.Length());
732 gp_Ax1 newAx(bar,Vec);
733 Handle(Geom_Line) theLin = new Geom_Line(newAx);