Commit 7c4cc73b authored by Béla Wiegel's avatar Béla Wiegel Committed by Gerrit Erichsen
Browse files

POL Solar files, bug fix

Added Solar POL files to LocationsCreator
Enhanced comb calculations
Removed a bug in PolygonObject editing in GUI
parent f6a34d19
......@@ -18,7 +18,7 @@ POLReadWrite::~POLReadWrite()
void POLReadWrite::writeFile(QString fileDescription)
{
QDateTime date(QDateTime::currentDateTime());
QFile file("C:/RES/CalculatedAreaPotential_" + fileDescription + "_" + date.toString("yyyyMMddHHmmss") + ".pol");
QFile file("C:/Res/CalculatedAreaPotential_" + fileDescription + "_" + date.toString("yyyyMMddHHmmss") + ".pol");
file.open(QIODevice::WriteOnly);
QDataStream dataStream(&file);
......@@ -111,7 +111,7 @@ bool POLReadWrite::openFile(QString fileName)
m_dataSetsMap.insert(dataSet->SN_L(), dataSet);
}
}
qDebug() << "\n";
// qDebug() << "\n";
file.close();
......
......@@ -25,9 +25,11 @@ WindowLocationsCreator::WindowLocationsCreator(LocationsTableModel * locationsTa
m_settings->beginGroup("LocationsCreator");
m_fileNameSF = m_settings->value("SFPath").toString();
m_fileNamePOL = m_settings->value("POLPath").toString();
m_fileNamePOLWind = m_settings->value("POLWindPath").toString();
m_fileNamePOLSolar = m_settings->value("POLSolarPath").toString();
m_lblSFPath->setText(m_fileNameSF);
m_lblPOLPath->setText(m_fileNamePOL);
m_lblPOLWindPath->setText(m_fileNamePOLWind);
m_lblPOLSolarPath->setText(m_fileNamePOLSolar);
this->resize(m_settings->value("WindowSize", QSize(400, 600)).toSize());
m_settings->endGroup();
}
......@@ -64,31 +66,58 @@ void WindowLocationsCreator::fileDialogSFFile()
m_settings->setValue("LocationsCreator/SFPath", m_fileNameSF);
}
void WindowLocationsCreator::fileDialogPOLFile()
void WindowLocationsCreator::fileDialogPOLWindFile()
{
QString file = m_settings->value("LocationsCreator/POLPath").toString().split("/").last();
QString directory = m_settings->value("LocationsCreator/POLPath").toString().remove("/" + file);
QString file = m_settings->value("LocationsCreator/POLWindPath").toString().split("/").last();
QString directory = m_settings->value("LocationsCreator/POLWindPath").toString().remove("/" + file);
QFileDialog fileDialog(this);
if (directory != "") fileDialog.setDirectory(directory + "/" + file);
if (file != "") fileDialog.selectFile(file);
fileDialog.setNameFilter("POL File (*.pol)");
fileDialog.setWindowTitle("Select POLFile");
fileDialog.setWindowTitle("Select POLFile for Wind");
if (!fileDialog.exec())
return;
if (fileDialog.selectedFiles().empty())
{
m_fileNamePOL.clear();
m_fileNamePOLWind.clear();
return;
}
m_fileNamePOL = fileDialog.selectedFiles().first();
m_lblPOLPath->setText(m_fileNamePOL);
m_fileNamePOLWind = fileDialog.selectedFiles().first();
m_lblPOLWindPath->setText(m_fileNamePOLWind);
// store values to QSettings
m_settings->setValue("LocationsCreator/POLPath", m_fileNamePOL);
m_settings->setValue("LocationsCreator/POLWindPath", m_fileNamePOLWind);
}
void WindowLocationsCreator::fileDialogPOLSolarFile()
{
QString file = m_settings->value("LocationsCreator/POLSolarPath").toString().split("/").last();
QString directory = m_settings->value("LocationsCreator/POLSolarPath").toString().remove("/" + file);
QFileDialog fileDialog(this);
if (directory != "") fileDialog.setDirectory(directory + "/" + file);
if (file != "") fileDialog.selectFile(file);
fileDialog.setNameFilter("POL File (*.pol)");
fileDialog.setWindowTitle("Select POLFile for Solar");
if (!fileDialog.exec())
return;
if (fileDialog.selectedFiles().empty())
{
m_fileNamePOLSolar.clear();
return;
}
m_fileNamePOLSolar = fileDialog.selectedFiles().first();
m_lblPOLSolarPath->setText(m_fileNamePOLSolar);
// store values to QSettings
m_settings->setValue("LocationsCreator/POLSolarPath", m_fileNamePOLSolar);
}
void WindowLocationsCreator::onBtnCreateLocationsClicked()
......@@ -99,11 +128,17 @@ void WindowLocationsCreator::onBtnCreateLocationsClicked()
{
warningText += "ShapeFile ";
}
if (m_fileNamePOL == "")
if (m_fileNamePOLWind == "")
{
if (warningText.length() > 3)
warningText += "and ";
warningText += "POL file ";
warningText += "POL Wind file ";
}
if (m_fileNamePOLSolar == "")
{
if (warningText.length() > 3)
warningText += "and ";
warningText += "POL Solar file ";
}
if (warningText.length() > 3)
{
......@@ -156,17 +191,29 @@ void WindowLocationsCreator::initWidgets()
lyoSF->addWidget(m_lblSFPath);
lyoFiles->addLayout(lyoSF);
// POL
QHBoxLayout * lyoPOL = new QHBoxLayout();
QPushButton * btnPOL = new QPushButton("Load POL");
btnPOL->setToolTip("Select the POL file.");
btnPOL->setWhatsThis(btnPOL->toolTip());
btnPOL->setMinimumWidth(btnWidth);
btnPOL->setMaximumWidth(btnWidth);
m_lblPOLPath = new QLabel();
lyoPOL->addWidget(btnPOL);
lyoPOL->addWidget(m_lblPOLPath);
lyoFiles->addLayout(lyoPOL);
// POL Wind
QHBoxLayout * lyoPOLWind = new QHBoxLayout();
QPushButton * btnPOLWind = new QPushButton("Load POL Wind");
btnPOLWind->setToolTip("Select the POL file.");
btnPOLWind->setWhatsThis(btnPOLWind->toolTip());
btnPOLWind->setMinimumWidth(btnWidth);
btnPOLWind->setMaximumWidth(btnWidth);
m_lblPOLWindPath = new QLabel();
lyoPOLWind->addWidget(btnPOLWind);
lyoPOLWind->addWidget(m_lblPOLWindPath);
lyoFiles->addLayout(lyoPOLWind);
// POL Wind
QHBoxLayout * lyoPOLSolar = new QHBoxLayout();
QPushButton * btnPOLSolar = new QPushButton("Load POL Solar");
btnPOLSolar->setToolTip("Select the POL file.");
btnPOLSolar->setWhatsThis(btnPOLSolar->toolTip());
btnPOLSolar->setMinimumWidth(btnWidth);
btnPOLSolar->setMaximumWidth(btnWidth);
m_lblPOLSolarPath = new QLabel();
lyoPOLSolar->addWidget(btnPOLSolar);
lyoPOLSolar->addWidget(m_lblPOLSolarPath);
lyoFiles->addLayout(lyoPOLSolar);
// --- locations creation -------------------------------------------------
QPushButton * btnCreateLocations = new QPushButton("Use SF + POL");
......@@ -183,7 +230,8 @@ void WindowLocationsCreator::initWidgets()
// --- connections --------------------------------------------------------
connect(btnSF, &QPushButton::clicked, [this](){fileDialogSFFile();});
connect(btnPOL, &QPushButton::clicked, [this](){fileDialogPOLFile();});
connect(btnPOLWind, &QPushButton::clicked, [this](){fileDialogPOLWindFile();});
connect(btnPOLSolar, &QPushButton::clicked, [this](){fileDialogPOLSolarFile();});
connect(btnCreateLocations, &QPushButton::clicked, this, &WindowLocationsCreator::onBtnCreateLocationsClicked);
connect(btnCreateLocationsBySF, &QPushButton::clicked, this, &WindowLocationsCreator::onBtnCreateLocationsBySFClicked);
......@@ -247,11 +295,16 @@ void WindowLocationsCreator::createItems()
// --- open POL file ------------------------------------------------------
POLReadWrite polR;
qDebug() << "Open POL file...";
if (!polR.openFile(m_fileNamePOL))
POLReadWrite polRWind, polRSolar;
qDebug() << "Open POL files...";
if (!polRWind.openFile(m_fileNamePOLWind))
{
QMessageBox::warning(this, "POL error", "Cannot open POL Wind file\n" + m_fileNamePOLWind);
return;
}
if (!polRSolar.openFile(m_fileNamePOLSolar))
{
QMessageBox::warning(this, "POL error", "Cannot open POL file\n" + m_fileNamePOL);
QMessageBox::warning(this, "POL error", "Cannot open POL Solar file\n" + m_fileNamePOLSolar);
return;
}
......@@ -311,8 +364,9 @@ void WindowLocationsCreator::createItems()
areaWind = 0;
// get areas from POL file
POLMunicipal * municipal = polR.getMunicipal(SN_L, RS);
if (municipal == nullptr)
POLMunicipal * municipalWind = polRWind.getMunicipal(SN_L, RS);
POLMunicipal * municipalSolar = polRSolar.getMunicipal(SN_L, RS);
if (municipalWind == nullptr && municipalSolar == nullptr)
{
// qCritical() << "Cannot find POLMunicipal" << RS << "in SN_L" << SN_L << "in POLReadWrite.";
}
......@@ -322,10 +376,14 @@ void WindowLocationsCreator::createItems()
LocationsTableItem locationItem(GEN, RS, AGS, lat, lon, areaSolar, areaWind, polygonID);
QVector<QPolygonF> polygonsAreaWind = municipal->polygons().toVector();
QVector<QPolygonF> polygonsAreaWind = municipalWind->polygons().toVector();
QVector<QPolygonF> polygonsAreaSolar = municipalSolar->polygons().toVector();
locationItem.setAreaPolygonsWind(polygonsAreaWind);
areaWind = municipal->getAreaSum();
locationItem.setAreaPolygonsSolar(polygonsAreaSolar);
areaWind = municipalWind->getAreaSum();
areaSolar = municipalSolar->getAreaSum();
locationItem.setAreaWind(areaWind);
locationItem.setAreaSolar(areaSolar);
locationItem.setMapPolygon(polygon);
locationItem.setSecondaryPolygons(secondaryPolygons);
......@@ -477,27 +535,3 @@ void WindowLocationsCreator::createItemsBySF()
emit locationsCreated();
}
......@@ -23,7 +23,8 @@ private slots:
void onBtnCreateLocationsClicked();
void onBtnCreateLocationsBySFClicked();
void fileDialogSFFile();
void fileDialogPOLFile();
void fileDialogPOLWindFile();
void fileDialogPOLSolarFile();
private:
void initWidgets();
......@@ -34,11 +35,13 @@ private:
// labels
QLabel * m_lblSFPath;
QLabel * m_lblPOLPath;
QLabel * m_lblPOLWindPath;
QLabel * m_lblPOLSolarPath;
// file paths
QString m_fileNameSF;
QString m_fileNamePOL;
QString m_fileNamePOLSolar;
QString m_fileNamePOLWind;
// miscellaneous
QSettings * m_settings;
......
......@@ -2,7 +2,7 @@
AreaPotentialCalculations::AreaPotentialCalculations(WindowShapeFileLoading * windowShapeFileLoading) :
m_windowShapeFileLoading(windowShapeFileLoading),
m_last_SN_L(15)
m_last_SN_L(0)
{
connect(m_windowShapeFileLoading, &WindowShapeFileLoading::calculationSequenceFinished, this, &AreaPotentialCalculations::handleCalculationSequenceFinished);
......@@ -12,9 +12,9 @@ AreaPotentialCalculations::AreaPotentialCalculations(WindowShapeFileLoading * wi
ShapeFileRW::UTM_ETRS89_GRS80_32N);
m_windowShapeFileLoading->selectPOLFile("D:/Calculation_Results/Area_Potential/CalculatedAreaPotential_Germany_Wind_20191014115238_bugfix.pol");
startCalculations();
// startCalculations();
// unifyPOLFiles();
unifyPOLFiles();
}
void AreaPotentialCalculations::handleCalculationSequenceFinished()
......@@ -89,37 +89,20 @@ void AreaPotentialCalculations::startCalculations()
void AreaPotentialCalculations::unifyPOLFiles()
{
// open POL files
QList<QString> paths;
paths
<< "CalculatedAreaPotential_SN_L_1_20190917140506"
<< "CalculatedAreaPotential_SN_L_2_20190917141210"
<< "CalculatedAreaPotential_SN_L_3_20190917223528"
<< "CalculatedAreaPotential_SN_L_4_20190917225255"
<< "CalculatedAreaPotential_SN_L_5_20190918085654"
<< "CalculatedAreaPotential_SN_L_6_20190918110327"
<< "CalculatedAreaPotential_SN_L_7_20190918143800"
<< "CalculatedAreaPotential_SN_L_8_20190918205548"
<< "CalculatedAreaPotential_SN_L_9_20190919211418"
<< "CalculatedAreaPotential_SN_L_10_20190920001535"
<< "CalculatedAreaPotential_SN_L_11_20190920010627"
<< "CalculatedAreaPotential_SN_L_12_20190920063214"
<< "CalculatedAreaPotential_SN_L_13_20190920103908"
<< "CalculatedAreaPotential_SN_L_14_20190920170214"
<< "CalculatedAreaPotential_SN_L_15_20190920201748"
<< "CalculatedAreaPotential_SN_L_16_20190921003027"
;
QDir dir("C:/Res");
dir.setNameFilters(QStringList({"*.pol"}));
QList<QString> paths = dir.entryList();
POLReadWrite polCombined;
for (QString str : paths)
{
POLReadWrite prw;
prw.openFile("D:/Calculation_Results/Area_Potential/NewCalculation_after_bugfix/" + str + ".pol");
prw.openFile("C:/Res/" + str);
polCombined.addDataSet(prw.getDataSets().first());
}
// write new file
polCombined.writeFile("Wind");
polCombined.writeFile("Solar");
}
......@@ -124,7 +124,7 @@ void PolygonObject::setPos(const QPointF & nPos)
if (nPos != _geoPoly.boundingRect().center())
{
const QPointF diff = nPos - this->pos();
//_geoPoly.translate(diff);
_geoPoly.translate(diff);
//We should also move our edit handles
foreach(MapGraphicsObject * circle, _editCircles)
......@@ -138,6 +138,7 @@ void PolygonObject::setPos(const QPointF & nPos)
//If this isn't here, we get TEARING when we edit our polygons
this->posChanged();
this->polygonChanged(this->geoPoly());
}
void PolygonObject::setObjectName(const QString & objectName)
......
......@@ -8,7 +8,8 @@
#include <regex>
PolygonObjectManager::PolygonObjectManager(QObject *parent) : QObject(parent),
m_polygonsEditable(true)
m_polygonsEditable(true),
m_removedSingleItem(false)
{
m_numOfPolygons = 0;
}
......@@ -36,9 +37,16 @@ void PolygonObjectManager::add(PolygonObject * p, QString name, QPolygonF polygo
int PolygonObjectManager::getIndex(QString PolygonName, bool noLocking)
{
if (noLocking)
return m_PolygonNamesMap[PolygonName];
{
if (!m_removedSingleItem)
return m_PolygonNamesMap[PolygonName];
else
return m_PolygonNames.indexOf(PolygonName);
}
else
{
return getIndex(PolygonName);
}
}
PolygonObject * PolygonObjectManager::remove(int index) {
......@@ -53,6 +61,7 @@ PolygonObject * PolygonObjectManager::remove(int index) {
m_QueryTypeList.removeAt(index);
m_QueryDescription.removeAt(index);
--m_numOfPolygons;
m_removedSingleItem = true;
readWriteLock.unlock();
return p;
......@@ -228,7 +237,13 @@ void PolygonObjectManager::appendQueryType(int index, QString queryType)
int PolygonObjectManager::getIndex(QString PolygonName)
{
readWriteLock.lockForRead();
int index = m_PolygonNamesMap[PolygonName];
int index;
if (m_removedSingleItem)
index = m_PolygonNames.indexOf(PolygonName);
else
index = m_PolygonNamesMap[PolygonName];
readWriteLock.unlock();
return index;
}
......@@ -393,6 +408,7 @@ void PolygonObjectManager::clearAll()
m_PolygonNamesMap.clear();
m_polygonDistances.clear();
m_numOfPolygons = 0;
m_removedSingleItem = false;
emit polygonCreated(0);
}
......
......@@ -72,6 +72,7 @@ private:
QMap<QString, int> m_PolygonNamesMap;
QList<int> m_polygonDistances;
int m_numOfPolygons;
bool m_removedSingleItem;
QMutex mutexAppendQueryType;
QReadWriteLock readWriteLock;
......
......@@ -208,7 +208,8 @@ void WidgetPolygons::onBtnRemoveClicked()
QModelIndexList selIndex = m_tableView->selectionModel()->selectedIndexes();
for (int i = selRows.count() - 1; i >= 0; --i)
{
emit removePolygon(m_PolygonObjectManager->getPolygonObject(selIndex.value(i).row()));
PolygonObject * po = m_PolygonObjectManager->getPolygonObject(selIndex.value(i).row());
emit removePolygon(po);
}
}
......@@ -352,7 +353,7 @@ void WidgetPolygons::onTxtDistanceKeyPressed(QKeyEvent * keyEvent)
void WidgetPolygons::handleSelectedRowChanged(const QModelIndex &current, const QModelIndex &previous)
{
Q_UNUSED(previous);
Q_UNUSED(previous)
emit selectedRowChanged(current.row());
if (!current.isValid())
......
......@@ -47,7 +47,7 @@ void CombCalculation_Parallel::run()
float combArea = m_combManager->combArea();
float coverageThreshold = (float)0.5; // changed from 0.05 to 0.5
float coverageThreshold = static_cast<float>(0.5); // changed from 0.05 to 0.5
float coverage = 0.0;
for (int i = 0; i < m_polygonList.size(); ++i)
{
......@@ -55,6 +55,9 @@ void CombCalculation_Parallel::run()
a = m_polygonList[i].boundingRect(),
b = combPolygon.boundingRect();
// slightly shrink comb to avoid floating point failures
b -= QMarginsF(b.width(), b.height(), b.width(), b.height()) / 100;
if (a.left() > b.right())
break;
......
......@@ -100,7 +100,6 @@ void CustomXmlHandler::run()
if (!file->exists())
{
qCritical() << "XMLParser: File" << xmlData.fileName << "does not exist.";
file->deleteLater();
emit parsingFinished(false);
}
else
......@@ -119,6 +118,8 @@ void CustomXmlHandler::run()
}
emit parsingFinished(ok);
}
file->close();
file->deleteLater();
xmlData = m_xmlParser->nextFile();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment