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_ArrayOfPoints.hxx>
56 #include <Visual3d_ViewManager.hxx>
57 #include <V3d_Viewer.hxx>
58 #include <TColgp_SequenceOfPnt.hxx>
59 #include <Graphic3d_ArrayOfSegments.hxx>
61 /*----------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------*/
71 V3d_RectangularGrid::V3d_RectangularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
72 : Aspect_RectangularGrid (1.,1.),
73 myStructure (new Graphic3d_Structure (aViewer->Viewer ())),
74 myGroup (new Graphic3d_Group (myStructure)),
76 myCurAreDefined (Standard_False)
79 myTenthColor = aTenthColor;
81 myStructure->SetInfiniteState (Standard_True);
83 const Standard_Real step = 10.;
84 const Standard_Real gstep = step/MYFACTOR;
85 const Standard_Real size = 0.5*myViewer->DefaultViewSize();
86 SetGraphicValues (size, size, gstep);
91 void V3d_RectangularGrid::SetColors (const Quantity_Color& aColor, const Quantity_Color& aTenthColor)
93 if( myColor != aColor || myTenthColor != aTenthColor ) {
95 myTenthColor = aTenthColor;
96 myCurAreDefined = Standard_False;
101 void V3d_RectangularGrid::Display ()
103 myStructure->Display (1);
106 void V3d_RectangularGrid::Erase () const
108 myStructure->Erase ();
111 Standard_Boolean V3d_RectangularGrid::IsDisplayed () const
113 return myStructure->IsDisplayed ();
116 void V3d_RectangularGrid::UpdateDisplay ()
118 gp_Ax3 ThePlane = myViewer->PrivilegedPlane ();
120 Standard_Boolean MakeTransform = Standard_False;
121 Standard_Real xl, yl, zl;
122 Standard_Real xdx, xdy, xdz;
123 Standard_Real ydx, ydy, ydz;
124 Standard_Real dx, dy, dz;
125 ThePlane.Location ().Coord (xl, yl, zl);
126 ThePlane.XDirection ().Coord (xdx, xdy, xdz);
127 ThePlane.YDirection ().Coord (ydx, ydy, ydz);
128 ThePlane.Direction ().Coord (dx, dy, dz);
129 if (! myCurAreDefined)
130 MakeTransform = Standard_True;
132 if (RotationAngle() != myCurAngle || XOrigin() != myCurXo || YOrigin() != myCurYo)
133 MakeTransform = Standard_True;
134 if (! MakeTransform) {
135 Standard_Real curxl, curyl, curzl;
136 Standard_Real curxdx, curxdy, curxdz;
137 Standard_Real curydx, curydy, curydz;
138 Standard_Real curdx, curdy, curdz;
139 myCurViewPlane.Location ().Coord (curxl, curyl, curzl);
140 myCurViewPlane.XDirection ().Coord (curxdx, curxdy, curxdz);
141 myCurViewPlane.YDirection ().Coord (curydx, curydy, curydz);
142 myCurViewPlane.Direction ().Coord (curdx, curdy, curdz);
143 if (xl != curxl || yl != curyl || zl != curzl ||
144 xdx != curxdx || xdy != curxdy || xdz != curxdz ||
145 ydx != curydx || ydy != curydy || ydz != curydz ||
146 dx != curdx || dy != curdy || dz != curdz)
147 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 of 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_RectangularGrid::DefineLines ()
216 const Standard_Real aXStep = XStep();
217 const Standard_Real aYStep = YStep();
218 const Standard_Boolean toUpdate = !myCurAreDefined
219 || myCurDrawMode != Aspect_GDM_Lines
220 || aXStep != myCurXStep
221 || aYStep != myCurYStep;
229 Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d ();
230 LineAttrib->SetColor (myColor);
231 LineAttrib->SetType (Aspect_TOL_SOLID);
232 LineAttrib->SetWidth (1.0);
234 Standard_Integer nblines;
235 Standard_Real xl, yl, zl = myOffSet;
237 TColgp_SequenceOfPnt aSeqLines, aSeqTenth;
240 aSeqTenth.Append(gp_Pnt(0., -myYSize, -zl));
241 aSeqTenth.Append(gp_Pnt(0., myYSize, -zl));
242 for (nblines = 1, xl = aXStep; xl < myXSize; xl += aXStep, nblines++)
244 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
245 aSeq.Append(gp_Pnt( xl, -myYSize, -zl));
246 aSeq.Append(gp_Pnt( xl, myYSize, -zl));
247 aSeq.Append(gp_Pnt(-xl, -myYSize, -zl));
248 aSeq.Append(gp_Pnt(-xl, myYSize, -zl));
252 aSeqTenth.Append(gp_Pnt(-myXSize, 0., -zl));
253 aSeqTenth.Append(gp_Pnt( myXSize, 0., -zl));
254 for (nblines = 1, yl = aYStep; yl < myYSize; yl += aYStep, nblines++)
256 TColgp_SequenceOfPnt &aSeq = (Modulus(nblines, 10) != 0)? aSeqLines : aSeqTenth;
257 aSeq.Append(gp_Pnt(-myXSize, yl, -zl));
258 aSeq.Append(gp_Pnt( myXSize, yl, -zl));
259 aSeq.Append(gp_Pnt(-myXSize, -yl, -zl));
260 aSeq.Append(gp_Pnt( myXSize, -yl, -zl));
263 if (aSeqLines.Length())
265 LineAttrib->SetColor (myColor);
266 myGroup->SetPrimitivesAspect (LineAttrib);
267 const Standard_Integer nbv = aSeqLines.Length();
268 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
269 Standard_Integer n = 1;
271 aPrims->AddVertex(aSeqLines(n++));
272 myGroup->AddPrimitiveArray(aPrims, Standard_False);
274 if (aSeqTenth.Length())
276 LineAttrib->SetColor (myTenthColor);
277 myGroup->SetPrimitivesAspect (LineAttrib);
278 const Standard_Integer nbv = aSeqTenth.Length();
279 Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(nbv);
280 Standard_Integer n = 1;
282 aPrims->AddVertex(aSeqTenth(n++));
283 myGroup->AddPrimitiveArray(aPrims, Standard_False);
286 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
287 myCurXStep = aXStep, myCurYStep = aYStep;
290 void V3d_RectangularGrid::DefinePoints ()
292 const Standard_Real aXStep = XStep();
293 const Standard_Real aYStep = YStep();
294 const Standard_Boolean toUpdate = !myCurAreDefined
295 || myCurDrawMode != Aspect_GDM_Points
296 || aXStep != myCurXStep
297 || aYStep != myCurYStep;
305 Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
306 MarkerAttrib->SetColor (myColor);
307 MarkerAttrib->SetType (Aspect_TOM_POINT);
308 MarkerAttrib->SetScale (3.);
311 Standard_Real xl, yl;
312 TColgp_SequenceOfPnt aSeqPnts;
313 for (xl = 0.0; xl <= myXSize; xl += aXStep) {
314 aSeqPnts.Append(gp_Pnt( xl, 0.0, -myOffSet));
315 aSeqPnts.Append(gp_Pnt(-xl, 0.0, -myOffSet));
316 for (yl = aYStep; yl <= myYSize; yl += aYStep) {
317 aSeqPnts.Append(gp_Pnt( xl, yl, -myOffSet));
318 aSeqPnts.Append(gp_Pnt( xl, -yl, -myOffSet));
319 aSeqPnts.Append(gp_Pnt(-xl, yl, -myOffSet));
320 aSeqPnts.Append(gp_Pnt(-xl, -yl, -myOffSet));
323 if (aSeqPnts.Length())
327 const Standard_Integer nbv = aSeqPnts.Length();
328 Handle(Graphic3d_ArrayOfPoints) Vertical = new Graphic3d_ArrayOfPoints (nbv);
329 for (i=1; i<=nbv; i++)
331 aSeqPnts(i).Coord(X,Y,Z);
332 Vertical->AddVertex (X,Y,Z);
334 myGroup->SetGroupPrimitivesAspect (MarkerAttrib);
335 myGroup->AddPrimitiveArray (Vertical, Standard_False);
338 myGroup->SetMinMaxValues(-myXSize, -myYSize, 0.0, myXSize, myYSize, 0.0);
339 myCurXStep = aXStep, myCurYStep = aYStep;
342 void V3d_RectangularGrid::GraphicValues (Standard_Real& theXSize, Standard_Real& theYSize, Standard_Real& theOffSet) const
346 theOffSet = myOffSet;
349 void V3d_RectangularGrid::SetGraphicValues (const Standard_Real theXSize, const Standard_Real theYSize, const Standard_Real theOffSet)
351 if (! myCurAreDefined) {
354 myOffSet = theOffSet;
356 if (myXSize != theXSize) {
358 myCurAreDefined = Standard_False;
360 if (myYSize != theYSize) {
362 myCurAreDefined = Standard_False;
364 if (myOffSet != theOffSet) {
365 myOffSet = theOffSet;
366 myCurAreDefined = Standard_False;
368 if( !myCurAreDefined ) UpdateDisplay();