1 // Created on: 1998-10-29
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1998-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 <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <Standard_Type.hxx>
22 #include <TopExp_Explorer.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopOpeBRep_define.hxx>
26 #include <TopOpeBRep_Hctxee2d.hxx>
27 #include <TopOpeBRepTool_2d.hxx>
28 #include <TopOpeBRepTool_CurveTool.hxx>
29 #include <TopOpeBRepTool_GEOMETRY.hxx>
30 #include <TopOpeBRepTool_PROJECT.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRep_Hctxee2d,Standard_Transient)
35 #include <GeomTools_SurfaceSet.hxx>
36 #include <GeomTools_CurveSet.hxx>
37 #include <GeomTools_Curve2dSet.hxx>
38 #include <Geom_Curve.hxx>
39 Standard_EXPORT Standard_Boolean TopOpeBRep_GettracePROEDG();
42 //=======================================================================
43 //function : TopOpeBRep_Hctxee2d
45 //=======================================================================
46 TopOpeBRep_Hctxee2d::TopOpeBRep_Hctxee2d()
50 //=======================================================================
53 //=======================================================================
54 void TopOpeBRep_Hctxee2d::SetEdges(const TopoDS_Edge& E1,const TopoDS_Edge& E2,
55 const BRepAdaptor_Surface& BAS1,
56 const BRepAdaptor_Surface& BAS2)
58 const TopoDS_Face& F1 = BAS1.Face();
59 GeomAbs_SurfaceType ST1 = BAS1.GetType();
60 const TopoDS_Face& F2 = BAS2.Face();
62 myEdge1 = TopoDS::Edge(E1);
63 myEdge2 = TopoDS::Edge(E2);
65 Standard_Real first,last,tole,tolpc;
66 gp_Pnt2d pfirst,plast;
68 Handle(Geom2d_Curve) PC1;
69 PC1 = FC2D_CurveOnSurface(myEdge1,F1,first,last,tolpc);
70 if (PC1.IsNull()) throw Standard_Failure("TopOpeBRep_Hctxee2d::SetEdges : no 2d curve");
72 BRep_Tool::UVPoints(myEdge1,F1,pfirst,plast);
73 tole = BRep_Tool::Tolerance(myEdge1);
74 myDomain1.SetValues(pfirst,first,tole,plast,last,tole);
77 Standard_Boolean trc = Standard_False;
79 std::cout<<"ed1 on fa1 : {pfirst=("<<pfirst.X()<<" "<<pfirst.Y()<<"),first="<<first<<"\n";
80 std::cout<<" plast =("<<plast.X()<<" "<<plast.Y()<<"),last="<<last<<"}"<<std::endl;}
83 Standard_Boolean memesfaces = F1.IsSame(F2);
84 Standard_Boolean memesupport = Standard_False;
85 TopLoc_Location L1,L2;
86 const Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
87 const Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
88 if (S1 == S2 && L1 == L2) memesupport=Standard_True;
90 if ( ST1 == GeomAbs_Plane || memesfaces || memesupport) {
91 Handle(Geom2d_Curve) PC2 = FC2D_CurveOnSurface(myEdge2,F1,first,last,tolpc);
93 BRep_Tool::UVPoints(myEdge2,F1,pfirst,plast);
94 tole = BRep_Tool::Tolerance(myEdge2);
95 myDomain2.SetValues(pfirst,first,tole,plast,last,tole);
99 std::cout<<"ed2 on fa1 : {pfirst=("<<pfirst.X()<<" "<<pfirst.Y()<<"),first="<<first<<"\n";
100 std::cout<<" plast =("<<plast.X()<<" "<<plast.Y()<<"),last="<<last<<"}"<<std::endl;
106 Handle(Geom2d_Curve) PC2on1; Handle(Geom_Curve) NC;
107 Standard_Boolean dgE2 = BRep_Tool::Degenerated(myEdge2);
109 { //xpu210998 : cto900Q3
110 TopExp_Explorer exv(myEdge2,TopAbs_VERTEX);
111 const TopoDS_Vertex& v2 = TopoDS::Vertex(exv.Current());
112 gp_Pnt pt2 = BRep_Tool::Pnt(v2);
113 gp_Pnt2d uv2; Standard_Real d; Standard_Boolean ok = FUN_tool_projPonF(pt2,F1,uv2,d);
114 if (!ok) return;//nyiRaise
115 Handle(Geom_Surface) aS1 = BRep_Tool::Surface(F1);
116 Standard_Boolean apex = FUN_tool_onapex(uv2,aS1);
118 TopoDS_Vertex vf,vl; TopExp::Vertices(myEdge1,vf,vl);
119 gp_Pnt ptf = BRep_Tool::Pnt(vf); Standard_Real df = pt2.Distance(ptf);
120 Standard_Real tolf = BRep_Tool::Tolerance(vf);
121 Standard_Boolean onf = (df < tolf);
122 TopoDS_Vertex v1 = onf ? vf : vl;
123 TopTools_IndexedDataMapOfShapeListOfShape mapVE; TopExp::MapShapesAndAncestors(F1,TopAbs_VERTEX,TopAbs_EDGE,mapVE);
124 const TopTools_ListOfShape& Edsanc = mapVE.FindFromKey(v1);
125 TopTools_ListIteratorOfListOfShape it(Edsanc);
126 for (; it.More(); it.Next()){
127 const TopoDS_Edge& ee = TopoDS::Edge(it.Value());
128 Standard_Boolean dgee = BRep_Tool::Degenerated(ee);
130 PC2on1 = BRep_Tool::CurveOnSurface(ee,F1,first,last);
133 else {} // NYIxpu210998
136 // project curve of edge 2 on surface of face 1
137 TopLoc_Location loc ;
138 Handle(Geom_Curve) C = BRep_Tool::Curve(myEdge2,loc,first,last);
139 NC = Handle(Geom_Curve)::DownCast(C->Transformed(loc.Transformation()));
140 Standard_Real tolreached2d; PC2on1 = TopOpeBRepTool_CurveTool::MakePCurveOnFace(F1,NC,tolreached2d);
143 if (!PC2on1.IsNull()) {
144 myCurve2.Load(PC2on1);
145 tole = BRep_Tool::Tolerance(myEdge2);
146 PC2on1->D0(first,pfirst);
147 PC2on1->D0(last,plast);
148 myDomain2.SetValues(pfirst,first,tole,plast,last,tole);
150 if ( TopOpeBRep_GettracePROEDG() ) {
151 std::cout<<"------------ projection de curve"<<std::endl;
152 std::cout<<"--- Curve : "<<std::endl;GeomTools_CurveSet::PrintCurve(NC,std::cout);
153 std::cout<<"--- nouvelle PCurve : "<<std::endl;GeomTools_Curve2dSet::PrintCurve2d(PC2on1,std::cout);
154 Handle(Geom_Surface) aS1 = BRep_Tool::Surface(F1);
155 std::cout<<"--- sur surface : "<<std::endl;GeomTools_SurfaceSet::PrintSurface(aS1,std::cout);
156 std::cout<<std::endl;
164 //=======================================================================
167 //=======================================================================
168 const TopoDS_Shape& TopOpeBRep_Hctxee2d::Edge(const Standard_Integer Index) const
170 if ( Index == 1 ) return myEdge1;
171 else if ( Index == 2 ) return myEdge2;
172 else throw Standard_Failure("TopOpeBRep_Hctxee2d::Edge");
175 //=======================================================================
178 //=======================================================================
179 const Geom2dAdaptor_Curve& TopOpeBRep_Hctxee2d::Curve(const Standard_Integer Index) const
181 if ( Index == 1 ) return myCurve1;
182 else if ( Index == 2 ) return myCurve2;
183 else throw Standard_Failure("TopOpeBRep_Hctxee2d::Curve");
186 //=======================================================================
189 //=======================================================================
190 const IntRes2d_Domain& TopOpeBRep_Hctxee2d::Domain(const Standard_Integer Index) const
192 if ( Index == 1 ) return myDomain1;
193 else if ( Index == 2 ) return myDomain2;
194 else throw Standard_Failure("TopOpeBRep_Hctxee2d::Domain");