1 // Created on: 1994-07-21
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-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.
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
23 #include <Draw_MarkerShape.hxx>
24 #include <Draw_Marker3D.hxx>
25 #include <Draw_Segment3D.hxx>
27 #include <TopAbs_State.hxx>
30 #include <BRep_Tool.hxx>
31 #include <Draw_Color.hxx>
32 #include <Geom_Line.hxx>
33 #include <Geom_TrimmedCurve.hxx>
34 #include <Geom2d_Line.hxx>
35 #include <Geom2d_TrimmedCurve.hxx>
36 #include <BRep_Tool.hxx>
37 #include <TopExp_Explorer.hxx>
38 #include <TopOpeBRepTool_DRAW.hxx>
40 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
41 Standard_IMPORT void DBRep_WriteColorOrientation ();
42 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
44 static Draw_MarkerShape MARKER3DSHAPE = Draw_Square;
45 static Draw_ColorKind MARKER3DCOLOR = Draw_magenta;
46 static Standard_Integer MARKER3DSIZE = 1;
47 static Draw_ColorKind SEGMENTCOLOR = Draw_vert;
49 //===========================================================================
50 void TopOpeBRepTool_DrawPoint
51 (const gp_Pnt& P, const Draw_MarkerShape T, const Draw_ColorKind C)
52 //===========================================================================
53 { dout<<new Draw_Marker3D(P,T,C,MARKER3DSIZE); dout.Flush(); }
54 void TopOpeBRepTool_DrawPoint(const gp_Pnt& P, const Draw_ColorKind C)
55 { TopOpeBRepTool_DrawPoint(P,MARKER3DSHAPE,C); }
56 void TopOpeBRepTool_DrawPoint(const gp_Pnt& P)
57 { TopOpeBRepTool_DrawPoint(P,MARKER3DSHAPE,MARKER3DCOLOR); }
60 //===========================================================================
61 void TopOpeBRepTool_DrawSegment
62 (const gp_Pnt& P1,const gp_Pnt& P2, const Draw_ColorKind C)
63 //===========================================================================
65 dout << new Draw_Segment3D(P1,P2,C);
66 TopOpeBRepTool_DrawPoint(P1); TopOpeBRepTool_DrawPoint(P2);
69 void TopOpeBRepTool_DrawSegment(const gp_Pnt& P1, const gp_Pnt& P2)
70 { TopOpeBRepTool_DrawSegment(P1,P2,SEGMENTCOLOR); }
73 //===========================================================================
74 void TopOpeBRepTool_DrawSegment
75 (const gp_Pnt& P,const gp_Lin& L,
76 const Standard_Real Par,const Draw_ColorKind C)
77 //===========================================================================
78 { TopOpeBRepTool_DrawSegment(P,ElCLib::Value(Par,L),C); }
81 //===========================================================================
82 Draw_ColorKind TopOpeBRepTool_ColorOnState(const TopAbs_State S)
83 //===========================================================================
87 case TopAbs_ON : c = Draw_blanc; break;
88 case TopAbs_UNKNOWN : c = Draw_rouge; break;
89 case TopAbs_IN : c = Draw_rose; break;
90 case TopAbs_OUT : c = Draw_cyan; break;
95 //===========================================================================
96 void TopOpeBRepTool_DrawSegment
97 (const gp_Pnt& P,const gp_Lin& L,const Standard_Real Par,
99 //===========================================================================
100 { TopOpeBRepTool_DrawSegment(P,L,Par,TopOpeBRepTool_ColorOnState(S)); }
101 void TopOpeBRepTool_DrawSegment
102 (const gp_Pnt& P,const gp_Lin& L,const Standard_Real Par)
103 { TopOpeBRepTool_DrawSegment(P,L,Par,SEGMENTCOLOR); }
106 Standard_EXPORT void FDRAW_DINS(const TCollection_AsciiString pref,const TopoDS_Shape& SS,const TCollection_AsciiString Snam,const TCollection_AsciiString suff)
108 DBRep::Set(Snam.ToCString(),SS);
109 std::cout<<pref<<FUN_tool_PRODINS()<<" "<<Snam<<";"<<suff;
112 Standard_EXPORT void FDRAW_DINE(const TCollection_AsciiString pref,const TopoDS_Edge& EE,const TCollection_AsciiString Enam,const TCollection_AsciiString suff)
114 TCollection_AsciiString VFnam,VRnam,VInam,VEnam;
115 TCollection_AsciiString blancV(" ");
116 TopoDS_Vertex VF,VR;TopExp::Vertices(EE,VF,VR);
117 if ( ! VF.IsNull() && !VR.IsNull() && !EE.IsNull() ) {
118 DBRep::Set(Enam.ToCString(),EE);
119 Standard_Real f,l; BRep_Tool::Range(EE,f,l);
120 std::cout<<pref<<FUN_tool_PRODINS()<<"-gO "<<Enam<<"; # f,l : "<<f<<","<<l<<suff;
123 Standard_Integer nfo=0,nre=0,nin=0,nex=0;
125 for (exx.Init(EE,TopAbs_VERTEX);exx.More();exx.Next()) {
126 // for (TopExp_Explorer exx(EE,TopAbs_VERTEX);exx.More();exx.Next()) {
127 const TopoDS_Vertex& vv = TopoDS::Vertex(exx.Current());
128 TopAbs_Orientation vvo = vv.Orientation();
129 if ( vvo == TopAbs_FORWARD ) {
130 nfo++; VFnam = Enam + ".vf" + nfo;
131 DBRep::Set(VFnam.ToCString(),vv);
132 std::cout<<blancV<<FUN_tool_PRODINS()<<VFnam;
134 else if ( vvo == TopAbs_REVERSED ) {
135 nre++; VRnam = Enam + ".vr" + nre;
136 DBRep::Set(VRnam.ToCString(),vv);
137 std::cout<<blancV<<FUN_tool_PRODINS()<<VRnam;
139 else if ( vvo == TopAbs_INTERNAL ) {
140 nin++; VInam = Enam + ".vi" + nin;
141 DBRep::Set(VInam.ToCString(),vv);
142 std::cout<<blancV<<FUN_tool_PRODINS()<<VInam;
144 else if ( vvo == TopAbs_EXTERNAL ) {
145 nex++; VEnam = Enam + ".ve" + nex;
146 DBRep::Set(VEnam.ToCString(),vv);
147 std::cout<<blancV<<FUN_tool_PRODINS()<<VEnam;
150 Standard_Real p = BRep_Tool::Parameter(vv,EE);
151 std::cout<<"; #draw ; par/"<<Enam<<" : "<<p<<std::endl;
158 Standard_EXPORT void FDRAW_DINLOE
159 (const TCollection_AsciiString pref,const TopTools_ListOfShape& LOE,const TCollection_AsciiString str1,const TCollection_AsciiString str2)
161 TopTools_ListIteratorOfListOfShape it(LOE);
162 for (Standard_Integer ned=1;it.More();it.Next(),ned++) {
163 TCollection_AsciiString Enam = str1 + str2 + "." + ned;
164 FDRAW_DINE(pref,TopoDS::Edge(it.Value()),Enam,"\n");
168 Standard_EXPORT void FUN_tool_draw (const TCollection_AsciiString& aa, const gp_Pnt& p, const gp_Dir& d)
170 char* aaa = aa.ToCString();
171 Handle(Geom_Line) L = new Geom_Line(p,d);
172 Handle(Geom_TrimmedCurve) tL = new Geom_TrimmedCurve(L,0.,1.);
173 DrawTrSurf::Set(aaa,tL);
175 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString& aa,const gp_Pnt2d& p, const gp_Dir2d& d,const Standard_Integer& i)
177 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(i); char* aaa = bb.ToCString();
178 Handle(Geom2d_Line) L = new Geom2d_Line(p,d);
179 Handle(Geom2d_TrimmedCurve) tL = new Geom2d_TrimmedCurve(L,0.,.5);
180 DrawTrSurf::Set(aaa,tL);
183 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const gp_Pnt2d& p2d)
185 char* aaa = aa.ToCString(); DrawTrSurf::Set(aaa,p2d);
187 Standard_EXPORT void FUN_tool_draw (const TCollection_AsciiString aa,const gp_Pnt& p)
189 char* aaa = aa.ToCString(); DrawTrSurf::Set(aaa,p);
192 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const Handle(Geom2d_Curve) c2d)
194 Draw_Color col(Draw_blanc); DrawTrSurf_CurveColor(col); char* aaa = aa.ToCString();
195 DrawTrSurf::Set(aaa,c2d);
197 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const Handle(Geom2d_Curve) c2d,
198 const Standard_Real f, const Standard_Real l)
200 Standard_Real tol = 1.e-7; Handle(Geom2d_Curve) cc2d;
201 if (Abs(f)<=tol && Abs(l)<=tol) cc2d = c2d;
202 else cc2d = new Geom2d_TrimmedCurve(c2d,f,l);
203 FUN_tool_draw(aa,cc2d);
205 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString& aa, const Handle(Geom_Curve)& C)
207 char* aaa = aa.ToCString();
208 DrawTrSurf::Set(aaa,C);
210 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const Handle(Geom_Curve) c,
211 const Standard_Real f, const Standard_Real l)
213 Standard_Real tol = 1.e-7; Handle(Geom_Curve) cc;
214 if (Abs(f)<=tol && Abs(l)<=tol) cc = c;
215 else cc = new Geom_TrimmedCurve(c,f,l);
216 FUN_tool_draw(aa,cc);
219 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa, const TopoDS_Shape& s)
221 char* aaa = aa.ToCString(); DBRep::Set(aaa,s);
223 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const TopoDS_Shape& S,const Standard_Integer is)
225 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(is); FUN_tool_draw(bb,S);
227 Standard_EXPORT void FUN_tool_draw(TCollection_AsciiString aa,const TopoDS_Edge& E, const TopoDS_Face& F,const Standard_Integer ie)
229 if (E.IsNull()) {std::cout<<"************* null edge\n"; return;}
230 Standard_Real f,l; const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(E,F,f,l);
231 if (PC.IsNull()) {std::cout<<"************* no curv on surf\n"; return;}
232 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(ie);
233 char* aaa = bb.ToCString();
235 Standard_Boolean coldef = Standard_False;
236 TopExp_Explorer ex(F,TopAbs_EDGE);
237 Draw_Color col,savecol = DrawTrSurf_CurveColor(Draw_rouge);
238 for (; ex.More(); ex.Next())
239 if (E.IsEqual(ex.Current()))
240 {col = DBRep_ColorOrientation(ex.Current().Orientation());
241 coldef = Standard_True;
243 if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
245 DrawTrSurf_CurveColor(col);
246 DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
249 Standard_EXPORT const TCollection_AsciiString& FUN_tool_PRODINS()
251 static TCollection_AsciiString PRODINS("dins ");
255 Standard_EXPORT const TCollection_AsciiString& FUN_tool_PRODINP()
257 static TCollection_AsciiString PRODINP("dinp ");