Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dwg import: progress display
  • Loading branch information
jef-n committed Feb 19, 2019
1 parent 0f6421d commit f12cac7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -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 );
}
Expand Down
32 changes: 29 additions & 3 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -36,6 +36,9 @@
#include <QFileInfo>
#include <QVector>
#include <QTransform>
#include <QLabel>
#include <QTextCodec>
#include <QRegularExpression>

#include <typeinfo>

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

Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 ) );
Expand Down
12 changes: 11 additions & 1 deletion src/app/dwg/qgsdwgimporter.h
Expand Up @@ -17,7 +17,10 @@

#include "drw_interface.h"

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

#include <ogr_api.h>

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

class QgsDwgImporter : public DRW_Interface
{
Expand All @@ -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;
Expand Down Expand Up @@ -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.