b311480e |
1 | // Created on: 1993-11-10 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1993-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 | |
c22b52d6 |
18 | #include <Adaptor2d_Curve2d.hxx> |
42cf5bc1 |
19 | #include <Adaptor3d_HVertex.hxx> |
7fd59977 |
20 | #include <BRepAdaptor_Curve2d.hxx> |
42cf5bc1 |
21 | #include <BRepTopAdaptor_HVertex.hxx> |
22 | #include <gp_Pnt.hxx> |
7fd59977 |
23 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
24 | #include <IntPatch_Point.hxx> |
7fd59977 |
25 | #include <Precision.hxx> |
42cf5bc1 |
26 | #include <Standard_DomainError.hxx> |
27 | #include <TCollection_AsciiString.hxx> |
28 | #include <TopoDS.hxx> |
29 | #include <TopoDS_Edge.hxx> |
30 | #include <TopoDS_Face.hxx> |
31 | #include <TopoDS_Shape.hxx> |
7fd59977 |
32 | #include <TopOpeBRep_define.hxx> |
42cf5bc1 |
33 | #include <TopOpeBRep_FFTransitionTool.hxx> |
34 | #include <TopOpeBRep_VPointInter.hxx> |
35 | #include <TopOpeBRepDS_Transition.hxx> |
36 | #include <TopOpeBRepTool_ShapeTool.hxx> |
7fd59977 |
37 | |
0797d9d3 |
38 | #ifdef OCCT_DEBUG |
7fd59977 |
39 | static TCollection_AsciiString PRODINP("dinp "); |
40 | #endif |
41 | |
42 | //======================================================================= |
43 | //function : SetPoint |
44 | //purpose : |
45 | //======================================================================= |
46 | void TopOpeBRep_VPointInter::SetPoint(const IntPatch_Point& P) |
47 | { |
48 | myPPOI = (IntPatch_Point*)&P; |
49 | |
50 | Standard_Boolean isOn1 = P.IsOnDomS1(); |
51 | Standard_Boolean isOn2 = P.IsOnDomS2(); |
52 | if (isOn1 && isOn2) myShapeIndex = 3; |
53 | else if (isOn2) myShapeIndex = 2; |
54 | else if (isOn1) myShapeIndex = 1; |
55 | else myShapeIndex = 0; |
56 | } |
57 | |
58 | //======================================================================= |
59 | //function : ArcOnS1 |
60 | //purpose : |
61 | //======================================================================= |
62 | const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS1() const |
63 | { |
c22b52d6 |
64 | const Handle(Adaptor2d_Curve2d)& HAHC2 = myPPOI->ArcOnS1(); |
65 | const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)HAHC2.get()); |
7fd59977 |
66 | return BRAC2P.Edge(); |
67 | } |
68 | |
69 | //======================================================================= |
70 | //function : ArcOnS2 |
71 | //purpose : |
72 | //======================================================================= |
73 | const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS2() const |
74 | { |
c22b52d6 |
75 | const Handle(Adaptor2d_Curve2d)& HAHC2 = myPPOI->ArcOnS2(); |
76 | const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)HAHC2.get()); |
7fd59977 |
77 | return BRAC2P.Edge(); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : VertexOnS1 |
82 | //purpose : |
83 | //======================================================================= |
84 | const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS1() const |
85 | { |
86 | if ( !myPPOI->IsVertexOnS1() ) |
9775fa61 |
87 | throw Standard_DomainError("TopOpeBRep_VPointInter::VertexOnS1"); |
7fd59977 |
88 | |
89 | const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS1()); |
90 | return (*HBRTAHV)->Vertex(); |
91 | } |
92 | |
93 | //======================================================================= |
94 | //function : VertexOnS2 |
95 | //purpose : |
96 | //======================================================================= |
97 | const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS2() const |
98 | { |
99 | if ( !myPPOI->IsVertexOnS2() ) |
9775fa61 |
100 | throw Standard_DomainError("TopOpeBRep_VPointInter::VertexOnS2"); |
7fd59977 |
101 | |
102 | const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS2()); |
103 | return (*HBRTAHV)->Vertex(); |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : State |
108 | //purpose : |
109 | //======================================================================= |
110 | void TopOpeBRep_VPointInter::State(const TopAbs_State S,const Standard_Integer I) |
111 | { |
112 | if (I == 1) myState1 = S; |
113 | else if (I == 2) myState2 = S; |
9775fa61 |
114 | else throw Standard_DomainError("TopOpeBRep_VPointInter::State"); |
7fd59977 |
115 | UpdateKeep(); |
116 | } |
117 | |
118 | //======================================================================= |
119 | //function : State |
120 | //purpose : |
121 | //======================================================================= |
122 | TopAbs_State TopOpeBRep_VPointInter::State(const Standard_Integer I) const |
123 | { |
124 | if (I == 1) return myState1; |
125 | else if (I == 2) return myState2; |
9775fa61 |
126 | else { throw Standard_DomainError("TopOpeBRep_VPointInter::State");} |
7fd59977 |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : EdgeON |
131 | //purpose : |
132 | //======================================================================= |
133 | void TopOpeBRep_VPointInter::EdgeON(const TopoDS_Shape& Eon,const Standard_Real Par,const Standard_Integer I) |
134 | { |
135 | if (I == 1) { |
136 | myEdgeON1 = Eon; |
137 | myEdgeONPar1 = Par; |
138 | } |
139 | else if (I == 2) { |
140 | myEdgeON2 = Eon; |
141 | myEdgeONPar2 = Par; |
142 | } |
143 | } |
144 | |
145 | //======================================================================= |
146 | //function : EdgeON |
147 | //purpose : |
148 | //======================================================================= |
149 | const TopoDS_Shape& TopOpeBRep_VPointInter::EdgeON(const Standard_Integer I) const |
150 | { |
151 | if (I == 1) return myEdgeON1; |
152 | else if (I == 2) return myEdgeON2; |
9775fa61 |
153 | else throw Standard_DomainError("TopOpeBRep_VPointInter::EdgeON"); |
7fd59977 |
154 | } |
155 | |
156 | //======================================================================= |
157 | //function : EdgeONParameter |
158 | //purpose : |
159 | //======================================================================= |
160 | Standard_Real TopOpeBRep_VPointInter::EdgeONParameter(const Standard_Integer I) const |
161 | { |
162 | if (I == 1) return myEdgeONPar1; |
163 | else if (I == 2) return myEdgeONPar2; |
9775fa61 |
164 | else throw Standard_DomainError("TopOpeBRep_VPointInter::EdgeONParameter"); |
7fd59977 |
165 | } |
166 | |
167 | //======================================================================= |
168 | //function : Edge |
169 | //purpose : |
170 | //======================================================================= |
171 | const TopoDS_Shape& TopOpeBRep_VPointInter::Edge(const Standard_Integer I) const |
172 | { |
173 | if (I == 1 && IsOnDomS1() ) return ArcOnS1(); |
174 | else if (I == 2 && IsOnDomS2() ) return ArcOnS2(); |
175 | |
176 | return myNullShape; |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : EdgeParameter |
181 | //purpose : |
182 | //======================================================================= |
183 | Standard_Real TopOpeBRep_VPointInter::EdgeParameter(const Standard_Integer I) const |
184 | { |
185 | if (I == 1 && IsOnDomS1() ) return ParameterOnArc1(); |
186 | else if (I == 2 && IsOnDomS2() ) return ParameterOnArc2(); |
187 | return 0.; |
188 | } |
189 | |
190 | //======================================================================= |
191 | //function : EdgeParameter |
192 | //purpose : |
193 | //======================================================================= |
194 | gp_Pnt2d TopOpeBRep_VPointInter::SurfaceParameters(const Standard_Integer I) const |
195 | { |
196 | Standard_Real u = 0., v = 0.; |
197 | //if (I == 1 && IsOnDomS1() ) ParametersOnS1(u,v); |
198 | //else if (I == 2 && IsOnDomS1() ) ParametersOnS2(u,v); |
199 | if (I == 1 ) ParametersOnS1(u,v); |
200 | else if (I == 2 ) ParametersOnS2(u,v); |
201 | gp_Pnt2d p2d(u,v); |
202 | return p2d; |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : IsVertex |
207 | //purpose : |
208 | //======================================================================= |
209 | Standard_Boolean TopOpeBRep_VPointInter::IsVertex(const Standard_Integer I) const |
210 | { |
211 | if ( I == 0 ) return Standard_False; |
212 | if ( I == 1 && IsVertexOnS1() ) return Standard_True; |
213 | else if ( I == 2 && IsVertexOnS2() ) return Standard_True; |
214 | return Standard_False; |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : Vertex |
219 | //purpose : |
220 | //======================================================================= |
221 | const TopoDS_Shape& TopOpeBRep_VPointInter::Vertex(const Standard_Integer I) const |
222 | { |
223 | if ( I == 1 && IsVertexOnS1() ) return VertexOnS1(); |
224 | else if ( I == 2 && IsVertexOnS2() ) return VertexOnS2(); |
225 | return myNullShape; |
226 | } |
227 | |
228 | //======================================================================= |
229 | //function : UpdateKeep |
230 | //purpose : |
231 | //======================================================================= |
232 | void TopOpeBRep_VPointInter::UpdateKeep() |
233 | { |
234 | #define M_SINON(s) (((s) == TopAbs_IN) || ((s) == TopAbs_ON)) |
235 | |
236 | TopAbs_State pos1 = State(1); |
237 | TopAbs_State pos2 = State(2); |
238 | |
239 | Standard_Integer SI = ShapeIndex(); |
240 | |
7fd59977 |
241 | Standard_Boolean condition=Standard_False; |
1d47d8d0 |
242 | |
7fd59977 |
243 | if (SI == 1) condition = M_SINON(pos2); |
244 | else if (SI == 2) condition = M_SINON(pos1); |
245 | else if (SI == 0) condition = M_SINON(pos1) && M_SINON(pos2); |
246 | else if (SI == 3) condition = M_SINON(pos1) && M_SINON(pos2); |
247 | // NYI : SI == 3 --> le VP devrait toujours etre Keep() (par definition) |
248 | |
249 | myKeep = condition; |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : EqualpP |
254 | //purpose : returns <True> if the 3d points and the parameters of the |
255 | // VPoints are same. |
256 | //======================================================================= |
257 | Standard_Boolean TopOpeBRep_VPointInter::EqualpP(const TopOpeBRep_VPointInter& VP) const |
258 | { |
259 | Standard_Real p1 = ParameterOnLine(); |
260 | Standard_Real p2 = VP.ParameterOnLine(); |
261 | Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion(); |
262 | gp_Pnt P1 = Value(); gp_Pnt P2 = VP.Value(); |
263 | Standard_Real Ptol1 = Tolerance(), Ptol2 = VP.Tolerance(); |
264 | Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2; |
265 | Standard_Boolean Pequal = P1.IsEqual(P2,Ptol); |
266 | Standard_Boolean pPequal = ( pequal && Pequal ); |
267 | return pPequal; |
268 | } |
269 | |
270 | //======================================================================= |
271 | //function : |
272 | //purpose : |
273 | //======================================================================= |
274 | Standard_Boolean TopOpeBRep_VPointInter::ParonE(const TopoDS_Edge& E,Standard_Real& par) const |
275 | { |
276 | Standard_Boolean found = Standard_False; |
277 | if (IsOnDomS1()) { |
278 | if(E.IsSame(ArcOnS1())) found = Standard_True; |
279 | if (found) {par = ParameterOnArc1(); return found;} |
280 | } |
281 | if (IsOnDomS2()) { |
282 | if(E.IsSame(ArcOnS2())) found = Standard_True; |
283 | if (found) {par = ParameterOnArc2(); return found;} |
284 | } |
285 | |
286 | for (Standard_Integer i = 1; i <= 2; i++) { |
287 | if (State(i) != TopAbs_ON) continue; |
288 | if (EdgeON(i).IsSame(E)) { |
289 | par = EdgeONParameter(i); |
290 | return Standard_True; |
291 | } |
292 | } |
293 | return found; |
294 | } |
295 | |
296 | //======================================================================= |
297 | //function : DumpEdge |
298 | //purpose : |
299 | //======================================================================= |
300 | Standard_OStream& TopOpeBRep_VPointInter::Dump(const Standard_Integer I,const TopoDS_Face& F,Standard_OStream& OS) const |
301 | { |
302 | const TopoDS_Edge& E = TopoDS::Edge(Edge(I)); |
0797d9d3 |
303 | #ifdef OCCT_DEBUG |
7fd59977 |
304 | Standard_Real Epar = |
305 | #endif |
306 | EdgeParameter(I); |
0797d9d3 |
307 | #ifdef OCCT_DEBUG |
7fd59977 |
308 | TopAbs_Orientation O = |
309 | #endif |
310 | E.Orientation(); |
0797d9d3 |
311 | #ifdef OCCT_DEBUG |
7fd59977 |
312 | Standard_Boolean closingedge = |
313 | #endif |
314 | TopOpeBRepTool_ShapeTool::Closed(E,F); |
315 | |
0797d9d3 |
316 | #ifdef OCCT_DEBUG |
04232180 |
317 | if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,std::cout); |
318 | std::cout<<" of "<<I<<" : par : "<<Epar<<std::endl; |
536a3cb8 |
319 | TopOpeBRep_FFTransitionTool::ProcessLineTransition(*this,I,O); |
7fd59977 |
320 | OS<<"line transition "; |
04232180 |
321 | if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,std::cout); |
322 | OS<<" of "<<I<<std::endl; |
7fd59977 |
323 | #endif |
324 | |
325 | return OS; |
326 | } |
327 | |
328 | //======================================================================= |
329 | //function : Dump |
330 | //purpose : |
331 | //======================================================================= |
0797d9d3 |
332 | #ifdef OCCT_DEBUG |
7fd59977 |
333 | Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face& FF1,const TopoDS_Face& FF2,Standard_OStream& OS) const |
334 | { |
7fd59977 |
335 | const TopoDS_Face& F1 = TopoDS::Face(FF1); |
336 | const TopoDS_Face& F2 = TopoDS::Face(FF2); |
337 | OS<<"VP "<<myIndex<<" on "<<myShapeIndex<<" :"; |
338 | Standard_Real Cpar = ParameterOnLine(); OS<<" on curve : "<<Cpar; |
339 | if (!myKeep) OS<<" NOT kept"; |
04232180 |
340 | OS<<std::endl; |
7fd59977 |
341 | const gp_Pnt& P = Value(); |
342 | OS<<PRODINP<<"P"<<myIndex<<" "; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z(); |
04232180 |
343 | OS<<"; #draw"<<std::endl; |
7fd59977 |
344 | |
04232180 |
345 | if (IsVertexOnS1()) { OS<<"is vertex of 1"<<std::endl; } |
346 | if (IsVertexOnS2()) { OS<<"is vertex of 2"<<std::endl; } |
347 | if (IsMultiple()) { OS<<"is multiple"<<std::endl; } |
348 | if (IsInternal()) { OS<<"is internal"<<std::endl; } |
7fd59977 |
349 | |
350 | if (myShapeIndex == 1) { |
351 | Dump(1,F1,OS); |
352 | } |
353 | else if (myShapeIndex == 2) { |
354 | Dump(2,F2,OS); |
355 | } |
356 | else if (myShapeIndex == 3) { |
357 | Dump(1,F1,OS); |
358 | Dump(2,F2,OS); |
359 | } |
498ce76b |
360 | #else |
361 | Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face&,const TopoDS_Face&,Standard_OStream& OS) const |
362 | { |
7fd59977 |
363 | #endif |
364 | |
365 | return OS; |
366 | } |
367 | |
368 | //======================================================================= |
369 | //function : PThePointOfIntersectionDummy |
370 | //purpose : |
371 | //======================================================================= |
372 | TopOpeBRep_PThePointOfIntersection TopOpeBRep_VPointInter::PThePointOfIntersectionDummy() const |
373 | { |
374 | return myPPOI; |
375 | } |