@@ -2194,7 +2194,7 @@ void QgsDwgImporter::addKnot( const DRW_Entity &data )
2194
2194
2195
2195
void QgsDwgImporter::addInsert ( const DRW_Insert &data )
2196
2196
{
2197
- OGRLayerH layer = OGR_DS_GetLayerByName ( mDs .get (), " inserts" );
2197
+ OGRLayerH layer = OGR_DS_GetLayerByName ( mDs .get (), " inserts" );
2198
2198
Q_ASSERT ( layer );
2199
2199
OGRFeatureDefnH dfn = OGR_L_GetLayerDefn ( layer );
2200
2200
Q_ASSERT ( dfn );
@@ -2615,10 +2615,10 @@ bool QgsDwgImporter::expandInserts( QString &error )
2615
2615
return false ;
2616
2616
}
2617
2617
2618
- QHash<QString, int > blockhandle;
2619
-
2620
2618
OGR_L_ResetReading ( blocks );
2621
2619
2620
+ mBlocks .clear ();
2621
+
2622
2622
gdal::ogr_feature_unique_ptr f;
2623
2623
for ( ;; )
2624
2624
{
@@ -2628,20 +2628,26 @@ bool QgsDwgImporter::expandInserts( QString &error )
2628
2628
2629
2629
QString name = QString::fromUtf8 ( OGR_F_GetFieldAsString ( f.get (), nameIdx ) );
2630
2630
int handle = OGR_F_GetFieldAsInteger ( f.get (), handleIdx );
2631
- blockhandle .insert ( name, handle );
2631
+ mBlocks .insert ( name, handle );
2632
2632
}
2633
2633
2634
- OGRLayerH inserts = OGR_DS_GetLayerByName ( mDs .get (), " inserts" );
2634
+ return expandInserts ( error, -1 , QTransform () );
2635
+ }
2636
+
2637
+ bool QgsDwgImporter::expandInserts ( QString &error, int block, QTransform base )
2638
+ {
2639
+ QgsDebugMsg ( QString ( " expanding block:%1" ).arg ( block ) );
2640
+ OGRLayerH inserts = OGR_DS_ExecuteSQL ( mDs .get (), QStringLiteral ( " SELECT * FROM inserts WHERE block=%1" ).arg ( block ).toUtf8 ().constData (), nullptr , nullptr );
2635
2641
if ( !inserts )
2636
2642
{
2637
- QgsDebugMsg ( QStringLiteral ( " could not open layer 'inserts'" ) );
2643
+ QgsDebugMsg ( QStringLiteral ( " could not query layer 'inserts'" ) );
2638
2644
return false ;
2639
2645
}
2640
2646
2641
- dfn = OGR_L_GetLayerDefn ( inserts );
2647
+ OGRFeatureDefnH dfn = OGR_L_GetLayerDefn ( inserts );
2642
2648
Q_ASSERT ( dfn );
2643
2649
2644
- nameIdx = OGR_FD_GetFieldIndex ( dfn, " name" );
2650
+ int nameIdx = OGR_FD_GetFieldIndex ( dfn, " name" );
2645
2651
int xscaleIdx = OGR_FD_GetFieldIndex ( dfn, " xscale" );
2646
2652
int yscaleIdx = OGR_FD_GetFieldIndex ( dfn, " yscale" );
2647
2653
int zscaleIdx = OGR_FD_GetFieldIndex ( dfn, " zscale" );
@@ -2669,17 +2675,22 @@ bool QgsDwgImporter::expandInserts( QString &error )
2669
2675
2670
2676
OGR_L_ResetReading ( inserts );
2671
2677
2672
- mTime .start ();
2678
+ if ( block == -1 )
2679
+ mTime .start ();
2673
2680
2674
2681
gdal::ogr_feature_unique_ptr insert;
2675
2682
int i = 0 , errors = 0 ;
2676
2683
for ( int i = 0 ; true ; ++i )
2677
2684
{
2678
- if ( mTime .elapsed () > 1000 )
2685
+ if ( block == - 1 && mTime .elapsed () > 1000 )
2679
2686
{
2680
2687
progress ( tr ( " Expanding block reference %1/%2…" ).arg ( i ).arg ( n ) );
2681
2688
mTime .restart ();
2682
2689
}
2690
+ else if ( i % 1000 == 0 )
2691
+ {
2692
+ QgsDebugMsg ( QStringLiteral ( " %1: expanding insert %2/%3…" ).arg ( block, 0 , 16 ).arg ( i ).arg ( n ) );
2693
+ }
2683
2694
2684
2695
insert.reset ( OGR_L_GetNextFeature ( inserts ) );
2685
2696
if ( !insert )
@@ -2714,7 +2725,7 @@ bool QgsDwgImporter::expandInserts( QString &error )
2714
2725
}
2715
2726
double blockLinewidth = OGR_F_GetFieldAsDouble ( insert.get (), linewidthIdx );
2716
2727
2717
- int handle = blockhandle .value ( name, -1 );
2728
+ int handle = mBlocks .value ( name, -1 );
2718
2729
if ( handle < 0 )
2719
2730
{
2720
2731
QgsDebugMsg ( QStringLiteral ( " Block '%1' not found" ).arg ( name ) );
@@ -2728,18 +2739,23 @@ bool QgsDwgImporter::expandInserts( QString &error )
2728
2739
2729
2740
QTransform t;
2730
2741
t.translate ( p.x (), p.y () ).scale ( xscale, yscale ).rotateRadians ( angle );
2742
+ t *= base;
2731
2743
2744
+ OGRLayerH src = nullptr ;
2732
2745
Q_FOREACH ( const QString &name, QStringList () << " hatches" << " lines" << " polylines" << " texts" << " points" )
2733
2746
{
2747
+ if ( src )
2748
+ OGR_DS_ReleaseResultSet ( mDs .get (), src );
2749
+
2734
2750
OGRLayerH src = OGR_DS_ExecuteSQL ( mDs .get (), QStringLiteral ( " SELECT * FROM %1 WHERE block=%2" ).arg ( name ).arg ( handle ).toUtf8 ().constData (), nullptr , nullptr );
2735
2751
if ( !src )
2736
2752
{
2737
- QgsDebugMsg ( QStringLiteral ( " %1: could not execute query for block %2 " ).arg ( name ). arg ( handle ) );
2753
+ QgsDebugMsg ( QStringLiteral ( " %1: could not open layer %1 " ).arg ( name ) );
2738
2754
continue ;
2739
2755
}
2740
2756
2741
- OGRLayerH dst = OGR_DS_GetLayerByName ( mDs . get (), name. toUtf8 (). constData () );
2742
- Q_ASSERT ( dst );
2757
+ GIntBig n = OGR_L_GetFeatureCount ( src, 0 );
2758
+ Q_UNUSED ( n );
2743
2759
2744
2760
dfn = OGR_L_GetLayerDefn ( src );
2745
2761
Q_ASSERT ( dfn );
@@ -2762,10 +2778,18 @@ bool QgsDwgImporter::expandInserts( QString &error )
2762
2778
2763
2779
OGR_L_ResetReading ( src );
2764
2780
2781
+ OGRLayerH dst = OGR_DS_GetLayerByName ( mDs .get (), name.toUtf8 ().constData () );
2782
+ Q_ASSERT ( dst );
2783
+
2765
2784
gdal::ogr_feature_unique_ptr f;
2766
2785
int j = 0 ;
2767
2786
for ( ;; )
2768
2787
{
2788
+ if ( j % 1000 == 0 )
2789
+ {
2790
+ QgsDebugMsg ( QStringLiteral ( " %1.%2: %3/%4 copied" ).arg ( block, 0 , 16 ).arg ( handle, 0 , 16 ).arg ( j ).arg ( n ) );
2791
+ }
2792
+
2769
2793
f.reset ( OGR_L_GetNextFeature ( src ) );
2770
2794
if ( !f )
2771
2795
break ;
@@ -2844,9 +2868,15 @@ bool QgsDwgImporter::expandInserts( QString &error )
2844
2868
++j;
2845
2869
}
2846
2870
2871
+ QgsDebugMsgLevel ( QStringLiteral ( " %1: %2 features copied" ).arg ( name ).arg ( j ), 5 );
2872
+ }
2873
+
2874
+ if ( src )
2847
2875
OGR_DS_ReleaseResultSet ( mDs .get (), src );
2848
2876
2849
- QgsDebugMsgLevel ( QStringLiteral ( " %1: %2 features copied" ).arg ( name ).arg ( j ), 5 );
2877
+ if ( !expandInserts ( error, handle, t ) )
2878
+ {
2879
+ QgsDebugMsg ( QString ( " %1: Expanding %2 failed" ).arg ( block ).arg ( handle ) );
2850
2880
}
2851
2881
}
2852
2882
@@ -2910,12 +2940,12 @@ void QgsDwgImporter::cleanText( QString &res )
2910
2940
{
2911
2941
QString prev ( res );
2912
2942
2913
- res = res.replace ( QRegularExpression ( " \\\\ f[0-9A-Za-z| ]{0,};" ), QStringLiteral ( " " ) ); // font setting
2914
- res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^){" ), QStringLiteral ( " \\ 1" ) ); // grouping
2915
- res = res.replace ( QRegularExpression ( " ([^\\\\ ])}" ), QStringLiteral ( " \\ 1" ) );
2916
- res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [loLOkx]" ), QStringLiteral ( " \\ 1" ) ); // underline, overstrike, strike through
2917
- res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [HWACQ ]\\ d*(\\ .\\ d*)?[xX]?;?" ), QStringLiteral ( " \\ 1" ) ); // text height, width, alignment, color and slanting
2918
- res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [ACQ]\\ d+;" ), QStringLiteral ( " \\ 1" ) ); // alignment, color and slanting
2943
+ res = res.replace ( QRegularExpression ( " \\\\ f[0-9A-Za-z| ]{0,};" ), QString ( " " ) ); // font setting
2944
+ res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^){" ), QStringLiteral ( " \\ 1" ) ); // grouping
2945
+ res = res.replace ( QRegularExpression ( " ([^\\\\ ])}" ), QStringLiteral ( " \\ 1" ) );
2946
+ res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [loLOkx]" ), QStringLiteral ( " \\ 1" ) ); // underline, overstrike, strike through
2947
+ res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [HhWwAaCcQq ]\\ d*(\\ .\\ d*)?[xX]?;?" ), QStringLiteral ( " \\ 1" ) ); // text height, width, alignment, color and slanting
2948
+ res = res.replace ( QRegularExpression ( " ([^\\\\ ]|^)\\\\ [ACQ]\\ d+;" ), QStringLiteral ( " \\ 1" ) ); // alignment, color and slanting
2919
2949
2920
2950
if ( res == prev )
2921
2951
break ;
0 commit comments