1 // Created on: 1996-09-04
2 // Created by: Olga PILLOT
3 // Copyright (c) 1996-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.
22 #include <LocOpe_DPrism.ixx>
25 #include <BRep_Builder.hxx>
26 #include <BRep_Tool.hxx>
27 #include <Geom_RectangularTrimmedSurface.hxx>
29 #include <BRepLib_MakeVertex.hxx>
30 #include <BRepLib_MakeEdge.hxx>
31 #include <BRepLib_MakeWire.hxx>
32 #include <BRepLib_MakeFace.hxx>
33 #include <BRepClass3d_SolidClassifier.hxx>
35 #include <BRepLib.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_DataMapOfShapeListOfShape.hxx>
41 #include <TopTools.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
44 #include <TopExp_Explorer.hxx>
46 #include <LocOpe_BuildShape.hxx>
48 #include <TColgp_SequenceOfPnt.hxx>
55 #include <Geom_Surface.hxx>
56 #include <Geom_RectangularTrimmedSurface.hxx>
57 #include <Geom_TrimmedCurve.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_Line.hxx>
60 #include <Geom_Curve.hxx>
64 #include <Precision.hxx>
65 #include <BSplCLib.hxx>
67 #include <BRepTools.hxx>
68 #include <Standard_ConstructionError.hxx>
71 Standard_IMPORT Standard_Boolean BRepFeat_GettraceFEAT();
74 #define NECHANT 7 // voir BRepFeat.cxx
76 //=======================================================================
77 //function : LocOpe_DPrism
79 //=======================================================================
81 LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
82 const Standard_Real Height1,
83 const Standard_Real Height2,
84 const Standard_Real Angle):
89 myHeight = Height1 + Height2;
90 Standard_Real y = Height1*sin(Angle);
91 Standard_Real z = Height1*cos(Angle);
93 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
95 Standard_Real y1 = -Height2*sin(Angle);
96 Standard_Real z1 = -Height2*cos(Angle);
98 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0,y1,z1));
100 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
102 Standard_Real Umin,Umax,Vmin,Vmax;
108 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
109 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
112 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay, z));
113 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
120 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
121 Standard_Real Deltay1 = Max(Umax-Umin,Vmax-Vmin) + Abs(y1);
124 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, y1+Deltay1, z1));
125 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
127 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
129 myDPrism.Perform(mySpine,myProfile,gp::XOY());
132 if (myDPrism.IsDone()) {
133 LocOpe_BuildShape BS;
137 TopTools_ListOfShape lfaces,lcomplete;
141 TopTools_ListIteratorOfListOfShape it;
142 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
143 TopTools_MapOfShape View;
144 for (; ExpS.More(); ExpS.Next()) {
145 const TopoDS_Shape& ES = ExpS.Current();
146 const TopTools_ListOfShape& lffs =
147 myDPrism.GeneratedShapes(ES, myProfile1);
148 for (it.Initialize(lffs); it.More(); it.Next()) {
149 if (View.Add(it.Value()))
154 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
155 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
158 for ( i = 1; i<=theMapEF.Extent(); i++) {
159 if (theMapEF(i).Extent() == 1) {
160 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
161 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
163 TopoDS_Shape aLocalShape = fac.EmptyCopied();
164 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
165 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
167 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
168 exp.More(); exp.Next()) {
169 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
170 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
171 for ( ; exp2.More(); exp2.Next()) {
172 if (exp2.Current().IsSame(edg)) {
173 B.Add(newFace,exp.Current());
174 lfaces.Append(newFace);
175 lcomplete.Append(newFace);
188 myFirstShape = BS.Shape();
196 for (; ExpS.More(); ExpS.Next()) {
197 const TopoDS_Shape& ES = ExpS.Current();
198 const TopTools_ListOfShape& lfls =
199 myDPrism.GeneratedShapes(ES, myProfile3);
200 for (it.Initialize(lfls); it.More(); it.Next()) {
201 if (View.Add(it.Value()))
208 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
211 for (i = 1; i<=theMapEF.Extent(); i++) {
212 if (theMapEF(i).Extent() == 1) {
213 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
214 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
216 TopoDS_Shape aLocalShape = fac.EmptyCopied();
217 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
218 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
220 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
221 exp.More(); exp.Next()) {
222 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
223 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
224 for ( ; exp2.More(); exp2.Next()) {
225 if (exp2.Current().IsSame(edg)) {
226 B.Add(newFace,exp.Current());
227 lfaces.Append(newFace);
228 lcomplete.Append(newFace);
240 myLastShape = BS.Shape();
245 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
246 const TopoDS_Shape& ES = ExpS.Current();
247 const TopTools_ListOfShape& lffs =
248 myDPrism.GeneratedShapes(ES, myProfile2);
250 for (it.Initialize(lffs); it.More(); it.Next()) {
251 if (it.Value().ShapeType() == TopAbs_EDGE) {
256 TopoDS_Shape RemovedEdge = it.Value();
260 TopAbs_Orientation Orref = TopAbs_FORWARD;
262 for (it.Initialize(lffs); it.More(); it.Next()) {
263 if (it.Value().ShapeType() == TopAbs_FACE) {
264 exp.Init(it.Value().Oriented(TopAbs_FORWARD),TopAbs_WIRE);
265 const TopoDS_Shape theWire = exp.Current();
266 if (NewFace.IsNull()) {
267 Handle(Geom_Surface) S =
268 BRep_Tool::Surface(TopoDS::Face(it.Value()));
269 if (S->DynamicType() ==
270 STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
271 S = Handle(Geom_RectangularTrimmedSurface)::
272 DownCast(S)->BasisSurface();
274 if (S->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
278 B.MakeFace(NewFace,S,BRep_Tool::
279 Tolerance(TopoDS::Face(it.Value())));
280 NewFace.Orientation(TopAbs_FORWARD);
281 Orref = theWire.Orientation();
282 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
283 exp.More(); exp.Next()) {
284 if (!exp.Current().IsSame(RemovedEdge)) {
285 B.Add(NewWire,exp.Current());
290 for (exp.Init(theWire.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
291 exp.More(); exp.Next()) {
292 if (!exp.Current().IsSame(RemovedEdge)) {
293 if (theWire.Orientation() != Orref) { // Les 2 faces planes ont des normales opposees
294 B.Add(NewWire,exp.Current());
297 B.Add(NewWire,exp.Current().Reversed());
304 if (!NewFace.IsNull()) {
305 B.Add(NewFace,NewWire.Oriented(Orref));
306 lcomplete.Append(NewFace);
307 TopTools_ListOfShape thelist;
308 myMap.Bind(ES, thelist);
309 myMap(ES).Append(NewFace);
312 for (it.Initialize(lffs); it.More(); it.Next()) {
313 if (View.Add(it.Value()) &&
314 it.Value().ShapeType() == TopAbs_FACE) {
315 lcomplete.Append(it.Value());
322 for (it.Initialize(lffs); it.More(); it.Next()) {
323 if (View.Add(it.Value()) && it.Value().ShapeType()
325 lcomplete.Append(it.Value());
330 TopExp_Explorer ExpS2;
331 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
332 const TopTools_ListOfShape& ls2 =
333 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
334 for (it.Initialize(ls2); it.More(); it.Next()) {
335 if (View.Add(it.Value()) && it.Value().ShapeType()
337 lcomplete.Append(it.Value());
343 BS.Perform(lcomplete);
345 BRepLib::UpdateTolerances(myRes);
351 //=======================================================================
352 //function : LocOpe_DPrism
354 //=======================================================================
356 LocOpe_DPrism::LocOpe_DPrism(const TopoDS_Face& Spine,
357 const Standard_Real Height,
358 const Standard_Real Angle):
363 Standard_Real y = Height*sin(Angle);
364 Standard_Real z = Height*cos(Angle);
366 TopoDS_Vertex Vert1 = BRepLib_MakeVertex(gp_Pnt(0, 0, 0));
367 TopoDS_Vertex Vert2 = BRepLib_MakeVertex(gp_Pnt(0,y,z));
368 myProfile2 = BRepLib_MakeEdge(Vert1, Vert2);
370 Standard_Real Umin,Umax,Vmin,Vmax;
371 BRepTools::UVBounds(Spine,Umin,Umax,Vmin,Vmax);
372 Standard_Real Deltay = Max(Umax-Umin,Vmax-Vmin) + Abs(y);
375 TopoDS_Vertex Vert3 = BRepLib_MakeVertex(gp_Pnt(0, y + Deltay,z));
376 myProfile3 = BRepLib_MakeEdge(Vert2, Vert3);
378 TopoDS_Vertex Vert4 = BRepLib_MakeVertex(gp_Pnt(0, Deltay,0));
379 myProfile1 = BRepLib_MakeEdge(Vert4, Vert1);
381 myProfile = BRepLib_MakeWire(myProfile1,myProfile2,myProfile3);
382 myDPrism.Perform(mySpine,myProfile,gp::XOY());
385 if (myDPrism.IsDone()) {
386 LocOpe_BuildShape BS;
390 TopTools_ListOfShape lfaces,lcomplete;
394 TopTools_ListIteratorOfListOfShape it;
395 TopExp_Explorer ExpS(mySpine,TopAbs_EDGE);
396 TopTools_MapOfShape View;
397 for (; ExpS.More(); ExpS.Next()) {
398 const TopoDS_Shape& ES = ExpS.Current();
399 const TopTools_ListOfShape& lffs =
400 myDPrism.GeneratedShapes(ES, myProfile1);
401 for (it.Initialize(lffs); it.More(); it.Next()) {
402 if (View.Add(it.Value()))
407 TopTools_IndexedDataMapOfShapeListOfShape theMapEF;
408 TopExp::MapShapesAndAncestors(C,TopAbs_EDGE,TopAbs_FACE,theMapEF);
411 for ( i = 1; i<=theMapEF.Extent(); i++) {
412 if (theMapEF(i).Extent() == 1) {
413 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
414 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
416 TopoDS_Shape aLocalShape = fac.EmptyCopied();
417 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
418 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
420 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
421 exp.More(); exp.Next()) {
422 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
423 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
424 for ( ; exp2.More(); exp2.Next()) {
425 if (exp2.Current().IsSame(edg)) {
426 B.Add(newFace,exp.Current());
427 lfaces.Append(newFace);
428 lcomplete.Append(newFace);
441 myFirstShape = BS.Shape();
449 for (; ExpS.More(); ExpS.Next()) {
450 const TopoDS_Shape& ES = ExpS.Current();
451 const TopTools_ListOfShape& lfls =
452 myDPrism.GeneratedShapes(ES, myProfile3);
453 for (it.Initialize(lfls); it.More(); it.Next()) {
454 if (View.Add(it.Value()))
461 TopExp::MapShapesAndAncestors(D,TopAbs_EDGE,TopAbs_FACE,theMapEF);
464 for (i = 1; i<=theMapEF.Extent(); i++) {
465 if (theMapEF(i).Extent() == 1) {
466 const TopoDS_Edge& edg = TopoDS::Edge(theMapEF.FindKey(i));
467 const TopoDS_Face& fac = TopoDS::Face(theMapEF(i).First());
469 TopoDS_Shape aLocalShape = fac.EmptyCopied();
470 TopoDS_Face newFace(TopoDS::Face(aLocalShape));
471 // TopoDS_Face newFace(TopoDS::Face(fac.EmptyCopied()));
473 for (exp.Init(fac.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
474 exp.More(); exp.Next()) {
475 // for (TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE);
476 TopExp_Explorer exp2(exp.Current(),TopAbs_EDGE) ;
477 for ( ; exp2.More(); exp2.Next()) {
478 if (exp2.Current().IsSame(edg)) {
479 B.Add(newFace,exp.Current());
480 lfaces.Append(newFace);
481 lcomplete.Append(newFace);
493 myLastShape = BS.Shape();
497 for (ExpS.ReInit(); ExpS.More(); ExpS.Next()) {
498 const TopoDS_Shape& ES = ExpS.Current();
499 const TopTools_ListOfShape& ls =
500 myDPrism.GeneratedShapes(ES, myProfile2);
501 for (it.Initialize(ls); it.More(); it.Next()) {
502 if (View.Add(it.Value())) {
503 lcomplete.Append(it.Value());
506 TopExp_Explorer ExpS2;
507 for (ExpS2.Init(ES,TopAbs_VERTEX);ExpS2.More(); ExpS2.Next()) {
508 const TopTools_ListOfShape& ls2 =
509 myDPrism.GeneratedShapes(ExpS2.Current(), myProfile2);
510 for (it.Initialize(ls2); it.More(); it.Next()) {
511 if (View.Add(it.Value()) && it.Value().
512 ShapeType() == TopAbs_FACE) {
513 lcomplete.Append(it.Value());
519 BS.Perform(lcomplete);
521 BRepLib::UpdateTolerances(myRes);
527 //=======================================================================
530 //=======================================================================
532 Standard_Boolean LocOpe_DPrism::IsDone() const
534 return myDPrism.IsDone();
538 //=======================================================================
541 //=======================================================================
543 const TopoDS_Shape& LocOpe_DPrism::Shape () const
545 if (!myDPrism.IsDone()) {
546 StdFail_NotDone::Raise();
552 //=======================================================================
555 //=======================================================================
557 const TopoDS_Shape& LocOpe_DPrism::Spine () const
562 //=======================================================================
565 //=======================================================================
567 const TopoDS_Shape& LocOpe_DPrism::Profile () const
573 //=======================================================================
574 //function : FirstShape
576 //=======================================================================
578 const TopoDS_Shape& LocOpe_DPrism::FirstShape () const
583 //=======================================================================
584 //function : LastShape
586 //=======================================================================
588 const TopoDS_Shape& LocOpe_DPrism::LastShape () const
594 //=======================================================================
597 //=======================================================================
599 const TopTools_ListOfShape&
600 LocOpe_DPrism::Shapes (const TopoDS_Shape& S)const
602 if (!myDPrism.IsDone()) {
603 StdFail_NotDone::Raise();
605 if (myMap.IsBound(S)) {
609 return myDPrism.GeneratedShapes(S,myProfile2);
614 //=======================================================================
617 //=======================================================================
619 void LocOpe_DPrism::Curves(TColGeom_SequenceOfCurve& Scurves) const
621 // Retrieves dy and dz with myProfile2
623 TopExp::Vertices(myProfile2,V1,V2);
624 gp_Pnt P1 = BRep_Tool::Pnt(V1);
625 gp_Pnt P2 = BRep_Tool::Pnt(V2);
626 Standard_Real dy = P2.Y() - P1.Y();
627 Standard_Real dz = P2.Z() - P1.Z();
629 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
630 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
631 S = Handle(Geom_RectangularTrimmedSurface)::
632 DownCast(S)->BasisSurface();
635 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
637 Standard_ConstructionError::Raise();
640 gp_Pln P = PP->Pln();
641 gp_Dir Normale(P.Axis().Direction());
646 TopTools_MapOfShape theMap;
647 TopExp_Explorer exp(mySpine.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
649 Handle(Geom_Curve) C;
650 Standard_Real f,l,prm;
653 for (; exp.More(); exp.Next()) {
654 const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
655 if (!theMap.Add(edg)) {
658 if (!BRep_Tool::Degenerated(edg)) {
659 C = BRep_Tool::Curve(edg,Loc,f,l);
660 C = Handle(Geom_Curve)::
661 DownCast(C->Transformed(Loc.Transformation()));
662 Standard_Real u1 = -2*Abs(myHeight);
663 Standard_Real u2 = 2*Abs(myHeight);
665 for (i=0; i<=NECHANT; i++) {
666 prm = ((NECHANT-i)*f+i*l)/NECHANT;
670 if (exp.Current().Orientation() == TopAbs_REVERSED) {
674 gp_Dir locy = Normale.Crossed(d1);
675 gp_Vec ldir = dy*locy.XYZ() + dz*Normale.XYZ();
676 gp_Lin lin(pt, ldir);
677 Handle(Geom_Line) Lin = new Geom_Line(lin);
678 Handle(Geom_TrimmedCurve) trlin =
679 new Geom_TrimmedCurve(Lin, u1, u2, Standard_True);
680 Scurves.Append(trlin);
687 //=======================================================================
688 //function : BarycCurve
690 //=======================================================================
692 Handle(Geom_Curve) LocOpe_DPrism::BarycCurve() const
695 TopExp::Vertices(myProfile2,V1,V2);
696 gp_Pnt P1 = BRep_Tool::Pnt(V1);
697 gp_Pnt P2 = BRep_Tool::Pnt(V2);
698 Standard_Real dz = P2.Z() - P1.Z();
700 Handle(Geom_Surface) S = BRep_Tool::Surface(mySpine);
701 if (S->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
702 S = Handle(Geom_RectangularTrimmedSurface)::
703 DownCast(S)->BasisSurface();
706 Handle(Geom_Plane) PP = Handle(Geom_Plane)::DownCast(S);
708 Standard_ConstructionError::Raise();
711 gp_Pln P = PP->Pln();
712 gp_Dir Normale(P.Axis().Direction());
716 if (mySpine.Orientation() == TopAbs_REVERSED) {
718 Standard_Boolean trc = BRepFeat_GettraceFEAT();
720 cout << "LocOpe_DPrism::BarycCurve()" << endl;
721 cout << " Reversed Spine orientation" << endl;
724 // Normale.Reverse(); //cts20871
726 gp_Vec Vec = dz*Normale.XYZ();
728 gp_Pnt bar(0., 0., 0.);
729 TColgp_SequenceOfPnt spt;
730 if(!myFirstShape.IsNull()) {
731 LocOpe::SampleEdges(myFirstShape,spt);
734 LocOpe::SampleEdges(mySpine,spt);
736 for (Standard_Integer jj=1;jj<=spt.Length(); jj++) {
737 const gp_Pnt& pvt = spt(jj);
738 bar.ChangeCoord() += pvt.XYZ();
740 bar.ChangeCoord().Divide(spt.Length());
741 gp_Ax1 newAx(bar,Vec);
742 Handle(Geom_Line) theLin = new Geom_Line(newAx);