25 , mPaintDevice( dxfDevice )
48 return QPaintEngine::User;
60 if ( state.
state() & QPaintEngine::DirtyTransform )
63 if ( state.
state() & QPaintEngine::DirtyPen )
66 if ( state.
state() & QPaintEngine::DirtyBrush )
67 mBrush = state.
brush();
69 if ( state.
state() & QPaintEngine::DirtyOpacity )
78 for (
int i = 0; i < pointCount; ++i )
79 polyline.
append( toDxfCoordinates( points[i] ) );
85 if ( !mDxf || !mPaintDevice )
90 setRing( polygon.
last(), points, pointCount );
92 if ( mode == QPaintEngine::PolylineMode )
95 mDxf->
writePolyline( polygon.
at( 0 ), mLayer,
"CONTINUOUS", penColor(), currentWidth() );
99 if ( mBrush.
style() != Qt::NoBrush )
100 mDxf->
writePolygon( polygon, mLayer,
"SOLID", brushColor() );
107 for (
int i = 0; i < pathLength; ++i )
110 if ( pathElem.type == QPainterPath::MoveToElement )
112 moveTo( pathElem.x, pathElem.y );
114 else if ( pathElem.type == QPainterPath::LineToElement )
116 lineTo( pathElem.x, pathElem.y );
118 else if ( pathElem.type == QPainterPath::CurveToElement )
120 curveTo( pathElem.x, pathElem.y );
122 else if ( pathElem.type == QPainterPath::CurveToDataElement )
130 if ( !mPolygon.
isEmpty() && mBrush.
style() != Qt::NoBrush )
131 mDxf->
writePolygon( mPolygon, mLayer,
"SOLID", brushColor() );
136 void QgsDxfPaintEngine::moveTo(
double dx,
double dy )
143 void QgsDxfPaintEngine::lineTo(
double dx,
double dy )
149 void QgsDxfPaintEngine::curveTo(
double dx,
double dy )
152 if ( !mCurrentPolygon.
isEmpty() )
153 mCurrentCurve.
append( mCurrentPolygon.
last() );
158 void QgsDxfPaintEngine::endPolygon()
160 if ( mCurrentPolygon.
size() > 1 )
162 if ( mPen.
style() != Qt::NoPen )
168 mCurrentPolygon.
clear();
171 void QgsDxfPaintEngine::endCurve()
173 if ( mCurrentCurve.
size() < 1 )
176 if ( mCurrentPolygon.
size() < 1 )
178 mCurrentCurve.
clear();
182 if ( mCurrentCurve.
size() >= 3 )
185 for (
int i = 1; i <= 20; ++i )
187 mCurrentPolygon.
append( bezierPoint( mCurrentCurve, t ) );
191 else if ( mCurrentCurve.
size() == 2 )
193 mCurrentPolygon.
append( mCurrentCurve.
at( 1 ) );
195 mCurrentCurve.
clear();
200 if ( !mDxf || !mPaintDevice || !lines || mPen.
style() == Qt::NoPen )
203 for (
int i = 0; i < lineCount; ++i )
205 mDxf->
writeLine( toDxfCoordinates( lines[i].p1() ),
206 toDxfCoordinates( lines[i].p2() ),
207 mLayer,
"CONTINUOUS", penColor(), currentWidth() );
213 if ( !mPaintDevice || !mDxf )
221 double QgsDxfPaintEngine::currentWidth()
const 233 int cPolySize = controlPolygon.
size();
238 for ( ; it != controlPolygon.
constEnd(); ++it )
240 bPoly = bernsteinPoly( cPolySize - 1, i, t );
241 x += ( it->x() * bPoly );
242 y += ( it->y() * bPoly );
249 double QgsDxfPaintEngine::bernsteinPoly(
int n,
int i,
double t )
254 return lower( n, i )*power( t, i )*power(( 1 - t ), ( n - i ) );
257 int QgsDxfPaintEngine::lower(
int n,
int i )
259 if ( i >= 0 && i <= n )
261 return faculty( n ) / ( faculty( i )*faculty( n - i ) );
269 double QgsDxfPaintEngine::power(
double a,
int b )
275 for (
int i = 2; i <= qAbs( static_cast< double >( b ) ); i++ )
284 int QgsDxfPaintEngine::faculty(
int n )
292 if ( n == 0 || n == 1 )
295 for ( i = n - 1; i >= 2; i-- )
301 QColor QgsDxfPaintEngine::penColor()
const 312 QColor QgsDxfPaintEngine::brushColor()
const 316 return mBrush.
color();
Qt::PenStyle style() const
Q_DECL_DEPRECATED void writeLine(const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Write line (as a polyline)
A paint device for drawing into dxf files.
void append(const T &value)
Qt::BrushStyle style() const
const T & at(int i) const
void drawPath(const QPainterPath &path) override
const QPainterPath::Element & elementAt(int index) const
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
void updateState(const QPaintEngineState &state) override
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override
const QColor & color() const
void append(const T &value)
Point geometry type, with support for z-dimension and m-values.
QgsDxfPaintEngine(const QgsDxfPaintDevice *dxfDevice, QgsDxfExport *dxf)
const T * constData() const
Q_DECL_DEPRECATED void writePolyline(const QgsPolyline &line, const QString &layer, const QString &lineStyleName, const QColor &color, double width=-1)
Draw dxf primitives (LWPOLYLINE)
void drawLines(const QLineF *lines, int lineCount) override
QPointF dxfCoordinates(QPointF pt) const
Converts a point from device coordinates to dxf coordinates.
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
Q_DECL_DEPRECATED void writePolygon(const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, const QColor &color)
Draw dxf filled polygon (HATCH)
QPaintEngine::Type type() const override
void setAlphaF(qreal alpha)
bool begin(QPaintDevice *pdev) override
const_iterator constEnd() const
const_iterator constBegin() const
double widthScaleFactor() const
Returns scale factor for line width.
QPaintEngine::DirtyFlags state() const
QList< QgsPointV2 > QgsPointSequenceV2