1 // Created on: 1998-07-22
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <BRep_Builder.hxx>
19 #include <BRepFill_Section.hxx>
20 #include <TopoDS.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopoDS_Vertex.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Iterator.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <ShapeUpgrade_RemoveLocations.hxx>
28
BRepFill_Section()29 BRepFill_Section::BRepFill_Section() :islaw(0),
30 ispunctual(0),
31 contact(0),
32 correction(0)
33 {
34 }
35
36
BRepFill_Section(const TopoDS_Shape & Profile,const TopoDS_Vertex & V,const Standard_Boolean WithContact,const Standard_Boolean WithCorrection)37 BRepFill_Section::BRepFill_Section(const TopoDS_Shape& Profile,
38 const TopoDS_Vertex& V,
39 const Standard_Boolean WithContact,
40 const Standard_Boolean WithCorrection)
41 : vertex(V),
42 islaw(0),
43 ispunctual(0),
44 contact(WithContact),
45 correction(WithCorrection)
46 {
47 myOriginalShape = Profile;
48
49 ShapeUpgrade_RemoveLocations RemLoc;
50 RemLoc.SetRemoveLevel(TopAbs_COMPOUND);
51 RemLoc.Remove(Profile);
52 TopoDS_Shape aProfile = RemLoc.GetResult();
53
54 if (aProfile.ShapeType() == TopAbs_WIRE)
55 wire = TopoDS::Wire(aProfile);
56 else if (aProfile.ShapeType() == TopAbs_VERTEX)
57 {
58 ispunctual = Standard_True;
59 TopoDS_Vertex aVertex = TopoDS::Vertex(aProfile);
60 BRep_Builder BB;
61
62 TopoDS_Edge DegEdge;
63 BB.MakeEdge( DegEdge );
64 BB.Add( DegEdge, aVertex.Oriented(TopAbs_FORWARD) );
65 BB.Add( DegEdge, aVertex.Oriented(TopAbs_REVERSED) );
66 BB.Degenerated( DegEdge, Standard_True );
67
68 BB.MakeWire( wire );
69 BB.Add( wire, DegEdge );
70 wire.Closed( Standard_True );
71 }
72 else
73 throw Standard_Failure("BRepFill_Section: bad shape type of section");
74 }
75
Set(const Standard_Boolean IsLaw)76 void BRepFill_Section::Set(const Standard_Boolean IsLaw)
77 {
78 islaw = IsLaw;
79 }
80
ModifiedShape(const TopoDS_Shape & theShape) const81 TopoDS_Shape BRepFill_Section::ModifiedShape(const TopoDS_Shape& theShape) const
82 {
83 TopoDS_Shape aModifiedShape;
84
85 switch (theShape.ShapeType())
86 {
87 case TopAbs_WIRE:
88 if (theShape.IsSame(myOriginalShape))
89 aModifiedShape = wire;
90 break;
91 case TopAbs_EDGE:
92 {
93 TopoDS_Iterator itor(myOriginalShape);
94 TopoDS_Iterator itw(wire);
95 for (; itor.More(); itor.Next(),itw.Next())
96 {
97 const TopoDS_Shape& anOriginalEdge = itor.Value();
98 const TopoDS_Shape& anEdge = itw.Value();
99 if (anOriginalEdge.IsSame(theShape))
100 {
101 aModifiedShape = anEdge;
102 break;
103 }
104 }
105 }
106 break;
107 case TopAbs_VERTEX:
108 if (theShape.IsSame(myOriginalShape))
109 {
110 TopExp_Explorer Explo(wire, TopAbs_VERTEX);
111 aModifiedShape = Explo.Current();
112 }
113 else
114 {
115 TopExp_Explorer ExpOrig(myOriginalShape, TopAbs_VERTEX);
116 TopExp_Explorer ExpWire(wire, TopAbs_VERTEX);
117 for (; ExpOrig.More(); ExpOrig.Next(),ExpWire.Next())
118 {
119 const TopoDS_Shape& anOriginalVertex = ExpOrig.Current();
120 const TopoDS_Shape& aVertex = ExpWire.Current();
121 if (anOriginalVertex.IsSame(theShape))
122 {
123 aModifiedShape = aVertex;
124 break;
125 }
126 }
127 }
128 break;
129 default:
130 break;
131 }
132
133 return aModifiedShape;
134 }
135