Skip to content

RHatchData

Class in Entity Module
Header: #include <src/entity/RHatchData.h>
Inherits: REntityData, RPainterPathSource

Stores and manages all data that defines the geometry and appearance of a hatch or solid fill entity.

Scriptable: This class is available in script environments.

Copyable: Objects are cleaned up automatically by the garbage collector of the script engine.

RHatchData()
RHatchData(bool solid, double scaleFactor, double angle, const QString &patternName)
RHatchData(const RHatchData &other)
void addBoundary(QSharedPointer< RShape > shape, bool addAutoLoops=true)
Add a boundary shape to the current loop.
void addBoundaryShape(QSharedPointer< RShape > shape, int loop)
void autoCloseLoops()
void cancelLoop()
virtual RShape * castToShape()
void clearBoundary()
void clearCustomPattern()
void clearGradient()
virtual bool cloneOnChange() const
Reimplement to force clone on change in transactions.
double getAngle() const
double getArea() const
bool getAutoRegen() const
QList< QList< QSharedPointer< RShape > > > getBoundary() const
QList< RPolyline > getBoundaryAsPolylines(double segmentLength=RDEFAULT_MIN1) const
QPair< QSharedPointer< RShape >, QSharedPointer< RShape > > getBoundaryElementsAt(int index, int &internalIndex) const
RPainterPath getBoundaryPath(double pixelSizeHint=RDEFAULT_MIN1) const
virtual RBox getBoundingBox(bool ignoreEmpty=false) const
virtual RColor getColor() const
virtual RColor getColor(bool resolve, const QStack< QSharedPointer< REntity > > &blockRefStack) const
virtual RColor getColor(const RColor &unresolvedColor, const QStack< QSharedPointer< REntity > > &blockRefStack) const
int getComplexity() const
RPattern getCustomPattern() const
virtual double getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const
virtual QList< QSharedPointer< RShape > > getExploded() const
double getGradientAngle() const
RColor getGradientColor1() const
RColor getGradientColor2() const
QString getGradientName() const
bool getGradientOneColorMode() const
double getGradientShift() const
double getGradientTint() const
double getLength() const
QList< QSharedPointer< RShape > > getLoopBoundary(int index) const
int getLoopCount() const
RVector getOriginPoint() const
virtual QList< RPainterPath > getPainterPaths(bool draft=false, double pixelSizeHint=RDEFAULT_MIN1) const
QString getPatternName() const
virtual RVector getPointOnEntity() const
virtual QList< RRefPoint > getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const
double getScale() const
virtual QList< QSharedPointer< RShape > > getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false, QList< RObject::Id > *entityIds=NULL) const
int getTransparency() const
virtual RS::EntityType getType() const
bool hasCustomPattern() const
virtual bool intersectsWith(const RShape &shape) const
bool isGradient() const
bool isSolid() const
bool isWinding() const
virtual bool mirror(const RLine &axis)
virtual bool move(const RVector &offset)
Moves this entity by the given offset.
virtual bool moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
Moves the given reference point to the given target point or does nothing if this entity has no reference point as the given location.
void newLoop()
RHatchData & operator=(const RHatchData &other)
bool order()
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
void setAngle(double a)
void setAutoRegen(bool on)
void setCustomPattern(const RPattern &p)
void setGradientAngle(double a)
void setGradientColor1(const RColor &c)
void setGradientColor2(const RColor &c)
void setGradientName(const QString &n)
Sets the gradient name and makes this hatch a gradient fill.
void setGradientOneColorMode(bool on)
void setGradientShift(double s)
void setGradientTint(double t)
void setOriginPoint(const RVector &op, bool clearCustom=true)
void setPattern(const RPattern &p)
void setPatternName(const QString &n)
void setScale(double s)
void setSolid(bool on)
void setTransparency(int t)
void setWinding(bool on)
virtual bool stretch(const RPolyline &area, const RVector &offset)
Stretches the end points of this entity that are inside area by offset.
virtual void update() const
Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty).
static RHatchProxy * getHatchProxy()
static bool hasProxy()
static QString normalizeGradientName(const QString &n)
static void setHatchProxy(RHatchProxy *p)
RHatchData(RDocument *document, const RHatchData &data)
QBrush createGradientBrush() const
QList< RLine > getSegments(const RLine &line) const
bool addWindingNumber(const int *edgeIndices, int count, double x, double y, int &windingNumber) const
Accumulates the winding number contribution of the given range of edges, using the same scanline rules as QPainterPath::contains.
bool isPointInBoundary(double x, double y) const
void updateBoundaryBoxes() const
Updates the cached bounding boxes of all boundary shapes.
void updateBoundaryPointCache() const
Updates the flattened representation of the boundary path which is used by isPointInBoundary().
double angle
bool autoRegen
QList< QList< QSharedPointer< RShape > > > boundary
Hatch boundary, ordered by loops, in strictly defined order.
int boundaryBandCount
QVector< int > boundaryBandEdges
double boundaryBandHeight
QVector< int > boundaryBandStart
QVector< double > boundaryBoxes
Bounding box of every boundary shape, grown by the same tolerance the intersection code uses.
bool boundaryBoxesValid
QVector< qint8 > boundaryEdgeDirs
QVector< double > boundaryEdges
Flattened boundary (boundaryPath), used to determine whether a point is inside the hatch much faster than QPainterPath::contains can.
double boundaryFlatteningError
QVector< int > boundaryLongEdges
double boundaryMaxX
double boundaryMaxY
double boundaryMinX
double boundaryMinY
RPainterPath boundaryPath
bool boundaryPointCacheValid
bool dirty
bool gotDraft
double gotPixelSizeHint
double gradientAngle
RColor gradientColor1
RColor gradientColor2
QString gradientName
Gradient fill data (DXF/DWG compatible).
bool gradientOneColorMode
double gradientShift
double gradientTint
RVector originPoint
QList< RPainterPath > painterPaths
RPattern pattern
Custom pattern loaded from DXF file, not LIN file.
QString patternName
double scaleFactor
bool solid
int transparency
bool winding
static RHatchProxy * hatchProxy
class RHatchEntity

RHatchData::RHatchData()

RHatchData::RHatchData(bool solid, double scaleFactor, double angle, const QString &patternName)

Parameters:

  • solid: True for a solid fill, false for a hatch pattern.
  • scaleFactor: Scale factor of the hatch pattern.
  • angle: Rotation angle of the hatch pattern.
  • patternName: Name of the hatch pattern. “SOLID” for solid fills.

RHatchData::RHatchData(const RHatchData &other)

void RHatchData::addBoundary(QSharedPointer< RShape > shape, bool addAutoLoops=true)

Add a boundary shape to the current loop.

Parameters:

  • addAutoLoops: True: create new loop if boundary does not connect. Otherwise add line segment on the fly (DXF/DWG import).

void RHatchData::addBoundaryShape(QSharedPointer< RShape > shape, int loop)

inline

void RHatchData::autoCloseLoops()

inline

void RHatchData::cancelLoop()

virtual RShape * RHatchData::castToShape()

virtual inline

Reimplemented from castToShape.

void RHatchData::clearBoundary()

void RHatchData::clearCustomPattern()

void RHatchData::clearGradient()

inline

virtual bool RHatchData::cloneOnChange() const

virtual inline const

Reimplement to force clone on change in transactions.

Reimplemented from cloneOnChange.

double RHatchData::getAngle() const

inline const

double RHatchData::getArea() const

const

bool RHatchData::getAutoRegen() const

inline const

QList< QList< QSharedPointer< RShape > > > RHatchData::getBoundary() const

inline const

QList< RPolyline > RHatchData::getBoundaryAsPolylines(double segmentLength=RDEFAULT_MIN1) const

const

QPair< QSharedPointer< RShape >, QSharedPointer< RShape > > RHatchData::getBoundaryElementsAt(int index, int &internalIndex) const

const

Non-Scriptable: This function is not available in script environments.

Returns: Pair of two shapes that connect to the vertex at the given index. The first shape connects with its end point, the second with its start point.

RPainterPath RHatchData::getBoundaryPath(double pixelSizeHint=RDEFAULT_MIN1) const

const

Returns: Painter path that represents this hatch boundary.

virtual RBox RHatchData::getBoundingBox(bool ignoreEmpty=false) const

virtual const

Returns: The bounding box that contains this entity.

Reimplemented from getBoundingBox.

virtual RColor RHatchData::getColor() const

virtual inline const

Reimplemented from getColor.

virtual RColor RHatchData::getColor(bool resolve, const QStack< QSharedPointer< REntity > > &blockRefStack) const

virtual inline const

Returns: Color of this entity.

Parameters:

  • resolve: Resolve color if ByLayer or ByBlock.

Reimplemented from getColor.

virtual RColor RHatchData::getColor(const RColor &unresolvedColor, const QStack< QSharedPointer< REntity > > &blockRefStack) const

virtual inline const

Reimplemented from getColor.

int RHatchData::getComplexity() const

const

RPattern RHatchData::getCustomPattern() const

inline const

virtual double RHatchData::getDistanceTo(const RVector &point, bool limited=true, double range=0.0, bool draft=false, double strictRange=RMAXDOUBLE) const

virtual const

Returns: The shortest distance from this entity to the given point.

Parameters:

  • limited: Limit lines, arcs at end points, otherwise the orthogonal distance to the unlimited line / circle is returned.
  • range: This is returned for solid filled entities (solid filled or dense hatches, text entities) if the point is on the entity and the distance would be zero.
  • draft: Calculate based on draft mode representation of the entity.
  • strictRange: If limited, this is the maximum range from either end point of the entity. Zero to only return distances that are strictly orthogonal to the entity.

Reimplemented from getDistanceTo.

virtual QList< QSharedPointer< RShape > > RHatchData::getExploded() const

virtual const

double RHatchData::getGradientAngle() const

inline const

RColor RHatchData::getGradientColor1() const

inline const

RColor RHatchData::getGradientColor2() const

inline const

QString RHatchData::getGradientName() const

inline const

bool RHatchData::getGradientOneColorMode() const

inline const

double RHatchData::getGradientShift() const

inline const

double RHatchData::getGradientTint() const

inline const

double RHatchData::getLength() const

const

QList< QSharedPointer< RShape > > RHatchData::getLoopBoundary(int index) const

const

int RHatchData::getLoopCount() const

inline const

RVector RHatchData::getOriginPoint() const

inline const

virtual QList< RPainterPath > RHatchData::getPainterPaths(bool draft=false, double pixelSizeHint=RDEFAULT_MIN1) const

virtual const

Parameters:

  • pixelSizeHint: Pixel size hint for rendering arcs. Negative if it does not matter (current cached painter paths are returned).

Reimplemented from getPainterPaths.

QString RHatchData::getPatternName() const

inline const

virtual RVector RHatchData::getPointOnEntity() const

virtual const

Returns: A point that is on the entity. Used to check if an entity is inside a polygon.

Reimplemented from getPointOnEntity.

virtual QList< RRefPoint > RHatchData::getReferencePoints(RS::ProjectionRenderingHint hint=RS::RenderTop) const

virtual const

Returns: Vector of reference points of this entity. Reference points can usually be moved around by the user to change the geometry of the entity.

Reimplemented from getReferencePoints.

double RHatchData::getScale() const

inline const

virtual QList< QSharedPointer< RShape > > RHatchData::getShapes(const RBox &queryBox=RDEFAULT_RBOX, bool ignoreComplex=false, bool segment=false, QList< RObject::Id > *entityIds=NULL) const

virtual const

Returns: Shapes that represent the geometry of this entity.

Parameters:

  • queryBox: Limit returned shapes to query box
  • ignoreComplex: Ignore complex shapes and explode those into simple shapes
  • segment: Split up splines into spline segments

Reimplemented from getShapes.

int RHatchData::getTransparency() const

inline const

virtual RS::EntityType RHatchData::getType() const

virtual inline const

Reimplemented from getType.

bool RHatchData::hasCustomPattern() const

inline const

virtual bool RHatchData::intersectsWith(const RShape &shape) const

virtual const

Returns: True if this entity intersects with the given shape, false otherwise.

Reimplemented from intersectsWith.

bool RHatchData::isGradient() const

inline const

Returns: True if this hatch is a gradient fill (gradient name set).

bool RHatchData::isSolid() const

inline const

bool RHatchData::isWinding() const

inline const

virtual bool RHatchData::mirror(const RLine &axis)

virtual

Reimplemented from mirror.

virtual bool RHatchData::move(const RVector &offset)

virtual

Moves this entity by the given offset.

Reimplemented from move.

virtual bool RHatchData::moveReferencePoint(const RVector &referencePoint, const RVector &targetPoint, Qt::KeyboardModifiers modifiers=Qt::NoModifier)

virtual

Moves the given reference point to the given target point or does nothing if this entity has no reference point as the given location.

Returns: True if a reference point has been moved successfully, false otherwise.

Reimplemented from moveReferencePoint.

void RHatchData::newLoop()

RHatchData & RHatchData::operator=(const RHatchData &other)

bool RHatchData::order()

virtual bool RHatchData::rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)

virtual

Reimplemented from rotate.

virtual bool RHatchData::scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)

virtual

Reimplemented from scale.

void RHatchData::setAngle(double a)

void RHatchData::setAutoRegen(bool on)

inline

void RHatchData::setCustomPattern(const RPattern &p)

inline

void RHatchData::setGradientAngle(double a)

inline

void RHatchData::setGradientColor1(const RColor &c)

inline

void RHatchData::setGradientColor2(const RColor &c)

inline

void RHatchData::setGradientName(const QString &n)

inline

Sets the gradient name and makes this hatch a gradient fill.

Valid names are LINEAR, CYLINDER, INVCYLINDER, SPHERICAL, INVSPHERICAL, HEMISPHERICAL, INVHEMISPHERICAL, CURVED, INVCURVED (CYLINDER and INVCYLINDER are cyclic gradients from color 1 to color 2 and back to color 1). AutoCAD resource names (GR_LINEAR, GR_CYLIN, GR_INVCYL, …) are accepted and normalized to the DXF names. An empty name means no gradient (regular hatch or solid fill).

void RHatchData::setGradientOneColorMode(bool on)

inline

void RHatchData::setGradientShift(double s)

inline

void RHatchData::setGradientTint(double t)

inline

void RHatchData::setOriginPoint(const RVector &op, bool clearCustom=true)

inline

void RHatchData::setPattern(const RPattern &p)

inline

void RHatchData::setPatternName(const QString &n)

inline

void RHatchData::setScale(double s)

void RHatchData::setSolid(bool on)

inline

void RHatchData::setTransparency(int t)

inline

void RHatchData::setWinding(bool on)

inline

virtual bool RHatchData::stretch(const RPolyline &area, const RVector &offset)

virtual

Stretches the end points of this entity that are inside area by offset.

Reimplemented from stretch.

virtual void RHatchData::update() const

virtual const

Entities can reimplement this function to invalidate any internal cache (mark the entity as dirty).

Reimplemented from update.

static RHatchProxy * RHatchData::getHatchProxy()

static inline

Non-Scriptable: This function is not available in script environments.

static bool RHatchData::hasProxy()

static inline

static QString RHatchData::normalizeGradientName(const QString &n)

static

Returns: Normalized gradient name: the canonical DXF name in upper case. Accepts DXF names (e.g. “CYLINDER”) as well as AutoCAD resource names (e.g. “GR_CYLIN”) as used by the AutoCAD gradient user interface.

static void RHatchData::setHatchProxy(RHatchProxy *p)

static inline

Non-Scriptable: This function is not available in script environments.

RHatchData::RHatchData(RDocument *document, const RHatchData &data)

protected

QBrush RHatchData::createGradientBrush() const

const protected

Returns: Gradient brush used to render this gradient fill. Approximates the AutoCAD gradient types (LINEAR, CYLINDER, SPHERICAL, HEMISPHERICAL, CURVED and their INV counterparts).

QList< RLine > RHatchData::getSegments(const RLine &line) const

const protected

bool RHatchData::addWindingNumber(const int *edgeIndices, int count, double x, double y, int &windingNumber) const

const private

Accumulates the winding number contribution of the given range of edges, using the same scanline rules as QPainterPath::contains.

Returns: False if the point is too close to one of the edges to be classified reliably from the flattened boundary.

bool RHatchData::isPointInBoundary(double x, double y) const

const private

Returns: True if the given point is inside the hatch boundary.

Equivalent to boundaryPath.contains(QPointF(x, y)) but based on the flattened, indexed boundary maintained by updateBoundaryPointCache(). Points which are too close to the boundary for the flattened representation to decide are handed to QPainterPath::contains.

void RHatchData::updateBoundaryBoxes() const

const private

Updates the cached bounding boxes of all boundary shapes.

The intersection code applies the same test but recalculates the bounding box of the shape for every single call. Since one hatch typically intersects every boundary element with hundreds of pattern lines, the bounding boxes are calculated once here instead.

void RHatchData::updateBoundaryPointCache() const

const private

Updates the flattened representation of the boundary path which is used by isPointInBoundary().

The boundary is flattened into line segments once and the segments are sorted into horizontal bands. Testing a point then only has to look at the few edges which cross the band the point is in, instead of at every element of the boundary path.

double RHatchData::angle

private

bool RHatchData::autoRegen

private

QList<QList<QSharedPointer<RShape> > > RHatchData::boundary

private

Hatch boundary, ordered by loops, in strictly defined order.

int RHatchData::boundaryBandCount

private

QVector<int> RHatchData::boundaryBandEdges

private

double RHatchData::boundaryBandHeight

private

QVector<int> RHatchData::boundaryBandStart

private

QVector<double> RHatchData::boundaryBoxes

private

Bounding box of every boundary shape, grown by the same tolerance the intersection code uses.

Cached to avoid recalculating the bounding box of every boundary element for every single hatch pattern line.

bool RHatchData::boundaryBoxesValid

private

QVector<qint8> RHatchData::boundaryEdgeDirs

private

QVector<double> RHatchData::boundaryEdges

private

Flattened boundary (boundaryPath), used to determine whether a point is inside the hatch much faster than QPainterPath::contains can.

Four coordinates per edge (x1,y1,x2,y2 with y1<y2), the edges sorted into horizontal bands (CSR style: bandStart indexes into bandEdges).

double RHatchData::boundaryFlatteningError

private

QVector<int> RHatchData::boundaryLongEdges

private

double RHatchData::boundaryMaxX

private

double RHatchData::boundaryMaxY

private

double RHatchData::boundaryMinX

private

double RHatchData::boundaryMinY

private

RPainterPath RHatchData::boundaryPath

private

bool RHatchData::boundaryPointCacheValid

private

bool RHatchData::dirty

private

bool RHatchData::gotDraft

private

double RHatchData::gotPixelSizeHint

private

double RHatchData::gradientAngle

private

RColor RHatchData::gradientColor1

private

RColor RHatchData::gradientColor2

private

QString RHatchData::gradientName

private

Gradient fill data (DXF/DWG compatible).

An empty gradient name means this hatch is not a gradient fill.

bool RHatchData::gradientOneColorMode

private

double RHatchData::gradientShift

private

double RHatchData::gradientTint

private

RVector RHatchData::originPoint

private

QList<RPainterPath> RHatchData::painterPaths

private

RPattern RHatchData::pattern

private

Custom pattern loaded from DXF file, not LIN file.

Pattern is stored independent of pattern origin point.

QString RHatchData::patternName

private

double RHatchData::scaleFactor

private

bool RHatchData::solid

private

int RHatchData::transparency

private

bool RHatchData::winding

private

static RHatchProxy * RHatchData::hatchProxy = NULL

static private

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD.

friend class RHatchEntity

private