Skip to content
Permalink
Browse files

Start implementation of QgsDxfPaintDevice / Engine to export svg mark…

…ers to dxf
  • Loading branch information
mhugent committed Nov 22, 2013
1 parent 5bd7083 commit 78fbee39dbc3b818456ad9ecafb5e01c1919a5c8
@@ -160,6 +160,9 @@ SET(QGIS_CORE_SRCS
composer/qgscomposerhtml.cpp
composer/qgscomposermultiframe.cpp
composer/qgscomposition.cpp

dxf/qgsdxfpaintdevice.cpp
dxf/qgsdxfpaintengine.cpp

pal/costcalculator.cpp
pal/feature.cpp
@@ -549,6 +552,7 @@ ENDIF (QT_MOBILITY_LOCATION_FOUND)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
composer
dxf
pal
raster
renderer
@@ -0,0 +1,84 @@
/***************************************************************************
qgsdxpaintdevice.cpp
--------------------
begin : November 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdxfpaintdevice.h"

QgsDxfPaintDevice::QgsDxfPaintDevice( QgsDxfExport* dxf ): QPaintDevice(), mPaintEngine( 0 )
{
mPaintEngine = new QgsDxfPaintEngine( this, dxf );
}

QgsDxfPaintDevice::~QgsDxfPaintDevice()
{
delete mPaintEngine;
}

QPaintEngine* QgsDxfPaintDevice::paintEngine() const
{
return mPaintEngine;
}

int QgsDxfPaintDevice::metric( PaintDeviceMetric metric ) const
{
switch ( metric )
{
case QPaintDevice::PdmWidth:
return mDrawingSize.width();
case QPaintDevice::PdmHeight:
return mDrawingSize.height();
case QPaintDevice::PdmWidthMM:
return mDrawingSize.width();
case QPaintDevice::PdmHeightMM:
return mDrawingSize.height();
case QPaintDevice::PdmNumColors:
return INT_MAX;
case QPaintDevice::PdmDepth:
return 32;
case QPaintDevice::PdmDpiX:
case QPaintDevice::PdmDpiY:
case QPaintDevice::PdmPhysicalDpiX:
case QPaintDevice::PdmPhysicalDpiY:
return 96;
}
return 0;
}

double QgsDxfPaintDevice::widthScaleFactor() const
{
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
{
return 1.0;
}

double widthFactor = mRectangle.width() / mDrawingSize.width();
double heightFactor = mRectangle.height() / mDrawingSize.height();
return ( widthFactor + heightFactor ) / 2.0;
}

QPointF QgsDxfPaintDevice::dxfCoordinates( const QPointF& pt )
{
if ( !mDrawingSize.isValid() || mRectangle.isEmpty() )
{
return QPointF( pt.x(), pt.y() );
}

double x = mRectangle.left() + pt.x() * ( mRectangle.width() / mDrawingSize.width() );
double y = mRectangle.bottom() - pt.y() * ( mRectangle.height() / mDrawingSize.height() );
return QPointF( x, y );
}


@@ -0,0 +1,59 @@
/***************************************************************************
qgsdxpaintdevice.h
------------------
begin : November 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDXFPAINTDEVICE_H
#define QGSDXFPAINTDEVICE_H

#include <QPaintDevice>
#include "qgsdxfpaintengine.h"

class QgsDxfExport;
class QPaintEngine;

/**A paint device for drawing into dxf files*/

class QgsDxfPaintDevice: public QPaintDevice
{
public:
QgsDxfPaintDevice( QgsDxfExport* dxf );
~QgsDxfPaintDevice();

QPaintEngine* paintEngine() const;

void setDrawingSize( const QSizeF& size ) { mDrawingSize = size; }
void setOutputSize( const QRectF& r ) { mRectangle = r; }

/**Returns scale factor for line width*/
double widthScaleFactor() const;

/**Converts a point from device coordinates to dxf coordinates*/
QPointF dxfCoordinates( const QPointF& pt );

/*int height() const { return mDrawingSize.height(); }
int width() const { return mDrawingSize.width(); }*/

int metric( PaintDeviceMetric metric ) const;


private:
QgsDxfPaintEngine* mPaintEngine;

QSizeF mDrawingSize; //size (in source coordinates)
QRectF mRectangle; //size (in dxf coordinates)
};

#endif // QGSDXFPAINTDEVICE_H
@@ -0,0 +1,89 @@
/***************************************************************************
qgsdxpaintengine.cpp
--------------------
begin : November 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsdxfpaintengine.h"
#include "qgsdxfexport.h"
#include "qgslogger.h"

QgsDxfPaintEngine::QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf ): QPaintEngine( QPaintEngine::AllFeatures /*QPaintEngine::PainterPaths | QPaintEngine::PaintOutsidePaintEvent*/ )
, mPaintDevice( dxfDevice ), mDxf( dxf )
{

}

QgsDxfPaintEngine::~QgsDxfPaintEngine()
{

}

bool QgsDxfPaintEngine::begin( QPaintDevice* pdev )
{
Q_UNUSED( pdev );
return true;
}

bool QgsDxfPaintEngine::end()
{
return true;
}

QPaintEngine::Type QgsDxfPaintEngine::type() const
{
return QPaintEngine::User;
}

void QgsDxfPaintEngine::drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr )
{
Q_UNUSED( r ); Q_UNUSED( pm ); Q_UNUSED( sr );
}

void QgsDxfPaintEngine::updateState( const QPaintEngineState& state )
{
if ( state.state() | QPaintEngine::DirtyTransform )
{
mTransform = state.transform();
}
if ( state.state() | QPaintEngine::DirtyPen )
{
mPen = state.pen();
}
}

void QgsDxfPaintEngine::drawPolygon( const QPointF* points, int pointCount, PolygonDrawMode mode )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing polygon*********************" );
}

void QgsDxfPaintEngine::drawRects( const QRectF * rects, int rectCount )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing rects*********************" );
}

void QgsDxfPaintEngine::drawEllipse( const QRectF& rect )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing ellipse*********************" );
}

void QgsDxfPaintEngine::drawPath( const QPainterPath& path )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" );
}

void QgsDxfPaintEngine::drawLines( const QLineF* lines, int lineCount )
{
QgsDebugMsg( "***********************Dxf paint engine: drawing path*********************" );
}
@@ -0,0 +1,54 @@
/***************************************************************************
qgsdxpaintengine.h
------------------
begin : November 2013
copyright : (C) 2013 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSDXFPAINTENGINE_H
#define QGSDXFPAINTENGINE_H

#include <QPaintEngine>

class QgsDxfExport;
class QgsDxfPaintDevice;

class QgsDxfPaintEngine: public QPaintEngine
{
public:
QgsDxfPaintEngine( const QgsDxfPaintDevice* dxfDevice, QgsDxfExport* dxf );
~QgsDxfPaintEngine();

bool begin( QPaintDevice* pdev );
bool end();
QPaintEngine::Type type() const;
void updateState( const QPaintEngineState& state );

void drawPixmap( const QRectF& r, const QPixmap& pm, const QRectF& sr );

void drawPolygon( const QPointF * points, int pointCount, PolygonDrawMode mode );
void drawRects( const QRectF * rects, int rectCount );
void drawEllipse( const QRectF& rect );
void drawPath( const QPainterPath& path );
void drawLines( const QLineF* lines, int lineCount );

private:
const QgsDxfPaintDevice* mPaintDevice;
QgsDxfExport* mDxf;

//painter state information
QTransform mTransform;
QPen mPen;
};

#endif // QGSDXFPAINTENGINE_H
@@ -17,6 +17,7 @@
#include "qgssymbollayerv2utils.h"

#include "qgsdxfexport.h"
#include "qgsdxfpaintdevice.h"
#include "qgsexpression.h"
#include "qgsrendercontext.h"
#include "qgslogger.h"
@@ -1165,6 +1166,25 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
return m;
}

void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const
{
QSvgRenderer r( mPath );
if ( !r.isValid() )
{
return;
}

QgsDxfPaintDevice pd( &e );
pd.setDrawingSize( QSizeF( r.defaultSize() ) );
double size = mSize * mmMapUnitScaleFactor ;
pd.setOutputSize( QRectF( 0, 0, size, size ) );
QPainter p;

p.begin( &pd );
r.render( &p );
p.end();
}

//////////

QgsFontMarkerSymbolLayerV2::QgsFontMarkerSymbolLayerV2( QString fontFamily, QChar chr, double pointSize, QColor color, double angle )
@@ -159,6 +159,8 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const;

protected:
QString mPath;

0 comments on commit 78fbee3

Please sign in to comment.
You can’t perform that action at this time.