Skip to content

Commit fa509b8

Browse files
committedNov 26, 2013
Change symbol layer dxf method signature and make first test with a data defined property
1 parent 9abba40 commit fa509b8

File tree

6 files changed

+113
-46
lines changed

6 files changed

+113
-46
lines changed
 

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void QgsDxfExport::writeTables()
417417
writeGroup( 2, "TABLES" );
418418

419419
//iterate through all layers and get symbol layer pointers
420-
QList<QgsSymbolLayerV2*> slList;
420+
QList< QPair<QgsSymbolLayerV2*, QgsSymbolV2*> > slList;
421421
if ( mSymbologyExport != NoSymbology )
422422
{
423423
slList = symbolLayers();
@@ -439,10 +439,10 @@ void QgsDxfExport::writeTables()
439439
writeGroup( 40, 0.0 );
440440

441441
//add symbol layer linestyles
442-
QList<QgsSymbolLayerV2*>::const_iterator slIt = slList.constBegin();
442+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >::const_iterator slIt = slList.constBegin();
443443
for ( ; slIt != slList.constEnd(); ++slIt )
444444
{
445-
writeSymbolLayerLinestyle( *slIt );
445+
writeSymbolLayerLinestyle( slIt->first );
446446
}
447447

448448
writeGroup( 0, "ENDTAB" );
@@ -472,20 +472,24 @@ void QgsDxfExport::writeBlocks()
472472
writeGroup( 2, "BLOCKS" );
473473

474474
//iterate through all layers and get symbol layer pointers
475-
QList<QgsSymbolLayerV2*> slList;
475+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > slList;
476476
if ( mSymbologyExport != NoSymbology )
477477
{
478478
slList = symbolLayers();
479479
}
480480

481-
QList<QgsSymbolLayerV2*>::const_iterator slIt = slList.constBegin();
481+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > >::const_iterator slIt = slList.constBegin();
482482
for ( ; slIt != slList.constEnd(); ++slIt )
483483
{
484484
//if point symbol layer and no data defined properties: write block
485-
QgsMarkerSymbolLayerV2* ml = dynamic_cast< QgsMarkerSymbolLayerV2*>( *slIt );
485+
QgsMarkerSymbolLayerV2* ml = dynamic_cast< QgsMarkerSymbolLayerV2*>( slIt->first );
486486
if ( ml )
487487
{
488-
//todo: find out if the marker symbol layer has data defined properties (in that case don't insert it)
488+
//markers with data defined properties are inserted inline
489+
if ( hasDataDefinedProperties( ml, slIt->second ) )
490+
{
491+
continue;
492+
}
489493
writeGroup( 0, "BLOCK" );
490494
writeGroup( 8, 0 );
491495
QString blockName = QString( "symbolLayer%1" ).arg( mBlockCounter );
@@ -501,7 +505,7 @@ void QgsDxfExport::writeBlocks()
501505
writeGroup( 30, 0 );
502506
writeGroup( 3, blockName );
503507

504-
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0" ); //maplayer 0 -> block receives layer from INSERT statement
508+
ml->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, ml->sizeUnit(), mMapUnits ), "0", 0, 0 ); //maplayer 0 -> block receives layer from INSERT statement
505509

506510
writeGroup( 0, "ENDBLK" );
507511
writeGroup( 8, 0 );
@@ -548,7 +552,7 @@ void QgsDxfExport::writeEntities()
548552
{
549553
if ( mSymbologyExport == NoSymbology )
550554
{
551-
addFeature( fet, vl->name(), 0 ); //no symbology at all
555+
addFeature( fet, vl->name(), 0, 0 ); //no symbology at all
552556
}
553557
else
554558
{
@@ -568,7 +572,7 @@ void QgsDxfExport::writeEntities()
568572
{
569573
continue;
570574
}
571-
addFeature( fet, vl->name(), s->symbolLayer( 0 ) );
575+
addFeature( fet, vl->name(), s->symbolLayer( 0 ), s );
572576
}
573577
}
574578
}
@@ -652,7 +656,7 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
652656
QList<QgsFeature>::iterator featureIt = featureList.begin();
653657
for ( ; featureIt != featureList.end(); ++featureIt )
654658
{
655-
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ) );
659+
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
656660
}
657661
}
658662
}
@@ -674,7 +678,7 @@ void QgsDxfExport::endSection()
674678
writeGroup( 0, "ENDSEC" );
675679
}
676680

677-
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
681+
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
678682
{
679683
#if 0
680684
//debug: draw rectangle for debugging
@@ -706,10 +710,17 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
706710
if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )
707711
{
708712
//write symbol directly here
713+
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
714+
if ( symbolLayer && symbol )
715+
{
716+
QgsRenderContext ct;
717+
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
718+
symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) );
719+
}
709720
}
710721
else
711722
{
712-
//insert block
723+
//insert block reference
713724
writeGroup( 0, "INSERT" );
714725
writeGroup( 8, layer );
715726
writeGroup( 2, blockIt.value() );
@@ -799,7 +810,7 @@ QgsRectangle QgsDxfExport::dxfExtent() const
799810
return extent;
800811
}
801812

802-
void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
813+
void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
803814
{
804815
QgsGeometry* geom = fet.geometry();
805816
if ( geom )
@@ -820,7 +831,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
820831
//single point
821832
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
822833
{
823-
writePoint( geom->asPoint(), layer, symbolLayer );
834+
writePoint( geom->asPoint(), layer, &fet, symbolLayer, symbol );
824835
}
825836

826837
//single line
@@ -1006,9 +1017,9 @@ double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::O
10061017
return 1.0;
10071018
}
10081019

1009-
QList<QgsSymbolLayerV2*> QgsDxfExport::symbolLayers()
1020+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers()
10101021
{
1011-
QList<QgsSymbolLayerV2*> symbolLayers;
1022+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers;
10121023

10131024
QList< QgsMapLayer* >::iterator lIt = mLayers.begin();
10141025
for ( ; lIt != mLayers.end(); ++lIt )
@@ -1039,7 +1050,7 @@ QList<QgsSymbolLayerV2*> QgsDxfExport::symbolLayers()
10391050
}
10401051
for ( int i = 0; i < maxSymbolLayers; ++i )
10411052
{
1042-
symbolLayers.append(( *symbolIt )->symbolLayer( i ) );
1053+
symbolLayers.append( qMakePair(( *symbolIt )->symbolLayer( i ), *symbolIt ) ) ;
10431054
}
10441055
}
10451056
}
@@ -1069,13 +1080,13 @@ void QgsDxfExport::writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLaye
10691080
}
10701081
}
10711082

1072-
int QgsDxfExport::nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers )
1083+
int QgsDxfExport::nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > >& symbolLayers )
10731084
{
10741085
int nLineTypes = 0;
1075-
QList<QgsSymbolLayerV2*>::const_iterator slIt = symbolLayers.constBegin();
1086+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >::const_iterator slIt = symbolLayers.constBegin();
10761087
for ( ; slIt != symbolLayers.constEnd(); ++slIt )
10771088
{
1078-
const QgsSimpleLineSymbolLayerV2* simpleLine = dynamic_cast< const QgsSimpleLineSymbolLayerV2* >( *slIt );
1089+
const QgsSimpleLineSymbolLayerV2* simpleLine = dynamic_cast< const QgsSimpleLineSymbolLayerV2* >( slIt->first );
10791090
if ( simpleLine )
10801091
{
10811092
if ( simpleLine->useCustomDashPattern() )
@@ -1116,6 +1127,22 @@ void QgsDxfExport::writeLinestyle( const QString& styleName, const QVector<qreal
11161127
}
11171128
}
11181129

1130+
bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const QgsSymbolV2* symbol )
1131+
{
1132+
if ( !sl || !symbol )
1133+
{
1134+
return false;
1135+
}
1136+
1137+
if ( symbol->renderHints() | QgsSymbolV2::DataDefinedSizeScale ||
1138+
symbol->renderHints() | QgsSymbolV2::DataDefinedRotation )
1139+
{
1140+
return true;
1141+
}
1142+
1143+
return sl->hasDataDefinedProperties();
1144+
}
1145+
11191146
/******************************************************Test with AC_1018 methods***************************************************************/
11201147

11211148
void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )
@@ -1256,7 +1283,7 @@ void QgsDxfExport::writeTablesAC1018( QTextStream& stream )
12561283
QList<QgsSymbolLayerV2*> slList;
12571284
if ( mSymbologyExport != NoSymbology )
12581285
{
1259-
slList = symbolLayers();
1286+
//slList = symbolLayers(); //todo...
12601287
}
12611288

12621289
//LTYPE
@@ -1270,7 +1297,7 @@ void QgsDxfExport::writeTablesAC1018( QTextStream& stream )
12701297
stream << "100\n";
12711298
stream << "AcDbSymbolTable\n";
12721299
stream << " 70\n";
1273-
stream << QString( "%1\n" ).arg( nLineTypes( slList ) + 1 ); //number of linetypes
1300+
//stream << QString( "%1\n" ).arg( nLineTypes( slList ) + 1 ); //number of linetypes
12741301

12751302
//add continuous style as default
12761303
stream << " 0\n";

‎src/core/dxf/qgsdxfexport.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class QgsDxfExport
106106
void startSection();
107107
void endSection();
108108

109-
void writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
109+
void writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
110110
void writeVertex( const QgsPoint& pt, const QString& layer );
111111
void writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLayer );
112112
void writeLinestyle( const QString& styleName, const QVector<qreal>& pattern, QgsSymbolV2::OutputUnit u );
@@ -125,7 +125,7 @@ class QgsDxfExport
125125

126126
QgsRectangle dxfExtent() const;
127127

128-
void addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
128+
void addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
129129
double scaleToMapUnits( double value, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits ) const;
130130

131131
//returns dxf palette index from symbol layer color
@@ -141,8 +141,9 @@ class QgsDxfExport
141141
void startRender( QgsVectorLayer* vl ) const;
142142
void stopRender( QgsVectorLayer* vl ) const;
143143
static double mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::OutputUnit symbolUnits, QGis::UnitType mapUnits );
144-
QList<QgsSymbolLayerV2*> symbolLayers();
145-
static int nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers );
144+
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers();
145+
static int nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >& symbolLayers );
146+
static bool hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const QgsSymbolV2* symbol );
146147
};
147148

148149
#endif // QGSDXFEXPORT_H

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -702,41 +702,76 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
702702
}
703703
}
704704

705-
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
705+
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset ) const
706706
{
707+
//data defined size?
707708
double size = mSize;
709+
710+
QgsExpression *sizeExpression = expression( "size" );
711+
bool hasDataDefinedSize = false;
712+
if ( context )
713+
{
714+
hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;
715+
}
716+
717+
//data defined size
718+
if ( hasDataDefinedSize )
719+
{
720+
if ( sizeExpression )
721+
{
722+
size = sizeExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
723+
}
724+
size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context->renderContext(), mSizeUnit );
725+
726+
switch ( mScaleMethod )
727+
{
728+
case QgsSymbolV2::ScaleArea:
729+
size = sqrt( size );
730+
break;
731+
case QgsSymbolV2::ScaleDiameter:
732+
break;
733+
}
734+
}
735+
708736
if ( mSizeUnit == QgsSymbolV2::MM )
709737
{
710738
size *= mmMapUnitScaleFactor;
711739
}
712740
double halfSize = size / 2.0;
713741
int colorIndex = QgsDxfExport::closestColorMatch( mBrush.color().rgb() );
714742

743+
//data defined size
744+
745+
746+
//data defined color, rotation, offset
747+
748+
749+
715750
if ( mName == "circle" )
716751
{
717752
e.writeGroup( 0, "CIRCLE" );
718753
e.writeGroup( 8, layerName );
719754

720755
e.writeGroup( 62, colorIndex );
721-
e.writeGroup( 10, halfSize );
722-
e.writeGroup( 20, halfSize );
756+
e.writeGroup( 10, halfSize + offset.x() );
757+
e.writeGroup( 20, halfSize + offset.y() );
723758
e.writeGroup( 30, 0.0 );
724759
e.writeGroup( 40, halfSize );
725760
}
726761
else if ( mName == "square" || mName == "rectangle" )
727762
{
728-
QgsPoint pt1( 0.0, 0.0 );
729-
QgsPoint pt2( size, 0.0 );
730-
QgsPoint pt3( 0.0, size );
731-
QgsPoint pt4( size, size );
763+
QgsPoint pt1( 0.0 + offset.x(), 0.0 + offset.y() );
764+
QgsPoint pt2( size + offset.x(), 0.0 + offset.y() );
765+
QgsPoint pt3( 0.0 + offset.x(), size + offset.y() );
766+
QgsPoint pt4( size + offset.x(), size + offset.y() );
732767
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
733768
}
734769
else if ( mName == "diamond" )
735770
{
736-
QgsPoint pt1( 0.0, halfSize );
737-
QgsPoint pt2( halfSize, 0.0 );
738-
QgsPoint pt3( halfSize, size );
739-
QgsPoint pt4( size, halfSize );
771+
QgsPoint pt1( 0.0 + offset.x(), halfSize + offset.y() );
772+
QgsPoint pt2( halfSize + offset.x(), 0.0 + offset.y() );
773+
QgsPoint pt3( halfSize + offset.x(), size + offset.y() );
774+
QgsPoint pt4( size + offset.x(), halfSize + offset.y() );
740775
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
741776
}
742777
}
@@ -1146,9 +1181,11 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
11461181
return m;
11471182
}
11481183

1149-
void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
1184+
void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
1185+
const QPointF& offset ) const
11501186
{
11511187
Q_UNUSED( layerName );
1188+
Q_UNUSED( offset ); //todo...
11521189

11531190
QSvgRenderer r( mPath );
11541191
if ( !r.isValid() )

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
7676
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
7777
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u ) { mOutlineWidthUnit = u; }
7878

79-
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const;
79+
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset = QPointF( 0.0, 0.0 ) ) const;
8080

8181
protected:
8282

@@ -159,7 +159,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
159159
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
160160
QgsSymbolV2::OutputUnit outputUnit() const;
161161

162-
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const;
162+
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset = QPointF( 0.0, 0.0 ) ) const;
163163

164164
protected:
165165
QString mPath;

‎src/core/symbology-ng/qgssymbollayerv2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ const QgsExpression* QgsSymbolLayerV2::dataDefinedProperty( const QString& prope
3434
return 0;
3535
}
3636

37-
QgsExpression* QgsSymbolLayerV2::expression( const QString& property )
37+
QgsExpression* QgsSymbolLayerV2::expression( const QString& property ) const
3838
{
39-
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.find( property );
40-
if ( it != mDataDefinedProperties.end() )
39+
QMap< QString, QgsExpression* >::const_iterator it = mDataDefinedProperties.find( property );
40+
if ( it != mDataDefinedProperties.constEnd() )
4141
{
4242
return it.value();
4343
}

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ class CORE_EXPORT QgsSymbolLayerV2
9292
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
9393
virtual void removeDataDefinedProperty( const QString& property );
9494
virtual void removeDataDefinedProperties();
95+
bool hasDataDefinedProperties() const { return mDataDefinedProperties.size() > 0; }
9596

96-
virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); }
97+
virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset = QPointF( 0.0, 0.0 ) ) const
98+
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( offset ); }
9799

98100
protected:
99101
QgsSymbolLayerV2( QgsSymbolV2::SymbolType type, bool locked = false )
@@ -112,7 +114,7 @@ class CORE_EXPORT QgsSymbolLayerV2
112114
static const bool selectFillStyle = false; // Fill symbol uses symbol layer style..
113115

114116
virtual void prepareExpressions( const QgsVectorLayer* vl );
115-
virtual QgsExpression* expression( const QString& property );
117+
virtual QgsExpression* expression( const QString& property ) const;
116118
/**Saves data defined properties to string map*/
117119
void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
118120
/**Copies data defined properties of this layer to another symbol layer*/

0 commit comments

Comments
 (0)
Please sign in to comment.