1 // Created on: 1995-01-03
2 // Created by: Frederic MAUPAS
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 //gka,abv 14.09.99: S4136: eliminate BRepAPI::Precision()
19 #include <BRep_Builder.hxx>
21 #include <Geom2d_Line.hxx>
22 #include <Geom_CartesianPoint.hxx>
23 #include <Geom_Line.hxx>
24 #include <Geom_Plane.hxx>
25 #include <Geom_Surface.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <Precision.hxx>
28 #include <ShapeAnalysis_Surface.hxx>
29 #include <StdFail_NotDone.hxx>
30 #include <StepGeom_HArray1OfCartesianPoint.hxx>
31 #include <StepShape_PolyLoop.hxx>
32 #include <StepToGeom.hxx>
33 #include <StepToTopoDS_PointPair.hxx>
34 #include <StepToTopoDS_Tool.hxx>
35 #include <StepToTopoDS_TranslatePolyLoop.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>
42 #include <Transfer_TransientProcess.hxx>
44 //#include <BRepAPI.hxx>
45 // ============================================================================
48 // ============================================================================
49 StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop()
51 done = Standard_False;
54 // ============================================================================
57 // ============================================================================
59 StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& T, const Handle(Geom_Surface)& S, const TopoDS_Face& F)
64 // ============================================================================
67 // ============================================================================
69 void StepToTopoDS_TranslatePolyLoop::Init(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& aTool, const Handle(Geom_Surface)& GeomSurf, const TopoDS_Face& TopoFace)
71 if (!aTool.IsBound(PL)) {
73 Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
75 //:S4136 Standard_Real preci = BRepAPI::Precision();
77 Handle(StepGeom_CartesianPoint) P1,P2;
78 Handle(Geom_CartesianPoint) GP1, GP2;
83 Handle(Geom2d_Line) L2d;
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);
94 for ( i=1; i<=Nb; i++ )
95 Poly->SetValue(i, PL->PolygonValue(i));
98 Poly->SetValue(Nb, PL->PolygonValue(1));
100 GP1 = StepToGeom::MakeCartesianPoint (P1);
101 if (aTool.IsVertexBound(P1)) {
102 V1 = aTool.FindVertex(P1);
105 B.MakeVertex(V1, GP1->Pnt(), Precision::Confusion()); //:S4136: preci
106 aTool.BindVertex(P1,V1);
109 for ( i=2; i<=Nb; i++){
111 if (P1 == P2) continue; // peut arriver (KK) CKY 9-DEC-1997
112 StepToTopoDS_PointPair PP(P1, P2);
113 GP2 = StepToGeom::MakeCartesianPoint (P2);
114 TopoDS_Shape aBoundEdge;
115 Standard_Boolean isbound = aTool.IsEdgeBound(PP);
117 if (aTool.IsVertexBound(P2)) {
118 V2 = aTool.FindVertex(P2);
121 B.MakeVertex(V2, GP2->Pnt(), Precision::Confusion()); //:S4136: preci
122 aTool.BindVertex(P2, V2);
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);
131 Magn = V.Magnitude();
132 B.UpdateVertex(V1, 0., E, 0.); //:S4136: preci
133 B.UpdateVertex(V2, Magn, E, 0.); //:S4136: preci
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);
144 gp_Pnt2d V2p1 = STSU->ValueOfUV (GP1->Pnt(), Precision());
145 gp_Pnt2d V2p2 = STSU->ValueOfUV (GP2->Pnt(), Precision());
146 if (E.Orientation() == TopAbs_FORWARD) {
147 V2d = gp_Vec2d(V2p1, V2p2);
148 L2d = new Geom2d_Line(V2p1, gp_Dir2d(V2d));
151 V2d = gp_Vec2d(V2p2, V2p1);
152 L2d = new Geom2d_Line(V2p2, gp_Dir2d(V2d));
154 B.UpdateEdge(E, L2d, TopoFace, 0.);
155 TopoDS_Edge EB = E; // pour le binding : cumul des orientations !
156 EB.Orientation (TopoFace.Orientation());
157 if (!isbound) aTool.BindEdge(PP, EB);
165 W.Closed (BRep_Tool::IsClosed (W));
168 myError = StepToTopoDS_TranslatePolyLoopDone;
169 done = Standard_True;
172 myResult = TopoDS::Wire(aTool.Find(PL));
173 myError = StepToTopoDS_TranslatePolyLoopDone;
174 done = Standard_True;
178 // ============================================================================
181 // ============================================================================
183 const TopoDS_Shape& StepToTopoDS_TranslatePolyLoop::Value() const
185 StdFail_NotDone_Raise_if (!done, "StepToTopoDS_TranslatePolyLoop::Value() - no result");
189 // ============================================================================
192 // ============================================================================
194 StepToTopoDS_TranslatePolyLoopError StepToTopoDS_TranslatePolyLoop::Error() const