~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/dxf2shp_converter/dxf2shpconvertergui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *Copyright (C) 2008 Paolo L. Scala, Barbara Rita Barricelli, Marco Padula *
 
3
 * CNR, Milan Unit (Information Technology),                               *
 
4
 * Construction Technologies Institute.\n";                                *
 
5
 *                                                                         *
 
6
 * email : Paolo L. Scala <scala@itc.cnr.it>                               *
 
7
 *                                                                         *
 
8
 *   This is a plugin generated from the QGIS plugin template              *
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 ***************************************************************************/
 
15
#include "dxf2shpconvertergui.h"
 
16
#include "qgscontexthelp.h"
 
17
 
 
18
#include "builder.h"
 
19
#include "getInsertions.h"
 
20
#include "dxflib/src/dl_dxf.h"
 
21
 
 
22
//qt includes
 
23
#include <qmessagebox.h>
 
24
#include <QSettings>
 
25
#include <QFileDialog>
 
26
#include <QFile>
 
27
#include <QDir>
 
28
 
 
29
#include "qgslogger.h"
 
30
 
 
31
dxf2shpConverterGui::dxf2shpConverterGui( QWidget *parent, Qt::WFlags fl ):
 
32
    QDialog( parent, fl )
 
33
{
 
34
  setupUi( this );
 
35
}
 
36
 
 
37
dxf2shpConverterGui::~dxf2shpConverterGui()
 
38
{
 
39
}
 
40
 
 
41
void dxf2shpConverterGui::on_buttonBox_accepted()
 
42
{
 
43
  QString inf = name->text();
 
44
  QString outd = dirout->text();
 
45
 
 
46
  if ( inf.size() > 1 )
 
47
  {
 
48
    int type = SHPT_POINT;
 
49
    bool convtexts = convertTextCheck->checkState();
 
50
 
 
51
    if ( polyline->isChecked() )
 
52
      type = SHPT_ARC;
 
53
 
 
54
    if ( polygon->isChecked() )
 
55
      type = SHPT_POLYGON;
 
56
 
 
57
    if ( point->isChecked() )
 
58
      type = SHPT_POINT;
 
59
 
 
60
    InsertRetrClass *insertRetr = new InsertRetrClass();
 
61
 
 
62
    DL_Dxf *dxf_inserts = new DL_Dxf();
 
63
 
 
64
    if ( !dxf_inserts->in( inf.toStdString(), insertRetr ) )
 
65
    {
 
66
      // if file open failed
 
67
      QgsDebugMsg( "Aborting: The input file could not be opened." );
 
68
      return;
 
69
    }
 
70
 
 
71
    Builder *parser = new Builder(
 
72
      outd.toStdString(),
 
73
      type,
 
74
      insertRetr->XVals, insertRetr->YVals,
 
75
      insertRetr->Names,
 
76
      insertRetr->countInserts,
 
77
      convtexts );
 
78
 
 
79
    QgsDebugMsg( QString( "Finished getting insertions. Count: %1" ).arg( insertRetr->countInserts ) );
 
80
 
 
81
    DL_Dxf *dxf_Main = new DL_Dxf();
 
82
 
 
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;
 
88
    }
 
89
 
 
90
    delete insertRetr;
 
91
    delete dxf_inserts;
 
92
    delete dxf_Main;
 
93
 
 
94
    parser->print_shpObjects();
 
95
 
 
96
    emit createLayer( QString(( parser->outputShp() ).c_str() ), QString( "Data layer" ) );
 
97
 
 
98
    if ( convtexts && parser->textObjectsSize() > 0 )
 
99
    {
 
100
      emit createLayer( QString(( parser->outputTShp() ).c_str() ), QString( "Text layer" ) );
 
101
    }
 
102
 
 
103
    delete parser;
 
104
  }
 
105
  else
 
106
  {
 
107
    QMessageBox::information( this, "Warning", "Please select a file to convert" );
 
108
    return;
 
109
  }
 
110
 
 
111
  accept();
 
112
}
 
113
 
 
114
void dxf2shpConverterGui::on_buttonBox_rejected()
 
115
{
 
116
  reject();
 
117
}
 
118
 
 
119
void dxf2shpConverterGui::on_buttonBox_helpRequested()
 
120
{
 
121
  QString s = tr( "Fields description:\n"
 
122
                  "* Input DXF file: path to the DXF file to be converted\n"
 
123
                  "* Output Shp file: desired name of the shape file to be created\n"
 
124
                  "* Shp output file type: specifies the type of the output shape file\n"
 
125
                  "* Export text labels checkbox: if checked, an additional shp points layer will be created, "
 
126
                  "  and the associated dbf table will contain informations about the \"TEXT\" fields found"
 
127
                  " in the dxf file, and the text strings themselves\n\n"
 
128
                  "---\n"
 
129
                  "Developed by Paolo L. Scala, Barbara Rita Barricelli, Marco Padula\n"
 
130
                  "CNR, Milan Unit (Information Technology), Construction Technologies Institute.\n"
 
131
                  "For support send a mail to scala@itc.cnr.it\n" );
 
132
 
 
133
  QMessageBox::information( this, "Help", s );
 
134
}
 
135
 
 
136
 
 
137
void dxf2shpConverterGui::on_btnBrowseForFile_clicked()
 
138
{
 
139
  getInputFileName();
 
140
}
 
141
 
 
142
void dxf2shpConverterGui::on_btnBrowseOutputDir_clicked()
 
143
{
 
144
  getOutputDir();
 
145
}
 
146
 
 
147
 
 
148
void dxf2shpConverterGui::getInputFileName()
 
149
{
 
150
  QSettings settings;
 
151
 
 
152
  QString s = QFileDialog::getOpenFileName( this,
 
153
              tr( "Choose a DXF file to open" ),
 
154
              settings.value( "/Plugin-DXF/text_path", "./" ).toString(),
 
155
              "Files DXF (*.dxf)" );
 
156
 
 
157
  name->setText( s );
 
158
}
 
159
 
 
160
void dxf2shpConverterGui::getOutputDir()
 
161
{
 
162
  QString s = QFileDialog::getSaveFileName( this,
 
163
              tr( "Choose a file name to save to" ),
 
164
              "output.shp",
 
165
              "Shapefile (*.shp)" );
 
166
 
 
167
  dirout->setText( s );
 
168
}