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 /***********************************************************************
18 Classe V3d_CircularGrid :
20 HISTORIQUE DES MODIFICATIONS :
21 --------------------------------
22 16-08-98 : CAL ; S3892. Ajout grilles 3d.
23 13-10-98 : CAL ; S3892. Ajout de la gestion de la taille des grilles 3d.
24 23-10-98 : CAL ; PRO 15885. Patch K4403 et K4404
25 03-11-98 : CAL ; PRO 16161. Patch K4418 et K4419
27 ************************************************************************/
29 /*----------------------------------------------------------------------*/
34 #include <V3d_RectangularGrid.ixx>
36 #include <TColStd_Array2OfReal.hxx>
37 #include <Graphic3d_AspectLine3d.hxx>
38 #include <Graphic3d_AspectMarker3d.hxx>
39 #include <Graphic3d_AspectText3d.hxx>
40 #include <Graphic3d_ArrayOfPoints.hxx>
41 #include <Visual3d_ViewManager.hxx>
42 #include <V3d_Viewer.hxx>
43 #include <TColgp_SequenceOfPnt.hxx>
44 #include <Graphic3d_ArrayOfSegments.hxx>
46 /*----------------------------------------------------------------------*/
54 /*----------------------------------------------------------------------*/
56 V3d_RectangularGrid::V3d_RectangularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
57 : Aspect_RectangularGrid (1.,1.),
58 myStructure (new Graphic3d_Structure (aViewer->Viewer ())),
59 myGroup (myStructure->NewGroup()),
61 myCurAreDefined (Standard_False)
64 myTenthColor = aTenthColor;
66 myStructure->SetInfiniteState (Standard_True);
68 const Standard_Real step = 10.;
69 const Standard_Real gstep = step/MYFACTOR;
70 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
71 SetGraphicValues (size, size, gstep);
76 void V3d_RectangularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
78 if( myColor != aColor || myTenthColor != aTenthColor ) {
80 myTenthColor = aTenthColor;
81 myCurAreDefined = Standard_False;
86 void V3d_RectangularGrid::Display ()
88 myStructure->SetDisplayPriority (1);
89 myStructure->Display();
92 void V3d_RectangularGrid::Erase () const
94 myStructure->Erase ();
97 Standard_Boolean V3d_RectangularGrid::IsDisplayed () const
99 return myStructure->IsDisplayed ();
102 void V3d_RectangularGrid::UpdateDisplay ()
104 gp_Ax3 ThePlane = myViewer->PrivilegedPlane ();
106 Standard_Boolean MakeTransform = Standard_False;
107 Standard_Real xl, yl, zl;
108 Standard_Real xdx, xdy, xdz;
109 Standard_Real ydx, ydy, ydz;
110 Standard_Real dx, dy, dz;
111 ThePlane.Location ().Coord (xl, yl, zl);
112 ThePlane.XDirection ().Coord (xdx, xdy, xdz);
113 ThePlane.YDirection ().Coord (ydx, ydy, ydz);
114 ThePlane.Direction ().Coord (dx, dy, dz);
115 if (! myCurAreDefined)
116 MakeTransform = Standard_True;
118 if (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo)
119 MakeTransform = Standard_True;
120 if (! MakeTransform) {
121 Standard_Real curxl, curyl, curzl;
122 Standard_Real curxdx, curxdy, curxdz;
123 Standard_Real curydx, curydy, curydz;
124 Standard_Real curdx, curdy, curdz;
125 myCurViewPlane.Location ().Coord (curxl, curyl, curzl);
126 myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz);
127 myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz);
128 myCurViewPlane.Direction ().Coord (curdx, curdy, curdz);
129 if (xl != curxl || yl != curyl || zl != curzl ||
130 xdx != curxdx || xdy != curxdy || xdz != curxdz ||
131 ydx != curydx || ydy != curydy || ydz != curydz ||
132 dx != curdx || dy != curdy || dz != curdz)
133 MakeTransform = Standard_True;
138 const Standard_Real CosAlpha = Cos (RotationAngle ());
139 const Standard_Real SinAlpha = Sin (RotationAngle ());
140 TColStd_Array2OfReal Trsf (1, 4, 1, 4);
142 Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0;
147 // Transformation of change of marker
157 myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE);
159 // Translation of the origin
160 Trsf (1, 4) = -XOrigin (),
161 Trsf (2, 4) = -YOrigin (),
163 // Rotation Alpha around axis -Z
164 Trsf (1, 1) = CosAlpha,
165 Trsf (2, 1) = -SinAlpha,
167 Trsf (1, 2) = SinAlpha,
168 Trsf (2, 2) = CosAlpha,
173 myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE);
175 myCurAngle = RotationAngle ();
176 myCurXo = XOrigin (), myCurYo = YOrigin ();
177 myCurViewPlane = ThePlane;
183 //case Aspect_GDM_Points:
185 myCurDrawMode = Aspect_GDM_Points;
187 case Aspect_GDM_Lines:
189 myCurDrawMode = Aspect_GDM_Lines;
192 case Aspect_GDM_None:
193 myCurDrawMode = Aspect_GDM_None;
197 myCurAreDefined = Standard_True;
200 void V3d_RectangularGrid::DefineLines ()
202 const Standard_Real aXStep = XStep();
203 const Standard_Real aYStep = YStep();
204 const Standard_Boolean toUpdate = !myCurAreDefined
205 || myCurDrawMode != Aspect_GDM_Lines
206 || aXStep != myCurXStep
207 || aYStep != myCurYStep;
215 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
216 LineAttrib->SetColor (myColor);
217 LineAttrib->SetType (Aspect_TOL_SOLID);
218 LineAttrib->SetWidth (1.0);
220 Standard_Integer nblines;
221 Standard_Real xl, yl, zl = myOffSet;
223 TColgp_SequenceOfPnt aSeqLines, aSeqTenth;
226 aSeqTenth.Append(gp_Pnt(0., -myYSize, -zl));
227 aSeqTenth.Append(gp_Pnt(0., myYSize, -zl));
228 for (nblines = 1, xl = aXStep; xl < myXSize; xl += aXStep, nblines++)
230 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
231 aSeq.Append(gp_Pnt( xl, -myYSize, -zl));
232 aSeq.Append(gp_Pnt( xl, myYSize, -zl));
233 aSeq.Append(gp_Pnt(-xl, -myYSize, -zl));
234 aSeq.Append(gp_Pnt(-xl, myYSize, -zl));
238 aSeqTenth.Append(gp_Pnt(-myXSize, 0., -zl));
239 aSeqTenth.Append(gp_Pnt( myXSize, 0., -zl));
240 for (nblines = 1, yl = aYStep; yl < myYSize; yl += aYStep, nblines++)
242 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
243 aSeq.Append(gp_Pnt(-myXSize, yl, -zl));
244 aSeq.Append(gp_Pnt( myXSize, yl, -zl));
245 aSeq.Append(gp_Pnt(-myXSize, -yl, -zl));
246 aSeq.Append(gp_Pnt( myXSize, -yl, -zl));
249 if (aSeqLines.Length())
251 LineAttrib->SetColor (myColor);
252 myGroup->SetPrimitivesAspect (LineAttrib);
253 const Standard_Integer nbv = aSeqLines.Length();
254 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
255 Standard_Integer n = 1;
257 aPrims->AddVertex(aSeqLines(n++));
258 myGroup->AddPrimitiveArray(aPrims, Standard_False);
260 if (aSeqTenth.Length())
262 LineAttrib->SetColor (myTenthColor);
263 myGroup->SetPrimitivesAspect (LineAttrib);
264 const Standard_Integer nbv = aSeqTenth.Length();
265 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
266 Standard_Integer n = 1;
268 aPrims->AddVertex(aSeqTenth(n++));
269 myGroup->AddPrimitiveArray(aPrims, Standard_False);
272 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
273 myCurXStep = aXStep, myCurYStep = aYStep;
276 void V3d_RectangularGrid::DefinePoints ()
278 const Standard_Real aXStep = XStep();
279 const Standard_Real aYStep = YStep();
280 const Standard_Boolean toUpdate = !myCurAreDefined
281 || myCurDrawMode != Aspect_GDM_Points
282 || aXStep != myCurXStep
283 || aYStep != myCurYStep;
291 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
292 MarkerAttrib->SetColor (myColor);
293 MarkerAttrib->SetType (Aspect_TOM_POINT);
294 MarkerAttrib->SetScale (3.);
297 Standard_Real xl, yl;
298 TColgp_SequenceOfPnt aSeqPnts;
299 for (xl = 0.0; xl <= myXSize; xl += aXStep) {
300 aSeqPnts.Append(gp_Pnt( xl, 0.0, -myOffSet));
301 aSeqPnts.Append(gp_Pnt(-xl, 0.0, -myOffSet));
302 for (yl = aYStep; yl <= myYSize; yl += aYStep) {
303 aSeqPnts.Append(gp_Pnt( xl, yl, -myOffSet));
304 aSeqPnts.Append(gp_Pnt( xl, -yl, -myOffSet));
305 aSeqPnts.Append(gp_Pnt(-xl, yl, -myOffSet));
306 aSeqPnts.Append(gp_Pnt(-xl, -yl, -myOffSet));
309 if (aSeqPnts.Length())
313 const Standard_Integer nbv = aSeqPnts.Length();
314 Handle(Graphic3d_ArrayOfPoints) Vertical = new Graphic3d_ArrayOfPoints (nbv);
315 for (i=1; i<=nbv; i++)
317 aSeqPnts(i).Coord(X,Y,Z);
318 Vertical->AddVertex (X,Y,Z);
320 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
321 myGroup->AddPrimitiveArray (Vertical, Standard_False);
324 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
325 myCurXStep = aXStep, myCurYStep = aYStep;
328 void V3d_RectangularGrid::GraphicValues (Standard_Real& theXSize, Standard_Real& theYSize, Standard_Real& theOffSet) const
332 theOffSet = myOffSet;
335 void V3d_RectangularGrid::SetGraphicValues (const Standard_Real theXSize, const Standard_Real theYSize, const Standard_Real theOffSet)
337 if (! myCurAreDefined) {
340 myOffSet = theOffSet;
342 if (myXSize != theXSize) {
344 myCurAreDefined = Standard_False;
346 if (myYSize != theYSize) {
348 myCurAreDefined = Standard_False;
350 if (myOffSet != theOffSet) {
351 myOffSet = theOffSet;
352 myCurAreDefined = Standard_False;
354 if( !myCurAreDefined ) UpdateDisplay();