24 : QPaintEngine( QPaintEngine::AllFeatures )
25 , mPaintDevice( dxfDevice ), mDxf( dxf )
46 return QPaintEngine::User;
51 Q_UNUSED( r ); Q_UNUSED( pm ); Q_UNUSED( sr );
56 if ( state.state() & QPaintEngine::DirtyTransform )
58 mTransform = state.transform();
60 if ( state.state() & QPaintEngine::DirtyPen )
64 if ( state.state() & QPaintEngine::DirtyBrush )
66 mBrush = state.brush();
73 if ( !mDxf || !mPaintDevice )
79 polygon[0].resize( pointCount );
82 for (
int i = 0; i < pointCount; ++i )
84 polyline[i] = toDxfCoordinates( points[i] );
87 if ( mode == QPaintEngine::PolylineMode )
89 mDxf->
writePolyline( polyline, mLayer,
"CONTINUOUS", mPen.color(), currentWidth(), true );
93 mDxf->
writePolygon( polygon, mLayer,
"SOLID", mBrush.color() );
99 if ( !mDxf || !mPaintDevice || !rects || mBrush.style() == Qt::NoBrush )
104 for (
int i = 0; i < rectCount; ++i )
106 double left = rects[i].left();
107 double right = rects[i].right();
108 double top = rects[i].top();
109 double bottom = rects[i].bottom();
110 QgsPoint pt1 = toDxfCoordinates( QPointF( left, bottom ) );
111 QgsPoint pt2 = toDxfCoordinates( QPointF( right, bottom ) );
112 QgsPoint pt3 = toDxfCoordinates( QPointF( left, top ) );
113 QgsPoint pt4 = toDxfCoordinates( QPointF( right, top ) );
114 mDxf->
writeSolid( mLayer, mBrush.color(), pt1, pt2, pt3, pt4 );
120 int pathLength = path.elementCount();
121 for (
int i = 0; i < pathLength; ++i )
123 const QPainterPath::Element& pathElem = path.elementAt( i );
124 if ( pathElem.type == QPainterPath::MoveToElement )
126 moveTo( pathElem.x, pathElem.y );
128 else if ( pathElem.type == QPainterPath::LineToElement )
130 lineTo( pathElem.x, pathElem.y );
132 else if ( pathElem.type == QPainterPath::CurveToElement )
134 curveTo( pathElem.x, pathElem.y );
136 else if ( pathElem.type == QPainterPath::CurveToDataElement )
138 mCurrentCurve.append( QPointF( pathElem.x, pathElem.y ) );
145 void QgsDxfPaintEngine::moveTo(
double dx,
double dy )
149 mCurrentPolygon.append( QPointF( dx, dy ) );
152 void QgsDxfPaintEngine::lineTo(
double dx,
double dy )
155 mCurrentPolygon.append( QPointF( dx, dy ) );
158 void QgsDxfPaintEngine::curveTo(
double dx,
double dy )
161 if ( mCurrentPolygon.size() > 0 )
163 mCurrentCurve.append( mCurrentPolygon.last() );
165 mCurrentCurve.append( QPointF( dx, dy ) );
168 void QgsDxfPaintEngine::endPolygon()
170 if ( mCurrentPolygon.size() > 1 )
172 if ( mPen.style() != Qt::NoPen )
173 drawPolygon( mCurrentPolygon.constData(), mCurrentPolygon.size(), QPaintEngine::PolylineMode );
174 if ( mBrush.style() != Qt::NoBrush )
175 drawPolygon( mCurrentPolygon.constData(), mCurrentPolygon.size(), QPaintEngine::OddEvenMode );
177 mCurrentPolygon.clear();
180 void QgsDxfPaintEngine::endCurve()
182 if ( mCurrentCurve.size() < 1 )
186 if ( mCurrentPolygon.size() < 1 )
188 mCurrentCurve.clear();
193 if ( mCurrentCurve.size() >= 3 )
196 for (
int i = 1; i < 20; ++i )
198 mCurrentPolygon.append( bezierPoint( mCurrentCurve, t ) );
202 else if ( mCurrentCurve.size() == 2 )
204 mCurrentPolygon.append( mCurrentCurve.at( 1 ) );
206 mCurrentCurve.clear();
211 if ( !mDxf || !mPaintDevice || !lines || mPen.style() == Qt::NoPen )
216 for (
int i = 0; i < lineCount; ++i )
218 QgsPoint pt1 = toDxfCoordinates( lines[i].p1() );
219 QgsPoint pt2 = toDxfCoordinates( lines[i].p2() );
220 mDxf->
writeLine( pt1, pt2, mLayer,
"CONTINUOUS", mPen.color(), currentWidth() );
224 QgsPoint QgsDxfPaintEngine::toDxfCoordinates(
const QPointF& pt )
const
226 if ( !mPaintDevice || !mDxf )
231 QPointF dxfPt = mPaintDevice->
dxfCoordinates( mTransform.map( pt ) ) + mShift;
232 return QgsPoint( dxfPt.x(), dxfPt.y() );
236 double QgsDxfPaintEngine::currentWidth()
const
246 QPointF QgsDxfPaintEngine::bezierPoint(
const QList<QPointF>& controlPolygon,
double t )
250 int cPolySize = controlPolygon.size();
253 QList<QPointF>::const_iterator it = controlPolygon.constBegin();
255 for ( ; it != controlPolygon.constEnd(); ++it )
257 bPoly = bernsteinPoly( cPolySize - 1, i, t );
258 x += ( it->x() * bPoly );
259 y += ( it->y() * bPoly );
263 return QPointF( x, y );
266 double QgsDxfPaintEngine::bernsteinPoly(
int n,
int i,
double t )
273 return lower( n, i )*power( t, i )*power(( 1 - t ), ( n - i ) );
276 int QgsDxfPaintEngine::lower(
int n,
int i )
278 if ( i >= 0 && i <= n )
280 return faculty( n ) / ( faculty( i )*faculty( n - i ) );
288 double QgsDxfPaintEngine::power(
double a,
int b )
295 for (
int i = 2; i <= qAbs((
double )b ); i++ )
309 int QgsDxfPaintEngine::faculty(
int n )
318 if ( n == 0 || n == 1 )
323 for ( i = n - 1; i >= 2; i-- )