Skip to content

Commit

Permalink
dxf2shp cleanup (fixes #1236)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9132 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 23, 2008
1 parent 74baa73 commit 07c905b
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 406 deletions.
506 changes: 234 additions & 272 deletions src/plugins/dxf2shp_converter/builder.cpp

Large diffs are not rendered by default.

62 changes: 23 additions & 39 deletions src/plugins/dxf2shp_converter/builder.h
Expand Up @@ -24,13 +24,16 @@
#include "shapelib-1.2.10/shapefil.h"
#include "getInsertions.h"
#include <vector>
#include <fstream>
using namespace std;

class Builder: public DL_CreationAdapter
{
public:
Builder();
Builder(std::string theFname,
int theShapefileType,
double *theGrpXVals, double *theGrpYVals,
std::string *theGrpNames,
int theInsertCount,
bool theConvertText);
~Builder();

void FinalizeAnyPolyline();
Expand All @@ -47,49 +50,35 @@ class Builder: public DL_CreationAdapter
virtual void endSequence();
virtual void addText(const DL_TextData &data);

void set_numlayers(int n);
void set_numpoints(int n);
void set_numlines(int n);
void set_numplines(int n);
void set_shptype(int n);

void set_convertText(bool);
void initBuilder(string, int, double*, double*, string*, int, bool);
void print_shpObjects();

int ret_numlabels();
int ret_numlayers();
int ret_numpoints();
int ret_numlines();
int ret_numplines();
int ret_shptype();
int ret_textObjectsSize();
string ret_outputshp();
string ret_outputtshp();
bool convertText;


int textObjectsSize();
std::string outputShp();
std::string outputTShp();

private:
string outputdbf;
string outputshp;
string outputtdbf;
string outputtshp;
string logfname;
ofstream logfile;
std::string fname;
int shapefileType; // SHPT_POINT, ...
double *grpXVals;
double *grpYVals;
std::string *grpNames;
int insertCount;
bool convertText;

std::string outputdbf;
std::string outputshp;
std::string outputtdbf;
std::string outputtshp;

vector < DL_VertexData > polyVertex;
vector <SHPObject *> shpObjects; // metto qui tutti gli oggetti letti
vector <DL_TextData> textObjects;
std::vector <DL_VertexData> polyVertex;
std::vector <SHPObject *> shpObjects; // all read objects are stored here
std::vector <DL_TextData> textObjects;

int numlayers;
int numpoints;
int numlines;
int numplines;

int shptype; // 0 ,1 ,2
int shapefileType; // SHPT_POINT, ...
int fetchedprims;
int fetchedtexts;

Expand All @@ -102,11 +91,6 @@ class Builder: public DL_CreationAdapter

SHPObject *currently_Adding_PolyLine;

double *grpXVals;
double *grpYVals;
string *grpNames;
string fname;
int insertCount;

double closePolyX, closePolyY, closePolyZ;
double currentBlockX, currentBlockY;
Expand Down
34 changes: 17 additions & 17 deletions src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
Expand Up @@ -32,7 +32,7 @@
#include <QAction>
#include <QToolBar>

static const char *const sIdent =
static const char *const sIdent =
"$Id: plugin.cpp 6935 2007-05-07 14:29:51Z wonder $";
static const QString sName = QObject::tr("Dxf2Shp Converter");
static const QString sDescription = QObject::tr(
Expand All @@ -47,7 +47,7 @@ static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
//////////////////////////////////////////////////////////////////////

/**
* Constructor for the plugin. The plugin is passed a pointer
* Constructor for the plugin. The plugin is passed a pointer
* an interface object that provides access to exposed functions in QGIS.
* @param theQGisInterface - Pointer to the QGIS interface object
*/
Expand All @@ -60,24 +60,23 @@ dxf2shpConverter::~dxf2shpConverter(){
}

/*
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* added to the plugin registry in the QGIS application.
*/
void dxf2shpConverter::initGui()
{

// Create the action for tool
mQActionPointer = new QAction(QIcon(":/dxf2shpconverter/dxf2shp_converter.png")
, "Dxf2Shp Converter", this);
mQActionPointer = new QAction(QIcon(":/dxf2shpconverter/dxf2shp_converter.png"), "Dxf2Shp Converter", this);

// Set the what's this text
mQActionPointer->setWhatsThis(tr(
"Converts DXF files in Shapefile format"));
mQActionPointer->setWhatsThis(tr("Converts DXF files in Shapefile format"));

// Connect the action to the run
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));

// Add the icon to the toolbar
mQGisIface->addToolBarIcon(mQActionPointer);
mQGisIface->addPluginMenu("&Dxf2Shp", mQActionPointer);

mQGisIface->addPluginMenu(tr("&Dxf2Shp"), mQActionPointer);
}

//method defined in interface
Expand All @@ -87,16 +86,17 @@ void dxf2shpConverter::help()
}

// Slot called when the menu item is activated
// If you created more menu items / toolbar buttons in initiGui, you should
// If you created more menu items / toolbar buttons in initiGui, you should
// create a separate handler for each action - this single run() method will
// not be enough
void dxf2shpConverter::run()
{
dxf2shpConverterGui *myPluginGui =
new dxf2shpConverterGui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);

myPluginGui->setAttribute(Qt::WA_DeleteOnClose);

connect(myPluginGui, SIGNAL(createLayer(QString)), this, SLOT(addMyLayer(QString)));
connect(myPluginGui, SIGNAL(createLayer(QString,QString)), this, SLOT(addMyLayer(QString,QString)));

myPluginGui->show();
}
Expand All @@ -105,14 +105,14 @@ void dxf2shpConverter::run()
void dxf2shpConverter::unload()
{
// remove the GUI
mQGisIface->removePluginMenu("&Dxf2Shp", mQActionPointer);
mQGisIface->removePluginMenu(tr("&Dxf2Shp"), mQActionPointer);
mQGisIface->removeToolBarIcon(mQActionPointer);
delete mQActionPointer;
}

void dxf2shpConverter::addMyLayer(QString myfname)
void dxf2shpConverter::addMyLayer(QString myfname,QString mytitle)
{
mQGisIface->addVectorLayer(myfname, "Converted_Layer", "ogr");
mQGisIface->addVectorLayer(myfname, mytitle, "ogr");
}

//////////////////////////////////////////////////////////////////////////
Expand All @@ -126,8 +126,8 @@ void dxf2shpConverter::addMyLayer(QString myfname)
//////////////////////////////////////////////////////////////////////////


/**
* Required extern functions needed for every plugin
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/dxf2shp_converter/dxf2shpconverter.h
Expand Up @@ -34,8 +34,8 @@ class QgisInterface;
*/
class dxf2shpConverter: public QObject, public QgisPlugin
{
Q_OBJECT;
public:
Q_OBJECT
public:

//////////////////////////////////////////////////////////////////////
//
Expand All @@ -62,7 +62,7 @@ class dxf2shpConverter: public QObject, public QgisPlugin
//! show the help document
void help();

void addMyLayer(QString);
void addMyLayer(QString,QString);

private:

Expand Down
112 changes: 52 additions & 60 deletions src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
Expand Up @@ -26,89 +26,81 @@
#include <QFile>
#include <QDir>

#include "qgslogger.h"

dxf2shpConverterGui::dxf2shpConverterGui(QWidget *parent, Qt::WFlags fl):
QDialog(parent, fl)
{
setupUi(this);
}

dxf2shpConverterGui::~dxf2shpConverterGui(){}
dxf2shpConverterGui::~dxf2shpConverterGui()
{
}

void dxf2shpConverterGui::on_buttonBox_accepted()
{

QString inf = nomein->text();
QString inf = name->text();
QString outd = dirout->text();

if (inf.size() > 1)
{
int type = SHPT_POINT;
bool convtexts = convertTextCheck->checkState();

int type = 1;
bool convtexts;

if(convertTextCheck->checkState())
convtexts = true;
else
convtexts = false;
if (polyline->isChecked())
type = SHPT_ARC;

if (zero->isChecked())
type = 0;
if (polygon->isChecked())
type = SHPT_POLYGON;

if (uno->isChecked())
type = 2;
if (point->isChecked())
type = SHPT_POINT;

if (due->isChecked())
type = 1;
InsertRetrClass *insertRetr = new InsertRetrClass();

InsertRetrClass * insertRetr = new InsertRetrClass();

DL_Dxf * dxf_inserts = new DL_Dxf();

if (!dxf_inserts->in((string)(inf.toLatin1()), insertRetr)) { // if file open failed

cout << "Aborting: The input file could not be opened.\n";
DL_Dxf *dxf_inserts = new DL_Dxf();

if ( !dxf_inserts->in(inf.toStdString(), insertRetr) )
{
// if file open failed
QgsDebugMsg( "Aborting: The input file could not be opened." );
return ;

}

Builder * parserClass = new Builder();
parserClass->initBuilder((string)(outd.toLatin1()), type, insertRetr->XVals, insertRetr->YVals, insertRetr->Names,
insertRetr->countInserts, convtexts);
Builder *parser= new Builder(
outd.toStdString(),
type,
insertRetr->XVals, insertRetr->YVals,
insertRetr->Names,
insertRetr->countInserts,
convtexts);

cout << "Finished getting insertions. Count: " << insertRetr->countInserts <<"\n";
QgsDebugMsg( QString("Finished getting insertions. Count: %1").arg( insertRetr->countInserts ) );

DL_Dxf * dxf_Main = new DL_Dxf();

if (!dxf_Main->in((string)(inf.toLatin1()), parserClass)) { // if file open failed

cout << "Aborting: The input file could not be opened.\n";

return ;
DL_Dxf *dxf_Main = new DL_Dxf();

if ( !dxf_Main->in( inf.toStdString(), parser) )
{
// if file open failed
QgsDebugMsg( "Aborting: The input file could not be opened." );
return;
}

delete insertRetr;
delete dxf_inserts;
delete dxf_Main;
parserClass->print_shpObjects();
bool textsPresent;
if(parserClass->ret_textObjectsSize() > 0)
textsPresent = true;
else
textsPresent = false;

parser->print_shpObjects();

QString mystring = QString((parserClass->ret_outputshp()).c_str());
emit createLayer( QString((parser->outputShp()).c_str()), QString("Data layer") );

emit(createLayer(mystring));

if((convertTextCheck->checkState()) && (textsPresent)) {
mystring = QString((parserClass->ret_outputtshp()).c_str());
emit(createLayer(mystring));
if( convtexts && parser->textObjectsSize()>0 )
{
emit createLayer( QString((parser->outputTShp()).c_str()), QString("Text layer") );
}

delete parserClass;
delete parser;
}
else
{
Expand All @@ -125,8 +117,8 @@ void dxf2shpConverterGui::on_buttonBox_rejected()

void dxf2shpConverterGui::on_buttonBox_helpRequested()
{
QString s = "Fields description:\n"
"* Input DXF file: path to the DXF file to be converted\n"
QString s = tr("Fields description:\n"
"* Input DXF file: path to the DXF file to be converted\n"
"* Output Shp file: desired filename of the ShapeFile to be created\n"
"* Shp output file type: specifies the type of the output shapefile\n"
"* Export text labels checkbox: if checked, an additional shp points layer will be created, "
Expand All @@ -135,7 +127,7 @@ void dxf2shpConverterGui::on_buttonBox_helpRequested()
"---\n"
"Developed by Paolo L. Scala, Barbara Rita Barricelli, Marco Padula\n"
"CNR, Milan Unit (Information Technology), Construction Technologies Institute.\n"
"For support send a mail to scala@itc.cnr.it\n";
"For support send a mail to scala@itc.cnr.it\n");

QMessageBox::information(this, "Help", s);
}
Expand All @@ -156,20 +148,20 @@ void dxf2shpConverterGui::getInputFileName()
{
QSettings settings;

QString s = QFileDialog::getOpenFileName(this, tr(
"Choose a delimited text file to open"), settings.value(
"/Plugin-DelimitedText/text_path", "./").toString(), "Files DXF (*.dxf)");
QString s = QFileDialog::getOpenFileName(this,
tr("Choose a DXF file to open"),
settings.value("/Plugin-DXF/text_path", "./").toString(),
"Files DXF (*.dxf)");

nomein->setText(s);
name->setText(s);
}

void dxf2shpConverterGui::getOutputDir()
{
QSettings settings;

QString s = QFileDialog::getSaveFileName(this,
"Choose a filename to save under", "output.shp", "Shapefile (*.shp)");

QString s = QFileDialog::getSaveFileName(this,
tr("Choose a filename to save to"),
"output.shp",
"Shapefile (*.shp)");

dirout->setText(s);
}

0 comments on commit 07c905b

Please sign in to comment.