418 changes: 195 additions & 223 deletions src/core/qgsdxfexport.cpp

Large diffs are not rendered by default.

47 changes: 27 additions & 20 deletions src/core/qgsdxfexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
#include "qgssymbolv2.h"
#include <QColor>
#include <QList>
#include <QTextStream>

class QgsMapLayer;
class QgsPoint;
class QgsSymbolLayerV2;
class QIODevice;
class QTextStream;

class QgsDxfExport
{
Expand Down Expand Up @@ -57,6 +57,14 @@ class QgsDxfExport
//get closest entry in dxf palette
static int closestColorMatch( QRgb pixel );

void writeGroup( int code, int i );
void writeGroup( int code, double d );
void writeGroup( int code, const QString& s );
void writeGroupCode( int code );
void writeInt( int i );
void writeDouble( double d );
void writeString( const QString& s );

private:

QList< QgsMapLayer* > mLayers;
Expand All @@ -65,6 +73,8 @@ class QgsDxfExport
SymbologyExport mSymbologyExport;
QGis::UnitType mMapUnits;

QTextStream mTextStream;

QVector<QRgb> mDxfColorPalette;

static double mDxfColors[][3];
Expand All @@ -77,22 +87,22 @@ class QgsDxfExport
QHash< const QgsSymbolLayerV2*, QString > mPointSymbolBlocks; //reference to point symbol blocks

//AC1009
void writeHeader( QTextStream& stream );
void writeTables( QTextStream& stream );
void writeBlocks( QTextStream& stream );
void writeEntities( QTextStream& stream );
void writeEntitiesSymbolLevels( QTextStream& stream, QgsVectorLayer* layer );
void writeEndFile( QTextStream& stream );

void startSection( QTextStream& stream );
void endSection( QTextStream& stream );

void writePoint( QTextStream& stream, const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
void writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
void writeHeader();
void writeTables();
void writeBlocks();
void writeEntities();
void writeEntitiesSymbolLevels( QgsVectorLayer* layer );
void writeEndFile();

void startSection();
void endSection();

void writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
void writePolyline( const QgsPolyline& line, const QString& layer, const QString& lineStyleName, int color,
double width = -1, bool polygon = false );
void writeVertex( QTextStream& stream, const QgsPoint& pt, const QString& layer );
void writeSymbolLayerLinestyle( QTextStream& stream, const QgsSymbolLayerV2* symbolLayer );
void writeLinestyle( QTextStream& stream, const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );
void writeVertex( const QgsPoint& pt, const QString& layer );
void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );
void writeLinestyle( const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );

//AC1018
void writeHeaderAC1018( QTextStream& stream );
Expand All @@ -108,7 +118,7 @@ class QgsDxfExport

QgsRectangle dxfExtent() const;

void addFeature( const QgsFeature& fet, QTextStream& stream, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
void addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
double scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits ) const;

//returns dxf palette index from symbol layer color
Expand All @@ -126,9 +136,6 @@ class QgsDxfExport
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
QList<QgsSymbolLayerV2*> symbolLayers();
static int nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers );



};

#endif // QGSDXFEXPORT_H
28 changes: 8 additions & 20 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
}
}

void QgsSimpleMarkerSymbolLayerV2::writeDxf( QTextStream& str, double mmMapUnitScaleFactor ) const
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const
{
double size = mSize;
if ( mSizeUnit == QgsSymbolV2::MM )
Expand All @@ -712,26 +712,14 @@ void QgsSimpleMarkerSymbolLayerV2::writeDxf( QTextStream& str, double mmMapUnitS

if ( mName == "circle" )
{
str << " 0\n";
str << "CIRCLE\n";
str << " 8\n";
str << "0\n";
//todo: linetype in group 6. Needs to be inserted into line table first

//color in group 62
str << " 62\n";
e.writeGroup( 0, "CIRCLE" );
e.writeGroup( 8, 0 );
int colorIndex = QgsDxfExport::closestColorMatch( mBrush.color().rgb() );
str << QString( "%1\n" ).arg( colorIndex );

//x/y/z center
str << " 10\n";
str << QString( "%1\n" ).arg( halfSize );
str << " 20\n";
str << QString( "%1\n" ).arg( halfSize );
str << " 30\n";
str << QString( "%1\n" ).arg( halfSize );
str << " 40\n";
str << QString( "%1\n" ).arg( halfSize );
e.writeGroup( 62, colorIndex );
e.writeGroup( 10, halfSize );
e.writeGroup( 20, halfSize );
e.writeGroup( 30, 0.0 );
e.writeGroup( 40, halfSize );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsmarkersymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }

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

protected:

Expand Down
3 changes: 2 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class QPainter;
class QSize;
class QPolygonF;

class QgsDxfExport;
class QgsExpression;
class QgsRenderContext;

Expand Down Expand Up @@ -92,7 +93,7 @@ class CORE_EXPORT QgsSymbolLayerV2
virtual void removeDataDefinedProperty( const QString& property );
virtual void removeDataDefinedProperties();

virtual void writeDxf( QTextStream& str, double mmMapUnitScaleFactor ) const { Q_UNUSED( str ); Q_UNUSED( mmMapUnitScaleFactor ); }
virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); }

protected:
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsdxfexportdialogbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>DXF export</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
Expand All @@ -29,7 +29,7 @@
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
Expand Down