[QGIS Commit] r9132 - in trunk/qgis/src/plugins/dxf2shp_converter:
. dxflib/src
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat Aug 23 09:54:45 EDT 2008
Author: jef
Date: 2008-08-23 09:54:45 -0400 (Sat, 23 Aug 2008)
New Revision: 9132
Modified:
trunk/qgis/src/plugins/dxf2shp_converter/builder.cpp
trunk/qgis/src/plugins/dxf2shp_converter/builder.h
trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.h
trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.h
trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.ui
trunk/qgis/src/plugins/dxf2shp_converter/dxflib/src/dl_writer_ascii.cpp
trunk/qgis/src/plugins/dxf2shp_converter/getInsertions.cpp
Log:
dxf2shp cleanup (fixes #1236)
Modified: trunk/qgis/src/plugins/dxf2shp_converter/builder.cpp
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/builder.cpp 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/builder.cpp 2008-08-23 13:54:45 UTC (rev 9132)
@@ -1,4 +1,4 @@
-// The code is heavily based on Christopher Michaelis' DXF to Shapefile Converter
+// The code is heavily based on Christopher Michaelis' DXF to Shapefile Converter
// (http://www.wanderingidea.com/content/view/12/25/), released under GPL License
//
// This code is based on two other products:
@@ -7,165 +7,157 @@
// SHAPELIB (http://shapelib.maptools.org/)
// Used for the Shapefile functionality.
// It is Copyright (c) 1999, Frank Warmerdam, released under the following "MIT Style" license:
-//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-//documentation files (the "Software"), to deal in the Software without restriction, including without limitation
-//the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
+//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+//documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+//the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
//and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-//LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+//LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
//IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
+#include <cmath>
#include <string>
-#include <iostream>
-#include <fstream>
+
#include "builder.h"
-#define DEBUG 1
+#include "qgslogger.h"
-Builder::Builder() {
- currentBlockX = 0.0;
- currentBlockY = 0.0;
- ignoringBlock = false;
- current_polyline_pointcount = 0;
+Builder::Builder(std::string theFname,
+ int theShapefileType,
+ double *theGrpXVals, double *theGrpYVals,
+ std::string *theGrpNames,
+ int theInsertCount,
+ bool theConvertText) :
+ fname(theFname),
+ shapefileType(theShapefileType),
+ grpXVals(theGrpXVals),
+ grpYVals(theGrpYVals),
+ grpNames(theGrpNames),
+ insertCount(theInsertCount),
+ convertText(theConvertText),
+ fetchedprims(0),
+ fetchedtexts(0),
+ ignoringBlock(false),
+ awaiting_polyline_vertices(0),
+ current_polyline_pointcount(0),
+ currentBlockX(0.0),
+ currentBlockY(0.0)
+{
}
-Builder::~Builder(){
+Builder::~Builder()
+{
+ polyVertex.clear();
+ shpObjects.clear();
+ textObjects.clear();
+}
- if(polyVertex.size() != 0)
- polyVertex.clear();
+int Builder::textObjectsSize()
+{
+ return textObjects.size();
+}
- if(shpObjects.size() != 0)
- shpObjects.clear();
-
- if(textObjects.size() != 0)
- textObjects.clear();
-
- logfile.close();
-
+std::string Builder::outputShp()
+{
+ return outputshp;
}
-void Builder::initBuilder(string outf, int stype, double* grps_XVals, double* grps_YVals, string* grps_Names, int in_insertCount, bool getTexts) {
- shptype = stype;
- fname = outf;
-
- logfname = fname;
- logfname = logfname.replace((logfname.length()-3),logfname.length(), "log");
- logfile.open (logfname.c_str());
-
- insertCount = in_insertCount;
- awaiting_polyline_vertices = 0;
- fetchedprims = 0;
- fetchedtexts = 0;
- grpXVals = grps_XVals;
- grpYVals = grps_YVals;
- grpNames = grps_Names;
- convertText = getTexts;
-
- switch (shptype) {
- case 1:
- shapefileType = SHPT_POINT;
- break;
- case 0:
- shapefileType = SHPT_ARC;
- break;
- case 2:
- shapefileType = SHPT_POLYGON;
- break;
- default:
- shapefileType = SHPT_NULL;
- break;
- }
+std::string Builder::outputTShp()
+{
+ return outputtshp;
}
-
-
void Builder::addBlock(const DL_BlockData& data)
{
+ QgsDebugMsg("start block.");
- logfile << "Block added\n";
if (data.name.compare("ADCADD_ZZ") == 0)
{
- logfile << "(Ignoring Block "<< data.name.c_str()<<")\n";
+ QgsDebugMsg( QString("Ignoring block %1").arg(data.name.c_str()) );
ignoringBlock = true;
- }
- else
- for (int i = 0; i < insertCount; i++)
+ }
+ else
+ {
+ for (int i=0; i<insertCount; i++)
{
- if (strcmp(grpNames[i].c_str(), data.name.c_str()) == 0)
+ if (grpNames[i] == data.name)
{
currentBlockX = grpXVals[i];
currentBlockY = grpYVals[i];
- logfile << "Found Coord for Block: ("<< grpXVals[i]<< "," << grpYVals[i]<<")\n";
+ QgsDebugMsg( QString("Found coord for block: (%1,%2)").arg( grpXVals[i] ).arg( grpYVals[i] ) );
}
}
+ }
}
void Builder::endBlock()
{
-
FinalizeAnyPolyline();
currentBlockX = 0.0;
currentBlockY = 0.0;
ignoringBlock = false;
- logfile << "endBlock added\n";
+ QgsDebugMsg("end block.");
}
-void Builder::addLayer(const DL_LayerData& data) {
- logfile << "Layer: " << data.name.c_str() << "\n";
+void Builder::addLayer(const DL_LayerData& data)
+{
+ QgsDebugMsg( QString("Layer: ").arg( data.name.c_str() ) );
}
-void Builder::addPoint(const DL_PointData& data) {
- if(shptype != 1) {
- logfile << " Ignoring Point \n";
+void Builder::addPoint(const DL_PointData& data)
+{
+ if(shapefileType != SHPT_POINT)
+ {
+ QgsDebugMsg("ignoring point");
return;
}
- logfile << "(Add Point (" << data.x << "," << data.y << "," << data.z << ")\n";
+ QgsDebugMsg( QString("point (%1,%2,%3)").arg( data.x ).arg( data.y ).arg( data.z ) );
if (ignoringBlock)
{
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
+ QgsDebugMsg("skipping point in block.");
return;
}
- double x = data.x + currentBlockX;
- double y = data.y + currentBlockY;
+ double x = data.x + currentBlockX;
+ double y = data.y + currentBlockY;
double z = data.z;
- SHPObject *psObject;
- psObject = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL,
- 1, &x, &y, &z, NULL );
+ SHPObject *psObject;
+ psObject = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, 1, &x, &y, &z, NULL );
- shpObjects.push_back(psObject);
+ shpObjects.push_back(psObject);
fetchedprims++;
}
void Builder::addLine(const DL_LineData& data) {
- //data.x1 , data.y1, data.z1
- //data.x2 , data.y2, data.z2
+ //data.x1 , data.y1, data.z1
+ //data.x2 , data.y2, data.z2
- if (shptype != 0)
+ if (shapefileType != SHPT_ARC)
{
- logfile << "(Add Line - Ignoring [not creating polyline shapefile])\n";
+ QgsDebugMsg( "ignoring line" );
return;
}
- logfile << "(AddLine (" << data.x1 << "," << data.y1 << "," << data.z1 << " to "
- << data.x2 << "," << data.y2 << "," << data.z2 <<")\n";
+ QgsDebugMsg( QString("line 1,%2,%3 %4,%5,%6")
+ .arg( data.x1 ).arg( data.y1 ).arg( data.z1 )
+ .arg( data.x2 ).arg( data.y2 ).arg( data.z2 ) );
if (ignoringBlock)
{
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
+ QgsDebugMsg( "skipping line in block." );
return;
}
@@ -177,158 +169,158 @@
xv[1] = data.x2 + currentBlockX;
yv[1] = data.y2 + currentBlockY;
- zv[1] = data.z2;
+ zv[1] = data.z2;
- SHPObject *psObject;
+ SHPObject *psObject;
- psObject = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL,
- 2, xv, yv, zv, NULL );
+ psObject = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, 2, xv, yv, zv, NULL );
- shpObjects.push_back(psObject);
+ shpObjects.push_back(psObject);
fetchedprims++;
}
+void Builder::addPolyline(const DL_PolylineData& data)
+{
+ if (shapefileType!=SHPT_ARC && shapefileType!=SHPT_POLYGON)
+ {
+ QgsDebugMsg( "ignoring polyline" );
+ return;
+ }
- void Builder::addPolyline(const DL_PolylineData& data) {
- if (shptype != 0 && shptype != 2)
- {
- logfile << "(Add Polyline - Ignoring [not creating polyline shapefile or polygon shapefile])\n";
- return;
- }
+ QgsDebugMsg( "reading polyline - expecting vertices" );
- logfile << "(Add Polyline) Awaiting Vertices...\n";
+ if (ignoringBlock)
+ {
+ QgsDebugMsg( "skipping polyline in block" );
+ return;
+ }
- if (ignoringBlock)
+ // Add previously created polyline if not finalized yet
+ if (current_polyline_pointcount > 0)
+ {
+ if (current_polyline_willclose)
{
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
- return;
- }
- // Add previously created polyline if not finalized yet
- if (current_polyline_pointcount > 0)
- {
- if (current_polyline_willclose)
- {
+ DL_VertexData myVertex;
- DL_VertexData myVertex;
+ myVertex.x = closePolyX;
+ myVertex.y = closePolyY;
+ myVertex.z = closePolyZ;
- myVertex.x = closePolyX;
- myVertex.y = closePolyY;
- myVertex.z = closePolyZ;
+ polyVertex.push_back(myVertex);
- polyVertex.push_back(myVertex);
+ }
- }
+ SHPObject *psShape;
+ int dim = polyVertex.size();
+ double *xv = new double[dim];
+ double *yv = new double[dim];
+ double *zv = new double[dim];
+ for (int i=0; i < dim; i++)
+ {
+ xv[i] = polyVertex[i].x;
+ yv[i] = polyVertex[i].y;
+ zv[i] = polyVertex[i].z;
+ }
- SHPObject *psShape;
- int dim = polyVertex.size();
- double *xv = new double[dim];
- double *yv = new double[dim];
- double *zv = new double[dim];
+ psShape = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, dim, xv, yv, zv, NULL );
- for (int i=0; i < dim; i++)
- {
- xv[i] = polyVertex[i].x;
- yv[i] = polyVertex[i].y;
- zv[i] = polyVertex[i].z;
- }
+ delete [] xv;
+ delete [] yv;
+ delete [] zv;
- psShape = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, dim, xv, yv, zv, NULL );
+ shpObjects.push_back(psShape);
- delete [] xv;
- delete [] yv;
- delete [] zv;
- shpObjects.push_back(psShape);
+ fetchedprims++;
+ polyVertex.clear();
- fetchedprims++;
+ QgsDebugMsg( QString("polyline prepared: %1").arg(fetchedprims - 1) );
+ current_polyline_pointcount = 0;
+ }
- polyVertex.clear();
+ // Now that the currently-adding polyline (if any) is
+ // finalized, parse out the flag options
- logfile << "Finalized adding of polyline shape " << fetchedprims - 1 << "\n";
- current_polyline_pointcount = 0;
- }
+ if (data.flags == 1 || data.flags == 32)
+ {
+ current_polyline_willclose = true;
+ store_next_vertex_for_polyline_close = true;
+ }
+ else
+ {
+ current_polyline_willclose = false;
+ store_next_vertex_for_polyline_close = false;
+ }
- // Now that the currently-adding polyline (if any) is
- // finalized, parse out the flag options
+ current_polyline_pointcount = 0;
- if (data.flags == 1 || data.flags == 32)
- {
- current_polyline_willclose = true;
- store_next_vertex_for_polyline_close = true;
- }
- else
- {
- current_polyline_willclose = false;
- store_next_vertex_for_polyline_close = false;
- }
+}
- current_polyline_pointcount = 0;
+void Builder::addVertex(const DL_VertexData& data)
+{
+ if (shapefileType!=SHPT_ARC && shapefileType!=SHPT_POLYGON)
+ {
+ QgsDebugMsg( "ignoring vertex" );
+ return;
}
+ QgsDebugMsg( QString("vertex (%1,%2,%3)").arg( data.x ).arg( data.y ).arg( data.z ) );
- void Builder::addVertex(const DL_VertexData& data) {
- if (shptype != 0 && shptype != 2)
- {
- logfile << "(Add Vertex - Ignoring [not creating polyline shapefile or polygon shapefile])\n";
- return;
- }
+ if (ignoringBlock)
+ {
+ QgsDebugMsg( "skipping vertex in block" );
+ return;
+ }
- logfile << "(Add Vertex) (" << data.x << "," << data.y << "," << data.z << ")\n";
+ DL_VertexData myVertex;
+ myVertex.x = data.x + currentBlockX;
+ myVertex.y = data.y + currentBlockY;
+ myVertex.z = data.z;
- if (ignoringBlock)
- {
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
- return;
- }
+ polyVertex.push_back(myVertex);
- DL_VertexData myVertex;
- myVertex.x = data.x + currentBlockX;
- myVertex.y = data.y + currentBlockY;
- myVertex.z = data.z;
+ current_polyline_pointcount++;
- polyVertex.push_back(myVertex);
-
- current_polyline_pointcount++;
-
- if (store_next_vertex_for_polyline_close)
- {
- store_next_vertex_for_polyline_close = false;
- closePolyX = data.x + currentBlockX;
- closePolyY = data.y + currentBlockY;
- closePolyZ = data.z;
- }
+ if (store_next_vertex_for_polyline_close)
+ {
+ store_next_vertex_for_polyline_close = false;
+ closePolyX = data.x + currentBlockX;
+ closePolyY = data.y + currentBlockY;
+ closePolyZ = data.z;
}
+}
-void Builder::endSequence() {
- logfile << "endSequence\n";
+void Builder::endSequence()
+{
+ QgsDebugMsg( "endSequence" );
}
void Builder::addArc(const DL_ArcData& data)
{
- if (shptype != 0)
+ if (shapefileType!=SHPT_ARC)
{
- logfile << "(Add Arc - Ignoring [not creating polyline shapefile])\n";
+ QgsDebugMsg( "ignoring arc" );
return;
}
- double pi = 3.1415926535897932384626433832795;
-
int fromAngle = (int) data.angle1 + 1;
int toAngle = (int) data.angle2 + 1;
- logfile << "(Add Arc (" << data.cx << "," << data.cy << "," << data.cz << ","
- << data.radius << "," << data.angle1 << "," << data.angle2 << ")\n";
+ QgsDebugMsg( QString("arc (%1,%2,%3 r=%4 a1=%5 a2=%6)")
+ .arg( data.cx ).arg( data.cy ).arg( data.cz )
+ .arg( data.radius )
+ .arg( data.angle1 ).arg( data.angle2 ) );
if (ignoringBlock)
{
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
+ QgsDebugMsg( "skipping arc in block" );
return;
}
@@ -337,20 +329,20 @@
// Approximate the arc
- register double radianMeasure;
- register double deg2radFactor = (pi / 180);
+ double radianMeasure;
- vector <DL_PointData> arcPoints;
+ std::vector <DL_PointData> arcPoints;
DL_PointData myPoint;
- for (i = fromAngle; ; i += 1, shpIndex++)
+ for (i = fromAngle; ; i++, shpIndex++)
{
if (i > 360)
i = 0;
- if (shpIndex > 1000) break;
+ if (shpIndex > 1000)
+ break;
- radianMeasure = i * deg2radFactor;
+ radianMeasure = i * M_PI / 180.0;
myPoint.x = data.radius * cos(radianMeasure) + data.cx + currentBlockX;
myPoint.y = data.radius * sin(radianMeasure) + data.cy + currentBlockY;
@@ -358,18 +350,19 @@
arcPoints.push_back(myPoint);
- if (i == toAngle) break;
+ if (i == toAngle)
+ break;
}
// Finalize
- SHPObject *psShape;
+ SHPObject *psShape;
int dim = arcPoints.size();
double *xv = new double[dim];
double *yv = new double[dim];
double *zv = new double[dim];
- for (int i=0; i < dim; i++)
+ for (int i=0; i < dim; i++)
{
xv[i] = arcPoints[i].x;
yv[i] = arcPoints[i].y;
@@ -394,35 +387,28 @@
void Builder::addCircle(const DL_CircleData& data)
{
- if (shptype != 0 && shptype != 2)
+ if (shapefileType!=SHPT_ARC && shapefileType!=SHPT_POLYGON)
{
- logfile << "(Add Circle - Ignoring [not creating polyline shapefile or polygon shapefile])\n";
+ QgsDebugMsg( "ignoring circle" );
return;
}
- logfile << "(Add Circle (%6.3f, %6.3f, %6.3f) %6.3f\n", data.cx, data.cy, data.cz, data.radius;
+ QgsDebugMsg( QString("circle (%1,%2,%3 r=%4)").arg( data.cx ).arg( data.cy ).arg( data.cz ).arg( data.radius ) );
if (ignoringBlock)
{
- logfile << "ADCADD_ZZ block; ignoring. Exiting last add function.\n";
+ QgsDebugMsg( "skipping circle in block" );
return;
}
- register double i = 0;
- register long shpIndex = 0;
-
- // Approximate the circle with 360 line segments connecting points along that circle
- double pi = 3.1415926535897932384626433832795;
- double increment = ((2 * pi ) / 360);
-
- vector <DL_PointData> circlePoints;
+ std::vector <DL_PointData> circlePoints;
DL_PointData myPoint;
-
- for (; i <= 2 * pi; i += increment, shpIndex++)
+ // Approximate the circle with 360 line segments connecting points along that circle
+ register long shpIndex = 0;
+ for (double i=0.0; i<=2*M_PI; i+=M_PI/180.0, shpIndex++)
{
-
myPoint.x = data.radius * cos(i) + data.cx + currentBlockX;
myPoint.y = data.radius * sin(i) + data.cy + currentBlockY;
myPoint.z = data.cz;
@@ -430,18 +416,17 @@
circlePoints.push_back(myPoint);
}
- SHPObject *psShape;
+ SHPObject *psShape;
int dim = circlePoints.size();
double *xv = new double[dim];
double *yv = new double[dim];
double *zv = new double[dim];
- for (int i=0; i < dim; i++)
+ for (int i=0; i < dim; i++)
{
xv[i] = circlePoints[i].x;
yv[i] = circlePoints[i].y;
zv[i] = circlePoints[i].z;
-
}
psShape = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, dim, xv, yv, zv, NULL );
@@ -455,28 +440,15 @@
fetchedprims++;
circlePoints.clear();
-
}
-void Builder::set_numlayers(int n) { numlayers = n; }
-void Builder::set_numpoints(int n) { numpoints = n; }
-void Builder::set_numlines(int n) { numlines = n; }
-void Builder::set_numplines(int n) { numplines = n; }
-
-int Builder::ret_numlayers() { return numlayers; }
-int Builder::ret_numpoints() { return numpoints; }
-int Builder::ret_numlines() { return numlines; }
-int Builder::ret_numplines() { return numplines; }
-int Builder::ret_textObjectsSize() { return textObjects.size(); }
-
-string Builder::ret_outputshp() { return outputshp; }
-string Builder::ret_outputtshp() { return outputtshp; }
-
-void Builder::addText(const DL_TextData& data) {
- if(convertText) {
+void Builder::addText(const DL_TextData &data)
+{
+ if(convertText)
+ {
DL_TextData myText(
data.ipx + currentBlockX, data.ipy + currentBlockY,data.ipz,
- data.apx,data.apy,data.apz,
+ data.apx,data.apy,data.apz,
data.height,data.xScaleFactor,data.textGenerationFlags,
data.hJustification,data.vJustification,
data.text,data.style,data.angle
@@ -484,15 +456,11 @@
textObjects.push_back(myText);
- logfile << "Text added: " <<data.text << "\n";
+ QgsDebugMsg( QString("text: %1").arg( data.text.c_str() ) );
fetchedtexts++;
}
}
-void Builder::set_shptype(int n) { shptype = n; }
-
-void Builder::set_convertText(bool b) { convertText = b; }
-
void Builder::FinalizeAnyPolyline()
{
// Save the last polyline / polygon if one exists.
@@ -505,21 +473,20 @@
myVertex.y = closePolyY;
myVertex.z = closePolyZ;
- polyVertex.push_back(myVertex);
+ polyVertex.push_back(myVertex);
}
- SHPObject *psObject;
+ SHPObject *psObject;
int dim = polyVertex.size();
double *xv = new double[dim];
double *yv = new double[dim];
double *zv = new double[dim];
- for (int i=0; i < dim; i++)
+ for (int i=0; i < dim; i++)
{
xv[i] = polyVertex[i].x;
yv[i] = polyVertex[i].y;
zv[i] = polyVertex[i].z;
-
}
psObject = SHPCreateObject( shapefileType, fetchedprims, 0, NULL, NULL, dim, xv, yv, zv, NULL );
@@ -530,25 +497,27 @@
shpObjects.push_back(psObject);
- polyVertex.clear();
+ polyVertex.clear();
fetchedprims++;
- logfile << "Finalized adding of polyline shape " << fetchedprims - 1 <<"\n";
+ QgsDebugMsg( QString("Finalized adding of polyline shape %1").arg( fetchedprims - 1 ) );
current_polyline_pointcount = 0;
}
}
-void Builder::print_shpObjects() {
+void Builder::print_shpObjects()
+{
int dim = shpObjects.size();
int dimTexts = textObjects.size();
- logfile << "Number Of Primitives: " << dim << "\n";
- logfile << "Numper of Text Fields: " << dimTexts << "\n";
+ QgsDebugMsg( QString( "Number pf primitives: %1").arg( dim ) );
+ QgsDebugMsg( QString( "Number of text fields: %1").arg( dimTexts ) );
- SHPHandle hSHP;
+ SHPHandle hSHP;
- if(strcmp(".shp",(fname.substr(fname.length()-4)).c_str()) == 0) {
+ if( fname.substr(fname.length()-4).compare(".shp")==0 )
+ {
outputdbf = fname;
outputdbf = outputdbf.replace((outputdbf.length()-3),outputdbf.length(), "dbf");
outputshp = fname;
@@ -557,14 +526,9 @@
outputtdbf = outputtdbf.replace((outputtdbf.length()-4),outputtdbf.length(), "_texts.dbf");
outputtshp = fname;
outputtshp = outputtshp.replace((outputtshp.length()-4),outputtshp.length(), "_texts.shp");
-
- // outputdbf = fname.replace((fname.length()-3),fname.length(), "dbf");
- // outputshp = fname.replace((fname.length()-3),fname.length(), "shp");
- // outputtdbf = fname.replace((fname.length()-4),fname.length(), "_texts.dbf");
- // outputtshp = fname.replace((fname.length()-4),fname.length(), "_texts.shp");
-
}
- else {
+ else
+ {
outputdbf = fname;
outputdbf = outputdbf.append(".dbf");
outputshp = fname;
@@ -573,10 +537,6 @@
outputtdbf = outputtdbf.append(".dbf");
outputtshp = fname;
outputtshp = outputtdbf.append(".shp");
- //outputdbf = fname.append(".dbf");
- //outputshp = fname.append(".shp");
- //outputtdbf = fname.append("_texts.dbf");
- //outputtshp = fname.append("_texts.shp");
}
DBFHandle dbffile = DBFCreate(outputdbf.c_str());
@@ -584,23 +544,26 @@
hSHP = SHPCreate( outputshp.c_str(), shapefileType );
- logfile << "Writing to main shp file...\n";
+ QgsDebugMsg( "Writing to main shp file..." );
- for(int i=0; i< dim; i++) {
+ for(int i=0; i<dim; i++)
+ {
SHPWriteObject(hSHP, -1, shpObjects[i] );
SHPDestroyObject(shpObjects[i]);
- DBFWriteIntegerAttribute(dbffile, i, 0, i);
+ DBFWriteIntegerAttribute(dbffile, i, 0, i);
}
+
SHPClose(hSHP);
DBFClose(dbffile);
- logfile << "Done!\n";
+ QgsDebugMsg( "Done!" );
- if((convertText) && (dimTexts > 0)) {
- SHPHandle thSHP;
+ if( convertText && dimTexts>0 )
+ {
+ SHPHandle thSHP;
DBFHandle Tdbffile = DBFCreate(outputtdbf.c_str());
- thSHP = SHPCreate( outputtshp.c_str(), SHPT_POINT );
+ thSHP = SHPCreate( outputtshp.c_str(), SHPT_POINT );
DBFAddField( Tdbffile, "tipx", FTDouble, 20, 10 );
DBFAddField( Tdbffile, "tipy", FTDouble, 20, 10 );
@@ -617,16 +580,15 @@
DBFAddField( Tdbffile, "style", FTString, 50, 0 );
DBFAddField( Tdbffile, "angle", FTDouble, 20, 10 );
- logfile << "Writing Texts' shp File...\n";
+ QgsDebugMsg( "Writing Texts' shp File..." );
- for(int i=0; i< dimTexts; i++) {
-
- SHPObject *psObject;
+ for(int i=0; i<dimTexts; i++)
+ {
+ SHPObject *psObject;
double x = textObjects[i].ipx;
double y = textObjects[i].ipy;
double z = textObjects[i].ipz;
- psObject = SHPCreateObject( SHPT_POINT, i, 0, NULL, NULL,
- 1, &x, &y, &z, NULL );
+ psObject = SHPCreateObject( SHPT_POINT, i, 0, NULL, NULL, 1, &x, &y, &z, NULL );
SHPWriteObject(thSHP, -1, psObject );
@@ -655,6 +617,6 @@
SHPClose(thSHP);
DBFClose(Tdbffile);
- logfile << "Done!";
+ QgsDebugMsg( "Done!" );
}
}
Modified: trunk/qgis/src/plugins/dxf2shp_converter/builder.h
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/builder.h 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/builder.h 2008-08-23 13:54:45 UTC (rev 9132)
@@ -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();
@@ -47,49 +50,35 @@
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;
@@ -102,11 +91,6 @@
SHPObject *currently_Adding_PolyLine;
- double *grpXVals;
- double *grpYVals;
- string *grpNames;
- string fname;
- int insertCount;
double closePolyX, closePolyY, closePolyZ;
double currentBlockX, currentBlockY;
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.cpp
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.cpp 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.cpp 2008-08-23 13:54:45 UTC (rev 9132)
@@ -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(
@@ -47,7 +47,7 @@
//////////////////////////////////////////////////////////////////////
/**
- * 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
*/
@@ -60,24 +60,23 @@
}
/*
- * 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);
- // Create the action for tool
- 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
@@ -87,16 +86,17 @@
}
// 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();
}
@@ -105,14 +105,14 @@
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");
}
//////////////////////////////////////////////////////////////////////////
@@ -126,8 +126,8 @@
//////////////////////////////////////////////////////////////////////////
-/**
- * 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
*/
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.h
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.h 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconverter.h 2008-08-23 13:54:45 UTC (rev 9132)
@@ -34,8 +34,8 @@
*/
class dxf2shpConverter: public QObject, public QgisPlugin
{
- Q_OBJECT;
- public:
+ Q_OBJECT
+public:
//////////////////////////////////////////////////////////////////////
//
@@ -62,7 +62,7 @@
//! show the help document
void help();
- void addMyLayer(QString);
+ void addMyLayer(QString,QString);
private:
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp 2008-08-23 13:54:45 UTC (rev 9132)
@@ -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 (polyline->isChecked())
+ type = SHPT_ARC;
- if(convertTextCheck->checkState())
- convtexts = true;
- else
- convtexts = false;
+ if (polygon->isChecked())
+ type = SHPT_POLYGON;
- if (zero->isChecked())
- type = 0;
+ if (point->isChecked())
+ type = SHPT_POINT;
- if (uno->isChecked())
- type = 2;
+ InsertRetrClass *insertRetr = new InsertRetrClass();
- if (due->isChecked())
- type = 1;
+ DL_Dxf *dxf_inserts = new DL_Dxf();
- 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";
-
+ 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();
+ 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 ;
-
+ 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
{
@@ -125,8 +117,8 @@
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, "
@@ -135,7 +127,7 @@
"---\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 at itc.cnr.it\n";
+ "For support send a mail to scala at itc.cnr.it\n");
QMessageBox::information(this, "Help", s);
}
@@ -156,20 +148,20 @@
{
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,
+ tr("Choose a filename to save to"),
+ "output.shp",
+ "Shapefile (*.shp)");
- QString s = QFileDialog::getSaveFileName(this,
- "Choose a filename to save under", "output.shp", "Shapefile (*.shp)");
-
-
dirout->setText(s);
}
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.h
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.h 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.h 2008-08-23 13:54:45 UTC (rev 9132)
@@ -23,22 +23,27 @@
*/
class dxf2shpConverterGui: public QDialog, private Ui::dxf2shpConverterGui
{
- Q_OBJECT public:
- dxf2shpConverterGui(QWidget *parent = 0, Qt::WFlags fl = 0);
+ Q_OBJECT
+
+public:
+ dxf2shpConverterGui(QWidget *parent = 0, Qt::WFlags fl = 0);
~dxf2shpConverterGui();
- private:
+private:
static const int context_id = 0;
void getInputFileName();
void getOutputFileName();
void getOutputDir();
- private slots: void on_buttonBox_accepted();
+
+private slots:
+ void on_buttonBox_accepted();
void on_buttonBox_rejected();
void on_buttonBox_helpRequested();
void on_btnBrowseForFile_clicked();
void on_btnBrowseOutputDir_clicked();
-signals: void createLayer(QString);
+signals:
+ void createLayer(QString,QString);
};
#endif
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.ui
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.ui 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxf2shpconvertergui.ui 2008-08-23 13:54:45 UTC (rev 9132)
@@ -36,7 +36,7 @@
</widget>
</item>
<item row="0" column="1" colspan="2" >
- <widget class="QLineEdit" name="nomein" />
+ <widget class="QLineEdit" name="name" />
</item>
<item row="0" column="3" >
<widget class="QToolButton" name="btnBrowseForFile" >
@@ -84,7 +84,7 @@
</property>
<layout class="QGridLayout" >
<item row="0" column="0" >
- <widget class="QRadioButton" name="zero" >
+ <widget class="QRadioButton" name="polyline" >
<property name="text" >
<string>Polyline</string>
</property>
@@ -94,14 +94,14 @@
</widget>
</item>
<item row="0" column="1" >
- <widget class="QRadioButton" name="uno" >
+ <widget class="QRadioButton" name="polygon" >
<property name="text" >
<string>Polygon</string>
</property>
</widget>
</item>
<item row="0" column="2" >
- <widget class="QRadioButton" name="due" >
+ <widget class="QRadioButton" name="point" >
<property name="text" >
<string>Point</string>
</property>
Modified: trunk/qgis/src/plugins/dxf2shp_converter/dxflib/src/dl_writer_ascii.cpp
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/dxflib/src/dl_writer_ascii.cpp 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/dxflib/src/dl_writer_ascii.cpp 2008-08-23 13:54:45 UTC (rev 9132)
@@ -58,7 +58,7 @@
*/
void DL_WriterA::dxfReal(int gc, double value) const {
char str[256];
- sprintf(str, "%.16lf", value);
+ sprintf(str, "%.16f", value);
// fix for german locale:
strReplace(str, ',', '.');
Modified: trunk/qgis/src/plugins/dxf2shp_converter/getInsertions.cpp
===================================================================
--- trunk/qgis/src/plugins/dxf2shp_converter/getInsertions.cpp 2008-08-23 13:22:02 UTC (rev 9131)
+++ trunk/qgis/src/plugins/dxf2shp_converter/getInsertions.cpp 2008-08-23 13:54:45 UTC (rev 9132)
@@ -29,9 +29,6 @@
#include "getInsertions.h"
-#include <iostream>
-#include <stdio.h>
-
InsertRetrClass::InsertRetrClass()
{
Names = new string[MaxInserts];
@@ -69,6 +66,4 @@
YVals[countInserts] = data.ipy;
}
countInserts++;
-
-
}
More information about the QGIS-commit
mailing list