25 , mPaintDevice( dxfDevice )
47 return QPaintEngine::User;
59 if ( state.
state() & QPaintEngine::DirtyTransform )
62 if ( state.
state() & QPaintEngine::DirtyPen )
65 if ( state.
state() & QPaintEngine::DirtyBrush )
66 mBrush = state.
brush();
69 void QgsDxfPaintEngine::setRing(
QgsPolyline &polyline,
const QPointF *points,
int pointCount )
71 polyline.
resize( pointCount );
72 for (
int i = 0; i < pointCount; ++i )
73 polyline[i] = toDxfCoordinates( points[i] );
79 if ( !mDxf || !mPaintDevice )
83 setRing( polygon[0], points, pointCount );
85 if ( mode == QPaintEngine::PolylineMode )
92 if ( mBrush.
style() != Qt::NoBrush )
100 for (
int i = 0; i < pathLength; ++i )
103 if ( pathElem.type == QPainterPath::MoveToElement )
105 moveTo( pathElem.x, pathElem.y );
107 else if ( pathElem.type == QPainterPath::LineToElement )
109 lineTo( pathElem.x, pathElem.y );
111 else if ( pathElem.type == QPainterPath::CurveToElement )
113 curveTo( pathElem.x, pathElem.y );
115 else if ( pathElem.type == QPainterPath::CurveToDataElement )
123 if ( mPolygon.
size() > 0 && mBrush.
style() != Qt::NoBrush )
129 void QgsDxfPaintEngine::moveTo(
double dx,
double dy )
136 void QgsDxfPaintEngine::lineTo(
double dx,
double dy )
142 void QgsDxfPaintEngine::curveTo(
double dx,
double dy )
145 if ( mCurrentPolygon.
size() > 0 )
146 mCurrentCurve.
append( mCurrentPolygon.
last() );
151 void QgsDxfPaintEngine::endPolygon()
153 if ( mCurrentPolygon.
size() > 1 )
155 if ( mPen.
style() != Qt::NoPen )
159 setRing( mPolygon[ mPolygon.
size() - 1 ], mCurrentPolygon.
constData(), mCurrentPolygon.
size() );
161 mCurrentPolygon.
clear();
164 void QgsDxfPaintEngine::endCurve()
166 if ( mCurrentCurve.
size() < 1 )
169 if ( mCurrentPolygon.
size() < 1 )
171 mCurrentCurve.
clear();
175 if ( mCurrentCurve.
size() >= 3 )
178 for (
int i = 1; i <= 20; ++i )
180 mCurrentPolygon.
append( bezierPoint( mCurrentCurve, t ) );
184 else if ( mCurrentCurve.
size() == 2 )
186 mCurrentPolygon.
append( mCurrentCurve.
at( 1 ) );
188 mCurrentCurve.
clear();
193 if ( !mDxf || !mPaintDevice || !lines || mPen.
style() == Qt::NoPen )
196 for (
int i = 0; i < lineCount; ++i )
198 QgsPoint pt1 = toDxfCoordinates( lines[i].p1() );
199 QgsPoint pt2 = toDxfCoordinates( lines[i].p2() );
200 mDxf->
writeLine( pt1, pt2, mLayer,
"CONTINUOUS", mPen.
color(), currentWidth() );
204 QgsPoint QgsDxfPaintEngine::toDxfCoordinates(
const QPointF& pt )
const
206 if ( !mPaintDevice || !mDxf )
210 return QgsPoint( dxfPt.x(), dxfPt.y() );
214 double QgsDxfPaintEngine::currentWidth()
const
226 int cPolySize = controlPolygon.
size();
231 for ( ; it != controlPolygon.
constEnd(); ++it )
233 bPoly = bernsteinPoly( cPolySize - 1, i, t );
234 x += ( it->x() * bPoly );
235 y += ( it->y() * bPoly );
242 double QgsDxfPaintEngine::bernsteinPoly(
int n,
int i,
double t )
247 return lower( n, i )*power( t, i )*power(( 1 - t ), ( n - i ) );
250 int QgsDxfPaintEngine::lower(
int n,
int i )
252 if ( i >= 0 && i <= n )
254 return faculty( n ) / ( faculty( i )*faculty( n - i ) );
262 double QgsDxfPaintEngine::power(
double a,
int b )
268 for (
int i = 2; i <= qAbs((
double )b ); i++ )
277 int QgsDxfPaintEngine::faculty(
int n )
285 if ( n == 0 || n == 1 )
288 for ( i = n - 1; i >= 2; i-- )
Qt::PenStyle style() const
A paint device for drawing into dxf files.
void append(const T &value)
Qt::BrushStyle style() const
void writePolygon(const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color)
Draw dxf polygon (HATCH)
QPointF dxfCoordinates(const QPointF &pt) const
Converts a point from device coordinates to dxf coordinates.
const T & at(int i) const
void drawPath(const QPainterPath &path) override
const QPainterPath::Element & elementAt(int index) const
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)
double widthScaleFactor() const
Returns scale factor for line width.
QgsDxfPaintEngine(const QgsDxfPaintDevice *dxfDevice, QgsDxfExport *dxf)
const T * constData() const
void writeLine(const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width=-1)
Write line (as a polyline)
A class to represent a point.
void drawLines(const QLineF *lines, int lineCount) override
void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override
QPaintEngine::Type type() const override
bool begin(QPaintDevice *pdev) override
const_iterator constEnd() const
const_iterator constBegin() const
QPaintEngine::DirtyFlags state() const
void writePolyline(const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width=-1)
Draw dxf primitives (LWPOLYLINE)