Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TopOpeBRep / TopOpeBRep_Hctxee2d.cxx
CommitLineData
7fd59977 1// File: TopOpeBRep_Hctxee2d.cxx
2// Created: Thu Oct 29 12:46:21 1998
3// Author: Jean Yves LEBEY
4// <jyl@langdox.paris1.matra-dtv.fr>
5
6#include <TopOpeBRep_Hctxee2d.ixx>
7#include <TopOpeBRep_define.hxx>
8#include <TopOpeBRepTool_CurveTool.hxx>
9#include <TopOpeBRepTool_ShapeTool.hxx>
10#include <TopOpeBRepTool_2d.hxx>
11#include <TopOpeBRepTool_GEOMETRY.hxx>
12#include <TopOpeBRepTool_PROJECT.hxx>
13#include <TopExp.hxx>
14#include <TopExp_Explorer.hxx>
15#include <TopAbs.hxx>
16#include <TopoDS.hxx>
17#include <BRep_Tool.hxx>
18
19#ifdef DEB
20#include <GeomTools_SurfaceSet.hxx>
21#include <GeomTools_CurveSet.hxx>
22#include <GeomTools_Curve2dSet.hxx>
23Standard_EXPORT Standard_Boolean TopOpeBRep_GettracePROEDG();
24#endif
25
26//=======================================================================
27//function : TopOpeBRep_Hctxee2d
28//purpose :
29//=======================================================================
30TopOpeBRep_Hctxee2d::TopOpeBRep_Hctxee2d()
31{
32}
33
34//=======================================================================
35//function : SetEdges
36//purpose :
37//=======================================================================
38void TopOpeBRep_Hctxee2d::SetEdges(const TopoDS_Edge& E1,const TopoDS_Edge& E2,
39 const BRepAdaptor_Surface& BAS1,
40 const BRepAdaptor_Surface& BAS2)
41{
42 const TopoDS_Face& F1 = BAS1.Face();
43 GeomAbs_SurfaceType ST1 = BAS1.GetType();
44 const TopoDS_Face& F2 = BAS2.Face();
45#ifdef DEb
46 GeomAbs_SurfaceType ST2 = BAS2.GetType();
47#endif
48
49 myEdge1 = TopoDS::Edge(E1);
50 myEdge2 = TopoDS::Edge(E2);
51
52 Standard_Real first,last,tole,tolpc;
53 gp_Pnt2d pfirst,plast;
54
55 Handle(Geom2d_Curve) PC1;
56 PC1 = FC2D_CurveOnSurface(myEdge1,F1,first,last,tolpc);
57 if (PC1.IsNull()) Standard_Failure::Raise("TopOpeBRep_Hctxee2d::SetEdges : no 2d curve");
58 myCurve1.Load(PC1);
59 BRep_Tool::UVPoints(myEdge1,F1,pfirst,plast);
60 tole = BRep_Tool::Tolerance(myEdge1);
61 myDomain1.SetValues(pfirst,first,tole,plast,last,tole);
62
63#ifdef DEB
64 Standard_Boolean trc = Standard_False;
65 if (trc) {
66 cout<<"ed1 on fa1 : {pfirst=("<<pfirst.X()<<" "<<pfirst.Y()<<"),first="<<first<<"\n";
67 cout<<" plast =("<<plast.X()<<" "<<plast.Y()<<"),last="<<last<<"}"<<endl;}
68#endif
69
70 Standard_Boolean memesfaces = F1.IsSame(F2);
71 Standard_Boolean memesupport = Standard_False;
72 TopLoc_Location L1,L2;
73 const Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
74 const Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
75 if (S1 == S2 && L1 == L2) memesupport=Standard_True;
76
77 if ( ST1 == GeomAbs_Plane || memesfaces || memesupport) {
78 Handle(Geom2d_Curve) PC2 = FC2D_CurveOnSurface(myEdge2,F1,first,last,tolpc);
79 myCurve2.Load(PC2);
80 BRep_Tool::UVPoints(myEdge2,F1,pfirst,plast);
81 tole = BRep_Tool::Tolerance(myEdge2);
82 myDomain2.SetValues(pfirst,first,tole,plast,last,tole);
83
84#ifdef DEB
85 if (trc) {
86 cout<<"ed2 on fa1 : {pfirst=("<<pfirst.X()<<" "<<pfirst.Y()<<"),first="<<first<<"\n";
87 cout<<" plast =("<<plast.X()<<" "<<plast.Y()<<"),last="<<last<<"}"<<endl;}
88#endif
89
90 }
91 else {
92
93 Handle(Geom2d_Curve) PC2on1; Handle(Geom_Curve) NC;
94 Standard_Boolean dgE2 = BRep_Tool::Degenerated(myEdge2);
95 if (dgE2) { //xpu210998 : cto900Q3
96 TopExp_Explorer exv(myEdge2,TopAbs_VERTEX);
97 const TopoDS_Vertex& v2 = TopoDS::Vertex(exv.Current());
98 gp_Pnt pt2 = BRep_Tool::Pnt(v2);
99 gp_Pnt2d uv2; Standard_Real d; Standard_Boolean ok = FUN_tool_projPonF(pt2,F1,uv2,d);
100 if (!ok) return;//nyiRaise
101 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1);
102 Standard_Boolean apex = FUN_tool_onapex(uv2,S1);
103 if (apex) {
104 TopoDS_Vertex vf,vl; TopExp::Vertices(myEdge1,vf,vl);
105 gp_Pnt ptf = BRep_Tool::Pnt(vf); Standard_Real df = pt2.Distance(ptf);
106 gp_Pnt ptl = BRep_Tool::Pnt(vl);
107#ifdef DEB
108 Standard_Real dl =
109#endif
110 pt2.Distance(ptl);
111 Standard_Real tolf = BRep_Tool::Tolerance(vf);
112#ifdef DEB
113 Standard_Real toll =
114#endif
115 BRep_Tool::Tolerance(vl);
116#ifdef DEB
117 Standard_Real tol = Max (tolf,toll);
118#endif
119 Standard_Boolean onf = (df < tolf);
120#ifdef DEB
121 Standard_Boolean onl = (dl < toll);
122#endif
123 TopoDS_Vertex v1 = onf ? vf : vl;
124 TopTools_IndexedDataMapOfShapeListOfShape mapVE; TopExp::MapShapesAndAncestors(F1,TopAbs_VERTEX,TopAbs_EDGE,mapVE);
125 const TopTools_ListOfShape& Edsanc = mapVE.FindFromKey(v1);
126 TopTools_ListIteratorOfListOfShape it(Edsanc);
127 for (; it.More(); it.Next()){
128 const TopoDS_Edge& ee = TopoDS::Edge(it.Value());
129 Standard_Boolean dgee = BRep_Tool::Degenerated(ee);
130 if (!dgee) continue;
131// Standard_Real f,l;
132 PC2on1 = BRep_Tool::CurveOnSurface(ee,F1,first,last);
133 }
134 }
135 else {} // NYIxpu210998
136 } //dgE2
137 else {
138 // project curve of edge 2 on surface of face 1
139 TopLoc_Location loc ;
140 Handle(Geom_Curve) C = BRep_Tool::Curve(myEdge2,loc,first,last);
141 NC = Handle(Geom_Curve)::DownCast(C->Transformed(loc.Transformation()));
142 Standard_Real tolreached2d; PC2on1 = TopOpeBRepTool_CurveTool::MakePCurveOnFace(F1,NC,tolreached2d);
143 }
144
145 if (!PC2on1.IsNull()) {
146 myCurve2.Load(PC2on1);
147 tole = BRep_Tool::Tolerance(myEdge2);
148 PC2on1->D0(first,pfirst);
149 PC2on1->D0(last,plast);
150 myDomain2.SetValues(pfirst,first,tole,plast,last,tole);
151#ifdef DEB
152 if ( TopOpeBRep_GettracePROEDG() ) {
153 cout<<"------------ projection de curve"<<endl;
154 cout<<"--- Curve : "<<endl;GeomTools_CurveSet::PrintCurve(NC,cout);
155 cout<<"--- nouvelle PCurve : "<<endl;GeomTools_Curve2dSet::PrintCurve2d(PC2on1,cout);
156 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1);
157 cout<<"--- sur surface : "<<endl;GeomTools_SurfaceSet::PrintSurface(S1,cout);
158 cout<<endl;
159 }
160#endif
161 }
162 }
163
164#ifdef DEB
165 GeomAbs_CurveType myCurveType1 = myCurve1.GetType();
166 GeomAbs_CurveType myCurveType2 = myCurve2.GetType();
167#endif
168
169} // SetEdges
170
171//=======================================================================
172//function : Edge
173//purpose :
174//=======================================================================
175const TopoDS_Shape& TopOpeBRep_Hctxee2d::Edge(const Standard_Integer Index) const
176{
177 if ( Index == 1 ) return myEdge1;
178 else if ( Index == 2 ) return myEdge2;
179 else Standard_Failure::Raise("TopOpeBRep_Hctxee2d::Edge");
180
181 return myEdge1;
182}
183
184//=======================================================================
185//function : Curve
186//purpose :
187//=======================================================================
188const Geom2dAdaptor_Curve& TopOpeBRep_Hctxee2d::Curve(const Standard_Integer Index) const
189{
190 if ( Index == 1 ) return myCurve1;
191 else if ( Index == 2 ) return myCurve2;
192 else Standard_Failure::Raise("TopOpeBRep_Hctxee2d::Curve");
193
194 return myCurve1;
195}
196
197//=======================================================================
198//function : Domain
199//purpose :
200//=======================================================================
201const IntRes2d_Domain& TopOpeBRep_Hctxee2d::Domain(const Standard_Integer Index) const
202{
203 if ( Index == 1 ) return myDomain1;
204 else if ( Index == 2 ) return myDomain2;
205 else Standard_Failure::Raise("TopOpeBRep_Hctxee2d::Domain");
206
207 return myDomain1;
208}