diff --git a/CMakeLists.txt b/CMakeLists.txt index ddb1b870c..040dff745 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,6 +403,7 @@ set(OpenInfraPlatform_UserInterface_Forms UserInterface/Forms/MainWindow.ui UserInterface/Forms/LicenseAndCopyrightInformation.ui UserInterface/Forms/PreferencesDialog.ui + UserInterface/Forms/IfcTreeDialog.ui # Currently not included. #UserInterface/Forms/CreateAccidentReport.ui diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp index 3836d3fc1..9cb1ec812 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.cpp @@ -19,6 +19,7 @@ #include "IfcGeometryModel.h" #include "Exception\UnhandledException.h" + void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::reset() { for( auto geom : geometries_ ) @@ -37,6 +38,11 @@ void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addGeometry(std::s geometryMutex_.unlock(); } +void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::setExpressModel(std::shared_ptr expressModel) +{ + expressModel_ = expressModel; +} + // --------------------------------------------------------------------------------------------------------------------------------------------------- // Interface IModel implementation bool OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::isEmpty() const diff --git a/Core/src/IfcGeometryConverter/IfcGeometryModel.h b/Core/src/IfcGeometryConverter/IfcGeometryModel.h index 207904f0a..0736faf9f 100644 --- a/Core/src/IfcGeometryConverter/IfcGeometryModel.h +++ b/Core/src/IfcGeometryConverter/IfcGeometryModel.h @@ -30,6 +30,7 @@ #include #include "namespace.h" +#include "EXPRESS/EXPRESSModel.h" typedef buw::VertexPosition3Color3Normal3 VertexLayout; @@ -80,8 +81,10 @@ namespace OpenInfraPlatform std::vector> geometries_; std::mutex geometryMutex_; - std::string filename_; - oip::GeorefMetadata georefMeta_; + std::string filename_; + oip::GeorefMetadata georefMeta_; + + std::shared_ptr expressModel_; public: void reset(); @@ -89,6 +92,9 @@ namespace OpenInfraPlatform void addGeometry(std::shared_ptr geometry); std::vector> const &geometries() const { return geometries_; } + void setExpressModel(std::shared_ptr expressModel); + std::shared_ptr const getExpressModel() const { return expressModel_; } + // --------------------------------------------------------------------------------------------------------------------------------------------------- // Interface IModel implementation // --------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Core/src/IfcGeometryConverter/IfcImporter.h b/Core/src/IfcGeometryConverter/IfcImporter.h index 2855748fc..0ac33b92e 100644 --- a/Core/src/IfcGeometryConverter/IfcImporter.h +++ b/Core/src/IfcGeometryConverter/IfcImporter.h @@ -95,6 +95,12 @@ class IfcImporterT if (!ifcModel->isEmpty()) models.push_back(ifcModel); + //store a pointer to the express model in the in the ifc model (used for the tree viewer) + for (auto& model : models) + { + model->setExpressModel(expressModel); + } + return models; } catch (const oip::InconsistentModellingException& ex) diff --git a/UserInterface/Dialogues/IfcTreeDialog.cpp b/UserInterface/Dialogues/IfcTreeDialog.cpp new file mode 100644 index 000000000..c8123b586 --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeDialog.cpp @@ -0,0 +1,67 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeDialog.h" +#include "IfcTreeModel.h" +#include "ui_IfcTreeDialog.h" +#include "DataManagement/General/Data.h" +#include "Exception\UnhandledException.h" +#include +#include + +#include +#include +#include +#include + +OpenInfraPlatform::UserInterface::IfcTreeDialog::IfcTreeDialog(QWidget *parent /*= nullptr*/) : + QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint), + ui_(new Ui::IfcTreeDialog) +{ + ui_->setupUi(this); +} + +OpenInfraPlatform::UserInterface::IfcTreeDialog::~IfcTreeDialog() +{ + +} + +void OpenInfraPlatform::UserInterface::IfcTreeDialog::show() +{ + //testing treeview with contents of IFC file + auto model = Core::DataManagement::DocumentManager::getInstance().getData().getLastModel(); + if (std::dynamic_pointer_cast(model)) + { + auto ifcModel = std::static_pointer_cast(model); + auto expressModelShared = ifcModel->getExpressModel(); + OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel = expressModelShared.get(); + IfcTreeModel *treeModel = new IfcTreeModel(expressModel); + ui_->ifcTreeView->setModel(treeModel); + ((QDialog*)this)->show(); + } + else + { + //only for now till the selected model is properly handled + throw oip::UnhandledException("Last model is not a IFC model"); + } +} + + +void OpenInfraPlatform::UserInterface::IfcTreeDialog::on_pushButtonClose_clicked() +{ + hide(); +} diff --git a/UserInterface/Dialogues/IfcTreeDialog.h b/UserInterface/Dialogues/IfcTreeDialog.h new file mode 100644 index 000000000..167d550ce --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeDialog.h @@ -0,0 +1,55 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include "ui_IfcTreeDialog.h" +#include "ViewPanel/View.h" + +#include +#include + +namespace OpenInfraPlatform +{ + namespace UserInterface + { + class IfcTreeDialog : public QDialog + { + Q_OBJECT; + + public: + IfcTreeDialog(QWidget *parent = nullptr); + + //! Virtual destructor. + virtual ~IfcTreeDialog(); + + void show(); + + private Q_SLOTS: + void on_pushButtonClose_clicked(); + + private: + Ui::IfcTreeDialog* ui_; + + }; // end class IfcTree + } // end namespace UserInterface +} // end namespace OpenInfraPlatform + +namespace oip +{ + using OpenInfraPlatform::UserInterface::IfcTreeDialog; +} diff --git a/UserInterface/Dialogues/IfcTreeItem.cpp b/UserInterface/Dialogues/IfcTreeItem.cpp new file mode 100644 index 000000000..b8009a4e3 --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeItem.cpp @@ -0,0 +1,181 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeItem.h" +#include +#include +#include +#include "Exception\UnhandledException.h" +#include "visit_struct\visit_struct.hpp" + + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem) +{ + data_ = data; + parentItem_ = parentItem; + //itemData_.push_back(data_->getStepLine()); + itemData_.push_back(QString::fromStdString(data_->classname())); +} + +//OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(std::shared_ptr &data, IfcTreeItem * parent) +// : m_managedData(data), m_parentItem(parent), parser_() +//{ +// parser_.thisPtr = this; +//} + +OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList &data, IfcTreeItem *parent) +{ + parentItem_ = parent; + itemData_ = data; +} + +OpenInfraPlatform::UserInterface::IfcTreeItem::~IfcTreeItem() +{ + qDeleteAll(childItems_); +} + +void OpenInfraPlatform::UserInterface::IfcTreeItem::appendChild(IfcTreeItem *child) +{ + childItems_.append(child); +} + +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::child(int row) +{ + //if (row < 0 || row >= m_childItems.size()) + // return nullptr; + return childItems_.value(row); //QList provides default values in case row is out of range +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::childCount() const +{ + return childItems_.count(); +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::columnCount() const +{ + return itemData_.count(); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +{ + //if (column < 0 || column >= m_itemData.size()) + // return QVariant(); + return itemData_.value(column); //QList provides default values in case row is out of range +} + +//QVariant OpenInfraPlatform::UserInterface::IfcTreeItem::data(int column) const +//{ +// //auto attributes = getAttributeDescription()(*data_); +// +// //switch (column) +// //{ +// //case 0: +// // return attributes.names_[row]; +// // break; +// //case 1: +// // return attributes.value_[row]; +// // break; +// //case 2: +// // return attributes.typename_[row]; +// // break; +// //} +//} + +OpenInfraPlatform::UserInterface::IfcTreeItem *OpenInfraPlatform::UserInterface::IfcTreeItem::parentItem() +{ + return parentItem_; +} + +int OpenInfraPlatform::UserInterface::IfcTreeItem::row() const +{ + if (parentItem_) + return parentItem_->childItems_.indexOf(const_cast(this)); + + return 0; +} + +QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const +{ + std::string ifcClassName = data_->classname(); + return QString::fromStdString(ifcClassName); +} + +//struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription +//{ +// template typename std::enable_if::value && std::is_base_of::value, void>::type +// operator()(T entity) +// { +// visit_struct::for_each(entity, [&](const char* name, const auto &value) { +// names_.push_back(name); +// typename_ = typeid(T).name(entity); +// value_.push_back(value); +// }); +// } +// +// //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. +// template typename std::enable_if::value, void>::type +// operator()(T& entity) const +// { +// std::string message = "Invalid function call. " + std::string(typeid(entity).name()) + " isn't a member of EXPRESSEntity."; +// throw oip::UnhandledException(message); +// } +// +// //This is a dummy function which should never be called but is required by the compiler since it could theoretically be called. Throws exception. +// void operator()(OpenInfraPlatform::EarlyBinding::EXPRESSEntity& entity) const +// { +// throw oip::UnhandledException("Invalid function call (IfcTreeItem::getAttributeDescription)"); +// } +// +// std::vector names_; +// std::vector typename_; +// std::vector value_; +//}; + +//void OpenInfraPlatform::UserInterface::IfcTreeItem::createChildren() +//{ +// auto func = [&](auto item)->void { +// visit_struct::for_each(item, [&](const char* name, auto &value) { +// IfcTreeItem* child; +// //if(std::is_base_of::value) { +// // child = new TreeItem(value, this); +// //} +// //else { +// // child = new TreeItem(OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Object(), this); +// //} +// std::shared_ptr ptr = nullptr; +// child = new IfcTreeItem(ptr, this); +// QList itemData; +// itemData << QVariant(name) << QVariant("") << QVariant(typeid(value).name()); +// this->appendChild(child); +// }); +// }; +// +// auto parse = [&](auto item) { +// visit_struct::for_each(item, parser_); +// }; +// +// if (m_managedData && m_managedData.get() != nullptr) { +// if (std::dynamic_pointer_cast(m_managedData)) { +// //OpenInfraPlatform::IfcAlignment1x1::castToVisitableAndCall(std::dynamic_pointer_cast(m_managedData), parse); +// } +// } +//} + +//void OpenInfraPlatform::UserInterface::TreeItem::setItemData(QList itemData) +//{ +// itemData_ = itemData; +//} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeItem.h b/UserInterface/Dialogues/IfcTreeItem.h new file mode 100644 index 000000000..5bdb37bec --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeItem.h @@ -0,0 +1,240 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef IFCTREEITEM_H +#define IFCTREEITEM_H + +#include "EXPRESS/EXPRESSReference.h" +#include +#include + + +namespace OpenInfraPlatform { + namespace UserInterface { + + class IfcTreeItem + { + public: + explicit IfcTreeItem(OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data, IfcTreeItem *parentItem); + explicit IfcTreeItem(const QList &data, IfcTreeItem *parentItem = 0); + ~IfcTreeItem(); + + void appendChild(IfcTreeItem *child); + + IfcTreeItem *child(int row); + int childCount() const; + int columnCount() const; + QVariant data(int column) const; + int row() const; + IfcTreeItem *parentItem(); + QString getIfcClassName() const; + + //void setItemData(QList itemData); + //void createChildren(); + + private: + QList childItems_; + OpenInfraPlatform::EarlyBinding::EXPRESSEntity *data_; + QList itemData_; + IfcTreeItem *parentItem_; + + //struct getAttributeDescription; + + //std::shared_ptr m_managedData = nullptr; + + ////Helper struct which parses the attributes of a derived entity which are IfcAlignment1x1Types and hold flat values. + //struct parseType { + + // void operator()(const char* name, std::string string) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(string.data()) << QVariant("std::string"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //Function operator() which creates a statement from a boolean value. + // void operator()(const char* name, bool value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value) << QVariant("bool"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // void operator()(const char* name, std::shared_ptr value) + // { + // TreeItem* child = new TreeItem(std::static_pointer_cast(value), thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value ? value->getId() : -1); //<< QVariant(value ? value->classname() : "nullptr"); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //TODO: Get value stored in type + // void operator()(const char* name, std::shared_ptr value) + // { + // TreeItem* child = new TreeItem(std::static_pointer_cast(value), thisPtr); + // QList itemData; + + // //std::stringstream ss; + // if (value) + // //readStepData(std::string& arg) + // //value->getStepData(ss); + + + // //auto classname = value->classname(); //Gibt z.B. IfcLabel o.ä. zurück + // //static_cast(value); + // //auto castedValue = value.m_value; //gibt m_value zurück aus IfcLabel, also den eigentlichen Wert, der als String o.ö. gespeichert ist + // //auto castedType = typeid(castedValue).name(); //gibt den Typ von m_value zurück, also z.B. String + // // + // //if (castedType == "string" || "char") + // // QVariant value2 = QVariant(castedValue.data()); + // // return value2; + // //if (castedType == "bool" || "int" || "float" || "double") + // // QVariant value2 = QVariant(castedValue); + // // return value2; + + // //itemData << QVariant(name) << QVariant(ss.str().data()) << QVariant(value ? value->classname() : "nullptr"); + // itemData << QVariant(name) << QVariant("m_type"); //<< QVariant(value ? value->classname() : "nullptr"); + // //itemData << QVariant(name) << QVariant("m_type") << QVariant(value ? value->classname() : "nullptr"); + + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //template typename std::enable_if::value && !std::is_base_of::value, void>::type + // //operator()(const char* name, std::shared_ptr value) + // //{ + // // std::shared_ptr ptr = nullptr; + // // TreeItem* child = new TreeItem(ptr, thisPtr); + // // QList itemData; + // // itemData << QVariant(name) << QVariant("m_select") << QVariant(typeid(T).name()); + // // child->setItemData(itemData); + // // thisPtr->appendChild(child); + // //} + + // //template typename std::enable_if::value && !std::is_base_of::value && !std::is_base_of::value, void>::type + // // operator()(const char* name, std::shared_ptr value) + // template typename std::enable_if::value && !std::is_base_of::value, void>::type + // operator()(const char* name, std::shared_ptr value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + + // //if !std::is_base_of::value, void>::type + // //{ + // //std::stringstream ss; + // //if(value) + // // value->getStepData(ss); + // //return ss; + // //} + + // //itemData << QVariant(name) << QVariant(ss.str().data()) << QVariant(typeid(T).name()); + // itemData << QVariant(name) << QVariant("m_select") << QVariant(typeid(T).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + // //void operator()(const char* name, std::shared_ptr value) + // //{ + // // std::shared_ptr ptr = nullptr; + // // TreeItem* child = new TreeItem(ptr, thisPtr); + // // QList itemData; + // // itemData << QVariant(name) << QVariant("m_enum") << QVariant(value->classname()); + // // child->setItemData(itemData); + // // thisPtr->appendChild(child); + // //} + + // template typename std::enable_if::value || std::is_same::value || std::is_same::value, void>::type + // operator()(const char* name, T value) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant(value) << QVariant(typeid(value).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + // } + + + // //Function operator() which covers std::shared_ptr. + // //template + // //void operator()(const char* name, std::shared_ptr &ptr) + // //{ + // //} + + // //Function operator() which covers std::vector. + // template + // void operator()(const char* name, std::vector vector) + // { + // std::shared_ptr ptr = nullptr; + // TreeItem* child = new TreeItem(ptr, thisPtr); + // QList itemData; + // itemData << QVariant(name) << QVariant("vector") << QVariant(typeid(T).name()); + // child->setItemData(itemData); + // thisPtr->appendChild(child); + + // int i = 0; + // for (T it : vector) { + // TreeItem* vectorChild = new TreeItem(ptr, child); + // QList vectorData; + // //doesn't work yet since it is of type T and that requires the parser again (rekusiver aufruf) + // //T value = it; + // // + // //auto parse = [&](auto item) { + // // visit_struct::for_each(item, parser_); + // //}; + // // + // //if(ptr && ptr.get() != nullptr) { + // // if(std::dynamic_pointer_cast(ptr)) + // // OpenInfraPlatform::IfcAlignment1x1::castToVisitableAndCall(std::dynamic_pointer_cast(ptr), parse); + // //} + // //vectorData << QVariant(i++) << QVariant(value) << QVariant(typeid(value).name()); + // vectorData << QVariant(i++) << QVariant("") << QVariant(""); + // vectorChild->setItemData(vectorData); + // child->appendChild(vectorChild); + // } + // } + + // //Function operator() which covers everything that is not an int, float/double, string, boolean, pointer or vector. + // //This function also takes enums, since alot of classes derived from IfcAlignment1x1Type have a corresponding enum class, which is derived from it. + // //template typename std::enable_if::value && !std::is_same::value, void>::type + // // operator()(const char* name, T t) + // //{ + // // + // //} + + // TreeItem* thisPtr = nullptr; + + //} parser_; + + }; + } +} + +#endif //IFCTREEITEM_H + +namespace oip +{ + using OpenInfraPlatform::UserInterface::IfcTreeItem; +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.cpp b/UserInterface/Dialogues/IfcTreeModel.cpp new file mode 100644 index 000000000..13d0a7b2a --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeModel.cpp @@ -0,0 +1,157 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "IfcTreeModel.h" + +#include +#include +#include + +#include +#include + + +//template T cast(S s) +//{ +// return dynamic_cast(s); +//} +// +//OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) +// : QAbstractItemModel(parent) +//{ +// QList rootData; +// rootData << "Title" << "Summary"; +// rootItem = new IfcTreeItem(rootData); +// +// for (auto entity : expressModel->entities) { +// IfcTreeItem* child = new IfcTreeItem(entity.second.get(), rootItem); +// QList itemData; +// itemData << QVariant(entity.first);// << QVariant(entity.second->classname()) << QVariant(""); +// child->setItemData(itemData); +// child->createChildren(); +// rootItem->appendChild(child); +// } +//} + +OpenInfraPlatform::UserInterface::IfcTreeModel::IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent) + : QAbstractItemModel(parent) +{ + QList rootData; + rootData << "Title" << "Summary"; + rootItem = new IfcTreeItem(rootData); + setupModelData(expressModel, rootItem); +} + +OpenInfraPlatform::UserInterface::IfcTreeModel::~IfcTreeModel() +{ + delete rootItem; +} + +int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +{ + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount(); +} + +//int OpenInfraPlatform::UserInterface::IfcTreeModel::columnCount(const QModelIndex &parent) const +//{ +// if (!parent.isValid()) +// return 1; //correct for testing? +// else +// return 3; +//} + + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + if (role != Qt::DisplayRole) + return QVariant(); + + IfcTreeItem *item = static_cast(index.internalPointer()); + + return item->data(index.column()); +} + +QVariant OpenInfraPlatform::UserInterface::IfcTreeModel::headerData(int section, Qt::Orientation orientation, + int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + return rootItem->data(section); + + return QVariant(); +} + +QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::index(int row, int column, const QModelIndex &parent) const +{ + if (!hasIndex(row, column, parent)) + return QModelIndex(); + + IfcTreeItem *parentItem; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + IfcTreeItem *childItem = parentItem->child(row); + if (childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex OpenInfraPlatform::UserInterface::IfcTreeModel::parent(const QModelIndex &index) const +{ + if (!index.isValid()) + return QModelIndex(); + + IfcTreeItem *childItem = static_cast(index.internalPointer()); + IfcTreeItem *parentItem = childItem->parentItem(); + + if (parentItem == rootItem) + return QModelIndex(); + + return createIndex(parentItem->row(), 0, parentItem); +} + +int OpenInfraPlatform::UserInterface::IfcTreeModel::rowCount(const QModelIndex &parent) const +{ + IfcTreeItem *parentItem; + if (parent.column() > 0) + return 0; + + if (!parent.isValid()) + parentItem = rootItem; + else + parentItem = static_cast(parent.internalPointer()); + + return parentItem->childCount(); +} + +void OpenInfraPlatform::UserInterface::IfcTreeModel::setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent) +{ + //ignoring tree structure for now + for (auto entity : expressModel->entities) + { + parent->appendChild(new IfcTreeItem(entity.second.get(), parent)); + } +} \ No newline at end of file diff --git a/UserInterface/Dialogues/IfcTreeModel.h b/UserInterface/Dialogues/IfcTreeModel.h new file mode 100644 index 000000000..8f1c72553 --- /dev/null +++ b/UserInterface/Dialogues/IfcTreeModel.h @@ -0,0 +1,60 @@ +/* + Copyright (c) 2021 Technical University of Munich + Chair of Computational Modeling and Simulation. + + TUM Open Infra Platform is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License Version 3 + as published by the Free Software Foundation. + + TUM Open Infra Platform is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef IFCTREEMODEL_H +#define IFCTREEMODEL_H + +#include "IfcTreeItem.h" +#include "EXPRESS/EXPRESSEntity.h" + +#include +#include +#include + + +namespace OpenInfraPlatform +{ + namespace UserInterface + { + + class IfcTreeModel : public QAbstractItemModel + { + Q_OBJECT; + + public: + explicit IfcTreeModel(OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, QObject *parent = nullptr); + ~IfcTreeModel(); + + //override from QAbstractItemModel + QVariant data(const QModelIndex &index, int role) const override; + QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const override; + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &index) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + private: + void setupModelData(const OpenInfraPlatform::EarlyBinding::EXPRESSModel *expressModel, IfcTreeItem *parent); + + IfcTreeItem *rootItem; + }; + } +} + +#endif //TREEMODEL_H \ No newline at end of file diff --git a/UserInterface/Forms/IfcTreeDialog.ui b/UserInterface/Forms/IfcTreeDialog.ui new file mode 100644 index 000000000..e76f52269 --- /dev/null +++ b/UserInterface/Forms/IfcTreeDialog.ui @@ -0,0 +1,32 @@ + + + IfcTreeDialog + + + + 0 + 0 + 450 + 600 + + + + Ifc Tree Viewer + + + + + + + + + + Close + + + + + + + + \ No newline at end of file diff --git a/UserInterface/MainWindow.cpp b/UserInterface/MainWindow.cpp index 258b5a5ed..82949e62f 100644 --- a/UserInterface/MainWindow.cpp +++ b/UserInterface/MainWindow.cpp @@ -506,6 +506,7 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() // - min, mid, max : QVector3D // 4. - GeoRef : georeferencing metadata // - key - val + // 5. - treeviewer : button (to open) // 1. filename auto itemModel = new QTreeWidgetItem(modelsTreeWidget_); @@ -552,6 +553,18 @@ void OpenInfraPlatform::UserInterface::MainWindow::updateModelsUI() // do nothing } + // 5. treeviewer + if (std::dynamic_pointer_cast(model)) + { + auto itemIfcTree = new QTreeWidgetItem(itemModel); + itemIfcTree->setText(0, "IfcTree"); + + QPushButton *openIfcTreeButton = new QPushButton(); + openIfcTreeButton->setText("Open Ifc Tree Dialog"); + QObject::connect(openIfcTreeButton, SIGNAL(clicked()), this, SLOT(on_actionShow_Ifc_Tree_triggered())); + modelsTreeWidget_->setItemWidget(itemIfcTree, 1, openIfcTreeButton); + } + // expanded per default itemModel->setExpanded(true); } @@ -1810,6 +1823,14 @@ void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_License_and_Cop licenseAndCopyrightInformationDialog_->show(); } +void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Ifc_Tree_triggered() { + if (ifcTreeDialog_ == nullptr) { + ifcTreeDialog_ = new IfcTreeDialog(this); + } + + ifcTreeDialog_->show(); +} + void OpenInfraPlatform::UserInterface::MainWindow::on_actionShow_Log_Folder_triggered() { // TODO: Find a way to do this with pure Qt or move it at least to an own // function that can be reused by on_actionShow_Log_File_triggered diff --git a/UserInterface/MainWindow.h b/UserInterface/MainWindow.h index c9528ed0c..f368180b5 100644 --- a/UserInterface/MainWindow.h +++ b/UserInterface/MainWindow.h @@ -22,6 +22,7 @@ #include "../UserInterface/ViewPanel/View.h" #include "../UserInterface/Dialogues/LicenseAndCopyrightInformationDialog.h" +#include "../UserInterface/Dialogues/IfcTreeDialog.h" #include "DataManagement/General/Data.h" #include "../UserInterface/Dialogues/PreferencesDialog.h" #include "../Core/src/DataManagement/General/ProgressCallback.h" @@ -141,6 +142,7 @@ namespace OpenInfraPlatform //void on_actionIFC_Alignment_1_1_Export_triggered(); void on_actionShow_License_and_Copyright_Information_triggered(); + void on_actionShow_Ifc_Tree_triggered(); void on_actionShow_Log_Folder_triggered(); @@ -366,6 +368,7 @@ namespace OpenInfraPlatform PreferencesDialog* preferencesDialog_ = nullptr; QProgressDialog* progressDialog_ = nullptr; LicenseAndCopyrightInformationDialog* licenseAndCopyrightInformationDialog_ = nullptr; + IfcTreeDialog* ifcTreeDialog_ = nullptr; QProgressBar* progressBar_; diff --git a/testdata/default.txt b/testdata/default.txt new file mode 100644 index 000000000..8c92181d4 --- /dev/null +++ b/testdata/default.txt @@ -0,0 +1,3 @@ +Getting Started How to familiarize yourself with Qt Designer + Launching Designer Running the Qt Designer application + The User Interface How to interact with Qt Designer \ No newline at end of file