0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_DRAW.cxx
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
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 <TopOpeBRepTool_DRAW.hxx>
19 #include <TopOpeBRepDS_DRAW.hxx>
20
21 #include <DrawTrSurf.hxx>
22 #include <DBRep.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>
34 #include <TopoDS.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <Precision.hxx>
37
38 Standard_EXPORT void FUN_draw (const TopoDS_Shape& s)
39 {
40   char* nnn = TCollection_AsciiString("name").ToCString();
41   if (s.IsNull()) std::cout<<"nullshape"<<std::endl;
42   DBRep::Set(nnn,s);
43 }
44 Standard_EXPORT void FUN_draw (const gp_Pnt& p)
45 {
46   char* nnn = TCollection_AsciiString("name").ToCString();
47   DrawTrSurf::Set(nnn,p);
48 }
49 Standard_EXPORT void FUN_draw (const gp_Pnt2d& p)
50 {
51   char* nnn = TCollection_AsciiString("name").ToCString();
52   DrawTrSurf::Set(nnn,p);
53 }
54 Standard_EXPORT void FUN_draw (const Handle(Geom2d_Curve) c, const Standard_Real dpar)
55 {
56   char* nnn = TCollection_AsciiString("c2d").ToCString();
57   if (dpar <= Precision::Confusion()) {
58     DrawTrSurf::Set(nnn,c);
59     return;
60   }
61   Handle(Geom2d_TrimmedCurve) tC = new Geom2d_TrimmedCurve(c,0.,dpar);
62   DrawTrSurf::Set(nnn,tC);
63 }
64
65 Standard_EXPORT void FUN_draw (const gp_Pnt& p, const gp_Dir& d)
66 {
67   TCollection_AsciiString aa("dir"); FUN_tool_draw(aa,p,d);
68 }
69
70 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const gp_Pnt& p)
71 {  
72   FUN_tool_draw(aa,p);
73 }
74
75 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const gp_Pnt& p, const gp_Dir& d)
76 {
77   FUN_tool_draw(aa,p,d);
78 }
79 Standard_EXPORT void FUN_brep_draw (const TCollection_AsciiString& aa, const TopoDS_Shape& s)
80 {
81   FUN_tool_draw(aa,s);
82 }
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)
85 {
86   FUN_tool_draw(aa,C,f,l);
87 }
88 Standard_EXPORT void FUN_brep_draw 
89 (const TCollection_AsciiString& aa, const Handle(Geom_Curve)& C)
90 {
91   FUN_tool_draw(aa,C);
92 }
93
94 Standard_EXPORT void FUN_DrawMap
95 (const TopTools_DataMapOfShapeListOfShape& DataforDegenEd)
96 {
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;
104     itoflos.Next();
105     TopoDS_Shape Ed =itoflos.Value();
106
107     Standard_Boolean tr = Standard_False;
108     if (tr) { FUN_draw(v); FUN_draw(Ec); FUN_draw(Ed);} 
109   }
110 }
111
112 static Standard_Boolean FUN_hascurveonsurf(const TopoDS_Edge& edge,const TopoDS_Face& face)
113 {
114   TopLoc_Location L;
115   Handle(Geom_Surface) S = BRep_Tool::Surface(face,L);
116
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;
121
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;
128   }
129   return iscurveonS;
130 }
131
132 Standard_EXPORT void FUN_draw2de (const TopoDS_Shape& ed,const TopoDS_Shape& fa)
133 {
134   char* nnn = TCollection_AsciiString("name").ToCString();
135   Standard_Real f,l;
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;
142
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);
146
147   Handle(Geom2d_TrimmedCurve) tC2d = new Geom2d_TrimmedCurve(C2d,f,l,sense);
148   DrawTrSurf::Set(nnn,tC2d);
149 } // FUN_draw2de
150
151 Standard_EXPORT void FUN_draw2d(const Standard_Real& par,const TopoDS_Edge& E,const TopoDS_Edge& Eref,const TopoDS_Face& Fref)
152 {
153   TopAbs_Orientation oriE = E.Orientation();
154   TopAbs_Orientation oriEref = Eref.Orientation();
155   Standard_Boolean ErefonFref = Standard_False;
156   Standard_Boolean EonFref = Standard_False;
157   TopExp_Explorer ex; 
158   Standard_Integer ne = 0;
159   for (ex.Init(Fref,TopAbs_EDGE); ex.More(); ex.Next()) ne++;
160   if (ne < 1) return;
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;}    
165   }
166   gp_Pnt2d p2d;
167   if (ErefonFref || EonFref) {
168     Standard_Real f,l;
169     Handle(Geom2d_Curve) C2d;
170     if (ErefonFref) {
171       C2d = BRep_Tool::CurveOnSurface(Eref,Fref,f,l);  
172       FUN_draw2de(Eref,Fref); 
173     }
174     if (EonFref) {
175       C2d = BRep_Tool::CurveOnSurface(E,Fref,f,l); 
176       FUN_draw2de(E,Fref); 
177     }
178     C2d->D0(par,p2d); 
179   }
180   else {
181     Standard_Real 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); }
190   
191   FUN_draw(p2d);
192 } // FUN_draw2d
193
194 #endif