1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 /***********************************************************************
17 Classe V3d_CircularGrid :
19 --------------------------------
20 ************************************************************************/
21 /*----------------------------------------------------------------------*/
26 #include <Graphic3d_Array1OfVertex.hxx>
27 #include <Graphic3d_ArrayOfPoints.hxx>
28 #include <Graphic3d_ArrayOfPolylines.hxx>
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>
37 #include <TColgp_SequenceOfPnt.hxx>
38 #include <TColStd_Array2OfReal.hxx>
39 #include <V3d_CircularGrid.hxx>
40 #include <V3d_Viewer.hxx>
41 #include <Visual3d_ViewManager.hxx>
43 /*----------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------*/
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 ())),
56 myGroup (myStructure->NewGroup()),
58 myCurAreDefined (Standard_False)
61 myTenthColor = aTenthColor;
63 myStructure->SetInfiniteState (Standard_True);
65 const Standard_Real step = 10.;
66 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
67 SetGraphicValues (size, step/MYFACTOR);
71 void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
73 if( myColor != aColor || myTenthColor != aTenthColor ) {
75 myTenthColor = aTenthColor;
76 myCurAreDefined = Standard_False;
81 void V3d_CircularGrid::Display ()
83 myStructure->SetDisplayPriority (1);
84 myStructure->Display();
87 void V3d_CircularGrid::Erase () const
89 myStructure->Erase ();
92 Standard_Boolean V3d_CircularGrid::IsDisplayed () const
94 return myStructure->IsDisplayed ();
97 void V3d_CircularGrid::UpdateDisplay ()
99 gp_Ax3 ThePlane = myViewer->PrivilegedPlane();
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);
110 Standard_Boolean MakeTransform = !myCurAreDefined;
113 MakeTransform = (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo);
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;
134 const Standard_Real CosAlpha = Cos (RotationAngle ());
135 const Standard_Real SinAlpha = Sin (RotationAngle ());
136 TColStd_Array2OfReal Trsf (1, 4, 1, 4);
138 Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0;
143 // Transformation change of marker
153 myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE);
155 // Translation of the origin
156 Trsf (1, 4) = -XOrigin (),
157 Trsf (2, 4) = -YOrigin (),
159 // Rotation Alpha around axis -Z
160 Trsf (1, 1) = CosAlpha,
161 Trsf (2, 1) = -SinAlpha,
163 Trsf (1, 2) = SinAlpha,
164 Trsf (2, 2) = CosAlpha,
169 myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE);
171 myCurAngle = RotationAngle ();
172 myCurXo = XOrigin (), myCurYo = YOrigin ();
173 myCurViewPlane = ThePlane;
179 //case Aspect_GDM_Points:
181 myCurDrawMode = Aspect_GDM_Points;
183 case Aspect_GDM_Lines:
185 myCurDrawMode = Aspect_GDM_Lines;
188 case Aspect_GDM_None:
189 myCurDrawMode = Aspect_GDM_None;
193 myCurAreDefined = Standard_True;
196 void V3d_CircularGrid::DefineLines ()
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;
211 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
212 LineAttrib->SetColor (myColor);
213 LineAttrib->SetType (Aspect_TOL_SOLID);
214 LineAttrib->SetWidth (1.0);
216 const Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION));
218 Standard_Integer nbpnts = 2 * Division;
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);
229 myGroup->AddPrimitiveArray(aPrims, Standard_False);
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);
243 if (aSeqTenth.Length())
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));
255 myGroup->AddPrimitiveArray(aPrims, Standard_False);
257 if (aSeqLines.Length())
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));
269 myGroup->AddPrimitiveArray(aPrims, Standard_False);
272 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
273 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
276 void V3d_CircularGrid::DefinePoints ()
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;
291 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
292 MarkerAttrib->SetColor (myColor);
293 MarkerAttrib->SetType (Aspect_TOM_POINT);
294 MarkerAttrib->SetScale (3.);
296 const Standard_Integer nbpnts = Standard_Integer (2*aDivision);
297 Standard_Real r, alpha = M_PI / aDivision;
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));
306 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
307 if (aSeqPnts.Length())
310 const Standard_Integer nbv = aSeqPnts.Length();
311 Handle(Graphic3d_ArrayOfPoints) Cercle = new Graphic3d_ArrayOfPoints (nbv);
312 for (Standard_Integer i=1; i<=nbv; i++)
314 aSeqPnts(i).Coord(X,Y,Z);
315 Cercle->AddVertex (X,Y,Z);
317 myGroup->AddPrimitiveArray (Cercle, Standard_False);
319 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
321 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
324 void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const
326 theRadius = myRadius;
327 theOffSet = myOffSet;
330 void V3d_CircularGrid::SetGraphicValues (const Standard_Real theRadius, const Standard_Real theOffSet)
332 if (! myCurAreDefined) {
333 myRadius = theRadius;
334 myOffSet = theOffSet;
336 if (myRadius != theRadius) {
337 myRadius = theRadius;
338 myCurAreDefined = Standard_False;
340 if (myOffSet != theOffSet) {
341 myOffSet = theOffSet;
342 myCurAreDefined = Standard_False;
344 if( !myCurAreDefined ) UpdateDisplay();