b311480e |
1 | // Created on: 1996-09-11 |
2 | // Created by: Jean Yves LEBEY |
3 | // Copyright (c) 1996-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 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <BRepAdaptor_Surface.hxx> |
19 | #include <BRepTools.hxx> |
42cf5bc1 |
20 | #include <Draw_Color.hxx> |
21 | #include <Draw_Display.hxx> |
22 | #include <Draw_Text3D.hxx> |
23 | #include <Geom_RectangularTrimmedSurface.hxx> |
24 | #include <Geom_Surface.hxx> |
25 | #include <gp.hxx> |
26 | #include <gp_Dir2d.hxx> |
27 | #include <gp_Pnt.hxx> |
28 | #include <gp_Pnt2d.hxx> |
7fd59977 |
29 | #include <gp_Vec.hxx> |
30 | #include <gp_Vec2d.hxx> |
42cf5bc1 |
31 | #include <Standard_Type.hxx> |
32 | #include <TestTopOpeDraw_DrawableSUR.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(TestTopOpeDraw_DrawableSUR,DrawTrSurf_Surface) |
35 | |
7fd59977 |
36 | //======================================================================= |
37 | //function : TestTopOpeDraw_DrawableSUR |
38 | //purpose : |
39 | //======================================================================= |
7fd59977 |
40 | TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR |
41 | (const Handle(Geom_Surface)& S, const Draw_Color& IsoColor) : |
42 | DrawTrSurf_Surface(S,0, 0, Draw_cyan, IsoColor,16, 0.01, 1), |
43 | // nu,nv,boundscolor Disc,Defl, DMode) |
44 | myNormalColor(Draw_blanc) |
45 | |
46 | { |
47 | myText = new Draw_Text3D(Pnt(),"",IsoColor); |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : TestTopOpeDraw_DrawableSUR |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR |
56 | (const Handle(Geom_Surface)& S, const Draw_Color& IsoColor, |
57 | const Standard_CString Text,const Draw_Color& TextColor) : |
58 | DrawTrSurf_Surface(S,0, 0, Draw_cyan, IsoColor,16, 0.01, 1), |
59 | // nu,nv,boundscolor Disc,Defl, DMode) |
60 | myNormalColor(Draw_blanc) |
61 | |
62 | { |
63 | myText = new Draw_Text3D(Pnt(),Text,TextColor); |
64 | } |
65 | |
66 | //======================================================================= |
67 | //function : TestTopOpeDraw_DrawableSUR |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR |
72 | (const Handle(Geom_Surface)& S, |
73 | const Draw_Color& IsoColor, |
74 | const Draw_Color& BoundColor, |
75 | const Draw_Color& NormalColor, |
76 | const Standard_CString Text,const Draw_Color& TextColor, |
77 | const Standard_Integer Nu, const Standard_Integer Nv, |
78 | const Standard_Integer Disc, const Standard_Real Defl, const Standard_Integer DMode, |
35e08fe8 |
79 | const Standard_Boolean /*DispOrigin*/) : |
7fd59977 |
80 | DrawTrSurf_Surface(S,Nu,Nv,IsoColor,BoundColor,Disc,Defl,DMode) |
81 | { |
82 | myText = new Draw_Text3D(Pnt(),Text,TextColor); |
83 | myNormalColor = NormalColor; |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : Pnt2d |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | gp_Pnt2d TestTopOpeDraw_DrawableSUR::Pnt2d() const |
92 | { |
93 | const Handle(Geom_Surface)& GS = GetSurface(); |
94 | Standard_Real u1,u2,v1,v2; GS->Bounds(u1,u2,v1,v2); |
95 | Standard_Real facpar = 0.20; |
96 | Standard_Real u = u1 + (u2-u1)*facpar; |
97 | Standard_Real v = v1 + (v2-v1)*facpar; |
98 | gp_Pnt2d P(u,v); |
99 | return P; |
100 | } |
101 | |
102 | //======================================================================= |
103 | //function : Pnt |
104 | //purpose : |
105 | //======================================================================= |
106 | |
107 | gp_Pnt TestTopOpeDraw_DrawableSUR::Pnt() const |
108 | { |
109 | const Handle(Geom_Surface)& GS = GetSurface(); |
110 | gp_Pnt2d P2d = Pnt2d(); |
111 | gp_Pnt P = GS->Value(P2d.X(),P2d.Y()); |
112 | return P; |
113 | } |
114 | |
115 | //======================================================================= |
116 | //function : DrawOn |
117 | //purpose : |
118 | //======================================================================= |
119 | |
120 | void TestTopOpeDraw_DrawableSUR::DrawOn(Draw_Display& dis) const |
121 | { |
122 | DrawTrSurf_Surface::DrawOn(dis); |
123 | myText->DrawOn(dis); |
124 | DrawNormale(dis); |
125 | } |
126 | |
127 | //======================================================================= |
128 | //function : NormalColor |
129 | //purpose : |
130 | //======================================================================= |
131 | |
132 | void TestTopOpeDraw_DrawableSUR::NormalColor(const Draw_Color& NormalColor) |
133 | { |
134 | myNormalColor = NormalColor; |
135 | } |
136 | |
137 | //======================================================================= |
138 | //function : DrawNormale |
139 | //purpose : |
140 | //======================================================================= |
141 | |
142 | void TestTopOpeDraw_DrawableSUR::DrawNormale(Draw_Display& dis) const |
143 | { |
144 | dis.SetColor(myNormalColor); |
145 | |
146 | // la normale |
147 | gp_Pnt2d P2d = Pnt2d(); Standard_Real u,v; P2d.Coord(u,v); |
148 | gp_Pnt P1,P2; gp_Vec V,V1,V2; |
149 | const Handle(Geom_Surface)& GS = GetSurface(); |
150 | GS->D1(u,v,P1,V1,V2); |
151 | Standard_Real mag; V = V1.Crossed(V2); mag = V.Magnitude(); |
152 | Standard_Real lvec = 1.; |
153 | Handle(Geom_RectangularTrimmedSurface) GRTS; |
154 | GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(GS); |
155 | if (!GRTS.IsNull()) { |
156 | Standard_Real u1,u2,v1,v2; GRTS->Bounds(u1,u2,v1,v2); |
157 | gp_Pnt Pmin,Pmax; GRTS->D0(u1,v1,Pmin); GRTS->D0(u2,v2,Pmax); |
158 | lvec = Pmin.Distance(Pmax); |
159 | } |
160 | if (mag > 1.e-10) V.Multiply(lvec/mag); |
161 | else { V.SetCoord(lvec/2.,0,0); cout<<"Null normal"<<endl; } |
162 | P2 = P1; P2.Translate(V); |
163 | dis.Draw(P1,P2); |
164 | |
165 | // la fleche de la normale |
166 | gp_Pnt2d p1,p2; |
167 | dis.Project(P1,p1); |
168 | dis.Project(P2,p2); |
169 | gp_Vec2d v2d(p1,p2); |
170 | if (v2d.Magnitude() > gp::Resolution()) { |
171 | Standard_Real L = 20 / dis.Zoom(); |
172 | Standard_Real H = 10 / dis.Zoom(); |
173 | gp_Dir2d d2d(v2d); |
174 | gp_Pnt2d pp; |
175 | pp.SetCoord(p2.X() - L*d2d.X() - H*d2d.Y(), p2.Y() - L*d2d.Y() + H*d2d.X()); |
176 | dis.MoveTo(pp); |
177 | dis.DrawTo(p2); |
178 | pp.SetCoord(p2.X() - L*d2d.X() + H*d2d.Y(), p2.Y() - L*d2d.Y() - H*d2d.X()); |
179 | dis.DrawTo(pp); |
180 | } |
181 | |
182 | } |