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 | |
7fd59977 |
15 | #include <DrawTrSurf_BezierSurface.ixx> |
16 | #include <DrawTrSurf_BezierCurve.hxx> |
17 | #include <Geom_BezierSurface.hxx> |
18 | #include <gp_Pnt2d.hxx> |
19 | #include <TColgp_Array2OfPnt.hxx> |
20 | #include <TColStd_Array1OfReal.hxx> |
21 | |
b311480e |
22 | DrawTrSurf_BezierSurface::DrawTrSurf_BezierSurface ( |
7fd59977 |
23 | const Handle(Geom_BezierSurface)& S) |
24 | : DrawTrSurf_Surface (S, 1, 1, Draw_jaune, Draw_bleu, 30, 0.05, 0) { |
25 | |
26 | drawPoles = Standard_True; |
27 | polesLook = Draw_rouge; |
28 | } |
29 | |
30 | |
31 | |
32 | DrawTrSurf_BezierSurface::DrawTrSurf_BezierSurface ( |
33 | const Handle(Geom_BezierSurface)& S, |
34 | const Standard_Integer NbUIsos, const Standard_Integer NbVIsos, |
35 | const Draw_Color& BoundsColor, const Draw_Color& IsosColor, |
36 | const Draw_Color& PolesColor, const Standard_Boolean ShowPoles, |
37 | const Standard_Integer Discret,const Standard_Real Deflection, |
38 | const Standard_Integer DrawMode) |
39 | : DrawTrSurf_Surface (S, NbUIsos, NbVIsos, BoundsColor, IsosColor, |
40 | Discret, Deflection, DrawMode){ |
41 | |
42 | drawPoles = ShowPoles; |
43 | polesLook = PolesColor; |
44 | } |
45 | |
46 | |
47 | |
48 | void DrawTrSurf_BezierSurface::DrawOn (Draw_Display& dis) const { |
49 | |
50 | Standard_Integer i,j; |
51 | Handle(Geom_BezierSurface) S = Handle(Geom_BezierSurface)::DownCast(surf); |
52 | |
53 | if (drawPoles) { |
54 | Standard_Integer NbUPoles = S->NbUPoles(); |
55 | Standard_Integer NbVPoles = S->NbVPoles(); |
56 | dis.SetColor(polesLook); |
57 | TColgp_Array2OfPnt SPoles (1, NbUPoles, 1, NbVPoles); |
58 | S->Poles (SPoles); |
59 | for (j = 1; j <= NbVPoles; j++) { |
60 | dis.MoveTo(SPoles(1, j)); |
61 | for (i = 2; i <= NbUPoles; i++) { |
62 | dis.DrawTo(SPoles(i, j)); |
63 | } |
64 | } |
65 | for (i = 1; i <= NbUPoles; i++) { |
66 | dis.MoveTo(SPoles(i, 1)); |
67 | for (j = 2; j <= NbVPoles; j++) { |
68 | dis.DrawTo(SPoles(i, j)); |
69 | } |
70 | } |
71 | } |
72 | |
73 | |
74 | DrawTrSurf_Surface::DrawOn(dis); |
75 | } |
76 | |
77 | |
78 | void DrawTrSurf_BezierSurface::ShowPoles () { drawPoles = Standard_True; } |
79 | |
80 | |
81 | void DrawTrSurf_BezierSurface::ClearPoles () { drawPoles = Standard_False; } |
82 | |
83 | |
84 | void DrawTrSurf_BezierSurface::FindPole ( |
85 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, |
86 | const Standard_Real XPrec, Standard_Integer& UIndex, Standard_Integer& VIndex) const { |
87 | |
88 | Handle(Geom_BezierSurface) bs = Handle(Geom_BezierSurface)::DownCast(surf); |
89 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
90 | Standard_Real Prec = XPrec / D.Zoom(); |
91 | UIndex++; |
92 | VIndex++; |
93 | Standard_Integer NbUPoles = bs->NbUPoles(); |
94 | Standard_Integer NbVPoles = bs->NbVPoles(); |
95 | while (VIndex <= NbVPoles) { |
96 | while (UIndex <= NbUPoles) { |
97 | if (D.Project(bs->Pole(UIndex, VIndex)).Distance(p1) <= Prec) |
98 | return; |
99 | UIndex++; |
100 | } |
101 | UIndex = 1; |
102 | VIndex++; |
103 | } |
104 | UIndex = VIndex = 0; |
105 | } |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : Copy |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Handle(Draw_Drawable3D) DrawTrSurf_BezierSurface::Copy()const |
114 | { |
115 | Handle(DrawTrSurf_BezierSurface) DS = new DrawTrSurf_BezierSurface |
116 | (Handle(Geom_BezierSurface)::DownCast(surf->Copy()), |
117 | nbUIsos,nbVIsos, |
118 | boundsLook,isosLook,polesLook,drawPoles, |
119 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
120 | |
121 | return DS; |
122 | } |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | |
129 | |