b311480e |
1 | // Created on: 1995-01-03 |
2 | // Created by: Frederic MAUPAS |
3 | // Copyright (c) 1995-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
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. |
10 | // |
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. |
13 | // |
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. |
20 | |
7fd59977 |
21 | //gka,abv 14.09.99: S4136: eliminate BRepAPI::Precision() |
22 | |
23 | #include <StepToTopoDS_TranslatePolyLoop.ixx> |
24 | |
25 | #include <StepToTopoDS_PointPair.hxx> |
26 | |
27 | #include <StepToGeom_MakeCartesianPoint.hxx> |
28 | |
29 | #include <BRep_Builder.hxx> |
30 | //#include <BRepAPI.hxx> |
31 | |
32 | #include <ElSLib.hxx> |
33 | #include <ShapeAnalysis_Surface.hxx> |
34 | |
35 | #include <TopoDS.hxx> |
36 | #include <TopoDS_Wire.hxx> |
37 | #include <TopoDS_Vertex.hxx> |
38 | #include <TopoDS_Edge.hxx> |
39 | |
40 | #include <Geom2d_Line.hxx> |
41 | #include <Geom_Line.hxx> |
42 | #include <Geom_Plane.hxx> |
43 | #include <Geom_CartesianPoint.hxx> |
44 | |
45 | #include <gp_Vec2d.hxx> |
46 | |
47 | #include <StepGeom_HArray1OfCartesianPoint.hxx> |
48 | #include <Transfer_TransientProcess.hxx> |
49 | #include <Precision.hxx> |
50 | |
51 | // ============================================================================ |
52 | // Method : |
53 | // Purpose : |
54 | // ============================================================================ |
55 | |
56 | StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop() |
57 | { |
58 | done = Standard_False; |
59 | } |
60 | |
61 | // ============================================================================ |
62 | // Method : |
63 | // Purpose : |
64 | // ============================================================================ |
65 | |
66 | StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& T, const Handle(Geom_Surface)& S, const TopoDS_Face& F) |
67 | { |
68 | Init (PL, T, S, F); |
69 | } |
70 | |
71 | // ============================================================================ |
72 | // Method : |
73 | // Purpose : |
74 | // ============================================================================ |
75 | |
76 | void StepToTopoDS_TranslatePolyLoop::Init(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& aTool, const Handle(Geom_Surface)& GeomSurf, const TopoDS_Face& TopoFace) |
77 | { |
78 | if (!aTool.IsBound(PL)) { |
79 | BRep_Builder B; |
80 | Handle(Transfer_TransientProcess) TP = aTool.TransientProcess(); |
81 | |
82 | //:S4136 Standard_Real preci = BRepAPI::Precision(); |
83 | Standard_Integer i; |
84 | Handle(StepGeom_CartesianPoint) P1,P2; |
85 | Handle(Geom_CartesianPoint) GP1, GP2; |
86 | TopoDS_Vertex V1, V2; |
87 | TopoDS_Edge E; |
88 | TopoDS_Wire W; |
89 | Handle(Geom_Line) L; |
90 | Handle(Geom2d_Line) L2d; |
91 | gp_Vec V; |
92 | gp_Vec2d V2d; |
93 | Standard_Real Magn; |
94 | Handle(Geom_Plane) SP = Handle(Geom_Plane)::DownCast(GeomSurf); |
95 | if (SP.IsNull()) TP->AddFail(PL,"Surface not planar in a FacetedBRep !"); |
96 | Handle(ShapeAnalysis_Surface) STSU = new ShapeAnalysis_Surface ( GeomSurf ); |
97 | Standard_Integer Nb = PL->NbPolygon(); |
98 | Handle(StepGeom_HArray1OfCartesianPoint) Poly = |
99 | new StepGeom_HArray1OfCartesianPoint(1, Nb+1); |
100 | |
101 | for ( i=1; i<=Nb; i++ ) |
102 | Poly->SetValue(i, PL->PolygonValue(i)); |
103 | |
104 | Nb++; |
105 | Poly->SetValue(Nb, PL->PolygonValue(1)); |
106 | P1 = Poly->Value(1); |
107 | StepToGeom_MakeCartesianPoint::Convert(P1,GP1); |
108 | if (aTool.IsVertexBound(P1)) { |
109 | V1 = aTool.FindVertex(P1); |
110 | } |
111 | else { |
112 | B.MakeVertex(V1, GP1->Pnt(), Precision::Confusion()); //:S4136: preci |
113 | aTool.BindVertex(P1,V1); |
114 | } |
115 | B.MakeWire(W); |
116 | for ( i=2; i<=Nb; i++){ |
117 | P2 = Poly->Value(i); |
118 | if (P1 == P2) continue; // peut arriver (KK) CKY 9-DEC-1997 |
119 | StepToTopoDS_PointPair PP(P1, P2); |
120 | StepToGeom_MakeCartesianPoint::Convert(P2,GP2); |
121 | TopoDS_Shape aBoundEdge; |
122 | Standard_Boolean isbound = aTool.IsEdgeBound(PP); |
123 | if ( !isbound) { |
124 | if (aTool.IsVertexBound(P2)) { |
125 | V2 = aTool.FindVertex(P2); |
126 | } |
127 | else { |
128 | B.MakeVertex(V2, GP2->Pnt(), Precision::Confusion()); //:S4136: preci |
129 | aTool.BindVertex(P2,V2); |
130 | } |
131 | V = gp_Vec( GP1->Pnt(), GP2->Pnt()); |
132 | L = new Geom_Line( GP1->Pnt() , gp_Dir(V) ); |
133 | B.MakeEdge(E, L, Precision::Confusion()); //:S4136: preci |
134 | V1.Orientation(TopAbs_FORWARD); |
135 | V2.Orientation(TopAbs_REVERSED); |
136 | B.Add(E, V1); |
137 | B.Add(E, V2); |
138 | Magn = V.Magnitude(); |
139 | B.UpdateVertex(V1, 0., E, 0. ); //:S4136: preci |
140 | B.UpdateVertex(V2, Magn, E, 0. ); //:S4136: preci |
141 | } |
142 | else { |
143 | aBoundEdge = aTool.FindEdge(PP); |
144 | E = TopoDS::Edge(aBoundEdge); |
145 | // Il faut qu en finale l edge soit vue |
146 | // - via sa premiere face, orientation combinee = celle de cette premiere face |
147 | // - via sa deuxieme face, orientation combinee INVERSE de la precedente |
148 | if (TopoFace.Orientation() == TopAbs_FORWARD) E.Reverse(); |
149 | V2 = aTool.FindVertex(P2); |
150 | // Standard_Real u1,v1,u2,v2; |
151 | // ElSLib::Parameters(SP->Pln(), GP1->Pnt(), u1, v1); |
152 | // ElSLib::Parameters(SP->Pln(), GP2->Pnt(), u2, v2); |
153 | // V2d = gp_Vec2d( gp_Pnt2d(u1,v1), gp_Pnt2d(u2,v2) ); |
154 | // L2d = new Geom2d_Line( gp_Pnt2d(u1,v1), gp_Dir2d(V2d) ); |
155 | } |
156 | gp_Pnt2d V2p1 = STSU->ValueOfUV (GP1->Pnt(), Precision()); |
157 | gp_Pnt2d V2p2 = STSU->ValueOfUV (GP2->Pnt(), Precision()); |
158 | if (E.Orientation() == TopAbs_FORWARD) { |
159 | V2d = gp_Vec2d( V2p1, V2p2 ); |
160 | L2d = new Geom2d_Line( V2p1, gp_Dir2d(V2d) ); |
161 | } else { |
162 | V2d = gp_Vec2d( V2p2, V2p1 ); |
163 | L2d = new Geom2d_Line( V2p2, gp_Dir2d(V2d) ); |
164 | } |
165 | B.UpdateEdge(E, L2d, TopoFace, 0.); |
166 | // E.Orientation(TopAbs_FORWARD); |
167 | TopoDS_Edge EB = E; // pour le binding : cumul des orientations ! |
168 | EB.Orientation (TopoFace.Orientation()); |
169 | if (!isbound) aTool.BindEdge(PP, EB); |
170 | if (!E.IsNull()) { |
171 | B.Add(W,E); |
172 | } |
173 | P1 = P2; |
174 | GP1 = GP2; |
175 | V1 = V2; |
176 | } |
177 | aTool.Bind(PL, W); |
178 | myResult = W; |
179 | myError = StepToTopoDS_TranslatePolyLoopDone; |
180 | done = Standard_True; |
181 | } |
182 | else { |
183 | myResult = TopoDS::Wire(aTool.Find(PL)); |
184 | myError = StepToTopoDS_TranslatePolyLoopDone; |
185 | done = Standard_True; |
186 | } |
187 | } |
188 | |
189 | // ============================================================================ |
190 | // Method : |
191 | // Purpose : |
192 | // ============================================================================ |
193 | |
194 | const TopoDS_Shape& StepToTopoDS_TranslatePolyLoop::Value() const |
195 | { |
196 | StdFail_NotDone_Raise_if(!done,""); |
197 | return myResult; |
198 | } |
199 | |
200 | // ============================================================================ |
201 | // Method : |
202 | // Purpose : |
203 | // ============================================================================ |
204 | |
205 | StepToTopoDS_TranslatePolyLoopError StepToTopoDS_TranslatePolyLoop::Error() const |
206 | { |
207 | return myError; |
208 | } |