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