summaryrefslogtreecommitdiff
path: root/src/StepToTopoDS/StepToTopoDS_TranslatePolyLoop.cxx
blob: 8479e07ceb5c064a4734861fe9dd96e66e59055c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// File:	StepToTopoDS_TranslatePolyLoop.cxx
// Created:	Tue Jan  3 13:58:54 1995
// Author:	Frederic MAUPAS
//		<fma@stylox>
//gka,abv 14.09.99: S4136: eliminate BRepAPI::Precision()

#include <StepToTopoDS_TranslatePolyLoop.ixx>

#include <StepToTopoDS_PointPair.hxx>

#include <StepToGeom_MakeCartesianPoint.hxx>

#include <BRep_Builder.hxx>
//#include <BRepAPI.hxx>

#include <ElSLib.hxx>
#include <ShapeAnalysis_Surface.hxx>

#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Edge.hxx>

#include <Geom2d_Line.hxx>
#include <Geom_Line.hxx>
#include <Geom_Plane.hxx>
#include <Geom_CartesianPoint.hxx>

#include <gp_Vec2d.hxx>

#include <StepGeom_HArray1OfCartesianPoint.hxx>
#include <Transfer_TransientProcess.hxx>
#include <Precision.hxx>

// ============================================================================
// Method  :
// Purpose :
// ============================================================================

StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop()
{
  done = Standard_False;
}

// ============================================================================
// Method  :
// Purpose :
// ============================================================================

StepToTopoDS_TranslatePolyLoop::StepToTopoDS_TranslatePolyLoop(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& T, const Handle(Geom_Surface)& S, const TopoDS_Face& F)
{
  Init (PL, T, S, F);
}

// ============================================================================
// Method  :
// Purpose :
// ============================================================================

void StepToTopoDS_TranslatePolyLoop::Init(const Handle(StepShape_PolyLoop)& PL, StepToTopoDS_Tool& aTool, const Handle(Geom_Surface)& GeomSurf, const TopoDS_Face& TopoFace)
{
  if (!aTool.IsBound(PL)) {
    BRep_Builder B;
    Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();

//:S4136    Standard_Real preci = BRepAPI::Precision();
    Standard_Integer i;
    Handle(StepGeom_CartesianPoint) P1,P2;
    Handle(Geom_CartesianPoint) GP1, GP2;
    TopoDS_Vertex V1, V2;
    TopoDS_Edge E;
    TopoDS_Wire W;
    Handle(Geom_Line) L;
    Handle(Geom2d_Line) L2d;
    gp_Vec V;
    gp_Vec2d V2d;
    Standard_Real Magn;
    Handle(Geom_Plane) SP = Handle(Geom_Plane)::DownCast(GeomSurf);
    if (SP.IsNull()) TP->AddFail(PL,"Surface not planar in a FacetedBRep !");
    Handle(ShapeAnalysis_Surface) STSU = new ShapeAnalysis_Surface ( GeomSurf );
    Standard_Integer Nb = PL->NbPolygon();
    Handle(StepGeom_HArray1OfCartesianPoint) Poly = 
      new StepGeom_HArray1OfCartesianPoint(1, Nb+1);

    for ( i=1; i<=Nb; i++ )
      Poly->SetValue(i, PL->PolygonValue(i));

    Nb++;
    Poly->SetValue(Nb, PL->PolygonValue(1));
    P1 = Poly->Value(1);
	StepToGeom_MakeCartesianPoint::Convert(P1,GP1);
    if (aTool.IsVertexBound(P1)) {
      V1 = aTool.FindVertex(P1);
    }
    else {
      B.MakeVertex(V1, GP1->Pnt(), Precision::Confusion()); //:S4136: preci
      aTool.BindVertex(P1,V1);
    }
    B.MakeWire(W);
    for ( i=2; i<=Nb; i++){
      P2 = Poly->Value(i);
      if (P1 == P2) continue;  // peut arriver (KK)  CKY 9-DEC-1997
      StepToTopoDS_PointPair PP(P1, P2); 
      StepToGeom_MakeCartesianPoint::Convert(P2,GP2);
      TopoDS_Shape aBoundEdge;
      Standard_Boolean isbound = aTool.IsEdgeBound(PP);
      if ( !isbound) {
	if (aTool.IsVertexBound(P2)) {
	  V2 = aTool.FindVertex(P2);
	}
	else {
	  B.MakeVertex(V2, GP2->Pnt(), Precision::Confusion()); //:S4136: preci
	  aTool.BindVertex(P2,V2);
	}
	V = gp_Vec( GP1->Pnt(), GP2->Pnt());
	L = new Geom_Line( GP1->Pnt() , gp_Dir(V) );
	B.MakeEdge(E, L, Precision::Confusion()); //:S4136: preci
	V1.Orientation(TopAbs_FORWARD);
	V2.Orientation(TopAbs_REVERSED);
	B.Add(E, V1);
	B.Add(E, V2);
	Magn = V.Magnitude();
	B.UpdateVertex(V1, 0., E, 0. ); //:S4136: preci
	B.UpdateVertex(V2, Magn, E, 0. ); //:S4136: preci
      } 
      else {
	aBoundEdge = aTool.FindEdge(PP);
	E = TopoDS::Edge(aBoundEdge);
//  Il faut qu en finale l edge soit vue
//  - via sa premiere face, orientation combinee = celle de cette premiere face
//  - via sa deuxieme face, orientation combinee INVERSE de la precedente
	if (TopoFace.Orientation() == TopAbs_FORWARD) E.Reverse();
	V2 = aTool.FindVertex(P2); 
//	Standard_Real u1,v1,u2,v2;
//	ElSLib::Parameters(SP->Pln(), GP1->Pnt(), u1, v1);
//	ElSLib::Parameters(SP->Pln(), GP2->Pnt(), u2, v2);
//	V2d = gp_Vec2d( gp_Pnt2d(u1,v1), gp_Pnt2d(u2,v2) );
//	L2d = new Geom2d_Line( gp_Pnt2d(u1,v1), gp_Dir2d(V2d) );
      }
      gp_Pnt2d V2p1 = STSU->ValueOfUV (GP1->Pnt(), Precision());
      gp_Pnt2d V2p2 = STSU->ValueOfUV (GP2->Pnt(), Precision());
      if (E.Orientation() == TopAbs_FORWARD) {
	V2d = gp_Vec2d( V2p1, V2p2 );
	L2d = new Geom2d_Line( V2p1, gp_Dir2d(V2d) );
      } else {
	V2d = gp_Vec2d( V2p2, V2p1 );
	L2d = new Geom2d_Line( V2p2, gp_Dir2d(V2d) );
      }
      B.UpdateEdge(E, L2d, TopoFace, 0.);
//      E.Orientation(TopAbs_FORWARD);
      TopoDS_Edge EB = E;  // pour le binding : cumul des orientations !
      EB.Orientation (TopoFace.Orientation());
      if (!isbound) aTool.BindEdge(PP, EB);
      if (!E.IsNull()) { 
	B.Add(W,E);
      }
      P1  = P2;
      GP1 = GP2;
      V1  = V2;
    }
    aTool.Bind(PL, W);
    myResult = W;
    myError  = StepToTopoDS_TranslatePolyLoopDone;
    done     = Standard_True;
  }
  else {
    myResult = TopoDS::Wire(aTool.Find(PL));
    myError  = StepToTopoDS_TranslatePolyLoopDone;
    done     = Standard_True;    
  }
}

// ============================================================================
// Method  :
// Purpose :
// ============================================================================

const TopoDS_Shape& StepToTopoDS_TranslatePolyLoop::Value() const 
{
  StdFail_NotDone_Raise_if(!done,"");
  return myResult;
}

// ============================================================================
// Method  :
// Purpose :
// ============================================================================

StepToTopoDS_TranslatePolyLoopError StepToTopoDS_TranslatePolyLoop::Error() const
{
  return myError;
}