2026-04-11 16:30:10 +10:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell 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 *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "MainWindow.h"
|
2026-04-11 20:05:50 +10:00
|
|
|
#include "AppSettings.h"
|
2026-04-27 18:31:59 +10:00
|
|
|
#include "Federation.h"
|
2026-05-02 08:02:59 +10:00
|
|
|
#include "FederationSettingsDialog.h"
|
2026-05-02 08:06:25 +10:00
|
|
|
#include "ModelTransformationDialog.h"
|
2026-04-11 16:30:10 +10:00
|
|
|
#include "SettingsWindow.h"
|
2026-04-13 18:31:43 +10:00
|
|
|
#include "LodBuilder.h"
|
2026-04-12 09:09:32 +10:00
|
|
|
#include "SidecarCache.h"
|
2026-04-11 16:30:10 +10:00
|
|
|
|
|
|
|
|
#include <QApplication>
|
2026-04-27 18:31:59 +10:00
|
|
|
#include <QCloseEvent>
|
2026-04-11 16:30:10 +10:00
|
|
|
#include <QMenuBar>
|
|
|
|
|
#include <QFileDialog>
|
2026-04-11 20:49:39 +10:00
|
|
|
#include <QFileInfo>
|
2026-04-11 16:30:10 +10:00
|
|
|
#include <QMessageBox>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QDockWidget>
|
2026-05-04 07:14:52 +10:00
|
|
|
#include <QListView>
|
|
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QAbstractItemView>
|
2026-04-21 18:05:19 +10:00
|
|
|
#include <QDebug>
|
2026-04-11 16:30:10 +10:00
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
{
|
|
|
|
|
setupUi();
|
|
|
|
|
setupMenus();
|
|
|
|
|
|
2026-04-27 18:31:59 +10:00
|
|
|
federation_ = new Federation(this);
|
2026-05-02 07:58:26 +10:00
|
|
|
|
|
|
|
|
// Federation -> viewport: granular signals so we recompose only what's
|
|
|
|
|
// affected. Each handler reads the current federation state, composes
|
|
|
|
|
// the matrix, and pushes to the viewport.
|
|
|
|
|
connect(federation_, &Federation::federatedFalseOriginChanged,
|
|
|
|
|
this, &MainWindow::applyFederatedFalseOriginToViewport);
|
|
|
|
|
connect(federation_, &Federation::configChanged, this, [this]() {
|
|
|
|
|
// Federation unit changed — both stage 3 (uses fed unit) and every
|
|
|
|
|
// model's stage 4 (b/pivot are in fed units) need recomposing.
|
|
|
|
|
applyFederatedFalseOriginToViewport();
|
|
|
|
|
for (const auto& kv : fed_id_to_model_id_) {
|
|
|
|
|
applyModelTransformationToViewport(kv.second);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
connect(federation_, &Federation::modelTransformationChanged,
|
|
|
|
|
this, [this](const QString& fed_id) {
|
|
|
|
|
auto it = fed_id_to_model_id_.find(fed_id);
|
|
|
|
|
if (it != fed_id_to_model_id_.end()) {
|
|
|
|
|
applyModelTransformationToViewport(it->second);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 18:31:59 +10:00
|
|
|
connect(federation_, &Federation::dirtyChanged, this, [this](bool dirty) {
|
|
|
|
|
setWindowModified(dirty);
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
loader_ = new SceneLoader(viewport_, this);
|
|
|
|
|
connect(loader_, &SceneLoader::loadStarted,
|
|
|
|
|
this, &MainWindow::onLoadStarted);
|
|
|
|
|
connect(loader_, &SceneLoader::progressChanged,
|
|
|
|
|
this, &MainWindow::onLoadProgressChanged);
|
|
|
|
|
connect(loader_, &SceneLoader::sidecarElementsReady,
|
|
|
|
|
this, &MainWindow::onSidecarElementsReady);
|
|
|
|
|
connect(loader_, &SceneLoader::loadedFromSidecar,
|
|
|
|
|
this, &MainWindow::onLoadedFromSidecar);
|
2026-04-24 13:45:04 +10:00
|
|
|
connect(loader_, &SceneLoader::dataSourceReady,
|
|
|
|
|
this, &MainWindow::onDataSourceReady);
|
2026-04-21 18:05:19 +10:00
|
|
|
connect(loader_, &SceneLoader::streamedElementsReady,
|
|
|
|
|
this, &MainWindow::onStreamedElementsReady);
|
|
|
|
|
connect(loader_, &SceneLoader::loadedFromStream,
|
|
|
|
|
this, &MainWindow::onLoadedFromStream);
|
2026-04-22 11:27:53 +10:00
|
|
|
connect(loader_, &SceneLoader::loadCancelled,
|
|
|
|
|
this, &MainWindow::onLoadCancelled);
|
2026-04-21 18:05:19 +10:00
|
|
|
connect(loader_, &SceneLoader::loadError,
|
|
|
|
|
this, &MainWindow::onLoadError);
|
|
|
|
|
connect(loader_, &SceneLoader::allLoadsFinished,
|
|
|
|
|
this, &MainWindow::onAllLoadsFinished);
|
|
|
|
|
|
|
|
|
|
connect(viewport_, &ViewportWindow::frameStatsUpdated, this,
|
|
|
|
|
[this](const ViewportWindow::FrameStats& s) {
|
2026-04-11 20:05:50 +10:00
|
|
|
if (!stats_label_->isVisible()) return;
|
|
|
|
|
stats_label_->setText(
|
2026-04-12 21:10:27 +10:00
|
|
|
QString("%1 fps | %2 ms | %3/%4 obj | %5/%6 tri | %7 gl_draws (%8 sub)")
|
2026-04-11 20:05:50 +10:00
|
|
|
.arg(s.fps, 0, 'f', 1)
|
|
|
|
|
.arg(s.frame_time_ms, 0, 'f', 1)
|
|
|
|
|
.arg(s.visible_objects)
|
|
|
|
|
.arg(s.total_objects)
|
|
|
|
|
.arg(s.visible_triangles)
|
2026-04-12 21:10:27 +10:00
|
|
|
.arg(s.total_triangles)
|
|
|
|
|
.arg(s.gl_draw_calls)
|
|
|
|
|
.arg(s.indirect_sub_draws));
|
2026-04-11 20:05:50 +10:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&AppSettings::instance(), &AppSettings::showStatsChanged, this, [this](bool show) {
|
|
|
|
|
stats_label_->setVisible(show);
|
|
|
|
|
if (!show) stats_label_->clear();
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-02 07:45:40 +10:00
|
|
|
// Toggling the CoordinateOperation setting walks every loaded model
|
|
|
|
|
// and pushes either its georef matrix or identity to the viewport.
|
|
|
|
|
connect(&AppSettings::instance(),
|
|
|
|
|
&AppSettings::applyCoordinateOperationChanged,
|
|
|
|
|
this, [this](bool /*enabled*/) {
|
|
|
|
|
for (const auto& kv : fed_id_to_model_id_) {
|
|
|
|
|
applyCoordinateOperationToViewport(kv.second);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-27 18:31:59 +10:00
|
|
|
updateWindowTitle();
|
2026-04-11 16:30:10 +10:00
|
|
|
resize(1400, 900);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
MainWindow::~MainWindow() = default;
|
2026-04-11 16:30:10 +10:00
|
|
|
|
|
|
|
|
void MainWindow::setupUi() {
|
|
|
|
|
viewport_ = new ViewportWindow();
|
|
|
|
|
viewport_container_ = QWidget::createWindowContainer(viewport_, this);
|
|
|
|
|
viewport_container_->setMinimumSize(400, 300);
|
|
|
|
|
viewport_container_->setFocusPolicy(Qt::StrongFocus);
|
|
|
|
|
setCentralWidget(viewport_container_);
|
|
|
|
|
|
|
|
|
|
connect(viewport_, &ViewportWindow::objectPicked, this, &MainWindow::onObjectPicked);
|
|
|
|
|
|
|
|
|
|
auto* tree_dock = new QDockWidget("Elements", this);
|
|
|
|
|
tree_dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
|
|
element_tree_ = new QTreeWidget();
|
|
|
|
|
element_tree_->setHeaderLabels({"Name", "Type", "GUID"});
|
|
|
|
|
element_tree_->setColumnWidth(0, 200);
|
|
|
|
|
element_tree_->setColumnWidth(1, 120);
|
|
|
|
|
element_tree_->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
connect(element_tree_, &QTreeWidget::itemSelectionChanged, this, &MainWindow::onTreeSelectionChanged);
|
|
|
|
|
tree_dock->setWidget(element_tree_);
|
|
|
|
|
addDockWidget(Qt::LeftDockWidgetArea, tree_dock);
|
|
|
|
|
|
|
|
|
|
auto* prop_dock = new QDockWidget("Properties", this);
|
|
|
|
|
prop_dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
|
|
|
|
property_table_ = new QTableWidget();
|
|
|
|
|
property_table_->setColumnCount(2);
|
|
|
|
|
property_table_->setHorizontalHeaderLabels({"Property", "Value"});
|
|
|
|
|
property_table_->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
|
property_table_->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
property_table_->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
prop_dock->setWidget(property_table_);
|
|
|
|
|
addDockWidget(Qt::RightDockWidgetArea, prop_dock);
|
|
|
|
|
|
|
|
|
|
progress_bar_ = new QProgressBar();
|
|
|
|
|
progress_bar_->setMaximumWidth(200);
|
|
|
|
|
progress_bar_->setVisible(false);
|
|
|
|
|
status_label_ = new QLabel("Ready");
|
2026-04-11 20:05:50 +10:00
|
|
|
stats_label_ = new QLabel();
|
|
|
|
|
stats_label_->setVisible(AppSettings::instance().showStats());
|
2026-04-11 16:30:10 +10:00
|
|
|
statusBar()->addWidget(status_label_, 1);
|
2026-04-11 20:05:50 +10:00
|
|
|
statusBar()->addPermanentWidget(stats_label_);
|
2026-04-11 16:30:10 +10:00
|
|
|
statusBar()->addPermanentWidget(progress_bar_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::setupMenus() {
|
|
|
|
|
auto* file_menu = menuBar()->addMenu("&File");
|
2026-04-27 18:31:59 +10:00
|
|
|
file_menu->addAction("&New Federation",
|
|
|
|
|
this, &MainWindow::onFederationNew,
|
|
|
|
|
QKeySequence::New);
|
|
|
|
|
file_menu->addAction("&Open Federation...",
|
|
|
|
|
this, &MainWindow::onFederationOpen,
|
|
|
|
|
QKeySequence::Open);
|
|
|
|
|
file_menu->addSeparator();
|
|
|
|
|
file_menu->addAction("&Add Files...",
|
|
|
|
|
this, &MainWindow::onFileOpen,
|
|
|
|
|
QKeySequence("Ctrl+Shift+O"));
|
2026-04-22 16:22:48 +10:00
|
|
|
file_menu->addAction("Add &Database...", this, &MainWindow::onDatabaseOpen);
|
2026-04-27 18:31:59 +10:00
|
|
|
file_menu->addSeparator();
|
|
|
|
|
file_menu->addAction("&Save Federation",
|
|
|
|
|
this, &MainWindow::onFederationSave,
|
|
|
|
|
QKeySequence::Save);
|
|
|
|
|
file_menu->addAction("Save Federation &As...",
|
|
|
|
|
this, &MainWindow::onFederationSaveAs,
|
|
|
|
|
QKeySequence::SaveAs);
|
2026-05-02 08:02:59 +10:00
|
|
|
file_menu->addAction("Federation Se&ttings...",
|
|
|
|
|
this, &MainWindow::onFederationSettings);
|
2026-05-02 08:06:25 +10:00
|
|
|
file_menu->addAction("&Model Transformations...",
|
|
|
|
|
this, &MainWindow::onModelTransformations);
|
2026-04-27 18:31:59 +10:00
|
|
|
file_menu->addSeparator();
|
2026-04-11 16:30:10 +10:00
|
|
|
file_menu->addAction("&Settings...", this, &MainWindow::onFileSettings);
|
|
|
|
|
file_menu->addSeparator();
|
|
|
|
|
file_menu->addAction("&Quit", QKeySequence::Quit, qApp, &QApplication::quit);
|
2026-04-27 18:31:59 +10:00
|
|
|
|
|
|
|
|
auto* view_menu = menuBar()->addMenu("&View");
|
2026-05-02 19:01:50 +10:00
|
|
|
// F frames the current selection. The viewport already binds F in its
|
|
|
|
|
// own keyPressEvent for the case where it has focus; this duplicate at
|
|
|
|
|
// window level is so the shortcut still fires when the tree, property
|
|
|
|
|
// table, or any other child widget has keyboard focus.
|
|
|
|
|
view_menu->addAction("&Frame Selected", this, [this]() {
|
|
|
|
|
viewport_->focusOnSelectedObject();
|
|
|
|
|
}, QKeySequence(Qt::Key_F));
|
|
|
|
|
view_menu->addAction("Print Selected &Coords", this, [this]() {
|
|
|
|
|
viewport_->printSelectedObjectCoords();
|
|
|
|
|
}, QKeySequence("Ctrl+Shift+P"));
|
|
|
|
|
view_menu->addSeparator();
|
2026-04-27 18:31:59 +10:00
|
|
|
view_menu->addAction("Set &Home View", this, &MainWindow::onSetHomeView);
|
|
|
|
|
view_menu->addAction("&Go to Home View", this, &MainWindow::onGoHomeView);
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onFileOpen() {
|
2026-04-11 20:49:39 +10:00
|
|
|
QStringList paths = QFileDialog::getOpenFileNames(
|
|
|
|
|
this, "Add IFC Files", QString(),
|
2026-04-24 13:45:04 +10:00
|
|
|
"IFC Files (*.ifc *.ifcxml *.ifczip);;"
|
|
|
|
|
"IFC Viewer Cache (*.ifcview);;"
|
|
|
|
|
"All Files (*)");
|
2026-04-11 20:49:39 +10:00
|
|
|
if (!paths.isEmpty()) {
|
|
|
|
|
addFiles(paths);
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 16:22:48 +10:00
|
|
|
void MainWindow::onDatabaseOpen() {
|
2026-05-04 07:14:52 +10:00
|
|
|
QFileDialog dialog(this, "Add IFC Databases");
|
|
|
|
|
dialog.setFileMode(QFileDialog::Directory);
|
|
|
|
|
dialog.setOption(QFileDialog::ShowDirsOnly, true);
|
|
|
|
|
dialog.setOption(QFileDialog::DontResolveSymlinks, true);
|
|
|
|
|
// Native dialogs only support single-directory selection — use Qt's
|
|
|
|
|
// dialog so we can flip the inner views into ExtendedSelection.
|
|
|
|
|
dialog.setOption(QFileDialog::DontUseNativeDialog, true);
|
|
|
|
|
if (auto* list = dialog.findChild<QListView*>("listView")) {
|
|
|
|
|
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
}
|
|
|
|
|
if (auto* tree = dialog.findChild<QTreeView*>()) {
|
|
|
|
|
tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
|
}
|
|
|
|
|
if (dialog.exec() != QDialog::Accepted) return;
|
|
|
|
|
QStringList paths = dialog.selectedFiles();
|
|
|
|
|
if (!paths.isEmpty()) {
|
|
|
|
|
addFiles(paths);
|
2026-04-22 16:22:48 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 16:30:10 +10:00
|
|
|
void MainWindow::onFileSettings() {
|
|
|
|
|
if (settings_ == nullptr) {
|
|
|
|
|
settings_ = new SettingsWindow(this);
|
|
|
|
|
}
|
|
|
|
|
settings_->open();
|
|
|
|
|
settings_->activateWindow();
|
|
|
|
|
settings_->raise();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 08:02:59 +10:00
|
|
|
void MainWindow::onFederationSettings() {
|
|
|
|
|
if (federation_settings_ == nullptr) {
|
|
|
|
|
federation_settings_ = new FederationSettingsDialog(federation_, this);
|
|
|
|
|
}
|
|
|
|
|
federation_settings_->open();
|
|
|
|
|
federation_settings_->activateWindow();
|
|
|
|
|
federation_settings_->raise();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 08:06:25 +10:00
|
|
|
void MainWindow::onModelTransformations() {
|
|
|
|
|
if (model_transformations_ == nullptr) {
|
|
|
|
|
model_transformations_ = new ModelTransformationDialog(federation_, this);
|
|
|
|
|
}
|
|
|
|
|
model_transformations_->open();
|
|
|
|
|
model_transformations_->activateWindow();
|
|
|
|
|
model_transformations_->raise();
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 20:49:39 +10:00
|
|
|
void MainWindow::addFiles(const QStringList& paths) {
|
2026-04-27 18:31:59 +10:00
|
|
|
QStringList accepted_paths;
|
|
|
|
|
QStringList accepted_fed_ids;
|
|
|
|
|
for (const auto& p : paths) {
|
|
|
|
|
QString fed_id = federation_->addModel(p);
|
|
|
|
|
if (fed_id.isEmpty()) continue; // .ifcfed or empty path — silently skipped
|
|
|
|
|
accepted_paths << p;
|
|
|
|
|
accepted_fed_ids << fed_id;
|
|
|
|
|
}
|
|
|
|
|
loadModelsFromPaths(accepted_paths, accepted_fed_ids);
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::loadModelsFromPaths(const QStringList& paths,
|
|
|
|
|
const QStringList& fed_ids) {
|
|
|
|
|
if (paths.isEmpty()) return;
|
2026-04-21 18:05:19 +10:00
|
|
|
auto ids = loader_->addFiles(paths);
|
|
|
|
|
for (int i = 0; i < paths.size() && i < static_cast<int>(ids.size()); ++i) {
|
2026-04-27 18:31:59 +10:00
|
|
|
uint32_t mid = ids[i];
|
|
|
|
|
const QString& fed_id = fed_ids[i];
|
|
|
|
|
fed_id_to_model_id_[fed_id] = mid;
|
|
|
|
|
model_id_to_fed_id_[mid] = fed_id;
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
QString display = QFileInfo(paths[i]).fileName();
|
2026-04-11 20:49:39 +10:00
|
|
|
auto* root = new QTreeWidgetItem(element_tree_);
|
2026-04-21 18:05:19 +10:00
|
|
|
root->setText(0, display);
|
2026-04-11 20:49:39 +10:00
|
|
|
root->setText(1, "IFC Model");
|
2026-04-21 18:05:19 +10:00
|
|
|
root->setData(0, Qt::UserRole, static_cast<uint32_t>(0));
|
2026-04-27 18:31:59 +10:00
|
|
|
tree_roots_[mid] = root;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MainWindow::openFederation(const QString& path) {
|
|
|
|
|
if (!confirmDiscardIfDirty()) return false;
|
|
|
|
|
|
|
|
|
|
QStringList warnings;
|
|
|
|
|
QString err;
|
|
|
|
|
if (!federation_->load(path, &warnings, &err)) {
|
|
|
|
|
QMessageBox::warning(this, "Open Federation",
|
|
|
|
|
QString("Could not open federation:\n%1").arg(err));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearScene();
|
|
|
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
|
QStringList fed_ids;
|
|
|
|
|
QStringList missing;
|
|
|
|
|
for (const auto& m : federation_->models()) {
|
|
|
|
|
if (m.source_kind != "local") continue; // already warned by load()
|
|
|
|
|
if (!QFileInfo::exists(m.source_path)) {
|
|
|
|
|
missing << m.source_path;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
paths << m.source_path;
|
|
|
|
|
fed_ids << m.id;
|
|
|
|
|
}
|
|
|
|
|
loadModelsFromPaths(paths, fed_ids);
|
|
|
|
|
|
|
|
|
|
for (const auto& msg : missing) {
|
|
|
|
|
warnings << QString("Source not found, kept in federation: %1").arg(msg);
|
2026-04-11 20:49:39 +10:00
|
|
|
}
|
2026-04-27 18:31:59 +10:00
|
|
|
if (!warnings.isEmpty()) {
|
|
|
|
|
QMessageBox::warning(this, "Open Federation",
|
|
|
|
|
"Federation opened with warnings:\n\n" + warnings.join("\n"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
federation_->markClean();
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
|
2026-05-02 07:58:26 +10:00
|
|
|
// Push the federation's loaded FederatedFalseOrigin to the viewport.
|
|
|
|
|
// Per-model ModelTransformations get pushed as each model finishes
|
|
|
|
|
// loading, via applyCoordinateOperationToViewport.
|
|
|
|
|
applyFederatedFalseOriginToViewport();
|
|
|
|
|
|
2026-04-27 18:31:59 +10:00
|
|
|
if (federation_->hasHomeView()) {
|
|
|
|
|
const auto& hv = federation_->homeView();
|
|
|
|
|
viewport_->setCamera(hv.target.x(), hv.target.y(), hv.target.z(),
|
|
|
|
|
hv.distance, hv.yaw, hv.pitch);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onFederationNew() {
|
|
|
|
|
if (!confirmDiscardIfDirty()) return;
|
|
|
|
|
clearScene();
|
|
|
|
|
federation_->clear();
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onFederationOpen() {
|
|
|
|
|
QString path = QFileDialog::getOpenFileName(
|
|
|
|
|
this, "Open Federation", QString(),
|
|
|
|
|
"IFC Federation (*.ifcfed);;All Files (*)");
|
|
|
|
|
if (path.isEmpty()) return;
|
|
|
|
|
openFederation(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MainWindow::onFederationSave() {
|
|
|
|
|
if (federation_->filePath().isEmpty()) return onFederationSaveAs();
|
|
|
|
|
QString err;
|
|
|
|
|
if (!federation_->save(federation_->filePath(), &err)) {
|
|
|
|
|
QMessageBox::warning(this, "Save Federation",
|
|
|
|
|
QString("Could not save federation:\n%1").arg(err));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MainWindow::onFederationSaveAs() {
|
|
|
|
|
QString suggested = federation_->filePath();
|
|
|
|
|
if (suggested.isEmpty()) suggested = "federation.ifcfed";
|
|
|
|
|
QString path = QFileDialog::getSaveFileName(
|
|
|
|
|
this, "Save Federation As", suggested,
|
|
|
|
|
"IFC Federation (*.ifcfed);;All Files (*)");
|
|
|
|
|
if (path.isEmpty()) return false;
|
|
|
|
|
if (!path.endsWith(".ifcfed", Qt::CaseInsensitive)) path += ".ifcfed";
|
|
|
|
|
|
|
|
|
|
QString err;
|
|
|
|
|
if (!federation_->save(path, &err)) {
|
|
|
|
|
QMessageBox::warning(this, "Save Federation",
|
|
|
|
|
QString("Could not save federation:\n%1").arg(err));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onSetHomeView() {
|
|
|
|
|
auto cs = viewport_->cameraState();
|
|
|
|
|
Federation::HomeView hv;
|
|
|
|
|
hv.target = cs.target;
|
|
|
|
|
hv.distance = cs.distance;
|
|
|
|
|
hv.yaw = cs.yaw;
|
|
|
|
|
hv.pitch = cs.pitch;
|
|
|
|
|
federation_->setHomeView(hv);
|
|
|
|
|
updateWindowTitle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onGoHomeView() {
|
|
|
|
|
if (!federation_->hasHomeView()) {
|
|
|
|
|
status_label_->setText("No home view set for this federation.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto& hv = federation_->homeView();
|
|
|
|
|
viewport_->setCamera(hv.target.x(), hv.target.y(), hv.target.z(),
|
|
|
|
|
hv.distance, hv.yaw, hv.pitch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::clearScene() {
|
|
|
|
|
while (!tree_roots_.empty()) {
|
|
|
|
|
uint32_t mid = tree_roots_.begin()->first;
|
|
|
|
|
viewport_->removeModel(mid);
|
|
|
|
|
removeModelUi(mid);
|
|
|
|
|
}
|
|
|
|
|
fed_id_to_model_id_.clear();
|
|
|
|
|
model_id_to_fed_id_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MainWindow::confirmDiscardIfDirty() {
|
|
|
|
|
if (!federation_->isDirty()) return true;
|
|
|
|
|
auto ret = QMessageBox::question(
|
|
|
|
|
this, "Unsaved Federation",
|
|
|
|
|
"The current federation has unsaved changes. Save before continuing?",
|
|
|
|
|
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
|
|
|
|
|
QMessageBox::Save);
|
|
|
|
|
if (ret == QMessageBox::Cancel) return false;
|
|
|
|
|
if (ret == QMessageBox::Save) return onFederationSave();
|
|
|
|
|
return true; // Discard
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::updateWindowTitle() {
|
|
|
|
|
QString fed_path = federation_->filePath();
|
|
|
|
|
if (fed_path.isEmpty() && federation_->models().empty()) {
|
|
|
|
|
setWindowTitle("IfcViewer");
|
|
|
|
|
} else if (fed_path.isEmpty()) {
|
|
|
|
|
setWindowTitle("untitled[*] — IfcViewer");
|
|
|
|
|
} else {
|
|
|
|
|
setWindowTitle(QFileInfo(fed_path).fileName() + "[*] — IfcViewer");
|
|
|
|
|
}
|
|
|
|
|
setWindowModified(federation_->isDirty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent* event) {
|
|
|
|
|
if (confirmDiscardIfDirty()) event->accept();
|
|
|
|
|
else event->ignore();
|
2026-04-11 20:49:39 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::onLoadStarted(uint32_t /*mid*/, QString display_name) {
|
|
|
|
|
progress_bar_->setValue(0);
|
|
|
|
|
progress_bar_->setVisible(true);
|
|
|
|
|
status_label_->setText("Loading: " + display_name);
|
2026-04-11 20:49:39 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::onLoadProgressChanged(int percent) {
|
|
|
|
|
progress_bar_->setValue(percent);
|
2026-04-12 09:09:32 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::appendElementToTree(uint32_t model_id,
|
|
|
|
|
uint32_t object_id,
|
|
|
|
|
int ifc_id,
|
|
|
|
|
int parent_ifc_id,
|
|
|
|
|
const std::string& guid,
|
|
|
|
|
const std::string& name,
|
|
|
|
|
const std::string& type) {
|
|
|
|
|
auto root_it = tree_roots_.find(model_id);
|
|
|
|
|
QTreeWidgetItem* parent_item = (root_it != tree_roots_.end()) ? root_it->second : nullptr;
|
|
|
|
|
|
|
|
|
|
auto parent_obj_it = scoped_ifc_id_to_object_id_.find(
|
|
|
|
|
scopedKey(model_id, parent_ifc_id));
|
|
|
|
|
if (parent_obj_it != scoped_ifc_id_to_object_id_.end()) {
|
|
|
|
|
auto tree_it = tree_items_.find(parent_obj_it->second);
|
|
|
|
|
if (tree_it != tree_items_.end()) {
|
|
|
|
|
parent_item = tree_it->second;
|
|
|
|
|
}
|
2026-04-12 20:10:20 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
QString display_name = QString::fromStdString(name);
|
|
|
|
|
if (display_name.isEmpty()) {
|
|
|
|
|
display_name = QString::fromStdString(type) + " #" + QString::number(ifc_id);
|
|
|
|
|
}
|
2026-04-12 20:10:20 +10:00
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
auto* item = new QTreeWidgetItem(parent_item);
|
|
|
|
|
item->setText(0, display_name);
|
|
|
|
|
item->setText(1, QString::fromStdString(type));
|
|
|
|
|
item->setText(2, QString::fromStdString(guid));
|
|
|
|
|
item->setData(0, Qt::UserRole, object_id);
|
2026-04-12 20:10:20 +10:00
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
tree_items_[object_id] = item;
|
2026-04-12 09:09:32 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::onSidecarElementsReady(uint32_t mid,
|
|
|
|
|
std::vector<PackedElementInfo> elements,
|
|
|
|
|
std::string string_table) {
|
2026-04-12 09:09:32 +10:00
|
|
|
auto str = [&](uint32_t offset, uint32_t length) -> std::string {
|
2026-04-21 18:05:19 +10:00
|
|
|
if (length == 0 || offset + length > string_table.size()) return {};
|
|
|
|
|
return string_table.substr(offset, length);
|
2026-04-12 09:09:32 +10:00
|
|
|
};
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
QElapsedTimer t;
|
|
|
|
|
t.start();
|
|
|
|
|
element_tree_->setUpdatesEnabled(false);
|
|
|
|
|
|
2026-04-12 09:09:32 +10:00
|
|
|
for (const auto& pe : elements) {
|
|
|
|
|
ElementInfo info;
|
|
|
|
|
info.object_id = pe.object_id;
|
2026-04-21 18:05:19 +10:00
|
|
|
info.model_id = pe.model_id;
|
|
|
|
|
info.ifc_id = pe.ifc_id;
|
2026-04-12 09:09:32 +10:00
|
|
|
info.parent_id = pe.parent_id;
|
|
|
|
|
info.guid = str(pe.guid_offset, pe.guid_length);
|
|
|
|
|
info.name = str(pe.name_offset, pe.name_length);
|
|
|
|
|
info.type = str(pe.type_offset, pe.type_length);
|
|
|
|
|
|
|
|
|
|
element_map_[info.object_id] = info;
|
|
|
|
|
scoped_ifc_id_to_object_id_[scopedKey(info.model_id, info.ifc_id)] = info.object_id;
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
appendElementToTree(info.model_id, info.object_id, info.ifc_id,
|
|
|
|
|
info.parent_id, info.guid, info.name, info.type);
|
2026-04-12 09:09:32 +10:00
|
|
|
}
|
2026-04-11 16:30:10 +10:00
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
element_tree_->setUpdatesEnabled(true);
|
|
|
|
|
qDebug(" Tree build: %lld ms (%zu elements)", t.elapsed(), elements.size());
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 13:45:04 +10:00
|
|
|
void MainWindow::onDataSourceReady(uint32_t mid) {
|
2026-05-02 07:45:40 +10:00
|
|
|
// The IFC file is now available — push the model's CoordinateOperation
|
|
|
|
|
// (or identity) to the viewport. Sidecar-hit models get here for the
|
|
|
|
|
// first time; stream-loaded models also pass through here when a
|
|
|
|
|
// separate data source opens, but applyCoordinateOperationToViewport
|
|
|
|
|
// is idempotent so double-applying is harmless.
|
|
|
|
|
applyCoordinateOperationToViewport(mid);
|
|
|
|
|
|
2026-04-24 13:45:04 +10:00
|
|
|
// Re-populate if the current selection belongs to this model, since
|
|
|
|
|
// populateProperties() now has an ifcFile() to query.
|
|
|
|
|
auto items = element_tree_->selectedItems();
|
|
|
|
|
if (items.isEmpty()) return;
|
|
|
|
|
uint32_t object_id = items.first()->data(0, Qt::UserRole).toUInt();
|
|
|
|
|
auto it = element_map_.find(object_id);
|
|
|
|
|
if (it != element_map_.end() && it->second.model_id == mid) {
|
|
|
|
|
populateProperties(object_id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 07:45:40 +10:00
|
|
|
void MainWindow::applyCoordinateOperationToViewport(uint32_t mid) {
|
|
|
|
|
Eigen::Matrix4d M = Eigen::Matrix4d::Identity();
|
|
|
|
|
if (AppSettings::instance().applyCoordinateOperation()) {
|
|
|
|
|
if (const ModelGeoref* gr = loader_->modelGeoref(mid)) {
|
|
|
|
|
if (gr->has_coordinate_operation) {
|
|
|
|
|
M = gr->coordinate_operation_meters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
viewport_->setModelCoordinateOperation(mid, M);
|
2026-05-02 07:58:26 +10:00
|
|
|
// ModelTransformation's compose can depend on the active
|
|
|
|
|
// CoordinateOperation (when ModelTransformation.a_frame == ModelLocal,
|
|
|
|
|
// a is lifted through stage 2), so re-push it whenever stage 2 changes.
|
|
|
|
|
applyModelTransformationToViewport(mid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::applyModelTransformationToViewport(uint32_t mid) {
|
|
|
|
|
Eigen::Matrix4d M = Eigen::Matrix4d::Identity();
|
|
|
|
|
auto fed_it = model_id_to_fed_id_.find(mid);
|
|
|
|
|
if (fed_it != model_id_to_fed_id_.end()) {
|
|
|
|
|
if (const Federation::Model* m = federation_->findById(fed_it->second)) {
|
|
|
|
|
// ModelUnits + the active CoordinateOperation come from the
|
|
|
|
|
// ModelGeoref cache; defaults are safe (1.0, 1.0, identity)
|
|
|
|
|
// when the IFC file isn't yet available.
|
|
|
|
|
ModelUnits units;
|
|
|
|
|
Eigen::Matrix4d coord_op = Eigen::Matrix4d::Identity();
|
|
|
|
|
if (const ModelGeoref* gr = loader_->modelGeoref(mid)) {
|
|
|
|
|
units = gr->units;
|
|
|
|
|
if (AppSettings::instance().applyCoordinateOperation() &&
|
|
|
|
|
gr->has_coordinate_operation) {
|
|
|
|
|
coord_op = gr->coordinate_operation_meters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
M = composeModelTransformation(
|
|
|
|
|
m->model_transformation, federation_->config(),
|
|
|
|
|
units, coord_op);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
viewport_->setModelTransformation(mid, M);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::applyFederatedFalseOriginToViewport() {
|
|
|
|
|
const Eigen::Matrix4d M = composeFederatedFalseOrigin(
|
|
|
|
|
federation_->federatedFalseOrigin(), federation_->config());
|
|
|
|
|
viewport_->setFederatedFalseOrigin(M);
|
2026-05-02 07:45:40 +10:00
|
|
|
}
|
|
|
|
|
|
2026-05-03 10:04:39 +10:00
|
|
|
void MainWindow::maybeGuessFederatedFalseOrigin(uint32_t mid) {
|
|
|
|
|
// Only auto-guess for untitled federations. A saved .ifcfed carries its
|
|
|
|
|
// authoritative origin (even if that happens to be the default), so we
|
|
|
|
|
// never silently overwrite it when the user re-adds a model.
|
|
|
|
|
if (!federation_->filePath().isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
// Skip once the origin is non-default — either the user edited it, a
|
|
|
|
|
// previous batch already guessed, or a load-from-file populated it.
|
|
|
|
|
// For a multi-file batch this means whichever model finishes first
|
|
|
|
|
// anchors the federation; the rest see a non-default origin and skip.
|
|
|
|
|
const FederatedFalseOrigin& cur = federation_->federatedFalseOrigin();
|
|
|
|
|
const FederatedFalseOrigin def;
|
|
|
|
|
if (cur.xyz != def.xyz || cur.rz_deg != def.rz_deg) return;
|
|
|
|
|
|
|
|
|
|
const Eigen::Matrix4d* placement = loader_->firstPlacement(mid);
|
|
|
|
|
const ModelGeoref* gr = loader_->modelGeoref(mid);
|
|
|
|
|
if (placement == nullptr || gr == nullptr) return;
|
|
|
|
|
|
|
|
|
|
const FederatedFalseOrigin guess = guessFederatedFalseOrigin(
|
|
|
|
|
*placement, *gr, federation_->config(),
|
|
|
|
|
AppSettings::instance().applyCoordinateOperation());
|
|
|
|
|
federation_->setFederatedFalseOrigin(guess);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 19:08:45 +10:00
|
|
|
void MainWindow::onLoadedFromSidecar(uint32_t mid, qint64 elapsed_ms) {
|
2026-04-21 18:05:19 +10:00
|
|
|
progress_bar_->setVisible(false);
|
|
|
|
|
status_label_->setText(QString("%1 elements across %2 model(s) — loaded from cache in %3")
|
|
|
|
|
.arg(element_map_.size())
|
|
|
|
|
.arg(loader_->modelCount())
|
|
|
|
|
.arg(formatElapsed(elapsed_ms)));
|
2026-05-02 19:08:45 +10:00
|
|
|
|
|
|
|
|
// Sidecar v11+ caches the CoordinateOperation, so SceneLoader has
|
|
|
|
|
// already populated modelGeoref by now — push CoordinateOperation +
|
|
|
|
|
// ModelTransformation immediately rather than waiting for the
|
|
|
|
|
// (possibly never-arriving) data-source load.
|
|
|
|
|
applyCoordinateOperationToViewport(mid);
|
2026-05-03 10:04:39 +10:00
|
|
|
maybeGuessFederatedFalseOrigin(mid);
|
2026-04-12 19:53:06 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::onStreamedElementsReady(uint32_t /*mid*/, std::vector<ElementInfo> elements) {
|
|
|
|
|
for (const auto& info : elements) {
|
|
|
|
|
element_map_[info.object_id] = info;
|
|
|
|
|
scoped_ifc_id_to_object_id_[scopedKey(info.model_id, info.ifc_id)] = info.object_id;
|
|
|
|
|
appendElementToTree(info.model_id, info.object_id, info.ifc_id,
|
|
|
|
|
info.parent_id, info.guid, info.name, info.type);
|
|
|
|
|
}
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::writeSidecarForModel(uint32_t mid) {
|
|
|
|
|
SidecarData sd;
|
|
|
|
|
if (!viewport_->snapshotModel(mid, sd)) return;
|
|
|
|
|
|
2026-05-02 19:08:45 +10:00
|
|
|
// Cache the model's CoordinateOperation alongside the geometry so a
|
|
|
|
|
// sidecar load doesn't need the IFC source just to apply georef.
|
|
|
|
|
if (const ModelGeoref* gr = loader_->modelGeoref(mid)) {
|
|
|
|
|
sd.has_coordinate_operation = gr->has_coordinate_operation ? 1 : 0;
|
|
|
|
|
Eigen::Map<Eigen::Matrix<double, 4, 4, Eigen::ColMajor>>(
|
|
|
|
|
sd.coordinate_operation_meters) = gr->coordinate_operation_meters;
|
|
|
|
|
sd.project_length_to_meters = gr->units.project_length_to_meters;
|
|
|
|
|
sd.map_unit_to_meters = gr->units.map_unit_to_meters;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
for (const auto& [oid, info] : element_map_) {
|
|
|
|
|
if (info.model_id != mid) continue;
|
|
|
|
|
PackedElementInfo pe;
|
|
|
|
|
pe.object_id = info.object_id;
|
|
|
|
|
pe.model_id = info.model_id;
|
|
|
|
|
pe.ifc_id = info.ifc_id;
|
|
|
|
|
pe.parent_id = info.parent_id;
|
|
|
|
|
pe.guid_offset = static_cast<uint32_t>(sd.string_table.size());
|
|
|
|
|
pe.guid_length = static_cast<uint32_t>(info.guid.size());
|
|
|
|
|
sd.string_table += info.guid;
|
|
|
|
|
pe.name_offset = static_cast<uint32_t>(sd.string_table.size());
|
|
|
|
|
pe.name_length = static_cast<uint32_t>(info.name.size());
|
|
|
|
|
sd.string_table += info.name;
|
|
|
|
|
pe.type_offset = static_cast<uint32_t>(sd.string_table.size());
|
|
|
|
|
pe.type_length = static_cast<uint32_t>(info.type.size());
|
|
|
|
|
sd.string_table += info.type;
|
|
|
|
|
sd.elements.push_back(pe);
|
2026-04-11 20:49:39 +10:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
QElapsedTimer t_lod; t_lod.start();
|
|
|
|
|
buildLods(sd);
|
|
|
|
|
LodStats ls = summariseLods(sd);
|
|
|
|
|
qDebug(" LOD build: %lld ms — %u/%u meshes got LOD1 "
|
|
|
|
|
"(%u tris -> %u tris for those meshes)",
|
|
|
|
|
t_lod.elapsed(),
|
|
|
|
|
ls.meshes_with_lod1, ls.meshes_total,
|
|
|
|
|
ls.tris_lod0_for_lod1, ls.tris_lod1);
|
|
|
|
|
viewport_->applyLodExtension(mid, sd);
|
|
|
|
|
|
|
|
|
|
QElapsedTimer t; t.start();
|
2026-04-22 11:58:04 +10:00
|
|
|
bool ok = writeSidecar(loader_->filePath(mid).toStdString(), sd);
|
2026-04-21 18:05:19 +10:00
|
|
|
qDebug(" Sidecar write: %lld ms (%s)", t.elapsed(), ok ? "ok" : "FAILED");
|
|
|
|
|
}
|
2026-04-11 20:49:39 +10:00
|
|
|
|
2026-04-22 11:27:53 +10:00
|
|
|
void MainWindow::removeModelUi(uint32_t mid) {
|
2026-04-27 18:31:59 +10:00
|
|
|
auto fed_it = model_id_to_fed_id_.find(mid);
|
|
|
|
|
if (fed_it != model_id_to_fed_id_.end()) {
|
|
|
|
|
fed_id_to_model_id_.erase(fed_it->second);
|
|
|
|
|
model_id_to_fed_id_.erase(fed_it);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-22 11:27:53 +10:00
|
|
|
auto root_it = tree_roots_.find(mid);
|
|
|
|
|
if (root_it != tree_roots_.end()) {
|
|
|
|
|
delete root_it->second;
|
|
|
|
|
tree_roots_.erase(root_it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto it = tree_items_.begin(); it != tree_items_.end();) {
|
|
|
|
|
auto info_it = element_map_.find(it->first);
|
|
|
|
|
if (info_it != element_map_.end() && info_it->second.model_id == mid) {
|
|
|
|
|
it = tree_items_.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto it = element_map_.begin(); it != element_map_.end();) {
|
|
|
|
|
if (it->second.model_id == mid) {
|
|
|
|
|
it = element_map_.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto it = scoped_ifc_id_to_object_id_.begin(); it != scoped_ifc_id_to_object_id_.end();) {
|
|
|
|
|
if (static_cast<uint32_t>(it->first >> 32) == mid) {
|
|
|
|
|
it = scoped_ifc_id_to_object_id_.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
viewport_->setSelectedObjectId(0);
|
|
|
|
|
property_table_->setRowCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
void MainWindow::onLoadedFromStream(uint32_t mid, qint64 elapsed_ms) {
|
|
|
|
|
progress_bar_->setVisible(false);
|
2026-04-11 20:49:39 +10:00
|
|
|
status_label_->setText(QString("%1 elements across %2 model(s) — last loaded in %3")
|
2026-04-21 18:05:19 +10:00
|
|
|
.arg(element_map_.size())
|
|
|
|
|
.arg(loader_->modelCount())
|
|
|
|
|
.arg(formatElapsed(elapsed_ms)));
|
2026-04-12 20:10:20 +10:00
|
|
|
|
2026-05-02 07:45:40 +10:00
|
|
|
applyCoordinateOperationToViewport(mid);
|
2026-05-03 10:04:39 +10:00
|
|
|
maybeGuessFederatedFalseOrigin(mid);
|
2026-05-02 07:45:40 +10:00
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
writeSidecarForModel(mid);
|
|
|
|
|
}
|
2026-04-12 09:09:32 +10:00
|
|
|
|
2026-04-22 11:27:53 +10:00
|
|
|
void MainWindow::onLoadCancelled(uint32_t mid) {
|
|
|
|
|
progress_bar_->setVisible(false);
|
|
|
|
|
removeModelUi(mid);
|
|
|
|
|
status_label_->setText(QString("%1 load cancelled").arg(loader_->displayName(mid)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onLoadError(uint32_t mid, QString message) {
|
|
|
|
|
progress_bar_->setVisible(false);
|
|
|
|
|
removeModelUi(mid);
|
|
|
|
|
status_label_->setText("Error: " + message);
|
2026-04-21 18:05:19 +10:00
|
|
|
QMessageBox::warning(this, "Error", message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onAllLoadsFinished() {
|
|
|
|
|
applyPendingBenchmark();
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onObjectPicked(uint32_t object_id) {
|
|
|
|
|
viewport_->setSelectedObjectId(object_id);
|
|
|
|
|
|
|
|
|
|
auto it = tree_items_.find(object_id);
|
|
|
|
|
if (it != tree_items_.end()) {
|
|
|
|
|
element_tree_->blockSignals(true);
|
|
|
|
|
element_tree_->setCurrentItem(it->second);
|
|
|
|
|
element_tree_->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
populateProperties(object_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::onTreeSelectionChanged() {
|
|
|
|
|
auto items = element_tree_->selectedItems();
|
|
|
|
|
if (items.isEmpty()) return;
|
|
|
|
|
|
|
|
|
|
uint32_t object_id = items.first()->data(0, Qt::UserRole).toUInt();
|
|
|
|
|
viewport_->setSelectedObjectId(object_id);
|
|
|
|
|
populateProperties(object_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::populateProperties(uint32_t object_id) {
|
|
|
|
|
property_table_->setRowCount(0);
|
|
|
|
|
if (object_id == 0) return;
|
|
|
|
|
|
|
|
|
|
auto it = element_map_.find(object_id);
|
|
|
|
|
if (it == element_map_.end()) return;
|
|
|
|
|
|
|
|
|
|
const auto& info = it->second;
|
|
|
|
|
|
|
|
|
|
auto addRow = [this](const QString& key, const QString& value) {
|
|
|
|
|
int row = property_table_->rowCount();
|
|
|
|
|
property_table_->insertRow(row);
|
|
|
|
|
property_table_->setItem(row, 0, new QTableWidgetItem(key));
|
|
|
|
|
property_table_->setItem(row, 1, new QTableWidgetItem(value));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addRow("IFC ID", QString::number(info.ifc_id));
|
|
|
|
|
addRow("GUID", QString::fromStdString(info.guid));
|
|
|
|
|
addRow("Name", QString::fromStdString(info.name));
|
|
|
|
|
addRow("Type", QString::fromStdString(info.type));
|
|
|
|
|
|
2026-04-21 18:05:19 +10:00
|
|
|
auto* file = loader_->ifcFile(info.model_id);
|
2026-04-11 16:30:10 +10:00
|
|
|
if (!file) return;
|
|
|
|
|
|
2026-04-11 19:23:10 +10:00
|
|
|
auto product = file->instance_by_id(info.ifc_id);
|
2026-04-11 16:30:10 +10:00
|
|
|
if (!product) return;
|
|
|
|
|
|
2026-04-11 19:23:10 +10:00
|
|
|
auto& decl = product.declaration();
|
2026-04-11 16:30:10 +10:00
|
|
|
if (auto* entity = decl.as_entity()) {
|
|
|
|
|
for (size_t i = 0; i < entity->attribute_count(); ++i) {
|
|
|
|
|
auto* attr = entity->attribute_by_index(i);
|
|
|
|
|
try {
|
2026-04-11 19:23:10 +10:00
|
|
|
auto val = product.get_attribute_value(i);
|
2026-04-11 16:30:10 +10:00
|
|
|
if (!val.isNull()) {
|
|
|
|
|
std::string str_val;
|
|
|
|
|
try {
|
|
|
|
|
str_val = static_cast<std::string>(val);
|
|
|
|
|
} catch (...) {
|
2026-04-11 19:23:10 +10:00
|
|
|
str_val = "<" + std::string(ifcopenshell::argument_type_to_string(val.type())) + ">";
|
2026-04-11 16:30:10 +10:00
|
|
|
}
|
|
|
|
|
addRow(QString::fromStdString(attr->name()), QString::fromStdString(str_val));
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-18 21:27:28 +10:00
|
|
|
|
|
|
|
|
void MainWindow::setPendingCamera(const QString& params) {
|
|
|
|
|
pending_camera_ = params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::setPendingBenchmark(int frames) {
|
|
|
|
|
pending_benchmark_ = frames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::applyPendingBenchmark() {
|
|
|
|
|
if (pending_camera_.isEmpty() && pending_benchmark_ <= 0) return;
|
|
|
|
|
|
|
|
|
|
if (!pending_camera_.isEmpty()) {
|
|
|
|
|
QStringList parts = pending_camera_.split(',');
|
|
|
|
|
if (parts.size() == 6) {
|
|
|
|
|
viewport_->setCamera(
|
|
|
|
|
parts[0].toFloat(), parts[1].toFloat(), parts[2].toFloat(),
|
|
|
|
|
parts[3].toFloat(), parts[4].toFloat(), parts[5].toFloat());
|
|
|
|
|
qDebug("Camera set: %s", qPrintable(pending_camera_));
|
|
|
|
|
} else {
|
|
|
|
|
qWarning("--camera expects 6 comma-separated values: tx,ty,tz,dist,yaw,pitch");
|
|
|
|
|
}
|
|
|
|
|
pending_camera_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pending_benchmark_ > 0) {
|
|
|
|
|
qDebug("Starting benchmark: %d frames", pending_benchmark_);
|
|
|
|
|
viewport_->setBenchmarkFrames(pending_benchmark_);
|
|
|
|
|
pending_benchmark_ = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-21 18:05:19 +10:00
|
|
|
|
|
|
|
|
QString MainWindow::formatElapsed(qint64 ms) const {
|
|
|
|
|
return (ms >= 1000)
|
|
|
|
|
? QString::number(ms / 1000.0, 'f', 2) + " s"
|
|
|
|
|
: QString::number(ms) + " ms";
|
|
|
|
|
}
|