Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change symbol layer dxf method signature and make first test with a d…
…ata defined property
  • Loading branch information
mhugent committed Nov 26, 2013
1 parent 9abba40 commit fa509b8
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 46 deletions.
73 changes: 50 additions & 23 deletions src/core/dxf/qgsdxfexport.cpp
Expand Up @@ -417,7 +417,7 @@ void QgsDxfExport::writeTables()
writeGroup( 2, "TABLES" );

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

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

writeGroup( 0, "ENDTAB" );
Expand Down Expand Up @@ -472,20 +472,24 @@ void QgsDxfExport::writeBlocks()
writeGroup( 2, "BLOCKS" );

//iterate through all layers and get symbol layer pointers
QList<QgsSymbolLayerV2*> slList;
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > slList;
if ( mSymbologyExport != NoSymbology )
{
slList = symbolLayers();
}

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

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

writeGroup( 0, "ENDBLK" );
writeGroup( 8, 0 );
Expand Down Expand Up @@ -548,7 +552,7 @@ void QgsDxfExport::writeEntities()
{
if ( mSymbologyExport == NoSymbology )
{
addFeature( fet, vl->name(), 0 ); //no symbology at all
addFeature( fet, vl->name(), 0, 0 ); //no symbology at all
}
else
{
Expand All @@ -568,7 +572,7 @@ void QgsDxfExport::writeEntities()
{
continue;
}
addFeature( fet, vl->name(), s->symbolLayer( 0 ) );
addFeature( fet, vl->name(), s->symbolLayer( 0 ), s );
}
}
}
Expand Down Expand Up @@ -652,7 +656,7 @@ void QgsDxfExport::writeEntitiesSymbolLevels( QgsVectorLayer* layer )
QList<QgsFeature>::iterator featureIt = featureList.begin();
for ( ; featureIt != featureList.end(); ++featureIt )
{
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ) );
addFeature( *featureIt, layer->name(), levelIt.key()->symbolLayer( llayer ), levelIt.key() );
}
}
}
Expand All @@ -674,7 +678,7 @@ void QgsDxfExport::endSection()
writeGroup( 0, "ENDSEC" );
}

void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
{
#if 0
//debug: draw rectangle for debugging
Expand Down Expand Up @@ -706,10 +710,17 @@ void QgsDxfExport::writePoint( const QgsPoint& pt, const QString& layer, const Q
if ( !symbolLayer || blockIt == mPointSymbolBlocks.constEnd() )
{
//write symbol directly here
const QgsMarkerSymbolLayerV2* msl = dynamic_cast< const QgsMarkerSymbolLayerV2* >( symbolLayer );
if ( symbolLayer && symbol )
{
QgsRenderContext ct;
QgsSymbolV2RenderContext ctx( ct, QgsSymbolV2::MapUnit, symbol->alpha(), false, symbol->renderHints(), f );
symbolLayer->writeDxf( *this, mapUnitScaleFactor( mSymbologyScaleDenominator, msl->sizeUnit(), mMapUnits ), layer, &ctx, f, QPointF( pt.x(), pt.y() ) );
}
}
else
{
//insert block
//insert block reference
writeGroup( 0, "INSERT" );
writeGroup( 8, layer );
writeGroup( 2, blockIt.value() );
Expand Down Expand Up @@ -799,7 +810,7 @@ QgsRectangle QgsDxfExport::dxfExtent() const
return extent;
}

void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer )
void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol )
{
QgsGeometry* geom = fet.geometry();
if ( geom )
Expand All @@ -820,7 +831,7 @@ void QgsDxfExport::addFeature( const QgsFeature& fet, const QString& layer, cons
//single point
if ( geometryType == QGis::WKBPoint || geometryType == QGis::WKBPoint25D )
{
writePoint( geom->asPoint(), layer, symbolLayer );
writePoint( geom->asPoint(), layer, &fet, symbolLayer, symbol );
}

//single line
Expand Down Expand Up @@ -1006,9 +1017,9 @@ double QgsDxfExport::mapUnitScaleFactor( double scaleDenominator, QgsSymbolV2::O
return 1.0;
}

QList<QgsSymbolLayerV2*> QgsDxfExport::symbolLayers()
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > QgsDxfExport::symbolLayers()
{
QList<QgsSymbolLayerV2*> symbolLayers;
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > > symbolLayers;

QList< QgsMapLayer* >::iterator lIt = mLayers.begin();
for ( ; lIt != mLayers.end(); ++lIt )
Expand Down Expand Up @@ -1039,7 +1050,7 @@ QList<QgsSymbolLayerV2*> QgsDxfExport::symbolLayers()
}
for ( int i = 0; i < maxSymbolLayers; ++i )
{
symbolLayers.append(( *symbolIt )->symbolLayer( i ) );
symbolLayers.append( qMakePair(( *symbolIt )->symbolLayer( i ), *symbolIt ) ) ;
}
}
}
Expand Down Expand Up @@ -1069,13 +1080,13 @@ void QgsDxfExport::writeSymbolLayerLinestyle( const QgsSymbolLayerV2* symbolLaye
}
}

int QgsDxfExport::nLineTypes( const QList<QgsSymbolLayerV2*>& symbolLayers )
int QgsDxfExport::nLineTypes( const QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2* > >& symbolLayers )
{
int nLineTypes = 0;
QList<QgsSymbolLayerV2*>::const_iterator slIt = symbolLayers.constBegin();
QList< QPair< QgsSymbolLayerV2*, QgsSymbolV2*> >::const_iterator slIt = symbolLayers.constBegin();
for ( ; slIt != symbolLayers.constEnd(); ++slIt )
{
const QgsSimpleLineSymbolLayerV2* simpleLine = dynamic_cast< const QgsSimpleLineSymbolLayerV2* >( *slIt );
const QgsSimpleLineSymbolLayerV2* simpleLine = dynamic_cast< const QgsSimpleLineSymbolLayerV2* >( slIt->first );
if ( simpleLine )
{
if ( simpleLine->useCustomDashPattern() )
Expand Down Expand Up @@ -1116,6 +1127,22 @@ void QgsDxfExport::writeLinestyle( const QString& styleName, const QVector<qreal
}
}

bool QgsDxfExport::hasDataDefinedProperties( const QgsSymbolLayerV2* sl, const QgsSymbolV2* symbol )
{
if ( !sl || !symbol )
{
return false;
}

if ( symbol->renderHints() | QgsSymbolV2::DataDefinedSizeScale ||
symbol->renderHints() | QgsSymbolV2::DataDefinedRotation )
{
return true;
}

return sl->hasDataDefinedProperties();
}

/******************************************************Test with AC_1018 methods***************************************************************/

void QgsDxfExport::writeHeaderAC1018( QTextStream& stream )
Expand Down Expand Up @@ -1256,7 +1283,7 @@ void QgsDxfExport::writeTablesAC1018( QTextStream& stream )
QList<QgsSymbolLayerV2*> slList;
if ( mSymbologyExport != NoSymbology )
{
slList = symbolLayers();
//slList = symbolLayers(); //todo...
}

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

//add continuous style as default
stream << " 0\n";
Expand Down
9 changes: 5 additions & 4 deletions src/core/dxf/qgsdxfexport.h
Expand Up @@ -106,7 +106,7 @@ class QgsDxfExport
void startSection();
void endSection();

void writePoint( const QgsPoint& pt, const QString& layer, const QgsSymbolLayerV2* symbolLayer );
void writePoint( const QgsPoint& pt, const QString& layer, const QgsFeature* f, const QgsSymbolLayerV2* symbolLayer, const QgsSymbolV2* symbol );
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 );
Expand All @@ -125,7 +125,7 @@ class QgsDxfExport

QgsRectangle dxfExtent() const;

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

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

#endif // QGSDXFEXPORT_H
61 changes: 49 additions & 12 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -702,41 +702,76 @@ void QgsSimpleMarkerSymbolLayerV2::drawMarker( QPainter* p, QgsSymbolV2RenderCon
}
}

void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
void QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset ) const
{
//data defined size?
double size = mSize;

QgsExpression *sizeExpression = expression( "size" );
bool hasDataDefinedSize = false;
if ( context )
{
hasDataDefinedSize = context->renderHints() & QgsSymbolV2::DataDefinedSizeScale || sizeExpression;
}

//data defined size
if ( hasDataDefinedSize )
{
if ( sizeExpression )
{
size = sizeExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
}
size *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context->renderContext(), mSizeUnit );

switch ( mScaleMethod )
{
case QgsSymbolV2::ScaleArea:
size = sqrt( size );
break;
case QgsSymbolV2::ScaleDiameter:
break;
}
}

if ( mSizeUnit == QgsSymbolV2::MM )
{
size *= mmMapUnitScaleFactor;
}
double halfSize = size / 2.0;
int colorIndex = QgsDxfExport::closestColorMatch( mBrush.color().rgb() );

//data defined size


//data defined color, rotation, offset



if ( mName == "circle" )
{
e.writeGroup( 0, "CIRCLE" );
e.writeGroup( 8, layerName );

e.writeGroup( 62, colorIndex );
e.writeGroup( 10, halfSize );
e.writeGroup( 20, halfSize );
e.writeGroup( 10, halfSize + offset.x() );
e.writeGroup( 20, halfSize + offset.y() );
e.writeGroup( 30, 0.0 );
e.writeGroup( 40, halfSize );
}
else if ( mName == "square" || mName == "rectangle" )
{
QgsPoint pt1( 0.0, 0.0 );
QgsPoint pt2( size, 0.0 );
QgsPoint pt3( 0.0, size );
QgsPoint pt4( size, size );
QgsPoint pt1( 0.0 + offset.x(), 0.0 + offset.y() );
QgsPoint pt2( size + offset.x(), 0.0 + offset.y() );
QgsPoint pt3( 0.0 + offset.x(), size + offset.y() );
QgsPoint pt4( size + offset.x(), size + offset.y() );
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
}
else if ( mName == "diamond" )
{
QgsPoint pt1( 0.0, halfSize );
QgsPoint pt2( halfSize, 0.0 );
QgsPoint pt3( halfSize, size );
QgsPoint pt4( size, halfSize );
QgsPoint pt1( 0.0 + offset.x(), halfSize + offset.y() );
QgsPoint pt2( halfSize + offset.x(), 0.0 + offset.y() );
QgsPoint pt3( halfSize + offset.x(), size + offset.y() );
QgsPoint pt4( size + offset.x(), halfSize + offset.y() );
e.writeSolid( layerName, colorIndex, pt1, pt2, pt3, pt4 );
}
}
Expand Down Expand Up @@ -1146,9 +1181,11 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
return m;
}

void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const
void QgsSvgMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f,
const QPointF& offset ) const
{
Q_UNUSED( layerName );
Q_UNUSED( offset ); //todo...

QSvgRenderer r( mPath );
if ( !r.isValid() )
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
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( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const;
void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& offset = QPointF( 0.0, 0.0 ) ) const;

protected:

Expand Down Expand Up @@ -159,7 +159,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

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

protected:
QString mPath;
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -34,10 +34,10 @@ const QgsExpression* QgsSymbolLayerV2::dataDefinedProperty( const QString& prope
return 0;
}

QgsExpression* QgsSymbolLayerV2::expression( const QString& property )
QgsExpression* QgsSymbolLayerV2::expression( const QString& property ) const
{
QMap< QString, QgsExpression* >::iterator it = mDataDefinedProperties.find( property );
if ( it != mDataDefinedProperties.end() )
QMap< QString, QgsExpression* >::const_iterator it = mDataDefinedProperties.find( property );
if ( it != mDataDefinedProperties.constEnd() )
{
return it.value();
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -92,8 +92,10 @@ class CORE_EXPORT QgsSymbolLayerV2
virtual void setDataDefinedProperty( const QString& property, const QString& expressionString );
virtual void removeDataDefinedProperty( const QString& property );
virtual void removeDataDefinedProperties();
bool hasDataDefinedProperties() const { return mDataDefinedProperties.size() > 0; }

virtual void writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName ) const { Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); }
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
{ Q_UNUSED( e ); Q_UNUSED( mmMapUnitScaleFactor ); Q_UNUSED( layerName ); Q_UNUSED( context ); Q_UNUSED( f ); Q_UNUSED( offset ); }

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

virtual void prepareExpressions( const QgsVectorLayer* vl );
virtual QgsExpression* expression( const QString& property );
virtual QgsExpression* expression( const QString& property ) const;
/**Saves data defined properties to string map*/
void saveDataDefinedProperties( QgsStringMap& stringMap ) const;
/**Copies data defined properties of this layer to another symbol layer*/
Expand Down

0 comments on commit fa509b8

Please sign in to comment.