Skip to content

Commit fb81ce6

Browse files
committedFeb 26, 2019
backport dwg import fixes
fec20ae dwg import: less noisy noise reduction 3aa2d9f dwg import: catch spline misinterpretation (fixes #20392) 1a96982 dwg import: fix handling of arc and splines in hatches 6090a93 dwg import: less noisy debugging 92e7faa dwg/dxf import: fix angle and alignment handing of (m)texts 0f6421d dwg import: use Q_DECLARE_TR_FUNCTIONS in QgsDwgImporter f12cac7 dwg import: progress display e1562a7 dwg import: support dxf encoding (fixes #15999) b8c727f dwg import: force polyline and hatch/ring continuity 355deb5 dwg import: fix exception (fixes #21177) d84c34e dwg import: support nested blocks (refs #20392) fd15c3e dwg import: handle wrong hatch interpretation (refs #20392)
1 parent 36a1046 commit fb81ce6

File tree

13 files changed

+743
-340
lines changed

13 files changed

+743
-340
lines changed
 

‎external/libdxfrw/drw_entities.cpp

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,29 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
15+
1316
#include <cstdlib>
1417

1518
#include "drw_entities.h"
1619
#include "intern/dxfreader.h"
1720
#include "intern/dwgbuffer.h"
1821
#include "intern/drw_dbg.h"
1922

20-
#undef QGISDEBUG
21-
#include "qgslogger.h"
2223
#include <QStringList>
2324

25+
#include "qgslogger.h"
26+
27+
#ifndef DWGDEBUG
28+
#undef QgsDebugCall
29+
#undef QgsDebugMsg
30+
#undef QgsDebugMsgLevel
31+
#define QgsDebugCall
32+
#define QgsDebugMsg(str)
33+
#define QgsDebugMsgLevel(str, level)
34+
#endif
35+
2436
#define RESERVE( vector, size ) try { \
2537
vector.reserve(size); \
2638
} catch(const std::exception &e) { \
@@ -436,7 +448,7 @@ bool DRW_Entity::parseDwg( DRW::Version version, dwgBuffer *buf, dwgBuffer *strB
436448
duint8 unk = buf->getBit();
437449
QgsDebugMsg( QString( "unknown bit: %1" ).arg( unk ) );
438450
}
439-
#endif
451+
#endif // 0
440452
return buf->isGood();
441453
}
442454

@@ -1537,7 +1549,7 @@ bool DRW_LWPolyline::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs
15371549
#if 0
15381550
if ( vertlist.size() < i )
15391551
vertlist.at( i )->vertexId = vertexId;
1540-
#endif
1552+
#endif // 0
15411553
}
15421554
}
15431555
//add widths
@@ -1592,7 +1604,7 @@ void DRW_Text::parseCode( int code, dxfReader *reader )
15921604
angle = reader->getDouble() / ARAD;
15931605
break;
15941606
case 51:
1595-
oblique = reader->getDouble();
1607+
oblique = reader->getDouble() / ARAD;
15961608
break;
15971609
case 71:
15981610
textgen = reader->getInt32();
@@ -1789,6 +1801,7 @@ bool DRW_MText::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
17891801

17901802
extPoint = buf->get3BitDouble(); /* Extrusion 3BD 210 Undocumented; */
17911803
secPoint = buf->get3BitDouble(); /* X-axis dir 3BD 11 */
1804+
haveXAxis = true;
17921805
updateAngle();
17931806
widthscale = buf->getBitDouble(); /* Rect width BD 41 */
17941807
if ( version > DRW::AC1018 ) //2007+
@@ -2178,7 +2191,7 @@ void DRW_Hatch::parseCode( int code, dxfReader *reader )
21782191
else if ( ellipse ) ellipse->endparam = reader->getDouble() / ARAD;
21792192
break;
21802193
case 52:
2181-
angle = reader->getDouble();
2194+
angle = reader->getDouble() / ARAD;
21822195
break;
21832196
case 73:
21842197
if ( arc ) arc->isccw = reader->getInt32();
@@ -2320,7 +2333,7 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
23202333

23212334
QgsDebugMsg( QString( "segs: %1" ).arg( numPathSeg ) );
23222335

2323-
for ( dint32 j = 0; j < numPathSeg; ++j )
2336+
for ( dint32 j = 0; j < numPathSeg && buf->isGood(); ++j )
23242337
{
23252338
duint8 typePath = buf->getRawChar8();
23262339
QgsDebugMsg( QString( " typepath: %1" ).arg( typePath ) );
@@ -2364,15 +2377,26 @@ bool DRW_Hatch::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )
23642377
.arg( spline->nknots ).arg( spline->ncontrol )
23652378
);
23662379
RESERVE( spline->knotslist, spline->nknots );
2367-
for ( dint32 j = 0; j < spline->nknots; ++j )
2380+
dint32 j;
2381+
for ( j = 0; j < spline->nknots && buf->isGood(); ++j )
23682382
{
23692383
spline->knotslist.push_back( buf->getBitDouble() );
23702384
QgsDebugMsg( QString( " knot %1: %2" ).arg( j )
23712385
.arg( spline->knotslist.back() )
23722386
);
23732387
}
2388+
2389+
if ( !buf->isGood() )
2390+
{
2391+
QgsDebugMsg( QStringLiteral( "NOT GOOD at %1! degree:%2 flags:0x%3 nknots:%4 ncontrol:%5" )
2392+
.arg( j )
2393+
.arg( spline->degree ).arg( spline->flags, 0, 16 )
2394+
.arg( spline->nknots ).arg( spline->ncontrol )
2395+
);
2396+
}
2397+
23742398
RESERVE( spline->controllist, spline->ncontrol );
2375-
for ( dint32 j = 0; j < spline->ncontrol && buf->isGood(); ++j )
2399+
for ( j = 0; j < spline->ncontrol && buf->isGood(); ++j )
23762400
{
23772401
DRW_Coord *crd = new DRW_Coord( buf->get2RawDouble() );
23782402
spline->controllist.push_back( crd );
@@ -2933,10 +2957,10 @@ void DRW_Dimension::parseCode( int code, dxfReader *reader )
29332957
rot = reader->getDouble();
29342958
break;
29352959
case 50:
2936-
angle = reader->getDouble();
2960+
angle = reader->getDouble() / ARAD;
29372961
break;
29382962
case 52:
2939-
oblique = reader->getDouble();
2963+
oblique = reader->getDouble() / ARAD;
29402964
break;
29412965
case 40:
29422966
length = reader->getDouble();

‎external/libdxfrw/drw_header.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,30 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
15+
1316
#include "drw_header.h"
1417
#include "intern/dxfreader.h"
1518
#include "intern/dxfwriter.h"
1619
#include "intern/drw_dbg.h"
1720
#include "intern/dwgbuffer.h"
1821

19-
#include "qgslogger.h"
2022
#include <QStringList>
2123

2224
#include <cassert>
2325

26+
#include "qgslogger.h"
27+
28+
#ifndef DWGDEBUG
29+
#undef QgsDebugCall
30+
#undef QgsDebugMsg
31+
#undef QgsDebugMsgLevel
32+
#define QgsDebugCall
33+
#define QgsDebugMsg(str)
34+
#define QgsDebugMsgLevel(str, level)
35+
#endif
36+
2437
DRW_Header::DRW_Header()
2538
: curr( nullptr )
2639
, version( DRW::AC1021 )

‎external/libdxfrw/drw_objects.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
15+
1316
#include <iostream>
1417
#include <cmath>
1518

@@ -20,10 +23,19 @@
2023
#include "intern/drw_dbg.h"
2124
#include "intern/dwgutil.h"
2225

23-
#undef QGISDEBUG
24-
#include "qgslogger.h"
2526
#include <QStringList>
2627

28+
#include "qgslogger.h"
29+
30+
#ifndef DWGDEBUG
31+
#undef QgsDebugCall
32+
#undef QgsDebugMsg
33+
#undef QgsDebugMsgLevel
34+
#define QgsDebugCall
35+
#define QgsDebugMsg(str)
36+
#define QgsDebugMsgLevel(str, level)
37+
#endif
38+
2739
#define RESERVE( vector, size ) try { \
2840
vector.reserve(size); \
2941
} catch(const std::exception &e) { \

‎external/libdxfrw/intern/drw_textcodec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ std::string DRW_Converter::encodeNum( int c )
296296
return std::string( ( char * )ret );
297297
}
298298

299-
/** 's' is a string with at least 4 bytes length
299+
/**
300+
* 's' is a string with at least 4 bytes length
300301
** returned 'b' is byte length of encoded char: 2,3 or 4
301302
**/
302303
int DRW_Converter::decodeNum( std::string s, int *b )

‎external/libdxfrw/intern/dwgbuffer.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,23 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
1315

1416
#include "dwgbuffer.h"
1517
#include "../libdwgr.h"
1618
#include "drw_textcodec.h"
1719
#include "drw_dbg.h"
1820

19-
#undef QGISDEBUG
2021
#include "qgslogger.h"
2122

22-
#if 0
23-
//#include <bitset>
24-
#include <fstream>
25-
#include <algorithm>
26-
#include <sstream>
27-
#include "dwgreader.h"
28-
#include "dxfwriter.h"
29-
30-
#define FIRSTHANDLE 48
31-
32-
enum sections
33-
{
34-
secUnknown,
35-
secHeader,
36-
secTables,
37-
secBlocks,
38-
secEntities,
39-
secObjects
40-
};
23+
#ifndef DWGDEBUG
24+
#undef QgsDebugCall
25+
#undef QgsDebugMsg
26+
#undef QgsDebugMsgLevel
27+
#define QgsDebugCall
28+
#define QgsDebugMsg(str)
29+
#define QgsDebugMsgLevel(str, level)
4130
#endif
4231

4332
static unsigned int crctable[256] =
@@ -711,7 +700,8 @@ std::string dwgBuffer::getCP8Text()
711700

712701
//TU unicode 16 bit (UCS) text converted to utf8
713702

714-
/** Reads 2-bytes char (UCS2, nullptr terminated) and convert to std::string (only for Latin-1)
703+
/**
704+
* Reads 2-bytes char (UCS2, nullptr terminated) and convert to std::string (only for Latin-1)
715705
ts= total input size in bytes.
716706
**/
717707
std::string dwgBuffer::getUCSStr( duint16 ts )
@@ -919,31 +909,31 @@ duint32 dwgBuffer::getEnColor( DRW::Version v, int &rgb, int &transparency )
919909
transparency = 0;
920910

921911
duint16 idx = getBitShort();
922-
QgsDebugMsg( QString( "idx reads COLOR: 0x%1" ).arg( idx, 0, 16 ) );
912+
QgsDebugMsgLevel( QString( "idx reads COLOR: 0x%1" ).arg( idx, 0, 16 ), 4 );
923913

924914
duint16 flags = idx >> 8;
925915

926916
idx = idx & 0x1FF; //RLZ: warning this is correct?
927917

928-
QgsDebugMsg( QString( "flag COLOR:0x%1, index COLOR:0x%2" ).arg( flags, 0, 16 ).arg( idx, 0, 16 ) );
918+
QgsDebugMsgLevel( QString( "flag COLOR:0x%1, index COLOR:0x%2" ).arg( flags, 0, 16 ).arg( idx, 0, 16 ), 4 );
929919

930920
if ( flags & 0x80 )
931921
{
932922
// complex color (rgb)
933923
rgb = getBitLong() & 0xffffff;
934924

935-
QgsDebugMsg( QString( "RGB COLOR:0x%1" ).arg( rgb, 0, 16 ) );
925+
QgsDebugMsgLevel( QString( "RGB COLOR:0x%1" ).arg( rgb, 0, 16 ), 4 );
936926

937927
if ( flags & 0x80 )
938928
{
939-
QgsDebugMsg( "acdbColor COLOR are present" );
929+
QgsDebugMsgLevel( "acdbColor COLOR are present", 4 );
940930
}
941931
}
942932

943933
if ( flags & 0x20 )
944934
{
945935
transparency = getBitLong();
946-
QgsDebugMsg( QString( "Transparency COLOR:0x%1" ).arg( transparency, 0, 16 ) );
936+
QgsDebugMsgLevel( QString( "Transparency COLOR:0x%1" ).arg( transparency, 0, 16 ), 4 );
947937
}
948938

949939
return idx; //default return ByLayer

‎external/libdxfrw/intern/dwgreader.cpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
15+
1316
#include <cstdlib>
1417
#include <iostream>
1518
#include <fstream>
@@ -19,12 +22,21 @@
1922
#include "dwgreader.h"
2023
#include "drw_textcodec.h"
2124

22-
#undef QGISDEBUG
2325
#include "qgslogger.h"
2426
#include "qgsmessagelog.h"
2527

2628
#include <QStringList>
2729

30+
#ifndef DWGDEBUG
31+
#undef QGISDEBUG
32+
#undef QgsDebugCall
33+
#undef QgsDebugMsg
34+
#undef QgsDebugMsgLevel
35+
#define QgsDebugCall
36+
#define QgsDebugMsg(str)
37+
#define QgsDebugMsgLevel(str, level)
38+
#endif
39+
2840

2941
dwgReader::~dwgReader()
3042
{
@@ -149,7 +161,8 @@ bool dwgReader::checkSentinel( dwgBuffer *buf, enum secEnum::DWGSection, bool st
149161

150162
/*********** objects map ************************/
151163

152-
/** Note: object map are split in sections with max size 2035?
164+
/**
165+
* Note: object map are split in sections with max size 2035?
153166
* each section are 2 bytes size + data bytes + 2 bytes crc
154167
* size value are data bytes + 2 and to calculate crc are used
155168
* 2 bytes size + data bytes
@@ -220,7 +233,7 @@ bool dwgReader::readDwgHandles( dwgBuffer *dbuf, duint32 offset, duint32 size )
220233
*/
221234
bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
222235
{
223-
QgsDebugMsg( "Entering." );
236+
QgsDebugMsgLevel( "Entering.", 4 );
224237

225238
bool ret = true;
226239
bool ret2 = true;
@@ -740,7 +753,7 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
740753
}
741754
}
742755

743-
#ifdef QGISDEBUG
756+
#if 0
744757
//RLZ: parse remaining object controls, TODO: implement all
745758
mit = ObjectMap.find( hdr.viewCtrl );
746759
if ( mit == ObjectMap.end() )
@@ -862,12 +875,12 @@ bool dwgReader::readDwgTables( DRW_Header &hdr, dwgBuffer *dbuf )
862875
ret2 = vpEntHeader.parseDwg( version, &buff, bs );
863876
if ( ret )
864877
ret = ret2;
865-
#endif
878+
#endif // 0
866879
}
867880
delete[]tmpByteStr;
868881
}
869882
}
870-
#endif
883+
#endif // 0
871884

872885
return ret;
873886
}
@@ -915,6 +928,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
915928
dwgBuffer buff( tmpByteStr, size, &decoder );
916929
DRW_Block bk;
917930
ret2 = bk.parseDwg( version, &buff, bs );
931+
if ( !ret2 )
932+
{
933+
QgsDebugMsg( "parseDwg failed" );
934+
}
918935
delete[]tmpByteStr;
919936
ret = ret && ret2;
920937
parseAttribs( &bk );
@@ -953,6 +970,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
953970
oc = mit->second;
954971
ObjectMap.erase( mit );
955972
ret2 = readDwgEntity( dbuf, oc, intfa );
973+
if ( !ret2 )
974+
{
975+
QgsDebugMsg( "readDwgEntity failed" );
976+
}
956977
ret = ret && ret2;
957978
}
958979
if ( nextH == bkr->lastEH )
@@ -973,13 +994,17 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
973994
ret = false;
974995
continue;
975996
}
976-
else //foud entity reads it
997+
else //found entity, read it
977998
{
978999
oc = mit->second;
9791000
ObjectMap.erase( mit );
9801001
QgsDebugMsgLevel( QString( "Blocks, parsing entity: 0x%1 loc=%2" ).arg( oc.handle, 0, 16 ).arg( oc.loc ), 5 );
9811002

9821003
ret2 = readDwgEntity( dbuf, oc, intfa );
1004+
if ( !ret2 )
1005+
{
1006+
QgsDebugMsg( "readDwgEntity failed" );
1007+
}
9831008
ret = ret && ret2;
9841009
}
9851010
}
@@ -1010,6 +1035,10 @@ bool dwgReader::readDwgBlocks( DRW_Interface &intfa, dwgBuffer *dbuf )
10101035
DRW_Block end;
10111036
end.isEnd = true;
10121037
ret2 = end.parseDwg( version, &buff1, bs );
1038+
if ( !ret2 )
1039+
{
1040+
QgsDebugMsg( QString( "parseDwg failed" ) );
1041+
}
10131042
delete[]tmpByteStr;
10141043
ret = ret && ret2;
10151044
if ( bk.parentHandle == DRW::NoHandle ) bk.parentHandle = bkr->handle;

‎external/libdxfrw/intern/dxfreader.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
15+
1316
#include <cstdlib>
1417
#include <fstream>
1518
#include <string>
@@ -20,6 +23,14 @@
2023

2124
#include "qgslogger.h"
2225

26+
#ifndef DWGDEBUG
27+
#undef QgsDebugCall
28+
#undef QgsDebugMsg
29+
#undef QgsDebugMsgLevel
30+
#define QgsDebugCall
31+
#define QgsDebugMsg(str)
32+
#define QgsDebugMsgLevel(str, level)
33+
#endif
2334

2435
bool dxfReader::readRec( int *codeData )
2536
{
@@ -219,6 +230,7 @@ bool dxfReaderAscii::readCode( int *code )
219230

220231
return filestr->good();
221232
}
233+
222234
bool dxfReaderAscii::readString( std::string *text )
223235
{
224236
type = STRING;
@@ -271,27 +283,15 @@ bool dxfReaderAscii::readInt64()
271283

272284
bool dxfReaderAscii::readDouble()
273285
{
286+
bool ok = false;
274287
type = DOUBLE;
275288
std::string text;
276289
if ( readString( &text ) )
277290
{
278-
#if defined(__APPLE__)
279-
int succeeded = sscanf( & ( text[0] ), "%lg", &doubleData );
280-
if ( succeeded != 1 )
281-
{
282-
QgsDebugMsg( QString( "reading double error:%1" ).arg( text.c_str() ) );
283-
}
284-
#else
285-
std::istringstream sd( text );
286-
sd >> doubleData;
291+
doubleData = QString::fromStdString( text ).toDouble( &ok );
287292
QgsDebugMsg( QString( "%1" ).arg( doubleData ) );
288-
#endif
289-
return true;
290-
}
291-
else
292-
{
293-
return false;
294293
}
294+
return ok;
295295
}
296296

297297
//saved as int or add a bool member??

‎external/libdxfrw/libdxfrw.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
1111
******************************************************************************/
1212

13+
// uncomment to get detailed debug output on DWG read. Caution: this option makes DWG import super-slow!
14+
// #define DWGDEBUG 1
1315

1416
#include "libdxfrw.h"
17+
1518
#include <fstream>
1619
#include <algorithm>
1720
#include <sstream>
@@ -24,6 +27,15 @@
2427

2528
#include "qgslogger.h"
2629

30+
#ifndef DWGDEBUG
31+
#undef QgsDebugCall
32+
#undef QgsDebugMsg
33+
#undef QgsDebugMsgLevel
34+
#define QgsDebugCall
35+
#define QgsDebugMsg(str)
36+
#define QgsDebugMsgLevel(str, level)
37+
#endif
38+
2739
#if __cplusplus >= 201500
2840
#define FALLTHROUGH [[fallthrough]];
2941
#elif defined(__clang__)
@@ -2314,7 +2326,6 @@ bool dxfRW::processTables()
23142326
bool dxfRW::processLType()
23152327
{
23162328
QgsDebugMsg( "Entering." );
2317-
23182329
int code;
23192330
std::string sectionstr;
23202331
bool reading = false;

‎python/core/auto_generated/qgspointxy.sip.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Multiply x and y by the given value
262262
sipRes = qHash( *sipCpp );
263263
%End
264264

265-
}; // class QgsPoint
265+
}; // class QgsPointXY
266266

267267

268268

‎src/app/dwg/qgsdwgimportdialog.cpp

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@ void QgsDwgImportDialog::pbImportDrawing_clicked()
246246

247247
QgsDwgImporter importer( mDatabaseFileWidget->filePath(), mCrsSelector->crs() );
248248

249+
lblMessage->setVisible( true );
250+
249251
QString error;
250-
if ( importer.import( leDrawing->text(), error, cbExpandInserts->isChecked(), cbUseCurves->isChecked() ) )
252+
if ( importer.import( leDrawing->text(), error, cbExpandInserts->isChecked(), cbUseCurves->isChecked(), lblMessage ) )
251253
{
252254
bar->pushMessage( tr( "Drawing import completed." ), Qgis::Info, 4 );
253255
}
@@ -360,40 +362,67 @@ void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, const QString &n
360362
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::MultiLineHeight, QgsProperty::fromExpression( QStringLiteral( "CASE WHEN interlin<0 THEN 1 ELSE interlin*1.5 END" ) ) );
361363
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionX, QgsProperty::fromExpression( QStringLiteral( "$x" ) ) );
362364
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionY, QgsProperty::fromExpression( QStringLiteral( "$y" ) ) );
363-
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Hali, QgsProperty::fromExpression( QStringLiteral( "CASE"
364-
" WHEN etype=%1 THEN"
365-
" CASE"
366-
" WHEN alignv IN (1,4,7) THEN 'Left'"
367-
" WHEN alignv IN (2,5,6) THEN 'Center'"
368-
" ELSE 'Right'"
369-
" END"
370-
" ELSE"
371-
" CASE"
372-
" WHEN alignh=0 THEN 'Left'"
373-
" WHEN alignh=1 THEN 'Center'"
374-
" WHEN alignh=2 THEN 'Right'"
375-
" WHEN alignh=3 THEN 'Left'"
376-
" WHEN alignh=4 THEN 'Left'"
377-
" END "
378-
" END" ).arg( DRW::MTEXT ) ) );
379-
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Vali, QgsProperty::fromExpression( QStringLiteral( "CASE"
380-
" WHEN etype=%1 THEN"
381-
" CASE"
382-
" WHEN alignv < 4 THEN 'Top'"
383-
" WHEN alignv < 7 THEN 'Half'"
384-
" ELSE 'Bottom'"
385-
" END"
386-
" ELSE"
387-
" CASE"
388-
" WHEN alignv=0 THEN 'Base'"
389-
" WHEN alignv=1 THEN 'Bottom'"
390-
" WHEN alignv=2 THEN 'Half'"
391-
" WHEN alignv=3 THEN 'Top'"
392-
" END"
393-
" END" ).arg( DRW::MTEXT ) ) );
394-
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle*180.0/pi()" ) ) );
395-
396-
pls.placement = QgsPalLayerSettings::OrderedPositionsAroundPoint;
365+
366+
// DXF TEXT
367+
// vertical: 0 = Base, 1 = Bottom, 2 = Middle, 3 = Top, default Base
368+
// horizontal: 0 = Left, 1 = Center, 2 = Right, 3 = Aligned (if Base), 4 = Middle (if Base), default Left
369+
370+
// DXF MTEXT
371+
// 1 = Top left; 2 = Top center; 3 = Top right
372+
// 4 = Middle left; 5 = Middle center; 6 = Middle right
373+
// 7 = Bottom left; 8 = Bottom center; 9 = Bottom right
374+
375+
// QGIS Quadrant
376+
// 0 QuadrantAboveLeft, 1 QuadrantAbove, 2 QuadrantAboveRight,
377+
// 3 QuadrantLeft, 4 QuadrantOver, 5 QuadrantRight,
378+
// 6 QuadrantBelowLeft, 7 QuadrantBelow, 8 QuadrantBelowRight,
379+
380+
pls.dataDefinedProperties().setProperty(
381+
QgsPalLayerSettings::Hali,
382+
QgsProperty::fromExpression( QStringLiteral(
383+
"CASE"
384+
" WHEN etype=%1 THEN"
385+
" CASE"
386+
" WHEN textgen % 3=2 THEN 'Center'"
387+
" WHEN textgen % 3=0 THEN 'Right'"
388+
" ELSE 'Left'"
389+
" END"
390+
" ELSE"
391+
" CASE"
392+
" WHEN alignh=1 THEN 'Center'"
393+
" WHEN alignh=2 THEN 'Right'"
394+
" ELSE 'Left'"
395+
" END"
396+
" END"
397+
).arg( DRW::MTEXT )
398+
)
399+
);
400+
401+
pls.dataDefinedProperties().setProperty(
402+
QgsPalLayerSettings::Vali,
403+
QgsProperty::fromExpression( QStringLiteral(
404+
"CASE"
405+
" WHEN etype=%1 THEN"
406+
" CASE"
407+
" WHEN textgen<4 THEN 'Top'"
408+
" WHEN textgen<7 THEN 'Half'"
409+
" ELSE 'Bottom'"
410+
" END"
411+
" ELSE"
412+
" CASE"
413+
" WHEN alignv=1 THEN 'Bottom'"
414+
" WHEN alignv=2 THEN 'Half'"
415+
" WHEN alignv=3 THEN 'Top'"
416+
" ELSE 'Base'"
417+
" END"
418+
" END"
419+
).arg( DRW::MTEXT )
420+
)
421+
);
422+
423+
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle" ) ) );
424+
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::AlwaysShow, QgsProperty::fromExpression( QStringLiteral( "1" ) ) );
425+
397426
l->setLabeling( new QgsVectorLayerSimpleLabeling( pls ) );
398427
l->setLabelsEnabled( true );
399428
}

‎src/app/dwg/qgsdwgimporter.cpp

Lines changed: 505 additions & 235 deletions
Large diffs are not rendered by default.

‎src/app/dwg/qgsdwgimporter.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717

1818
#include "drw_interface.h"
1919

20+
#include <QCoreApplication>
2021
#include <QString>
22+
#include <QTime>
23+
2124
#include <ogr_api.h>
2225

2326
#include "qgsabstractgeometry.h"
2427
#include "qgsogrutils.h"
2528

2629
class QgsCompoundCurve;
30+
class QgsLineString;
31+
class QgsCircularString;
2732
class QgsQgsCoordinateReferenceSystem;
33+
class QLabel;
34+
class QTextCodec;
2835

2936
class QgsDwgImporter : public DRW_Interface
3037
{
38+
Q_DECLARE_TR_FUNCTIONS( QgsDwgImporter )
39+
3140
public:
3241
QgsDwgImporter( const QString &database, const QgsCoordinateReferenceSystem &crs );
3342
~QgsDwgImporter() override;
3443

35-
bool import( const QString &drawing, QString &error, bool expandInserts, bool useCurves );
44+
bool import( const QString &drawing, QString &error, bool expandInserts, bool useCurves, QLabel *label );
3645

3746
//! Called when header is parsed.
3847
void addHeader( const DRW_Header *data ) override;
@@ -172,18 +181,27 @@ class QgsDwgImporter : public DRW_Interface
172181
bool exec( const QString &sql, bool logError = true );
173182
OGRLayerH query( const QString &sql );
174183

184+
void progress( const QString &msg );
185+
QString decode( const std::string &s ) const;
186+
void cleanText( QString &s );
187+
175188
void addEntity( OGRFeatureDefnH dfn, OGRFeatureH f, const DRW_Entity &data );
176-
QString colorString( int color, int color24, int transparency, const std::string &layer ) const;
177-
double lineWidth( int lWeight, const std::string &layer ) const;
178-
QString linetypeString( const std::string &linetype, const std::string &layer ) const;
189+
QString colorString( int color, int color24, int transparency, const QString &layer ) const;
190+
double lineWidth( int lWeight, const QString &layer ) const;
191+
QString linetypeString( const QString &linetype, const QString &layer ) const;
179192
void setString( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, const std::string &value ) const;
193+
void setString( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, const QString &value ) const;
194+
void setString( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, const char *value ) const;
180195
void setDouble( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, double value ) const;
181196
void setInteger( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, int value ) const;
182197
void setPoint( OGRFeatureDefnH dfn, OGRFeatureH f, const QString &field, const DRW_Coord &value ) const;
183198

184199
bool curveFromLWPolyline( const DRW_LWPolyline &data, QgsCompoundCurve &cc );
200+
bool circularStringFromArc( const DRW_Arc &data, QgsCircularString &c );
201+
bool lineFromSpline( const DRW_Spline &data, QgsLineString &l );
185202

186203
bool expandInserts( QString &error );
204+
bool expandInserts( QString &error, int block, QTransform base );
187205

188206
bool createFeature( OGRLayerH layer, OGRFeatureH f, const QgsAbstractGeometry &g ) const;
189207

@@ -200,4 +218,10 @@ class QgsDwgImporter : public DRW_Interface
200218
QHash<QString, double> mLayerLinewidth;
201219
QHash<QString, QString> mLayerLinetype;
202220
QHash<QString, QString> mLinetype;
221+
QHash<QString, int> mBlocks;
222+
223+
QLabel *mLabel = nullptr;
224+
int mEntities = 0;
225+
QTextCodec *mCodec = nullptr;
226+
QTime mTime;
203227
};

‎src/core/qgspointxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class CORE_EXPORT QgsPointXY
340340

341341
friend uint qHash( const QgsPointXY &pnt );
342342

343-
}; // class QgsPoint
343+
}; // class QgsPointXY
344344

345345
Q_DECLARE_METATYPE( QgsPointXY )
346346

0 commit comments

Comments
 (0)
Please sign in to comment.