Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree viewer #429

Draft
wants to merge 21 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6b789bd
Add Button to UI that will open the Ifc Tree once it is implemented
jschlenger Apr 7, 2021
4fab59d
Add TreeDialog to UI
jschlenger Apr 8, 2021
773bafe
Adding first part of the tree model and tree item (not working yet)
jschlenger Apr 15, 2021
49fe485
Small changes maily to treeModel and treeItem
jschlenger Apr 20, 2021
4383357
Adding a ExpressModel to the ifcModel in order to be able to access i…
jschlenger Apr 20, 2021
02418af
Add IfcTreeItem.cpp + some minor changes
jschlenger Apr 21, 2021
6de63e9
Small improvements
jschlenger Apr 23, 2021
b54c255
Changes to the tree model
jschlenger May 21, 2021
bc8c767
Small changes to tree items (not working yet!)
jschlenger May 21, 2021
a1f2e4a
Change everything from shared pointers to pointers (not working yet!)
jschlenger May 21, 2021
6226824
minor changes (still not working)
jschlenger May 28, 2021
79b3c90
Just some testing
jschlenger Jul 1, 2021
e51816b
Merge branch 'development' of https://github.com/jschlenger/Open-Infr…
jschlenger Jul 1, 2021
9df4951
Adapt to the newest version of ifcImporter.h
jschlenger Jul 1, 2021
b112e1f
Trying to exactly replicate the Qt 5.12 simple tree model example (no…
jschlenger Jul 1, 2021
83a9654
All it takes to get it to work
jschlenger Jul 1, 2021
15d3a2f
Letting the treeviewer show the list of all IfcEntities within the lo…
jschlenger Jul 1, 2021
5a28961
Clean up IfcTreeItem
jschlenger Jul 1, 2021
a7d19f5
Clean up IfcTreeDialog
jschlenger Jul 1, 2021
007fa6f
Clean up IfcTreeModel
jschlenger Jul 1, 2021
42bdceb
Some code from old tree viewer versions
jschlenger Jul 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Core/src/IfcGeometryConverter/IfcGeometryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "IfcGeometryModel.h"
#include "Exception\UnhandledException.h"


void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::reset()
{
for( auto geom : geometries_ )
Expand All @@ -37,6 +38,11 @@ void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::addGeometry(std::s
geometryMutex_.unlock();
}

void OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::setExpressModel(std::shared_ptr<OpenInfraPlatform::EarlyBinding::EXPRESSModel> expressModel)
{
expressModel_ = expressModel;
}

// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Interface IModel implementation
bool OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel::isEmpty() const
Expand Down
10 changes: 8 additions & 2 deletions Core/src/IfcGeometryConverter/IfcGeometryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <IModel.h>

#include "namespace.h"
#include "EXPRESS/EXPRESSModel.h"

typedef buw::VertexPosition3Color3Normal3 VertexLayout;

Expand Down Expand Up @@ -80,15 +81,20 @@ namespace OpenInfraPlatform
std::vector<std::shared_ptr<GeometryDescription>> geometries_;
std::mutex geometryMutex_;

std::string filename_;
oip::GeorefMetadata georefMeta_;
std::string filename_;
oip::GeorefMetadata georefMeta_;

std::shared_ptr<oip::EXPRESSModel> expressModel_;

public:
void reset();

void addGeometry(std::shared_ptr<GeometryDescription> geometry);
std::vector<std::shared_ptr<GeometryDescription>> const &geometries() const { return geometries_; }

void setExpressModel(std::shared_ptr<OpenInfraPlatform::EarlyBinding::EXPRESSModel> expressModel);
std::shared_ptr<OpenInfraPlatform::EarlyBinding::EXPRESSModel> const getExpressModel() const { return expressModel_; }

// ---------------------------------------------------------------------------------------------------------------------------------------------------
// Interface IModel implementation
// ---------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Core/src/IfcGeometryConverter/IfcImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
67 changes: 67 additions & 0 deletions UserInterface/Dialogues/IfcTreeDialog.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#include "IfcTreeDialog.h"
#include "IfcTreeModel.h"
#include "ui_IfcTreeDialog.h"
#include "DataManagement/General/Data.h"
#include "Exception\UnhandledException.h"
#include <QFileSystemModel>
#include <QTreeWidgetItem>

#include <filesystem>
#include <string>
#include <iostream>
#include <direct.h>

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<oip::IfcModel>(model))
{
auto ifcModel = std::static_pointer_cast<OpenInfraPlatform::Core::IfcGeometryConverter::IfcModel>(model);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dynamic pointer cast as well

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();
}
55 changes: 55 additions & 0 deletions UserInterface/Dialogues/IfcTreeDialog.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "ui_IfcTreeDialog.h"
#include "ViewPanel/View.h"

#include <QDialog>
#include <iostream>

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;
}
181 changes: 181 additions & 0 deletions UserInterface/Dialogues/IfcTreeItem.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#include "IfcTreeItem.h"
#include <QStringList>
#include <type_traits>
#include <cstdlib>
#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<OpenInfraPlatform::EarlyBinding::EXPRESSObject> &data, IfcTreeItem * parent)
// : m_managedData(data), m_parentItem(parent), parser_()
//{
// parser_.thisPtr = this;
//}

OpenInfraPlatform::UserInterface::IfcTreeItem::IfcTreeItem(const QList<QVariant> &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()<OpenInfraPlatform::EarlyBinding::EXPRESSEntity>(*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<IfcTreeItem*>(this));

return 0;
}

QString OpenInfraPlatform::UserInterface::IfcTreeItem::getIfcClassName() const
{
std::string ifcClassName = data_->classname();
return QString::fromStdString(ifcClassName);
}

//struct OpenInfraPlatform::UserInterface::IfcTreeItem::getAttributeDescription
//{
// template <class T> typename std::enable_if<visit_struct::traits::is_visitable<T>::value && std::is_base_of<OpenInfraPlatform::EarlyBinding::EXPRESSEntity, T>::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 <class T> typename std::enable_if<!std::is_base_of<OpenInfraPlatform::EarlyBinding::EXPRESSEntity, T>::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<const char*> names_;
// std::vector<const char*> typename_;
// std::vector <QVariant> 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<OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Object, decltype(value)>::value) {
// // child = new TreeItem(value, this);
// //}
// //else {
// // child = new TreeItem(OpenInfraPlatform::IfcAlignment1x1::IfcAlignment1x1Object(), this);
// //}
// std::shared_ptr<OpenInfraPlatform::EarlyBinding::EXPRESSObject> ptr = nullptr;
// child = new IfcTreeItem(ptr, this);
// QList<QVariant> 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<OpenInfraPlatform::EarlyBinding::EXPRESSEntity>(m_managedData)) {
// //OpenInfraPlatform::IfcAlignment1x1::castToVisitableAndCall<decltype(parse), void>(std::dynamic_pointer_cast<OpenInfraPlatform::EarlyBinding::EXPRESSEntity>(m_managedData), parse);
// }
// }
//}

//void OpenInfraPlatform::UserInterface::TreeItem::setItemData(QList<QVariant> itemData)
//{
// itemData_ = itemData;
//}
Loading