b311480e |
1 | // Created on: 1993-06-23 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRep_Builder.hxx> |
19 | #include <BRepPrim_FaceBuilder.hxx> |
20 | #include <Geom2d_Line.hxx> |
21 | #include <Geom_Surface.hxx> |
22 | #include <gp_Pnt.hxx> |
23 | #include <Precision.hxx> |
24 | #include <Standard_ConstructionError.hxx> |
7fd59977 |
25 | #include <Standard_OutOfRange.hxx> |
42cf5bc1 |
26 | #include <TopoDS_Edge.hxx> |
27 | #include <TopoDS_Face.hxx> |
28 | #include <TopoDS_Vertex.hxx> |
29 | #include <TopoDS_Wire.hxx> |
7fd59977 |
30 | |
31 | //======================================================================= |
32 | //function : BRepPrim_FaceBuilder |
33 | //purpose : |
34 | //======================================================================= |
7fd59977 |
35 | BRepPrim_FaceBuilder::BRepPrim_FaceBuilder() |
36 | { |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : BRepPrim_FaceBuilder |
41 | //purpose : |
42 | //======================================================================= |
43 | |
44 | BRepPrim_FaceBuilder::BRepPrim_FaceBuilder(const BRep_Builder& B, |
45 | const Handle(Geom_Surface)& S) |
46 | { |
47 | Init(B,S); |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : BRepPrim_FaceBuilder |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | BRepPrim_FaceBuilder::BRepPrim_FaceBuilder(const BRep_Builder& B, |
57 | const Handle(Geom_Surface)& S, |
58 | const Standard_Real UMin, |
59 | const Standard_Real UMax, |
60 | const Standard_Real VMin, |
61 | const Standard_Real VMax) |
62 | { |
63 | Init(B,S,UMin,UMax,VMin,VMax); |
64 | } |
65 | |
66 | |
67 | //======================================================================= |
68 | //function : Init |
69 | //purpose : |
70 | //======================================================================= |
71 | |
72 | void BRepPrim_FaceBuilder::Init(const BRep_Builder& B, |
73 | const Handle(Geom_Surface)& S) |
74 | { |
75 | Standard_Real UMin,UMax,VMin,VMax; |
76 | S->Bounds(UMin,UMax,VMin,VMax); |
77 | Init(B,S,UMin,UMax,VMin,VMax); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Init |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void BRepPrim_FaceBuilder::Init(const BRep_Builder& B, |
86 | const Handle(Geom_Surface)& S, |
87 | const Standard_Real UMin, |
88 | const Standard_Real UMax, |
89 | const Standard_Real VMin, |
90 | const Standard_Real VMax) |
91 | { |
92 | // Check the values |
93 | Standard_Real USMin,USMax,VSMin,VSMax; |
94 | S->Bounds(USMin,USMax,VSMin,VSMax); |
95 | |
9775fa61 |
96 | if (UMin >= UMax) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
97 | if (VMin >= VMax) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
98 | if (UMin < USMin) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
99 | if (UMax > USMax) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
100 | if (VMin < VSMin) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
101 | if (VMax > VSMax) throw Standard_ConstructionError("BRepPrim_FaceBuilder"); |
7fd59977 |
102 | |
103 | // Make the vertices |
104 | B.MakeVertex(myVertex[0],S->Value(UMin,VMin),Precision::Confusion()); |
105 | B.MakeVertex(myVertex[1],S->Value(UMax,VMin),Precision::Confusion()); |
106 | B.MakeVertex(myVertex[2],S->Value(UMax,VMax),Precision::Confusion()); |
107 | B.MakeVertex(myVertex[3],S->Value(UMin,VMax),Precision::Confusion()); |
108 | |
109 | // Make the edges |
110 | B.MakeEdge(myEdges[0]); |
111 | B.MakeEdge(myEdges[1]); |
112 | B.MakeEdge(myEdges[2]); |
113 | B.MakeEdge(myEdges[3]); |
114 | |
115 | // Make the face |
116 | B.MakeFace(myFace,S,Precision::Confusion()); |
117 | |
118 | // set the pcurves |
119 | Handle(Geom2d_Line) L; |
120 | L = new Geom2d_Line(gp_Pnt2d(UMin,VMin),gp_Dir2d(1,0)); |
121 | B.UpdateEdge(myEdges[0],L,myFace,Precision::Confusion()); |
122 | L = new Geom2d_Line(gp_Pnt2d(UMax,VMin),gp_Dir2d(0,1)); |
123 | B.UpdateEdge(myEdges[1],L,myFace,Precision::Confusion()); |
124 | L = new Geom2d_Line(gp_Pnt2d(UMax,VMax),gp_Dir2d(-1,0)); |
125 | B.UpdateEdge(myEdges[2],L,myFace,Precision::Confusion()); |
126 | L = new Geom2d_Line(gp_Pnt2d(UMin,VMax),gp_Dir2d(0,-1)); |
127 | B.UpdateEdge(myEdges[3],L,myFace,Precision::Confusion()); |
128 | |
129 | // set the parameters |
130 | B.UpdateVertex(myVertex[0],0,myEdges[0],0); |
131 | B.UpdateVertex(myVertex[1],UMax-UMin,myEdges[0],0); |
132 | B.UpdateVertex(myVertex[1],0,myEdges[1],0); |
133 | B.UpdateVertex(myVertex[2],VMax-VMin,myEdges[1],0); |
134 | B.UpdateVertex(myVertex[2],0,myEdges[2],0); |
135 | B.UpdateVertex(myVertex[3],UMax-UMin,myEdges[2],0); |
136 | B.UpdateVertex(myVertex[3],0,myEdges[3],0); |
137 | B.UpdateVertex(myVertex[0],VMax-VMin,myEdges[3],0); |
138 | |
139 | // insert vertices in edges |
140 | myVertex[0].Orientation(TopAbs_REVERSED); |
141 | B.Add(myEdges[3],myVertex[0]); |
142 | myVertex[0].Orientation(TopAbs_FORWARD); |
143 | B.Add(myEdges[0],myVertex[0]); |
144 | myVertex[1].Orientation(TopAbs_REVERSED); |
145 | B.Add(myEdges[0],myVertex[1]); |
146 | myVertex[1].Orientation(TopAbs_FORWARD); |
147 | B.Add(myEdges[1],myVertex[1]); |
148 | myVertex[2].Orientation(TopAbs_REVERSED); |
149 | B.Add(myEdges[1],myVertex[2]); |
150 | myVertex[2].Orientation(TopAbs_FORWARD); |
151 | B.Add(myEdges[2],myVertex[2]); |
152 | myVertex[3].Orientation(TopAbs_REVERSED); |
153 | B.Add(myEdges[2],myVertex[3]); |
154 | myVertex[3].Orientation(TopAbs_FORWARD); |
155 | B.Add(myEdges[3],myVertex[3]); |
156 | |
157 | // insert edges in a wire and in the face |
158 | TopoDS_Wire W; |
159 | B.MakeWire(W); |
160 | B.Add(W,myEdges[0]); |
161 | B.Add(W,myEdges[1]); |
162 | B.Add(W,myEdges[2]); |
163 | B.Add(W,myEdges[3]); |
164 | |
165 | B.Add(myFace,W); |
166 | |
167 | // set the natural restriction flag |
168 | if ( UMin == USMin && UMax == USMax && VMin == VSMin && VMax == VSMax) |
169 | B.NaturalRestriction(myFace,Standard_True); |
170 | } |
171 | |
172 | |
173 | //======================================================================= |
174 | //function : Face |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | const TopoDS_Face& BRepPrim_FaceBuilder::Face()const |
179 | { |
180 | return myFace; |
181 | } |
182 | |
183 | |
184 | //======================================================================= |
185 | //function : Edge |
186 | //purpose : |
187 | //======================================================================= |
188 | |
189 | const TopoDS_Edge& BRepPrim_FaceBuilder::Edge(const Standard_Integer I)const |
190 | { |
191 | Standard_OutOfRange_Raise_if(I<1 || I >4,"BRepPrim_FaceBuilder::Edge"); |
192 | return myEdges[I-1]; |
193 | } |
194 | |
195 | |
196 | //======================================================================= |
197 | //function : Vertex |
198 | //purpose : |
199 | //======================================================================= |
200 | |
201 | const TopoDS_Vertex& BRepPrim_FaceBuilder::Vertex(const Standard_Integer I)const |
202 | { |
203 | Standard_OutOfRange_Raise_if(I<1 || I >4,"BRepPrim_FaceBuilder::Vertex"); |
204 | return myVertex[I-1]; |
205 | } |
206 | |
207 | |
208 | |
209 | //======================================================================= |
210 | //function : operator TopoDS_Face |
211 | //purpose : |
212 | //======================================================================= |
213 | |
214 | BRepPrim_FaceBuilder::operator TopoDS_Face() |
215 | { |
216 | return Face(); |
217 | } |