Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:15:36

0001 // Copyright (c) 2026 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Aspect_GridParams_HeaderFile
0015 #define _Aspect_GridParams_HeaderFile
0016 
0017 #include <Standard.hxx>
0018 #include <Standard_DefineAlloc.hxx>
0019 #include <Standard_NegativeValue.hxx>
0020 
0021 #include <Aspect_GridDrawMode.hxx>
0022 #include <Quantity_Color.hxx>
0023 #include <gp_Pnt.hxx>
0024 
0025 //! Grid appearance for V3d_View::GridDisplay: color, scale, bounds, arc, draw mode,
0026 //! background and adaptive flags.
0027 class Aspect_GridParams
0028 {
0029 public:
0030   DEFINE_STANDARD_ALLOC
0031 
0032   //! Construct with sensible defaults: grey lines on the plane origin with
0033   //! axis coloring enabled, 1/100 plane-unit spacing, overlay mode,
0034   //! unbounded in extent and radius.
0035   Aspect_GridParams()
0036       : myColor(Quantity_NOC_GRAY70),
0037         myAccentColor(Quantity_NOC_GRAY50),
0038         myOrigin(0.0, 0.0, 0.0),
0039         myScale(0.01),
0040         myScaleY(0.0),
0041         myAccentScaleX(0.0),
0042         myAccentScaleY(0.0),
0043         myAccentAngularScale(0.0),
0044         myLineThickness(0.01),
0045         myRotationAngle(0.0),
0046         mySizeX(0.0),
0047         mySizeY(0.0),
0048         myRadius(0.0),
0049         myZOffset(0.0),
0050         myAngleStart(0.0),
0051         myAngleEnd(0.0),
0052         myAngularDivisions(0),
0053         myDrawMode(Aspect_GDM_Lines),
0054         myIsBackground(false),
0055         myIsDrawAxis(true),
0056         myIsViewAdaptive(false)
0057   {
0058   }
0059 
0060   //! Return grid line color.
0061   const Quantity_Color& Color() const { return myColor; }
0062 
0063   //! Set grid line color.
0064   void SetColor(const Quantity_Color& theColor) { myColor = theColor; }
0065 
0066   //! Return local offset of the grid origin within the plane.
0067   const gp_Pnt& Origin() const { return myOrigin; }
0068 
0069   //! Set local offset of the grid origin within the plane.
0070   void SetOrigin(const gp_Pnt& theOrigin) { myOrigin = theOrigin; }
0071 
0072   //! Return every-tenth-line / accent colour rendered by the shader.
0073   const Quantity_Color& AccentColor() const { return myAccentColor; }
0074 
0075   //! Set every-tenth-line / accent colour rendered by the shader.
0076   void SetAccentColor(const Quantity_Color& theColor) { myAccentColor = theColor; }
0077 
0078   //! Return accent overlay scale along the plane X/radial direction.
0079   //! Zero disables the accent layer on that axis.
0080   double AccentScaleX() const { return myAccentScaleX; }
0081 
0082   //! Set accent overlay scale along the plane X/radial direction.
0083   void SetAccentScaleX(const double theScale) { myAccentScaleX = theScale; }
0084 
0085   //! Return accent overlay scale along the plane Y direction.
0086   //! Zero disables the accent layer on that axis.
0087   double AccentScaleY() const { return myAccentScaleY; }
0088 
0089   //! Set accent overlay scale along the plane Y direction.
0090   void SetAccentScaleY(const double theScale) { myAccentScaleY = theScale; }
0091 
0092   //! Return accent overlay angular scale for circular-grid spokes.
0093   //! Zero disables the angular accent layer.
0094   double AccentAngularScale() const { return myAccentAngularScale; }
0095 
0096   //! Set accent overlay angular scale for circular-grid spokes.
0097   void SetAccentAngularScale(const double theScale) { myAccentAngularScale = theScale; }
0098 
0099   //! Return major-grid scale factor along the plane X direction (cells per plane unit).
0100   double Scale() const { return myScale; }
0101 
0102   //! Set major-grid scale factor along the plane X direction (cells per plane unit).
0103   //! Must be non-negative; zero is a valid "unused" sentinel.
0104   void SetScale(const double theScale)
0105   {
0106     Standard_NegativeValue_Raise_if(theScale < 0.0, "invalid grid scale");
0107     myScale = theScale;
0108   }
0109 
0110   //! Return explicit Y-direction scale. When 0.0, renderer falls back to Scale() (isotropic).
0111   double ScaleY() const { return myScaleY; }
0112 
0113   //! Set explicit Y-direction scale. Pass 0.0 to mirror Scale() (isotropic, default).
0114   void SetScaleY(const double theScaleY)
0115   {
0116     Standard_NegativeValue_Raise_if(theScaleY < 0.0, "invalid grid Y-scale");
0117     myScaleY = theScaleY;
0118   }
0119 
0120   //! Effective Y-direction scale actually consumed by the renderer.
0121   double EffectiveScaleY() const { return myScaleY > 0.0 ? myScaleY : myScale; }
0122 
0123   //! Return line thickness in plane units (minimum pixel-space line width is derived from fwidth).
0124   double LineThickness() const { return myLineThickness; }
0125 
0126   //! Set line thickness in plane units.
0127   void SetLineThickness(const double theThickness)
0128   {
0129     Standard_NegativeValue_Raise_if(theThickness < 0.0, "invalid grid line thickness");
0130     myLineThickness = theThickness;
0131   }
0132 
0133   //! Return in-plane rotation angle (radians) applied to the grid axes around the plane normal.
0134   double RotationAngle() const { return myRotationAngle; }
0135 
0136   //! Set in-plane rotation angle (radians) applied to the grid axes around the plane normal.
0137   void SetRotationAngle(const double theAngle) { myRotationAngle = theAngle; }
0138 
0139   //! Return the angular subdivision count of the half-circle for circular grids.
0140   //! Zero means rectangular grid (default); any positive value switches the
0141   //! renderer to polar rings (Scale -> radial step) and spokes at pi/N rad.
0142   int AngularDivisions() const { return myAngularDivisions; }
0143 
0144   //! Set angular subdivision count (0 = rectangular grid, N>0 = circular with N spokes per 180
0145   //! deg).
0146   void SetAngularDivisions(const int theDivisions) { myAngularDivisions = theDivisions; }
0147 
0148   //! Return TRUE when the parameters describe a circular (polar) grid.
0149   bool IsCircular() const { return myAngularDivisions > 0; }
0150 
0151   //! Return rectangular bounded extent along plane X; 0.0 means unbounded.
0152   double SizeX() const { return mySizeX; }
0153 
0154   //! Set rectangular bounded extent along plane X; 0.0 means unbounded.
0155   void SetSizeX(const double theSize)
0156   {
0157     Standard_NegativeValue_Raise_if(theSize < 0.0, "invalid grid X-size");
0158     mySizeX = theSize;
0159   }
0160 
0161   //! Return rectangular bounded extent along plane Y; 0.0 means unbounded.
0162   double SizeY() const { return mySizeY; }
0163 
0164   //! Set rectangular bounded extent along plane Y; 0.0 means unbounded.
0165   void SetSizeY(const double theSize)
0166   {
0167     Standard_NegativeValue_Raise_if(theSize < 0.0, "invalid grid Y-size");
0168     mySizeY = theSize;
0169   }
0170 
0171   //! Return circular bounded radius; 0.0 means unbounded.
0172   double Radius() const { return myRadius; }
0173 
0174   //! Set circular bounded radius; 0.0 means unbounded.
0175   void SetRadius(const double theRadius)
0176   {
0177     Standard_NegativeValue_Raise_if(theRadius < 0.0, "invalid grid radius");
0178     myRadius = theRadius;
0179   }
0180 
0181   //! Return signed plane-normal offset applied at render time.
0182   double ZOffset() const { return myZOffset; }
0183 
0184   //! Set signed plane-normal offset applied at render and echo time.
0185   void SetZOffset(const double theOffset) { myZOffset = theOffset; }
0186 
0187   //! Return arc start angle (radians). Meaningful only when IsArc() is true.
0188   double AngleStart() const { return myAngleStart; }
0189 
0190   //! Return arc end angle (radians). Meaningful only when IsArc() is true.
0191   double AngleEnd() const { return myAngleEnd; }
0192 
0193   //! Restrict the circular grid to an angular wedge [start, end], walking CCW.
0194   //! Equal start and end (e.g. 0.0 and 0.0) returns to full-circle rendering.
0195   void SetArcRange(const double theStart, const double theEnd)
0196   {
0197     myAngleStart = theStart;
0198     myAngleEnd   = theEnd;
0199   }
0200 
0201   //! Return TRUE when the parameters describe a bounded rectangle or disc.
0202   bool IsBounded() const { return mySizeX > 0.0 || mySizeY > 0.0 || myRadius > 0.0; }
0203 
0204   //! Return TRUE when the circular grid is restricted to a sub-arc.
0205   bool IsArc() const { return myAngleStart != myAngleEnd; }
0206 
0207   //! Return draw mode: lines, points at grid intersections, or none.
0208   Aspect_GridDrawMode DrawMode() const { return myDrawMode; }
0209 
0210   //! Set draw mode. Aspect_GDM_None suppresses rendering entirely; Points draws
0211   //! dots at grid-line intersections, Lines (default) draws the full grid.
0212   void SetDrawMode(const Aspect_GridDrawMode theMode) { myDrawMode = theMode; }
0213 
0214   //! Return TRUE if grid is drawn as a view-space background (behind all geometry).
0215   bool IsBackground() const { return myIsBackground; }
0216 
0217   //! Set background-mode rendering on/off.
0218   void SetIsBackground(const bool theIsBackground) { myIsBackground = theIsBackground; }
0219 
0220   //! Return TRUE if axis lines on the grid plane are drawn in red/green/blue.
0221   bool IsDrawAxis() const { return myIsDrawAxis; }
0222 
0223   //! Set axis coloring on/off.
0224   void SetIsDrawAxis(const bool theIsDrawAxis) { myIsDrawAxis = theIsDrawAxis; }
0225 
0226   //! Return TRUE if grid spacing and visible extents adapt to the camera view.
0227   bool IsViewAdaptive() const { return myIsViewAdaptive; }
0228 
0229   //! Set view-adaptive grid on/off. When enabled, shader renderer keeps the
0230   //! screen-space grid step stable by scaling the cell spacing with camera zoom.
0231   void SetIsViewAdaptive(const bool theIsViewAdaptive) { myIsViewAdaptive = theIsViewAdaptive; }
0232 
0233 private:
0234   Quantity_Color      myColor;
0235   Quantity_Color      myAccentColor;
0236   gp_Pnt              myOrigin;
0237   double              myScale;
0238   double              myScaleY;
0239   double              myAccentScaleX;
0240   double              myAccentScaleY;
0241   double              myAccentAngularScale;
0242   double              myLineThickness;
0243   double              myRotationAngle;
0244   double              mySizeX;
0245   double              mySizeY;
0246   double              myRadius;
0247   double              myZOffset;
0248   double              myAngleStart;
0249   double              myAngleEnd;
0250   int                 myAngularDivisions;
0251   Aspect_GridDrawMode myDrawMode;
0252   bool                myIsBackground;
0253   bool                myIsDrawAxis;
0254   bool                myIsViewAdaptive;
0255 };
0256 
0257 #endif // _Aspect_GridParams_HeaderFile