OGS
SHPImportDialog.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "SHPImportDialog.h"
5
6#include <QDialogButtonBox>
7#include <QFileInfo>
8#include <QLabel>
9#include <QLineEdit>
10#include <QRadioButton>
11#include <QVBoxLayout>
12
14#include "Base/OGSError.h"
15#include "GeoLib/GEOObjects.h"
16
18 GeoLib::GEOObjects& geo_objects,
19 std::string const& gmsh_path,
20 QDialog* parent)
21 : QDialog(parent),
22 _buttonBox(nullptr),
23 _layout(nullptr),
24 _shpContentLabel(nullptr),
25 _nameLabel(nullptr),
26 _listName(new QLineEdit()),
27 _choice1(nullptr),
28 _choice2(nullptr),
29 _filename(std::move(filename)),
30 _fileType(0),
31 _shpInterface(new FileIO::SHPInterface(geo_objects)),
32 _gmsh_path(gmsh_path)
33{
35 show();
36}
37
39{
40 delete _shpInterface;
41 delete _buttonBox;
42 delete _listName;
43 delete _choice1;
44 delete _choice2;
45 delete _shpContentLabel;
46 delete _nameLabel;
47 delete _layout;
48}
49
51{
52 _layout = new QGridLayout(this);
53 int shpType = 0;
54 int numberOfEntities = 0;
55 QString type = "";
56
57 setWindowTitle("Import SHP File");
58
59 if (_shpInterface->readSHPInfo(_filename, shpType, numberOfEntities))
60 {
61 if ((shpType - 1) % 10 == 0)
62 {
63 type = "points";
64 }
65 if ((shpType - 3) % 10 == 0)
66 {
67 type = "polylines";
68 }
69 if ((shpType - 5) % 10 == 0)
70 {
71 type = "polygons";
72 }
73 if ((shpType - 8) % 10 == 0)
74 {
75 type = "multipoints";
76 }
77 if (shpType == 31)
78 {
79 type = "TIN elements";
80 }
81
83 new QLabel("The selected file contains " +
84 QString::number(numberOfEntities) + " " + type,
85 this);
86 _nameLabel = new QLabel("List Name: ", this);
87
88 QFileInfo fi(QString::fromStdString(_filename));
89 _listName->setText(fi.baseName());
90
91 if ((shpType - 1) % 10 == 0 && shpType != 31) // Points
92 {
93 _choice1 = new QRadioButton("Read as Geometry Points");
94 _choice2 = new QRadioButton("Read as Station Points");
95 _choice1->toggle(); // default choice
96 _layout->addWidget(_shpContentLabel);
97 _layout->addWidget(_choice1);
98 _layout->addWidget(_choice2);
99 _layout->addWidget(_nameLabel);
100 _layout->addWidget(_listName);
101 _fileType = 1;
102 }
103 else if ((shpType - 3) % 10 == 0 ||
104 (shpType - 5) % 10 == 0) // Polylines
105 {
106 _choice1 = new QRadioButton("Read Polylines only");
107 _choice2 = new QRadioButton("Read Polylines/Surfaces");
108 if ((shpType - 3) % 10 == 0)
109 {
110 _choice2->setDisabled(true); // disable polygon-choice if file
111 // contains only polylines
112 }
113 _choice1->toggle(); // default choice
114 _layout->addWidget(_shpContentLabel);
115 _layout->addWidget(_choice1);
116 _layout->addWidget(_choice2);
117 _layout->addWidget(_nameLabel);
118 _layout->addWidget(_listName);
119 _fileType = 2;
120 }
121 else
122 {
123 _nameLabel->setText(
124 "This element type is currently not supported.");
125 _layout->addWidget(_shpContentLabel);
126 _layout->addWidget(_nameLabel);
127 }
128
129 _buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
130 QDialogButtonBox::Cancel);
131 connect(_buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
132 connect(_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
133 _layout->addWidget(_buttonBox);
134
135 setLayout(_layout);
136 }
137 else
138 {
139 OGSError::box("Error reading shapefile!");
140 }
141}
142
144{
145 QString list_name(_listName->text());
146 if (list_name.compare("") == 0)
147 {
148 OGSError::box("Please insert a name for the data in this file.");
149 return;
150 }
151
152 if (_fileType == 1 && _choice1->isChecked())
153 {
154 _shpInterface->readSHPFile(_filename,
156 list_name.toStdString(), _gmsh_path);
157 }
158 if (_fileType == 1 && _choice2->isChecked())
159 {
160 _shpInterface->readSHPFile(_filename,
162 list_name.toStdString(), _gmsh_path);
163 }
164 if (_fileType == 2 && _choice1->isChecked())
165 {
166 _shpInterface->readSHPFile(_filename,
168 list_name.toStdString(), _gmsh_path);
169 }
170 if (_fileType == 2 && _choice2->isChecked())
171 {
172 _shpInterface->readSHPFile(_filename,
174 list_name.toStdString(), _gmsh_path);
175 }
176 emit shpLoaded(list_name);
177
178 this->done(QDialog::Accepted);
179}
180
182{
183 this->done(QDialog::Rejected);
184}
Container class for geometric objects.
Definition GEOObjects.h:46
static void box(const QString &e)
Definition OGSError.cpp:13
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