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 :
24 HISTORIQUE DES MODIFICATIONS :
25 --------------------------------
26 16-08-98 : CAL ; S3892. Ajout grilles 3d.
27 13-10-98 : CAL ; S3892. Ajout de la gestion de la taille des grilles 3d.
28 23-10-98 : CAL ; PRO 15885. Patch K4403 et K4404
29 03-11-98 : CAL ; PRO 16161. Patch K4418 et K4419
30 IMP230300: GG The color fields and methods have moved in Aspect_Grid
33 ************************************************************************/
35 #define IMP200100 //GG
36 // -> Compute the case Aspect_GDM_None
37 // -> Initialize the grid size according to the
38 // viewer default size.
40 #define IMP200300 //GG
41 // -> Recompute the grid when any graphic parameter is
44 /*----------------------------------------------------------------------*/
49 #include <V3d_RectangularGrid.ixx>
51 #include <TColStd_Array2OfReal.hxx>
52 #include <Graphic3d_AspectLine3d.hxx>
53 #include <Graphic3d_AspectMarker3d.hxx>
54 #include <Graphic3d_AspectText3d.hxx>
55 #include <Graphic3d_Vertex.hxx>
56 #include <Graphic3d_Array1OfVertex.hxx>
57 #include <Visual3d_ViewManager.hxx>
58 #include <V3d_Viewer.hxx>
59 #include <TColgp_SequenceOfPnt.hxx>
60 #include <Graphic3d_ArrayOfSegments.hxx>
62 /*----------------------------------------------------------------------*/
70 /*----------------------------------------------------------------------*/
72 V3d_RectangularGrid::V3d_RectangularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
73 : Aspect_RectangularGrid (1.,1.),
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 gstep = step/MYFACTOR;
86 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
87 SetGraphicValues (size, size, gstep);
92 void V3d_RectangularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
94 if( myColor != aColor || myTenthColor != aTenthColor ) {
96 myTenthColor = aTenthColor;
97 myCurAreDefined = Standard_False;
102 void V3d_RectangularGrid::Display ()
104 myStructure->Display (1);
107 void V3d_RectangularGrid::Erase () const
109 myStructure->Erase ();
112 Standard_Boolean V3d_RectangularGrid::IsDisplayed () const
114 return myStructure->IsDisplayed ();
117 void V3d_RectangularGrid::UpdateDisplay ()
119 gp_Ax3 ThePlane = myViewer->PrivilegedPlane ();
121 Standard_Boolean MakeTransform = Standard_False;
122 Standard_Real xl, yl, zl;
123 Standard_Real xdx, xdy, xdz;
124 Standard_Real ydx, ydy, ydz;
125 Standard_Real dx, dy, dz;
126 ThePlane.Location ().Coord (xl, yl, zl);
127 ThePlane.XDirection ().Coord (xdx, xdy, xdz);
128 ThePlane.YDirection ().Coord (ydx, ydy, ydz);
129 ThePlane.Direction ().Coord (dx, dy, dz);
130 if (! myCurAreDefined)
131 MakeTransform = Standard_True;
133 if (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo)
134 MakeTransform = Standard_True;
135 if (! MakeTransform) {
136 Standard_Real curxl, curyl, curzl;
137 Standard_Real curxdx, curxdy, curxdz;
138 Standard_Real curydx, curydy, curydz;
139 Standard_Real curdx, curdy, curdz;
140 myCurViewPlane.Location ().Coord (curxl, curyl, curzl);
141 myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz);
142 myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz);
143 myCurViewPlane.Direction ().Coord (curdx, curdy, curdz);
144 if (xl != curxl || yl != curyl || zl != curzl ||
145 xdx != curxdx || xdy != curxdy || xdz != curxdz ||
146 ydx != curydx || ydy != curydy || ydz != curydz ||
147 dx != curdx || dy != curdy || dz != curdz)
148 MakeTransform = Standard_True;
153 const Standard_Real CosAlpha = Cos (RotationAngle ());
154 const Standard_Real SinAlpha = Sin (RotationAngle ());
155 TColStd_Array2OfReal Trsf (1, 4, 1, 4);
157 Trsf (4, 1) = Trsf (4, 2) = Trsf (4, 3) = 0.0;
162 // Transformation of change of marker
172 myStructure->SetTransform (Trsf, Graphic3d_TOC_REPLACE);
174 // Translation of the origin
175 Trsf (1, 4) = -XOrigin (),
176 Trsf (2, 4) = -YOrigin (),
178 // Rotation Alpha around axis -Z
179 Trsf (1, 1) = CosAlpha,
180 Trsf (2, 1) = -SinAlpha,
182 Trsf (1, 2) = SinAlpha,
183 Trsf (2, 2) = CosAlpha,
188 myStructure->SetTransform (Trsf,Graphic3d_TOC_POSTCONCATENATE);
190 myCurAngle = RotationAngle ();
191 myCurXo = XOrigin (), myCurYo = YOrigin ();
192 myCurViewPlane = ThePlane;
198 //case Aspect_GDM_Points:
200 myCurDrawMode = Aspect_GDM_Points;
202 case Aspect_GDM_Lines:
204 myCurDrawMode = Aspect_GDM_Lines;
207 case Aspect_GDM_None:
208 myCurDrawMode = Aspect_GDM_None;
212 myCurAreDefined = Standard_True;
215 void V3d_RectangularGrid::DefineLines ()
217 const Standard_Real aXStep = XStep();
218 const Standard_Real aYStep = YStep();
219 const Standard_Boolean toUpdate = !myCurAreDefined
220 || myCurDrawMode != Aspect_GDM_Lines
221 || aXStep != myCurXStep
222 || aYStep != myCurYStep;
230 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
231 LineAttrib->SetColor (myColor);
232 LineAttrib->SetType (Aspect_TOL_SOLID);
233 LineAttrib->SetWidth (1.0);
235 Standard_Integer nblines;
236 Standard_Real xl, yl, zl = myOffSet;
238 TColgp_SequenceOfPnt aSeqLines, aSeqTenth;
241 aSeqTenth.Append(gp_Pnt(0., -myYSize, -zl));
242 aSeqTenth.Append(gp_Pnt(0., myYSize, -zl));
243 for (nblines = 1, xl = aXStep; xl < myXSize; xl += aXStep, nblines++)
245 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
246 aSeq.Append(gp_Pnt( xl, -myYSize, -zl));
247 aSeq.Append(gp_Pnt( xl, myYSize, -zl));
248 aSeq.Append(gp_Pnt(-xl, -myYSize, -zl));
249 aSeq.Append(gp_Pnt(-xl, myYSize, -zl));
253 aSeqTenth.Append(gp_Pnt(-myXSize, 0., -zl));
254 aSeqTenth.Append(gp_Pnt( myXSize, 0., -zl));
255 for (nblines = 1, yl = aYStep; yl < myYSize; yl += aYStep, nblines++)
257 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
258 aSeq.Append(gp_Pnt(-myXSize, yl, -zl));
259 aSeq.Append(gp_Pnt( myXSize, yl, -zl));
260 aSeq.Append(gp_Pnt(-myXSize, -yl, -zl));
261 aSeq.Append(gp_Pnt( myXSize, -yl, -zl));
264 if (aSeqLines.Length())
266 LineAttrib->SetColor (myColor);
267 myGroup->SetPrimitivesAspect (LineAttrib);
268 const Standard_Integer nbv = aSeqLines.Length();
269 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
270 Standard_Integer n = 1;
272 aPrims->AddVertex(aSeqLines(n++));
273 myGroup->AddPrimitiveArray(aPrims, Standard_False);
275 if (aSeqTenth.Length())
277 LineAttrib->SetColor (myTenthColor);
278 myGroup->SetPrimitivesAspect (LineAttrib);
279 const Standard_Integer nbv = aSeqTenth.Length();
280 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
281 Standard_Integer n = 1;
283 aPrims->AddVertex(aSeqTenth(n++));
284 myGroup->AddPrimitiveArray(aPrims, Standard_False);
287 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
288 myCurXStep = aXStep, myCurYStep = aYStep;
291 void V3d_RectangularGrid::DefinePoints ()
293 const Standard_Real aXStep = XStep();
294 const Standard_Real aYStep = YStep();
295 const Standard_Boolean toUpdate = !myCurAreDefined
296 || myCurDrawMode != Aspect_GDM_Points
297 || aXStep != myCurXStep
298 || aYStep != myCurYStep;
306 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
307 MarkerAttrib->SetColor (myColor);
308 MarkerAttrib->SetType (Aspect_TOM_POINT);
309 MarkerAttrib->SetScale (3.);
312 Standard_Real xl, yl;
313 TColgp_SequenceOfPnt aSeqPnts;
314 for (xl = 0.0; xl <= myXSize; xl += aXStep) {
315 aSeqPnts.Append(gp_Pnt( xl, 0.0, -myOffSet));
316 aSeqPnts.Append(gp_Pnt(-xl, 0.0, -myOffSet));
317 for (yl = aYStep; yl <= myYSize; yl += aYStep) {
318 aSeqPnts.Append(gp_Pnt( xl, yl, -myOffSet));
319 aSeqPnts.Append(gp_Pnt( xl, -yl, -myOffSet));
320 aSeqPnts.Append(gp_Pnt(-xl, yl, -myOffSet));
321 aSeqPnts.Append(gp_Pnt(-xl, -yl, -myOffSet));
324 if (aSeqPnts.Length())
328 const Standard_Integer nbv = aSeqPnts.Length();
329 Graphic3d_Array1OfVertex Vertical (1,nbv);
330 for (i=1; i<=nbv; i++)
332 aSeqPnts(i).Coord(X,Y,Z);
333 Vertical(i).SetCoord(X,Y,Z);
335 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
336 myGroup->MarkerSet (Vertical, Standard_False);
339 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
340 myCurXStep = aXStep, myCurYStep = aYStep;
343 void V3d_RectangularGrid::GraphicValues (Standard_Real& theXSize, Standard_Real& theYSize, Standard_Real& theOffSet) const
347 theOffSet = myOffSet;
350 void V3d_RectangularGrid::SetGraphicValues (const Standard_Real theXSize, const Standard_Real theYSize, const Standard_Real theOffSet)
352 if (! myCurAreDefined) {
355 myOffSet = theOffSet;
357 if (myXSize != theXSize) {
359 myCurAreDefined = Standard_False;
361 if (myYSize != theYSize) {
363 myCurAreDefined = Standard_False;
365 if (myOffSet != theOffSet) {
366 myOffSet = theOffSet;
367 myCurAreDefined = Standard_False;
369 if( !myCurAreDefined ) UpdateDisplay();