From 941f045e6f40fe9a2dc044006c2f34b85e932e9f Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Fri, 27 Mar 2015 23:47:17 +0100 Subject: [PATCH] dxf export: * reinstate palette colors, but exclude black/white * fix hatch transparency * fix active (initial) v(iew)port (cherry-picked b6a4194 and 9961095) --- src/core/dxf/qgsdxfexport.cpp | 89 +++++++++++++++-------------------- 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/src/core/dxf/qgsdxfexport.cpp b/src/core/dxf/qgsdxfexport.cpp index 37307b72be08..a3655c996b60 100644 --- a/src/core/dxf/qgsdxfexport.cpp +++ b/src/core/dxf/qgsdxfexport.cpp @@ -418,7 +418,6 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p, double z, bool skipz void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, int transparencyCode ) { -#if 0 int minDistAt = -1; int minDist = INT_MAX; @@ -432,13 +431,12 @@ void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, in minDist = dist; } - writeGroup( exactMatchCode, minDistAt ); - if ( minDist == 0 && color.alpha() == 255 ) + if ( minDist == 0 && color.alpha() == 255 && minDistAt != 7 ) { - // exact full opaque match + // exact full opaque match, not black/white + writeGroup( exactMatchCode, minDistAt ); return; } -#endif int c = ( color.red() & 0xff ) * 0x10000 + ( color.green() & 0xff ) * 0x100 + ( color.blue() & 0xff ); writeGroup( rgbCode, c ); @@ -482,10 +480,8 @@ int QgsDxfExport::writeToFile( QIODevice* d, QString encoding ) } mTextStream.setDevice( d ); - QgsDebugMsg( "encoding:" + encoding ); mTextStream.setCodec( encoding.toLocal8Bit() ); - QgsDebugMsg( "dxfEncoding:" + dxfEncoding( encoding ) ); writeHeader( dxfEncoding( encoding ) ); writeTables(); writeBlocks(); @@ -506,7 +502,7 @@ void QgsDxfExport::writeHeader( QString codepage ) writeGroup( 9, "$ACADVER" ); writeGroup( 1, "AC1015" ); - QgsRectangle ext = dxfExtent(); + QgsRectangle ext( mExtent.isEmpty() ? dxfExtent() : mExtent ); if ( !ext.isEmpty() ) { // EXTMIN @@ -666,8 +662,7 @@ void QgsDxfExport::writeTables() writeHandle(); writeGroup( 100, "AcDbSymbolTable" ); -#if 0 - QgsRectangle ext( dxfExtent() ); + QgsRectangle ext( mExtent.isEmpty() ? dxfExtent() : mExtent ); writeGroup( 0, "VPORT" ); writeHandle(); @@ -675,37 +670,36 @@ void QgsDxfExport::writeTables() writeGroup( 100, "AcDbViewportTableRecord" ); writeGroup( 2, "*ACTIVE" ); writeGroup( 70, 0 ); // flags - writeGroup( 0, QgsPoint( ext.xMinimum(), ext.yMinimum() ) ); // lower-left corner - writeGroup( 1, QgsPoint( ext.xMaximum(), ext.yMaximum() ) ); // upper right corner - writeGroup( 2, ext.center() ); // view center point - writeGroup( 3, QgsPoint( 0.0, 0.0 ) ); // snap base point - writeGroup( 4, QgsPoint( 0.5, 0.5 ) ); // snap spacing x/y - writeGroup( 5, QgsPoint( 0.5, 0.5 ) ); // grid spacing x/y - writeGroup( 6, QgsPoint( 0.0, 0.0 ), 1.0, false ); // view direction from target point - writeGroup( 7, QgsPoint( 0.0, 0.0 ), 0.0, false ); // view target point - writeGroup( 40, 10.0 ); // ? - writeGroup( 42, 50.0 ); // lens length - writeGroup( 43, 0.0 ); // front clipping plan - writeGroup( 44, 0.0 ); // back clipping plan - writeGroup( 50, 0.0 ); // snap rotation angle - writeGroup( 51, 0.0 ); // view twist angle - writeGroup( 71, 0 ); // view mode - writeGroup( 72, 1000 ); // circle sides - writeGroup( 73, 1 ); // ? - writeGroup( 74, 3 ); // UCSICON setting - writeGroup( 75, 0 ); // ? - writeGroup( 76, 0 ); // ? - writeGroup( 77, 0 ); // ? - writeGroup( 78, 0 ); // ? - writeGroup( 281, 0 ); // Render mode (2D) - writeGroup( 100, QgsPoint( 0.0, 0.0 ), 0.0, false ); // UCS origin - writeGroup( 101, QgsPoint( 1.0, 0.0 ), 0.0, false ); // UCS x axis - writeGroup( 102, QgsPoint( 0.0, 1.0 ), 0.0, false ); // UCS y axis - writeGroup( 79, 0 ); // Orthographic type of UCS (not orthographic) - writeGroup( 146, 0.0 ); // elevation - writeGroup( 60, 3 ); // ? - writeGroup( 61, 5 ); // major grid line -#endif + writeGroup( 0, QgsPoint( 0.0, 0.0 ), 0.0, true ); // lower left + writeGroup( 1, QgsPoint( 1.0, 1.0 ), 0.0, true ); // upper right + writeGroup( 2, QgsPoint( 0.0, 0.0 ), 0.0, true ); // view center point + writeGroup( 3, QgsPoint( 0.0, 0.0 ), 0.0, true ); // snap base point + writeGroup( 4, QgsPoint( 1.0, 1.0 ), 0.0, true ); // snap spacing + writeGroup( 5, QgsPoint( 1.0, 1.0 ), 0.0, true ); // grid spacing + writeGroup( 6, QgsPoint( 0.0, 0.0 ), 1.0 ); // view direction from target point + writeGroup( 7, ext.center(), 0.0, true ); // view target point + writeGroup( 40, ext.height() ); // view height + writeGroup( 41, ext.width() / ext.height() ); // view aspect ratio + writeGroup( 42, 50.0 ); // lens length + writeGroup( 43, 0.0 ); // front clipping plane + writeGroup( 44, 0.0 ); // back clipping plane + writeGroup( 50, 0.0 ); // snap rotation + writeGroup( 51, 0.0 ); // view twist angle + writeGroup( 71, 0 ); // view mode (0 = deactivates) + writeGroup( 72, 100 ); // circle zoom percent + writeGroup( 73, 1 ); // fast zoom setting + writeGroup( 74, 1 ); // UCSICON setting + writeGroup( 75, 0 ); // snapping off + writeGroup( 76, 0 ); // grid off + writeGroup( 77, 0 ); // snap style + writeGroup( 78, 0 ); // snap isopair + writeGroup( 281, 0 ); // render mode (0 = 2D optimized) + writeGroup( 65, 1 ); // value of UCSVP for this viewport + writeGroup( 100, QgsPoint( 0.0, 0.0 ) ); // UCS origin + writeGroup( 101, QgsPoint( 1.0, 0.0 ) ); // UCS x axis + writeGroup( 102, QgsPoint( 0.0, 1.0 ) ); // UCS y axis + writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic) + writeGroup( 146, 0.0 ); // Elevation writeGroup( 70, 0 ); writeGroup( 0, "ENDTAB" ); @@ -3369,22 +3363,21 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer, void QgsDxfExport::writePolygon( const QgsPolygon& polygon, const QString& layer, const QString& hatchPattern, QColor color ) { - writeGroup( 0, "HATCH" ); // Entity type + writeGroup( 0, "HATCH" ); // Entity type writeHandle(); writeGroup( 330, mModelSpaceBR ); writeGroup( 100, "AcDbEntity" ); + writeGroup( 8, layer ); // Layer name + writeGroup( color ); // Color writeGroup( 100, "AcDbHatch" ); - writeGroup( 8, layer ); // Layer name - writeGroup( 0, QgsPoint( 0, 0 ) ); // Elevation point (in OCS) + writeGroup( 0, QgsPoint( 0, 0 ) ); // Elevation point (in OCS) writeGroup( 200, QgsPoint( 0, 0 ), 1.0 ); writeGroup( 2, hatchPattern ); // Hatch pattern name writeGroup( 70, hatchPattern == "SOLID" ); // Solid fill flag (solid fill = 1; pattern fill = 0) writeGroup( 71, 0 ); // Associativity flag (associative = 1; non-associative = 0) - writeGroup( color ); // Color (0 by block, 256 by layer) - writeGroup( 91, polygon.size() ); // Number of boundary paths (loops) for ( int i = 0; i < polygon.size(); ++i ) { @@ -3520,10 +3513,6 @@ void QgsDxfExport::writeMText( const QString& layer, const QString& text, const writeGroup( 0, pt ); - QgsDebugMsg( QString( "text:%1" ).arg( text ) ); - QgsDebugMsg( QString( "canEncode:%1" ).arg( mTextStream.codec()->canEncode( text ) ? "yes" : "no" ) ); - QgsDebugMsg( QString( "fromUnicode:%1" ).arg( mTextStream.codec()->fromUnicode( text ).constData() ) ); - QString t( text ); while ( t.length() > 250 ) {