Skip to content
Permalink
Browse files
More symbology updates for dxf
  • Loading branch information
mhugent committed Sep 15, 2013
1 parent 32221fd commit dc62376fd2e25b7dceaf511077f699053492e5f1
Showing with 109 additions and 6 deletions.
  1. +90 −2 src/core/qgsdxfexport.cpp
  2. +19 −4 src/core/qgsdxfexport.h
@@ -103,6 +103,11 @@ void QgsDxfExport::writeHeader( QTextStream& stream )
stream << " 40\n";
stream << "1\n";
endSection( stream );
//PSLTSCALE
stream << " 9\n";
stream << "$PSLTSCALE\n";
stream << " 70\n";
stream << "0\n";
}

void QgsDxfExport::writeTables( QTextStream& stream )
@@ -186,19 +191,50 @@ void QgsDxfExport::writeEntities( QTextStream& stream )
QgsFeature fet;
while ( featureIt.nextFeature( fet ) )
{
if ( mSymbologyExport == NoSymbology )
{
addFeature( fet, stream, vl->name(), 0 ); //no symbology at all
}
else
{
if ( !renderer )
{
continue;
}
QgsSymbolV2List symbolList = renderer->symbolsForFeature( fet );
if ( symbolList.size() < 1 )
{
continue;
}

//take first symbollayer from first symbol
QgsSymbolV2* s = symbolList.first();
if ( !s || s->symbolLayerCount() < 1 )
{
continue;
}
addFeature( fet, stream, vl->name(), s->symbolLayer( 0 ) );
}
#if 0
//get geometry and write it. Todo: consider symbolisation
QgsGeometry* geom = fet.geometry();
if ( geom )
{
//try with line first
writePolyline( stream, geom->asPolyline(), vl->name() );
}
#endif //0
}
}

endSection( stream );
}

void QgsDxfExport::writeEntitiesSymbolLevels( QTextStream& stream )
{
//todo....
}

void QgsDxfExport::writeEndFile( QTextStream& stream )
{
endSection( stream );
@@ -216,17 +252,26 @@ void QgsDxfExport::endSection( QTextStream& stream )
stream << "ENDSEC\n";
}

void QgsDxfExport::writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, bool closed )
void QgsDxfExport::writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, int color,
double width, bool closed )
{
stream << " 0\n";
stream << "POLYLINE\n";
stream << " 8\n";
stream << layer << "\n";
stream << " 6\n";
stream << "CONTINUOUS\n"; //todo: reference to linetype here
stream << " 62\n";
stream << color << "\n";
stream << " 66\n";
stream << " 1\n";
stream << "1\n";
stream << " 70\n";
int type = closed ? 32 : 0;
stream << type << "\n";
stream << " 40\n";
stream << width << "\n";
stream << " 41\n";
stream << width << "\n";

QgsPolyline::const_iterator lineIt = line.constBegin();
for ( ; lineIt != line.constEnd(); ++lineIt )
@@ -270,3 +315,46 @@ QgsRectangle QgsDxfExport::dxfExtent() const
}
return extent;
}

void QgsDxfExport::addFeature( const QgsFeature& fet, QTextStream& stream, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
{
QgsGeometry* geom = fet.geometry();
if ( geom )
{
//get color from symbollayer
int c = colorFromSymbolLayer( symbolLayer );
//get width from symbollayer
double width = widthFromSymbolLayer( symbolLayer );
writePolyline( stream, geom->asPolyline(), layer, c, width );
}
}

double QgsDxfExport::scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits ) const
{
if ( symbolUnits == QgsSymbolV2::MapUnit )
{
return 1.0;
}

//symbology in mm
value *= mSymbologyScaleDenominator / 1000;
if ( mapUnits == QGis::Feet )
{
value *= 0.3048;
}
else if ( mapUnits == QGis::Degrees )
{
value /= 111120;
}
return value;
}

int QgsDxfExport::colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
{
return 5; //todo...
}

double QgsDxfExport::widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer )
{
return 50; //todo...
}
@@ -19,10 +19,12 @@
#define QGSDXFEXPORT_H

#include "qgsgeometry.h"
#include "qgssymbolv2.h"
#include <QList>

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

@@ -42,27 +44,40 @@ class QgsDxfExport
void addLayers( QList< QgsMapLayer* >& layers ) { mLayers = layers; }
int writeToFile( QIODevice* d, SymbologyExport s = SymbolLayerSymbology ); //maybe add progress dialog? //other parameters (e.g. scale, dpi)?

void setSymbologyScaleDenominator( double d ) { mSymbologyScaleDenominator = d; }
double symbologyScaleDenominator() const { return mSymbologyScaleDenominator; }

void setSymbologyExport( SymbologyExport e ) { mSymbologyExport = e; }
SymbologyExport symbologyExport() const { return mSymbologyExport; }

private:

QList< QgsMapLayer* > mLayers;
/**Scale for symbology export (used if symbols units are mm)*/
double mSymbologyScaleDenominator;
SymbologyExport mSymbologyExport;

void writeHeader( QTextStream& stream );
void writeTables( QTextStream& stream );
void writeEntities( QTextStream& stream );
void writeEntitiesSymbolLevels( QTextStream& stream );
void writeEndFile( QTextStream& stream );

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

void writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, bool closed = false );
void writePolyline( QTextStream& stream, const QgsPolyline& line, const QString& layer, int color,
double width = -1, bool closed = false );
void writeVertex( QTextStream& stream, const QgsPoint& pt, const QString& layer );

QgsRectangle dxfExtent() const;

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

//Option: export feature once / multiple export (considering symbol layers / symbol levels)
//returns dxf palette index from symbol layer color
int colorFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
double widthFromSymbolLayer( const QgsSymbolLayerV2* symbolLayer );
};

#endif // QGSDXFEXPORT_H

0 comments on commit dc62376

Please sign in to comment.