1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 /***********************************************************************
22 Classe V3d_CircularGrid :
25 --------------------------------
26 IMP230300: GG The color fields and methods have moved in Aspect_Grid
29 ************************************************************************/
31 #define IMP200100 //GG
32 // -> Compute the case Aspect_GDM_None
33 // -> Initialize the grid size according to the
34 // viewer default size.
36 #define IMP200300 //GG
37 // -> Recompute the grid when any graphic parameter is
40 #define IMP300300 //GG
41 // -> Draw circles with 2 colors (tenth and normal colors)
43 /*----------------------------------------------------------------------*/
48 #include <V3d_CircularGrid.ixx>
50 #include <TColStd_Array2OfReal.hxx>
51 #include <Graphic3d_AspectLine3d.hxx>
52 #include <Graphic3d_AspectMarker3d.hxx>
53 #include <Graphic3d_Vertex.hxx>
54 #include <Graphic3d_Array1OfVertex.hxx>
55 #include <Graphic3d_ArrayOfSegments.hxx>
56 #include <Graphic3d_ArrayOfPolylines.hxx>
57 #include <Visual3d_ViewManager.hxx>
58 #include <V3d_Viewer.hxx>
59 #include <TColgp_SequenceOfPnt.hxx>
61 /*----------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------*/
72 V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
73 : Aspect_CircularGrid (1.,8),
74 myStructure (new Graphic3d_Structure (aViewer->Viewer ())),
75 myGroup (new Graphic3d_Group (myStructure)),
77 myCurAreDefined (Standard_False)
80 myTenthColor = aTenthColor;
82 myStructure->SetInfiniteState (Standard_True);
84 const Standard_Real step = 10.;
85 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
86 SetGraphicValues (size, step/MYFACTOR);
90 void V3d_CircularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
92 if( myColor != aColor || myTenthColor != aTenthColor ) {
94 myTenthColor = aTenthColor;
95 myCurAreDefined = Standard_False;
100 void V3d_CircularGrid::Display ()
102 myStructure->Display (1);
105 void V3d_CircularGrid::Erase () const
107 myStructure->Erase ();
110 Standard_Boolean V3d_CircularGrid::IsDisplayed () const
112 return myStructure->IsDisplayed ();
115 void V3d_CircularGrid::UpdateDisplay ()
117 gp_Ax3 ThePlane = myViewer->PrivilegedPlane();
119 Standard_Real xl, yl, zl;
120 Standard_Real xdx, xdy, xdz;
121 Standard_Real ydx, ydy, ydz;
122 Standard_Real dx, dy, dz;
123 ThePlane.Location ().Coord (xl, yl, zl);
124 ThePlane.XDirection ().Coord (xdx, xdy, xdz);
125 ThePlane.YDirection ().Coord (ydx, ydy, ydz);
126 ThePlane.Direction ().Coord (dx, dy, dz);
128 Standard_Boolean MakeTransform = !myCurAreDefined;
131 MakeTransform = (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo);
134 Standard_Real curxl, curyl, curzl;
135 Standard_Real curxdx, curxdy, curxdz;
136 Standard_Real curydx, curydy, curydz;
137 Standard_Real curdx, curdy, curdz;
138 myCurViewPlane.Location ().Coord (curxl, curyl, curzl);
139 myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz);
140 myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz);
141 myCurViewPlane.Direction ().Coord (curdx, curdy, curdz);
142 if (xl != curxl || yl != curyl || zl != curzl ||
143 xdx != curxdx || xdy != curxdy || xdz != curxdz ||
144 ydx != curydx || ydy != curydy || ydz != curydz ||
145 dx != curdx || dy != curdy || dz != curdz)
146 MakeTransform = Standard_True;
152 const Standard_Real CosAlpha = Cos (RotationAngle ());
153 const Standard_Real SinAlpha = Sin (RotationAngle ());
154 TColStd_Array2OfReal Trsf (1, 4, 1, 4);
156 Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0;
161 // Transformation change of marker
171 myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE);
173 // Translation of the origin
174 Trsf (1, 4) = -XOrigin (),
175 Trsf (2, 4) = -YOrigin (),
177 // Rotation Alpha around axis -Z
178 Trsf (1, 1) = CosAlpha,
179 Trsf (2, 1) = -SinAlpha,
181 Trsf (1, 2) = SinAlpha,
182 Trsf (2, 2) = CosAlpha,
187 myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE);
189 myCurAngle = RotationAngle ();
190 myCurXo = XOrigin (), myCurYo = YOrigin ();
191 myCurViewPlane = ThePlane;
197 //case Aspect_GDM_Points:
199 myCurDrawMode = Aspect_GDM_Points;
201 case Aspect_GDM_Lines:
203 myCurDrawMode = Aspect_GDM_Lines;
206 case Aspect_GDM_None:
207 myCurDrawMode = Aspect_GDM_None;
211 myCurAreDefined = Standard_True;
214 void V3d_CircularGrid::DefineLines ()
216 const Standard_Real aStep = RadiusStep ();
217 const Standard_Real aDivision = DivisionNumber ();
218 const Standard_Boolean toUpdate = !myCurAreDefined
219 || myCurDrawMode != Aspect_GDM_Lines
220 || aDivision != myCurDivi
221 || aStep != myCurStep;
229 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
230 LineAttrib->SetColor (myColor);
231 LineAttrib->SetType (Aspect_TOL_SOLID);
232 LineAttrib->SetWidth (1.0);
234 const Standard_Integer Division = (Standard_Integer )( (aDivision >= DIVISION ? aDivision : DIVISION));
236 Standard_Integer nbpnts = 2 * Division;
238 Standard_Real alpha = M_PI / aDivision;
239 LineAttrib->SetColor (myTenthColor);
240 myGroup->SetGroupPrimitivesAspect (LineAttrib);
241 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2*nbpnts);
242 const gp_Pnt p0(0., 0., -myOffSet);
243 for (Standard_Integer i=1; i<=nbpnts; i++) {
244 aPrims->AddVertex(p0);
245 aPrims->AddVertex(Cos(alpha*i)*myRadius, Sin(alpha*i)*myRadius, -myOffSet);
247 myGroup->AddPrimitiveArray(aPrims, Standard_False);
250 nbpnts = 2 * Division + 1;
251 alpha = M_PI / Division;
252 Standard_Integer nblines = 0;
253 TColgp_SequenceOfPnt aSeqLines, aSeqTenth;
254 for (Standard_Real r=aStep; r<=myRadius; r+=aStep, nblines++) {
255 const Standard_Boolean isTenth = (Modulus(nblines, 10) == 0);
256 for (Standard_Integer i=0; i<nbpnts; i++) {
257 const gp_Pnt pt(Cos(alpha*i)*r,Sin(alpha*i)*r,-myOffSet);
258 (isTenth? aSeqTenth : aSeqLines).Append(pt);
261 if (aSeqTenth.Length())
263 LineAttrib->SetColor (myTenthColor);
264 myGroup->SetGroupPrimitivesAspect (LineAttrib);
265 Standard_Integer n, np;
266 const Standard_Integer nbl = aSeqTenth.Length() / nbpnts;
267 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqTenth.Length(),nbl);
268 for (np = 1, n=0; n<nbl; n++) {
269 aPrims->AddBound(nbpnts);
270 for (Standard_Integer i=0; i<nbpnts; i++, np++)
271 aPrims->AddVertex(aSeqTenth(np));
273 myGroup->AddPrimitiveArray(aPrims, Standard_False);
275 if (aSeqLines.Length())
277 LineAttrib->SetColor (myColor);
278 myGroup->SetPrimitivesAspect (LineAttrib);
279 Standard_Integer n, np;
280 const Standard_Integer nbl = aSeqLines.Length() / nbpnts;
281 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(aSeqLines.Length(),nbl);
282 for (np = 1, n=0; n<nbl; n++) {
283 aPrims->AddBound(nbpnts);
284 for (Standard_Integer i=0; i<nbpnts; i++, np++)
285 aPrims->AddVertex(aSeqLines(np));
287 myGroup->AddPrimitiveArray(aPrims, Standard_False);
290 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
291 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
294 void V3d_CircularGrid::DefinePoints ()
296 const Standard_Real aStep = RadiusStep();
297 const Standard_Real aDivision = DivisionNumber();
298 const Standard_Boolean toUpdate = !myCurAreDefined
299 || myCurDrawMode != Aspect_GDM_Points
300 || aDivision != myCurDivi
301 || aStep != myCurStep;
309 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
310 MarkerAttrib->SetColor (myColor);
311 MarkerAttrib->SetType (Aspect_TOM_POINT);
312 MarkerAttrib->SetScale (3.);
314 const Standard_Integer nbpnts = Standard_Integer (2*aDivision);
315 Standard_Real r, alpha = M_PI / aDivision;
318 TColgp_SequenceOfPnt aSeqPnts;
319 aSeqPnts.Append(gp_Pnt(0.0, 0.0, -myOffSet));
320 for (r=aStep; r<=myRadius; r+=aStep) {
321 for (Standard_Integer i=0; i<nbpnts; i++)
322 aSeqPnts.Append(gp_Pnt(Cos(alpha*i)*r, Sin(alpha*i)*r, -myOffSet));
324 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
325 if (aSeqPnts.Length())
328 const Standard_Integer nbv = aSeqPnts.Length();
329 Graphic3d_Array1OfVertex Cercle (1,nbv);
330 for (Standard_Integer i=1; i<=nbv; i++)
332 aSeqPnts(i).Coord(X,Y,Z);
333 Cercle(i).SetCoord(X,Y,Z);
335 myGroup->MarkerSet (Cercle, Standard_False);
337 myGroup->SetMinMaxValues(-myRadius, -myRadius, 0.0, myRadius, myRadius, 0.0);
339 myCurStep = aStep, myCurDivi = (Standard_Integer ) aDivision;
342 void V3d_CircularGrid::GraphicValues (Standard_Real& theRadius, Standard_Real& theOffSet) const
344 theRadius = myRadius;
345 theOffSet = myOffSet;
348 void V3d_CircularGrid::SetGraphicValues (const Standard_Real theRadius, const Standard_Real theOffSet)
350 if (! myCurAreDefined) {
351 myRadius = theRadius;
352 myOffSet = theOffSet;
354 if (myRadius != theRadius) {
355 myRadius = theRadius;
356 myCurAreDefined = Standard_False;
358 if (myOffSet != theOffSet) {
359 myOffSet = theOffSet;
360 myCurAreDefined = Standard_False;
362 if( !myCurAreDefined ) UpdateDisplay();