Skip to content

Commit 941f045

Browse files
committed
dxf export:
* reinstate palette colors, but exclude black/white * fix hatch transparency * fix active (initial) v(iew)port (cherry-picked b6a4194 and 9961095)
1 parent fe3dc4c commit 941f045

File tree

1 file changed

+39
-50
lines changed

1 file changed

+39
-50
lines changed

src/core/dxf/qgsdxfexport.cpp

+39-50
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ void QgsDxfExport::writeGroup( int code, const QgsPoint &p, double z, bool skipz
418418

419419
void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, int transparencyCode )
420420
{
421-
#if 0
422421
int minDistAt = -1;
423422
int minDist = INT_MAX;
424423

@@ -432,13 +431,12 @@ void QgsDxfExport::writeGroup( QColor color, int exactMatchCode, int rgbCode, in
432431
minDist = dist;
433432
}
434433

435-
writeGroup( exactMatchCode, minDistAt );
436-
if ( minDist == 0 && color.alpha() == 255 )
434+
if ( minDist == 0 && color.alpha() == 255 && minDistAt != 7 )
437435
{
438-
// exact full opaque match
436+
// exact full opaque match, not black/white
437+
writeGroup( exactMatchCode, minDistAt );
439438
return;
440439
}
441-
#endif
442440

443441
int c = ( color.red() & 0xff ) * 0x10000 + ( color.green() & 0xff ) * 0x100 + ( color.blue() & 0xff );
444442
writeGroup( rgbCode, c );
@@ -482,10 +480,8 @@ int QgsDxfExport::writeToFile( QIODevice* d, QString encoding )
482480
}
483481

484482
mTextStream.setDevice( d );
485-
QgsDebugMsg( "encoding:" + encoding );
486483
mTextStream.setCodec( encoding.toLocal8Bit() );
487484

488-
QgsDebugMsg( "dxfEncoding:" + dxfEncoding( encoding ) );
489485
writeHeader( dxfEncoding( encoding ) );
490486
writeTables();
491487
writeBlocks();
@@ -506,7 +502,7 @@ void QgsDxfExport::writeHeader( QString codepage )
506502
writeGroup( 9, "$ACADVER" );
507503
writeGroup( 1, "AC1015" );
508504

509-
QgsRectangle ext = dxfExtent();
505+
QgsRectangle ext( mExtent.isEmpty() ? dxfExtent() : mExtent );
510506
if ( !ext.isEmpty() )
511507
{
512508
// EXTMIN
@@ -666,46 +662,44 @@ void QgsDxfExport::writeTables()
666662
writeHandle();
667663
writeGroup( 100, "AcDbSymbolTable" );
668664

669-
#if 0
670-
QgsRectangle ext( dxfExtent() );
665+
QgsRectangle ext( mExtent.isEmpty() ? dxfExtent() : mExtent );
671666

672667
writeGroup( 0, "VPORT" );
673668
writeHandle();
674669
writeGroup( 100, "AcDbSymbolTableRecord" );
675670
writeGroup( 100, "AcDbViewportTableRecord" );
676671
writeGroup( 2, "*ACTIVE" );
677672
writeGroup( 70, 0 ); // flags
678-
writeGroup( 0, QgsPoint( ext.xMinimum(), ext.yMinimum() ) ); // lower-left corner
679-
writeGroup( 1, QgsPoint( ext.xMaximum(), ext.yMaximum() ) ); // upper right corner
680-
writeGroup( 2, ext.center() ); // view center point
681-
writeGroup( 3, QgsPoint( 0.0, 0.0 ) ); // snap base point
682-
writeGroup( 4, QgsPoint( 0.5, 0.5 ) ); // snap spacing x/y
683-
writeGroup( 5, QgsPoint( 0.5, 0.5 ) ); // grid spacing x/y
684-
writeGroup( 6, QgsPoint( 0.0, 0.0 ), 1.0, false ); // view direction from target point
685-
writeGroup( 7, QgsPoint( 0.0, 0.0 ), 0.0, false ); // view target point
686-
writeGroup( 40, 10.0 ); // ?
687-
writeGroup( 42, 50.0 ); // lens length
688-
writeGroup( 43, 0.0 ); // front clipping plan
689-
writeGroup( 44, 0.0 ); // back clipping plan
690-
writeGroup( 50, 0.0 ); // snap rotation angle
691-
writeGroup( 51, 0.0 ); // view twist angle
692-
writeGroup( 71, 0 ); // view mode
693-
writeGroup( 72, 1000 ); // circle sides
694-
writeGroup( 73, 1 ); // ?
695-
writeGroup( 74, 3 ); // UCSICON setting
696-
writeGroup( 75, 0 ); // ?
697-
writeGroup( 76, 0 ); // ?
698-
writeGroup( 77, 0 ); // ?
699-
writeGroup( 78, 0 ); // ?
700-
writeGroup( 281, 0 ); // Render mode (2D)
701-
writeGroup( 100, QgsPoint( 0.0, 0.0 ), 0.0, false ); // UCS origin
702-
writeGroup( 101, QgsPoint( 1.0, 0.0 ), 0.0, false ); // UCS x axis
703-
writeGroup( 102, QgsPoint( 0.0, 1.0 ), 0.0, false ); // UCS y axis
704-
writeGroup( 79, 0 ); // Orthographic type of UCS (not orthographic)
705-
writeGroup( 146, 0.0 ); // elevation
706-
writeGroup( 60, 3 ); // ?
707-
writeGroup( 61, 5 ); // major grid line
708-
#endif
673+
writeGroup( 0, QgsPoint( 0.0, 0.0 ), 0.0, true ); // lower left
674+
writeGroup( 1, QgsPoint( 1.0, 1.0 ), 0.0, true ); // upper right
675+
writeGroup( 2, QgsPoint( 0.0, 0.0 ), 0.0, true ); // view center point
676+
writeGroup( 3, QgsPoint( 0.0, 0.0 ), 0.0, true ); // snap base point
677+
writeGroup( 4, QgsPoint( 1.0, 1.0 ), 0.0, true ); // snap spacing
678+
writeGroup( 5, QgsPoint( 1.0, 1.0 ), 0.0, true ); // grid spacing
679+
writeGroup( 6, QgsPoint( 0.0, 0.0 ), 1.0 ); // view direction from target point
680+
writeGroup( 7, ext.center(), 0.0, true ); // view target point
681+
writeGroup( 40, ext.height() ); // view height
682+
writeGroup( 41, ext.width() / ext.height() ); // view aspect ratio
683+
writeGroup( 42, 50.0 ); // lens length
684+
writeGroup( 43, 0.0 ); // front clipping plane
685+
writeGroup( 44, 0.0 ); // back clipping plane
686+
writeGroup( 50, 0.0 ); // snap rotation
687+
writeGroup( 51, 0.0 ); // view twist angle
688+
writeGroup( 71, 0 ); // view mode (0 = deactivates)
689+
writeGroup( 72, 100 ); // circle zoom percent
690+
writeGroup( 73, 1 ); // fast zoom setting
691+
writeGroup( 74, 1 ); // UCSICON setting
692+
writeGroup( 75, 0 ); // snapping off
693+
writeGroup( 76, 0 ); // grid off
694+
writeGroup( 77, 0 ); // snap style
695+
writeGroup( 78, 0 ); // snap isopair
696+
writeGroup( 281, 0 ); // render mode (0 = 2D optimized)
697+
writeGroup( 65, 1 ); // value of UCSVP for this viewport
698+
writeGroup( 100, QgsPoint( 0.0, 0.0 ) ); // UCS origin
699+
writeGroup( 101, QgsPoint( 1.0, 0.0 ) ); // UCS x axis
700+
writeGroup( 102, QgsPoint( 0.0, 1.0 ) ); // UCS y axis
701+
writeGroup( 79, 0 ); // Orthographic type of UCS (0 = UCS is not orthographic)
702+
writeGroup( 146, 0.0 ); // Elevation
709703

710704
writeGroup( 70, 0 );
711705
writeGroup( 0, "ENDTAB" );
@@ -3369,22 +3363,21 @@ void QgsDxfExport::writePolyline( const QgsPolyline& line, const QString& layer,
33693363

33703364
void QgsDxfExport::writePolygon( const QgsPolygon& polygon, const QString& layer, const QString& hatchPattern, QColor color )
33713365
{
3372-
writeGroup( 0, "HATCH" ); // Entity type
3366+
writeGroup( 0, "HATCH" ); // Entity type
33733367
writeHandle();
33743368
writeGroup( 330, mModelSpaceBR );
33753369
writeGroup( 100, "AcDbEntity" );
3370+
writeGroup( 8, layer ); // Layer name
3371+
writeGroup( color ); // Color
33763372
writeGroup( 100, "AcDbHatch" );
33773373

3378-
writeGroup( 8, layer ); // Layer name
3379-
writeGroup( 0, QgsPoint( 0, 0 ) ); // Elevation point (in OCS)
3374+
writeGroup( 0, QgsPoint( 0, 0 ) ); // Elevation point (in OCS)
33803375
writeGroup( 200, QgsPoint( 0, 0 ), 1.0 );
33813376

33823377
writeGroup( 2, hatchPattern ); // Hatch pattern name
33833378
writeGroup( 70, hatchPattern == "SOLID" ); // Solid fill flag (solid fill = 1; pattern fill = 0)
33843379
writeGroup( 71, 0 ); // Associativity flag (associative = 1; non-associative = 0)
33853380

3386-
writeGroup( color ); // Color (0 by block, 256 by layer)
3387-
33883381
writeGroup( 91, polygon.size() ); // Number of boundary paths (loops)
33893382
for ( int i = 0; i < polygon.size(); ++i )
33903383
{
@@ -3520,10 +3513,6 @@ void QgsDxfExport::writeMText( const QString& layer, const QString& text, const
35203513

35213514
writeGroup( 0, pt );
35223515

3523-
QgsDebugMsg( QString( "text:%1" ).arg( text ) );
3524-
QgsDebugMsg( QString( "canEncode:%1" ).arg( mTextStream.codec()->canEncode( text ) ? "yes" : "no" ) );
3525-
QgsDebugMsg( QString( "fromUnicode:%1" ).arg( mTextStream.codec()->fromUnicode( text ).constData() ) );
3526-
35273516
QString t( text );
35283517
while ( t.length() > 250 )
35293518
{

0 commit comments

Comments
 (0)