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