OGS
SHPImportDialog.cpp
Go to the documentation of this file.
1
15#include "SHPImportDialog.h"
16
17#include <QDialogButtonBox>
18#include <QFileInfo>
19#include <QLabel>
20#include <QLineEdit>
21#include <QRadioButton>
22#include <QVBoxLayout>
23
25#include "Base/OGSError.h"
26#include "GeoLib/GEOObjects.h"
27
29 GeoLib::GEOObjects& geo_objects,
30 std::string const& gmsh_path,
31 QDialog* parent)
32 : QDialog(parent),
33 _buttonBox(nullptr),
34 _layout(nullptr),
35 _shpContentLabel(nullptr),
36 _nameLabel(nullptr),
37 _listName(new QLineEdit()),
38 _choice1(nullptr),
39 _choice2(nullptr),
40 _filename(std::move(filename)),
41 _fileType(0),
42 _shpInterface(new FileIO::SHPInterface(geo_objects)),
43 _gmsh_path(gmsh_path)
44{
46 show();
47}
48
50{
51 delete _shpInterface;
52 delete _buttonBox;
53 delete _listName;
54 delete _choice1;
55 delete _choice2;
56 delete _shpContentLabel;
57 delete _nameLabel;
58 delete _layout;
59}
60
62{
63 _layout = new QGridLayout(this);
64 int shpType = 0;
65 int numberOfEntities = 0;
66 QString type = "";
67
68 setWindowTitle("Import SHP File");
69
70 if (_shpInterface->readSHPInfo(_filename, shpType, numberOfEntities))
71 {
72 if ((shpType - 1) % 10 == 0)
73 {
74 type = "points";
75 }
76 if ((shpType - 3) % 10 == 0)
77 {
78 type = "polylines";
79 }
80 if ((shpType - 5) % 10 == 0)
81 {
82 type = "polygons";
83 }
84 if ((shpType - 8) % 10 == 0)
85 {
86 type = "multipoints";
87 }
88 if (shpType == 31)
89 {
90 type = "TIN elements";
91 }
92
94 new QLabel("The selected file contains " +
95 QString::number(numberOfEntities) + " " + type,
96 this);
97 _nameLabel = new QLabel("List Name: ", this);
98
99 QFileInfo fi(QString::fromStdString(_filename));
100 _listName->setText(fi.baseName());
101
102 if ((shpType - 1) % 10 == 0 && shpType != 31) // Points
103 {
104 _choice1 = new QRadioButton("Read as Geometry Points");
105 _choice2 = new QRadioButton("Read as Station Points");
106 _choice1->toggle(); // default choice
107 _layout->addWidget(_shpContentLabel);
108 _layout->addWidget(_choice1);
109 _layout->addWidget(_choice2);
110 _layout->addWidget(_nameLabel);
111 _layout->addWidget(_listName);
112 _fileType = 1;
113 }
114 else if ((shpType - 3) % 10 == 0 ||
115 (shpType - 5) % 10 == 0) // Polylines
116 {
117 _choice1 = new QRadioButton("Read Polylines only");
118 _choice2 = new QRadioButton("Read Polylines/Surfaces");
119 if ((shpType - 3) % 10 == 0)
120 {
121 _choice2->setDisabled(true); // disable polygon-choice if file
122 // contains only polylines
123 }
124 _choice1->toggle(); // default choice
125 _layout->addWidget(_shpContentLabel);
126 _layout->addWidget(_choice1);
127 _layout->addWidget(_choice2);
128 _layout->addWidget(_nameLabel);
129 _layout->addWidget(_listName);
130 _fileType = 2;
131 }
132 else
133 {
134 _nameLabel->setText(
135 "This element type is currently not supported.");
136 _layout->addWidget(_shpContentLabel);
137 _layout->addWidget(_nameLabel);
138 }
139
140 _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
141 QDialogButtonBox::Cancel);
142 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
143 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
144 _layout->addWidget(_buttonBox);
145
146 setLayout(_layout);
147 }
148 else
149 {
150 OGSError::box("Error reading shapefile!");
151 }
152}
153
155{
156 QString list_name(_listName->text());
157 if (list_name.compare("") == 0)
158 {
159 OGSError::box("Please insert a name for the data in this file.");
160 return;
161 }
162
163 if (_fileType == 1 && _choice1->isChecked())
164 {
167 list_name.toStdString(), _gmsh_path);
168 }
169 if (_fileType == 1 && _choice2->isChecked())
170 {
173 list_name.toStdString(), _gmsh_path);
174 }
175 if (_fileType == 2 && _choice1->isChecked())
176 {
179 list_name.toStdString(), _gmsh_path);
180 }
181 if (_fileType == 2 && _choice2->isChecked())
182 {
185 list_name.toStdString(), _gmsh_path);
186 }
187 emit shpLoaded(list_name);
188
189 this->done(QDialog::Accepted);
190}
191
193{
194 this->done(QDialog::Rejected);
195}
Definition of the GEOObjects class.
Definition of the OGSError class.
Definition of the SHPImportDialog class.
Implementation of the SHPInterface class.
static bool readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities)
Reads the header of the shape file.
void readSHPFile(const std::string &filename, OGSType choice, const std::string &listName, std::string const &gmsh_path)
Reads data from the shape file.
Container class for geometric objects.
Definition GEOObjects.h:57
static void box(const QString &e)
Definition OGSError.cpp:23
void accept() override
Instructions if the OK-Button has been pressed.
QGridLayout * _layout
QRadioButton * _choice2
void reject() override
Instructions if the Cancel-Button has been pressed.
void shpLoaded(QString)
void setupDialog()
The buttons used in this dialog.
QLineEdit * _listName
QRadioButton * _choice1
QLabel * _shpContentLabel
std::string _filename
~SHPImportDialog() override
SHPImportDialog(std::string filename, GeoLib::GEOObjects &geo_objects, std::string const &gmsh_path, QDialog *parent=nullptr)
Constructor.
QDialogButtonBox * _buttonBox
FileIO::SHPInterface * _shpInterface
std::string const _gmsh_path