Skip to content

Commit fd15c3e

Browse files
committedFeb 19, 2019
dwg import: handle wrong hatch interpretation (refs #20392)
1 parent d84c34e commit fd15c3e

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed
 

‎external/libdxfrw/drw_entities.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,12 +2333,12 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
23332333
{
23342334
dint32 numPathSeg = buf->getBitLong();
23352335

2336-
QgsDebugMsgLevel( QStringLiteral( "segs: %1" ).arg( numPathSeg ), 4 );
2336+
QgsDebugMsgLevel( QStringLiteral( " segs: %1" ).arg( numPathSeg ), 4 );
23372337

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

2377-
QgsDebugMsgLevel( QStringLiteral( " degree:%1 flags:0x%2 nknots:%3 ncontrol:%4" )
2377+
QgsDebugMsgLevel( QStringLiteral( " degree:%1 flags:0x%2 nknots:%3 ncontrol:%4" )
23782378
.arg( spline->degree ).arg( spline->flags, 0, 16 )
23792379
.arg( spline->nknots ).arg( spline->ncontrol ), 4
23802380
);
@@ -2384,7 +2384,7 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
23842384
for ( j = 0; j < spline->nknots && buf->isGood(); ++j )
23852385
{
23862386
spline->knotslist.push_back( buf->getBitDouble() );
2387-
QgsDebugMsgLevel( QStringLiteral( " knot %1: %2" ).arg( j )
2387+
QgsDebugMsgLevel( QStringLiteral( " knot %1: %2" ).arg( j )
23882388
.arg( spline->knotslist.back() ), 4
23892389
);
23902390
}
@@ -2406,22 +2406,22 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
24062406
if ( isRational )
24072407
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
24082408
spline->controllist.push_back( crd );
2409-
QgsDebugMsgLevel( QStringLiteral( " control %1: %2" )
2409+
QgsDebugMsgLevel( QStringLiteral( " control %1: %2" )
24102410
.arg( j )
24112411
.arg( QStringLiteral( "%1,%2,%3" ).arg( crd->x ).arg( crd->y ).arg( crd->z ) ), 4
24122412
);
24132413
}
24142414
if ( version > DRW::AC1021 ) //2010+
24152415
{
24162416
spline->nfit = buf->getBitLong();
2417-
QgsDebugMsgLevel( QStringLiteral( " nfit:%1" ).arg( spline->nfit ), 4 );
2417+
QgsDebugMsgLevel( QStringLiteral( " nfit:%1" ).arg( spline->nfit ), 4 );
24182418
RESERVE( spline->fitlist, spline->nfit );
24192419
for ( dint32 j = 0; j < spline->nfit && buf->isGood(); ++j )
24202420
{
24212421
DRW_Coord *crd = new DRW_Coord( buf->get2RawDouble() );
24222422
spline->fitlist.push_back( crd );
24232423

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

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

‎external/libdxfrw/intern/dwgreader.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <QStringList>
2929

3030
#ifndef DWGDEBUG
31+
#undef QGISDEBUG
3132
#undef QgsDebugCall
3233
#undef QgsDebugMsg
3334
#undef QgsDebugMsgLevel
@@ -752,7 +753,7 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
752753
}
753754
}
754755

755-
#ifdef QGISDEBUG
756+
#if 0
756757
//RLZ: parse remaining object controls, TODO: implement all
757758
mit = ObjectMap.find( hdr.viewCtrl );
758759
if ( mit == ObjectMap.end() )
@@ -874,12 +875,12 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
874875
ret2 = vpEntHeader.parseDwg( version, &buff, bs );
875876
if ( ret )
876877
ret = ret2;
877-
#endif
878+
#endif // 0
878879
}
879880
delete[]tmpByteStr;
880881
}
881882
}
882-
#endif
883+
#endif // 0
883884

884885
return ret;
885886
}
@@ -927,6 +928,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
927928
dwgBuffer buff( tmpByteStr, size, &decoder );
928929
DRW_Block bk;
929930
ret2 = bk.parseDwg( version, &buff, bs );
931+
if ( !ret2 )
932+
{
933+
QgsDebugMsg( "parseDwg failed" );
934+
}
930935
delete[]tmpByteStr;
931936
ret = ret && ret2;
932937
parseAttribs( &bk );
@@ -965,6 +970,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
965970
oc = mit->second;
966971
ObjectMap.erase( mit );
967972
ret2 = readDwgEntity( dbuf, oc, intfa );
973+
if ( !ret2 )
974+
{
975+
QgsDebugMsg( "readDwgEntity failed" );
976+
}
968977
ret = ret && ret2;
969978
}
970979
if ( nextH == bkr->lastEH )
@@ -992,6 +1001,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
9921001
QgsDebugMsgLevel( QString( "Blocks, parsing entity: 0x%1 loc=%2" ).arg( oc.handle, 0, 16 ).arg( oc.loc ), 5 );
9931002

9941003
ret2 = readDwgEntity( dbuf, oc, intfa );
1004+
if ( !ret2 )
1005+
{
1006+
QgsDebugMsg( "readDwgEntity failed" );
1007+
}
9951008
ret = ret && ret2;
9961009
}
9971010
}
@@ -1022,6 +1035,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
10221035
DRW_Block end;
10231036
end.isEnd = true;
10241037
ret2 = end.parseDwg( version, &buff1, bs );
1038+
if ( !ret2 )
1039+
{
1040+
QgsDebugMsg( QString( "parseDwg failed" ) );
1041+
}
10251042
delete[]tmpByteStr;
10261043
ret = ret && ret2;
10271044
if ( bk.parentHandle == DRW::NoHandle ) bk.parentHandle = bkr->handle;

0 commit comments

Comments
 (0)
Please sign in to comment.