0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / TestTopOpeDraw / TestTopOpeDraw_DrawableSUR.cxx
1 // Created on: 1996-09-11
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <TestTopOpeDraw_DrawableSUR.ixx>
23 #include <Geom_RectangularTrimmedSurface.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRepTools.hxx>
26 #include <gp_Vec.hxx>
27 #include <gp_Vec2d.hxx>
28 #include <gp_Dir2d.hxx>
29 #include <gp.hxx>
30
31 //=======================================================================
32 //function : TestTopOpeDraw_DrawableSUR
33 //purpose  : 
34 //=======================================================================
35
36 TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR
37 (const Handle(Geom_Surface)& S, const Draw_Color& IsoColor) :
38  DrawTrSurf_Surface(S,0, 0, Draw_cyan, IsoColor,16,  0.01, 1),
39                   //  nu,nv,boundscolor         Disc,Defl, DMode)
40  myNormalColor(Draw_blanc)
41
42 {
43   myText = new Draw_Text3D(Pnt(),"",IsoColor);
44 }
45
46 //=======================================================================
47 //function : TestTopOpeDraw_DrawableSUR
48 //purpose  : 
49 //=======================================================================
50
51 TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR
52 (const Handle(Geom_Surface)& S, const Draw_Color& IsoColor,
53  const Standard_CString Text,const Draw_Color& TextColor) :
54  DrawTrSurf_Surface(S,0, 0, Draw_cyan, IsoColor,16,  0.01, 1),
55                   //  nu,nv,boundscolor         Disc,Defl, DMode)
56  myNormalColor(Draw_blanc)
57
58 {
59   myText = new Draw_Text3D(Pnt(),Text,TextColor);
60 }
61
62 //=======================================================================
63 //function : TestTopOpeDraw_DrawableSUR
64 //purpose  : 
65 //=======================================================================
66
67 TestTopOpeDraw_DrawableSUR::TestTopOpeDraw_DrawableSUR
68 (const Handle(Geom_Surface)& S,
69  const Draw_Color& IsoColor,
70  const Draw_Color& BoundColor, 
71  const Draw_Color& NormalColor,
72  const Standard_CString Text,const Draw_Color& TextColor,
73  const Standard_Integer Nu, const Standard_Integer Nv,
74  const Standard_Integer Disc, const Standard_Real Defl, const Standard_Integer DMode,
75  const Standard_Boolean /*DispOrigin*/) :
76  DrawTrSurf_Surface(S,Nu,Nv,IsoColor,BoundColor,Disc,Defl,DMode)
77 {
78   myText = new Draw_Text3D(Pnt(),Text,TextColor);
79   myNormalColor = NormalColor;
80 }
81
82 //=======================================================================
83 //function : Pnt2d
84 //purpose  : 
85 //=======================================================================
86
87 gp_Pnt2d TestTopOpeDraw_DrawableSUR::Pnt2d() const 
88 {
89   const Handle(Geom_Surface)& GS = GetSurface();
90   Standard_Real u1,u2,v1,v2; GS->Bounds(u1,u2,v1,v2);
91   Standard_Real facpar = 0.20;
92   Standard_Real u = u1 + (u2-u1)*facpar;
93   Standard_Real v = v1 + (v2-v1)*facpar;
94   gp_Pnt2d P(u,v);
95   return P;
96 }
97
98 //=======================================================================
99 //function : Pnt
100 //purpose  : 
101 //=======================================================================
102
103 gp_Pnt TestTopOpeDraw_DrawableSUR::Pnt() const
104 {
105   const Handle(Geom_Surface)& GS = GetSurface();
106   gp_Pnt2d P2d = Pnt2d();
107   gp_Pnt P = GS->Value(P2d.X(),P2d.Y());
108   return P;
109 }
110
111 //=======================================================================
112 //function : DrawOn
113 //purpose  : 
114 //=======================================================================
115
116 void  TestTopOpeDraw_DrawableSUR::DrawOn(Draw_Display& dis) const
117 {
118   DrawTrSurf_Surface::DrawOn(dis);
119   myText->DrawOn(dis);
120   DrawNormale(dis);
121 }
122
123 //=======================================================================
124 //function : NormalColor
125 //purpose  : 
126 //=======================================================================
127
128 void  TestTopOpeDraw_DrawableSUR::NormalColor(const Draw_Color& NormalColor)
129 {
130   myNormalColor =  NormalColor;
131 }
132
133 //=======================================================================
134 //function : DrawNormale
135 //purpose  : 
136 //=======================================================================
137
138 void  TestTopOpeDraw_DrawableSUR::DrawNormale(Draw_Display& dis) const 
139 {
140   dis.SetColor(myNormalColor);
141
142   // la normale
143   gp_Pnt2d P2d = Pnt2d(); Standard_Real u,v; P2d.Coord(u,v);
144   gp_Pnt P1,P2; gp_Vec V,V1,V2; 
145   const Handle(Geom_Surface)& GS = GetSurface();
146   GS->D1(u,v,P1,V1,V2); 
147   Standard_Real mag; V = V1.Crossed(V2); mag = V.Magnitude();
148   Standard_Real lvec = 1.;
149   Handle(Geom_RectangularTrimmedSurface) GRTS;
150   GRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(GS);
151   if (!GRTS.IsNull()) {
152     Standard_Real u1,u2,v1,v2; GRTS->Bounds(u1,u2,v1,v2);
153     gp_Pnt Pmin,Pmax; GRTS->D0(u1,v1,Pmin); GRTS->D0(u2,v2,Pmax);
154     lvec = Pmin.Distance(Pmax);
155   }
156   if (mag > 1.e-10) V.Multiply(lvec/mag);
157   else { V.SetCoord(lvec/2.,0,0); cout<<"Null normal"<<endl; }
158   P2 = P1; P2.Translate(V);
159   dis.Draw(P1,P2);
160
161   // la fleche de la normale
162   gp_Pnt2d p1,p2;
163   dis.Project(P1,p1);
164   dis.Project(P2,p2);
165   gp_Vec2d v2d(p1,p2);
166   if (v2d.Magnitude() > gp::Resolution()) {
167     Standard_Real L = 20 / dis.Zoom();
168     Standard_Real H = 10 / dis.Zoom();
169     gp_Dir2d d2d(v2d);
170     gp_Pnt2d pp;
171     pp.SetCoord(p2.X() - L*d2d.X() - H*d2d.Y(), p2.Y() - L*d2d.Y() + H*d2d.X());
172     dis.MoveTo(pp);
173     dis.DrawTo(p2);
174     pp.SetCoord(p2.X() - L*d2d.X() + H*d2d.Y(), p2.Y() - L*d2d.Y() - H*d2d.X());
175     dis.DrawTo(pp);
176   }
177
178 }