0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_DRAW.cxx
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
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 #ifdef DRAW
18 #include <DBRep.hxx>
19 #include <gp_Lin.hxx>
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <Draw.hxx>
23 #include <Draw_MarkerShape.hxx>
24 #include <Draw_Marker3D.hxx>
25 #include <Draw_Segment3D.hxx>
26 #include <ElCLib.hxx>
27 #include <TopAbs_State.hxx>
28 #include <TopExp.hxx>
29 #include <TopoDS.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>
39
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);
43
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;
48
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); }
58
59
60 //===========================================================================
61 void TopOpeBRepTool_DrawSegment
62   (const gp_Pnt& P1,const gp_Pnt& P2, const Draw_ColorKind C) 
63 //===========================================================================
64
65   dout << new Draw_Segment3D(P1,P2,C);
66   TopOpeBRepTool_DrawPoint(P1); TopOpeBRepTool_DrawPoint(P2);
67 }
68
69 void TopOpeBRepTool_DrawSegment(const gp_Pnt& P1, const gp_Pnt& P2) 
70 { TopOpeBRepTool_DrawSegment(P1,P2,SEGMENTCOLOR); }
71
72
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); }
79
80
81 //===========================================================================
82 Draw_ColorKind TopOpeBRepTool_ColorOnState(const TopAbs_State S)
83 //===========================================================================
84 {  
85   Draw_ColorKind c;
86   switch (S) {
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;
91   }
92   return c;
93 }
94
95 //===========================================================================
96 void TopOpeBRepTool_DrawSegment
97   (const gp_Pnt& P,const gp_Lin& L,const Standard_Real Par,
98    const TopAbs_State S) 
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); }
104
105
106 Standard_EXPORT void FDRAW_DINS(const TCollection_AsciiString pref,const TopoDS_Shape& SS,const TCollection_AsciiString Snam,const TCollection_AsciiString suff)
107 {
108   DBRep::Set(Snam.ToCString(),SS);
109   std::cout<<pref<<FUN_tool_PRODINS()<<" "<<Snam<<";"<<suff;
110 }
111
112 Standard_EXPORT void FDRAW_DINE(const TCollection_AsciiString pref,const TopoDS_Edge& EE,const TCollection_AsciiString Enam,const TCollection_AsciiString suff)
113 {
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;
121     
122 #if 0
123     Standard_Integer nfo=0,nre=0,nin=0,nex=0;
124     TopExp_Explorer exx;
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;
133       }
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;
138       }
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;
143       }
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;
148       }
149       
150       Standard_Real p = BRep_Tool::Parameter(vv,EE);
151       std::cout<<"; #draw ; par/"<<Enam<<" : "<<p<<std::endl;   
152     }
153 #endif
154     
155   }
156 }
157
158 Standard_EXPORT void FDRAW_DINLOE
159 (const TCollection_AsciiString pref,const TopTools_ListOfShape& LOE,const TCollection_AsciiString str1,const TCollection_AsciiString str2)
160 {
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");
165   }
166 }
167
168 Standard_EXPORT void FUN_tool_draw (const TCollection_AsciiString& aa, const gp_Pnt& p, const gp_Dir& d)
169 {
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);
174 }
175 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString& aa,const gp_Pnt2d& p, const gp_Dir2d& d,const Standard_Integer& i)
176 {  
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);
181 }
182
183 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const gp_Pnt2d& p2d)
184 {
185   char* aaa = aa.ToCString(); DrawTrSurf::Set(aaa,p2d);
186 }
187 Standard_EXPORT void FUN_tool_draw (const TCollection_AsciiString aa,const gp_Pnt& p)
188 {
189   char* aaa = aa.ToCString(); DrawTrSurf::Set(aaa,p);
190 }
191
192 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const Handle(Geom2d_Curve) c2d)
193 {
194   Draw_Color col(Draw_blanc); DrawTrSurf_CurveColor(col); char* aaa = aa.ToCString();
195   DrawTrSurf::Set(aaa,c2d);
196 }
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)
199 {
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);
204 }
205 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString& aa, const Handle(Geom_Curve)& C)
206 {
207   char* aaa = aa.ToCString();
208   DrawTrSurf::Set(aaa,C);
209 }
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)
212 {
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);
217 }
218
219 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa, const TopoDS_Shape& s)
220 {
221   char* aaa = aa.ToCString(); DBRep::Set(aaa,s);
222 }
223 Standard_EXPORT void FUN_tool_draw(const TCollection_AsciiString aa,const TopoDS_Shape& S,const Standard_Integer is)
224 {
225   TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(is); FUN_tool_draw(bb,S);
226 }
227 Standard_EXPORT void FUN_tool_draw(TCollection_AsciiString aa,const TopoDS_Edge& E, const TopoDS_Face& F,const Standard_Integer ie)
228 {  
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();
234
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;
242        break;}
243   if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
244     
245   DrawTrSurf_CurveColor(col);  
246   DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
247 }
248
249 Standard_EXPORT const TCollection_AsciiString& FUN_tool_PRODINS() 
250 {
251   static TCollection_AsciiString PRODINS("dins ");
252   return PRODINS;
253 }
254
255 Standard_EXPORT const TCollection_AsciiString& FUN_tool_PRODINP() 
256 {
257   static TCollection_AsciiString PRODINP("dinp ");
258   return PRODINP;
259 }
260
261 #endif