Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dxf export: deprecate writeSolid (replaced with writePolygon) and add…
… some doxymentation
  • Loading branch information
jef-n committed Jun 23, 2015
1 parent 38a247f commit 7031cfb
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 108 deletions.
17 changes: 14 additions & 3 deletions python/core/dxf/qgsdxfexport.sip
Expand Up @@ -63,30 +63,41 @@ class QgsDxfExport
void writeGroup( int code, const QgsPoint &p, double z = 0.0, bool skipz = false ) /PyName=writeGroupPoint/;
void writeGroup( QColor color, int exactMatch = 62, int rgbCode = 420, int transparencyCode = 440 );

//! Write handle
int writeHandle( int code = 5, int handle = 0 );

//draw dxf primitives
//! Draw dxf polyline
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );

//! Draw dxf polygon (HATCH)
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );

void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
/** Draw solid
* @deprecated see writePolygon
*/
void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 ) /Deprecated/;

//write line (as a polyline)
//! write line (as a polyline)
void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );

//! Write point
void writePoint( const QString &layer, QColor color, const QgsPoint &pt );

//! Write filled circle (as hatch)
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );

//! Write circle (as polyline)
void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );

//! Write text (TEXT)
void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );

//! Write mtext (MTEXT)
void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );

//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );

};
23 changes: 13 additions & 10 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -3514,16 +3514,19 @@ void QgsDxfExport::writeMText( const QString& layer, const QString& text, const

void QgsDxfExport::writeSolid( const QString& layer, QColor color, const QgsPoint& pt1, const QgsPoint& pt2, const QgsPoint& pt3, const QgsPoint& pt4 )
{
writeGroup( 0, "SOLID" );
writeHandle();
writeGroup( 100, "AcDbEntity" );
writeGroup( 100, "AcDbTrace" );
writeGroup( 8, layer );
writeGroup( color );
writeGroup( 0, pt1 );
writeGroup( 1, pt2 );
writeGroup( 2, pt3 );
writeGroup( 3, pt4 );
// pt1 pt2
// pt3 pt4
int i = 0;
QgsPolygon p( 1 );
p[0].resize( pt3 != pt4 ? 5 : 4 );
p[0][i++] = pt1;
p[0][i++] = pt2;
p[0][i++] = pt4;
if ( p[0].size() == 5 )
p[0][i++] = pt3;
p[0][i] = pt1;

writePolygon( p, layer, "SOLID", color );
}

void QgsDxfExport::writeVertex( const QgsPoint& pt, const QString& layer )
Expand Down
17 changes: 13 additions & 4 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -78,29 +78,38 @@ class CORE_EXPORT QgsDxfExport

int writeHandle( int code = 5, int handle = 0 );

//! draw dxf primitives
//! Draw dxf primitives (LWPOLYLINE)
void writePolyline( const QgsPolyline &line, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );

//! Draw dxf polygon (HATCH)
void writePolygon( const QgsPolygon &polygon, const QString &layer, const QString &hatchPattern, QColor color );

void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );
/** Draw solid
* @deprecated see writePolygon
*/
Q_DECL_DEPRECATED void writeSolid( const QString &layer, QColor color, const QgsPoint &pt1, const QgsPoint &pt2, const QgsPoint &pt3, const QgsPoint &pt4 );

//! write line (as a polyline)
//! Write line (as a polyline)
void writeLine( const QgsPoint &pt1, const QgsPoint &pt2, const QString &layer, const QString &lineStyleName, QColor color, double width = -1 );

//! Write point
void writePoint( const QString &layer, QColor color, const QgsPoint &pt );

//! Write filled circle (as hatch)
void writeFilledCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius );

//! Write circle (as polyline)
void writeCircle( const QString &layer, QColor color, const QgsPoint &pt, double radius, const QString &lineStyleName, double width );

//! Write text (TEXT)
void writeText( const QString &layer, const QString &text, const QgsPoint &pt, double size, double angle, QColor color );

//! Write mtext (MTEXT)
void writeMText( const QString &layer, const QString &text, const QgsPoint &pt, double width, double angle, QColor color );

static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );

//! return cleaned layer name for use in DXF
//! Return cleaned layer name for use in DXF
static QString dxfLayerName( const QString &name );

//! return DXF encoding for Qt encoding
Expand Down
63 changes: 26 additions & 37 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -687,55 +687,44 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
}
else if ( symbolName == "rectangle" )
{
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
QPointF pt3( t.map( QPointF( -halfWidth, halfHeight ) ) );
QPointF pt4( t.map( QPointF( halfWidth, halfHeight ) ) );
QgsPolygon p( 1 );
p[0].resize( 5 );
p[0][0] = t.map( QPointF( -halfWidth, -halfHeight ) );
p[0][1] = t.map( QPointF( halfWidth, -halfHeight ) );
p[0][2] = t.map( QPointF( halfWidth, halfHeight ) );
p[0][3] = t.map( QPointF( -halfWidth, halfHeight ) );
p[0][4] = p[0][0];
if ( mBrush.style() != Qt::NoBrush )
e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 );
QgsPolyline line( 5 );
line[0] = pt1;
line[1] = pt2;
line[2] = pt3;
line[3] = pt4;
line[4] = pt1;
e.writePolygon( p, layerName, "SOLID", fc );
if ( mPen.style() != Qt::NoPen )
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
e.writePolyline( p[0], layerName, "CONTINUOUS", oc, outlineWidth );
return true;
}
else if ( symbolName == "cross" && mPen.style() != Qt::NoPen )
{
QgsPolyline line1( 2 );
QPointF pt1( t.map( QPointF( -halfWidth, 0 ) ) );
QPointF pt2( t.map( QPointF( halfWidth, 0 ) ) );
line1[0] = pt1;
line1[1] = pt2;
e.writePolyline( line1, layerName, "CONTINUOUS", oc, outlineWidth );
QgsPolyline line2( 2 );
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
QPointF pt4( t.map( QPointF( 0, -halfHeight ) ) );
line2[0] = pt3;
line2[1] = pt4;
e.writePolyline( line2, layerName, "CONTINUOUS", oc, outlineWidth );
QgsPolyline line( 2 );
line[0] = t.map( QPointF( -halfWidth, 0 ) );
line[1] = t.map( QPointF( halfWidth, 0 ) );
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );

line[0] = t.map( QPointF( 0, halfHeight ) );
line[1] = t.map( QPointF( 0, -halfHeight ) );
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );

return true;
}
else if ( symbolName == "triangle" )
{
QPointF pt1( t.map( QPointF( -halfWidth, -halfHeight ) ) );
QPointF pt2( t.map( QPointF( halfWidth, -halfHeight ) ) );
QPointF pt3( t.map( QPointF( 0, halfHeight ) ) );
QPointF pt4( t.map( QPointF( 0, halfHeight ) ) );
QgsPolygon p( 1 );
p[0].resize( 4 );
p[0][0] = QPointF( t.map( QPointF( -halfWidth, -halfHeight ) ) );
p[0][1] = QPointF( t.map( QPointF( halfWidth, -halfHeight ) ) );
p[0][2] = QPointF( t.map( QPointF( 0, halfHeight ) ) );
p[0][3] = p[0][0];
if ( mBrush.style() != Qt::NoBrush )
e.writeSolid( layerName, fc, pt1, pt2, pt3, pt4 );
e.writePolygon( p, layerName, "SOLID", fc );
if ( mPen.style() != Qt::NoPen )
{
QgsPolyline line( 4 );
line[0] = pt1;
line[1] = pt2;
line[2] = pt3;
line[3] = pt4;
e.writePolyline( line, layerName, "CONTINUOUS", oc, outlineWidth );
}
e.writePolyline( p[0], layerName, "CONTINUOUS", oc, outlineWidth );
return true;
}

Expand Down
101 changes: 47 additions & 54 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -909,57 +909,48 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
}
else if ( mName == "square" || mName == "rectangle" )
{
// pt1 pt2
// pt3 pt4
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt4 = t.map( QPointF( halfSize, halfSize ) );
QgsPolygon p( 1 );
p[0].resize( 5 );
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
p[0][1] = t.map( QPointF( -halfSize, halfSize ) );
p[0][2] = t.map( QPointF( halfSize, halfSize ) );
p[0][3] = t.map( QPointF( halfSize, -halfSize ) );
p[0][4] = p[0][0];

if ( mBrush.style() != Qt::NoBrush )
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt4 );

e.writePolygon( p, layerName, "SOLID", bc );
if ( mPen.style() != Qt::NoPen )
{
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt2, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt4, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
}
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
}
else if ( mName == "diamond" )
{
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
QPointF pt2 = t.map( QPointF( 0, -halfSize ) );
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
QPointF pt4 = t.map( QPointF( halfSize, 0 ) );
QgsPolygon p( 1 );
p[0].resize( 5 );
p[0][0] = t.map( QPointF( -halfSize, 0 ) );
p[0][1] = t.map( QPointF( 0, halfSize ) );
p[0][3] = t.map( QPointF( halfSize, 0 ) );
p[0][1] = t.map( QPointF( 0, -halfSize ) );
p[0][4] = p[0][0];

if ( mBrush.style() != Qt::NoBrush )
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt4 );

e.writePolygon( p, layerName, "SOLID", bc );
if ( mPen.style() != Qt::NoPen )
{
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt4, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
}
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
}
else if ( mName == "triangle" )
{
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
QPointF pt2 = t.map( QPointF( halfSize, -halfSize ) );
QPointF pt3 = t.map( QPointF( 0, halfSize ) );
QgsPolygon p( 1 );
p[0].resize( 4 );
p[0][0] = t.map( QPointF( -halfSize, -halfSize ) );
p[0][1] = t.map( QPointF( halfSize, -halfSize ) );
p[0][1] = t.map( QPointF( 0, halfSize ) );
p[0][2] = p[0][0];

if ( mBrush.style() != Qt::NoBrush )
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt3 );
e.writePolygon( p, layerName, "SOLID", bc );

if ( mPen.style() != Qt::NoPen )
{
e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt2, pt3, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt1, layerName, "CONTINUOUS", pc, outlineWidth );
}
e.writePolyline( p[0], layerName, "CONTINUOUS", pc, outlineWidth );
}
#if 0
else if ( mName == "equilateral_triangle" )
Expand All @@ -977,51 +968,53 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
}
else if ( mName == "cross" )
{
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
QPointF pt2 = t.map( QPointF( halfSize, 0 ) );
QPointF pt3 = t.map( QPointF( 0, -halfSize ) );
QPointF pt4 = t.map( QPointF( 0, halfSize ) );

if ( mPen.style() != Qt::NoPen )
{
QPointF pt1 = t.map( QPointF( -halfSize, 0 ) );
QPointF pt2 = t.map( QPointF( halfSize, 0 ) );
QPointF pt3 = t.map( QPointF( 0, -halfSize ) );
QPointF pt4 = t.map( QPointF( 0, halfSize ) );

e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
}
}
else if ( mName == "x" || mName == "cross2" )
{
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );

if ( mPen.style() != Qt::NoPen )
{
QPointF pt1 = t.map( QPointF( -halfSize, -halfSize ) );
QPointF pt2 = t.map( QPointF( halfSize, halfSize ) );
QPointF pt3 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt4 = t.map( QPointF( halfSize, -halfSize ) );

e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt4, layerName, "CONTINUOUS", pc, outlineWidth );
}
}
else if ( mName == "arrowhead" )
{
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt2 = t.map( QPointF( 0, 0 ) );
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );

if ( mPen.style() != Qt::NoPen )
{
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt2 = t.map( QPointF( 0, 0 ) );
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );

e.writeLine( pt1, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
e.writeLine( pt3, pt2, layerName, "CONTINUOUS", pc, outlineWidth );
}
}
else if ( mName == "filled_arrowhead" )
{
QPointF pt1 = t.map( QPointF( -halfSize, halfSize ) );
QPointF pt2 = t.map( QPointF( 0, 0 ) );
QPointF pt3 = t.map( QPointF( -halfSize, -halfSize ) );

if ( mBrush.style() != Qt::NoBrush )
{
e.writeSolid( layerName, bc, pt1, pt2, pt3, pt3 );
QgsPolygon p( 1 );
p[0].resize( 4 );
p[0][0] = t.map( QPointF( -halfSize, halfSize ) );
p[0][1] = t.map( QPointF( 0, 0 ) );
p[0][2] = t.map( QPointF( -halfSize, -halfSize ) );
p[0][3] = p[0][0];
e.writePolygon( p, layerName, "SOLID", bc );
}
}
else
Expand Down

0 comments on commit 7031cfb

Please sign in to comment.