Skip to content

Commit 7703910

Browse files

File tree

9 files changed

+344
-406
lines changed

9 files changed

+344
-406
lines changed
 

‎src/plugins/dxf2shp_converter/builder.cpp

Lines changed: 234 additions & 272 deletions
Large diffs are not rendered by default.

‎src/plugins/dxf2shp_converter/builder.h

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
#include "shapelib-1.2.10/shapefil.h"
2525
#include "getInsertions.h"
2626
#include <vector>
27-
#include <fstream>
28-
using namespace std;
2927

3028
class Builder: public DL_CreationAdapter
3129
{
3230
public:
33-
Builder();
31+
Builder(std::string theFname,
32+
int theShapefileType,
33+
double *theGrpXVals, double *theGrpYVals,
34+
std::string *theGrpNames,
35+
int theInsertCount,
36+
bool theConvertText);
3437
~Builder();
3538

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

50-
void set_numlayers(int n);
51-
void set_numpoints(int n);
52-
void set_numlines(int n);
53-
void set_numplines(int n);
54-
void set_shptype(int n);
55-
56-
void set_convertText(bool);
57-
void initBuilder(string, int, double*, double*, string*, int, bool);
5853
void print_shpObjects();
5954

60-
int ret_numlabels();
61-
int ret_numlayers();
62-
int ret_numpoints();
63-
int ret_numlines();
64-
int ret_numplines();
65-
int ret_shptype();
66-
int ret_textObjectsSize();
67-
string ret_outputshp();
68-
string ret_outputtshp();
69-
bool convertText;
70-
71-
55+
int textObjectsSize();
56+
std::string outputShp();
57+
std::string outputTShp();
7258

7359
private:
74-
string outputdbf;
75-
string outputshp;
76-
string outputtdbf;
77-
string outputtshp;
78-
string logfname;
79-
ofstream logfile;
60+
std::string fname;
61+
int shapefileType; // SHPT_POINT, ...
62+
double *grpXVals;
63+
double *grpYVals;
64+
std::string *grpNames;
65+
int insertCount;
66+
bool convertText;
8067

68+
std::string outputdbf;
69+
std::string outputshp;
70+
std::string outputtdbf;
71+
std::string outputtshp;
8172

82-
vector < DL_VertexData > polyVertex;
83-
vector <SHPObject *> shpObjects; // metto qui tutti gli oggetti letti
84-
vector <DL_TextData> textObjects;
73+
std::vector <DL_VertexData> polyVertex;
74+
std::vector <SHPObject *> shpObjects; // all read objects are stored here
75+
std::vector <DL_TextData> textObjects;
8576

8677
int numlayers;
8778
int numpoints;
8879
int numlines;
8980
int numplines;
9081

91-
int shptype; // 0 ,1 ,2
92-
int shapefileType; // SHPT_POINT, ...
9382
int fetchedprims;
9483
int fetchedtexts;
9584

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

10392
SHPObject *currently_Adding_PolyLine;
10493

105-
double *grpXVals;
106-
double *grpYVals;
107-
string *grpNames;
108-
string fname;
109-
int insertCount;
11094

11195
double closePolyX, closePolyY, closePolyZ;
11296
double currentBlockX, currentBlockY;

‎src/plugins/dxf2shp_converter/dxf2shpconverter.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <QAction>
3333
#include <QToolBar>
3434

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

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

6262
/*
63-
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
63+
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
6464
* added to the plugin registry in the QGIS application.
6565
*/
6666
void dxf2shpConverter::initGui()
6767
{
68-
6968
// Create the action for tool
70-
mQActionPointer = new QAction(QIcon(":/dxf2shpconverter/dxf2shp_converter.png")
71-
, "Dxf2Shp Converter", this);
69+
mQActionPointer = new QAction(QIcon(":/dxf2shpconverter/dxf2shp_converter.png"), "Dxf2Shp Converter", this);
70+
7271
// Set the what's this text
73-
mQActionPointer->setWhatsThis(tr(
74-
"Converts DXF files in Shapefile format"));
72+
mQActionPointer->setWhatsThis(tr("Converts DXF files in Shapefile format"));
73+
7574
// Connect the action to the run
7675
connect(mQActionPointer, SIGNAL(activated()), this, SLOT(run()));
76+
7777
// Add the icon to the toolbar
7878
mQGisIface->addToolBarIcon(mQActionPointer);
79-
mQGisIface->addPluginMenu("&Dxf2Shp", mQActionPointer);
80-
79+
mQGisIface->addPluginMenu(tr("&Dxf2Shp"), mQActionPointer);
8180
}
8281

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

8988
// Slot called when the menu item is activated
90-
// If you created more menu items / toolbar buttons in initiGui, you should
89+
// If you created more menu items / toolbar buttons in initiGui, you should
9190
// create a separate handler for each action - this single run() method will
9291
// not be enough
9392
void dxf2shpConverter::run()
9493
{
9594
dxf2shpConverterGui *myPluginGui =
9695
new dxf2shpConverterGui(mQGisIface->getMainWindow(), QgisGui::ModalDialogFlags);
96+
9797
myPluginGui->setAttribute(Qt::WA_DeleteOnClose);
9898

99-
connect(myPluginGui, SIGNAL(createLayer(QString)), this, SLOT(addMyLayer(QString)));
99+
connect(myPluginGui, SIGNAL(createLayer(QString,QString)), this, SLOT(addMyLayer(QString,QString)));
100100

101101
myPluginGui->show();
102102
}
@@ -105,14 +105,14 @@ void dxf2shpConverter::run()
105105
void dxf2shpConverter::unload()
106106
{
107107
// remove the GUI
108-
mQGisIface->removePluginMenu("&Dxf2Shp", mQActionPointer);
108+
mQGisIface->removePluginMenu(tr("&Dxf2Shp"), mQActionPointer);
109109
mQGisIface->removeToolBarIcon(mQActionPointer);
110110
delete mQActionPointer;
111111
}
112112

113-
void dxf2shpConverter::addMyLayer(QString myfname)
113+
void dxf2shpConverter::addMyLayer(QString myfname,QString mytitle)
114114
{
115-
mQGisIface->addVectorLayer(myfname, "Converted_Layer", "ogr");
115+
mQGisIface->addVectorLayer(myfname, mytitle, "ogr");
116116
}
117117

118118
//////////////////////////////////////////////////////////////////////////
@@ -126,8 +126,8 @@ void dxf2shpConverter::addMyLayer(QString myfname)
126126
//////////////////////////////////////////////////////////////////////////
127127

128128

129-
/**
130-
* Required extern functions needed for every plugin
129+
/**
130+
* Required extern functions needed for every plugin
131131
* These functions can be called prior to creating an instance
132132
* of the plugin class
133133
*/

‎src/plugins/dxf2shp_converter/dxf2shpconverter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class QgisInterface;
3434
*/
3535
class dxf2shpConverter: public QObject, public QgisPlugin
3636
{
37-
Q_OBJECT;
38-
public:
37+
Q_OBJECT
38+
public:
3939

4040
//////////////////////////////////////////////////////////////////////
4141
//
@@ -62,7 +62,7 @@ class dxf2shpConverter: public QObject, public QgisPlugin
6262
//! show the help document
6363
void help();
6464

65-
void addMyLayer(QString);
65+
void addMyLayer(QString,QString);
6666

6767
private:
6868

‎src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -26,89 +26,81 @@
2626
#include <QFile>
2727
#include <QDir>
2828

29+
#include "qgslogger.h"
30+
2931
dxf2shpConverterGui::dxf2shpConverterGui(QWidget *parent, Qt::WFlags fl):
3032
QDialog(parent, fl)
3133
{
3234
setupUi(this);
3335
}
3436

35-
dxf2shpConverterGui::~dxf2shpConverterGui(){}
37+
dxf2shpConverterGui::~dxf2shpConverterGui()
38+
{
39+
}
3640

3741
void dxf2shpConverterGui::on_buttonBox_accepted()
3842
{
39-
40-
QString inf = nomein->text();
43+
QString inf = name->text();
4144
QString outd = dirout->text();
4245

4346
if (inf.size() > 1)
4447
{
48+
int type = SHPT_POINT;
49+
bool convtexts = convertTextCheck->checkState();
4550

46-
int type = 1;
47-
bool convtexts;
48-
49-
if(convertTextCheck->checkState())
50-
convtexts = true;
51-
else
52-
convtexts = false;
51+
if (polyline->isChecked())
52+
type = SHPT_ARC;
5353

54-
if (zero->isChecked())
55-
type = 0;
54+
if (polygon->isChecked())
55+
type = SHPT_POLYGON;
5656

57-
if (uno->isChecked())
58-
type = 2;
57+
if (point->isChecked())
58+
type = SHPT_POINT;
5959

60-
if (due->isChecked())
61-
type = 1;
60+
InsertRetrClass *insertRetr = new InsertRetrClass();
6261

63-
InsertRetrClass * insertRetr = new InsertRetrClass();
64-
65-
DL_Dxf * dxf_inserts = new DL_Dxf();
66-
67-
if (!dxf_inserts->in((string)(inf.toLatin1()), insertRetr)) { // if file open failed
68-
69-
cout << "Aborting: The input file could not be opened.\n";
62+
DL_Dxf *dxf_inserts = new DL_Dxf();
7063

64+
if ( !dxf_inserts->in(inf.toStdString(), insertRetr) )
65+
{
66+
// if file open failed
67+
QgsDebugMsg( "Aborting: The input file could not be opened." );
7168
return ;
72-
7369
}
7470

75-
Builder * parserClass = new Builder();
76-
parserClass->initBuilder((string)(outd.toLatin1()), type, insertRetr->XVals, insertRetr->YVals, insertRetr->Names,
77-
insertRetr->countInserts, convtexts);
71+
Builder *parser= new Builder(
72+
outd.toStdString(),
73+
type,
74+
insertRetr->XVals, insertRetr->YVals,
75+
insertRetr->Names,
76+
insertRetr->countInserts,
77+
convtexts);
7878

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

81-
DL_Dxf * dxf_Main = new DL_Dxf();
82-
83-
if (!dxf_Main->in((string)(inf.toLatin1()), parserClass)) { // if file open failed
84-
85-
cout << "Aborting: The input file could not be opened.\n";
86-
87-
return ;
81+
DL_Dxf *dxf_Main = new DL_Dxf();
8882

83+
if ( !dxf_Main->in( inf.toStdString(), parser) )
84+
{
85+
// if file open failed
86+
QgsDebugMsg( "Aborting: The input file could not be opened." );
87+
return;
8988
}
9089

9190
delete insertRetr;
9291
delete dxf_inserts;
9392
delete dxf_Main;
94-
parserClass->print_shpObjects();
95-
bool textsPresent;
96-
if(parserClass->ret_textObjectsSize() > 0)
97-
textsPresent = true;
98-
else
99-
textsPresent = false;
10093

94+
parser->print_shpObjects();
10195

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

104-
emit(createLayer(mystring));
105-
106-
if((convertTextCheck->checkState()) && (textsPresent)) {
107-
mystring = QString((parserClass->ret_outputtshp()).c_str());
108-
emit(createLayer(mystring));
98+
if( convtexts && parser->textObjectsSize()>0 )
99+
{
100+
emit createLayer( QString((parser->outputTShp()).c_str()), QString("Text layer") );
109101
}
110102

111-
delete parserClass;
103+
delete parser;
112104
}
113105
else
114106
{
@@ -125,8 +117,8 @@ void dxf2shpConverterGui::on_buttonBox_rejected()
125117

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

140132
QMessageBox::information(this, "Help", s);
141133
}
@@ -156,20 +148,20 @@ void dxf2shpConverterGui::getInputFileName()
156148
{
157149
QSettings settings;
158150

159-
QString s = QFileDialog::getOpenFileName(this, tr(
160-
"Choose a delimited text file to open"), settings.value(
161-
"/Plugin-DelimitedText/text_path", "./").toString(), "Files DXF (*.dxf)");
151+
QString s = QFileDialog::getOpenFileName(this,
152+
tr("Choose a DXF file to open"),
153+
settings.value("/Plugin-DXF/text_path", "./").toString(),
154+
"Files DXF (*.dxf)");
162155

163-
nomein->setText(s);
156+
name->setText(s);
164157
}
165158

166159
void dxf2shpConverterGui::getOutputDir()
167160
{
168-
QSettings settings;
169-
170-
QString s = QFileDialog::getSaveFileName(this,
171-
"Choose a filename to save under", "output.shp", "Shapefile (*.shp)");
172-
161+
QString s = QFileDialog::getSaveFileName(this,
162+
tr("Choose a filename to save to"),
163+
"output.shp",
164+
"Shapefile (*.shp)");
173165

174166
dirout->setText(s);
175167
}

0 commit comments

Comments
 (0)
Please sign in to comment.