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