Skip to content
Permalink
Browse files

dwg import: progress display

  • Loading branch information
jef-n committed Feb 19, 2019
1 parent 0f6421d commit f12cac7cb4671fab0adc31ff5beb171e0843b646
Showing with 43 additions and 5 deletions.
  1. +3 −1 src/app/dwg/qgsdwgimportdialog.cpp
  2. +29 −3 src/app/dwg/qgsdwgimporter.cpp
  3. +11 −1 src/app/dwg/qgsdwgimporter.h
@@ -246,8 +246,10 @@ void QgsDwgImportDialog::pbImportDrawing_clicked()

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

lblMessage->setVisible( true );

QString error;
if ( importer.import( leDrawing->text(), error, cbExpandInserts->isChecked(), cbUseCurves->isChecked() ) )
if ( importer.import( leDrawing->text(), error, cbExpandInserts->isChecked(), cbUseCurves->isChecked(), lblMessage ) )
{
bar->pushMessage( tr( "Drawing import completed." ), Qgis::Info, 4 );
}
@@ -36,6 +36,9 @@
#include <QFileInfo>
#include <QVector>
#include <QTransform>
#include <QLabel>
#include <QTextCodec>
#include <QRegularExpression>

#include <typeinfo>

@@ -70,6 +73,7 @@ QgsDwgImporter::QgsDwgImporter( const QString &database, const QgsCoordinateRefe
, mCrs( crs.srsid() )
, mCrsH( nullptr )
, mUseCurves( true )
, mEntities( 0 )
{
QgsDebugCall;

@@ -169,10 +173,12 @@ QgsDwgImporter::~QgsDwgImporter()
}
}

bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpandInserts, bool useCurves )
bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpandInserts, bool useCurves, QLabel *label )
{
QgsDebugCall;

mLabel = label;

OGRwkbGeometryType lineGeomType, hatchGeomType;
if ( useCurves )
{
@@ -483,6 +489,8 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
return false;
}

progress( tr( "Creating database…" ) );

// create database
mDs.reset( OGR_Dr_CreateDataSource( driver, mDatabase.toUtf8().constData(), nullptr ) );
if ( !mDs )
@@ -491,6 +499,8 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
return false;
}

progress( tr( "Creating tables…" ) );

startTransaction();

Q_FOREACH ( const table &t, tables )
@@ -543,6 +553,8 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa

commitTransaction();

progress( tr( "Importing drawing…" ) );

OGRLayerH layer = OGR_DS_GetLayerByName( mDs.get(), "drawing" );
Q_ASSERT( layer );

@@ -591,6 +603,9 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa

DRW::error result( DRW::BAD_NONE );

mTime.start();
mEntities = 0;

if ( fi.suffix().compare( QLatin1String( "dxf" ), Qt::CaseInsensitive ) == 0 )
{
//loads dxf
@@ -1218,6 +1233,14 @@ void QgsDwgImporter::endBlock()
void QgsDwgImporter::addEntity( OGRFeatureDefnH dfn, OGRFeatureH f, const DRW_Entity &data )
{
QgsDebugMsgLevel( QStringLiteral( "handle:0x%1 block:0x%2" ).arg( data.handle, 0, 16 ).arg( mBlockHandle, 0, 16 ), 5 );

mEntities++;
if ( mTime.elapsed() > 1000 )
{
progress( tr( "%1 entities processed." ).arg( mEntities ) );
mTime.restart();
}

SETINTEGER( handle );
setInteger( dfn, f, QStringLiteral( "block" ), mBlockHandle );
SETINTEGER( eType );
@@ -2547,13 +2570,16 @@ bool QgsDwgImporter::expandInserts( QString &error )

OGR_L_ResetReading( inserts );

mTime.start();

gdal::ogr_feature_unique_ptr insert;
int i = 0, errors = 0;
for ( int i = 0; true; ++i )
{
if ( i % 1000 == 0 )
if ( mTime.elapsed() > 1000 )
{
QgsDebugMsg( QStringLiteral( "Expanding inserts %1/%2..." ).arg( i ).arg( n ) );
progress( tr( "Expanding block reference %1/%2…" ).arg( i ).arg( n ) );
mTime.restart();
}

insert.reset( OGR_L_GetNextFeature( inserts ) );
@@ -17,7 +17,10 @@

#include "drw_interface.h"

#include <QCoreApplication>
#include <QString>
#include <QTime>

#include <ogr_api.h>

#include "qgsabstractgeometry.h"
@@ -27,6 +30,8 @@ class QgsCompoundCurve;
class QgsLineString;
class QgsCircularString;
class QgsQgsCoordinateReferenceSystem;
class QLabel;
class QTextCodec;

class QgsDwgImporter : public DRW_Interface
{
@@ -36,7 +41,7 @@ class QgsDwgImporter : public DRW_Interface
QgsDwgImporter( const QString &database, const QgsCoordinateReferenceSystem &crs );
~QgsDwgImporter() override;

bool import( const QString &drawing, QString &error, bool expandInserts, bool useCurves );
bool import( const QString &drawing, QString &error, bool expandInserts, bool useCurves, QLabel *label );

//! Called when header is parsed.
void addHeader( const DRW_Header *data ) override;
@@ -206,4 +211,9 @@ class QgsDwgImporter : public DRW_Interface
QHash<QString, double> mLayerLinewidth;
QHash<QString, QString> mLayerLinetype;
QHash<QString, QString> mLinetype;

QLabel *mLabel = nullptr;
int mEntities = 0;
QTextCodec *mCodec = nullptr;
QTime mTime;
};

0 comments on commit f12cac7

Please sign in to comment.
You can’t perform that action at this time.