1 // Created on: 1993-11-10
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TopOpeBRep_VPointInter.ixx>
24 #include <Standard_DomainError.hxx>
25 #include <TopOpeBRepTool_ShapeTool.hxx>
26 #include <TopOpeBRep_FFTransitionTool.hxx>
27 #include <TopOpeBRepDS_Transition.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Face.hxx>
31 #include <BRepAdaptor_HCurve2d.hxx>
32 #include <BRepTopAdaptor_HVertex.hxx>
33 #include <Adaptor3d_HVertex.hxx>
34 #include <Adaptor2d_HCurve2d.hxx>
35 #include <BRepAdaptor_Curve2d.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <gp_Pnt2d.hxx>
38 #include <Precision.hxx>
39 #include <TopOpeBRep_define.hxx>
42 extern Standard_Boolean TopOpeBRepDS_GettraceDSFK();
43 static TCollection_AsciiString PRODINP("dinp ");
46 //=======================================================================
49 //=======================================================================
50 void TopOpeBRep_VPointInter::SetPoint(const IntPatch_Point& P)
52 myPPOI = (IntPatch_Point*)&P;
54 Standard_Boolean isOn1 = P.IsOnDomS1();
55 Standard_Boolean isOn2 = P.IsOnDomS2();
56 if (isOn1 && isOn2) myShapeIndex = 3;
57 else if (isOn2) myShapeIndex = 2;
58 else if (isOn1) myShapeIndex = 1;
59 else myShapeIndex = 0;
62 //=======================================================================
65 //=======================================================================
66 const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS1() const
68 const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS1();
69 const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
73 //=======================================================================
76 //=======================================================================
77 const TopoDS_Shape& TopOpeBRep_VPointInter::ArcOnS2() const
79 const Handle(Adaptor2d_HCurve2d)& HAHC2 = myPPOI->ArcOnS2();
80 const BRepAdaptor_Curve2d& BRAC2P = *((BRepAdaptor_Curve2d*)&(HAHC2->Curve2d()));
84 //=======================================================================
85 //function : VertexOnS1
87 //=======================================================================
88 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS1() const
90 if ( !myPPOI->IsVertexOnS1() )
91 Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS1");
93 const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS1());
94 return (*HBRTAHV)->Vertex();
97 //=======================================================================
98 //function : VertexOnS2
100 //=======================================================================
101 const TopoDS_Shape& TopOpeBRep_VPointInter::VertexOnS2() const
103 if ( !myPPOI->IsVertexOnS2() )
104 Standard_DomainError::Raise("TopOpeBRep_VPointInter::VertexOnS2");
106 const Handle(BRepTopAdaptor_HVertex)* HBRTAHV = (Handle(BRepTopAdaptor_HVertex)*)&(myPPOI->VertexOnS2());
107 return (*HBRTAHV)->Vertex();
110 //=======================================================================
113 //=======================================================================
114 void TopOpeBRep_VPointInter::State(const TopAbs_State S,const Standard_Integer I)
116 if (I == 1) myState1 = S;
117 else if (I == 2) myState2 = S;
118 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::State");
122 //=======================================================================
125 //=======================================================================
126 TopAbs_State TopOpeBRep_VPointInter::State(const Standard_Integer I) const
128 if (I == 1) return myState1;
129 else if (I == 2) return myState2;
130 else { Standard_DomainError::Raise("TopOpeBRep_VPointInter::State"); return TopAbs_UNKNOWN; }
133 //=======================================================================
136 //=======================================================================
137 void TopOpeBRep_VPointInter::EdgeON(const TopoDS_Shape& Eon,const Standard_Real Par,const Standard_Integer I)
149 //=======================================================================
152 //=======================================================================
153 const TopoDS_Shape& TopOpeBRep_VPointInter::EdgeON(const Standard_Integer I) const
155 if (I == 1) return myEdgeON1;
156 else if (I == 2) return myEdgeON2;
157 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeON");
161 //=======================================================================
162 //function : EdgeONParameter
164 //=======================================================================
165 Standard_Real TopOpeBRep_VPointInter::EdgeONParameter(const Standard_Integer I) const
167 if (I == 1) return myEdgeONPar1;
168 else if (I == 2) return myEdgeONPar2;
169 else Standard_DomainError::Raise("TopOpeBRep_VPointInter::EdgeONParameter");
173 //=======================================================================
176 //=======================================================================
177 const TopoDS_Shape& TopOpeBRep_VPointInter::Edge(const Standard_Integer I) const
179 if (I == 1 && IsOnDomS1() ) return ArcOnS1();
180 else if (I == 2 && IsOnDomS2() ) return ArcOnS2();
185 //=======================================================================
186 //function : EdgeParameter
188 //=======================================================================
189 Standard_Real TopOpeBRep_VPointInter::EdgeParameter(const Standard_Integer I) const
191 if (I == 1 && IsOnDomS1() ) return ParameterOnArc1();
192 else if (I == 2 && IsOnDomS2() ) return ParameterOnArc2();
196 //=======================================================================
197 //function : EdgeParameter
199 //=======================================================================
200 gp_Pnt2d TopOpeBRep_VPointInter::SurfaceParameters(const Standard_Integer I) const
202 Standard_Real u = 0., v = 0.;
203 //if (I == 1 && IsOnDomS1() ) ParametersOnS1(u,v);
204 //else if (I == 2 && IsOnDomS1() ) ParametersOnS2(u,v);
205 if (I == 1 ) ParametersOnS1(u,v);
206 else if (I == 2 ) ParametersOnS2(u,v);
211 //=======================================================================
212 //function : IsVertex
214 //=======================================================================
215 Standard_Boolean TopOpeBRep_VPointInter::IsVertex(const Standard_Integer I) const
217 if ( I == 0 ) return Standard_False;
218 if ( I == 1 && IsVertexOnS1() ) return Standard_True;
219 else if ( I == 2 && IsVertexOnS2() ) return Standard_True;
220 return Standard_False;
223 //=======================================================================
226 //=======================================================================
227 const TopoDS_Shape& TopOpeBRep_VPointInter::Vertex(const Standard_Integer I) const
229 if ( I == 1 && IsVertexOnS1() ) return VertexOnS1();
230 else if ( I == 2 && IsVertexOnS2() ) return VertexOnS2();
234 //=======================================================================
235 //function : UpdateKeep
237 //=======================================================================
238 void TopOpeBRep_VPointInter::UpdateKeep()
240 #define M_SINON(s) (((s) == TopAbs_IN) || ((s) == TopAbs_ON))
242 TopAbs_State pos1 = State(1);
243 TopAbs_State pos2 = State(2);
245 Standard_Integer SI = ShapeIndex();
247 Standard_Boolean condition=Standard_False;
249 if (SI == 1) condition = M_SINON(pos2);
250 else if (SI == 2) condition = M_SINON(pos1);
251 else if (SI == 0) condition = M_SINON(pos1) && M_SINON(pos2);
252 else if (SI == 3) condition = M_SINON(pos1) && M_SINON(pos2);
253 // NYI : SI == 3 --> le VP devrait toujours etre Keep() (par definition)
258 //=======================================================================
260 //purpose : returns <True> if the 3d points and the parameters of the
262 //=======================================================================
263 Standard_Boolean TopOpeBRep_VPointInter::EqualpP(const TopOpeBRep_VPointInter& VP) const
265 Standard_Real p1 = ParameterOnLine();
266 Standard_Real p2 = VP.ParameterOnLine();
267 Standard_Boolean pequal = fabs(p1-p2) < Precision::PConfusion();
268 gp_Pnt P1 = Value(); gp_Pnt P2 = VP.Value();
269 Standard_Real Ptol1 = Tolerance(), Ptol2 = VP.Tolerance();
270 Standard_Real Ptol = (Ptol1 > Ptol2) ? Ptol1 : Ptol2;
271 Standard_Boolean Pequal = P1.IsEqual(P2,Ptol);
272 Standard_Boolean pPequal = ( pequal && Pequal );
276 //=======================================================================
279 //=======================================================================
280 Standard_Boolean TopOpeBRep_VPointInter::ParonE(const TopoDS_Edge& E,Standard_Real& par) const
282 Standard_Boolean found = Standard_False;
284 if(E.IsSame(ArcOnS1())) found = Standard_True;
285 if (found) {par = ParameterOnArc1(); return found;}
288 if(E.IsSame(ArcOnS2())) found = Standard_True;
289 if (found) {par = ParameterOnArc2(); return found;}
292 for (Standard_Integer i = 1; i <= 2; i++) {
293 if (State(i) != TopAbs_ON) continue;
294 if (EdgeON(i).IsSame(E)) {
295 par = EdgeONParameter(i);
296 return Standard_True;
302 //=======================================================================
303 //function : DumpEdge
305 //=======================================================================
306 Standard_OStream& TopOpeBRep_VPointInter::Dump(const Standard_Integer I,const TopoDS_Face& F,Standard_OStream& OS) const
308 const TopoDS_Edge& E = TopoDS::Edge(Edge(I));
314 TopAbs_Orientation O =
318 Standard_Boolean closingedge =
320 TopOpeBRepTool_ShapeTool::Closed(E,F);
323 if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
324 cout<<" of "<<I<<" : par : "<<Epar<<endl;
325 TopOpeBRepDS_Transition T = TopOpeBRep_FFTransitionTool::ProcessLineTransition(*this,I,O);
326 OS<<"line transition ";
327 if (closingedge) OS<<"on closing edge "; else OS<<"on edge "; TopAbs::Print(O,cout);
328 OS<<" of "<<I<<" : "; T.Dump(OS);OS<<endl;
334 //=======================================================================
337 //=======================================================================
339 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face& FF1,const TopoDS_Face& FF2,Standard_OStream& OS) const
341 const TopoDS_Face& F1 = TopoDS::Face(FF1);
342 const TopoDS_Face& F2 = TopoDS::Face(FF2);
343 OS<<"VP "<<myIndex<<" on "<<myShapeIndex<<" :";
344 Standard_Real Cpar = ParameterOnLine(); OS<<" on curve : "<<Cpar;
345 if (!myKeep) OS<<" NOT kept";
347 const gp_Pnt& P = Value();
348 OS<<PRODINP<<"P"<<myIndex<<" "; OS<<P.X()<<" "<<P.Y()<<" "<<P.Z();
351 if (TopOpeBRepDS_GettraceDSFK()) { Standard_Real u,v;
352 ParametersOnS1(u,v); OS<<"u1,v1 : "<<u<<" "<<v; OS<<" ";
353 ParametersOnS2(u,v); OS<<"u2,v2 : "<<u<<" "<<v; OS<<endl;
356 if (IsVertexOnS1()) { OS<<"is vertex of 1"<<endl; }
357 if (IsVertexOnS2()) { OS<<"is vertex of 2"<<endl; }
358 if (IsMultiple()) { OS<<"is multiple"<<endl; }
359 if (IsInternal()) { OS<<"is internal"<<endl; }
361 if (myShapeIndex == 1) {
364 else if (myShapeIndex == 2) {
367 else if (myShapeIndex == 3) {
372 Standard_OStream& TopOpeBRep_VPointInter::Dump(const TopoDS_Face&,const TopoDS_Face&,Standard_OStream& OS) const
379 //=======================================================================
380 //function : PThePointOfIntersectionDummy
382 //=======================================================================
383 TopOpeBRep_PThePointOfIntersection TopOpeBRep_VPointInter::PThePointOfIntersectionDummy() const