0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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
18 #include <BRep_Tool.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <Standard_Type.hxx>
21 #include <TopExp.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <TopoDS.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>
31
32 IMPLEMENT_STANDARD_RTTIEXT(TopOpeBRep_Hctxee2d,Standard_Transient)
33
34 #ifdef OCCT_DEBUG
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();
40 #endif
41
42 //=======================================================================
43 //function : TopOpeBRep_Hctxee2d
44 //purpose  : 
45 //=======================================================================
46 TopOpeBRep_Hctxee2d::TopOpeBRep_Hctxee2d() 
47 {
48 }
49
50 //=======================================================================
51 //function : SetEdges
52 //purpose  : 
53 //=======================================================================
54 void TopOpeBRep_Hctxee2d::SetEdges(const TopoDS_Edge& E1,const TopoDS_Edge& E2,
55                                    const BRepAdaptor_Surface& BAS1,
56                                    const BRepAdaptor_Surface& BAS2)
57 {
58   const TopoDS_Face& F1 = BAS1.Face();
59   GeomAbs_SurfaceType ST1 = BAS1.GetType();
60   const TopoDS_Face& F2 = BAS2.Face();
61   
62   myEdge1 = TopoDS::Edge(E1);
63   myEdge2 = TopoDS::Edge(E2);
64   
65   Standard_Real first,last,tole,tolpc;
66   gp_Pnt2d pfirst,plast;
67
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");
71   myCurve1.Load(PC1);
72   BRep_Tool::UVPoints(myEdge1,F1,pfirst,plast);
73   tole = BRep_Tool::Tolerance(myEdge1);
74   myDomain1.SetValues(pfirst,first,tole,plast,last,tole);
75
76 #ifdef OCCT_DEBUG
77   Standard_Boolean trc = Standard_False;
78   if (trc) {
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;}
81 #endif
82
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;
89   
90   if ( ST1 == GeomAbs_Plane || memesfaces || memesupport) {    
91     Handle(Geom2d_Curve) PC2 = FC2D_CurveOnSurface(myEdge2,F1,first,last,tolpc);
92     myCurve2.Load(PC2);
93     BRep_Tool::UVPoints(myEdge2,F1,pfirst,plast);
94     tole = BRep_Tool::Tolerance(myEdge2);
95     myDomain2.SetValues(pfirst,first,tole,plast,last,tole);
96
97 #ifdef OCCT_DEBUG
98     if (trc) {
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;
101     }
102 #endif
103   }
104   else {
105
106     Handle(Geom2d_Curve) PC2on1; Handle(Geom_Curve) NC;
107     Standard_Boolean dgE2 = BRep_Tool::Degenerated(myEdge2);
108     if (dgE2)
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);
117       if (apex) {
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);
129           if (!dgee) continue;
130           PC2on1 = BRep_Tool::CurveOnSurface(ee,F1,first,last);
131         }
132       }
133       else {} // NYIxpu210998
134     } //dgE2
135     else {
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);
141     }
142     
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);
149 #ifdef OCCT_DEBUG
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;
157       }
158 #endif
159     }
160   }
161   
162 } // SetEdges
163
164 //=======================================================================
165 //function : Edge
166 //purpose  : 
167 //=======================================================================
168 const TopoDS_Shape& TopOpeBRep_Hctxee2d::Edge(const Standard_Integer Index) const 
169 {
170   if      ( Index == 1 ) return myEdge1;
171   else if ( Index == 2 ) return myEdge2;
172   else throw Standard_Failure("TopOpeBRep_Hctxee2d::Edge");
173 }
174
175 //=======================================================================
176 //function : Curve
177 //purpose  : 
178 //=======================================================================
179 const Geom2dAdaptor_Curve& TopOpeBRep_Hctxee2d::Curve(const Standard_Integer Index) const 
180 {
181   if      ( Index == 1 ) return myCurve1;
182   else if ( Index == 2 ) return myCurve2;
183   else throw Standard_Failure("TopOpeBRep_Hctxee2d::Curve");
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 throw Standard_Failure("TopOpeBRep_Hctxee2d::Domain");
195 }