Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_EdgeInterferenceTool.cxx
CommitLineData
7fd59977 1// File: TopOpeBRepDS_EdgeInterferenceTool.cxx
2// Created: Tue Nov 8 14:52:21 1994
3// Author: Jean Yves LEBEY
4// <jyl@bravox>
5
6#include <TopOpeBRepDS_EdgeInterferenceTool.ixx>
7
8#include <TopOpeBRepDS_CurvePointInterference.hxx>
9#include <TopOpeBRepDS_EdgeVertexInterference.hxx>
10#include <BRepLProp_CLProps.hxx>
11#include <BRep_Tool.hxx>
12#include <TopoDS_Iterator.hxx>
13#include <Precision.hxx>
14#include <TopoDS.hxx>
15#include <TopOpeBRepTool_ShapeTool.hxx>
16#include <Standard_ProgramError.hxx>
17
18#ifdef DEB
19Standard_EXPORT Standard_Boolean TopOpeBRepDS_GettracePEI();
20#endif
21
22//=======================================================================
23//function : TopOpeBRepDS_EdgeInterferenceTool
24//purpose :
25//=======================================================================
26
27 TopOpeBRepDS_EdgeInterferenceTool::TopOpeBRepDS_EdgeInterferenceTool()
28{
29}
30
31static Standard_Real Parameter(const Handle(TopOpeBRepDS_Interference)& I)
32{
33 Standard_Real p = 0;
34 if ( I->IsKind(STANDARD_TYPE(TopOpeBRepDS_EdgeVertexInterference)) )
35 p = Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I)->Parameter();
36 else if ( I->IsKind(STANDARD_TYPE(TopOpeBRepDS_CurvePointInterference)) )
37 p = Handle(TopOpeBRepDS_CurvePointInterference)::DownCast(I)->Parameter();
38 else {
39#ifdef DEB
40 cout<<"EdgeInterference : mauvais type d'interference"<<endl;
41#endif
42 Standard_ProgramError::Raise("TopOpeBRepDS_EdgeInterferenceTool1");
43 }
44 return p;
45}
46
47
48//=======================================================================
49//function : Init
50//purpose :
51//=======================================================================
52
53void TopOpeBRepDS_EdgeInterferenceTool::Init
54(const TopoDS_Shape& E, const Handle(TopOpeBRepDS_Interference)& I)
55{
56 myEdgeOrientation = E.Orientation();
57 myEdgeOriented = I->Support();
58
59 // NYI 971219 : on ne tient pas compte de l'orientation de E = arete-mere de l'interference I
60 if (myEdgeOrientation == TopAbs_INTERNAL ||
61 myEdgeOrientation == TopAbs_EXTERNAL) {
62 return;
63 }
64
65 // la premiere arete orientee est gardee dans myEdgeOriented pour MAJ de
66 // l'arete croisee dans l'interference resultat.
67
68 // par = parametre sur l'arete croisee
69 Standard_Real par = ::Parameter(I);
70 gp_Dir T,N; Standard_Real C;
71 TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
72 myTool.Reset(T,N,C);
73}
74
75//=======================================================================
76//function : Add
77//purpose :
78//=======================================================================
79
80void TopOpeBRepDS_EdgeInterferenceTool::Add
81(const TopoDS_Shape& E,
82 const TopoDS_Shape& V,
83 const Handle(TopOpeBRepDS_Interference)& I)
84{
85 TopAbs_Orientation Eori = E.Orientation();
86 if (Eori == TopAbs_INTERNAL ||
87 Eori == TopAbs_EXTERNAL) {
88 return;
89 }
90
91 // premiere interference sur arete orientee : Init
92 if (myEdgeOrientation == TopAbs_INTERNAL ||
93 myEdgeOrientation == TopAbs_EXTERNAL) {
94 Init(E,I);
95 return;
96 }
97
98 // V est un sommet de E ?
99 Standard_Boolean VofE = Standard_False;
100 TopoDS_Iterator it(E,Standard_False);
101 for ( ; it.More(); it.Next() ) {
102 const TopoDS_Shape& S = it.Value();
103 if ( S.IsSame(V) ) {
104 VofE = Standard_True;
105 break;
106 }
107 }
108
109#ifdef DEB
110 if (TopOpeBRepDS_GettracePEI() && !VofE) {
111 cout<<"===================== VofE = False"<<endl;
112 }
113#endif
114
115 // V est un sommet de E
116 const TopoDS_Vertex& VV = TopoDS::Vertex(V);
117 const TopoDS_Edge& EE = TopoDS::Edge(E);
118 Standard_Real par = BRep_Tool::Parameter(VV,EE);
119
120 gp_Dir T,N; Standard_Real C;
121 Standard_Real tol = TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
122 TopAbs_Orientation oriloc = I->Transition().Orientation(TopAbs_IN);
123 TopAbs_Orientation oritan = it.Value().Orientation();
124 myTool.Compare(tol,T,N,C,oriloc,oritan);
125}
126
127//=======================================================================
128//function : Add
129//purpose :
130//=======================================================================
131
132void TopOpeBRepDS_EdgeInterferenceTool::Add
133(const TopoDS_Shape& E,
134// const TopOpeBRepDS_Point& P,
135 const TopOpeBRepDS_Point& ,
136 const Handle(TopOpeBRepDS_Interference)& I)
137{
138 TopAbs_Orientation Eori = E.Orientation();
139 if (Eori == TopAbs_INTERNAL ||
140 Eori == TopAbs_EXTERNAL) {
141 return;
142 }
143
144 // premiere interference sur arete orientee : Init
145 if (myEdgeOrientation == TopAbs_INTERNAL ||
146 myEdgeOrientation == TopAbs_EXTERNAL) {
147 Init(E,I);
148 return;
149 }
150
151 Standard_Real par = ::Parameter(I);
152
153 gp_Dir T,N; Standard_Real C;
154 Standard_Real tol = TopOpeBRepTool_ShapeTool::EdgeData(E,par,T,N,C);
155 TopAbs_Orientation oriloc = I->Transition().Orientation(TopAbs_IN);
156 TopAbs_Orientation oritan = TopAbs_INTERNAL;
157 myTool.Compare(tol,T,N,C,oriloc,oritan);
158}
159
160//=======================================================================
161//function : Transition
162//purpose :
163//=======================================================================
164
165void TopOpeBRepDS_EdgeInterferenceTool::Transition
166(const Handle(TopOpeBRepDS_Interference)& I) const
167{
168 TopOpeBRepDS_Transition& T = I->ChangeTransition();
169
170 if (myEdgeOrientation == TopAbs_INTERNAL) {
171 T.Set(TopAbs_IN,TopAbs_IN);
172 }
173 else if (myEdgeOrientation == TopAbs_EXTERNAL) {
174 T.Set(TopAbs_OUT,TopAbs_OUT);
175 }
176 else {
177 I->Support(myEdgeOriented);
178 T.Set(myTool.StateBefore(),myTool.StateAfter());
179 }
180}