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>
42 /*----------------------------------------------------------------------*/
50 /*----------------------------------------------------------------------*/
52 V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
53 : Aspect_CircularGrid (1.,8),
54 myStructure (new Graphic3d_Structure (aViewer->StructureManager())),
55 myGroup (myStructure->NewGroup()),
57 myCurAreDefined (Standard_False)
60 myTenthColor = aTenthColor;
62 myStructure->SetInfiniteState (Standard_True);
64 const Standard_Real step = 10.;
65 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
66 SetGraphicValues (size, step/MYFACTOR);
70 void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
72 if( myColor != aColor || myTenthColor != aTenthColor ) {
74 myTenthColor = aTenthColor;
75 myCurAreDefined = Standard_False;
80 void V3d_CircularGrid::Display ()
82 myStructure->SetDisplayPriority (1);
83 myStructure->Display();
86 void V3d_CircularGrid::Erase () const
88 myStructure->Erase ();
91 Standard_Boolean V3d_CircularGrid::IsDisplayed () const
93 return myStructure->IsDisplayed ();
96 void V3d_CircularGrid::UpdateDisplay ()
98 gp_Ax3 ThePlane = myViewer->PrivilegedPlane();
100 Standard_Real xl, yl, zl;
101 Standard_Real xdx, xdy, xdz;
102 Standard_Real ydx, ydy, ydz;
103 Standard_Real dx, dy, dz;
104 ThePlane.Location ().Coord (xl, yl, zl);
105 ThePlane.XDirection ().Coord (xdx, xdy, xdz);
106 ThePlane.YDirection ().Coord (ydx, ydy, ydz);
107 ThePlane.Direction ().Coord (dx, dy, dz);
109 Standard_Boolean MakeTransform = !myCurAreDefined;
112 MakeTransform = (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo);
115 Standard_Real curxl, curyl, curzl;
116 Standard_Real curxdx, curxdy, curxdz;
117 Standard_Real curydx, curydy, curydz;
118 Standard_Real curdx, curdy, curdz;
119 myCurViewPlane.Location ().Coord (curxl, curyl, curzl);
120 myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz);
121 myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz);
122 myCurViewPlane.Direction ().Coord (curdx, curdy, curdz);
123 if (xl != curxl || yl != curyl || zl != curzl ||
124 xdx != curxdx || xdy != curxdy || xdz != curxdz ||
125 ydx != curydx || ydy != curydy || ydz != curydz ||
126 dx != curdx || dy != curdy || dz != curdz)
127 MakeTransform = Standard_True;
133 const Standard_Real CosAlpha = Cos (RotationAngle ());
134 const Standard_Real SinAlpha = Sin (RotationAngle ());
135 TColStd_Array2OfReal Trsf (1, 4, 1, 4);
137 Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0;
142 // Transformation change of marker
152 myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE);
154 // Translation of the origin
155 Trsf (1, 4) = -XOrigin (),
156 Trsf (2, 4) = -YOrigin (),
158 // Rotation Alpha around axis -Z
159 Trsf (1, 1) = CosAlpha,
160 Trsf (2, 1) = -SinAlpha,
162 Trsf (1, 2) = SinAlpha,
163 Trsf (2, 2) = CosAlpha,
168 myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE);
170 myCurAngle = RotationAngle ();
171 myCurXo = XOrigin (), myCurYo = YOrigin ();
172 myCurViewPlane = ThePlane;
178 //case Aspect_GDM_Points:
180 myCurDrawMode = Aspect_GDM_Points;
182 case Aspect_GDM_Lines:
184 myCurDrawMode = Aspect_GDM_Lines;
187 case Aspect_GDM_None:
188 myCurDrawMode = Aspect_GDM_None;
192 myCurAreDefined = Standard_True;
195 void V3d_CircularGrid::DefineLines ()
197 const Standard_Real aStep = RadiusStep ();
198 const Standard_Real aDivision = DivisionNumber ();
199 const Standard_Boolean toUpdate = !myCurAreDefined
200 || myCurDrawMode != Aspect_GDM_Lines
201 || aDivision != myCurDivi
202 || aStep != myCurStep;
210 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
211 LineAttrib->SetColor (myColor);
212 LineAttrib->SetType (Aspect_TOL_SOLID);
213 LineAttrib->SetWidth (1.0);
215 const Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION));
217 Standard_Integer nbpnts = 2 * Division;
219 Standard_Real alpha = M_PI / aDivision;
220 LineAttrib->SetColor (myTenthColor);
221 myGroup->SetGroupPrimitivesAspect (LineAttrib);
222 Handle(Graphic3d_ArrayOfSegments) aPrims1 = new Graphic3d_ArrayOfSegments(2*nbpnts);
223 const gp_Pnt p0(0., 0., -myOffSet);
224 for (Standard_Integer i=1; i<=nbpnts; i++) {
225 aPrims1->AddVertex(p0);
226 aPrims1->AddVertex(Cos(alpha*i)*myRadius, Sin(alpha*i)*myRadius, -myOffSet);
228 myGroup->AddPrimitiveArray(aPrims1, Standard_False);
231 nbpnts = 2 * Division + 1;
232 alpha = M_PI / Division;
233 Standard_Integer nblines = 0;
234 TColgp_SequenceOfPnt aSeqLines, aSeqTenth;
235 for (Standard_Real r=aStep; r<=myRadius; r+=aStep, nblines++) {
236 const Standard_Boolean isTenth = (Modulus(nblines, 10) == 0);
237 for (Standard_Integer i=0; i<nbpnts; i++) {
238 const gp_Pnt pt(Cos(alpha*i)*r,Sin(alpha*i)*r,-myOffSet);
239 (isTenth? aSeqTenth : aSeqLines).Append(pt);
242 if (aSeqTenth.Length())
244 LineAttrib->SetColor (myTenthColor);
245 myGroup->SetGroupPrimitivesAspect (LineAttrib);
246 Standard_Integer n, np;
247 const Standard_Integer nbl = aSeqTenth.Length() / nbpnts;
248 Handle(Graphic3d_ArrayOfPolylines) aPrims2 = new Graphic3d_ArrayOfPolylines(aSeqTenth.Length(),nbl);
249 for (np = 1, n=0; n<nbl; n++) {
250 aPrims2->AddBound(nbpnts);
251 for (Standard_Integer i=0; i<nbpnts; i++, np++)
252 aPrims2->AddVertex(aSeqTenth(np));
254 myGroup->AddPrimitiveArray(aPrims2, Standard_False);
256 if (aSeqLines.Length())
258 LineAttrib->SetColor (myColor);
259 myGroup->SetPrimitivesAspect (LineAttrib);
260 Standard_Integer n, np;
261 const Standard_Integer nbl = aSeqLines.Length() / nbpnts;
262 Handle(Graphic3d_ArrayOfPolylines) aPrims3 = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),nbl);
263 for (np = 1, n=0; n<nbl; n++) {
264 aPrims3->AddBound(nbpnts);
265 for (Standard_Integer i=0; i<nbpnts; i++, np++)
266 aPrims3->AddVertex(aSeqLines(np));
268 myGroup->AddPrimitiveArray(aPrims3, Standard_False);
271 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
272 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
275 void V3d_CircularGrid::DefinePoints ()
277 const Standard_Real aStep = RadiusStep();
278 const Standard_Real aDivision = DivisionNumber();
279 const Standard_Boolean toUpdate = !myCurAreDefined
280 || myCurDrawMode != Aspect_GDM_Points
281 || aDivision != myCurDivi
282 || aStep != myCurStep;
290 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
291 MarkerAttrib->SetColor (myColor);
292 MarkerAttrib->SetType (Aspect_TOM_POINT);
293 MarkerAttrib->SetScale (3.);
295 const Standard_Integer nbpnts = Standard_Integer (2*aDivision);
296 Standard_Real r, alpha = M_PI / aDivision;
299 TColgp_SequenceOfPnt aSeqPnts;
300 aSeqPnts.Append(gp_Pnt(0.0, 0.0, -myOffSet));
301 for (r=aStep; r<=myRadius; r+=aStep) {
302 for (Standard_Integer i=0; i<nbpnts; i++)
303 aSeqPnts.Append(gp_Pnt(Cos(alpha*i)*r, Sin(alpha*i)*r, -myOffSet));
305 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
306 if (aSeqPnts.Length())
309 const Standard_Integer nbv = aSeqPnts.Length();
310 Handle(Graphic3d_ArrayOfPoints) Cercle = new Graphic3d_ArrayOfPoints (nbv);
311 for (Standard_Integer i=1; i<=nbv; i++)
313 aSeqPnts(i).Coord(X,Y,Z);
314 Cercle->AddVertex (X,Y,Z);
316 myGroup->AddPrimitiveArray (Cercle, Standard_False);
318 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
320 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
323 void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const
325 theRadius = myRadius;
326 theOffSet = myOffSet;
329 void V3d_CircularGrid::SetGraphicValues (const Standard_Real theRadius, const Standard_Real theOffSet)
331 if (! myCurAreDefined) {
332 myRadius = theRadius;
333 myOffSet = theOffSet;
335 if (myRadius != theRadius) {
336 myRadius = theRadius;
337 myCurAreDefined = Standard_False;
339 if (myOffSet != theOffSet) {
340 myOffSet = theOffSet;
341 myCurAreDefined = Standard_False;
343 if( !myCurAreDefined ) UpdateDisplay();