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