b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
42cf5bc1 |
15 | |
16 | #include <Draw_Color.hxx> |
17 | #include <Draw_Display.hxx> |
18 | #include <Draw_Drawable3D.hxx> |
7fd59977 |
19 | #include <DrawTrSurf_BezierCurve.hxx> |
42cf5bc1 |
20 | #include <DrawTrSurf_BezierSurface.hxx> |
7fd59977 |
21 | #include <Geom_BezierSurface.hxx> |
22 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
23 | #include <Standard_Type.hxx> |
7fd59977 |
24 | #include <TColgp_Array2OfPnt.hxx> |
25 | #include <TColStd_Array1OfReal.hxx> |
26 | |
b311480e |
27 | DrawTrSurf_BezierSurface::DrawTrSurf_BezierSurface ( |
7fd59977 |
28 | const Handle(Geom_BezierSurface)& S) |
29 | : DrawTrSurf_Surface (S, 1, 1, Draw_jaune, Draw_bleu, 30, 0.05, 0) { |
30 | |
31 | drawPoles = Standard_True; |
32 | polesLook = Draw_rouge; |
33 | } |
34 | |
35 | |
36 | |
37 | DrawTrSurf_BezierSurface::DrawTrSurf_BezierSurface ( |
38 | const Handle(Geom_BezierSurface)& S, |
39 | const Standard_Integer NbUIsos, const Standard_Integer NbVIsos, |
40 | const Draw_Color& BoundsColor, const Draw_Color& IsosColor, |
41 | const Draw_Color& PolesColor, const Standard_Boolean ShowPoles, |
42 | const Standard_Integer Discret,const Standard_Real Deflection, |
43 | const Standard_Integer DrawMode) |
44 | : DrawTrSurf_Surface (S, NbUIsos, NbVIsos, BoundsColor, IsosColor, |
45 | Discret, Deflection, DrawMode){ |
46 | |
47 | drawPoles = ShowPoles; |
48 | polesLook = PolesColor; |
49 | } |
50 | |
51 | |
52 | |
53 | void DrawTrSurf_BezierSurface::DrawOn (Draw_Display& dis) const { |
54 | |
55 | Standard_Integer i,j; |
56 | Handle(Geom_BezierSurface) S = Handle(Geom_BezierSurface)::DownCast(surf); |
57 | |
58 | if (drawPoles) { |
59 | Standard_Integer NbUPoles = S->NbUPoles(); |
60 | Standard_Integer NbVPoles = S->NbVPoles(); |
61 | dis.SetColor(polesLook); |
62 | TColgp_Array2OfPnt SPoles (1, NbUPoles, 1, NbVPoles); |
63 | S->Poles (SPoles); |
64 | for (j = 1; j <= NbVPoles; j++) { |
65 | dis.MoveTo(SPoles(1, j)); |
66 | for (i = 2; i <= NbUPoles; i++) { |
67 | dis.DrawTo(SPoles(i, j)); |
68 | } |
69 | } |
70 | for (i = 1; i <= NbUPoles; i++) { |
71 | dis.MoveTo(SPoles(i, 1)); |
72 | for (j = 2; j <= NbVPoles; j++) { |
73 | dis.DrawTo(SPoles(i, j)); |
74 | } |
75 | } |
76 | } |
77 | |
78 | |
79 | DrawTrSurf_Surface::DrawOn(dis); |
80 | } |
81 | |
82 | |
83 | void DrawTrSurf_BezierSurface::ShowPoles () { drawPoles = Standard_True; } |
84 | |
85 | |
86 | void DrawTrSurf_BezierSurface::ClearPoles () { drawPoles = Standard_False; } |
87 | |
88 | |
89 | void DrawTrSurf_BezierSurface::FindPole ( |
90 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, |
91 | const Standard_Real XPrec, Standard_Integer& UIndex, Standard_Integer& VIndex) const { |
92 | |
93 | Handle(Geom_BezierSurface) bs = Handle(Geom_BezierSurface)::DownCast(surf); |
94 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
95 | Standard_Real Prec = XPrec / D.Zoom(); |
96 | UIndex++; |
97 | VIndex++; |
98 | Standard_Integer NbUPoles = bs->NbUPoles(); |
99 | Standard_Integer NbVPoles = bs->NbVPoles(); |
100 | while (VIndex <= NbVPoles) { |
101 | while (UIndex <= NbUPoles) { |
102 | if (D.Project(bs->Pole(UIndex, VIndex)).Distance(p1) <= Prec) |
103 | return; |
104 | UIndex++; |
105 | } |
106 | UIndex = 1; |
107 | VIndex++; |
108 | } |
109 | UIndex = VIndex = 0; |
110 | } |
111 | |
112 | |
113 | //======================================================================= |
114 | //function : Copy |
115 | //purpose : |
116 | //======================================================================= |
117 | |
118 | Handle(Draw_Drawable3D) DrawTrSurf_BezierSurface::Copy()const |
119 | { |
120 | Handle(DrawTrSurf_BezierSurface) DS = new DrawTrSurf_BezierSurface |
121 | (Handle(Geom_BezierSurface)::DownCast(surf->Copy()), |
122 | nbUIsos,nbVIsos, |
123 | boundsLook,isosLook,polesLook,drawPoles, |
124 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
125 | |
126 | return DS; |
127 | } |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 | |