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
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.
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.
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.
22 #include <TestTopOpeDraw_DrawableSUR.ixx>
23 #include <Geom_RectangularTrimmedSurface.hxx>
24 #include <BRepAdaptor_Surface.hxx>
25 #include <BRepTools.hxx>
27 #include <gp_Vec2d.hxx>
28 #include <gp_Dir2d.hxx>
31 //=======================================================================
32 //function : TestTopOpeDraw_DrawableSUR
34 //=======================================================================
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)
43 myText = new Draw_Text3D(Pnt(),"",IsoColor);
46 //=======================================================================
47 //function : TestTopOpeDraw_DrawableSUR
49 //=======================================================================
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)
59 myText = new Draw_Text3D(Pnt(),Text,TextColor);
62 //=======================================================================
63 //function : TestTopOpeDraw_DrawableSUR
65 //=======================================================================
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)
78 myText = new Draw_Text3D(Pnt(),Text,TextColor);
79 myNormalColor = NormalColor;
82 //=======================================================================
85 //=======================================================================
87 gp_Pnt2d TestTopOpeDraw_DrawableSUR::Pnt2d() const
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;
98 //=======================================================================
101 //=======================================================================
103 gp_Pnt TestTopOpeDraw_DrawableSUR::Pnt() const
105 const Handle(Geom_Surface)& GS = GetSurface();
106 gp_Pnt2d P2d = Pnt2d();
107 gp_Pnt P = GS->Value(P2d.X(),P2d.Y());
111 //=======================================================================
114 //=======================================================================
116 void TestTopOpeDraw_DrawableSUR::DrawOn(Draw_Display& dis) const
118 DrawTrSurf_Surface::DrawOn(dis);
123 //=======================================================================
124 //function : NormalColor
126 //=======================================================================
128 void TestTopOpeDraw_DrawableSUR::NormalColor(const Draw_Color& NormalColor)
130 myNormalColor = NormalColor;
133 //=======================================================================
134 //function : DrawNormale
136 //=======================================================================
138 void TestTopOpeDraw_DrawableSUR::DrawNormale(Draw_Display& dis) const
140 dis.SetColor(myNormalColor);
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);
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);
161 // la fleche de la normale
166 if (v2d.Magnitude() > gp::Resolution()) {
167 Standard_Real L = 20 / dis.Zoom();
168 Standard_Real H = 10 / dis.Zoom();
171 pp.SetCoord(p2.X() - L*d2d.X() - H*d2d.Y(), p2.Y() - L*d2d.Y() + H*d2d.X());
174 pp.SetCoord(p2.X() - L*d2d.X() + H*d2d.Y(), p2.Y() - L*d2d.Y() - H*d2d.X());