Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dwg import: handle wrong hatch interpretation (refs #20392)
  • Loading branch information
jef-n committed Feb 19, 2019
1 parent d84c34e commit fd15c3e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
18 changes: 9 additions & 9 deletions external/libdxfrw/drw_entities.cpp
Expand Up @@ -2333,12 +2333,12 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
{
dint32 numPathSeg = buf->getBitLong();

QgsDebugMsgLevel( QStringLiteral( "segs: %1" ).arg( numPathSeg ), 4 );
QgsDebugMsgLevel( QStringLiteral( " segs: %1" ).arg( numPathSeg ), 4 );

for ( dint32 j = 0; j < numPathSeg; ++j )
for ( dint32 j = 0; j < numPathSeg && buf->isGood(); ++j )
{
duint8 typePath = buf->getRawChar8();
QgsDebugMsgLevel( QStringLiteral( " typepath: %1" ).arg( typePath ), 4 );
QgsDebugMsgLevel( QStringLiteral( " typepath: %1" ).arg( typePath ), 4 );
if ( typePath == 1 ) //line
{
addLine();
Expand Down Expand Up @@ -2374,7 +2374,7 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
spline->nknots = buf->getBitLong();
spline->ncontrol = buf->getBitLong();

QgsDebugMsgLevel( QStringLiteral( " degree:%1 flags:0x%2 nknots:%3 ncontrol:%4" )
QgsDebugMsgLevel( QStringLiteral( " degree:%1 flags:0x%2 nknots:%3 ncontrol:%4" )
.arg( spline->degree ).arg( spline->flags, 0, 16 )
.arg( spline->nknots ).arg( spline->ncontrol ), 4
);
Expand All @@ -2384,7 +2384,7 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
for ( j = 0; j < spline->nknots && buf->isGood(); ++j )
{
spline->knotslist.push_back( buf->getBitDouble() );
QgsDebugMsgLevel( QStringLiteral( " knot %1: %2" ).arg( j )
QgsDebugMsgLevel( QStringLiteral( " knot %1: %2" ).arg( j )
.arg( spline->knotslist.back() ), 4
);
}
Expand All @@ -2406,22 +2406,22 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
if ( isRational )
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
spline->controllist.push_back( crd );
QgsDebugMsgLevel( QStringLiteral( " control %1: %2" )
QgsDebugMsgLevel( QStringLiteral( " control %1: %2" )
.arg( j )
.arg( QStringLiteral( "%1,%2,%3" ).arg( crd->x ).arg( crd->y ).arg( crd->z ) ), 4
);
}
if ( version > DRW::AC1021 ) //2010+
{
spline->nfit = buf->getBitLong();
QgsDebugMsgLevel( QStringLiteral( " nfit:%1" ).arg( spline->nfit ), 4 );
QgsDebugMsgLevel( QStringLiteral( " nfit:%1" ).arg( spline->nfit ), 4 );
RESERVE( spline->fitlist, spline->nfit );
for ( dint32 j = 0; j < spline->nfit && buf->isGood(); ++j )
{
DRW_Coord *crd = new DRW_Coord( buf->get2RawDouble() );
spline->fitlist.push_back( crd );

QgsDebugMsgLevel( QStringLiteral( " fit %1: %2" )
QgsDebugMsgLevel( QStringLiteral( " fit %1: %2" )
.arg( j )
.arg( QStringLiteral( "%1,%2,%3" ).arg( crd->x ).arg( crd->y ).arg( crd->z ) ), 4
);
Expand All @@ -2439,7 +2439,7 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
pline->flags = buf->getBit();//closed bit
dint32 numVert = buf->getBitLong();

QgsDebugMsgLevel( QStringLiteral( "hasBulge:%1 flags:%2 verts:%3" )
QgsDebugMsgLevel( QStringLiteral( " hasBulge:%1 flags:%2 verts:%3" )
.arg( hasBulges ).arg( pline->flags, 0, 16 ).arg( numVert ), 4
);

Expand Down
23 changes: 20 additions & 3 deletions external/libdxfrw/intern/dwgreader.cpp
Expand Up @@ -28,6 +28,7 @@
#include <QStringList>

#ifndef DWGDEBUG
#undef QGISDEBUG
#undef QgsDebugCall
#undef QgsDebugMsg
#undef QgsDebugMsgLevel
Expand Down Expand Up @@ -752,7 +753,7 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
}
}

#ifdef QGISDEBUG
#if 0
//RLZ: parse remaining object controls, TODO: implement all
mit = ObjectMap.find( hdr.viewCtrl );
if ( mit == ObjectMap.end() )
Expand Down Expand Up @@ -874,12 +875,12 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
ret2 = vpEntHeader.parseDwg( version, &buff, bs );
if ( ret )
ret = ret2;
#endif
#endif // 0
}
delete[]tmpByteStr;
}
}
#endif
#endif // 0

return ret;
}
Expand Down Expand Up @@ -927,6 +928,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
dwgBuffer buff( tmpByteStr, size, &decoder );
DRW_Block bk;
ret2 = bk.parseDwg( version, &buff, bs );
if ( !ret2 )
{
QgsDebugMsg( "parseDwg failed" );
}
delete[]tmpByteStr;
ret = ret && ret2;
parseAttribs( &bk );
Expand Down Expand Up @@ -965,6 +970,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
oc = mit->second;
ObjectMap.erase( mit );
ret2 = readDwgEntity( dbuf, oc, intfa );
if ( !ret2 )
{
QgsDebugMsg( "readDwgEntity failed" );
}
ret = ret && ret2;
}
if ( nextH == bkr->lastEH )
Expand Down Expand Up @@ -992,6 +1001,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
QgsDebugMsgLevel( QString( "Blocks, parsing entity: 0x%1 loc=%2" ).arg( oc.handle, 0, 16 ).arg( oc.loc ), 5 );

ret2 = readDwgEntity( dbuf, oc, intfa );
if ( !ret2 )
{
QgsDebugMsg( "readDwgEntity failed" );
}
ret = ret && ret2;
}
}
Expand Down Expand Up @@ -1022,6 +1035,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
DRW_Block end;
end.isEnd = true;
ret2 = end.parseDwg( version, &buff1, bs );
if ( !ret2 )
{
QgsDebugMsg( QString( "parseDwg failed" ) );
}
delete[]tmpByteStr;
ret = ret && ret2;
if ( bk.parentHandle == DRW::NoHandle ) bk.parentHandle = bkr->handle;
Expand Down

0 comments on commit fd15c3e

Please sign in to comment.