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