1 // Created on: 1993-11-10
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HVertex.hxx>
20 #include <BRepAdaptor_Curve2d.hxx>
21 #include <BRepAdaptor_HCurve2d.hxx>
22 #include <BRepTopAdaptor_HVertex.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <IntPatch_Point.hxx>
26 #include <Precision.hxx>
27 #include <Standard_DomainError.hxx>
28 #include <TCollection_AsciiString.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopOpeBRep_define.hxx>
34 #include <TopOpeBRep_FFTransitionTool.hxx>
35 #include <TopOpeBRep_VPointInter.hxx>
36 #include <TopOpeBRepDS_Transition.hxx>
37 #include <TopOpeBRepTool_ShapeTool.hxx>
40 static TCollection_AsciiString PRODINP("dinp ");
43 //=======================================================================
46 //=======================================================================
47 void TopOpeBRep_VPointInter::SetPoint(const IntPatch_Point& P)
49 myPPOI = (IntPatch_Point*)&P;
51 Standard_Boolean isOn1 = P.IsOnDomS1();
52 Standard_Boolean isOn2 = P.IsOnDomS2();
53 if (isOn1 && isOn2) myShapeIndex = 3;
54 else if (isOn2) myShapeIndex = 2;
55 else if (isOn1) myShapeIndex = 1;
56 else myShapeIndex = 0;
59 //=======================================================================
62 //=======================================================================
63 const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS1() const
65 const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS1();
66 const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
70 //=======================================================================
73 //=======================================================================
74 const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS2() const
76 const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS2();
77 const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
81 //=======================================================================
82 //function : VertexOnS1
84 //=======================================================================
85 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS1() const
87 if ( !myPPOI->IsVertexOnS1() )
88 Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS1");
90 const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS1());
91 return (*HBRTAHV)->Vertex();
94 //=======================================================================
95 //function : VertexOnS2
97 //=======================================================================
98 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS2() const
100 if ( !myPPOI->IsVertexOnS2() )
101 Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS2");
103 const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS2());
104 return (*HBRTAHV)->Vertex();
107 //=======================================================================
110 //=======================================================================
111 void TopOpeBRep_VPointInter::State(const TopAbs_State S,const Standard_Integer I)
113 if (I == 1) myState1 = S;
114 else if (I == 2) myState2 = S;
115 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::State");
119 //=======================================================================
122 //=======================================================================
123 TopAbs_State TopOpeBRep_VPointInter::State(const Standard_Integer I) const
125 if (I == 1) return myState1;
126 else if (I == 2) return myState2;
127 else { Standard_DomainError::Raise("TopOpeBRep_VPointInter::State"); return TopAbs_UNKNOWN; }
130 //=======================================================================
133 //=======================================================================
134 void TopOpeBRep_VPointInter::EdgeON(const TopoDS_Shape& Eon,const Standard_Real Par,const Standard_Integer I)
146 //=======================================================================
149 //=======================================================================
150 const TopoDS_Shape& TopOpeBRep_VPointInter::EdgeON(const Standard_Integer I) const
152 if (I == 1) return myEdgeON1;
153 else if (I == 2) return myEdgeON2;
154 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeON");
158 //=======================================================================
159 //function : EdgeONParameter
161 //=======================================================================
162 Standard_Real TopOpeBRep_VPointInter::EdgeONParameter(const Standard_Integer I) const
164 if (I == 1) return myEdgeONPar1;
165 else if (I == 2) return myEdgeONPar2;
166 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeONParameter");
170 //=======================================================================
173 //=======================================================================
174 const TopoDS_Shape& TopOpeBRep_VPointInter::Edge(const Standard_Integer I) const
176 if (I == 1 && IsOnDomS1() ) return ArcOnS1();
177 else if (I == 2 && IsOnDomS2() ) return ArcOnS2();
182 //=======================================================================
183 //function : EdgeParameter
185 //=======================================================================
186 Standard_Real TopOpeBRep_VPointInter::EdgeParameter(const Standard_Integer I) const
188 if (I == 1 && IsOnDomS1() ) return ParameterOnArc1();
189 else if (I == 2 && IsOnDomS2() ) return ParameterOnArc2();
193 //=======================================================================
194 //function : EdgeParameter
196 //=======================================================================
197 gp_Pnt2d TopOpeBRep_VPointInter::SurfaceParameters(const Standard_Integer I) const
199 Standard_Real u = 0., v = 0.;
200 //if (I == 1 && IsOnDomS1() ) ParametersOnS1(u,v);
201 //else if (I == 2 && IsOnDomS1() ) ParametersOnS2(u,v);
202 if (I == 1 ) ParametersOnS1(u,v);
203 else if (I == 2 ) ParametersOnS2(u,v);
208 //=======================================================================
209 //function : IsVertex
211 //=======================================================================
212 Standard_Boolean TopOpeBRep_VPointInter::IsVertex(const Standard_Integer I) const
214 if ( I == 0 ) return Standard_False;
215 if ( I == 1 && IsVertexOnS1() ) return Standard_True;
216 else if ( I == 2 && IsVertexOnS2() ) return Standard_True;
217 return Standard_False;
220 //=======================================================================
223 //=======================================================================
224 const TopoDS_Shape& TopOpeBRep_VPointInter::Vertex(const Standard_Integer I) const
226 if ( I == 1 && IsVertexOnS1() ) return VertexOnS1();
227 else if ( I == 2 && IsVertexOnS2() ) return VertexOnS2();
231 //=======================================================================
232 //function : UpdateKeep
234 //=======================================================================
235 void TopOpeBRep_VPointInter::UpdateKeep()
237 #define M_SINON(s) (((s) == TopAbs_IN) || ((s) == TopAbs_ON))
239 TopAbs_State pos1 = State(1);
240 TopAbs_State pos2 = State(2);
242 Standard_Integer SI = ShapeIndex();
244 Standard_Boolean condition=Standard_False;
246 if (SI == 1) condition = M_SINON(pos2);
247 else if (SI == 2) condition = M_SINON(pos1);
248 else if (SI == 0) condition = M_SINON(pos1) && M_SINON(pos2);
249 else if (SI == 3) condition = M_SINON(pos1) && M_SINON(pos2);
250 // NYI : SI == 3 --> le VP devrait toujours etre Keep() (par definition)
255 //=======================================================================
257 //purpose : returns <True> if the 3d points and the parameters of the
259 //=======================================================================
260 Standard_Boolean TopOpeBRep_VPointInter::EqualpP(const TopOpeBRep_VPointInter& VP) const
262 Standard_Real p1 = ParameterOnLine();
263 Standard_Real p2 = VP.ParameterOnLine();
264 Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion();
265 gp_Pnt P1 = Value(); gp_Pnt P2 = VP.Value();
266 Standard_Real Ptol1 = Tolerance(), Ptol2 = VP.Tolerance();
267 Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2;
268 Standard_Boolean Pequal = P1.IsEqual(P2,Ptol);
269 Standard_Boolean pPequal = ( pequal && Pequal );
273 //=======================================================================
276 //=======================================================================
277 Standard_Boolean TopOpeBRep_VPointInter::ParonE(const TopoDS_Edge& E,Standard_Real& par) const
279 Standard_Boolean found = Standard_False;
281 if(E.IsSame(ArcOnS1())) found = Standard_True;
282 if (found) {par = ParameterOnArc1(); return found;}
285 if(E.IsSame(ArcOnS2())) found = Standard_True;
286 if (found) {par = ParameterOnArc2(); return found;}
289 for (Standard_Integer i = 1; i <= 2; i++) {
290 if (State(i) != TopAbs_ON) continue;
291 if (EdgeON(i).IsSame(E)) {
292 par = EdgeONParameter(i);
293 return Standard_True;
299 //=======================================================================
300 //function : DumpEdge
302 //=======================================================================
303 Standard_OStream& TopOpeBRep_VPointInter::Dump(const Standard_Integer I,const TopoDS_Face& F,Standard_OStream& OS) const
305 const TopoDS_Edge& E = TopoDS::Edge(Edge(I));
311 TopAbs_Orientation O =
315 Standard_Boolean closingedge =
317 TopOpeBRepTool_ShapeTool::Closed(E,F);
320 if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
321 cout<<" of "<<I<<" : par : "<<Epar<<endl;
322 TopOpeBRep_FFTransitionTool::ProcessLineTransition(*this,I,O);
323 OS<<"line transition ";
324 if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
331 //=======================================================================
334 //=======================================================================
336 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face& FF1,const TopoDS_Face& FF2,Standard_OStream& OS) const
338 const TopoDS_Face& F1 = TopoDS::Face(FF1);
339 const TopoDS_Face& F2 = TopoDS::Face(FF2);
340 OS<<"VP "<<myIndex<<" on "<<myShapeIndex<<" :";
341 Standard_Real Cpar = ParameterOnLine(); OS<<" on curve : "<<Cpar;
342 if (!myKeep) OS<<" NOT kept";
344 const gp_Pnt& P = Value();
345 OS<<PRODINP<<"P"<<myIndex<<" "; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z();
348 if (IsVertexOnS1()) { OS<<"is vertex of 1"<<endl; }
349 if (IsVertexOnS2()) { OS<<"is vertex of 2"<<endl; }
350 if (IsMultiple()) { OS<<"is multiple"<<endl; }
351 if (IsInternal()) { OS<<"is internal"<<endl; }
353 if (myShapeIndex == 1) {
356 else if (myShapeIndex == 2) {
359 else if (myShapeIndex == 3) {
364 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face&,const TopoDS_Face&,Standard_OStream& OS) const
371 //=======================================================================
372 //function : PThePointOfIntersectionDummy
374 //=======================================================================
375 TopOpeBRep_PThePointOfIntersection TopOpeBRep_VPointInter::PThePointOfIntersectionDummy() const