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

Add H5Read to DataTableModel (NOT FINISHED YET)

additional changes:
LocationsTableModel selection behavior changed
Node polygons drawing after Project load works now
PolygonCalculations::toString bug fix
HDF5 reader bug fix
parent a4f0d9df
......@@ -8,7 +8,7 @@ BinaryFileRead::BinaryFileRead(QString fileLocation) :
m_fileLocation(fileLocation),
m_fileBuffered(false)
{
m_ok = QFile::exists(fileLocation);
}
BinaryFileRead::~BinaryFileRead()
......@@ -52,6 +52,11 @@ bool BinaryFileRead::fileBuffered() const
return m_fileBuffered;
}
bool BinaryFileRead::isOK() const
{
return m_ok;
}
bool BinaryFileRead::dataStream(QDataStream * stream, QByteArray * byteArray, quint64 offset, quint64 size)
{
if (size == 0)
......
......@@ -3,8 +3,6 @@
#include <QtCore>
class BinaryFileRead
{
public:
......@@ -17,7 +15,11 @@ public:
bool fileBuffered() const;
bool isOK() const;
private:
bool m_ok;
QString m_fileLocation;
bool m_fileBuffered;
char * m_bufferedFile;
......
......@@ -19,17 +19,25 @@
H5Read::H5Read(QString fileLocation) :
m_fileLocation(fileLocation),
m_binaryFileRead(nullptr),
m_LocalHeap(nullptr),
m_GroupSymbolTable(nullptr),
m_LatLonGrid(nullptr),
m_ok(false)
{
// create BinaryFileRead
m_binaryFileRead = new BinaryFileRead(fileLocation);
if (!m_binaryFileRead->isOK())
{
qCritical() << C_ERR << "File not existent";
}
QByteArray * byteArray = new QByteArray();
QDataStream * stream = new QDataStream();
if (!m_binaryFileRead->dataStream(stream, byteArray))
{
qCritical() << C_ERR << "Error during file read out. Abort.";
m_ok = false;
return;
}
......@@ -38,6 +46,11 @@ H5Read::H5Read(QString fileLocation) :
* ----------------------------------------------------------------------------------------------- */
Superblock * H_superblock = new Superblock(stream, m_binaryFileRead);
if (!H_superblock->ok())
{
qCritical() << C_ERR << "Error in Superbock. See log for details.";
return;
}
/* -----------------------------------------------------------------------------------------------
* III.A. Disk Format: Level 1A - B-trees and B-tree Nodes
......@@ -60,7 +73,6 @@ H5Read::H5Read(QString fileLocation) :
if (!H_B_Valid)
{
qCritical() << C_ERR << "Signature of B-Tree expected. Got" << H_BSignature;
m_ok = false;
return;
}
......@@ -74,7 +86,6 @@ H5Read::H5Read(QString fileLocation) :
if (H_BNode_EntriesUsed > 1)
{
qCritical() << C_RESTRICTED << "More then one Entries of B-Tree used:" << H_BNode_EntriesUsed;
m_ok = false;
return;
}
......@@ -93,7 +104,6 @@ H5Read::H5Read(QString fileLocation) :
if (H_BNode_NodeType != 0)
{
qCritical() << C_ERR << C_RESTRICTED << "Expected B-Tree Node Type 0. Got:" << H_BNode_NodeType;
m_ok = false;
return;
}
......@@ -136,7 +146,6 @@ H5Read::H5Read(QString fileLocation) :
if (index_lat == -1 || index_lon == -1)
{
qCritical() << C_ERR << "Cannot find DatasetIndex.";
m_ok = false;
return;
}
......@@ -161,7 +170,6 @@ H5Read::H5Read(QString fileLocation) :
m_GroupSymbolTable->getDimensionSizes(index_lat)[1] != m_GroupSymbolTable->getDimensionSizes(index_lon)[1])
{
qCritical() << C_ERR << "Dimensions of Latitude and Longitude data does not match.";
m_ok = false;
return;
}
......@@ -189,11 +197,11 @@ H5Read::H5Read(QString fileLocation) :
H5Read::~H5Read()
{
delete m_LocalHeap;
delete m_GroupSymbolTable;
delete m_LatLonGrid;
if (m_LocalHeap != nullptr) delete m_LocalHeap;
if (m_GroupSymbolTable != nullptr) delete m_GroupSymbolTable;
if (m_LatLonGrid != nullptr) delete m_LatLonGrid;
delete m_binaryFileRead;
if (m_binaryFileRead != nullptr) delete m_binaryFileRead;
}
vector<float> H5Read::extractTimeSeries(QString datasetName, float lat, float lon)
......@@ -340,6 +348,11 @@ pair<float, float> H5Read::getCoordinatesByCellIndex(int index)
return m_LatLonGrid->getPair(index);
}
LocalHeap * H5Read::getLocalHeap()
{
return m_LocalHeap;
}
bool H5Read::ok() const
{
return m_ok;
......
#ifndef H5READ_H
#define H5READ_H
#include "charlfiletools_global.h"
#include "GroupSymbolTable.h"
#include "LatLonGrid.h"
#include "LocalHeap.h"
#include "charlfiletools_global.h"
#include <BinaryFileRead.h>
#include <QDataStream>
......@@ -26,6 +26,8 @@ public:
pair<float, float> getCoordinatesByCellIndex(int index);
LocalHeap * getLocalHeap();
bool ok() const;
private:
......
......@@ -44,3 +44,8 @@ int LocalHeap::getDatasetIndex(QString linkName)
}
return found;
}
QList<QString> LocalHeap::getLinkNames()
{
return m_LinkNames;
}
#ifndef LOCALHEAP_H
#define LOCALHEAP_H
#include "charlfiletools_global.h"
#include "GroupSymbolTable.h"
#include "InformationBlock.h"
......@@ -8,12 +9,13 @@
class LocalHeap : public InformationBlock
class CHARLFILETOOLSSHARED_EXPORT LocalHeap : public InformationBlock
{
public:
LocalHeap(QDataStream * stream, GroupSymbolTable * groupSymbolTable);
int getDatasetIndex(QString linkName);
QList<QString> getLinkNames();
private:
quint8 m_Version;
......
#include "Superblock.h"
Superblock::Superblock(QDataStream * stream, BinaryFileRead * binaryFileRead)
Superblock::Superblock(QDataStream * stream, BinaryFileRead * binaryFileRead) :
m_ok(false)
{
const quint8 formatSignature_VALUE[8] = {137, (uint)'H', (uint)'D', (uint)'F', 13, 10, 26, 10};
......@@ -58,6 +59,8 @@ Superblock::Superblock(QDataStream * stream, BinaryFileRead * binaryFileRead)
return;
}
m_ok = true;
/// Part of Superblock: Root Group Symbol Table Entry
m_RootGroupSymbolTableEntry = new SymbolTableEntry(stream, binaryFileRead);
}
......@@ -12,6 +12,8 @@ class Superblock
public:
Superblock(QDataStream * stream, BinaryFileRead * binaryFileRead);
bool m_ok;
SymbolTableEntry * m_RootGroupSymbolTableEntry;
quint8 m_formatSignature[8];
......@@ -30,6 +32,8 @@ public:
m_AddressOfFileFreeSpaceInfo,
m_EndOfFileAdress,
m_DriverInformationBlockAddress;
bool ok() const {return m_ok;}
};
#endif // SUPERBLOCK_H
......@@ -468,7 +468,7 @@ void CharLGui::initWidgets()
m_plantWidget->setObjectName("PlantWidget");
m_dataWidget = new DataWidget(m_modelWindData, m_modelSolarData, m_modelTemperatureData,
m_modelPowerDemandData, this);
m_modelPowerDemandData, m_preferences, this);
m_dataWidget->setObjectName("DataWidget");
m_locationsWidget = new LocationsWidget(m_modelLocations, m_modelSelectNode,
......@@ -1204,6 +1204,11 @@ bool CharLGui::loadProject()
else if (grandElement.tagName() == "map_polygon")
{
item->setMapPolygon(PolygonCalculations::fromString(grandElement.text()));
PolygonObject * polygonObject = new PolygonObject(item->getMapPolygon());
polygonObject->setObjectName(item->getName());
polygonObject->drawName();
item->setPolygonObject(polygonObject);
m_nodeWidget->drawPolygon(polygonObject);
}
grandChild = grandChild.nextSibling();
}
......
......@@ -6,6 +6,8 @@
#include "SimulationPreferences.h"
#include "HDF5/H5Read.h"
//////////////////////////////////////////
/// ITEM IMPLEMENTATION ///////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
......@@ -63,25 +65,44 @@ bool DataTableItem::setDataFile(QString fileName)
}
if (fileName != "")
{
if (!loadFile(fileName, dummyVector))
{
m_dataFile = "";
return false;
}
if (static_cast<int>(dummyVector.size()) == m_preferences->getNumberOfTimeSteps())
if (m_preferences->assignDataFromMap())
{
m_dataFile = fileName;
m_data = dummyVector;
H5Read h5(fileName);
if (h5.ok())
{
m_dataFile = fileName;
m_dataFileSet = "";
}
else
{
m_dataFile = "";
m_dataFileSet = "";
return false;
}
}
else
{
QMessageBox::information(nullptr, QObject::tr("CharL - Mismatch"),
QObject::tr("Number of points does not match preference "
"specification and therefor was not read.\n"
"Please choose file accordingly or chance preferences.\n"
"Previous File not replaced."),
QMessageBox::Ok);
return false;
if (!loadFile(fileName, dummyVector))
{
m_dataFile = "";
return false;
}
if (static_cast<int>(dummyVector.size()) == m_preferences->getNumberOfTimeSteps())
{
m_dataFile = fileName;
m_data = dummyVector;
}
else
{
QMessageBox::information(nullptr, QObject::tr("CharL - Mismatch"),
QObject::tr("Number of points does not match preference "
"specification and therefor was not read.\n"
"Please choose file accordingly or chance preferences.\n"
"Previous File not replaced."),
QMessageBox::Ok);
return false;
}
}
}
else
......@@ -108,25 +129,43 @@ bool DataTableItem::setDataFileTwo(QString fileName)
}
if (fileName != "")
{
if (!loadFile(fileName, dummyVector))
{
m_dataFileTwo = "";
return false;
}
if (static_cast<int>(dummyVector.size()) == m_preferences->getNumberOfTimeSteps())
if (m_preferences->assignDataFromMap())
{
m_dataFileTwo = fileName;
m_dataTwo = dummyVector;
H5Read h5(fileName);
if (h5.ok())
{
m_dataFileTwo = fileName;
m_dataFileTwoSet = "";
}
else
{
m_dataFileTwo = "";
m_dataFileTwoSet = "";
return false;
}
}
else
{
QMessageBox::information(nullptr, QObject::tr("CharL - Mismatch"),
QObject::tr("Number of points does not match preference "
"specification and therefor was not read.\n"
"Please choose file accordingly or chance preferences.\n"
"Previous File not replaced."),
QMessageBox::Ok);
return false;
if (!loadFile(fileName, dummyVector))
{
m_dataFileTwo = "";
return false;
}
if (static_cast<int>(dummyVector.size()) == m_preferences->getNumberOfTimeSteps())
{
m_dataFileTwo = fileName;
m_dataTwo = dummyVector;
}
else
{
QMessageBox::information(nullptr, QObject::tr("CharL - Mismatch"),
QObject::tr("Number of points does not match preference "
"specification and therefor was not read.\n"
"Please choose file accordingly or chance preferences.\n"
"Previous File not replaced."),
QMessageBox::Ok);
return false;
}
}
}
else
......@@ -367,7 +406,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
case 2:
if (m_data[index.row()].getDataFile() != "")
{
return "File loaded.";
if (m_preferences->assignDataFromMap())
{
return "H5 loaded.";
}
else
{
return "File loaded.";
}
}
return "No File.";
case 3:
......@@ -389,7 +435,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
case PowerDemand:
if (m_data[index.row()].getDataForecastFile() != "")
{
return "File loaded.";
if (m_preferences->assignDataFromMap())
{
return "H5 loaded.";
}
else
{
return "File loaded.";
}
}
return "No File.";
}
......@@ -398,7 +451,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataFileTwo() != "")
{
return "File loaded.";
if (m_preferences->assignDataFromMap())
{
return "H5 loaded.";
}
else
{
return "File loaded.";
}
}
return "No File.";
}
......@@ -407,7 +467,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataForecastFile() != "")
{
return "File loaded.";
if (m_preferences->assignDataFromMap())
{
return "H5 loaded.";
}
else
{
return "File loaded.";
}
}
return "No File.";
}
......@@ -416,7 +483,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataForecastFileTwo() != "")
{
return "File loaded.";
if (m_preferences->assignDataFromMap())
{
return "H5 loaded.";
}
else
{
return "File loaded.";
}
}
return "No File.";
}
......@@ -431,7 +505,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
case 2:
if (m_data[index.row()].getDataFile() != "")
{
return QVariant(QColor(200,250,200));
if (m_preferences->assignDataFromMap())
{
return QVariant(QColor(255,225,0));
}
else
{
return QVariant(QColor(200,250,200));
}
}
return QVariant(QColor(250,200,200));
case 3:
......@@ -439,7 +520,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataForecastFile() != "")
{
return QVariant(QColor(200,250,200));
if (m_preferences->assignDataFromMap())
{
return QVariant(QColor(255,225,0));
}
else
{
return QVariant(QColor(200,250,200));
}
}
return QVariant(QColor(250,200,200));
}
......@@ -449,7 +537,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataFileTwo() != "")
{
return QVariant(QColor(200,250,200));
if (m_preferences->assignDataFromMap())
{
return QVariant(QColor(255,225,0));
}
else
{
return QVariant(QColor(200,250,200));
}
}
return QVariant(QColor(250,200,200));
}
......@@ -459,7 +554,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataForecastFile() != "")
{
return QVariant(QColor(200,250,200));
if (m_preferences->assignDataFromMap())
{
return QVariant(QColor(255,225,0));
}
else
{
return QVariant(QColor(200,250,200));
}
}
return QVariant(QColor(250,200,200));
}
......@@ -469,7 +571,14 @@ QVariant DataTableModel::data(const QModelIndex &index, int role) const
{
if (m_data[index.row()].getDataForecastFileTwo() != "")
{
return QVariant(QColor(200,250,200));
if (m_preferences->assignDataFromMap())
{
return QVariant(QColor(255,225,0));
}
else
{
return QVariant(QColor(200,250,200));
}
}
return QVariant(QColor(250,200,200));
}
......@@ -894,8 +1003,8 @@ bool DataTableModel::removeItem(const QModelIndex &index)
emit layoutAboutToBeChanged();
beginRemoveRows(QModelIndex(), index.row(), index.row());
m_data.remove(index.row());
emit layoutChanged();
endRemoveRows();
emit layoutChanged();
return true;
}
return false;
......@@ -919,7 +1028,10 @@ const AbstractCharLItem *DataTableModel::getItem(int row) const
/// DELEGATE IMPLEMENTATION ///////////////////////////////////////////////////////////////////
//////////////////////////////////////////
DataTableDelegate::DataTableDelegate(QObject *parent) : QItemDelegate(parent)
DataTableDelegate::DataTableDelegate(
Preferences * preferences,
QObject * parent) : QItemDelegate(parent),
m_preferences(preferences)
{
}
......@@ -943,7 +1055,9 @@ QWidget * DataTableDelegate::createEditor(QWidget *parent, const QStyleOptionVie
QComboBox * box = new QComboBox(parent);
box->setMinimumHeight(10);
box->setMinimumWidth(10);
QStringList entries = {"No", "Yes"};
QStringList entries;
entries.append("No");
entries.append("Yes");
box->insertItems(0, entries);
return box;
}
......@@ -959,7 +1073,17 @@ QWidget * DataTableDelegate::createEditor(QWidget *parent, const QStyleOptionVie
/// this is a quick and dirty work-around and should be replaced by a more elegant method ///
///////////////////////////////////////////////////////////////////////////////////////////////////////////
QString fileName = QFileDialog::getOpenFileName(parent, tr("Open Time Series for " + index.model()->data(index.model()->index(index.row(), 2)).toByteArray()), "C:" , tr("*.csv"));
QString fileFilter;
if (m_preferences->assignDataFromMap())
{
fileFilter = "HDF5 File (*.h5)";
}
else
{
fileFilter = "CSV File (*.csv)";
}
QString fileName = QFileDialog::getOpenFileName(parent, tr("Open Time Series for " + index.model()->data(index.model()->index(index.row(), 2)).toByteArray()), "C:" , fileFilter);
QWidget * widget = new QWidget(parent);
widget->setObjectName(fileName);
return widget;
......
......@@ -25,6 +25,8 @@
#include <QDialog>
#include <QDomDocument>
#include "AbstractCharLTableModel.h"
#include "../Preferences.h"
......@@ -84,9 +86,13 @@ private:
bool m_scaledData;
bool m_doubleDataRequired; //Currently used for solar (when DHI given, then DNI needed) and wind (when also direction is given)
QString m_dataFile;
QString m_dataFileSet;
QString m_dataFileTwo;
QString m_dataFileTwoSet;
QString m_dataForecastFile;
QString m_dataForecastFileSet;
QString m_dataForecastFileTwo;
QString m_dataForecastFileTwoSet;
vector<float> m_data;
vector<float> m_dataTwo;
vector<vector<float>> m_dataForecast;
......@@ -138,7 +144,7 @@ class DataTableDelegate : public QItemDelegate
{