973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | /*********************************************************************** |
7fd59977 |
15 | FONCTION : |
16 | ---------- |
17 | Classe V3d_CircularGrid : |
81bba717 |
18 | VERSION HISTORY : |
7fd59977 |
19 | -------------------------------- |
7fd59977 |
20 | ************************************************************************/ |
7fd59977 |
21 | /*----------------------------------------------------------------------*/ |
22 | /* |
23 | * Includes |
24 | */ |
25 | |
7fd59977 |
26 | #include <Graphic3d_Array1OfVertex.hxx> |
a577aaab |
27 | #include <Graphic3d_ArrayOfPoints.hxx> |
b8ddfc2f |
28 | #include <Graphic3d_ArrayOfPolylines.hxx> |
42cf5bc1 |
29 | #include <Graphic3d_ArrayOfSegments.hxx> |
30 | #include <Graphic3d_AspectLine3d.hxx> |
31 | #include <Graphic3d_AspectMarker3d.hxx> |
32 | #include <Graphic3d_Group.hxx> |
33 | #include <Graphic3d_Structure.hxx> |
34 | #include <Graphic3d_Vertex.hxx> |
35 | #include <Quantity_Color.hxx> |
36 | #include <Standard_Type.hxx> |
b8ddfc2f |
37 | #include <TColgp_SequenceOfPnt.hxx> |
42cf5bc1 |
38 | #include <TColStd_Array2OfReal.hxx> |
39 | #include <V3d_CircularGrid.hxx> |
40 | #include <V3d_Viewer.hxx> |
41 | #include <Visual3d_ViewManager.hxx> |
7fd59977 |
42 | |
43 | /*----------------------------------------------------------------------*/ |
44 | /* |
45 | * Constant |
46 | */ |
7fd59977 |
47 | #define DIVISION 8 |
48 | #define MYMINMAX 25. |
49 | #define MYFACTOR 50. |
50 | |
51 | /*----------------------------------------------------------------------*/ |
52 | |
b8ddfc2f |
53 | V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor) |
54 | : Aspect_CircularGrid (1.,8), |
55 | myStructure (new Graphic3d_Structure (aViewer->Viewer ())), |
b64d84be |
56 | myGroup (myStructure->NewGroup()), |
b8ddfc2f |
57 | myViewer (aViewer), |
58 | myCurAreDefined (Standard_False) |
7fd59977 |
59 | { |
b8ddfc2f |
60 | myColor = aColor; |
61 | myTenthColor = aTenthColor; |
7fd59977 |
62 | |
b8ddfc2f |
63 | myStructure->SetInfiniteState (Standard_True); |
7fd59977 |
64 | |
b8ddfc2f |
65 | const Standard_Real step = 10.; |
66 | const Standard_Real size = 0.5*myViewer->DefaultViewSize(); |
67 | SetGraphicValues (size, step/MYFACTOR); |
68 | SetRadiusStep (step); |
7fd59977 |
69 | } |
70 | |
b8ddfc2f |
71 | void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor) |
72 | { |
73 | if( myColor != aColor || myTenthColor != aTenthColor ) { |
74 | myColor = aColor; |
75 | myTenthColor = aTenthColor; |
76 | myCurAreDefined = Standard_False; |
77 | UpdateDisplay(); |
78 | } |
7fd59977 |
79 | } |
80 | |
b8ddfc2f |
81 | void V3d_CircularGrid::Display () |
82 | { |
a1954302 |
83 | myStructure->SetDisplayPriority (1); |
84 | myStructure->Display(); |
7fd59977 |
85 | } |
86 | |
b8ddfc2f |
87 | void V3d_CircularGrid::Erase () const |
88 | { |
89 | myStructure->Erase (); |
7fd59977 |
90 | } |
91 | |
b8ddfc2f |
92 | Standard_Boolean V3d_CircularGrid::IsDisplayed () const |
93 | { |
94 | return myStructure->IsDisplayed (); |
7fd59977 |
95 | } |
96 | |
b8ddfc2f |
97 | void V3d_CircularGrid::UpdateDisplay () |
98 | { |
99 | gp_Ax3 ThePlane = myViewer->PrivilegedPlane(); |
100 | |
101 | Standard_Real xl, yl, zl; |
102 | Standard_Real xdx, xdy, xdz; |
103 | Standard_Real ydx, ydy, ydz; |
104 | Standard_Real dx, dy, dz; |
105 | ThePlane.Location ().Coord (xl, yl, zl); |
106 | ThePlane.XDirection ().Coord (xdx, xdy, xdz); |
107 | ThePlane.YDirection ().Coord (ydx, ydy, ydz); |
108 | ThePlane.Direction ().Coord (dx, dy, dz); |
109 | |
110 | Standard_Boolean MakeTransform = !myCurAreDefined; |
111 | if (!MakeTransform) |
112 | { |
113 | MakeTransform = (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo); |
114 | if (!MakeTransform) |
115 | { |
116 | Standard_Real curxl, curyl, curzl; |
117 | Standard_Real curxdx, curxdy, curxdz; |
118 | Standard_Real curydx, curydy, curydz; |
119 | Standard_Real curdx, curdy, curdz; |
120 | myCurViewPlane.Location ().Coord (curxl, curyl, curzl); |
121 | myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz); |
122 | myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz); |
123 | myCurViewPlane.Direction ().Coord (curdx, curdy, curdz); |
124 | if (xl != curxl || yl != curyl || zl != curzl || |
125 | xdx != curxdx || xdy != curxdy || xdz != curxdz || |
126 | ydx != curydx || ydy != curydy || ydz != curydz || |
127 | dx != curdx || dy != curdy || dz != curdz) |
128 | MakeTransform = Standard_True; |
129 | } |
130 | } |
131 | |
132 | if (MakeTransform) |
133 | { |
134 | const Standard_Real CosAlpha = Cos (RotationAngle ()); |
135 | const Standard_Real SinAlpha = Sin (RotationAngle ()); |
136 | TColStd_Array2OfReal Trsf (1, 4, 1, 4); |
137 | Trsf (4, 4) = 1.0; |
138 | Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0; |
139 | // Translation |
140 | Trsf (1, 4) = xl, |
141 | Trsf (2, 4) = yl, |
142 | Trsf (3, 4) = zl; |
143 | // Transformation change of marker |
144 | Trsf (1, 1) = xdx, |
145 | Trsf (2, 1) = xdy, |
146 | Trsf (3, 1) = xdz, |
147 | Trsf (1, 2) = ydx, |
148 | Trsf (2, 2) = ydy, |
149 | Trsf (3, 2) = ydz, |
150 | Trsf (1, 3) = dx, |
151 | Trsf (2, 3) = dy, |
152 | Trsf (3, 3) = dz; |
153 | myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE); |
154 | |
155 | // Translation of the origin |
156 | Trsf (1, 4) = -XOrigin (), |
157 | Trsf (2, 4) = -YOrigin (), |
158 | Trsf (3, 4) = 0.0; |
159 | // Rotation Alpha around axis -Z |
160 | Trsf (1, 1) = CosAlpha, |
161 | Trsf (2, 1) = -SinAlpha, |
162 | Trsf (3, 1) = 0.0, |
163 | Trsf (1, 2) = SinAlpha, |
164 | Trsf (2, 2) = CosAlpha, |
165 | Trsf (3, 2) = 0.0, |
166 | Trsf (1, 3) = 0.0, |
167 | Trsf (2, 3) = 0.0, |
168 | Trsf (3, 3) = 1.0; |
169 | myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE); |
170 | |
171 | myCurAngle = RotationAngle (); |
172 | myCurXo = XOrigin (), myCurYo = YOrigin (); |
173 | myCurViewPlane = ThePlane; |
174 | } |
175 | |
176 | switch (DrawMode()) |
177 | { |
178 | default: |
179 | //case Aspect_GDM_Points: |
180 | DefinePoints (); |
181 | myCurDrawMode = Aspect_GDM_Points; |
182 | break; |
183 | case Aspect_GDM_Lines: |
184 | DefineLines (); |
185 | myCurDrawMode = Aspect_GDM_Lines; |
186 | break; |
7fd59977 |
187 | #ifdef IMP210100 |
b8ddfc2f |
188 | case Aspect_GDM_None: |
189 | myCurDrawMode = Aspect_GDM_None; |
190 | break; |
7fd59977 |
191 | #endif |
b8ddfc2f |
192 | } |
193 | myCurAreDefined = Standard_True; |
7fd59977 |
194 | } |
195 | |
b8ddfc2f |
196 | void V3d_CircularGrid::DefineLines () |
197 | { |
198 | const Standard_Real aStep = RadiusStep (); |
199 | const Standard_Real aDivision = DivisionNumber (); |
200 | const Standard_Boolean toUpdate = !myCurAreDefined |
201 | || myCurDrawMode != Aspect_GDM_Lines |
202 | || aDivision != myCurDivi |
203 | || aStep != myCurStep; |
204 | if (!toUpdate) |
205 | { |
206 | return; |
207 | } |
208 | |
209 | myGroup->Clear (); |
210 | |
211 | Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d (); |
212 | LineAttrib->SetColor (myColor); |
213 | LineAttrib->SetType (Aspect_TOL_SOLID); |
214 | LineAttrib->SetWidth (1.0); |
215 | |
216 | const Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION)); |
217 | |
218 | Standard_Integer nbpnts = 2 * Division; |
219 | // diametres |
220 | Standard_Real alpha = M_PI / aDivision; |
221 | LineAttrib->SetColor (myTenthColor); |
222 | myGroup->SetGroupPrimitivesAspect (LineAttrib); |
223 | Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2*nbpnts); |
224 | const gp_Pnt p0(0., 0., -myOffSet); |
225 | for (Standard_Integer i=1; i<=nbpnts; i++) { |
226 | aPrims->AddVertex(p0); |
227 | aPrims->AddVertex(Cos(alpha*i)*myRadius, Sin(alpha*i)*myRadius, -myOffSet); |
228 | } |
229 | myGroup->AddPrimitiveArray(aPrims, Standard_False); |
230 | |
231 | // circles |
232 | nbpnts = 2 * Division + 1; |
233 | alpha = M_PI / Division; |
234 | Standard_Integer nblines = 0; |
235 | TColgp_SequenceOfPnt aSeqLines, aSeqTenth; |
236 | for (Standard_Real r=aStep; r<=myRadius; r+=aStep, nblines++) { |
237 | const Standard_Boolean isTenth = (Modulus(nblines, 10) == 0); |
238 | for (Standard_Integer i=0; i<nbpnts; i++) { |
239 | const gp_Pnt pt(Cos(alpha*i)*r,Sin(alpha*i)*r,-myOffSet); |
240 | (isTenth? aSeqTenth : aSeqLines).Append(pt); |
241 | } |
242 | } |
243 | if (aSeqTenth.Length()) |
244 | { |
245 | LineAttrib->SetColor (myTenthColor); |
246 | myGroup->SetGroupPrimitivesAspect (LineAttrib); |
247 | Standard_Integer n, np; |
248 | const Standard_Integer nbl = aSeqTenth.Length() / nbpnts; |
249 | Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqTenth.Length(),nbl); |
250 | for (np = 1, n=0; n<nbl; n++) { |
251 | aPrims->AddBound(nbpnts); |
252 | for (Standard_Integer i=0; i<nbpnts; i++, np++) |
253 | aPrims->AddVertex(aSeqTenth(np)); |
254 | } |
255 | myGroup->AddPrimitiveArray(aPrims, Standard_False); |
256 | } |
257 | if (aSeqLines.Length()) |
258 | { |
259 | LineAttrib->SetColor (myColor); |
260 | myGroup->SetPrimitivesAspect (LineAttrib); |
261 | Standard_Integer n, np; |
262 | const Standard_Integer nbl = aSeqLines.Length() / nbpnts; |
263 | Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),nbl); |
264 | for (np = 1, n=0; n<nbl; n++) { |
265 | aPrims->AddBound(nbpnts); |
266 | for (Standard_Integer i=0; i<nbpnts; i++, np++) |
267 | aPrims->AddVertex(aSeqLines(np)); |
268 | } |
269 | myGroup->AddPrimitiveArray(aPrims, Standard_False); |
270 | } |
271 | |
272 | myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0); |
273 | myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision; |
7fd59977 |
274 | } |
275 | |
b8ddfc2f |
276 | void V3d_CircularGrid::DefinePoints () |
277 | { |
278 | const Standard_Real aStep = RadiusStep(); |
279 | const Standard_Real aDivision = DivisionNumber(); |
280 | const Standard_Boolean toUpdate = !myCurAreDefined |
281 | || myCurDrawMode != Aspect_GDM_Points |
282 | || aDivision != myCurDivi |
283 | || aStep != myCurStep; |
284 | if (!toUpdate) |
285 | { |
286 | return; |
287 | } |
288 | |
289 | myGroup->Clear (); |
290 | |
291 | Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d (); |
292 | MarkerAttrib->SetColor (myColor); |
293 | MarkerAttrib->SetType (Aspect_TOM_POINT); |
294 | MarkerAttrib->SetScale (3.); |
295 | |
296 | const Standard_Integer nbpnts = Standard_Integer (2*aDivision); |
297 | Standard_Real r, alpha = M_PI / aDivision; |
298 | |
299 | // diameters |
300 | TColgp_SequenceOfPnt aSeqPnts; |
301 | aSeqPnts.Append(gp_Pnt(0.0, 0.0, -myOffSet)); |
302 | for (r=aStep; r<=myRadius; r+=aStep) { |
303 | for (Standard_Integer i=0; i<nbpnts; i++) |
304 | aSeqPnts.Append(gp_Pnt(Cos(alpha*i)*r, Sin(alpha*i)*r, -myOffSet)); |
305 | } |
306 | myGroup->SetGroupPrimitivesAspect (MarkerAttrib); |
307 | if (aSeqPnts.Length()) |
308 | { |
309 | Standard_Real X,Y,Z; |
310 | const Standard_Integer nbv = aSeqPnts.Length(); |
a577aaab |
311 | Handle(Graphic3d_ArrayOfPoints) Cercle = new Graphic3d_ArrayOfPoints (nbv); |
b8ddfc2f |
312 | for (Standard_Integer i=1; i<=nbv; i++) |
313 | { |
314 | aSeqPnts(i).Coord(X,Y,Z); |
a577aaab |
315 | Cercle->AddVertex (X,Y,Z); |
b8ddfc2f |
316 | } |
a577aaab |
317 | myGroup->AddPrimitiveArray (Cercle, Standard_False); |
b8ddfc2f |
318 | } |
319 | myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0); |
320 | |
321 | myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision; |
7fd59977 |
322 | } |
323 | |
b8ddfc2f |
324 | void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const |
325 | { |
326 | theRadius = myRadius; |
327 | theOffSet = myOffSet; |
7fd59977 |
328 | } |
329 | |
b8ddfc2f |
330 | void V3d_CircularGrid::SetGraphicValues (const Standard_Real theRadius, const Standard_Real theOffSet) |
331 | { |
332 | if (! myCurAreDefined) { |
333 | myRadius = theRadius; |
334 | myOffSet = theOffSet; |
335 | } |
336 | if (myRadius != theRadius) { |
337 | myRadius = theRadius; |
338 | myCurAreDefined = Standard_False; |
339 | } |
340 | if (myOffSet != theOffSet) { |
341 | myOffSet = theOffSet; |
342 | myCurAreDefined = Standard_False; |
343 | } |
344 | if( !myCurAreDefined ) UpdateDisplay(); |
7fd59977 |
345 | } |