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