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