b311480e |
1 | // Created on: 1994-10-24 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <BRep_Tool.hxx> |
7fd59977 |
19 | #include <BRepAdaptor_Curve.hxx> |
42cf5bc1 |
20 | #include <BRepAdaptor_Surface.hxx> |
21 | #include <BRepTools.hxx> |
7fd59977 |
22 | #include <Draw_Color.hxx> |
42cf5bc1 |
23 | #include <Draw_Display.hxx> |
24 | #include <Draw_Marker3D.hxx> |
7fd59977 |
25 | #include <Draw_Segment3D.hxx> |
42cf5bc1 |
26 | #include <Draw_Text3D.hxx> |
ec357c5c |
27 | #include <Geom_Curve.hxx> |
42cf5bc1 |
28 | #include <Geom_RectangularTrimmedSurface.hxx> |
29 | #include <Geom_Surface.hxx> |
30 | #include <Geom_TrimmedCurve.hxx> |
31 | #include <gp.hxx> |
32 | #include <gp_Pnt.hxx> |
33 | #include <gp_Vec.hxx> |
34 | #include <Precision.hxx> |
35 | #include <Standard_Type.hxx> |
36 | #include <TestTopOpeDraw_DrawableC3D.hxx> |
37 | #include <TestTopOpeDraw_DrawableP3D.hxx> |
38 | #include <TestTopOpeDraw_DrawableSHA.hxx> |
39 | #include <TestTopOpeDraw_DrawableSUR.hxx> |
40 | #include <TopExp_Explorer.hxx> |
41 | #include <TopoDS.hxx> |
42 | #include <TopoDS_Face.hxx> |
43 | #include <TopoDS_Iterator.hxx> |
44 | #include <TopoDS_Shape.hxx> |
7fd59977 |
45 | |
92efcf78 |
46 | IMPLEMENT_STANDARD_RTTIEXT(TestTopOpeDraw_DrawableSHA,DBRep_DrawableShape) |
47 | |
7fd59977 |
48 | Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation); |
49 | |
50 | //======================================================================= |
51 | //function : TestTopOpeDraw_DrawableSHA |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | TestTopOpeDraw_DrawableSHA::TestTopOpeDraw_DrawableSHA |
56 | (const TopoDS_Shape& aShape, |
57 | const Draw_Color& FreeCol, |
58 | const Draw_Color& ConnCol, |
59 | const Draw_Color& EdgeCol, |
60 | const Draw_Color& IsosCol, |
61 | const Standard_Real size, |
62 | const Standard_Integer nbisos, |
63 | const Standard_Integer discret, |
64 | const Standard_CString Text, |
65 | const Draw_Color& TextColor, |
66 | const Standard_Boolean DisplayGeometry) : |
67 | DBRep_DrawableShape(aShape,FreeCol,ConnCol,EdgeCol,IsosCol,size,nbisos,discret), |
68 | myTol(0.0), myPar(-1.0) |
69 | { |
70 | myDisplayGeometry = DisplayGeometry; |
71 | myText = new Draw_Text3D(Pnt(),Text,TextColor); |
72 | myTextColor = TextColor; |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : Pnt |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | gp_Pnt TestTopOpeDraw_DrawableSHA::Pnt() const |
82 | { |
83 | gp_Pnt P(0,0,0); |
84 | Standard_Real u1,u2,v1,v2; |
85 | TopExp_Explorer ex; |
86 | |
87 | TopoDS_Shape S = Shape(); |
88 | TopAbs_ShapeEnum T = S.ShapeType(); |
89 | Standard_Real facpar = 0.; |
90 | |
91 | while ( T == TopAbs_COMPOUND ) { |
92 | TopoDS_Iterator ti(S); |
93 | if ( ti.More() ) { |
94 | S = ti.Value(); T = S.ShapeType(); |
95 | } |
96 | else { |
97 | break; |
98 | } |
99 | } |
100 | // si S final = compound --> P = 0 0 0 |
101 | |
102 | switch (T) { |
103 | |
104 | case TopAbs_VERTEX : |
105 | P = BRep_Tool::Pnt(TopoDS::Vertex(S)); |
106 | break; |
107 | |
108 | case TopAbs_WIRE : |
109 | T = TopAbs_EDGE; |
110 | ex.Init(S,T); S = ex.Current(); |
111 | facpar = 0.33; |
112 | // no break, in order to execute EDGE case |
113 | |
114 | case TopAbs_EDGE : |
115 | { |
116 | BRepAdaptor_Curve CU(TopoDS::Edge(S)); |
117 | u1 = CU.FirstParameter(); u2 = CU.LastParameter(); |
118 | if (facpar == 0.) facpar = 0.20; |
119 | if (myPar != -1.0) facpar = myPar; |
120 | Standard_Real p = u1 + (u2-u1)*facpar; |
121 | P = CU.Value(p); |
122 | } |
123 | break; |
124 | |
125 | case TopAbs_SHELL : case TopAbs_SOLID : case TopAbs_COMPSOLID : |
126 | T = TopAbs_FACE; |
127 | ex.Init(S,T); S = ex.Current(); |
128 | facpar = 0.33; |
129 | // no break, in order to execute FACE case |
130 | |
131 | case TopAbs_FACE : |
132 | { |
133 | BRepAdaptor_Surface SU(TopoDS::Face(S)); |
134 | BRepTools::UVBounds(TopoDS::Face(S),u1,u2,v1,v2); |
135 | if (facpar == 0.) facpar = 0.20; |
136 | Standard_Real u = u1 + (u2-u1)*facpar; |
137 | Standard_Real v = v1 + (v2-v1)*facpar; |
138 | P = SU.Value(u,v); |
139 | } |
140 | break; |
7fd59977 |
141 | default: |
142 | break; |
7fd59977 |
143 | } |
144 | |
145 | return P; |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : SetDisplayGeometry |
150 | //purpose : |
151 | //======================================================================= |
152 | |
153 | void TestTopOpeDraw_DrawableSHA::SetDisplayGeometry(const Standard_Boolean b) |
154 | { |
155 | myDisplayGeometry = b; |
156 | } |
157 | |
158 | //======================================================================= |
159 | //function : SetTol |
160 | //purpose : |
161 | //======================================================================= |
162 | |
163 | void TestTopOpeDraw_DrawableSHA::SetTol(const Standard_Real t) |
164 | { |
165 | myTol = t; |
166 | if(myTol != 0.0) |
167 | myDM3d = new Draw_Marker3D(Pnt(), Draw_CircleZoom , Draw_rouge, myTol); |
168 | } |
169 | |
170 | |
171 | //======================================================================= |
172 | //function : SetPar |
173 | //purpose : |
174 | //======================================================================= |
175 | |
176 | void TestTopOpeDraw_DrawableSHA::SetPar(const Standard_Real t) |
177 | { |
178 | myPar = t; |
179 | myText->SetPnt(Pnt()); |
180 | } |
181 | |
182 | |
183 | //======================================================================= |
184 | //function : DrawOn |
185 | //purpose : |
186 | //======================================================================= |
187 | |
188 | void TestTopOpeDraw_DrawableSHA::DrawOn(Draw_Display& dis) const |
189 | { |
190 | if(myDM3d.IsNull()) |
191 | DBRep_DrawableShape::DrawOn(dis); |
192 | else |
193 | myDM3d->DrawOn(dis); |
194 | myText->DrawOn(dis); |
195 | if (myDisplayGeometry) DisplayGeometry(dis); |
196 | } |
197 | |
198 | //======================================================================= |
199 | //function : DisplayGeometry |
200 | //purpose : |
201 | //======================================================================= |
202 | |
203 | void TestTopOpeDraw_DrawableSHA::DisplayGeometry(Draw_Display& dis) const |
204 | { |
205 | const TopoDS_Shape& aShape = Shape(); |
206 | const TopAbs_ShapeEnum t = aShape.ShapeType(); |
207 | |
208 | if ( t == TopAbs_FACE ) { |
209 | const TopoDS_Face& F = TopoDS::Face(aShape); |
210 | TopLoc_Location loc; |
211 | Handle(Geom_Surface) GS = BRep_Tool::Surface(F,loc); |
212 | if ( GS.IsNull() ) return; |
213 | Standard_Real u1,u2,v1,v2; BRepTools::UVBounds(F,u1,u2,v1,v2); |
214 | GS = Handle(Geom_Surface)::DownCast(GS->Transformed(loc.Transformation())); |
215 | Handle(Geom_RectangularTrimmedSurface) GRTS; |
216 | GRTS = new Geom_RectangularTrimmedSurface(GS,u1,u2,v1,v2); |
217 | Handle(TestTopOpeDraw_DrawableSUR) D; |
218 | D = new TestTopOpeDraw_DrawableSUR(GRTS,Draw_bleu); |
219 | Draw_Color norcol = DBRep_ColorOrientation(aShape.Orientation()); |
220 | D->NormalColor(norcol); |
221 | D->DrawNormale(dis); |
222 | } |
223 | |
224 | else if ( t == TopAbs_EDGE ) { |
225 | const TopoDS_Edge& E = TopoDS::Edge(aShape); |
226 | TopLoc_Location loc; Standard_Real f,l; |
227 | Handle(Geom_Curve) GC = BRep_Tool::Curve(E,loc,f,l); |
228 | if ( GC.IsNull() ) return; |
229 | GC = Handle(Geom_Curve)::DownCast(GC->Transformed(loc.Transformation())); |
230 | Handle(Geom_TrimmedCurve) GTC = new Geom_TrimmedCurve(GC,f,l); |
231 | Handle(TestTopOpeDraw_DrawableC3D) D; |
232 | D = new TestTopOpeDraw_DrawableC3D(GTC,myTextColor); |
233 | D->DrawOn(dis); |
234 | } |
235 | |
236 | else if ( t == TopAbs_VERTEX ) { |
237 | const TopoDS_Vertex& V = TopoDS::Vertex(aShape); |
238 | gp_Pnt P = BRep_Tool::Pnt(V); |
239 | Handle(TestTopOpeDraw_DrawableP3D) D; |
240 | D = new TestTopOpeDraw_DrawableP3D(P,myTextColor); |
241 | D->DrawOn(dis); |
242 | } |
243 | |
244 | } |