1 // Created on: 1997-11-26
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-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 <TopOpeBRepTool_DRAW.hxx>
19 #include <TopOpeBRepDS_DRAW.hxx>
21 #include <DrawTrSurf.hxx>
23 #include <Geom2d_TrimmedCurve.hxx>
24 #include <Geom2d_Curve.hxx>
25 #include <Geom2d_Line.hxx>
26 #include <Geom_Line.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <BRep_TEdge.hxx>
29 #include <BRep_ListOfCurveRepresentation.hxx>
30 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
31 #include <BRep_CurveRepresentation.hxx>
32 #include <BRep_Tool.hxx>
33 #include <GeomAPI_ProjectPointOnSurf.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <Precision.hxx>
38 Standard_EXPORT void FUN_draw (const TopoDS_Shape& s)
40 char* nnn = TCollection_AsciiString("name").ToCString();
41 if (s.IsNull()) std::cout<<"nullshape"<<std::endl;
44 Standard_EXPORT void FUN_draw (const gp_Pnt& p)
46 char* nnn = TCollection_AsciiString("name").ToCString();
47 DrawTrSurf::Set(nnn,p);
49 Standard_EXPORT void FUN_draw (const gp_Pnt2d& p)
51 char* nnn = TCollection_AsciiString("name").ToCString();
52 DrawTrSurf::Set(nnn,p);
54 Standard_EXPORT void FUN_draw (const Handle(Geom2d_Curve) c, const Standard_Real dpar)
56 char* nnn = TCollection_AsciiString("c2d").ToCString();
57 if (dpar <= Precision::Confusion()) {
58 DrawTrSurf::Set(nnn,c);
61 Handle(Geom2d_TrimmedCurve) tC = new Geom2d_TrimmedCurve(c,0.,dpar);
62 DrawTrSurf::Set(nnn,tC);
65 Standard_EXPORT void FUN_draw (const gp_Pnt& p, const gp_Dir& d)
67 TCollection_AsciiString aa("dir"); FUN_tool_draw(aa,p,d);
70 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const gp_Pnt& p)
75 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const gp_Pnt& p, const gp_Dir& d)
77 FUN_tool_draw(aa,p,d);
79 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const TopoDS_Shape& s)
83 Standard_EXPORT void FUN_brep_draw
84 (const TCollection_AsciiString& aa, const Handle(Geom_Curve)& C, const Standard_Real& f, const Standard_Real& l)
86 FUN_tool_draw(aa,C,f,l);
88 Standard_EXPORT void FUN_brep_draw
89 (const TCollection_AsciiString& aa, const Handle(Geom_Curve)& C)
94 Standard_EXPORT void FUN_DrawMap
95 (const TopTools_DataMapOfShapeListOfShape& DataforDegenEd)
97 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itemap(DataforDegenEd);
98 for (; itemap.More(); itemap.Next()) {
99 TopoDS_Shape v =itemap.Key();
100 TopTools_ListIteratorOfListOfShape itoflos(itemap.Value());
101 if(!itoflos.More()) continue;
102 TopoDS_Shape Ec = itoflos.Value();
103 if(!itoflos.More()) continue;
105 TopoDS_Shape Ed =itoflos.Value();
107 Standard_Boolean tr = Standard_False;
108 if (tr) { FUN_draw(v); FUN_draw(Ec); FUN_draw(Ed);}
112 static Standard_Boolean FUN_hascurveonsurf(const TopoDS_Edge& edge,const TopoDS_Face& face)
115 Handle(Geom_Surface) S = BRep_Tool::Surface(face,L);
117 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&edge.TShape());
118 const BRep_ListOfCurveRepresentation& lcr = TE->Curves();
119 BRep_ListIteratorOfListOfCurveRepresentation itcr(lcr);
120 Standard_Boolean iscurveonS = Standard_False;
122 for (;itcr.More();itcr.Next()) {
123 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
124 Standard_Boolean iscurveonsurface = cr->IsCurveOnSurface();
125 if (!iscurveonsurface) continue;
126 iscurveonS = cr->IsCurveOnSurface(S,L);
127 if (iscurveonS) break;
132 Standard_EXPORT void FUN_draw2de (const TopoDS_Shape& ed,const TopoDS_Shape& fa)
134 char* nnn = TCollection_AsciiString("name").ToCString();
136 if (ed.IsNull()) return;
137 if (fa.IsNull()) return;
138 TopoDS_Edge edge = TopoDS::Edge(ed);
139 TopoDS_Face face = TopoDS::Face(fa);
140 Standard_Boolean hascons = FUN_hascurveonsurf(edge,face);
141 if (!hascons) return;
143 TopAbs_Orientation ori = edge.Orientation();
144 Standard_Boolean sense = (ori == TopAbs_FORWARD)? Standard_True :Standard_False;
145 Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(edge, face,f,l);
147 Handle(Geom2d_TrimmedCurve) tC2d = new Geom2d_TrimmedCurve(C2d,f,l,sense);
148 DrawTrSurf::Set(nnn,tC2d);
151 Standard_EXPORT void FUN_draw2d(const Standard_Real& par,const TopoDS_Edge& E,const TopoDS_Edge& Eref,const TopoDS_Face& Fref)
153 TopAbs_Orientation oriE = E.Orientation();
154 TopAbs_Orientation oriEref = Eref.Orientation();
155 Standard_Boolean ErefonFref = Standard_False;
156 Standard_Boolean EonFref = Standard_False;
158 Standard_Integer ne = 0;
159 for (ex.Init(Fref,TopAbs_EDGE); ex.More(); ex.Next()) ne++;
161 for (ex.Init(Fref,TopAbs_EDGE); ex.More(); ex.Next()) {
162 const TopoDS_Edge ed = TopoDS::Edge(ex.Current());
163 if (ed.IsSame(Eref)) {ErefonFref = Standard_True; break;}
164 if (ed.IsSame(E)) {EonFref = Standard_True; break;}
167 if (ErefonFref || EonFref) {
169 Handle(Geom2d_Curve) C2d;
171 C2d = BRep_Tool::CurveOnSurface(Eref,Fref,f,l);
172 FUN_draw2de(Eref,Fref);
175 C2d = BRep_Tool::CurveOnSurface(E,Fref,f,l);
182 Handle(Geom_Curve) C3d = BRep_Tool::Curve(Eref,f,l);
183 gp_Pnt P; C3d->D0(par,P);
184 Handle(Geom_Surface) S = BRep_Tool::Surface(Fref);
185 GeomAPI_ProjectPointOnSurf PonS(P, S);
186 if (!PonS.Extrema().IsDone()) return;
187 if (PonS.NbPoints() == 0) return;
188 Standard_Real u,v; PonS.Parameters(1,u,v);
189 p2d = gp_Pnt2d(u,v); }