Rename IfcViewerFull to Bonsai Viewer

Directory src/ifcviewer-full -> src/bonsaiviewer, CMake target
IfcViewerFull -> BonsaiViewer, namespace ifcviewerfull -> bonsaiviewer,
QApplication / window titles / connector path now use the new brand.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-05-20 09:38:10 +10:00
parent fcae3d90af
commit 59e5b2b1b8
125 changed files with 308 additions and 308 deletions
+123
View File
@@ -0,0 +1,123 @@
# This file was generated with the assistance of an AI coding tool.
################################################################################
# #
# 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/>. #
# #
################################################################################
message("Running CMakeLists.txt in /src/bonsaiviewer")
set(QT_VERSION 6 CACHE STRING "Qt version")
find_package(Qt${QT_VERSION} COMPONENTS Core CorePrivate Gui Widgets Svg REQUIRED PATHS ${QT_DIR})
set(BONSAIVIEWER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ElementRegistry.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ElementRegistry.h
${CMAKE_CURRENT_SOURCE_DIR}/ViewerSettings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/ViewerSettings.h
${CMAKE_CURRENT_SOURCE_DIR}/SessionState.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SessionState.h
${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/MainWindow.h
${CMAKE_CURRENT_SOURCE_DIR}/Measurement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Measurement.h
${CMAKE_CURRENT_SOURCE_DIR}/components/SvgIcon.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/SvgIcon.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Style.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Style.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Dialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Dialog.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Tabs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Tabs.h
${CMAKE_CURRENT_SOURCE_DIR}/components/KeyValueTable.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/KeyValueTable.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Buttons.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Buttons.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Section.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Section.h
${CMAKE_CURRENT_SOURCE_DIR}/components/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/components/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Discovery.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Discovery.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/PickerDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/PickerDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Process.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Process.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Registry.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/connectors/Registry.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/AddModelDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/AddModelDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/SettingsDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/SettingsDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/SettingsView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/SettingsView.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/Types.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/Commands.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/Commands.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/FederationItemModel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/FederationItemModel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/View.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/models/View.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/todo/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/todo/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/properties/Types.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/properties/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/properties/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/properties/View.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/properties/View.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/project/Commands.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/project/Commands.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/project/SaveProjectDialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/project/SaveProjectDialog.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/settings/Dialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/settings/Dialog.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/spatial_hierarchy/Types.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/spatial_hierarchy/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/spatial_hierarchy/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/spatial_hierarchy/View.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/spatial_hierarchy/View.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/Panel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/Panel.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/Commands.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/Commands.h
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/View.cpp
${CMAKE_CURRENT_SOURCE_DIR}/modules/viewport/View.h
${CMAKE_CURRENT_SOURCE_DIR}/bonsaiviewer_resources.qrc
)
add_executable(BonsaiViewer ${BONSAIVIEWER_FILES})
set_target_properties(BonsaiViewer PROPERTIES
AUTOMOC ON
AUTORCC ON
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)
target_link_libraries(BonsaiViewer PRIVATE
IfcViewer
Qt${QT_VERSION}::Core
Qt${QT_VERSION}::CorePrivate
Qt${QT_VERSION}::Gui
Qt${QT_VERSION}::Svg
Qt${QT_VERSION}::Widgets
)
install(TARGETS BonsaiViewer EXPORT ${IFCOPENSHELL_EXPORT_TARGETS})
ifcopenshell_deploy_qt_runtime(BonsaiViewer)
+126
View File
@@ -0,0 +1,126 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "ElementRegistry.h"
#include "../ifcviewer/GeometryStreamer.h"
#include "../ifcviewer/SceneLoader.h"
#include "../ifcviewer/SidecarCache.h"
namespace bonsaiviewer {
ElementRegistry::ElementRegistry(QObject* parent)
: QObject(parent)
{
}
void ElementRegistry::bindLoader(SceneLoader* loader) {
loader_ = loader;
connect(loader, &SceneLoader::sidecarElementsReady,
this, &ElementRegistry::onSidecarElementsReady);
connect(loader, &SceneLoader::streamedElementsReady,
this, &ElementRegistry::onStreamedElementsReady);
}
void ElementRegistry::clear() {
elements_.clear();
}
void ElementRegistry::removeModel(uint32_t model_id) {
for (auto it = elements_.begin(); it != elements_.end();) {
if (it->second.model_id == model_id) {
it = elements_.erase(it);
} else {
++it;
}
}
}
std::vector<BasicElementInfo> ElementRegistry::basicElementInfoForModel(uint32_t model_id) const {
std::vector<BasicElementInfo> result;
result.reserve(elements_.size());
for (const auto& [object_id, info] : elements_) {
(void)object_id;
if (info.model_id != model_id) continue;
result.push_back(info);
}
return result;
}
std::optional<BasicElementInfo> ElementRegistry::findBasicElementInfo(uint32_t object_id) const {
auto it = elements_.find(object_id);
if (it == elements_.end()) return std::nullopt;
return it->second;
}
std::optional<express::Base> ElementRegistry::findEntity(uint32_t object_id) const {
if (!loader_) return std::nullopt;
auto info = findBasicElementInfo(object_id);
if (!info) return std::nullopt;
auto* file = loader_->ifcFile(info->model_id);
if (!file) return std::nullopt;
try {
auto instance = file->instance_by_id(info->ifc_id);
if (!instance) return std::nullopt;
return instance;
} catch (...) {
return std::nullopt;
}
}
void ElementRegistry::onSidecarElementsReady(uint32_t /*mid*/,
std::vector<PackedElementInfo> elements,
std::string string_table) {
auto str = [&](uint32_t offset, uint32_t length) -> QString {
if (length == 0 || offset + length > string_table.size()) return {};
return QString::fromStdString(string_table.substr(offset, length));
};
for (const auto& pe : elements) {
BasicElementInfo info;
info.object_id = pe.object_id;
info.model_id = pe.model_id;
info.ifc_id = pe.ifc_id;
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);
elements_[info.object_id] = info;
}
}
void ElementRegistry::onStreamedElementsReady(uint32_t /*mid*/, std::vector<ElementInfo> elements) {
for (const auto& e : elements) {
BasicElementInfo info;
info.object_id = e.object_id;
info.model_id = e.model_id;
info.ifc_id = e.ifc_id;
info.parent_id = e.parent_id;
info.guid = QString::fromStdString(e.guid);
info.name = QString::fromStdString(e.name);
info.type = QString::fromStdString(e.type);
elements_[info.object_id] = info;
}
}
} // namespace bonsaiviewer
+72
View File
@@ -0,0 +1,72 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_ELEMENTREGISTRY_H
#define IFCINTERFACE_ELEMENTREGISTRY_H
#include <QObject>
#include <QString>
#include "../ifcparse/express.h"
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
class SceneLoader;
struct PackedElementInfo;
struct ElementInfo;
namespace bonsaiviewer {
struct BasicElementInfo {
uint32_t object_id = 0;
uint32_t model_id = 0;
int ifc_id = 0;
int parent_id = 0;
QString guid;
QString name;
QString type;
};
class ElementRegistry : public QObject {
Q_OBJECT
public:
explicit ElementRegistry(QObject* parent = nullptr);
void bindLoader(SceneLoader* loader);
void clear();
void removeModel(uint32_t model_id);
std::vector<BasicElementInfo> basicElementInfoForModel(uint32_t model_id) const;
std::optional<BasicElementInfo> findBasicElementInfo(uint32_t object_id) const;
std::optional<express::Base> findEntity(uint32_t object_id) const;
private:
void onSidecarElementsReady(uint32_t mid,
std::vector<PackedElementInfo> elements,
std::string string_table);
void onStreamedElementsReady(uint32_t mid, std::vector<ElementInfo> elements);
SceneLoader* loader_ = nullptr;
std::unordered_map<uint32_t, BasicElementInfo> elements_;
};
} // namespace bonsaiviewer
#endif
+511
View File
@@ -0,0 +1,511 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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"
#include "../ifcviewer/AppSettings.h"
#include "../ifcviewer/Federation.h"
#include "../ifcviewer/ViewportWindow.h"
#include "SessionState.h"
#include "components/Buttons.h"
#include "components/Panel.h"
#include "components/Style.h"
#include "components/Tabs.h"
#include "modules/models/Commands.h"
#include "modules/todo/Panel.h"
#include "modules/models/View.h"
#include "modules/models/Panel.h"
#include "modules/project/Commands.h"
#include "modules/properties/View.h"
#include "modules/properties/Panel.h"
#include "modules/settings/Dialog.h"
#include "modules/spatial_hierarchy/View.h"
#include "modules/spatial_hierarchy/Panel.h"
#include "modules/viewport/Commands.h"
#include "modules/viewport/Panel.h"
#include "modules/viewport/View.h"
#include <QDockWidget>
#include <QFileInfo>
#include <QHBoxLayout>
#include <QIcon>
#include <QLabel>
#include <QMessageBox>
#include <QShortcut>
#include <QSignalBlocker>
#include <QStackedWidget>
#include <QStatusBar>
#include <QProgressBar>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::shell {
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
session_state_ = new bonsaiviewer::SessionState(this);
auto on_mutated = [this]() {
setWindowModified(true);
updateWindowTitle();
};
auto on_clean_state = [this]() {
setWindowModified(false);
updateWindowTitle();
};
connect(session_state_, &bonsaiviewer::SessionState::federationChanged, this, on_mutated);
connect(session_state_, &bonsaiviewer::SessionState::modelsChanged, this, on_mutated);
connect(session_state_, &bonsaiviewer::SessionState::projectReset, this, on_clean_state);
connect(session_state_, &bonsaiviewer::SessionState::projectOpened, this, on_clean_state);
connect(session_state_, &bonsaiviewer::SessionState::projectSaved, this, on_clean_state);
setupChrome();
setupViewport();
setupPanels();
setupStatus();
setupLoader();
setupRibbon();
resize(1720, 980);
}
void MainWindow::setupChrome() {
setObjectName("appWindow");
setDockOptions(QMainWindow::AllowNestedDocks |
QMainWindow::AllowTabbedDocks |
QMainWindow::GroupedDragging);
auto bind_shortcut = [this](const QKeySequence& sequence, auto fn) {
auto* shortcut = new QShortcut(sequence, this);
shortcut->setContext(Qt::WindowShortcut);
connect(shortcut, &QShortcut::activated, this, fn);
};
bind_shortcut(QKeySequence("Ctrl+Shift+L"), [this]() {
modules::viewport::commands::toggleDistance(*viewport_widget_->viewport());
});
bind_shortcut(QKeySequence("Ctrl+Shift+A"), [this]() {
modules::viewport::commands::toggleArea(*viewport_widget_->viewport());
});
bind_shortcut(QKeySequence("Ctrl+Shift+V"), [this]() {
modules::viewport::commands::toggleVolume(*viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::SHIFT | Qt::Key_F), [this]() {
modules::viewport::commands::fly(*session_state_, *viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::Key_K), [this]() {
modules::viewport::commands::toggleSection(*session_state_, *viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::SHIFT | Qt::Key_K), [this]() {
modules::viewport::commands::clearSection(*session_state_, *viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::Key_H), [this]() {
modules::viewport::commands::hideSelected(*viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::SHIFT | Qt::Key_H), [this]() {
modules::viewport::commands::isolateSelected(*viewport_widget_->viewport());
});
bind_shortcut(QKeySequence(Qt::ALT | Qt::Key_H), [this]() {
modules::viewport::commands::showAll(*viewport_widget_->viewport());
});
updateWindowTitle();
}
QToolButton* MainWindow::makePanelToggle(const QString& text, QDockWidget* dock) {
auto* button = components::buttons::makeButton(text, ":/icons/sidebar-expand.svg", this);
button->setCheckable(true);
button->setChecked(dock->isVisible());
connect(button, &QToolButton::toggled, dock, [dock](bool checked) {
dock->setVisible(checked);
if (checked) dock->raise();
});
connect(dock, &QDockWidget::visibilityChanged, button, [button](bool visible) {
const QSignalBlocker blocker(button);
button->setChecked(visible);
});
return button;
}
QWidget* MainWindow::buildHomeRibbonPage() {
auto* page = new QFrame(this);
page->setObjectName("ribbonPage");
auto* row = new QHBoxLayout(page);
row->setContentsMargins(6, 4, 6, 4);
row->setSpacing(0);
auto* new_project = components::buttons::makeButton("New Project", ":/icons/plus-square.svg", this);
connect(new_project, &QToolButton::clicked, this, [this]() {
modules::project::commands::newProject(
*session_state_, *this, *viewport_widget_->viewport());
});
auto* open_project = components::buttons::makeButton("Open Project", ":/icons/download-square.svg", this);
connect(open_project, &QToolButton::clicked, this, [this]() {
modules::project::commands::openProject(
*session_state_, *this, *viewport_widget_->viewport());
});
auto* open_cloud = components::buttons::makeButton("Open Cloud", ":/icons/cloud-square.svg", this);
connect(open_cloud, &QToolButton::clicked, this, [this]() {
modules::project::commands::openCloudProject(
*session_state_, *this, *viewport_widget_->viewport());
});
auto* open_recent = components::buttons::makeButton("Open Recent", ":/icons/clock-rotate-right.svg", this);
connect(open_recent, &QToolButton::clicked, this, [this]() {
session_state_->setStatusMessage("Project", "Open Recent coming soon");
});
auto* save_project = components::buttons::makeButton("Save Project", ":/icons/floppy-disk.svg", this);
connect(save_project, &QToolButton::clicked, this, [this]() {
modules::project::commands::saveProjectDialog(*session_state_, *this);
});
auto* add_model = components::buttons::makeButton("Add Model", ":/icons/cube.svg", this);
connect(add_model, &QToolButton::clicked, this, [this]() {
modules::models::commands::addModel(*session_state_, *this);
});
auto* sync_from_cloud = components::buttons::makeButton("Sync From Cloud", ":/icons/refresh-double.svg", this);
connect(sync_from_cloud, &QToolButton::clicked, this, [this]() {
modules::project::commands::syncCloudProject(
*session_state_, *this, *viewport_widget_->viewport());
});
auto* settings_button = components::buttons::makeButton("Settings", ":/icons/settings.svg", this);
connect(settings_button, &QToolButton::clicked, this, [this]() {
modules::settings::SettingsDialog dialog(session_state_, this);
dialog.exec();
});
row->addWidget(components::buttons::makeButtonGroup("PROJECT", {new_project, open_project, open_cloud, open_recent, save_project}, this));
row->addWidget(components::buttons::makeButtonGroup("MODELS", {add_model, sync_from_cloud}, this));
row->addWidget(components::buttons::makeButtonGroup("SETTINGS", {settings_button}, this));
row->addStretch(1);
return page;
}
QWidget* MainWindow::buildNavigateRibbonPage() {
auto* page = new QFrame(this);
page->setObjectName("ribbonPage");
auto* row = new QHBoxLayout(page);
row->setContentsMargins(2, 4, 2, 4);
row->setSpacing(0);
auto* set_home = components::buttons::makeButton("Set Home", ":/icons/home.svg", this);
connect(set_home, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::setHome(*session_state_, *viewport_widget_->viewport());
});
auto* go_home = components::buttons::makeButton("Go Home", ":/icons/home-alt.svg", this);
connect(go_home, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::goHome(*session_state_, *viewport_widget_->viewport());
});
auto* view_all = components::buttons::makeButton("View All", ":/icons/cube-scan.svg", this);
connect(view_all, &QToolButton::clicked, this, [this]() {
if (viewport_widget_) viewport_widget_->viewport()->viewAll();
});
auto* view_selected = components::buttons::makeButton("View Selected", ":/icons/cube-scan-solid.svg", this);
connect(view_selected, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::viewSelected(*viewport_widget_->viewport());
});
auto* plan_view = components::buttons::makeButton("Plan", ":/icons/planimetry.svg", this);
connect(plan_view, &QToolButton::clicked, this, [this]() {
if (viewport_widget_) viewport_widget_->viewport()->setStandardView(90.0f, 90.0f);
});
auto* front_view = components::buttons::makeButton("Front", ":/icons/city.svg", this);
connect(front_view, &QToolButton::clicked, this, [this]() {
if (viewport_widget_) viewport_widget_->viewport()->setStandardView(0.0f, 0.0f);
});
auto* side_view = components::buttons::makeButton("Side", ":/icons/building.svg", this);
connect(side_view, &QToolButton::clicked, this, [this]() {
if (viewport_widget_) viewport_widget_->viewport()->setStandardView(90.0f, 0.0f);
});
auto* align_object = components::buttons::makeButton("Align Object", ":/icons/cellar.svg", this);
connect(align_object, &QToolButton::clicked, this, [this]() {
session_state_->setStatusMessage("Orientation", "Align to object coming soon");
});
auto* projection_button = components::buttons::makeButton("Perspective", ":/icons/perspective-view.svg", this);
connect(projection_button, &QToolButton::clicked, this, [this, projection_button]() {
if (!viewport_widget_) return;
viewport_widget_->viewport()->toggleProjection();
projection_button->setText(
viewport_widget_->viewport()->projectionOrtho() ? "Ortho" : "Perspective");
});
auto* fly_mode = components::buttons::makeButton("Fly", ":/icons/drone.svg", this);
connect(fly_mode, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::fly(*session_state_, *viewport_widget_->viewport());
});
auto* section_mode = components::buttons::makeButton("Section", ":/icons/cube-cut-with-curve.svg", this);
connect(section_mode, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::toggleSection(*session_state_, *viewport_widget_->viewport());
});
row->addWidget(components::buttons::makeButtonGroup("CAMERA", {set_home, go_home, view_all, view_selected}, this));
row->addWidget(components::buttons::makeButtonGroup("ORIENTATION", {plan_view, front_view, side_view, align_object, projection_button}, this));
row->addWidget(components::buttons::makeButtonGroup("MODE", {fly_mode, section_mode}, this));
row->addStretch(1);
return page;
}
QWidget* MainWindow::buildInspectRibbonPage() {
auto* page = new QFrame(this);
page->setObjectName("ribbonPage");
auto* row = new QHBoxLayout(page);
row->setContentsMargins(2, 4, 2, 4);
row->setSpacing(0);
auto* hide_selected = components::buttons::makeButton("Hide", ":/icons/eye-closed.svg", this);
connect(hide_selected, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::hideSelected(*viewport_widget_->viewport());
});
auto* isolate_selected = components::buttons::makeButton("Isolate", ":/icons/eye-solid.svg", this);
connect(isolate_selected, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::isolateSelected(*viewport_widget_->viewport());
});
auto* show_all = components::buttons::makeButton("Show All", ":/icons/eye.svg", this);
connect(show_all, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::showAll(*viewport_widget_->viewport());
});
auto* invert_selection = components::buttons::makeButton("Invert", ":/icons/intersect.svg", this);
connect(invert_selection, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::invertVisibility(*viewport_widget_->viewport());
});
auto* distance = components::buttons::makeButton("Distance", ":/icons/select-edge3d.svg", this);
connect(distance, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::toggleDistance(*viewport_widget_->viewport());
});
auto* area = components::buttons::makeButton("Area", ":/icons/select-face3d.svg", this);
connect(area, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::toggleArea(*viewport_widget_->viewport());
});
auto* volume = components::buttons::makeButton("Volume", ":/icons/select-point3d.svg", this);
connect(volume, &QToolButton::clicked, this, [this]() {
modules::viewport::commands::toggleVolume(*viewport_widget_->viewport());
});
row->addWidget(components::buttons::makeButtonGroup("SELECTION", {hide_selected, isolate_selected, show_all, invert_selection}, this));
row->addWidget(components::buttons::makeButtonGroup("MEASURE", {distance, area, volume}, this));
row->addStretch(1);
return page;
}
QWidget* MainWindow::buildPanelsRibbonPage() {
auto* page = new QFrame(this);
page->setObjectName("ribbonPage");
auto* row = new QHBoxLayout(page);
row->setContentsMargins(2, 4, 2, 4);
row->setSpacing(0);
row->addWidget(components::buttons::makeButtonGroup("DATA", {
makePanelToggle("Models", models_panel_),
makePanelToggle("Spatial", spatial_panel_),
makePanelToggle("Layers", layers_panel_),
makePanelToggle("Properties", properties_panel_)
}, this));
row->addWidget(components::buttons::makeButtonGroup("QUERY", {
makePanelToggle("Views", stored_views_panel_),
makePanelToggle("Search", search_panel_),
makePanelToggle("Sheets", spreadsheet_panel_),
makePanelToggle("Audit", audit_panel_)
}, this));
row->addWidget(components::buttons::makeButtonGroup("COLLABORATE", {
makePanelToggle("Clash", clash_panel_),
makePanelToggle("Issues", issues_panel_)
}, this));
row->addStretch(1);
return page;
}
void MainWindow::setupRibbon() {
auto* shell = new QFrame(this);
auto* shell_layout = new QVBoxLayout(shell);
shell_layout->setContentsMargins(0, 0, 0, 0);
shell_layout->setSpacing(0);
ribbon_tabs_ = new components::TabBar(shell);
ribbon_tabs_->addTab("Home");
ribbon_tabs_->addTab("Navigate");
ribbon_tabs_->addTab("Inspect");
ribbon_tabs_->addTab("Panels");
ribbon_tabs_->setCurrentIndex(0);
auto* ribbon_band = new QFrame(shell);
ribbon_band->setObjectName("ribbonBand");
auto* band_layout = new QVBoxLayout(ribbon_band);
band_layout->setContentsMargins(0, 0, 0, 0);
band_layout->setSpacing(0);
ribbon_pages_ = new QStackedWidget(ribbon_band);
ribbon_pages_->addWidget(buildHomeRibbonPage());
ribbon_pages_->addWidget(buildNavigateRibbonPage());
ribbon_pages_->addWidget(buildInspectRibbonPage());
ribbon_pages_->addWidget(buildPanelsRibbonPage());
band_layout->addWidget(ribbon_pages_);
shell_layout->addWidget(ribbon_tabs_);
shell_layout->addWidget(ribbon_band);
connect(ribbon_tabs_, &components::TabBar::currentChanged,
ribbon_pages_, &QStackedWidget::setCurrentIndex);
setMenuWidget(shell);
}
void MainWindow::setupViewport() {
viewport_widget_ = new modules::viewport::ViewportPanel(this);
setCentralWidget(viewport_widget_);
}
void MainWindow::setupPanels() {
models_panel_ = new modules::models::ModelsPanel(
session_state_, viewport_widget_->viewport(), this);
spatial_panel_ = new modules::spatial_hierarchy::SpatialHierarchyPanel(this);
properties_panel_ = new modules::properties::PropertiesPanel(this);
models_view_ = new modules::models::ModelsPanelView(models_panel_, session_state_, this);
spatial_view_ = new modules::spatial_hierarchy::SpatialHierarchyPanelView(spatial_panel_, session_state_, this);
properties_view_ = new modules::properties::PropertiesPanelView(properties_panel_, session_state_, this);
layers_panel_ = new components::Panel("Layers", new modules::todo::TodoPanel("Layers", this), this);
stored_views_panel_ = new components::Panel(
"Stored Views", new modules::todo::TodoPanel("Stored Views", this), this);
search_panel_ = new components::Panel(
"Search and Query", new modules::todo::TodoPanel("Search and Query", this), this);
spreadsheet_panel_ = new components::Panel(
"Spreadsheet", new modules::todo::TodoPanel("Spreadsheet", this), this);
audit_panel_ = new components::Panel("Audit", new modules::todo::TodoPanel("Audit", this), this);
clash_panel_ = new components::Panel("Clash", new modules::todo::TodoPanel("Clash", this), this);
issues_panel_ = new components::Panel("Issues", new modules::todo::TodoPanel("Issues", this), this);
addDockWidget(Qt::LeftDockWidgetArea, models_panel_);
addDockWidget(Qt::LeftDockWidgetArea, spatial_panel_);
splitDockWidget(models_panel_, spatial_panel_, Qt::Vertical);
addDockWidget(Qt::RightDockWidgetArea, properties_panel_);
addDockWidget(Qt::RightDockWidgetArea, layers_panel_);
addDockWidget(Qt::RightDockWidgetArea, stored_views_panel_);
addDockWidget(Qt::RightDockWidgetArea, search_panel_);
addDockWidget(Qt::RightDockWidgetArea, spreadsheet_panel_);
addDockWidget(Qt::RightDockWidgetArea, audit_panel_);
addDockWidget(Qt::RightDockWidgetArea, clash_panel_);
addDockWidget(Qt::RightDockWidgetArea, issues_panel_);
tabifyDockWidget(properties_panel_, layers_panel_);
tabifyDockWidget(layers_panel_, stored_views_panel_);
tabifyDockWidget(stored_views_panel_, search_panel_);
tabifyDockWidget(search_panel_, spreadsheet_panel_);
tabifyDockWidget(spreadsheet_panel_, audit_panel_);
tabifyDockWidget(audit_panel_, clash_panel_);
tabifyDockWidget(clash_panel_, issues_panel_);
properties_panel_->raise();
layers_panel_->hide();
stored_views_panel_->hide();
search_panel_->hide();
spreadsheet_panel_->hide();
audit_panel_->hide();
clash_panel_->hide();
issues_panel_->hide();
resizeDocks({models_panel_, properties_panel_}, {290, 330}, Qt::Horizontal);
resizeDocks({models_panel_, spatial_panel_}, {280, 240}, Qt::Vertical);
}
void MainWindow::setupStatus() {
status_mode_label_ = new QLabel("Ready", this);
status_selection_label_ = new QLabel("No selection", this);
status_perf_label_ = new QLabel(this);
status_progress_bar_ = new QProgressBar(this);
status_perf_label_->setVisible(AppSettings::instance().showStats());
status_progress_bar_->setMaximumWidth(200);
status_progress_bar_->setVisible(false);
statusBar()->setSizeGripEnabled(false);
statusBar()->addWidget(status_mode_label_);
statusBar()->addWidget(status_selection_label_, 1);
statusBar()->addPermanentWidget(status_perf_label_);
statusBar()->addPermanentWidget(status_progress_bar_);
connect(&AppSettings::instance(), &AppSettings::showStatsChanged, this, [this](bool show) {
status_perf_label_->setVisible(show);
if (!show) status_perf_label_->clear();
});
connect(session_state_, &bonsaiviewer::SessionState::statusMessageChanged,
this, [this](const QString& mode, const QString& detail) {
status_mode_label_->setText(mode);
status_selection_label_->setText(detail);
});
connect(session_state_, &bonsaiviewer::SessionState::progressBegan, this, [this](const QString&) {
// Start in indeterminate mode (spinning bar). The first concrete
// setProgress(...) call below switches it to a determinate 0-100 bar.
status_progress_bar_->setRange(0, 0);
status_progress_bar_->setVisible(true);
});
connect(session_state_, &bonsaiviewer::SessionState::progressChanged, this, [this](int percent) {
if (status_progress_bar_->maximum() == 0) status_progress_bar_->setRange(0, 100);
status_progress_bar_->setValue(percent);
});
connect(session_state_, &bonsaiviewer::SessionState::progressEnded, this, [this]() {
status_progress_bar_->setVisible(false);
});
session_state_->setStatusMessage("Ready", "No selection");
}
void MainWindow::setupLoader() {
session_state_->createLoader(viewport_widget_->viewport());
viewport_view_ = new modules::viewport::ViewportView(
session_state_, viewport_widget_->viewport(), this);
// Load errors surface through SessionState as a session-level signal; the
// status text + progress are already cleared there, we only show the modal.
connect(session_state_, &bonsaiviewer::SessionState::loadError, this,
[this](const QString& message) {
QMessageBox::warning(this, "Bonsai Viewer", message);
});
connect(viewport_widget_->viewport(), &ViewportWindow::frameStatsUpdated, this,
[this](const ViewportWindow::FrameStats& s) {
if (!status_perf_label_->isVisible()) return;
status_perf_label_->setText(
QString("%1 fps | %2 ms | %3/%4 obj | %5/%6 tri | %7 draws")
.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)
.arg(s.total_triangles)
.arg(s.gl_draw_calls));
});
connect(viewport_widget_->viewport(), &ViewportWindow::objectPicked,
this, [this](uint32_t object_id) {
session_state_->setSelectedObjectId(object_id);
session_state_->notifySelectionChanged();
});
}
void MainWindow::updateWindowTitle() {
auto* federation = session_state_->federation();
const QString project_path = federation->filePath();
if (project_path.isEmpty() && federation->models().empty()) {
setWindowTitle("Bonsai Viewer");
} else if (project_path.isEmpty()) {
setWindowTitle("untitled[*] - Bonsai Viewer");
} else {
setWindowTitle(QFileInfo(project_path).fileName() + "[*] - Bonsai Viewer");
}
}
} // namespace bonsaiviewer::shell
+92
View File
@@ -0,0 +1,92 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_SHELL_MAINWINDOW_H
#define IFCINTERFACE_SHELL_MAINWINDOW_H
#include <QHash>
#include <QMainWindow>
#include <QStringList>
class QLabel;
class QDockWidget;
class QProgressBar;
class QStackedWidget;
class QToolButton;
namespace bonsaiviewer { class SessionState; }
namespace bonsaiviewer::components { class TabBar; }
namespace bonsaiviewer::modules::models { class ModelsPanel; }
namespace bonsaiviewer::modules::models { class ModelsPanelView; }
namespace bonsaiviewer::modules::spatial_hierarchy { class SpatialHierarchyPanel; }
namespace bonsaiviewer::modules::spatial_hierarchy { class SpatialHierarchyPanelView; }
namespace bonsaiviewer::modules::properties { class PropertiesPanel; }
namespace bonsaiviewer::modules::properties { class PropertiesPanelView; }
namespace bonsaiviewer::modules::viewport { class ViewportView; }
namespace bonsaiviewer::modules::viewport { class ViewportPanel; }
namespace bonsaiviewer::shell {
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = nullptr);
private:
void setupChrome();
void setupRibbon();
void setupViewport();
void setupPanels();
void setupStatus();
void setupLoader();
QWidget* buildHomeRibbonPage();
QWidget* buildNavigateRibbonPage();
QWidget* buildInspectRibbonPage();
QWidget* buildPanelsRibbonPage();
void updateWindowTitle();
QToolButton* makePanelToggle(const QString& text, QDockWidget* dock);
private:
QLabel* status_mode_label_ = nullptr;
QLabel* status_selection_label_ = nullptr;
QLabel* status_perf_label_ = nullptr;
QProgressBar* status_progress_bar_ = nullptr;
bonsaiviewer::components::TabBar* ribbon_tabs_ = nullptr;
QStackedWidget* ribbon_pages_ = nullptr;
bonsaiviewer::modules::viewport::ViewportPanel* viewport_widget_ = nullptr;
bonsaiviewer::modules::viewport::ViewportView* viewport_view_ = nullptr;
bonsaiviewer::SessionState* session_state_ = nullptr;
bonsaiviewer::modules::models::ModelsPanel* models_panel_ = nullptr;
bonsaiviewer::modules::spatial_hierarchy::SpatialHierarchyPanel* spatial_panel_ = nullptr;
QDockWidget* layers_panel_ = nullptr;
bonsaiviewer::modules::properties::PropertiesPanel* properties_panel_ = nullptr;
QDockWidget* stored_views_panel_ = nullptr;
QDockWidget* search_panel_ = nullptr;
QDockWidget* spreadsheet_panel_ = nullptr;
QDockWidget* audit_panel_ = nullptr;
QDockWidget* clash_panel_ = nullptr;
QDockWidget* issues_panel_ = nullptr;
bonsaiviewer::modules::models::ModelsPanelView* models_view_ = nullptr;
bonsaiviewer::modules::spatial_hierarchy::SpatialHierarchyPanelView* spatial_view_ = nullptr;
bonsaiviewer::modules::properties::PropertiesPanelView* properties_view_ = nullptr;
};
} // namespace bonsaiviewer::shell
#endif
File diff suppressed because it is too large Load Diff
+162
View File
@@ -0,0 +1,162 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MEASUREMENT_H
#define IFCINTERFACE_MEASUREMENT_H
#include <cstddef>
#include "ViewportWindow.h"
#include <QString>
#include <array>
#include <cstdint>
#include <unordered_map>
#include <vector>
// Sum of mesh-local volumes (m³) of every instance whose object_id is in
// `object_ids`. Groups by (model, mesh) so each unique mesh is read back
// from the GPU at most once per call; instances of the same mesh are scaled
// by |det(placement_3x3)| to pick up mapped-item scale/mirror. Volume is
// taken as the absolute value of the signed-tetrahedra sum, so winding
// convention does not matter. Returns 0.0 for empty input or when nothing
// resolves. Recomputes from scratch on every call — no cache.
double volumeOfObjects(ViewportWindow& vp,
const std::vector<uint32_t>& object_ids);
// Per-object volumes (m³). Same algorithm as volumeOfObjects but
// attributed per id rather than summed. Skips ids that don't resolve
// to a live instance, so the result may be shorter than the input.
// Used by MainWindow's volume readout to drive both the total HUD and
// the per-object overlay labels.
std::vector<std::pair<uint32_t, double>>
volumesPerObject(ViewportWindow& vp,
const std::vector<uint32_t>& object_ids);
// Click-to-accumulate area measurement. Each pick resolves the screen
// click to a (instance, triangle) using ViewportWindow's primitives,
// expands it into the connected coplanar patch (BFS over shared edges,
// dot(normal, seed_normal) > 0.9999), then either adds or removes that
// patch from the running set depending on whether the seed triangle was
// already in. Alt-click skips the BFS expansion (single-triangle).
// Picks on different instances (even of the same mesh) are kept as
// separate patches and their areas are summed.
//
// On every pick the world-space triangles of the running set are pushed
// to ViewportWindow::setHighlightTriangles for in-viewport shading.
// State is cleared on construction, on clear(), and is expected to be
// reset by the host (e.g. when the viewport's area tool toggles off).
class AreaMeasurement {
public:
AreaMeasurement();
// Main entry point: handle one click in area-tool mode. alt = true
// suppresses BFS expansion. Logs the per-click delta and running total
// via qInfo. Misses are silent.
void onPick(ViewportWindow& vp, int x, int y, bool alt);
// Wipe all accumulated triangles, per-mesh adjacency caches, and the
// viewport overlay.
void clear(ViewportWindow& vp);
double totalArea() const { return total_area_m2_; }
size_t triangleCount() const { return selected_.size(); }
private:
// Cached per-mesh data: triangles + edge→triangles adjacency. Keyed
// by (model_id << 32) | mesh_id. Filled lazily on first pick of that
// mesh, dropped on clear().
struct MeshCache {
std::vector<float> positions; // 3 * N_verts
std::vector<uint32_t> indices; // 3 * N_tris
std::vector<float> tri_normals; // 3 * N_tris (unit, mesh-local)
std::vector<float> tri_areas; // N_tris
// edge_key (min<<32 | max) → list of triangle indices touching it.
std::unordered_map<uint64_t, std::vector<uint32_t>> edges;
};
MeshCache* meshCache(ViewportWindow& vp, uint32_t model_id, uint32_t mesh_id);
// Per-selected-triangle record. The composed transform is captured at
// pick time so the overlay rebuild doesn't have to re-query the
// viewport for it (and so the overlay keeps working if the picked
// instance later goes hidden).
struct SelectedTri {
uint32_t model_id;
uint32_t mesh_id;
uint32_t tri;
float composed_transform[16];
};
// Selection key: object_id (high 32) | tri index (low 32). Packing
// by object_id rather than mesh_id means two distinct instances of
// the same mesh contribute independently, as the user spec'd.
static uint64_t triKey(uint32_t object_id, uint32_t tri) {
return (uint64_t(object_id) << 32) | uint64_t(tri);
}
void rebuildHighlight(ViewportWindow& vp);
std::unordered_map<uint64_t, MeshCache> mesh_cache_;
std::unordered_map<uint64_t, SelectedTri> selected_;
double total_area_m2_ = 0.0;
};
// Click-to-place length / angle / area measurement. Each pick appends a
// world-space point. The readout adapts to the point count:
//
// 1 point → "laser-measure" mode: 6 rays (±surface-normal, ±tangent₁,
// ±tangent₂ in the surface's own basis) trace into the scene.
// On a wall this gives thickness + floor-to-ceiling height +
// length-along-wall in one click. Tangent₁ is world up
// projected onto the surface plane (Gram-Schmidt against the
// normal); tangent₂ = normal × tangent₁.
// 2 points → straight-line distance plus axis-aligned ΔX/ΔY/ΔZ
// 3 points → angle at the middle vertex plus the triangle's area
// 4+ → polygon area: best-fit-plane shoelace if the points are
// near-coplanar (RMS plane distance < 1e-3 of the bounding
// box), else fan-triangulated from the first point
//
// Clicked points are pushed to the viewport overlay as small dots and
// the connecting polyline (or the laser rays for 1-point); readouts
// go to the multi-line HUD.
class LengthMeasurement {
public:
LengthMeasurement();
void onPick(ViewportWindow& vp, int x, int y, bool alt);
void removeLastPoint(ViewportWindow& vp);
void clear(ViewportWindow& vp);
size_t pointCount() const { return points_.size(); }
private:
void rebuildOverlay(ViewportWindow& vp);
void rebuildLaserOverlay(ViewportWindow& vp);
QString formatReadout() const;
std::vector<std::array<float, 3>> points_;
std::vector<std::array<float, 3>> normals_; // surface normal at each pick
// Captured at the very first pick of a fresh sequence and never
// updated afterwards. Used by the 1-pt laser BFS to re-locate the
// mesh-local position of points_[0] without re-picking. Stays valid
// while points_[0] does (pop_back never touches the first element).
ViewportWindow::MeshLocalPick first_pick_{};
};
#endif // IFCINTERFACE_MEASUREMENT_H
+186
View File
@@ -0,0 +1,186 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "SessionState.h"
#include "ElementRegistry.h"
#include "modules/connectors/Registry.h"
#include "../ifcviewer/Federation.h"
#include "../ifcviewer/SceneLoader.h"
namespace bonsaiviewer {
SessionState::SessionState(QObject* parent)
: QObject(parent)
, federation_(new Federation(this))
, element_registry_(new ElementRegistry(this))
, connector_registry_(new modules::connectors::ConnectorRegistry(this))
{
}
void SessionState::createLoader(ViewportWindow* viewport) {
Q_ASSERT(!loader_);
loader_ = new SceneLoader(viewport, this);
loader_->setShouldReadSidecar(true);
loader_->setShouldWriteSidecar(true);
element_registry_->bindLoader(loader_);
auto format_elapsed = [](qint64 ms) {
return (ms >= 1000)
? QString::number(ms / 1000.0, 'f', 2) + " s"
: QString::number(ms) + " ms";
};
// Translate low-level loader events into session-level signals, status
// text, and progress so views don't need to subscribe to the loader.
connect(loader_, &SceneLoader::loadStarted, this,
[this](uint32_t, const QString& display_name) {
setStatusMessage("Loading", display_name);
beginProgress(display_name);
});
connect(loader_, &SceneLoader::progressChanged, this, &SessionState::setProgress);
connect(loader_, &SceneLoader::loadedFromSidecar, this,
[this, format_elapsed](uint32_t mid, qint64 elapsed_ms) {
setStatusMessage("Loaded",
QString("%1 from cache in %2")
.arg(loader_->displayName(mid))
.arg(format_elapsed(elapsed_ms)));
endProgress();
emit modelGeometryReady(mid);
});
connect(loader_, &SceneLoader::loadedFromStream, this,
[this, format_elapsed](uint32_t mid, qint64 elapsed_ms) {
setStatusMessage("Loaded",
QString("%1 streamed in %2")
.arg(loader_->displayName(mid))
.arg(format_elapsed(elapsed_ms)));
endProgress();
emit modelGeometryReady(mid);
});
connect(loader_, &SceneLoader::loadCancelled, this, [this](uint32_t mid) {
setStatusMessage("Cancelled", loader_->displayName(mid));
endProgress();
});
connect(loader_, &SceneLoader::loadError, this,
[this](uint32_t, const QString& message) {
setStatusMessage("Error", message);
endProgress();
emit loadError(message);
});
connect(loader_, &SceneLoader::allLoadsFinished, this, [this]() {
setStatusMessage("Loaded", QString("%1 model(s)").arg(loader_->modelCount()));
});
}
void SessionState::setSelectedObjectId(uint32_t object_id) {
selected_object_id_ = object_id;
}
void SessionState::setStatusMessage(const QString& mode, const QString& detail) {
status_mode_ = mode;
status_detail_ = detail;
emit statusMessageChanged(status_mode_, status_detail_);
}
void SessionState::beginProgress(const QString& label) {
emit progressBegan(label);
}
void SessionState::setProgress(int percent) {
emit progressChanged(percent);
}
void SessionState::endProgress() {
emit progressEnded();
}
void SessionState::setModelMapping(const QString& fed_id, uint32_t model_id) {
fed_id_to_model_id_[fed_id] = model_id;
model_id_to_fed_id_[model_id] = fed_id;
}
void SessionState::removeModelMappingByFedId(const QString& fed_id) {
cloud_metadata_.remove(fed_id);
auto it = fed_id_to_model_id_.find(fed_id);
if (it == fed_id_to_model_id_.end()) return;
model_id_to_fed_id_.remove(it.value());
fed_id_to_model_id_.erase(it);
}
void SessionState::clearModelMappings() {
fed_id_to_model_id_.clear();
model_id_to_fed_id_.clear();
cloud_metadata_.clear();
}
void SessionState::setCloudMetadata(const QString& fed_id, const QVariantMap& metadata) {
if (metadata.isEmpty()) cloud_metadata_.remove(fed_id);
else cloud_metadata_.insert(fed_id, metadata);
}
QVariantMap SessionState::cloudMetadata(const QString& fed_id) const {
return cloud_metadata_.value(fed_id);
}
uint32_t SessionState::modelIdForFedId(const QString& fed_id) const {
return fed_id_to_model_id_.value(fed_id, 0);
}
QString SessionState::fedIdForModelId(uint32_t model_id) const {
return model_id_to_fed_id_.value(model_id);
}
QList<uint32_t> SessionState::modelIds() const {
return model_id_to_fed_id_.keys();
}
void SessionState::notifySelectionChanged() {
emit selectionChanged(selected_object_id_);
}
void SessionState::notifyModelsChanged() {
emit modelsChanged();
}
void SessionState::notifyFederationChanged() {
emit federationChanged();
}
void SessionState::notifyVisibilityChanged() {
emit visibilityChanged();
}
void SessionState::notifyModelGeometryReady(uint32_t model_id) {
emit modelGeometryReady(model_id);
}
void SessionState::notifyProjectOpened(const QString& path) {
emit projectOpened(path);
}
void SessionState::notifyProjectSaved(const QString& path) {
emit projectSaved(path);
}
void SessionState::notifyProjectReset() {
emit projectReset();
}
} // namespace bonsaiviewer
+129
View File
@@ -0,0 +1,129 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_SESSIONSTATE_H
#define IFCINTERFACE_SESSIONSTATE_H
#include <QHash>
#include <QObject>
#include <QString>
#include <QVariantMap>
class Federation;
class SceneLoader;
class ViewportWindow;
namespace bonsaiviewer {
class ElementRegistry;
namespace modules::connectors { class ConnectorRegistry; }
class SessionState : public QObject {
Q_OBJECT
public:
explicit SessionState(QObject* parent = nullptr);
// Owned by SessionState once it can be tied to a viewport. Wires
// loader → element registry signals internally. Call exactly once.
void createLoader(ViewportWindow* viewport);
Federation* federation() const { return federation_; }
SceneLoader* loader() const { return loader_; }
ElementRegistry* elementRegistry() const { return element_registry_; }
modules::connectors::ConnectorRegistry* connectorRegistry() const { return connector_registry_; }
QString statusMode() const { return status_mode_; }
QString statusDetail() const { return status_detail_; }
void setSelectedObjectId(uint32_t object_id);
uint32_t selectedObjectId() const { return selected_object_id_; }
void setStatusMessage(const QString& mode, const QString& detail);
// Generic progress reporting for any long-running operation (load,
// convert, export, ...). Subscribers (the status bar) react to the
// signals; they do not need to know which operation is running.
void beginProgress(const QString& label);
void setProgress(int percent);
void endProgress();
void setModelMapping(const QString& fed_id, uint32_t model_id);
void removeModelMappingByFedId(const QString& fed_id);
void clearModelMappings();
// Per-session cloud metadata returned by connectors (revision/date/
// author/...). Not persisted to the .ifcfed; display only. Lifetime
// is tied to the fed_id — removeModelMappingByFedId and
// clearModelMappings drop the matching entries.
void setCloudMetadata(const QString& fed_id, const QVariantMap& metadata);
QVariantMap cloudMetadata(const QString& fed_id) const;
uint32_t modelIdForFedId(const QString& fed_id) const;
QString fedIdForModelId(uint32_t model_id) const;
QList<uint32_t> modelIds() const;
void notifySelectionChanged();
void notifyModelsChanged();
void notifyFederationChanged();
void notifyVisibilityChanged();
void notifyModelGeometryReady(uint32_t model_id);
void notifyProjectOpened(const QString& path);
void notifyProjectSaved(const QString& path);
void notifyProjectReset();
signals:
void projectOpened(const QString& path);
void projectSaved(const QString& path);
void projectReset();
void modelsChanged();
// Fires whenever a command has mutated the federation (groups, transforms,
// origin, config). Always implies the project is now dirty; callers do not
// emit this on save/load/reset — projectSaved/Opened/Reset cover those.
void federationChanged();
void visibilityChanged();
// Fires when a model's geometry has been pushed to the viewport. Fires
// for both sidecar-cache and stream loads; subscribers that just need to
// re-derive view state (e.g. ViewportView::refresh) listen to this.
void modelGeometryReady(uint32_t model_id);
// Fires when SceneLoader reports a load failure. SessionState turns the
// raw loader signal into a session-level one so views (e.g. the MessageBox)
// can subscribe without touching the loader directly.
void loadError(const QString& message);
void selectionChanged(uint32_t object_id);
void statusMessageChanged(const QString& mode, const QString& detail);
void progressBegan(const QString& label);
void progressChanged(int percent);
void progressEnded();
private:
Federation* federation_ = nullptr;
SceneLoader* loader_ = nullptr;
ElementRegistry* element_registry_ = nullptr;
modules::connectors::ConnectorRegistry* connector_registry_ = nullptr;
uint32_t selected_object_id_ = 0;
QString status_mode_;
QString status_detail_;
QHash<QString, uint32_t> fed_id_to_model_id_;
QHash<uint32_t, QString> model_id_to_fed_id_;
QHash<QString, QVariantMap> cloud_metadata_;
};
} // namespace bonsaiviewer
#endif
+189
View File
@@ -0,0 +1,189 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "ViewerSettings.h"
#include "components/Style.h"
#include <QColor>
#include <QSettings>
namespace {
constexpr const char* kThemeModeKey = "interface/theme/mode";
constexpr const char* kThemeColorPrefix = "interface/theme/colors/";
using Spec = bonsaiviewer::ViewerSettings::ThemeColorSpec;
const std::vector<Spec> kThemeColorSpecs = {
{"app_background", "App Background", bonsaiviewer::components::style::palette::app_background, "#eef1f5"},
{"border", "Border", bonsaiviewer::components::style::palette::border, "#c9d1dc"},
{"selection_background", "Selection Background", bonsaiviewer::components::style::palette::selection_background,
"#2f9e44"},
{"tab_bar_background", "Tab Bar Background", bonsaiviewer::components::style::palette::tab_bar_background,
"#eef1f5"},
{"tab_background", "Tab Background", bonsaiviewer::components::style::palette::tab_background, "#e3e8ef"},
{"ribbon_background", "Ribbon Background", bonsaiviewer::components::style::palette::ribbon_background,
"#e3e8ef"},
{"ribbon_button_hover", "Ribbon Button Hover", bonsaiviewer::components::style::palette::ribbon_button_hover,
"#d6dde7"},
{"ribbon_button_pressed", "Ribbon Button Pressed", bonsaiviewer::components::style::palette::ribbon_button_pressed,
"#cad3df"},
{"viewport_shell_background", "Viewport Shell Background",
bonsaiviewer::components::style::palette::viewport_shell_background, "#dbe1e8"},
{"viewport_background", "Viewport Background", bonsaiviewer::components::style::palette::viewport_background,
"#eef2f6"},
{"panel_background", "Panel Background", bonsaiviewer::components::style::palette::panel_background, "#ffffff"},
{"control_background", "Control Background", bonsaiviewer::components::style::palette::control_background,
"#f5f7fa"},
{"control_border_focus", "Control Border Focus", bonsaiviewer::components::style::palette::control_border_focus,
"#7c8ca3"},
{"box_background", "Box Background", bonsaiviewer::components::style::palette::box_background, "#f5f7fa"},
{"scroll_handle", "Scroll Handle", bonsaiviewer::components::style::palette::scroll_handle, "#b1bac8"},
{"scroll_handle_hover", "Scroll Handle Hover", bonsaiviewer::components::style::palette::scroll_handle_hover,
"#929daf"},
{"status_background", "Status Background", bonsaiviewer::components::style::palette::status_background,
"#edf1f5"},
{"section_header_background", "Section Header Background",
bonsaiviewer::components::style::palette::section_header_background, "#eef2f6"},
{"primary_text", "Primary Text", bonsaiviewer::components::style::palette::primary_text, "#1f2937"},
{"secondary_text", "Secondary Text", bonsaiviewer::components::style::palette::secondary_text, "#5b6676"},
{"disabled_text", "Disabled Text", bonsaiviewer::components::style::palette::disabled_text, "#8b95a3"},
{"warning_text", "Warning Text", bonsaiviewer::components::style::palette::warning_text, "#b26b00"},
{"selection_text", "Selection Text", bonsaiviewer::components::style::palette::selection_text, "#ffffff"},
{"hover_text", "Hover Text", bonsaiviewer::components::style::palette::hover_text, "#0f172a"},
{"icon_color", "Icon Color", "#e7ebf2", "#445066"},
{"icon_active_color", "Icon Active Color", "#ffffff", "#101828"},
{"icon_disabled_color", "Icon Disabled Color", "#6f7988", "#98a2b3"},
{"icon_accent_color", "Accent Icon Color", "#39b54a", "#2f9e44"},
{"icon_accent_active_color", "Accent Icon Active Color", "#53c763", "#267e37"},
};
int colorIndexForKey(const QString& key) {
for (size_t i = 0; i < kThemeColorSpecs.size(); ++i) {
if (QString::fromUtf8(kThemeColorSpecs[i].key) == key) {
return static_cast<int>(i);
}
}
return -1;
}
QString normalizedColor(const QString& value, const QString& fallback) {
const QString trimmed = value.trimmed();
if (!QColor::isValidColorName(trimmed)) return fallback;
return QColor(trimmed).name(QColor::HexRgb);
}
} // namespace
namespace bonsaiviewer {
ViewerSettings& ViewerSettings::instance() {
static ViewerSettings inst;
return inst;
}
const std::vector<ViewerSettings::ThemeColorSpec>& ViewerSettings::themeColorSpecs() {
return kThemeColorSpecs;
}
ViewerSettings::ViewerSettings() {
custom_colors_.resize(kThemeColorSpecs.size());
load();
}
ViewerSettings::ThemeMode ViewerSettings::themeMode() const {
return theme_mode_;
}
void ViewerSettings::setThemeMode(ThemeMode mode) {
if (theme_mode_ == mode) return;
theme_mode_ = mode;
persist();
emit themeModeChanged(mode);
emit themeChanged();
}
QString ViewerSettings::color(const QString& key) const {
const int index = colorIndexForKey(key);
if (index < 0) return {};
const auto& spec = kThemeColorSpecs[static_cast<size_t>(index)];
switch (theme_mode_) {
case ThemeMode::Dark:
return QString::fromUtf8(spec.dark_default);
case ThemeMode::Light:
return QString::fromUtf8(spec.light_default);
case ThemeMode::Custom:
return customColor(key);
}
return QString::fromUtf8(spec.dark_default);
}
QString ViewerSettings::customColor(const QString& key) const {
const int index = colorIndexForKey(key);
if (index < 0) return {};
const auto& spec = kThemeColorSpecs[static_cast<size_t>(index)];
const QString& stored = custom_colors_[static_cast<size_t>(index)];
return stored.isEmpty() ? QString::fromUtf8(spec.dark_default) : stored;
}
void ViewerSettings::setCustomColor(const QString& key, const QString& value) {
const int index = colorIndexForKey(key);
if (index < 0) return;
const auto& spec = kThemeColorSpecs[static_cast<size_t>(index)];
const QString normalized = normalizedColor(value, QString::fromUtf8(spec.dark_default));
QString& stored = custom_colors_[static_cast<size_t>(index)];
if (stored == normalized) return;
stored = normalized;
persist();
if (theme_mode_ == ThemeMode::Custom) {
emit themeChanged();
}
}
void ViewerSettings::load() {
QSettings settings;
int raw_mode = settings.value(kThemeModeKey, static_cast<int>(ThemeMode::Dark)).toInt();
if (raw_mode < static_cast<int>(ThemeMode::Dark) || raw_mode > static_cast<int>(ThemeMode::Custom)) {
raw_mode = static_cast<int>(ThemeMode::Dark);
}
theme_mode_ = static_cast<ThemeMode>(raw_mode);
for (size_t i = 0; i < kThemeColorSpecs.size(); ++i) {
const auto& spec = kThemeColorSpecs[i];
const QString stored = settings.value(QString::fromUtf8(kThemeColorPrefix) + QString::fromUtf8(spec.key),
QString::fromUtf8(spec.dark_default))
.toString();
custom_colors_[i] = normalizedColor(stored, QString::fromUtf8(spec.dark_default));
}
}
void ViewerSettings::persist() const {
QSettings settings;
settings.setValue(kThemeModeKey, static_cast<int>(theme_mode_));
for (size_t i = 0; i < kThemeColorSpecs.size(); ++i) {
settings.setValue(QString::fromUtf8(kThemeColorPrefix) + QString::fromUtf8(kThemeColorSpecs[i].key),
custom_colors_[i]);
}
}
} // namespace bonsaiviewer
+72
View File
@@ -0,0 +1,72 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_INTERFACESETTINGS_H
#define IFCINTERFACE_INTERFACESETTINGS_H
#include <QObject>
#include <QString>
#include <vector>
namespace bonsaiviewer {
class ViewerSettings : public QObject {
Q_OBJECT
public:
enum class ThemeMode {
Dark = 0,
Light = 1,
Custom = 2,
};
Q_ENUM(ThemeMode)
struct ThemeColorSpec {
const char* key;
const char* label;
const char* dark_default;
const char* light_default;
};
static ViewerSettings& instance();
static const std::vector<ThemeColorSpec>& themeColorSpecs();
ThemeMode themeMode() const;
void setThemeMode(ThemeMode mode);
QString color(const QString& key) const;
QString customColor(const QString& key) const;
void setCustomColor(const QString& key, const QString& value);
signals:
void themeModeChanged(ThemeMode mode);
void themeChanged();
private:
ViewerSettings();
void load();
void persist() const;
ThemeMode theme_mode_ = ThemeMode::Dark;
std::vector<QString> custom_colors_;
};
} // namespace bonsaiviewer
#endif
@@ -0,0 +1,50 @@
<!-- This file was generated with the assistance of an AI coding tool. -->
<RCC>
<qresource prefix="/fonts">
<file alias="DMSans-VariableFont_opsz,wght.ttf">../ifctester/webapp/public/fonts/dmsans/DMSans-VariableFont_opsz,wght.ttf</file>
</qresource>
<qresource prefix="/icons">
<file alias="plus-square.svg">icons/plus-square.svg</file>
<file alias="download-square.svg">icons/download-square.svg</file>
<file alias="cloud-square.svg">icons/cloud-square.svg</file>
<file alias="clock-rotate-right.svg">icons/clock-rotate-right.svg</file>
<file alias="floppy-disk.svg">icons/floppy-disk.svg</file>
<file alias="floppy-disk-arrow-in.svg">icons/floppy-disk-arrow-in.svg</file>
<file alias="cube.svg">icons/cube.svg</file>
<file alias="refresh-double.svg">icons/refresh-double.svg</file>
<file alias="settings.svg">icons/settings.svg</file>
<file alias="home.svg">icons/home.svg</file>
<file alias="home-alt.svg">icons/home-alt.svg</file>
<file alias="cube-scan.svg">icons/cube-scan.svg</file>
<file alias="cube-scan-solid.svg">icons/cube-scan-solid.svg</file>
<file alias="planimetry.svg">icons/planimetry.svg</file>
<file alias="city.svg">icons/city.svg</file>
<file alias="building.svg">icons/building.svg</file>
<file alias="cellar.svg">icons/cellar.svg</file>
<file alias="perspective-view.svg">icons/perspective-view.svg</file>
<file alias="drone.svg">icons/drone.svg</file>
<file alias="cube-cut-with-curve.svg">icons/cube-cut-with-curve.svg</file>
<file alias="folder-plus.svg">icons/folder-plus.svg</file>
<file alias="folder-minus.svg">icons/folder-minus.svg</file>
<file alias="folder.svg">icons/folder.svg</file>
<file alias="minus-square.svg">icons/minus-square.svg</file>
<file alias="eye-closed.svg">icons/eye-closed.svg</file>
<file alias="eye.svg">icons/eye.svg</file>
<file alias="eye-solid.svg">icons/eye-solid.svg</file>
<file alias="intersect.svg">icons/intersect.svg</file>
<file alias="select-edge3d.svg">icons/select-edge3d.svg</file>
<file alias="select-face3d.svg">icons/select-face3d.svg</file>
<file alias="select-point3d.svg">icons/select-point3d.svg</file>
<file alias="frame-alt.svg">icons/frame-alt.svg</file>
<file alias="square3d-from-center.svg">icons/square3d-from-center.svg</file>
<file alias="filter.svg">icons/filter.svg</file>
<file alias="cube-dots.svg">icons/cube-dots.svg</file>
<file alias="cursor-pointer.svg">icons/cursor-pointer.svg</file>
<file alias="sidebar-expand.svg">icons/sidebar-expand.svg</file>
<file alias="check.svg">icons/check.svg</file>
<file alias="xmark-circle.svg">icons/xmark-circle.svg</file>
<file alias="database.svg">icons/database.svg</file>
<file alias="database-restore.svg">icons/database-restore.svg</file>
<file alias="cube-bandage.svg">icons/cube-bandage.svg</file>
</qresource>
</RCC>
+77
View File
@@ -0,0 +1,77 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Buttons.h"
#include "SvgIcon.h"
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::components::buttons {
QToolButton* makeButton(const QString& text,
const QString& icon_path,
QWidget* parent) {
auto* button = new QToolButton(parent);
button->setObjectName("ribbonButton");
button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
button->setIcon(components::icons::makeAccentSvgIcon(icon_path));
button->setIconSize(QSize(20, 20));
button->setText(text);
button->setMinimumSize(QSize(90, 68));
button->setAutoRaise(false);
return button;
}
QWidget* makeButtonGroup(const QString& title,
const QList<QToolButton*>& buttons,
QWidget* parent,
bool trailing_separator,
int vertical_spacing) {
auto* group = new QFrame(parent);
group->setObjectName("ribbonGroup");
group->setProperty("separator", trailing_separator);
auto* group_layout = new QVBoxLayout(group);
group_layout->setContentsMargins(8, 6, 8, 4);
group_layout->setSpacing(vertical_spacing);
auto* button_row = new QHBoxLayout();
button_row->setContentsMargins(0, 0, 0, 0);
button_row->setSpacing(4);
for (auto* button : buttons) {
button_row->addWidget(button);
}
auto* label = new QLabel(title, group);
label->setObjectName("ribbonGroupLabel");
label->setProperty("textRole", "secondary");
label->setAlignment(Qt::AlignCenter);
group_layout->addLayout(button_row);
group_layout->addWidget(label);
return group;
}
} // namespace bonsaiviewer::components::buttons
+43
View File
@@ -0,0 +1,43 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_BUTTONS_H
#define IFCINTERFACE_COMPONENTS_BUTTONS_H
#include <QList>
class QToolButton;
class QWidget;
namespace bonsaiviewer::components::buttons {
QToolButton* makeButton(const QString& text,
const QString& icon_path,
QWidget* parent);
QWidget* makeButtonGroup(const QString& title,
const QList<QToolButton*>& buttons,
QWidget* parent,
bool trailing_separator = true,
int vertical_spacing = 4);
} // namespace bonsaiviewer::components::buttons
#endif
+143
View File
@@ -0,0 +1,143 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Dialog.h"
#include "Style.h"
#include "Tabs.h"
#include <QDialog>
#include <QFrame>
#include <QScrollArea>
#include <QVBoxLayout>
namespace bonsaiviewer::components {
Dialog::Dialog(QWidget* parent, bool scrollable)
: QDialog(parent)
{
auto* outer_layout = new QVBoxLayout(this);
outer_layout->setContentsMargins(style::metrics::padding,
style::metrics::padding,
style::metrics::padding,
style::metrics::padding);
outer_layout->setSpacing(0);
auto* frame = new QFrame(this);
frame->setObjectName("panel");
auto* frame_layout = new QVBoxLayout(frame);
frame_layout->setContentsMargins(0,
style::metrics::section_body_padding,
0,
style::metrics::section_body_padding);
frame_layout->setSpacing(0);
auto* scroll = new QScrollArea(frame);
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
auto* scroll_body = new QWidget(scroll);
scroll_body->setObjectName("panelScrollBody");
body_layout_ = new QVBoxLayout(scroll_body);
body_layout_->setContentsMargins(0, 0, 0, 0);
body_layout_->setSpacing(style::metrics::section_body_padding);
body_layout_->setAlignment(Qt::AlignTop);
scroll->setWidget(scroll_body);
frame_layout->addWidget(scroll, scrollable ? 1 : 0);
auto* footer = new QWidget(frame);
footer_layout_ = new QVBoxLayout(footer);
footer_layout_->setContentsMargins(style::metrics::section_body_padding,
style::metrics::section_body_padding,
style::metrics::section_body_padding,
0);
footer_layout_->setSpacing(style::metrics::section_body_padding);
footer_layout_->setAlignment(Qt::AlignTop);
frame_layout->addWidget(footer);
outer_layout->addWidget(frame);
}
void Dialog::addBodyWidget(QWidget* widget) {
body_layout_->addWidget(widget);
}
void Dialog::addFooterWidget(QWidget* widget) {
footer_layout_->addWidget(widget);
}
TabbedDialog::TabbedDialog(QWidget* parent)
: QDialog(parent)
{
auto* outer_layout = new QVBoxLayout(this);
outer_layout->setContentsMargins(style::metrics::padding,
style::metrics::padding,
style::metrics::padding,
style::metrics::padding);
outer_layout->setSpacing(0);
auto* frame = new QFrame(this);
frame->setObjectName("panel");
auto* frame_layout = new QVBoxLayout(frame);
frame_layout->setContentsMargins(0,
style::metrics::section_body_padding,
0,
style::metrics::section_body_padding);
frame_layout->setSpacing(0);
tabs_ = new TabWidget(frame);
frame_layout->addWidget(tabs_, 1);
auto* footer = new QWidget(frame);
footer_layout_ = new QVBoxLayout(footer);
footer_layout_->setContentsMargins(style::metrics::section_body_padding,
style::metrics::section_body_padding,
style::metrics::section_body_padding,
0);
footer_layout_->setSpacing(style::metrics::section_body_padding);
footer_layout_->setAlignment(Qt::AlignTop);
frame_layout->addWidget(footer);
outer_layout->addWidget(frame);
}
void TabbedDialog::addTab(const QString& title, QWidget* widget) {
auto* scroll = new QScrollArea(tabs_);
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
auto* scroll_body = new QWidget(scroll);
scroll_body->setObjectName("panelScrollBody");
auto* layout = new QVBoxLayout(scroll_body);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(style::metrics::section_body_padding);
layout->setAlignment(Qt::AlignTop);
layout->addWidget(widget);
scroll->setWidget(scroll_body);
tabs_->addTab(scroll, title);
}
void TabbedDialog::addFooterWidget(QWidget* widget) {
footer_layout_->addWidget(widget);
}
} // namespace bonsaiviewer::components
+63
View File
@@ -0,0 +1,63 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_DIALOG_H
#define IFCINTERFACE_COMPONENTS_DIALOG_H
#include <QDialog>
class QVBoxLayout;
class QWidget;
class QTabWidget;
namespace bonsaiviewer::components {
class Dialog : public QDialog {
Q_OBJECT
public:
explicit Dialog(QWidget* parent = nullptr,
bool scrollable = false);
void addBodyWidget(QWidget* widget);
void addFooterWidget(QWidget* widget);
private:
QVBoxLayout* body_layout_ = nullptr;
QVBoxLayout* footer_layout_ = nullptr;
};
class TabbedDialog : public QDialog {
Q_OBJECT
public:
explicit TabbedDialog(QWidget* parent = nullptr);
void addTab(const QString& title, QWidget* widget);
void addFooterWidget(QWidget* widget);
private:
QTabWidget* tabs_ = nullptr;
QVBoxLayout* footer_layout_ = nullptr;
};
} // namespace bonsaiviewer::components
#endif
@@ -0,0 +1,72 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "KeyValueTable.h"
#include "SvgIcon.h"
#include <QGridLayout>
#include <QLabel>
namespace bonsaiviewer::components {
KeyValueTable::KeyValueTable(const QList<KeyValueTableRow>& rows, QWidget* parent)
: QWidget(parent)
{
setObjectName("keyValueTable");
auto* layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setHorizontalSpacing(12);
layout->setVerticalSpacing(6);
layout->setColumnStretch(1, 1);
int row_index = 0;
for (const auto& row_data : rows) {
auto* key = new QLabel(row_data.key, this);
key->setProperty("textRole", "secondary");
if (row_data.key_minimum_width > 0) {
key->setMinimumWidth(row_data.key_minimum_width);
}
auto* value = new QLabel(row_data.value, this);
value->setObjectName(row_data.value_object_name.isEmpty()
? "keyValueValueLabel"
: row_data.value_object_name);
value->setWordWrap(true);
value->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
layout->addWidget(key, row_index, 0, Qt::AlignLeft | Qt::AlignTop);
layout->addWidget(value, row_index, 1);
if (!row_data.trailing_icon_path.isEmpty()) {
auto* icon = new QLabel(this);
icon->setObjectName(row_data.trailing_icon_object_name.isEmpty()
? "keyValueTrailingIconLabel"
: row_data.trailing_icon_object_name);
icon->setPixmap(icons::makeSvgPixmap(row_data.trailing_icon_path, QSize(14, 14)));
icon->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
layout->addWidget(icon, row_index, 2, Qt::AlignRight | Qt::AlignTop);
}
++row_index;
}
}
} // namespace bonsaiviewer::components
@@ -0,0 +1,47 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_KEYVALUETABLE_H
#define IFCINTERFACE_COMPONENTS_KEYVALUETABLE_H
#include <QList>
#include <QString>
#include <QWidget>
namespace bonsaiviewer::components {
struct KeyValueTableRow {
QString key;
QString value;
QString value_object_name = "keyValueValueLabel";
QString trailing_icon_path;
QString trailing_icon_object_name;
int key_minimum_width = 0;
};
class KeyValueTable : public QWidget {
Q_OBJECT
public:
explicit KeyValueTable(const QList<KeyValueTableRow>& rows, QWidget* parent = nullptr);
};
} // namespace bonsaiviewer::components
#endif
+140
View File
@@ -0,0 +1,140 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Panel.h"
#include "Style.h"
#include "SvgIcon.h"
#include <QDockWidget>
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QScrollArea>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::components {
namespace {
class DockTitleBar : public QWidget {
public:
explicit DockTitleBar(const QString& title,
bool has_settings = false,
std::function<void()> on_settings = {},
QWidget* parent = nullptr)
: QWidget(parent)
{
auto* layout = new QHBoxLayout(this);
layout->setContentsMargins(10, 6, 6, 6);
layout->setSpacing(6);
auto* text = new QLabel(title.toUpper(), this);
text->setObjectName("panelTitleText");
layout->addWidget(text);
layout->addStretch(1);
if (has_settings) {
auto* settings = new QToolButton(this);
settings->setIcon(icons::makeSvgIcon(":/icons/settings.svg"));
settings->setAutoRaise(true);
settings->setCursor(Qt::ArrowCursor);
settings->setFixedSize(18, 18);
settings->setObjectName("panelTitleButton");
settings->setToolTip(QString("%1 settings").arg(title));
connect(settings, &QToolButton::clicked, this, [on_settings = std::move(on_settings)]() {
if (on_settings) on_settings();
});
layout->addWidget(settings);
}
}
};
} // namespace
Panel::Panel(const QString& title, QWidget* content, QWidget* parent, bool has_settings, bool scrollable)
: QDockWidget(title, parent)
{
auto* outer = new QFrame();
auto* outer_layout = new QVBoxLayout(outer);
outer_layout->setContentsMargins(style::metrics::padding,
style::metrics::padding,
style::metrics::padding,
style::metrics::padding);
outer_layout->setSpacing(0);
auto* frame = new QFrame(outer);
frame->setObjectName("panel");
auto* frame_layout = new QVBoxLayout(frame);
frame_layout->setContentsMargins(0, style::metrics::section_body_padding, 0, style::metrics::section_body_padding);
frame_layout->setSpacing(0);
if (scrollable) {
auto* scroll = new QScrollArea(frame);
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
auto* scroll_body = new QWidget(scroll);
scroll_body->setObjectName("panelScrollBody");
body_layout_ = new QVBoxLayout(scroll_body);
body_layout_->setContentsMargins(0, 0, 0, 0);
body_layout_->setSpacing(style::metrics::section_body_padding);
body_layout_->setAlignment(Qt::AlignTop);
scroll->setWidget(scroll_body);
frame_layout->addWidget(scroll);
} else {
auto* body = new QWidget(frame);
body_layout_ = new QVBoxLayout(body);
body_layout_->setContentsMargins(0, 0, 0, 0);
body_layout_->setSpacing(style::metrics::section_body_padding);
body_layout_->setAlignment(Qt::AlignTop);
frame_layout->addWidget(body);
}
if (content) {
addBodyWidget(content);
}
outer_layout->addWidget(frame);
setObjectName(title);
setFeatures(QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetClosable);
setTitleBarWidget(new DockTitleBar(title, has_settings, [this]() {
emit settingsRequested();
}, this));
setWidget(outer);
}
void Panel::addBodyWidget(QWidget* widget) {
body_layout_->addWidget(widget);
}
void Panel::clearBodyWidgets() {
while (auto* item = body_layout_->takeAt(0)) {
if (auto* widget = item->widget()) widget->deleteLater();
delete item;
}
}
} // namespace bonsaiviewer::components
+53
View File
@@ -0,0 +1,53 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_PANEL_PANELCHROME_H
#define IFCINTERFACE_COMPONENTS_PANEL_PANELCHROME_H
#include <QDockWidget>
class QWidget;
class QVBoxLayout;
namespace bonsaiviewer::components {
class Panel : public QDockWidget {
Q_OBJECT
public:
explicit Panel(const QString& title,
QWidget* content = nullptr,
QWidget* parent = nullptr,
bool has_settings = false,
bool scrollable = false);
void addBodyWidget(QWidget* widget);
void clearBodyWidgets();
signals:
void settingsRequested();
private:
QVBoxLayout* body_layout_ = nullptr;
};
} // namespace bonsaiviewer::components
#endif
+118
View File
@@ -0,0 +1,118 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Section.h"
#include "Style.h"
#include <QFrame>
#include <QHBoxLayout>
#include <QSizePolicy>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::components {
Section::Section(const QString& title, SectionHeaderMode header_mode, QWidget* parent)
: QWidget(parent)
{
setObjectName("panelSection");
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
auto* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(style::metrics::padding);
if (header_mode == SectionHeaderMode::Visible) {
auto* header = new QFrame(this);
header->setObjectName("panelSectionHeader");
header_layout_ = new QHBoxLayout(header);
header_layout_->setContentsMargins(0, 0, 0, 0);
header_layout_->setSpacing(style::metrics::padding);
toggle_button_ = new QToolButton(header);
toggle_button_->setObjectName("panelSectionHeaderButton");
toggle_button_->setText(title);
toggle_button_->setCheckable(true);
toggle_button_->setChecked(true);
toggle_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
toggle_button_->setArrowType(Qt::DownArrow);
header_layout_->addWidget(toggle_button_);
header_layout_->addStretch(1);
layout->addWidget(header);
connect(toggle_button_, &QToolButton::toggled, this, [this](bool expanded) {
toggle_button_->setArrowType(expanded ? Qt::DownArrow : Qt::RightArrow);
body_->setVisible(expanded);
body_->setMaximumHeight(expanded ? QWIDGETSIZE_MAX : 0);
body_->setMinimumHeight(0);
setSizePolicy(QSizePolicy::Preferred,
body_expanding_ && expanded ? QSizePolicy::Expanding : QSizePolicy::Maximum);
updateGeometry();
});
}
body_ = new QWidget(this);
body_->setObjectName("panelSectionBody");
body_layout_ = new QVBoxLayout(body_);
body_layout_->setContentsMargins(style::metrics::section_body_padding,
0,
style::metrics::section_body_padding,
0);
body_layout_->setSpacing(style::metrics::padding);
body_->setMinimumHeight(0);
layout->addWidget(body_);
}
void Section::addBodyWidget(QWidget* widget) {
body_layout_->addWidget(widget);
}
void Section::clearBody() {
while (auto* item = body_layout_->takeAt(0)) {
if (auto* widget = item->widget()) widget->deleteLater();
delete item;
}
}
void Section::addHeaderWidget(QWidget* widget) {
if (!header_layout_) return;
header_layout_->addWidget(widget);
}
bool Section::isExpanded() const {
return !toggle_button_ || toggle_button_->isChecked();
}
void Section::setExpanded(bool expanded) {
if (!toggle_button_) return;
toggle_button_->setChecked(expanded);
}
void Section::setBodyExpanding(bool expanding) {
body_expanding_ = expanding;
body_->setSizePolicy(QSizePolicy::Preferred, expanding ? QSizePolicy::Expanding : QSizePolicy::Preferred);
body_layout_->setStretch(0, expanding ? 1 : 0);
setSizePolicy(QSizePolicy::Preferred,
expanding && isExpanded() ? QSizePolicy::Expanding : QSizePolicy::Maximum);
updateGeometry();
}
} // namespace bonsaiviewer::components
+61
View File
@@ -0,0 +1,61 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_SECTION_H
#define IFCINTERFACE_COMPONENTS_SECTION_H
#include <QWidget>
class QHBoxLayout;
class QToolButton;
class QVBoxLayout;
namespace bonsaiviewer::components {
enum class SectionHeaderMode {
Visible,
Hidden,
};
class Section : public QWidget {
Q_OBJECT
public:
explicit Section(const QString& title,
SectionHeaderMode header_mode = SectionHeaderMode::Visible,
QWidget* parent = nullptr);
void addBodyWidget(QWidget* widget);
void clearBody();
void addHeaderWidget(QWidget* widget);
bool isExpanded() const;
void setExpanded(bool expanded);
void setBodyExpanding(bool expanding);
private:
QWidget* body_ = nullptr;
QVBoxLayout* body_layout_ = nullptr;
QHBoxLayout* header_layout_ = nullptr;
QToolButton* toggle_button_ = nullptr;
bool body_expanding_ = false;
};
} // namespace bonsaiviewer::components
#endif
+497
View File
@@ -0,0 +1,497 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Style.h"
#include "../ViewerSettings.h"
namespace bonsaiviewer::components::style {
QString buildAppStyleSheet() {
const auto& theme = bonsaiviewer::ViewerSettings::instance();
QString stylesheet = QStringLiteral(R"(
QMainWindow#appWindow {
background: ${app_background};
color: ${primary_text};
selection-background-color: ${selection_background};
selection-color: ${selection_text};
}
QDialog#appDialog {
background: ${app_background};
color: ${primary_text};
}
QMessageBox,
QMessageBox QWidget,
QMessageBox QLabel {
background: ${app_background};
color: ${primary_text};
}
QFileDialog,
QFileDialog QWidget,
QFileDialog QStackedWidget,
QFileDialog QSplitter {
background: ${app_background};
color: ${primary_text};
}
QTabBar#appTabBar {
background: ${tab_bar_background};
}
QTabBar#appTabBar::tab {
background: ${tab_background};
color: ${secondary_text};
padding: 8px 14px;
margin-right: 2px;
border-bottom: 2px solid transparent;
}
QTabBar#appTabBar::tab:selected {
color: ${primary_text};
border-bottom: 2px solid ${selection_background};
}
QTabBar#appTabBar::tab:hover {
color: ${hover_text};
}
QFrame#ribbonBand {
background: ${ribbon_background};
border-top: 1px solid ${border};
}
QTabWidget#appTabWidget::pane {
border: none;
background: transparent;
}
QFrame#ribbonPage {
background: transparent;
}
QFrame#ribbonGroup {
background: transparent;
border-right: 1px solid ${border};
}
QFrame#ribbonGroup[separator="false"] {
border-right: none;
}
QLabel#ribbonGroupLabel {
font-size: ${font_small}px;
font-weight: 600;
}
QToolButton#ribbonButton {
background: transparent;
border: none;
padding: 6px 4px 4px 4px;
color: ${primary_text};
}
QToolButton#ribbonButton:hover {
background: ${ribbon_button_hover};
}
QToolButton#ribbonButton:pressed {
background: ${ribbon_button_pressed};
}
QFrame#viewportShell {
background: ${viewport_shell_background};
border-top: none;
}
QFrame#viewportFrame {
border: 1px solid ${border};
}
QDockWidget {
color: ${primary_text};
}
QLabel {
color: ${primary_text};
background: transparent;
}
QAbstractItemView,
QTreeWidget,
QListWidget,
QTableWidget,
QLineEdit,
QComboBox,
QSpinBox,
QDoubleSpinBox,
QCheckBox,
QRadioButton,
QPushButton,
QToolButton {
color: ${primary_text};
}
QLabel[textRole="secondary"] {
color: ${secondary_text};
}
QLabel[textRole="disabled"] {
color: ${disabled_text};
}
QLabel[textRole="warning"] {
color: ${warning_text};
}
QLabel#panelTitleText {
color: ${primary_text};
font-size: ${font_small}px;
font-weight: 600;
}
QToolButton#panelTitleButton {
border: none;
background: transparent;
}
QToolButton#panelTitleButton:hover {
color: ${hover_text};
background: ${ribbon_button_hover};
}
QFrame#panel {
background: ${panel_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
}
QTreeWidget, QListWidget, QTableWidget, QAbstractScrollArea {
background: ${panel_background};
border: none;
outline: none;
gridline-color: ${border};
}
QTableWidget#modelCoordinatesTable {
font-size: ${font_small}px;
}
QTableWidget#modelCoordinatesTable QHeaderView::section {
font-size: ${font_small}px;
}
QTreeWidget::viewport, QListWidget::viewport, QTableWidget::viewport {
background: ${panel_background};
}
QHeaderView::section {
background: ${control_background};
color: ${primary_text};
border: none;
border-bottom: 1px solid ${border};
padding: 7px 8px;
font-weight: 600;
}
QTableCornerButton::section {
background: ${control_background};
border: none;
}
QScrollArea {
background: ${panel_background};
border: none;
}
QScrollArea > QWidget > QWidget {
background: ${panel_background};
}
QLineEdit {
background: ${control_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
padding: ${padding}px ${padding}px;
color: ${primary_text};
}
QLineEdit:focus {
border: 1px solid ${control_border_focus};
}
QComboBox {
background: ${control_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
padding: ${padding}px 24px ${padding}px ${padding}px;
}
QComboBox:focus {
border: 1px solid ${control_border_focus};
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 18px;
border: none;
background: transparent;
}
QComboBox::down-arrow {
width: 0px;
height: 0px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid ${secondary_text};
margin-right: 4px;
}
QComboBox QAbstractItemView {
background: ${panel_background};
border: 1px solid ${border};
selection-background-color: ${selection_background};
selection-color: ${selection_text};
}
QSpinBox, QDoubleSpinBox {
background: ${control_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
padding: ${padding}px 24px ${padding}px ${padding}px;
}
QSpinBox:focus, QDoubleSpinBox:focus {
border: 1px solid ${control_border_focus};
}
QSpinBox::up-button, QDoubleSpinBox::up-button,
QSpinBox::down-button, QDoubleSpinBox::down-button {
subcontrol-origin: padding;
width: 18px;
border: none;
background: transparent;
}
QSpinBox::up-button, QDoubleSpinBox::up-button {
subcontrol-position: top right;
}
QSpinBox::down-button, QDoubleSpinBox::down-button {
subcontrol-position: bottom right;
}
QSpinBox::up-arrow, QDoubleSpinBox::up-arrow {
width: 0px;
height: 0px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 5px solid ${secondary_text};
}
QSpinBox::down-arrow, QDoubleSpinBox::down-arrow {
width: 0px;
height: 0px;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-top: 5px solid ${secondary_text};
}
QCheckBox {
background: transparent;
spacing: 8px;
}
QCheckBox::indicator {
width: 16px;
height: 16px;
border: 1px solid ${border};
border-radius: ${panel_radius}px;
background: ${control_background};
}
QCheckBox::indicator:hover {
background: ${ribbon_button_hover};
}
QCheckBox::indicator:checked {
border: 1px solid ${selection_background};
background: ${selection_background};
}
QRadioButton {
background: transparent;
color: ${primary_text};
spacing: 8px;
padding: 2px 0;
}
QRadioButton::indicator {
width: 16px;
height: 16px;
border: 1px solid ${border};
border-radius: 8px;
background: ${control_background};
}
QRadioButton::indicator:hover {
background: ${ribbon_button_hover};
}
QRadioButton::indicator:checked {
border: 1px solid ${selection_background};
background: ${selection_background};
}
QRadioButton::indicator:unchecked {
background: ${control_background};
}
QPushButton {
background: ${control_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
padding: ${padding}px ${padding}px;
}
QPushButton:hover {
background: ${ribbon_button_hover};
}
QPushButton:pressed {
background: ${ribbon_button_pressed};
}
QMenu {
background: ${panel_background};
color: ${primary_text};
border: 1px solid ${border};
padding: 4px;
}
QMenu::item {
background: transparent;
color: ${primary_text};
padding: 6px 24px 6px 10px;
border-radius: ${panel_radius}px;
}
QMenu::item:selected {
background: ${selection_background};
color: ${selection_text};
}
QMenu::item:disabled {
color: ${disabled_text};
}
QMenu::separator {
height: 1px;
background: ${border};
margin: 4px 8px;
}
QMenu::icon {
padding-left: 2px;
}
QFrame#entityClassBox,
QGroupBox#propertySetBox {
background: ${box_background};
border: 1px solid ${border};
border-radius: ${panel_radius}px;
}
QLabel#entityClassLabel {
color: ${primary_text};
font-weight: 700;
background: transparent;
}
QWidget#keyValueTable {
background: transparent;
}
QTreeView::item, QListView::item, QTableView::item {
padding: 4px;
}
QScrollBar:vertical {
background: transparent;
width: 10px;
margin: 2px 2px 2px 0;
}
QScrollBar:horizontal {
background: transparent;
height: 10px;
margin: 0 2px 2px 2px;
}
QScrollBar::handle:vertical, QScrollBar::handle:horizontal {
background: ${scroll_handle};
border-radius: ${panel_radius}px;
min-height: 24px;
min-width: 24px;
}
QScrollBar::handle:vertical:hover, QScrollBar::handle:horizontal:hover {
background: ${scroll_handle_hover};
}
QScrollBar::add-line, QScrollBar::sub-line,
QScrollBar::add-page, QScrollBar::sub-page {
background: transparent;
border: none;
}
QStatusBar {
background: ${status_background};
}
QStatusBar QLabel {
color: ${secondary_text};
background: transparent;
border: none;
padding: 2px 8px;
}
QGroupBox {
background: transparent;
border: 1px solid ${border};
border-radius: ${panel_radius}px;
margin-top: 10px;
padding-top: 10px;
}
QGroupBox#propertySetBox::title {
subcontrol-origin: margin;
left: ${padding}px;
padding: 0 4px;
color: ${primary_text};
}
QGroupBox#propertySetBox > QWidget {
background: ${box_background};
}
QWidget#panelSection {
background: transparent;
}
QWidget#panelSectionFilterWrapper {
background: transparent;
}
QLabel#keyValueTrailingIconLabel {
background: transparent;
}
QWidget#panelScrollBody {
background: ${panel_background};
}
QFrame#panelSectionHeader {
background: ${section_header_background};
}
QToolButton#panelSectionHeaderButton {
background: transparent;
border: none;
color: ${primary_text};
font-weight: 700;
text-align: left;
padding: ${section_header_padding}px;
margin: 0;
}
QToolButton#panelSectionHeaderButton:hover {
color: ${hover_text};
}
QToolButton#panelSectionHeaderButton::menu-indicator {
image: none;
width: 0;
}
QToolButton#panelSectionFilterToggle {
background: transparent;
border: none;
padding: ${section_header_padding}px;
}
QToolButton#panelSectionFilterToggle:hover {
background: ${ribbon_button_hover};
}
QWidget#panelSectionBody {
background: transparent;
}
QLabel#keyValueValueLabel {
color: ${primary_text};
background: transparent;
}
)");
stylesheet.replace("${panel_radius}", QString::number(metrics::panel_radius));
stylesheet.replace("${padding}", QString::number(metrics::padding));
stylesheet.replace("${section_header_padding}", QString::number(metrics::section_header_padding));
stylesheet.replace("${font_small}", QString::number(typography::small));
stylesheet.replace("${app_background}", theme.color("app_background"));
stylesheet.replace("${border}", theme.color("border"));
stylesheet.replace("${selection_background}", theme.color("selection_background"));
stylesheet.replace("${selection_text}", theme.color("selection_text"));
stylesheet.replace("${tab_bar_background}", theme.color("tab_bar_background"));
stylesheet.replace("${tab_background}", theme.color("tab_background"));
stylesheet.replace("${hover_text}", theme.color("hover_text"));
stylesheet.replace("${ribbon_background}", theme.color("ribbon_background"));
stylesheet.replace("${ribbon_button_hover}", theme.color("ribbon_button_hover"));
stylesheet.replace("${ribbon_button_pressed}", theme.color("ribbon_button_pressed"));
stylesheet.replace("${viewport_shell_background}", theme.color("viewport_shell_background"));
stylesheet.replace("${viewport_background}", theme.color("viewport_background"));
stylesheet.replace("${panel_background}", theme.color("panel_background"));
stylesheet.replace("${control_background}", theme.color("control_background"));
stylesheet.replace("${control_border_focus}", theme.color("control_border_focus"));
stylesheet.replace("${box_background}", theme.color("box_background"));
stylesheet.replace("${scroll_handle}", theme.color("scroll_handle"));
stylesheet.replace("${scroll_handle_hover}", theme.color("scroll_handle_hover"));
stylesheet.replace("${status_background}", theme.color("status_background"));
stylesheet.replace("${section_header_background}", theme.color("section_header_background"));
stylesheet.replace("${primary_text}", theme.color("primary_text"));
stylesheet.replace("${secondary_text}", theme.color("secondary_text"));
stylesheet.replace("${disabled_text}", theme.color("disabled_text"));
stylesheet.replace("${warning_text}", theme.color("warning_text"));
return stylesheet;
}
} // namespace bonsaiviewer::components::style
+77
View File
@@ -0,0 +1,77 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_STYLE_H
#define IFCINTERFACE_COMPONENTS_STYLE_H
#include <QString>
namespace bonsaiviewer::components::style::metrics {
inline constexpr int padding = 6;
inline constexpr int section_body_padding = 10;
inline constexpr int section_header_padding = 2;
inline constexpr int panel_radius = 3;
} // namespace bonsaiviewer::components::style::metrics
namespace bonsaiviewer::components::style::typography {
inline constexpr int small = 10;
} // namespace bonsaiviewer::components::style::typography
namespace bonsaiviewer::components::style::palette {
inline constexpr auto app_background = "#26292f";
inline constexpr auto border = "#3e444e";
inline constexpr auto selection_background = "#39b54a";
inline constexpr auto tab_bar_background = "#26292f";
inline constexpr auto tab_background = "#31353d";
inline constexpr auto ribbon_background = "#31353d";
inline constexpr auto ribbon_button_hover = "#3a3f48";
inline constexpr auto ribbon_button_pressed = "#24282f";
inline constexpr auto viewport_shell_background = "#202329";
inline constexpr auto viewport_background = "#2e3338";
inline constexpr auto panel_background = "#2b2f36";
inline constexpr auto control_background = "#31353d";
inline constexpr auto control_border_focus = "#5b6472";
inline constexpr auto box_background = "#26292f";
inline constexpr auto scroll_handle = "#525a67";
inline constexpr auto scroll_handle_hover = "#697385";
inline constexpr auto status_background = "#26292f";
inline constexpr auto section_header_background = "#26292f";
inline constexpr auto primary_text = "#d0d5dd";
inline constexpr auto secondary_text = "#9aa4b3";
inline constexpr auto disabled_text = "#8f98a6";
inline constexpr auto warning_text = "#e4b35a";
inline constexpr auto selection_text = "#14161a";
inline constexpr auto hover_text = "#ffffff";
} // namespace bonsaiviewer::components::style::palette
namespace bonsaiviewer::components::style {
QString buildAppStyleSheet();
} // namespace bonsaiviewer::components::style
#endif
+86
View File
@@ -0,0 +1,86 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "SvgIcon.h"
#include "../ViewerSettings.h"
#include <QFile>
#include <QPainter>
#include <QRegularExpression>
#include <QSvgRenderer>
namespace bonsaiviewer::components::icons {
QPixmap renderTintedSvgPixmap(const QString& icon_path, const QString& color, const QSize& size) {
QFile file(icon_path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return QIcon(icon_path).pixmap(size);
}
QString svg = QString::fromUtf8(file.readAll());
svg.replace("currentColor", color, Qt::CaseSensitive);
svg.replace(QRegularExpression(R"(stroke="[^"]*")"), QString("stroke=\"%1\"").arg(color));
svg.replace(QRegularExpression(R"(fill="none")"), "fill=\"none\"");
QSvgRenderer renderer(svg.toUtf8());
QPixmap pixmap(size);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
renderer.render(&painter);
return pixmap;
}
QIcon makeTintedSvgIcon(const QString& icon_path, const QString& normal,
const QString& active, const QString& disabled) {
QFile file(icon_path);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
return QIcon(icon_path);
}
QIcon icon;
icon.addPixmap(renderTintedSvgPixmap(icon_path, normal, QSize(20, 20)), QIcon::Normal, QIcon::Off);
icon.addPixmap(renderTintedSvgPixmap(icon_path, active, QSize(20, 20)), QIcon::Active, QIcon::Off);
icon.addPixmap(renderTintedSvgPixmap(icon_path, active, QSize(20, 20)), QIcon::Selected, QIcon::Off);
icon.addPixmap(renderTintedSvgPixmap(icon_path, disabled, QSize(20, 20)), QIcon::Disabled, QIcon::Off);
return icon;
}
QIcon makeAccentSvgIcon(const QString& icon_path) {
const auto& theme = bonsaiviewer::ViewerSettings::instance();
return makeTintedSvgIcon(icon_path,
theme.color("icon_accent_color"),
theme.color("icon_accent_active_color"),
theme.color("icon_disabled_color"));
}
QIcon makeSvgIcon(const QString& icon_path) {
const auto& theme = bonsaiviewer::ViewerSettings::instance();
return makeTintedSvgIcon(icon_path,
theme.color("icon_color"),
theme.color("icon_active_color"),
theme.color("icon_disabled_color"));
}
QPixmap makeSvgPixmap(const QString& icon_path, const QSize& size) {
return renderTintedSvgPixmap(icon_path, bonsaiviewer::ViewerSettings::instance().color("icon_color"), size);
}
} // namespace bonsaiviewer::components::icons
+42
View File
@@ -0,0 +1,42 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_ICONS_SVGICON_H
#define IFCINTERFACE_COMPONENTS_ICONS_SVGICON_H
#include <QIcon>
#include <QPixmap>
#include <QString>
#include <QSize>
namespace bonsaiviewer::components::icons {
QPixmap renderTintedSvgPixmap(const QString& icon_path, const QString& color, const QSize& size);
QIcon makeTintedSvgIcon(const QString& icon_path,
const QString& normal = "#39b54a",
const QString& active = "#53c763",
const QString& disabled = "#6f7988");
QIcon makeAccentSvgIcon(const QString& icon_path);
QIcon makeSvgIcon(const QString& icon_path);
QPixmap makeSvgPixmap(const QString& icon_path, const QSize& size);
} // namespace bonsaiviewer::components::icons
#endif
+40
View File
@@ -0,0 +1,40 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Tabs.h"
namespace bonsaiviewer::components {
TabBar::TabBar(QWidget* parent)
: QTabBar(parent)
{
setObjectName("appTabBar");
setExpanding(false);
setDrawBase(false);
}
TabWidget::TabWidget(QWidget* parent)
: QTabWidget(parent)
{
setObjectName("appTabWidget");
setTabBar(new TabBar(this));
}
} // namespace bonsaiviewer::components
+45
View File
@@ -0,0 +1,45 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_COMPONENTS_TABS_H
#define IFCINTERFACE_COMPONENTS_TABS_H
#include <QTabBar>
#include <QTabWidget>
namespace bonsaiviewer::components {
class TabBar : public QTabBar {
Q_OBJECT
public:
explicit TabBar(QWidget* parent = nullptr);
};
class TabWidget : public QTabWidget {
Q_OBJECT
public:
explicit TabWidget(QWidget* parent = nullptr);
};
} // namespace bonsaiviewer::components
#endif
+8
View File
@@ -0,0 +1,8 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 17C12.5523 17 13 16.5523 13 16C13 15.4477 12.5523 15 12 15C11.4477 15 11 15.4477 11 16C11 16.5523 11.4477 17 12 17Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20.5 16.7222L12.2914 12.1618C12.1102 12.0612 11.8898 12.0612 11.7086 12.1618L3.5 16.7222" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.52844 7.29363L11.7086 11.8382C11.8898 11.9388 12.1102 11.9388 12.2914 11.8382L20.5 7.27783" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 3L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 19.5V22" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

@@ -0,0 +1,8 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 23C12.5523 23 13 22.5523 13 22C13 21.4477 12.5523 21 12 21C11.4477 21 11 21.4477 11 22C11 22.5523 11.4477 23 12 23Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 8C3.55228 8 4 7.55228 4 7C4 6.44772 3.55228 6 3 6C2.44772 6 2 6.44772 2 7C2 7.55228 2.44772 8 3 8Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 18C3.55228 18 4 17.5523 4 17C4 16.4477 3.55228 16 3 16C2.44772 16 2 16.4477 2 17C2 17.5523 2.44772 18 3 18Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.52844 7.29363L11.7086 11.8382C11.8898 11.9388 12.1102 11.9388 12.2914 11.8382L20.5 7.27783" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 21L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

+9
View File
@@ -0,0 +1,9 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 9.01L10.01 8.99889" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 9.01L14.01 8.99889" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10 13.01L10.01 12.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 13.01L14.01 12.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10 17.01L10.01 16.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M14 17.01L14.01 16.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M6 20.4V5.6C6 5.26863 6.26863 5 6.6 5H12V3.6C12 3.26863 12.2686 3 12.6 3H17.4C17.7314 3 18 3.26863 18 3.6V20.4C18 20.7314 17.7314 21 17.4 21H6.6C6.26863 21 6 20.7314 6 20.4Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1005 B

+6
View File
@@ -0,0 +1,6 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 21H21V12C21 9.61305 20.0518 7.32387 18.364 5.63604C16.6761 3.94821 14.3869 3 12 3C9.61305 3 7.32387 3.94821 5.63604 5.63604C3.94821 7.32387 3 9.61305 3 12V21Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 17L21 17" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9 17V13H21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13 13V9H20" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 644 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 12.5L9.5 17L19 7.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 227 B

+9
View File
@@ -0,0 +1,9 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7 9.01L7.01 8.99889" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 9.01L11.01 8.99889" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7 13.01L7.01 12.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 13.01L11.01 12.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7 17.01L7.01 16.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 17.01L11.01 16.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15 21H3.6C3.26863 21 3 20.7314 3 20.4V5.6C3 5.26863 3.26863 5 3.6 5H9V3.6C9 3.26863 9.26863 3 9.6 3H14.4C14.7314 3 15 3.26863 15 3.6V9M15 21H20.4C20.7314 21 21 20.7314 21 20.4V9.6C21 9.26863 20.7314 9 20.4 9H15M15 21V17M15 9V13M15 13H17M15 13V17M15 17H17" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 6L12 12L18 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.8883 10.5C21.1645 5.68874 17.013 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C16.1006 22 19.6248 19.5318 21.1679 16" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17 16H21.4C21.7314 16 22 16.2686 22 16.6V21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 562 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" stroke="currentColor" stroke-width="1.5"/>
<path d="M12 8C8.72727 8 8.72727 10 8.72727 11C7.81818 11 6 11.5 6 13.5C6 15.5 7.81818 16 8.72727 16H15.2727C16.1818 16 18 15.5 18 13.5C18 11.5 16.1818 11 15.2727 11C15.2727 10 15.2727 8 12 8Z" stroke="currentColor" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 556 B

+10
View File
@@ -0,0 +1,10 @@
<!-- This file was generated with the assistance of an AI coding tool. -->
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 7.35304V16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647V7.35304C3 7.13514 3.11814 6.93437 3.30861 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8819 6.93437 21 7.13514 21 7.35304Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.52844 7.29357L11.7086 11.8381C11.8898 11.9388 12.1102 11.9388 12.2914 11.8381L20.5 7.27777" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 21V12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8.5 8.5L15.5 15.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8.5 15.5L15.5 8.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10.5 8.5L8.5 10.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15.5 13.5L13.5 15.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

@@ -0,0 +1,9 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3.52844 7.29346L9 10.3332" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M22 2L20 2M12 12L12 10C12 6.45478 14.3061 3.44817 17.5 2.39838" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M22 12L20 12M12 22L12 20C12 16.4548 14.3061 13.4482 17.5 12.3984" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 22L3.30861 17.1715C3.11813 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L15 3.66667" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 11.9999L3.52842 7.29346" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 21L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15 13.5L15 4" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

+8
View File
@@ -0,0 +1,8 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.4961 19.7165L18.4961 16.2879C18.8077 16.1099 19 15.7785 19 15.4197V9.58032C19 9.22147 18.8077 8.89012 18.4961 8.71208L12.4961 5.28351C12.1887 5.10783 11.8113 5.10783 11.5039 5.28351L5.50386 8.71208C5.19229 8.89012 5 9.22147 5 9.58032V15.4197C5 15.7785 5.19229 16.1099 5.50386 16.2879L11.5039 19.7165C11.8113 19.8922 12.1887 19.8922 12.4961 19.7165Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5.5 9.5L12 13M12 13L18.5 9.5M12 13V19.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 3.01013L3.01 2.99902" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 21.0101L3.01 20.999" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 3.01013L21.01 2.99902" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 21.0101L21.01 20.999" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -0,0 +1,7 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.25 3C2.25 2.58579 2.58579 2.25 3 2.25H6C6.41421 2.25 6.75 2.58579 6.75 3C6.75 3.41421 6.41421 3.75 6 3.75H3.75V6C3.75 6.41421 3.41421 6.75 3 6.75C2.58579 6.75 2.25 6.41421 2.25 6V3Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.25 3C17.25 2.58579 17.5858 2.25 18 2.25H21C21.4142 2.25 21.75 2.58579 21.75 3V6C21.75 6.41421 21.4142 6.75 21 6.75C20.5858 6.75 20.25 6.41421 20.25 6V3.75H18C17.5858 3.75 17.25 3.41421 17.25 3Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 17.25C3.41421 17.25 3.75 17.5858 3.75 18V20.25H6C6.41421 20.25 6.75 20.5858 6.75 21C6.75 21.4142 6.41421 21.75 6 21.75H3C2.58579 21.75 2.25 21.4142 2.25 21V18C2.25 17.5858 2.58579 17.25 3 17.25Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M21 17.25C21.4142 17.25 21.75 17.5858 21.75 18V21C21.75 21.4142 21.4142 21.75 21 21.75H18C17.5858 21.75 17.25 21.4142 17.25 21C17.25 20.5858 17.5858 20.25 18 20.25H20.25V18C20.25 17.5858 20.5858 17.25 21 17.25Z" fill="currentColor"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.9004 6.6654C12.3462 6.33289 11.6538 6.33289 11.0996 6.6654L7.09963 9.0654C6.57252 9.38167 6.25 9.95131 6.25 10.566V14.4336C6.25 15.0483 6.57252 15.618 7.09963 15.9342L11.0996 18.3342C11.6538 18.6668 12.3462 18.6668 12.9004 18.3342L16.9004 15.9342C17.4275 15.618 17.75 15.0483 17.75 14.4336V10.566C17.75 9.95131 17.4275 9.38167 16.9004 9.0654L12.9004 6.6654ZM9.3642 10.6785C9.00209 10.4773 8.5455 10.6078 8.34437 10.9699C8.14324 11.332 8.27373 11.7886 8.63583 11.9898L11.25 13.4418V16.0001C11.25 16.4144 11.5858 16.7501 12 16.7501C12.4142 16.7501 12.75 16.4144 12.75 16.0001V13.4456C12.9152 13.3554 13.1243 13.241 13.3607 13.1115C13.9447 12.7916 14.6961 12.3787 15.3642 12.0077C15.7263 11.8066 15.8568 11.35 15.6557 10.9879C15.4546 10.6257 14.998 10.4952 14.6359 10.6964C13.9716 11.0653 13.223 11.4766 12.6401 11.796C12.3908 11.9325 12.172 12.0521 12.0032 12.1443L9.3642 10.6785Z" fill="currentColor"/>
</svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

+8
View File
@@ -0,0 +1,8 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 3H3V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18 3H21V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M6 21H3V18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18 21H21V18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12.5145 17.6913L16.5145 15.2913C16.8157 15.1106 17 14.7851 17 14.4338V10.5662C17 10.2149 16.8157 9.88942 16.5145 9.7087L12.5145 7.3087C12.1978 7.11869 11.8022 7.11869 11.4855 7.3087L7.4855 9.7087C7.1843 9.88942 7 10.2149 7 10.5662V14.4338C7 14.7851 7.1843 15.1106 7.4855 15.2913L11.4855 17.6913C11.8022 17.8813 12.1978 17.8813 12.5145 17.6913Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7.5 10.5L12 12.9995M12 12.9995C12 12.9995 15.7637 10.9492 16.5 10.5M12 12.9995V17.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.52844 7.29357L11.7086 11.8381C11.8898 11.9388 12.1102 11.9388 12.2914 11.8381L20.5 7.27777" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 21L12 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 834 B

@@ -0,0 +1,3 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.5027 9.96958C20.7073 10.4588 20.6154 12.1941 19.3658 12.5533L13.0605 14.3658L10.1807 20.2606C9.60996 21.4288 7.88499 21.218 7.6124 19.9468L4.67677 6.25646C4.44638 5.18204 5.5121 4.2878 6.53019 4.70126L19.5027 9.96958Z" stroke="currentColor" stroke-width="1.5"/>
</svg>

After

Width:  |  Height:  |  Size: 437 B

@@ -0,0 +1,6 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4 6V12C4 12 4 15 11 15C18 15 18 12 18 12V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 3C18 3 18 6 18 6C18 6 18 9 11 9C4 9 4 6 4 6C4 6 4 3 11 3Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 21C4 21 4 18 4 18V12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 22V16M19 16L22 19M19 16L16 19" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 611 B

+6
View File
@@ -0,0 +1,6 @@
<!-- This file was generated with the assistance of an AI coding tool. -->
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 6.5C5 4.567 8.13401 3 12 3C15.866 3 19 4.567 19 6.5C19 8.433 15.866 10 12 10C8.13401 10 5 8.433 5 6.5Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 6.5V12.5C19 14.433 15.866 16 12 16C8.13401 16 5 14.433 5 12.5V6.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 12.5V17.5C19 19.433 15.866 21 12 21C8.13401 21 5 19.433 5 17.5V12.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 688 B

@@ -0,0 +1,5 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 18L18 18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 6V14M12 14L15.5 10.5M12 14L8.5 10.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" stroke="currentColor" stroke-width="1.5"/>
</svg>

After

Width:  |  Height:  |  Size: 528 B

+11
View File
@@ -0,0 +1,11 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13.463 17H10.537C10.2313 17 9.97446 16.7701 9.9407 16.4663L9.07403 8.66626C9.03454 8.31084 9.31275 8 9.67036 8L14.3296 8C14.6872 8 14.9655 8.31084 14.926 8.66626L14.0593 16.4663C14.0255 16.7701 13.7687 17 13.463 17Z" stroke="currentColor" stroke-linecap="round"/>
<path d="M4.5 7C5.88071 7 7 5.88071 7 4.5C7 3.11929 5.88071 2 4.5 2C3.11929 2 2 3.11929 2 4.5C2 5.88071 3.11929 7 4.5 7Z" stroke="currentColor" stroke-miterlimit="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.5 4.5L9 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.49988 19.5L9.5 15.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.5 4.5L15 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.5 19.5L14.5 15.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.5 22C5.88071 22 7 20.8807 7 19.5C7 18.1193 5.88071 17 4.5 17C3.11929 17 2 18.1193 2 19.5C2 20.8807 3.11929 22 4.5 22Z" stroke="currentColor" stroke-miterlimit="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.5 7C20.8807 7 22 5.88071 22 4.5C22 3.11929 20.8807 2 19.5 2C18.1193 2 17 3.11929 17 4.5C17 5.88071 18.1193 7 19.5 7Z" stroke="currentColor" stroke-miterlimit="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.5 22C20.8807 22 22 20.8807 22 19.5C22 18.1193 20.8807 17 19.5 17C18.1193 17 17 18.1193 17 19.5C17 20.8807 18.1193 22 19.5 22Z" stroke="currentColor" stroke-miterlimit="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

+6
View File
@@ -0,0 +1,6 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19.5 16L17.0248 12.6038" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 17.5V14" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.5 16L6.96895 12.6124" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 8C6.6 16 17.4 16 21 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 532 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 13C6.6 5 17.4 5 21 13" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 17C10.3431 17 9 15.6569 9 14C9 12.3431 10.3431 11 12 11C13.6569 11 15 12.3431 15 14C15 15.6569 13.6569 17 12 17Z" fill="currentColor" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 465 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 13C6.6 5 17.4 5 21 13" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 17C10.3431 17 9 15.6569 9 14C9 12.3431 10.3431 11 12 11C13.6569 11 15 12.3431 15 14C15 15.6569 13.6569 17 12 17Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 426 B

+7
View File
@@ -0,0 +1,7 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 7.77961V15.5763C20 15.7783 19.8983 15.9668 19.7295 16.0778L13.1137 20.4253C13.0388 20.4745 12.954 20.5063 12.8652 20.5184L2.68109 21.9071C2.32083 21.9563 2.00002 21.6762 2.00002 21.3126L2 9.01164C2 8.79805 2.11354 8.60057 2.29813 8.49311L13.087 2.21229C13.3057 2.08493 13.5809 2.10857 13.7747 2.27137L19.7859 7.32017C19.9216 7.43417 20 7.60236 20 7.77961Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2.5 9L12.727 11.922C12.8998 11.9714 13.0857 11.9407 13.2334 11.8384L19.5 7.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13 20.5L13 12" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16.5 14.01L16.51 13.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M22 17.01L22.01 16.9989" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

+3
View File
@@ -0,0 +1,3 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3.99961 3H19.9997C20.552 3 20.9997 3.44764 20.9997 3.99987L20.9999 5.58569C21 5.85097 20.8946 6.10538 20.707 6.29295L14.2925 12.7071C14.105 12.8946 13.9996 13.149 13.9996 13.4142L13.9996 19.7192C13.9996 20.3698 13.3882 20.8472 12.7571 20.6894L10.7571 20.1894C10.3119 20.0781 9.99961 19.6781 9.99961 19.2192L9.99961 13.4142C9.99961 13.149 9.89425 12.8946 9.70672 12.7071L3.2925 6.29289C3.10496 6.10536 2.99961 5.851 2.99961 5.58579V4C2.99961 3.44772 3.44732 3 3.99961 3Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 674 B

@@ -0,0 +1,8 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 7.5V5C3 3.89543 3.89543 3 5 3H16.1716C16.702 3 17.2107 3.21071 17.5858 3.58579L20.4142 6.41421C20.7893 6.78929 21 7.29799 21 7.82843V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V16.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M6 21V17" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18 21V13.6C18 13.2686 17.7314 13 17.4 13H15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 3V8.4C16 8.73137 15.7314 9 15.4 9H13.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8 3V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M1 12H12M12 12L9 9M12 12L9 15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 942 B

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 19V5C3 3.89543 3.89543 3 5 3H16.1716C16.702 3 17.2107 3.21071 17.5858 3.58579L20.4142 6.41421C20.7893 6.78929 21 7.29799 21 7.82843V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19Z" stroke="currentColor" stroke-width="1.5"/>
<path d="M8.6 9H15.4C15.7314 9 16 8.73137 16 8.4V3.6C16 3.26863 15.7314 3 15.4 3H8.6C8.26863 3 8 3.26863 8 3.6V8.4C8 8.73137 8.26863 9 8.6 9Z" stroke="currentColor" stroke-width="1.5"/>
<path d="M6 13.6V21H18V13.6C18 13.2686 17.7314 13 17.4 13H6.6C6.26863 13 6 13.2686 6 13.6Z" stroke="currentColor" stroke-width="1.5"/>
</svg>

After

Width:  |  Height:  |  Size: 691 B

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18 6H20H22" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.4 20H2.6C2.26863 20 2 19.7314 2 19.4V11H21.4C21.7314 11 22 11.2686 22 11.6V19.4C22 19.7314 21.7314 20 21.4 20Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H14" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 632 B

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M18 6H20M22 6H20M20 6V4M20 6V8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21.4 20H2.6C2.26863 20 2 19.7314 2 19.4V11H21.4C21.7314 11 22 11.2686 22 11.6V19.4C22 19.7314 21.7314 20 21.4 20Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H14" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 651 B

+3
View File
@@ -0,0 +1,3 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 11V4.6C2 4.26863 2.26863 4 2.6 4H8.77805C8.92127 4 9.05977 4.05124 9.16852 4.14445L12.3315 6.85555C12.4402 6.94876 12.5787 7 12.722 7H21.4C21.7314 7 22 7.26863 22 7.6V11M2 11V19.4C2 19.7314 2.26863 20 2.6 20H21.4C21.7314 20 22 19.7314 22 19.4V11M2 11H22" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 460 B

+7
View File
@@ -0,0 +1,7 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M6 3L6 21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18 3L18 21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 6L21 6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.6 9H14.4C14.7314 9 15 9.26863 15 9.6V14.4C15 14.7314 14.7314 15 14.4 15H9.6C9.26863 15 9 14.7314 9 14.4V9.6C9 9.26863 9.26863 9 9.6 9Z" fill="currentColor"/>
<path d="M3 18L21 18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 700 B

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10 18V15C10 13.8954 10.8954 13 12 13V13C13.1046 13 14 13.8954 14 15V18" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 8L11.7317 3.13416C11.9006 3.04971 12.0994 3.0497 12.2683 3.13416L22 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 11V19C20 20.1046 19.1046 21 18 21H6C4.89543 21 4 20.1046 4 19V11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 579 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2 8L11.7317 3.13416C11.9006 3.04971 12.0994 3.0497 12.2683 3.13416L22 8" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M20 11V19C20 20.1046 19.1046 21 18 21H6C4.89543 21 4 20.1046 4 19V11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 426 B

+12
View File
@@ -0,0 +1,12 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 13.5V16.5M13.5 21H16.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16.5 9H9.6C9.26863 9 9 9.26863 9 9.6V16.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10.5 21H9.6C9.26863 21 9 20.7314 9 20.4V19.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 19.5V20.4C21 20.7314 20.7314 21 20.4 21H19.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.5 9H20.4C20.7314 9 21 9.26863 21 9.6V10.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 10.5V7.5M7.5 3H10.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7.5 15H14.4C14.7314 15 15 14.7314 15 14.4V7.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4.5 15H3.6C3.26863 15 3 14.7314 3 14.4V13.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 4.5V3.6C3 3.26863 3.26863 3 3.6 3H4.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M13.5 3H14.4C14.7314 3 15 3.26863 15 3.6V4.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 12H12H15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 435 B

@@ -0,0 +1,9 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M1 21L4.14286 3H19.8571L23 21H1Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2 16.5H22" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3 12H21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M4 7.5H20" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 3V21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M8 3.5L6.5 20.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M16 3.5L17.5 20.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 795 B

+10
View File
@@ -0,0 +1,10 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M11 16L11 11L3 11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 8H15V10" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15 18L15 21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 19V21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 3V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 15H15L15 13" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11 9V11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 995 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 12H12M15 12H12M12 12V9M12 12V15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 458 B

@@ -0,0 +1,6 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21.1679 8C19.6247 4.46819 16.1006 2 11.9999 2C6.81459 2 2.55104 5.94668 2.04932 11" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17 8H21.4C21.7314 8 22 7.73137 22 7.4V3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M2.88146 16C4.42458 19.5318 7.94874 22 12.0494 22C17.2347 22 21.4983 18.0533 22 13" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M7.04932 16H2.64932C2.31795 16 2.04932 16.2686 2.04932 16.6V21" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 717 B

+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12 21L12 12" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12.5 11V21C12.5 21.2761 12.2761 21.5 12 21.5C11.7239 21.5 11.5 21.2761 11.5 21V11C11.5 10.7239 11.7239 10.5 12 10.5C12.2761 10.5 12.5 10.7239 12.5 11Z" fill="#000000" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 1020 B

+1
View File
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M3.52844 7.29357L11.7086 11.8381C11.8898 11.9388 12.1102 11.9388 12.2914 11.8381L20.5 7.27777" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M12 21L12 12" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M11.6914 11.8285L3.89139 7.49521C3.49147 7.27304 3 7.56222 3 8.01971V16.647C3 16.8649 3.11813 17.0656 3.30861 17.1715L11.1086 21.5048C11.5085 21.727 12 21.4378 12 20.9803V12.353C12 12.1351 11.8819 11.9344 11.6914 11.8285Z" fill="#000000" stroke="#000000" stroke-width="1.5" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><svg width="24px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000"><path d="M12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11C11.4477 11 11 11.4477 11 12C11 12.5523 11.4477 13 12 13Z" fill="#000000" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path><path d="M21 7.35304L21 16.647C21 16.8649 20.8819 17.0656 20.6914 17.1715L12.2914 21.8381C12.1102 21.9388 11.8898 21.9388 11.7086 21.8381L3.30861 17.1715C3.11814 17.0656 3 16.8649 3 16.647L2.99998 7.35304C2.99998 7.13514 3.11812 6.93437 3.3086 6.82855L11.7086 2.16188C11.8898 2.06121 12.1102 2.06121 12.2914 2.16188L20.6914 6.82855C20.8818 6.93437 21 7.13514 21 7.35304Z" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg>

After

Width:  |  Height:  |  Size: 875 B

+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 15C13.6569 15 15 13.6569 15 12C15 10.3431 13.6569 9 12 9C10.3431 9 9 10.3431 9 12C9 13.6569 10.3431 15 12 15Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19.6224 10.3954L18.5247 7.7448L20 6L18 4L16.2647 5.48295L13.5578 4.36974L12.9353 2H10.981L10.3491 4.40113L7.70441 5.51596L6 4L4 6L5.45337 7.78885L4.3725 10.4463L2 11V13L4.40111 13.6555L5.51575 16.2997L4 18L6 20L7.79116 18.5403L10.397 19.6123L11 22H13L13.6045 19.6132L16.2551 18.5155C16.6969 18.8313 18 20 18 20L20 18L18.5159 16.2494L19.6139 13.598L21.9999 12.9772L22 11L19.6224 10.3954Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 786 B

@@ -0,0 +1,5 @@
<svg width="24" stroke-width="1.5" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M19 21L5 21C3.89543 21 3 20.1046 3 19L3 5C3 3.89543 3.89543 3 5 3L19 3C20.1046 3 21 3.89543 21 5L21 19C21 20.1046 20.1046 21 19 21Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9.5 21V3" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M5.5 10L7.25 12L5.5 14" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 533 B

@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" stroke-width="1.5" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M3 20.4V3.6C3 3.26863 3.26863 3 3.6 3H20.4C20.7314 3 21 3.26863 21 3.6V20.4C21 20.7314 20.7314 21 20.4 21H3.6C3.26863 21 3 20.7314 3 20.4Z" stroke="currentColor"/>
<path d="M12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11C11.4477 11 11 11.4477 11 12C11 12.5523 11.4477 13 12 13Z" fill="currentColor" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 516 B

+5
View File
@@ -0,0 +1,5 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M9 9L15 15" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M15 9L9 15" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 545 B

+81
View File
@@ -0,0 +1,81 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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"
#include "ViewerSettings.h"
#include "components/Style.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QFont>
#include <QFontDatabase>
#include <QSurfaceFormat>
namespace {
void installUiFont() {
const int font_id = QFontDatabase::addApplicationFont(
":/fonts/DMSans-VariableFont_opsz,wght.ttf");
QString family;
if (font_id >= 0) {
const QStringList families = QFontDatabase::applicationFontFamilies(font_id);
if (!families.isEmpty()) {
family = families.front();
}
}
if (!family.isEmpty()) {
QApplication::setFont(QFont(family, 10));
}
}
} // namespace
int main(int argc, char* argv[]) {
QApplication app(argc, argv);
app.setApplicationName("Bonsai Viewer");
app.setOrganizationName("IfcOpenShell");
QSurfaceFormat fmt;
fmt.setVersion(4, 5);
fmt.setProfile(QSurfaceFormat::CoreProfile);
fmt.setDepthBufferSize(24);
fmt.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
fmt.setSamples(4);
QSurfaceFormat::setDefaultFormat(fmt);
QCommandLineParser parser;
parser.setApplicationDescription("Bonsai Viewer — IfcOpenShell IFC viewer");
parser.addHelpOption();
parser.process(app);
installUiFont();
const auto applyStyle = [&app]() {
app.setStyleSheet(bonsaiviewer::components::style::buildAppStyleSheet());
};
applyStyle();
QObject::connect(&bonsaiviewer::ViewerSettings::instance(),
&bonsaiviewer::ViewerSettings::themeChanged,
&app,
applyStyle);
bonsaiviewer::shell::MainWindow window;
window.show();
return app.exec();
}
@@ -0,0 +1,114 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Discovery.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSet>
#include <QStandardPaths>
namespace bonsaiviewer::modules::connectors {
namespace {
QString resolveExec(const QString& exec_field, const QString& folder) {
QString resolved = QDir(folder).absoluteFilePath(exec_field);
#if defined(Q_OS_WIN)
if (!QFileInfo::exists(resolved) && QFileInfo::exists(resolved + ".exe")) {
resolved += ".exe";
}
#endif
return QDir::cleanPath(resolved);
}
bool parseManifest(const QString& folder, ConnectorManifest& out) {
const QString manifest_path = QDir(folder).filePath("connector.json");
QFile file(manifest_path);
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "ifcviewer connectors: cannot read" << manifest_path
<< ":" << file.errorString();
return false;
}
QJsonParseError err{};
const QJsonDocument doc = QJsonDocument::fromJson(file.readAll(), &err);
if (doc.isNull() || !doc.isObject()) {
qWarning() << "ifcviewer connectors: malformed manifest"
<< manifest_path << ":" << err.errorString();
return false;
}
const QJsonObject obj = doc.object();
const QString id = obj.value("id").toString();
const QString name = obj.value("name").toString();
const QString version = obj.value("version").toString();
const QString exec_field = obj.value("exec").toString();
if (id.isEmpty() || name.isEmpty() || exec_field.isEmpty()) {
qWarning() << "ifcviewer connectors: missing required field (id/name/exec) in"
<< manifest_path;
return false;
}
out.id = id;
out.name = name;
out.version = version;
out.folder = QDir::cleanPath(folder);
out.exec_path = resolveExec(exec_field, out.folder);
return true;
}
} // namespace
QString userConnectorsDir() {
// GenericDataLocation maps to the platform's per-user data root:
// Linux -> ~/.local/share
// macOS -> ~/Library/Application Support
// Win -> %APPDATA% (Roaming)
// matching CLOUD_SYNC_PROTOCOL.md's listed locations.
const QString base = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
return QDir(base).filePath("IfcOpenShell/BonsaiViewer/connectors");
}
std::vector<ConnectorManifest> discoverConnectors() {
std::vector<ConnectorManifest> result;
QSet<QString> seen_ids;
QDir dir(userConnectorsDir());
if (!dir.exists()) return result;
const QFileInfoList entries = dir.entryInfoList(
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
for (const QFileInfo& entry : entries) {
if (!QFileInfo(QDir(entry.absoluteFilePath()).filePath("connector.json")).exists()) continue;
ConnectorManifest m;
if (!parseManifest(entry.absoluteFilePath(), m)) continue;
if (seen_ids.contains(m.id)) {
qWarning() << "ifcviewer connectors: duplicate id" << m.id
<< "at" << entry.absoluteFilePath()
<< "ignored (earlier match wins)";
continue;
}
seen_ids.insert(m.id);
result.push_back(std::move(m));
}
return result;
}
} // namespace bonsaiviewer::modules::connectors
@@ -0,0 +1,50 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_CONNECTORS_DISCOVERY_H
#define IFCINTERFACE_MODULES_CONNECTORS_DISCOVERY_H
#include <QString>
#include <vector>
namespace bonsaiviewer::modules::connectors {
struct ConnectorManifest {
QString id; // from connector.json; stable identifier
QString name; // human-readable label
QString version; // informational
QString folder; // directory containing connector.json
QString exec_path; // resolved executable; absolute when possible,
// otherwise a bare name for PATH lookup at launch
};
// Scans the per-user connectors directory per CLOUD_SYNC_PROTOCOL.md.
// First match wins for any given id; duplicates and malformed manifests
// are skipped with a qWarning. Returned in discovery order so first-wins
// is observable to callers.
std::vector<ConnectorManifest> discoverConnectors();
// Per-user connectors directory (platform-specific). Exposed for tests and
// for "open user connectors dir" affordances.
QString userConnectorsDir();
} // namespace bonsaiviewer::modules::connectors
#endif
@@ -0,0 +1,79 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "PickerDialog.h"
#include "../../components/Buttons.h"
#include "../../components/Section.h"
#include "../../components/Style.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::modules::connectors {
ConnectorPickerDialog::ConnectorPickerDialog(const std::vector<ConnectorManifest>& manifests,
const QString& title,
const QString& description,
QWidget* parent)
: components::Dialog(parent)
{
setObjectName("appDialog");
setWindowTitle(title);
setModal(true);
if (auto* root = qobject_cast<QVBoxLayout*>(layout())) {
root->setSizeConstraint(QLayout::SetFixedSize);
}
auto* description_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* description_label = new QLabel(description, description_section);
description_label->setProperty("textRole", "secondary");
description_label->setWordWrap(true);
description_label->setAlignment(Qt::AlignCenter);
description_label->setMinimumWidth((90 * 3) + (components::style::metrics::padding * 2));
description_section->addBodyWidget(description_label);
auto* choices_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* choices = new QWidget(choices_section);
auto* row = new QHBoxLayout(choices);
row->setContentsMargins(0, 0, 0, 0);
row->setSpacing(components::style::metrics::padding);
QList<QToolButton*> buttons;
for (const auto& m : manifests) {
auto* button = components::buttons::makeButton(m.name, ":/icons/cloud-square.svg", choices);
const QString id = m.id;
connect(button, &QToolButton::clicked, this, [this, id]() {
selected_id_ = id;
accept();
});
buttons.push_back(button);
}
row->addWidget(components::buttons::makeButtonGroup("CONNECTORS", buttons, choices, true, 8));
choices_section->addBodyWidget(choices);
addBodyWidget(description_section);
addBodyWidget(choices_section);
}
} // namespace bonsaiviewer::modules::connectors
@@ -0,0 +1,54 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_CONNECTORS_PICKERDIALOG_H
#define IFCINTERFACE_MODULES_CONNECTORS_PICKERDIALOG_H
#include "Discovery.h"
#include "../../components/Dialog.h"
#include <QString>
#include <vector>
namespace bonsaiviewer::modules::connectors {
// Connector chooser, modelled on AddModelDialog: one button per available
// connector. Always shown (even when only one connector is installed), per
// project UX direction.
class ConnectorPickerDialog : public components::Dialog {
Q_OBJECT
public:
// `title` and `description` adapt the dialog to the calling workflow
// (e.g. "Open from Cloud", "Save Model to Cloud").
ConnectorPickerDialog(const std::vector<ConnectorManifest>& manifests,
const QString& title,
const QString& description,
QWidget* parent = nullptr);
QString selectedId() const { return selected_id_; }
private:
QString selected_id_;
};
} // namespace bonsaiviewer::modules::connectors
#endif
@@ -0,0 +1,197 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Process.h"
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
#include <QTimer>
namespace bonsaiviewer::modules::connectors {
namespace {
constexpr int kStartTimeoutMs = 5000;
constexpr int kShutdownTimeoutMs = 3000;
// Reserved out-of-band error codes used by the host (not by the connector).
// JSON-RPC reserves -32000..-32099 for "implementation-defined server
// errors"; we co-opt three for transport failures.
constexpr int kErrLaunchFailed = -32000;
constexpr int kErrShutdown = -32001;
constexpr int kErrProcessExited = -32002;
} // namespace
ConnectorProcess::ConnectorProcess(ConnectorManifest manifest, QObject* parent)
: QObject(parent)
, manifest_(std::move(manifest))
{
}
ConnectorProcess::~ConnectorProcess() {
shutdown();
}
bool ConnectorProcess::isRunning() const {
return process_ && process_->state() != QProcess::NotRunning;
}
bool ConnectorProcess::ensureStarted() {
if (isRunning()) return true;
if (manifest_.exec_path.isEmpty()) {
last_error_ = QString("Connector '%1' has no executable configured.")
.arg(manifest_.id);
return false;
}
process_ = new QProcess(this);
process_->setWorkingDirectory(manifest_.folder);
process_->setProcessChannelMode(QProcess::SeparateChannels);
connect(process_, &QProcess::readyReadStandardOutput,
this, &ConnectorProcess::onReadyReadStdout);
connect(process_, &QProcess::finished,
this, &ConnectorProcess::onProcessFinished);
process_->start(manifest_.exec_path, QStringList{});
if (!process_->waitForStarted(kStartTimeoutMs)) {
last_error_ = QString("Failed to launch connector '%1': %2")
.arg(manifest_.id, process_->errorString());
process_->deleteLater();
process_ = nullptr;
return false;
}
last_error_.clear();
shutting_down_ = false;
return true;
}
void ConnectorProcess::call(const QString& method,
const QJsonValue& params,
ResultHandler on_result,
ErrorHandler on_error) {
if (!ensureStarted()) {
const QString err = last_error_;
// Queue rather than invoke inline so callers see uniform async order
// regardless of whether the launch succeeded.
QTimer::singleShot(0, this, [on_error = std::move(on_error), err]() {
if (on_error) on_error(kErrLaunchFailed, err);
});
return;
}
const QString id = QString::number(next_request_id_++);
pending_.insert(id, Pending{std::move(on_result), std::move(on_error)});
QJsonObject msg;
msg["jsonrpc"] = "2.0";
msg["id"] = id;
msg["method"] = method;
if (!params.isUndefined() && !params.isNull()) {
msg["params"] = params;
}
const QByteArray line = QJsonDocument(msg).toJson(QJsonDocument::Compact) + '\n';
process_->write(line);
}
void ConnectorProcess::shutdown() {
if (!process_) return;
shutting_down_ = true;
if (process_->state() == QProcess::Running) {
process_->closeWriteChannel();
if (!process_->waitForFinished(kShutdownTimeoutMs)) {
qWarning() << "ifcviewer connectors:" << manifest_.id
<< "did not exit within" << kShutdownTimeoutMs
<< "ms after stdin close; killing.";
process_->kill();
process_->waitForFinished(1000);
}
}
failPendingAndClear(kErrShutdown,
QString("Connector '%1' was shut down.").arg(manifest_.id));
process_->deleteLater();
process_ = nullptr;
}
void ConnectorProcess::onReadyReadStdout() {
if (!process_) return;
buffer_.append(process_->readAllStandardOutput());
int newline = buffer_.indexOf('\n');
while (newline >= 0) {
const QByteArray line = buffer_.left(newline);
buffer_.remove(0, newline + 1);
if (!line.isEmpty()) dispatchLine(line);
newline = buffer_.indexOf('\n');
}
}
void ConnectorProcess::onProcessFinished(int exit_code, QProcess::ExitStatus status) {
const bool unexpected = !shutting_down_;
const QString reason = (status == QProcess::CrashExit)
? QString("Connector '%1' crashed (exit %2).").arg(manifest_.id).arg(exit_code)
: QString("Connector '%1' exited (code %2).").arg(manifest_.id).arg(exit_code);
failPendingAndClear(kErrProcessExited, reason);
if (unexpected) emit crashed(reason);
}
void ConnectorProcess::dispatchLine(const QByteArray& line) {
QJsonParseError err{};
const QJsonDocument doc = QJsonDocument::fromJson(line, &err);
if (doc.isNull() || !doc.isObject()) {
qWarning() << "ifcviewer connectors:" << manifest_.id
<< "emitted non-JSON line:" << line << err.errorString();
return;
}
const QJsonObject obj = doc.object();
if (obj.value("jsonrpc").toString() != "2.0") {
qWarning() << "ifcviewer connectors:" << manifest_.id
<< "ignored message missing jsonrpc=2.0:" << line;
return;
}
// Connector echoes our id verbatim (we always send strings), but accept
// numeric ids too in case a connector parses our "0" as an int.
const QString id = obj.value("id").toVariant().toString();
if (!pending_.contains(id)) {
qWarning() << "ifcviewer connectors:" << manifest_.id
<< "ignored response with unknown id:" << id;
return;
}
Pending pending = pending_.take(id);
if (obj.contains("error")) {
const QJsonObject err_obj = obj.value("error").toObject();
const int code = err_obj.value("code").toInt();
const QString message = err_obj.value("message").toString();
if (pending.on_error) pending.on_error(code, message);
} else {
if (pending.on_result) pending.on_result(obj.value("result"));
}
}
void ConnectorProcess::failPendingAndClear(int code, const QString& message) {
QHash<QString, Pending> snapshot;
snapshot.swap(pending_);
for (const auto& p : snapshot) {
if (p.on_error) p.on_error(code, message);
}
}
} // namespace bonsaiviewer::modules::connectors
@@ -0,0 +1,98 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_CONNECTORS_PROCESS_H
#define IFCINTERFACE_MODULES_CONNECTORS_PROCESS_H
#include "Discovery.h"
#include <QByteArray>
#include <QHash>
#include <QJsonValue>
#include <QObject>
#include <QProcess>
#include <QString>
#include <functional>
namespace bonsaiviewer::modules::connectors {
// One running connector subprocess. Owns the QProcess, frames stdio as
// newline-delimited JSON-RPC 2.0, and routes responses back to per-call
// callbacks. Per the protocol, one process per session: launch lazily on
// first call(), keep alive until shutdown().
class ConnectorProcess : public QObject {
Q_OBJECT
public:
using ResultHandler = std::function<void(const QJsonValue& result)>;
using ErrorHandler = std::function<void(int code, const QString& message)>;
explicit ConnectorProcess(ConnectorManifest manifest, QObject* parent = nullptr);
~ConnectorProcess() override;
const ConnectorManifest& manifest() const { return manifest_; }
bool isRunning() const;
QString lastError() const { return last_error_; }
// Lazy-launches the underlying process. Returns false on launch failure;
// the user-facing reason is in lastError().
bool ensureStarted();
// Async JSON-RPC 2.0 call. Exactly one of on_result / on_error fires
// exactly once, on the same thread (queued). Launch failure synthesizes
// an immediate on_error via singleShot so callers see consistent
// async ordering.
void call(const QString& method,
const QJsonValue& params,
ResultHandler on_result,
ErrorHandler on_error);
// Closes stdin and waits a few seconds for clean exit; SIGKILLs on
// timeout. Any in-flight calls fail via on_error. Safe to call when
// not running.
void shutdown();
signals:
// Process exited unexpectedly (not via shutdown()). In-flight calls have
// already been failed via on_error before this fires.
void crashed(const QString& message);
private:
void onReadyReadStdout();
void onProcessFinished(int exit_code, QProcess::ExitStatus status);
void dispatchLine(const QByteArray& line);
void failPendingAndClear(int code, const QString& message);
ConnectorManifest manifest_;
QProcess* process_ = nullptr;
QByteArray buffer_;
QString last_error_;
bool shutting_down_ = false;
quint64 next_request_id_ = 0;
struct Pending {
ResultHandler on_result;
ErrorHandler on_error;
};
QHash<QString, Pending> pending_;
};
} // namespace bonsaiviewer::modules::connectors
#endif
@@ -0,0 +1,109 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Registry.h"
#include "Process.h"
#include <QDebug>
namespace bonsaiviewer::modules::connectors {
ConnectorRegistry::ConnectorRegistry(QObject* parent)
: QObject(parent)
{
}
ConnectorRegistry::~ConnectorRegistry() {
shutdownAll();
}
const std::vector<ConnectorManifest>& ConnectorRegistry::available() {
if (!discovered_) refresh();
return manifests_;
}
void ConnectorRegistry::refresh() {
manifests_ = discoverConnectors();
discovered_ = true;
// Cull processes whose connector is no longer discoverable, or whose
// exec changed under us. Surviving entries keep their running process.
for (auto it = processes_.begin(); it != processes_.end();) {
const QString id = it.key();
ConnectorProcess* p = it.value();
const ConnectorManifest* now = manifestFor(id);
const bool stale = !now || !p ||
p->manifest().exec_path != now->exec_path;
if (stale) {
if (p) {
p->shutdown();
p->deleteLater();
}
it = processes_.erase(it);
} else {
++it;
}
}
}
const ConnectorManifest* ConnectorRegistry::manifestFor(const QString& id) const {
for (const auto& m : manifests_) {
if (m.id == id) return &m;
}
return nullptr;
}
ConnectorProcess* ConnectorRegistry::get(const QString& id) {
if (!discovered_) refresh();
if (auto* existing = processes_.value(id, nullptr)) return existing;
const ConnectorManifest* manifest = manifestFor(id);
if (!manifest) {
last_error_ = QString("Unknown connector '%1'.").arg(id);
return nullptr;
}
auto* proc = new ConnectorProcess(*manifest, this);
if (!proc->ensureStarted()) {
last_error_ = proc->lastError();
delete proc;
return nullptr;
}
last_error_.clear();
processes_.insert(id, proc);
connect(proc, &ConnectorProcess::crashed, this, [this, id](const QString& message) {
qWarning() << "ifcviewer connectors:" << message;
if (auto* p = processes_.take(id)) p->deleteLater();
});
return proc;
}
void ConnectorRegistry::shutdownAll() {
const auto procs = processes_;
processes_.clear();
for (auto it = procs.begin(); it != procs.end(); ++it) {
if (auto* p = it.value()) {
p->shutdown();
p->deleteLater();
}
}
}
} // namespace bonsaiviewer::modules::connectors
@@ -0,0 +1,74 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_CONNECTORS_REGISTRY_H
#define IFCINTERFACE_MODULES_CONNECTORS_REGISTRY_H
#include "Discovery.h"
#include <QHash>
#include <QObject>
#include <QString>
#include <vector>
namespace bonsaiviewer::modules::connectors {
class ConnectorProcess;
// Per-session catalog of available connectors plus their lazily-launched
// subprocesses. One instance lives on SessionState; processes are launched
// on first get() and shut down on ~Registry / shutdownAll().
class ConnectorRegistry : public QObject {
Q_OBJECT
public:
explicit ConnectorRegistry(QObject* parent = nullptr);
~ConnectorRegistry() override;
// Discovered connectors in discovery order. First call triggers a scan;
// call refresh() to force a rescan.
const std::vector<ConnectorManifest>& available();
// Re-scans the filesystem. Live processes for ids that have disappeared
// (or whose exec changed) are shut down; surviving connectors keep their
// running process.
void refresh();
// Returns the manifest for `id`, or nullptr.
const ConnectorManifest* manifestFor(const QString& id) const;
// Lazily-launched process. Returns nullptr if `id` is unknown or launch
// failed; the reason is in lastError().
ConnectorProcess* get(const QString& id);
QString lastError() const { return last_error_; }
// Close stdin on every live connector. Idempotent.
void shutdownAll();
private:
bool discovered_ = false;
std::vector<ConnectorManifest> manifests_;
QHash<QString, ConnectorProcess*> processes_;
QString last_error_;
};
} // namespace bonsaiviewer::modules::connectors
#endif
@@ -0,0 +1,160 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "AddModelDialog.h"
#include "../../components/Dialog.h"
#include "../../components/Buttons.h"
#include "../../components/Section.h"
#include "../../components/Style.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::modules::models {
namespace {
class HoverDescriptionFilter : public QObject {
public:
HoverDescriptionFilter(QLabel* label, QString hover_text, QString default_text)
: label_(label), hover_text_(std::move(hover_text)), default_text_(std::move(default_text)) {}
protected:
bool eventFilter(QObject* watched, QEvent* event) override {
Q_UNUSED(watched);
if (event->type() == QEvent::Enter) {
label_->setText(hover_text_);
} else if (event->type() == QEvent::Leave) {
label_->setText(default_text_);
}
return false;
}
private:
QLabel* label_ = nullptr;
QString hover_text_;
QString default_text_;
};
} // namespace
AddModelDialog::AddModelDialog(QWidget* parent)
: components::Dialog(parent)
{
setObjectName("appDialog");
setWindowTitle("Add Model");
setModal(true);
setupUi();
}
void AddModelDialog::setupUi() {
if (auto* root = qobject_cast<QVBoxLayout*>(layout())) {
root->setSizeConstraint(QLayout::SetFixedSize);
}
const QString default_description = "Choose what to add to the project";
auto* description_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* description = new QLabel(default_description, description_section);
description->setProperty("textRole", "secondary");
description->setWordWrap(true);
description->setAlignment(Qt::AlignCenter);
description->setMinimumWidth((90 * 4) + (components::style::metrics::padding * 3));
description->setMinimumHeight(description->fontMetrics().lineSpacing() * 2 + 4);
description_section->addBodyWidget(description);
auto* choices_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* choices = new QWidget(choices_section);
auto* row = new QHBoxLayout(choices);
row->setContentsMargins(0, 0, 0, 0);
row->setSpacing(components::style::metrics::padding);
auto* add_ifc = components::buttons::makeButton("Add IFC File", ":/icons/cube.svg", choices);
connect(add_ifc, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::IfcFile;
accept();
});
add_ifc->installEventFilter(new HoverDescriptionFilter(
description,
"Add IFC files and load both geometry and data.",
default_description));
auto* add_database = components::buttons::makeButton("Add IFC\nDatabase", ":/icons/database.svg", choices);
connect(add_database, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::IfcDatabase;
accept();
});
add_database->installEventFilter(new HoverDescriptionFilter(
description,
"Add IFC RDB databases for optimised performance",
default_description));
auto* add_geometry = components::buttons::makeButton("Add Geometry", ":/icons/cube-bandage.svg", choices);
connect(add_geometry, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::GeometryOnly;
accept();
});
add_geometry->installEventFilter(new HoverDescriptionFilter(
description,
"Add pure geometry for fast visualisation",
default_description));
auto* add_cloud = components::buttons::makeButton("Add From\nCloud", ":/icons/cloud-square.svg", choices);
connect(add_cloud, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::CloudModel;
accept();
});
add_cloud->installEventFilter(new HoverDescriptionFilter(
description,
"Browse a cloud connector and add one or more models from there.",
default_description));
auto* convert_database = components::buttons::makeButton("Convert IFC File\nto Database", ":/icons/database-restore.svg", choices);
connect(convert_database, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::ConvertToDatabase;
accept();
});
convert_database->installEventFilter(new HoverDescriptionFilter(
description,
"Convert IFC files to databases for smaller filesizes, reduced memory, and faster access. No data is lost.",
default_description));
auto* export_geometry_database = components::buttons::makeButton("Export Geometry\nDatabase", ":/icons/database-restore.svg", choices);
connect(export_geometry_database, &QToolButton::clicked, this, [this]() {
selected_mode_ = SourceMode::ExportGeometryDatabase;
accept();
});
export_geometry_database->installEventFilter(new HoverDescriptionFilter(
description,
"Convert IFC files to a read-only geometry database for smaller filesizes, reduced memory, and faster access. Ideal for cloud read-only coordination workflows. Only parametric geometry editing capabilities are lost.",
default_description));
row->addWidget(components::buttons::makeButtonGroup("ADD", {add_ifc, add_database, add_geometry, add_cloud}, choices, true, 8));
row->addWidget(components::buttons::makeButtonGroup("TOOLS", {convert_database, export_geometry_database}, choices, false, 8));
choices_section->addBodyWidget(choices);
addBodyWidget(description_section);
addBodyWidget(choices_section);
}
} // namespace bonsaiviewer::modules::models
@@ -0,0 +1,53 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_PANELS_ADDMODELDIALOG_H
#define IFCINTERFACE_PANELS_ADDMODELDIALOG_H
#include "../../components/Dialog.h"
namespace bonsaiviewer::modules::models {
enum class SourceMode {
None,
IfcFile,
IfcDatabase,
GeometryOnly,
CloudModel,
ConvertToDatabase,
ExportGeometryDatabase,
};
class AddModelDialog : public components::Dialog {
Q_OBJECT
public:
explicit AddModelDialog(QWidget* parent = nullptr);
SourceMode selectedMode() const { return selected_mode_; }
private:
void setupUi();
SourceMode selected_mode_ = SourceMode::None;
};
} // namespace bonsaiviewer::modules::models
#endif
@@ -0,0 +1,752 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Commands.h"
#include "AddModelDialog.h"
#include "SettingsDialog.h"
#include "../../ElementRegistry.h"
#include "../../SessionState.h"
#include "../connectors/PickerDialog.h"
#include "../connectors/Process.h"
#include "../connectors/Registry.h"
#include "../../../ifcviewer/Federation.h"
#include "../../../ifcviewer/SceneLoader.h"
#include "../../../ifcviewer/SidecarBuilder.h"
#include "../../../ifcviewer/ViewportWindow.h"
#include "../../../ifcgeom/Serializer.h"
#include "../../../serializers/document_serializer_plugin.h"
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QElapsedTimer>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QInputDialog>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QLineEdit>
#include <QListView>
#include <QMessageBox>
#include <QPointer>
#include <QStandardPaths>
#include <QThread>
#include <QTreeView>
#include <QUuid>
#include <QtCore/private/qzipwriter_p.h>
#include <Eigen/Dense>
#include <memory>
namespace bonsaiviewer::modules::models::commands {
namespace {
QString formatElapsed(qint64 ms) {
return (ms >= 1000)
? QString::number(ms / 1000.0, 'f', 2) + " s"
: QString::number(ms) + " ms";
}
} // namespace
void toggleVisibility(SessionState& s, ItemKind kind, const QString& id) {
Federation* fed = s.federation();
if (kind == ItemKind::Group) {
const Federation::Group* group = fed->findGroupById(id);
if (!group) return;
fed->setGroupVisible(id, !group->visible);
s.notifyVisibilityChanged();
s.setStatusMessage("Models", group->visible ? "Group hidden" : "Group shown");
} else {
const Federation::Model* model = fed->findById(id);
if (!model) return;
fed->setModelVisible(id, !model->visible);
s.notifyVisibilityChanged();
s.setStatusMessage("Models", model->visible ? "Model hidden" : "Model shown");
}
}
void addGroup(SessionState& s, QWidget& host, const QString& parent_group_id) {
bool ok = false;
const QString name = QInputDialog::getText(
&host, "New Group", "Group name:", QLineEdit::Normal, "Group", &ok);
if (!ok) return;
const QString trimmed = name.trimmed();
if (trimmed.isEmpty()) return;
s.federation()->addGroup(trimmed, parent_group_id);
s.notifyFederationChanged();
s.setStatusMessage("Models", "Group added");
}
void renameGroup(SessionState& s, QWidget& host, const QString& group_id) {
const Federation::Group* group = s.federation()->findGroupById(group_id);
if (!group) return;
bool ok = false;
const QString name = QInputDialog::getText(
&host, "Rename Group", "Group name:", QLineEdit::Normal, group->display_name, &ok);
if (!ok) return;
const QString trimmed = name.trimmed();
if (trimmed.isEmpty()) return;
s.federation()->setGroupName(group_id, trimmed);
s.notifyFederationChanged();
s.setStatusMessage("Models", "Group renamed");
}
void moveGroup(SessionState& s, const QString& id, const QString& parent_group_id) {
s.federation()->setGroupParent(id, parent_group_id);
s.notifyFederationChanged();
s.setStatusMessage("Models", parent_group_id.isEmpty() ? "Group moved to root" : "Group moved");
}
void moveModels(SessionState& s, const QStringList& ids, const QString& parent_group_id) {
for (const auto& id : ids) {
s.federation()->setModelGroup(id, parent_group_id);
}
s.notifyFederationChanged();
s.setStatusMessage("Models", parent_group_id.isEmpty() ? "Model(s) moved to root" : "Model(s) moved");
}
void removeGroup(SessionState& s, QWidget& host, const QString& group_id) {
const Federation::Group* group = s.federation()->findGroupById(group_id);
if (!group) return;
const auto choice = QMessageBox::question(
&host, "Remove Group",
QString("Remove group '%1'? Models inside it will move to the parent.").arg(group->display_name),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (choice != QMessageBox::Yes) return;
s.federation()->removeGroup(group_id);
s.notifyFederationChanged();
s.setStatusMessage("Models", "Group removed");
}
void removeModel(SessionState& s, ViewportWindow& vp, QWidget& host, const QString& fed_id) {
const Federation::Model* model = s.federation()->findById(fed_id);
const QString label = model ? model->display_name : fed_id;
const auto choice = QMessageBox::question(
&host, "Remove Model",
QString("Remove model '%1' from the federation?").arg(label),
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (choice != QMessageBox::Yes) return;
const uint32_t mid = s.modelIdForFedId(fed_id);
if (mid == 0) {
s.federation()->removeModel(fed_id);
s.notifyFederationChanged();
s.setStatusMessage("Models", "Model removed");
return;
}
if (s.loader()->isLoadingModel(mid)) return;
vp.setSelectedObjectId(0);
s.setSelectedObjectId(0);
s.federation()->removeModel(fed_id);
vp.removeModel(mid);
s.loader()->removeModel(mid);
s.elementRegistry()->removeModel(mid);
s.removeModelMappingByFedId(fed_id);
s.notifySelectionChanged();
s.notifyModelsChanged();
s.setStatusMessage("Models", "Model removed");
}
namespace detail {
void loadModels(SessionState& s, const QStringList& paths, const QStringList& fed_ids) {
if (paths.isEmpty()) return;
const auto ids = s.loader()->addFiles(paths);
for (int i = 0; i < paths.size() && i < static_cast<int>(ids.size()) && i < fed_ids.size(); ++i) {
s.setModelMapping(fed_ids[i], ids[i]);
}
}
} // namespace detail
void addModel(SessionState& s, QWidget& host) {
AddModelDialog dialog(&host);
if (dialog.exec() != QDialog::Accepted) return;
QStringList paths;
switch (dialog.selectedMode()) {
case SourceMode::IfcFile: {
QFileDialog file_dialog(&host, "Add IFC Files");
file_dialog.setFileMode(QFileDialog::ExistingFiles);
file_dialog.setNameFilter("IFC Files (*.ifc);;All Files (*)");
file_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (file_dialog.exec() == QDialog::Accepted) {
paths = file_dialog.selectedFiles();
}
break;
}
case SourceMode::IfcDatabase: {
QFileDialog database_dialog(&host, "Add IFC Databases");
database_dialog.setFileMode(QFileDialog::Directory);
database_dialog.setOption(QFileDialog::ShowDirsOnly, true);
database_dialog.setOption(QFileDialog::DontResolveSymlinks, true);
database_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (auto* list = database_dialog.findChild<QListView*>("listView")) {
list->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
if (auto* tree = database_dialog.findChild<QTreeView*>()) {
tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
if (database_dialog.exec() == QDialog::Accepted) {
paths = database_dialog.selectedFiles();
}
break;
}
case SourceMode::GeometryOnly: {
QFileDialog file_dialog(&host, "Add Geometry Only");
file_dialog.setFileMode(QFileDialog::ExistingFiles);
file_dialog.setNameFilter("IFC Viewer Cache (*.ifcview);;All Files (*)");
file_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (file_dialog.exec() == QDialog::Accepted) {
paths = file_dialog.selectedFiles();
}
break;
}
case SourceMode::CloudModel:
addModelFromCloud(s, host);
return;
case SourceMode::ConvertToDatabase:
convertIfcToDatabase(s, host);
return;
case SourceMode::ExportGeometryDatabase:
exportGeometryDatabase(s, host);
return;
case SourceMode::None:
return;
}
QStringList accepted_paths;
QStringList accepted_fed_ids;
for (const auto& path : paths) {
const QString fed_id = s.federation()->addModel(path);
if (fed_id.isEmpty()) continue;
accepted_paths << path;
accepted_fed_ids << fed_id;
}
detail::loadModels(s, accepted_paths, accepted_fed_ids);
s.notifyModelsChanged();
}
void addModelFromCloud(SessionState& s, QWidget& host) {
auto* registry = s.connectorRegistry();
const auto& manifests = registry->available();
if (manifests.empty()) {
QMessageBox::information(&host, "Add From Cloud",
"No connectors are installed.");
return;
}
modules::connectors::ConnectorPickerDialog picker(
manifests, "Add From Cloud",
"Pick a connector to browse models on.", &host);
if (picker.exec() != QDialog::Accepted) return;
const QString connector_id = picker.selectedId();
if (connector_id.isEmpty()) return;
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Add From Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return;
}
s.setStatusMessage("Cloud", QString("Browsing %1...").arg(connector_id));
QPointer<SessionState> sguard(&s);
proc->call("pull_models_interactive", QJsonValue(),
[sguard, connector_id](const QJsonValue& result) {
if (!sguard) return;
const QJsonArray arr = result.toArray();
QStringList paths;
QStringList fed_ids;
int added = 0;
for (const QJsonValue& v : arr) {
if (v.isNull() || !v.isObject()) continue;
const QJsonObject entry = v.toObject();
const QString display_name = entry.value("display_name").toString();
const QString path = entry.value("path").toString();
if (path.isEmpty()) continue;
const QJsonObject source = entry.value("source").toObject();
QString src_connector = source.value("connector").toString();
if (src_connector.isEmpty()) src_connector = connector_id;
const QString fed_id = sguard->federation()->addCloudModel(
display_name, src_connector, source);
if (fed_id.isEmpty()) continue;
const QJsonObject meta = entry.value("metadata").toObject();
sguard->setCloudMetadata(fed_id, meta.toVariantMap());
paths << path;
fed_ids << fed_id;
++added;
}
if (!paths.isEmpty()) {
detail::loadModels(*sguard, paths, fed_ids);
sguard->notifyModelsChanged();
}
sguard->setStatusMessage("Cloud",
QString("Added %1 model(s) from %2").arg(added).arg(connector_id));
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "pull_models_interactive from" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
}
namespace {
// Shared "local path on disk" lookup for the right-click cloud commands:
// the loader keeps the path keyed by mid (set when a file or pull_models
// path was queued). Both local-sourced and resolved cloud-sourced models
// have one; only un-resolved cloud models (where pull_models hasn't
// returned yet) won't.
QString localPathForModel(SessionState& s, const QString& fed_id) {
const uint32_t mid = s.modelIdForFedId(fed_id);
if (mid == 0 || !s.loader()) return {};
return s.loader()->filePath(mid);
}
} // namespace
void saveModelToCloud(SessionState& s, QWidget& host, const QString& fed_id) {
auto* fed = s.federation();
const Federation::Model* model = fed->findById(fed_id);
if (!model) return;
if (model->source_connector == "local") {
QMessageBox::information(&host, "Save Model To Cloud",
"This model has no cloud target. Use \"Save As To Cloud\" first.");
return;
}
const QString local_path = localPathForModel(s, fed_id);
if (local_path.isEmpty()) {
QMessageBox::warning(&host, "Save Model To Cloud",
"Cannot find a local copy of this model to push.");
return;
}
const QString connector_id = model->source_connector;
auto* registry = s.connectorRegistry();
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Save Model To Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return;
}
QJsonObject source = model->source_data;
source["connector"] = connector_id;
QJsonObject params;
params["path"] = local_path;
params["source"] = source;
s.setStatusMessage("Cloud",
QString("Saving %1 to %2...").arg(model->display_name, connector_id));
QPointer<SessionState> sguard(&s);
proc->call("push_model", params,
[sguard, fed_id, connector_id](const QJsonValue& result) {
if (!sguard) return;
const QJsonObject obj = result.toObject();
const QJsonObject new_source = obj.value("source").toObject();
QString new_connector = new_source.value("connector").toString();
if (new_connector.isEmpty()) new_connector = connector_id;
sguard->federation()->setModelSource(fed_id, new_connector, new_source);
const QJsonObject meta = obj.value("metadata").toObject();
sguard->setCloudMetadata(fed_id, meta.toVariantMap());
sguard->setStatusMessage("Cloud",
QString("Saved to %1").arg(new_connector));
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "push_model to" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
}
void saveModelAsToCloud(SessionState& s, QWidget& host, const QString& fed_id) {
const Federation::Model* model = s.federation()->findById(fed_id);
if (!model) return;
const QString local_path = localPathForModel(s, fed_id);
if (local_path.isEmpty()) {
QMessageBox::warning(&host, "Save Model As To Cloud",
"Cannot find a local copy of this model to push.");
return;
}
auto* registry = s.connectorRegistry();
const auto& manifests = registry->available();
if (manifests.empty()) {
QMessageBox::information(&host, "Save Model As To Cloud",
"No connectors are installed.");
return;
}
modules::connectors::ConnectorPickerDialog picker(
manifests, "Save Model As To Cloud",
QString("Pick a connector to push '%1' to.").arg(model->display_name),
&host);
if (picker.exec() != QDialog::Accepted) return;
const QString connector_id = picker.selectedId();
if (connector_id.isEmpty()) return;
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Save Model As To Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return;
}
QJsonObject params;
params["path"] = local_path;
s.setStatusMessage("Cloud",
QString("Pushing %1 to %2...").arg(model->display_name, connector_id));
QPointer<SessionState> sguard(&s);
proc->call("push_model_interactive", params,
[sguard, fed_id, connector_id](const QJsonValue& result) {
if (!sguard) return;
const QJsonObject obj = result.toObject();
const QJsonObject new_source = obj.value("source").toObject();
QString new_connector = new_source.value("connector").toString();
if (new_connector.isEmpty()) new_connector = connector_id;
sguard->federation()->setModelSource(fed_id, new_connector, new_source);
const QString new_name = obj.value("display_name").toString();
if (!new_name.isEmpty()) {
sguard->federation()->setModelDisplayName(fed_id, new_name);
}
const QJsonObject meta = obj.value("metadata").toObject();
sguard->setCloudMetadata(fed_id, meta.toVariantMap());
sguard->setStatusMessage("Cloud",
QString("Pushed to %1").arg(new_connector));
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "push_model_interactive to" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
}
void convertIfcToDatabase(SessionState& s, QWidget& host) {
QFileDialog input_dialog(&host, "Select IFC File to Convert");
input_dialog.setFileMode(QFileDialog::ExistingFile);
input_dialog.setNameFilter("IFC Files (*.ifc);;All Files (*)");
input_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (input_dialog.exec() != QDialog::Accepted) return;
const QStringList inputs = input_dialog.selectedFiles();
if (inputs.isEmpty()) return;
const QString input_path = inputs.first();
const QFileInfo input_info(input_path);
const QString default_output = input_info.absoluteDir().filePath(input_info.completeBaseName() + ".rdb");
QFileDialog output_dialog(&host, "Save IFC Database As");
output_dialog.setAcceptMode(QFileDialog::AcceptSave);
output_dialog.setFileMode(QFileDialog::AnyFile);
output_dialog.setNameFilter("IFC Database (*.rdb);;All Files (*)");
output_dialog.setDefaultSuffix("rdb");
output_dialog.selectFile(default_output);
output_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
output_dialog.setOption(QFileDialog::DontConfirmOverwrite, true);
if (output_dialog.exec() != QDialog::Accepted) return;
const QStringList outputs = output_dialog.selectedFiles();
if (outputs.isEmpty()) return;
QString output_path = outputs.first();
if (!output_path.endsWith(".rdb", Qt::CaseInsensitive)) {
output_path += ".rdb";
}
const QFileInfo output_info(output_path);
if (output_info.exists()) {
const QString message = QString("'%1' already exists. Overwrite?").arg(output_info.fileName());
if (QMessageBox::question(&host, "Convert IFC to Database", message,
QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) {
return;
}
}
s.beginProgress(QString("Converting %1 to %2…")
.arg(QFileInfo(input_path).fileName(),
QFileInfo(output_path).fileName()));
s.setStatusMessage("Converting",
QString("%1 → %2").arg(QFileInfo(input_path).fileName(), QFileInfo(output_path).fileName()));
auto timer = std::make_shared<QElapsedTimer>();
timer->start();
auto error_message = std::make_shared<QString>();
QThread* thread = QThread::create([input_path, output_path, error_message]() {
try {
ifcopenshell::serializers::document_serializer_context context;
context.file = nullptr;
context.input_filename = input_path.toStdString();
context.output_filename = output_path.toStdString();
context.stream = true;
auto& registry = ifcopenshell::serializers::document_serializer_registry_instance();
const auto* info = registry.find("rdb");
if (!info) {
throw ifcopenshell::exception(
"No 'rdb' document serializer is registered. The RocksDB serializer plugin may not be installed.");
}
if (!info->supports_input_filename) {
throw ifcopenshell::exception("RDB serializer does not support streaming from an input filename");
}
boost::shared_ptr<Serializer> serializer = registry.create("rdb", context);
serializer->finalize();
} catch (const std::exception& e) {
*error_message = QString::fromUtf8(e.what());
} catch (...) {
*error_message = "Unknown error during IFC to RDB conversion";
}
});
QObject::connect(thread, &QThread::finished, &host,
[&s, host_ptr = &host, thread, timer, error_message, input_path, output_path]() {
const qint64 elapsed = timer->elapsed();
s.endProgress();
thread->deleteLater();
if (!error_message->isEmpty()) {
s.setStatusMessage("Error", *error_message);
QMessageBox::warning(host_ptr, "Convert IFC to Database",
QString("Conversion failed:\n%1").arg(*error_message));
return;
}
s.setStatusMessage(
"Converted",
QString("%1 → %2 in %3")
.arg(QFileInfo(input_path).fileName(),
QFileInfo(output_path).fileName(),
formatElapsed(elapsed)));
QMessageBox::information(host_ptr, "Convert IFC to Database",
QString("Database written to:\n%1").arg(output_path));
});
thread->start();
}
void exportGeometryDatabase(SessionState& s, QWidget& host) {
QFileDialog input_dialog(&host, "Select IFC File to Export");
input_dialog.setFileMode(QFileDialog::ExistingFile);
input_dialog.setNameFilter("IFC Files (*.ifc);;All Files (*)");
input_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (input_dialog.exec() != QDialog::Accepted) return;
const QStringList inputs = input_dialog.selectedFiles();
if (inputs.isEmpty()) return;
const QString input_path = inputs.first();
const QFileInfo input_info(input_path);
const QString default_output = input_info.absoluteDir().filePath(input_info.completeBaseName() + ".rdbview");
QFileDialog output_dialog(&host, "Save Geometry Database As");
output_dialog.setAcceptMode(QFileDialog::AcceptSave);
output_dialog.setFileMode(QFileDialog::AnyFile);
output_dialog.setNameFilter("Geometry Database (*.rdbview);;All Files (*)");
output_dialog.setDefaultSuffix("rdbview");
output_dialog.selectFile(default_output);
output_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (output_dialog.exec() != QDialog::Accepted) return;
const QStringList outputs = output_dialog.selectedFiles();
if (outputs.isEmpty()) return;
QString output_path = outputs.first();
if (!output_path.endsWith(".rdbview", Qt::CaseInsensitive)) {
output_path += ".rdbview";
}
s.beginProgress(QString("Exporting %1 to %2…")
.arg(QFileInfo(input_path).fileName(),
QFileInfo(output_path).fileName()));
s.setStatusMessage("Exporting",
QString("%1 → %2").arg(QFileInfo(input_path).fileName(), QFileInfo(output_path).fileName()));
auto timer = std::make_shared<QElapsedTimer>();
timer->start();
auto error_message = std::make_shared<QString>();
QThread* thread = QThread::create([input_path, output_path, error_message]() {
// Scratch dir holds the intermediate .ifcview and .rdb directory
// until they're zipped into the .rdbview. RAII-like cleanup at the
// bottom of this lambda; on early exception we leak it (cheap
// tradeoff to keep the failure log around for the user).
const QString tmp_root = QDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation))
.filePath(QString("ifcviewer-export-%1")
.arg(QUuid::createUuid().toString(QUuid::Id128)));
QDir().mkpath(tmp_root);
const QString tmp_anchor = QDir(tmp_root).filePath("model.ifc");
const QString tmp_sidecar = QDir(tmp_root).filePath("model.ifcview");
const QString tmp_rdb_dir = QDir(tmp_root).filePath("model.rdb");
try {
ifcopenshell::serializers::document_serializer_context context;
context.file = nullptr;
context.input_filename = input_path.toStdString();
context.output_filename = tmp_rdb_dir.toStdString();
context.stream = true;
context.skip_supertypes = { "IfcRepresentationItem" };
auto& registry = ifcopenshell::serializers::document_serializer_registry_instance();
const auto* info = registry.find("rdb");
if (!info) {
throw ifcopenshell::exception(
"No 'rdb' document serializer is registered. The RocksDB serializer plugin may not be installed.");
}
if (!info->supports_input_filename) {
throw ifcopenshell::exception("RDB serializer does not support streaming from an input filename");
}
boost::shared_ptr<Serializer> serializer = registry.create("rdb", context);
serializer->finalize();
serializer.reset();
SidecarBuilder builder;
if (!builder.build(input_path, tmp_anchor)) {
throw ifcopenshell::exception(
("Sidecar build failed: " + builder.lastError()).toStdString());
}
if (!QFileInfo::exists(tmp_sidecar)) {
throw ifcopenshell::exception(
("Sidecar build reported success but " + tmp_sidecar + " is missing").toStdString());
}
// Write to a sibling `.tmp` then rename so a partial file never
// appears at the destination (matters for cloud-sync folders).
const QString tmp_zip = output_path + ".tmp";
QFile::remove(tmp_zip);
{
QZipWriter writer(tmp_zip);
if (writer.status() != QZipWriter::NoError) {
throw ifcopenshell::exception(
("Failed to open " + tmp_zip + " for writing").toStdString());
}
writer.setCompressionPolicy(QZipWriter::AutoCompress);
{
QFile sf(tmp_sidecar);
if (!sf.open(QIODevice::ReadOnly)) {
throw ifcopenshell::exception(
("Failed to read sidecar " + tmp_sidecar).toStdString());
}
writer.addFile("model.ifcview", sf.readAll());
}
QDirIterator it(tmp_rdb_dir, QDir::Files | QDir::NoDotAndDotDot,
QDirIterator::Subdirectories);
const QDir rdb_root(tmp_rdb_dir);
while (it.hasNext()) {
const QString file_path = it.next();
const QString rel = rdb_root.relativeFilePath(file_path);
QFile f(file_path);
if (!f.open(QIODevice::ReadOnly)) {
throw ifcopenshell::exception(
("Failed to read " + file_path + " for zip").toStdString());
}
writer.addFile(QString("model.rdb/%1").arg(rel), f.readAll());
}
writer.close();
if (writer.status() != QZipWriter::NoError) {
throw ifcopenshell::exception(
("Failed to finalize " + tmp_zip).toStdString());
}
}
QFile::remove(output_path);
if (!QFile::rename(tmp_zip, output_path)) {
QFile::remove(tmp_zip);
throw ifcopenshell::exception(
("Failed to move " + tmp_zip + " to " + output_path).toStdString());
}
} catch (const std::exception& e) {
*error_message = QString::fromUtf8(e.what());
} catch (...) {
*error_message = "Unknown error during geometry database export";
}
QDir(tmp_root).removeRecursively();
});
QObject::connect(thread, &QThread::finished, &host,
[&s, host_ptr = &host, thread, timer, error_message, input_path, output_path]() {
const qint64 elapsed = timer->elapsed();
s.endProgress();
thread->deleteLater();
if (!error_message->isEmpty()) {
s.setStatusMessage("Error", *error_message);
QMessageBox::warning(host_ptr, "Export Geometry Database",
QString("Export failed:\n%1").arg(*error_message));
return;
}
s.setStatusMessage(
"Exported",
QString("%1 → %2 in %3")
.arg(QFileInfo(input_path).fileName(),
QFileInfo(output_path).fileName(),
formatElapsed(elapsed)));
QMessageBox::information(host_ptr, "Export Geometry Database",
QString("Geometry database written to:\n%1").arg(output_path));
});
thread->start();
}
void openSettings(SessionState& s, QWidget& host) {
SettingsDialog dialog(&s, &host);
dialog.exec();
}
} // namespace bonsaiviewer::modules::models::commands
@@ -0,0 +1,72 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_MODELS_COMMANDS_H
#define IFCINTERFACE_MODULES_MODELS_COMMANDS_H
#include "Types.h"
#include <QString>
#include <QStringList>
#include <cstdint>
class QWidget;
class ViewportWindow;
namespace bonsaiviewer { class SessionState; }
namespace bonsaiviewer::modules::models::commands {
// User-facing commands. Each one is responsible for emitting any notify()
// signals exactly once, at the end of its execution.
void toggleVisibility(SessionState& s, ItemKind kind, const QString& id);
void addGroup(SessionState& s, QWidget& host, const QString& parent_group_id);
void renameGroup(SessionState& s, QWidget& host, const QString& group_id);
void moveGroup(SessionState& s, const QString& id, const QString& parent_group_id);
void moveModels(SessionState& s, const QStringList& ids, const QString& parent_group_id);
void removeGroup(SessionState& s, QWidget& host, const QString& group_id);
void removeModel(SessionState& s, ViewportWindow& vp, QWidget& host, const QString& fed_id);
void addModel(SessionState& s, QWidget& host);
// Connector picker → pull_models_interactive → addCloudModel + load.
// Reachable from AddModelDialog's CloudModel button; the underlying call
// is async, so addModelFromCloud returns immediately after kicking it off.
void addModelFromCloud(SessionState& s, QWidget& host);
// push_model: push a cloud-sourced model back to its existing target.
// Only valid when model.source_connector != "local". Async.
void saveModelToCloud(SessionState& s, QWidget& host, const QString& fed_id);
// push_model_interactive: pick a connector and push to a fresh cloud
// target. Valid for any model (local or already cloud-sourced). Async.
void saveModelAsToCloud(SessionState& s, QWidget& host, const QString& fed_id);
void convertIfcToDatabase(SessionState& s, QWidget& host);
void exportGeometryDatabase(SessionState& s, QWidget& host);
void openSettings(SessionState& s, QWidget& host);
// Internal building blocks shared by commands here and by ProjectController.
// These NEVER call notify*() — the caller is responsible for emitting once
// at the end of its execution.
namespace detail {
// Queues already-federated models on the loader and maps their fed-ids to mids.
void loadModels(SessionState& s, const QStringList& paths, const QStringList& fed_ids);
} // namespace detail
} // namespace bonsaiviewer::modules::models::commands
#endif
@@ -0,0 +1,274 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "FederationItemModel.h"
#include "../../ViewerSettings.h"
#include "../../components/SvgIcon.h"
#include "../../../ifcviewer/Federation.h"
#include <QBrush>
#include <QColor>
namespace bonsaiviewer::modules::models {
namespace {
QStandardItem* siblingVisibilityItem(QStandardItem* name_item) {
QStandardItem* parent = name_item->parent();
if (!parent) parent = name_item->model()->invisibleRootItem();
return parent->child(name_item->row(), 1);
}
template <typename F>
void walkSubtree(QStandardItem* root, F visit) {
visit(root);
for (int i = 0; i < root->rowCount(); ++i) {
walkSubtree(root->child(i, 0), visit);
}
}
} // namespace
FederationItemModel::FederationItemModel(Federation* federation, QObject* parent)
: QStandardItemModel(parent)
, federation_(federation)
{
setColumnCount(2);
rebuildAll();
connect(federation_, &Federation::groupAdded, this, &FederationItemModel::onGroupAdded);
connect(federation_, &Federation::groupRemoved, this, &FederationItemModel::onGroupRemoved);
connect(federation_, &Federation::groupChanged, this, &FederationItemModel::onGroupChanged);
connect(federation_, &Federation::groupVisibilityChanged, this, &FederationItemModel::onGroupVisibilityChanged);
connect(federation_, &Federation::modelAdded, this, &FederationItemModel::onModelAdded);
connect(federation_, &Federation::modelRemoved, this, &FederationItemModel::onModelRemoved);
connect(federation_, &Federation::modelVisibilityChanged, this, &FederationItemModel::onModelVisibilityChanged);
connect(federation_, &Federation::modelGroupChanged, this, &FederationItemModel::onModelGroupChanged);
connect(federation_, &Federation::modelChanged, this, &FederationItemModel::onModelChanged);
}
void FederationItemModel::rebuildAll() {
clear();
setColumnCount(2);
id_to_name_item_.clear();
for (const auto& root_group : federation_->rootGroups()) {
appendGroupSubtreeTo(invisibleRootItem(), root_group->id);
}
for (const auto& model : federation_->models()) {
if (!model.group_id.isEmpty()) continue;
appendModelTo(invisibleRootItem(), model.id);
}
}
QStandardItem* FederationItemModel::makeGroupNameItem(const QString& group_id, const QString& display_name) const {
auto* item = new QStandardItem(components::icons::makeSvgIcon(":/icons/folder.svg"), display_name);
item->setData(group_id, IdRole);
item->setData(int(ItemKind::Group), KindRole);
item->setEditable(false);
return item;
}
QStandardItem* FederationItemModel::makeModelNameItem(const QString& fed_id, const QString& display_name) const {
auto* item = new QStandardItem(components::icons::makeSvgIcon(":/icons/cube.svg"), display_name);
item->setData(fed_id, IdRole);
item->setData(int(ItemKind::Model), KindRole);
item->setEditable(false);
return item;
}
QStandardItem* FederationItemModel::makeVisibilityItem(ItemKind kind, bool visible) const {
QString icon_path;
if (kind == ItemKind::Group) {
icon_path = visible ? ":/icons/eye.svg" : ":/icons/eye-closed.svg";
} else {
icon_path = visible ? ":/icons/eye-solid.svg" : ":/icons/eye-closed.svg";
}
auto* item = new QStandardItem(components::icons::makeSvgIcon(icon_path), QString());
item->setEditable(false);
return item;
}
void FederationItemModel::styleRowVisibility(QStandardItem* name_item, bool visible) const {
QStandardItem* vis_item = siblingVisibilityItem(name_item);
if (visible) {
name_item->setData(QVariant(), Qt::ForegroundRole);
if (vis_item) vis_item->setData(QVariant(), Qt::ForegroundRole);
} else {
const QBrush disabled(QColor(bonsaiviewer::ViewerSettings::instance().color("disabled_text")));
name_item->setForeground(disabled);
if (vis_item) vis_item->setForeground(disabled);
}
}
QStandardItem* FederationItemModel::findItem(const QString& id) const {
return id_to_name_item_.value(id, nullptr);
}
QStandardItem* FederationItemModel::parentItemForGroup(const QString& parent_group_id) const {
if (parent_group_id.isEmpty()) return invisibleRootItem();
QStandardItem* found = findItem(parent_group_id);
return found ? found : invisibleRootItem();
}
void FederationItemModel::appendModelTo(QStandardItem* parent_item, const QString& fed_id) {
const Federation::Model* model = federation_->findById(fed_id);
if (!model) return;
auto* name_item = makeModelNameItem(fed_id, model->display_name);
auto* vis_item = makeVisibilityItem(ItemKind::Model, federation_->isModelEffectivelyVisible(fed_id));
parent_item->appendRow({name_item, vis_item});
id_to_name_item_.insert(fed_id, name_item);
styleRowVisibility(name_item, federation_->isModelEffectivelyVisible(fed_id));
}
void FederationItemModel::appendGroupSubtreeTo(QStandardItem* parent_item, const QString& group_id) {
const Federation::Group* group = federation_->findGroupById(group_id);
if (!group) return;
auto* name_item = makeGroupNameItem(group_id, group->display_name);
auto* vis_item = makeVisibilityItem(ItemKind::Group, group->visible);
parent_item->appendRow({name_item, vis_item});
id_to_name_item_.insert(group_id, name_item);
styleRowVisibility(name_item, group->visible);
for (const auto& child : group->children) {
appendGroupSubtreeTo(name_item, child->id);
}
for (const auto& model : federation_->models()) {
if (model.group_id != group_id) continue;
appendModelTo(name_item, model.id);
}
}
void FederationItemModel::refreshSubtreeVisibility(QStandardItem* root) {
walkSubtree(root, [this](QStandardItem* item) {
const QString id = item->data(IdRole).toString();
if (id.isEmpty()) return;
const auto kind = static_cast<ItemKind>(item->data(KindRole).toInt());
bool visible = true;
if (kind == ItemKind::Group) {
const Federation::Group* g = federation_->findGroupById(id);
visible = g && g->visible;
} else {
visible = federation_->isModelEffectivelyVisible(id);
}
QStandardItem* vis_item = siblingVisibilityItem(item);
if (vis_item) {
const QString icon_path = (kind == ItemKind::Group)
? (visible ? ":/icons/eye.svg" : ":/icons/eye-closed.svg")
: (visible ? ":/icons/eye-solid.svg" : ":/icons/eye-closed.svg");
vis_item->setIcon(components::icons::makeSvgIcon(icon_path));
}
styleRowVisibility(item, visible);
});
}
void FederationItemModel::onGroupAdded(const QString& group_id) {
const Federation::Group* group = federation_->findGroupById(group_id);
if (!group) return;
QStandardItem* parent_item = parentItemForGroup(group->parent ? group->parent->id : QString());
appendGroupSubtreeTo(parent_item, group_id);
}
void FederationItemModel::onGroupRemoved(const QString& group_id) {
QStandardItem* item = findItem(group_id);
if (!item) return;
walkSubtree(item, [this](QStandardItem* descendant) {
const QString id = descendant->data(IdRole).toString();
if (!id.isEmpty()) id_to_name_item_.remove(id);
});
QStandardItem* parent_item = item->parent();
if (!parent_item) parent_item = invisibleRootItem();
parent_item->removeRow(item->row());
}
void FederationItemModel::onGroupChanged(const QString& group_id) {
QStandardItem* item = findItem(group_id);
if (!item) return;
const Federation::Group* group = federation_->findGroupById(group_id);
if (!group) return;
QStandardItem* current_parent = item->parent();
if (!current_parent) current_parent = invisibleRootItem();
QStandardItem* target_parent = parentItemForGroup(group->parent ? group->parent->id : QString());
if (current_parent == target_parent) {
item->setText(group->display_name);
return;
}
// Reparent: take row from current parent, append at target. Pointers
// survive — id_to_name_item_ entries remain valid.
QList<QStandardItem*> taken = current_parent->takeRow(item->row());
taken.first()->setText(group->display_name);
target_parent->appendRow(taken);
refreshSubtreeVisibility(taken.first());
}
void FederationItemModel::onGroupVisibilityChanged(const QString& group_id, bool /*visible*/) {
QStandardItem* item = findItem(group_id);
if (!item) return;
refreshSubtreeVisibility(item);
}
void FederationItemModel::onModelAdded(const QString& fed_id) {
const Federation::Model* model = federation_->findById(fed_id);
if (!model) return;
QStandardItem* parent_item = parentItemForGroup(model->group_id);
appendModelTo(parent_item, fed_id);
}
void FederationItemModel::onModelRemoved(const QString& fed_id) {
QStandardItem* item = findItem(fed_id);
if (!item) return;
id_to_name_item_.remove(fed_id);
QStandardItem* parent_item = item->parent();
if (!parent_item) parent_item = invisibleRootItem();
parent_item->removeRow(item->row());
}
void FederationItemModel::onModelVisibilityChanged(const QString& fed_id, bool /*visible*/) {
QStandardItem* item = findItem(fed_id);
if (!item) return;
refreshSubtreeVisibility(item);
}
void FederationItemModel::onModelChanged(const QString& fed_id) {
QStandardItem* item = findItem(fed_id);
if (!item) return;
const Federation::Model* model = federation_->findById(fed_id);
if (!model) return;
item->setText(model->display_name);
}
void FederationItemModel::onModelGroupChanged(const QString& fed_id, const QString& new_group_id) {
QStandardItem* item = findItem(fed_id);
if (!item) return;
QStandardItem* current_parent = item->parent();
if (!current_parent) current_parent = invisibleRootItem();
QStandardItem* target_parent = parentItemForGroup(new_group_id);
if (current_parent == target_parent) return;
QList<QStandardItem*> taken = current_parent->takeRow(item->row());
target_parent->appendRow(taken);
refreshSubtreeVisibility(taken.first());
}
} // namespace bonsaiviewer::modules::models
@@ -0,0 +1,86 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_MODELS_FEDERATIONITEMMODEL_H
#define IFCINTERFACE_MODULES_MODELS_FEDERATIONITEMMODEL_H
#include "Types.h"
#include <QHash>
#include <QStandardItemModel>
class Federation;
namespace bonsaiviewer::modules::models {
// QStandardItemModel that mirrors the Federation tree (groups + models in
// two columns: name + visibility icon). Subscribes directly to Federation's
// granular signals so each mutation only touches the affected rows — view
// state (expansion, selection, scroll) is preserved automatically.
//
// Coarse session events (project open/reset, theme change) are not the
// model's concern: the owning View calls rebuildAll() in those cases.
class FederationItemModel : public QStandardItemModel {
Q_OBJECT
public:
enum Role {
IdRole = Qt::UserRole + 1,
KindRole = Qt::UserRole + 2,
};
explicit FederationItemModel(Federation* federation, QObject* parent = nullptr);
// Discard everything and rebuild from current Federation state. Loses
// expansion/selection — caller is the only one that knows whether that's
// acceptable (e.g. project reset, where there's no prior state worth
// preserving anyway).
void rebuildAll();
private slots:
void onGroupAdded(const QString& group_id);
void onGroupRemoved(const QString& group_id);
void onGroupChanged(const QString& group_id);
void onGroupVisibilityChanged(const QString& group_id, bool visible);
void onModelAdded(const QString& fed_id);
void onModelRemoved(const QString& fed_id);
void onModelVisibilityChanged(const QString& fed_id, bool visible);
void onModelGroupChanged(const QString& fed_id, const QString& new_group_id);
void onModelChanged(const QString& fed_id);
private:
QStandardItem* makeGroupNameItem(const QString& group_id, const QString& display_name) const;
QStandardItem* makeModelNameItem(const QString& fed_id, const QString& display_name) const;
QStandardItem* makeVisibilityItem(ItemKind kind, bool visible) const;
void styleRowVisibility(QStandardItem* name_item, bool visible) const;
QStandardItem* findItem(const QString& id) const;
QStandardItem* parentItemForGroup(const QString& parent_group_id) const;
void appendModelTo(QStandardItem* parent_item, const QString& fed_id);
void appendGroupSubtreeTo(QStandardItem* parent_item, const QString& group_id);
void refreshSubtreeVisibility(QStandardItem* root);
Federation* federation_ = nullptr;
QHash<QString, QStandardItem*> id_to_name_item_; // both group_ids and fed_ids
};
} // namespace bonsaiviewer::modules::models
#endif
+395
View File
@@ -0,0 +1,395 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Panel.h"
#include "Commands.h"
#include "FederationItemModel.h"
#include "View.h"
#include "../../SessionState.h"
#include "../../components/Section.h"
#include "../../components/SvgIcon.h"
#include "../../../ifcviewer/Federation.h"
#include <QDataStream>
#include <QDrag>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QHeaderView>
#include <QMenu>
#include <QMimeData>
#include <QSizePolicy>
#include <QTreeView>
namespace bonsaiviewer::modules::models {
namespace {
constexpr auto kDragMimeType = "application/x-bonsaiviewer-model-items";
QString idOf(const QModelIndex& index) {
return index.sibling(index.row(), 0).data(FederationItemModel::IdRole).toString();
}
ItemKind kindOf(const QModelIndex& index) {
return static_cast<ItemKind>(
index.sibling(index.row(), 0).data(FederationItemModel::KindRole).toInt());
}
QStringList selectedModelIdsAt(QTreeView* tree, const QModelIndex& clicked_index) {
QStringList ids;
const QModelIndexList selection = tree->selectionModel()->selectedRows(0);
bool clicked_in_selection = false;
for (const QModelIndex& index : selection) {
if (index == clicked_index.sibling(clicked_index.row(), 0)) {
clicked_in_selection = true;
break;
}
}
if (clicked_in_selection) {
for (const QModelIndex& index : selection) {
if (kindOf(index) == ItemKind::Model) {
ids << idOf(index);
}
}
ids.removeDuplicates();
} else {
ids << idOf(clicked_index);
}
return ids;
}
constexpr int kVisibilityColumnWidth = 28;
// QTreeView subclass that handles drag-and-drop. Drop logic dispatches
// through commands (not directly into the model) so notifications + status
// messages happen the same way as menu-driven moves.
class ModelsTreeView : public QTreeView {
public:
explicit ModelsTreeView(bonsaiviewer::SessionState* session_state, QWidget* parent)
: QTreeView(parent), session_state_(session_state) {}
protected:
void resizeEvent(QResizeEvent* event) override {
QTreeView::resizeEvent(event);
if (model() && model()->columnCount() >= 2) {
const int vw = viewport()->width();
setColumnWidth(0, std::max(40, vw - kVisibilityColumnWidth));
setColumnWidth(1, kVisibilityColumnWidth);
}
}
void startDrag(Qt::DropActions actions) override {
const QModelIndexList selection = selectionModel()->selectedRows(0);
if (selection.isEmpty()) return;
const auto first_kind = kindOf(selection.first());
if (first_kind == ItemKind::Group && selection.size() != 1) return;
QByteArray payload;
QDataStream stream(&payload, QIODevice::WriteOnly);
stream << static_cast<int>(first_kind);
if (first_kind == ItemKind::Group) {
stream << idOf(selection.first());
} else {
QStringList ids;
for (const QModelIndex& index : selection) {
if (kindOf(index) != first_kind) return;
ids.push_back(idOf(index));
}
ids.removeDuplicates();
stream << ids;
}
auto* mime = new QMimeData();
mime->setData(QString::fromUtf8(kDragMimeType), payload);
auto* drag = new QDrag(this);
drag->setMimeData(mime);
drag->exec(actions);
}
void dragEnterEvent(QDragEnterEvent* event) override {
if (event->mimeData()->hasFormat(QString::fromUtf8(kDragMimeType))) {
event->acceptProposedAction();
return;
}
QTreeView::dragEnterEvent(event);
}
void dragMoveEvent(QDragMoveEvent* event) override {
if (!event->mimeData()->hasFormat(QString::fromUtf8(kDragMimeType))) {
QTreeView::dragMoveEvent(event);
return;
}
QString target_group_id;
if (!decodeTargetGroup(event->position().toPoint(), target_group_id) ||
!canAcceptDrop(event->mimeData(), indexAt(event->position().toPoint()), target_group_id)) {
event->ignore();
return;
}
event->acceptProposedAction();
}
void dropEvent(QDropEvent* event) override {
if (!event->mimeData()->hasFormat(QString::fromUtf8(kDragMimeType))) {
QTreeView::dropEvent(event);
return;
}
QString target_group_id;
if (!decodeTargetGroup(event->position().toPoint(), target_group_id) ||
!canAcceptDrop(event->mimeData(), indexAt(event->position().toPoint()), target_group_id)) {
event->ignore();
return;
}
QByteArray payload = event->mimeData()->data(QString::fromUtf8(kDragMimeType));
QDataStream stream(&payload, QIODevice::ReadOnly);
int kind_int = 0;
stream >> kind_int;
const auto kind = static_cast<ItemKind>(kind_int);
if (kind == ItemKind::Group) {
QString group_id;
stream >> group_id;
commands::moveGroup(*session_state_, group_id, target_group_id);
} else {
QStringList ids;
stream >> ids;
ids.removeDuplicates();
if (!ids.isEmpty()) commands::moveModels(*session_state_, ids, target_group_id);
}
event->acceptProposedAction();
}
private:
bool decodeTargetGroup(const QPoint& pos, QString& out) const {
out.clear();
const QModelIndex index = indexAt(pos);
if (!index.isValid()) return true;
if (kindOf(index) != ItemKind::Group) return false;
out = idOf(index);
return true;
}
bool canAcceptDrop(const QMimeData* mime,
const QModelIndex& target_index,
const QString& target_group_id) const {
QByteArray payload = mime->data(QString::fromUtf8(kDragMimeType));
QDataStream stream(&payload, QIODevice::ReadOnly);
int kind_int = 0;
stream >> kind_int;
const auto kind = static_cast<ItemKind>(kind_int);
if (kind == ItemKind::Group) {
QString group_id;
stream >> group_id;
if (group_id.isEmpty()) return false;
if (!target_index.isValid()) return true;
if (kindOf(target_index) != ItemKind::Group) return false;
if (group_id == target_group_id) return false;
for (QModelIndex cur = target_index; cur.isValid(); cur = cur.parent()) {
if (idOf(cur) == group_id) return false;
}
return true;
}
if (kind == ItemKind::Model) {
QStringList ids;
stream >> ids;
ids.removeDuplicates();
if (ids.isEmpty()) return false;
return !target_index.isValid() || !target_group_id.isNull();
}
return false;
}
bonsaiviewer::SessionState* session_state_;
};
} // namespace
ModelsPanel::ModelsPanel(bonsaiviewer::SessionState* session_state,
ViewportWindow* viewport,
QWidget* parent)
: components::Panel("Models", nullptr, parent, true)
, session_state_(session_state)
, viewport_(viewport)
{
auto* section = new components::Section("", components::SectionHeaderMode::Hidden, this);
section->setBodyExpanding(true);
tree_ = new ModelsTreeView(session_state_, section);
tree_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
tree_->setIconSize(QSize(16, 16));
tree_->setSelectionMode(QAbstractItemView::ExtendedSelection);
tree_->setContextMenuPolicy(Qt::CustomContextMenu);
tree_->setDragEnabled(true);
tree_->viewport()->setAcceptDrops(true);
tree_->setDropIndicatorShown(true);
tree_->setDragDropMode(QAbstractItemView::DragDrop);
tree_->setDefaultDropAction(Qt::MoveAction);
tree_->setUniformRowHeights(true);
tree_->setExpandsOnDoubleClick(false);
tree_->setEditTriggers(QAbstractItemView::NoEditTriggers);
tree_->header()->hide();
section->addBodyWidget(tree_);
addBodyWidget(section);
connect(tree_, &QTreeView::clicked, this, [this](const QModelIndex& index) {
if (!index.isValid() || index.column() != 1) return;
commands::toggleVisibility(*session_state_, kindOf(index), idOf(index));
});
connect(tree_, &QTreeView::customContextMenuRequested, this, [this](const QPoint& pos) {
const QModelIndex index = tree_->indexAt(pos);
QMenu menu(tree_);
if (!index.isValid()) {
QAction* add_group_action = menu.addAction(
components::icons::makeSvgIcon(":/icons/folder-plus.svg"), "Add Group");
connect(add_group_action, &QAction::triggered, this, [this]() {
commands::addGroup(*session_state_, *this, QString());
});
menu.exec(tree_->viewport()->mapToGlobal(pos));
return;
}
const auto kind = kindOf(index);
const QString id = idOf(index);
QAction* toggle_action = menu.addAction(
components::icons::makeSvgIcon(":/icons/eye.svg"), "Toggle Visibility");
connect(toggle_action, &QAction::triggered, this, [this, kind, id]() {
commands::toggleVisibility(*session_state_, kind, id);
});
if (kind == ItemKind::Group) {
QAction* add_subgroup = menu.addAction(
components::icons::makeSvgIcon(":/icons/folder-plus.svg"), "New Subgroup");
connect(add_subgroup, &QAction::triggered, this, [this, id]() {
commands::addGroup(*session_state_, *this, id);
});
QAction* rename = menu.addAction(
components::icons::makeSvgIcon(":/icons/folder.svg"), "Rename Group");
connect(rename, &QAction::triggered, this, [this, id]() {
commands::renameGroup(*session_state_, *this, id);
});
QMenu* move_menu = menu.addMenu("Move to Parent");
QAction* move_root = move_menu->addAction("(Root)");
connect(move_root, &QAction::triggered, this, [this, id]() {
commands::moveGroup(*session_state_, id, QString());
});
move_menu->addSeparator();
for (const auto& target : validMoveTargets(*session_state_->federation(), id)) {
QAction* action = move_menu->addAction(target.display_name);
const QString target_id = target.id;
connect(action, &QAction::triggered, this, [this, id, target_id]() {
commands::moveGroup(*session_state_, id, target_id);
});
}
QAction* remove = menu.addAction(
components::icons::makeSvgIcon(":/icons/folder-minus.svg"), "Remove Group");
connect(remove, &QAction::triggered, this, [this, id]() {
commands::removeGroup(*session_state_, *this, id);
});
} else {
QString parent_group_id;
const QModelIndex parent_index = index.parent();
if (parent_index.isValid() && kindOf(parent_index) == ItemKind::Group) {
parent_group_id = idOf(parent_index);
}
QAction* add_group = menu.addAction(
components::icons::makeSvgIcon(":/icons/folder-plus.svg"), "New Group");
connect(add_group, &QAction::triggered, this, [this, parent_group_id]() {
commands::addGroup(*session_state_, *this, parent_group_id);
});
const QStringList selected_model_ids = selectedModelIdsAt(tree_, index);
QMenu* move_menu = menu.addMenu("Move to Group");
QAction* move_root = move_menu->addAction("(Root)");
connect(move_root, &QAction::triggered, this, [this, selected_model_ids]() {
commands::moveModels(*session_state_, selected_model_ids, QString());
});
move_menu->addSeparator();
for (const auto& target : validMoveTargets(*session_state_->federation(), QString())) {
QAction* action = move_menu->addAction(target.display_name);
const QString target_id = target.id;
connect(action, &QAction::triggered, this, [this, selected_model_ids, target_id]() {
commands::moveModels(*session_state_, selected_model_ids, target_id);
});
}
const Federation::Model* selected = session_state_->federation()->findById(id);
const bool has_cloud_source = selected && selected->source_connector != "local";
menu.addSeparator();
QAction* save_to_cloud = menu.addAction(
components::icons::makeSvgIcon(":/icons/cloud-square.svg"), "Save To Cloud");
save_to_cloud->setEnabled(has_cloud_source);
if (!has_cloud_source) {
save_to_cloud->setToolTip(
"This model has no cloud target yet. Use \"Save As To Cloud\" first.");
}
connect(save_to_cloud, &QAction::triggered, this, [this, id]() {
commands::saveModelToCloud(*session_state_, *this, id);
});
QAction* save_as_to_cloud = menu.addAction(
components::icons::makeSvgIcon(":/icons/cloud-square.svg"), "Save As To Cloud");
connect(save_as_to_cloud, &QAction::triggered, this, [this, id]() {
commands::saveModelAsToCloud(*session_state_, *this, id);
});
menu.addSeparator();
QAction* remove = menu.addAction(
components::icons::makeSvgIcon(":/icons/minus-square.svg"), "Remove Model");
connect(remove, &QAction::triggered, this, [this, id]() {
commands::removeModel(*session_state_, *viewport_, *this, id);
});
}
menu.exec(tree_->viewport()->mapToGlobal(pos));
});
connect(this, &components::Panel::settingsRequested, this, [this]() {
commands::openSettings(*session_state_, *this);
});
}
void ModelsPanel::setModel(FederationItemModel* model) {
model_ = model;
tree_->setModel(model);
// Columns are sized by ModelsTreeView::resizeEvent — header is hidden so
// there's no user-facing resize affordance, and Stretch mode on
// non-last sections proved unreliable here. Manual sizing is simpler.
tree_->header()->setMinimumSectionSize(16);
tree_->header()->setStretchLastSection(false);
tree_->setColumnWidth(0, std::max(40, tree_->viewport()->width() - kVisibilityColumnWidth));
tree_->setColumnWidth(1, kVisibilityColumnWidth);
tree_->expandAll();
}
} // namespace bonsaiviewer::modules::models
+60
View File
@@ -0,0 +1,60 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_MODELS_PANEL_H
#define IFCINTERFACE_MODULES_MODELS_PANEL_H
#include "Types.h"
#include "../../components/Panel.h"
class QTreeView;
class ViewportWindow;
namespace bonsaiviewer { class SessionState; }
namespace bonsaiviewer::modules::models {
class FederationItemModel;
// The widget for the Models dock. Owns no domain state; click handlers call
// commands directly. The QTreeView reads from a FederationItemModel which
// subscribes to Federation's granular signals — view state (expansion,
// selection, scroll) is preserved across mutations automatically.
class ModelsPanel : public components::Panel {
Q_OBJECT
public:
explicit ModelsPanel(bonsaiviewer::SessionState* session_state,
ViewportWindow* viewport,
QWidget* parent = nullptr);
// Owned externally (the View constructs and owns the model). The panel
// assigns it to the tree view; same model can outlive setModel calls.
void setModel(FederationItemModel* model);
private:
bonsaiviewer::SessionState* session_state_ = nullptr;
ViewportWindow* viewport_ = nullptr;
QTreeView* tree_ = nullptr;
FederationItemModel* model_ = nullptr;
};
} // namespace bonsaiviewer::modules::models
#endif
@@ -0,0 +1,485 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "SettingsDialog.h"
#include "SettingsView.h"
#include "../../SessionState.h"
#include "../../../ifcviewer/Federation.h"
#include "../../../ifcviewer/SceneLoader.h"
#include "../../components/Section.h"
#include "../../components/Style.h"
#include "../../components/SvgIcon.h"
#include "../../components/Tabs.h"
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QHeaderView>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QRegularExpression>
#include <QSizePolicy>
#include <QShowEvent>
#include <QSignalBlocker>
#include <QScrollBar>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QVBoxLayout>
namespace bonsaiviewer::modules::models {
namespace {
struct UnitChoice {
const char* label;
const char* prefix;
const char* name;
};
const UnitChoice kUnitChoices[] = {
{"Metres (m)", "", "METRE"},
{"Millimetres (mm)", "MILLI", "METRE"},
{"Centimetres (cm)", "CENTI", "METRE"},
{"Kilometres (km)", "KILO", "METRE"},
{"Feet (ft)", "", "foot"},
{"Inches (in)", "", "inch"},
{"Yards (yd)", "", "yard"},
{"Miles (mi)", "", "mile"},
};
QLineEdit* makeNumericField(QWidget* parent, const QString& placeholder = {}) {
auto* field = new QLineEdit(parent);
field->setPlaceholderText(placeholder);
field->setMaximumWidth(96);
return field;
}
QWidget* makeEqualThirdsRow(QWidget* parent, QLineEdit* a, QLineEdit* b, QLineEdit* c) {
auto* row = new QWidget(parent);
auto* layout = new QHBoxLayout(row);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(components::style::metrics::padding);
for (QLineEdit* field : {a, b, c}) {
field->setMaximumWidth(QWIDGETSIZE_MAX);
field->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(field, 1);
}
return row;
}
QString formatNumber(double value) {
return QString::number(value, 'f', 6);
}
double parseNumber(QLineEdit* field) {
bool ok = false;
const double value = field->text().toDouble(&ok);
return ok ? value : 0.0;
}
QString formatVector3(const Eigen::Vector3d& value) {
return QString("%1, %2, %3").arg(formatNumber(value.x()), formatNumber(value.y()), formatNumber(value.z()));
}
Eigen::Vector3d parseVector3(const QString& text) {
const QStringList parts = text.split(QRegularExpression("[,\\s]+"), Qt::SkipEmptyParts);
if (parts.size() != 3) return Eigen::Vector3d::Zero();
bool ok_x = false;
bool ok_y = false;
bool ok_z = false;
const double x = parts[0].toDouble(&ok_x);
const double y = parts[1].toDouble(&ok_y);
const double z = parts[2].toDouble(&ok_z);
if (!ok_x || !ok_y || !ok_z) return Eigen::Vector3d::Zero();
return Eigen::Vector3d(x, y, z);
}
QLabel* makeReadOnlyValue(QWidget* parent) {
auto* label = new QLabel(parent);
label->setTextInteractionFlags(Qt::TextSelectableByMouse);
label->setWordWrap(true);
return label;
}
} // namespace
SettingsDialog::SettingsDialog(bonsaiviewer::SessionState* session_state, QWidget* parent)
: components::TabbedDialog(parent)
, session_state_(session_state)
, federation_(session_state ? session_state->federation() : nullptr)
, loader_(session_state ? session_state->loader() : nullptr)
, settings_view_(new SettingsView(this, session_state))
{
setObjectName("appDialog");
setWindowTitle("Model Settings");
setModal(true);
resize(980, 560);
setupUi();
}
void SettingsDialog::showEvent(QShowEvent* event) {
federation_ = session_state_ ? session_state_->federation() : federation_;
loader_ = session_state_ ? session_state_->loader() : loader_;
syncFromFederation();
populateModelTable();
QDialog::showEvent(event);
}
void SettingsDialog::setupUi() {
auto* federation_tab = new QWidget(this);
auto* federation_layout = new QVBoxLayout(federation_tab);
federation_layout->setContentsMargins(0, 0, 0, 0);
federation_layout->setSpacing(components::style::metrics::padding);
federation_layout->setAlignment(Qt::AlignTop);
auto* federation_unit_section =
new components::Section("Federation Unit", components::SectionHeaderMode::Visible, federation_tab);
auto* unit_hint = new QLabel(
"All measurements, federated false origins, and destination model transforms will be interpreted in this unit.",
federation_unit_section);
unit_hint->setProperty("textRole", "secondary");
unit_hint->setWordWrap(true);
auto* federation_unit_body = new QWidget(federation_unit_section);
auto* federation_unit_form = new QFormLayout(federation_unit_body);
federation_unit_form->setContentsMargins(0, 0, 0, 0);
federation_unit_form->setHorizontalSpacing(16);
federation_unit_form->setVerticalSpacing(10);
unit_combo_ = new QComboBox(federation_unit_body);
for (const auto& uc : kUnitChoices) {
QStringList data;
data << QString::fromUtf8(uc.prefix) << QString::fromUtf8(uc.name);
unit_combo_->addItem(uc.label, data);
}
federation_unit_form->addRow("Unit", unit_combo_);
federation_unit_section->addBodyWidget(unit_hint);
federation_unit_section->addBodyWidget(federation_unit_body);
auto* origin_section =
new components::Section("Federated False Origin", components::SectionHeaderMode::Visible, federation_tab);
auto* origin_hint = new QLabel(
"Nominate a false origin and project north to use when viewing the federation of models.",
origin_section);
origin_hint->setProperty("textRole", "secondary");
origin_hint->setWordWrap(true);
auto* origin_body = new QWidget(origin_section);
auto* origin_form = new QFormLayout(origin_body);
origin_form->setContentsMargins(0, 0, 0, 0);
origin_form->setHorizontalSpacing(16);
origin_form->setVerticalSpacing(10);
xyz_x_ = makeNumericField(origin_body, "X");
xyz_y_ = makeNumericField(origin_body, "Y");
xyz_z_ = makeNumericField(origin_body, "Z");
rz_deg_ = makeNumericField(origin_body, "deg");
origin_form->addRow("XYZ", makeEqualThirdsRow(origin_body, xyz_x_, xyz_y_, xyz_z_));
origin_form->addRow("Z rotation (°)", rz_deg_);
origin_section->addBodyWidget(origin_hint);
origin_section->addBodyWidget(origin_body);
federation_layout->addWidget(federation_unit_section);
federation_layout->addWidget(origin_section);
federation_layout->addStretch(1);
auto* model_tab = new QWidget(this);
auto* model_layout = new QVBoxLayout(model_tab);
model_layout->setContentsMargins(0, 0, 0, 0);
model_layout->setSpacing(components::style::metrics::padding);
model_layout->setAlignment(Qt::AlignTop);
auto* georef_section =
new components::Section("Selected Model Georeferencing", components::SectionHeaderMode::Visible, model_tab);
auto* georef_body = new QWidget(georef_section);
auto* georef_layout = new QHBoxLayout(georef_body);
georef_layout->setContentsMargins(0, 0, 0, 0);
georef_layout->setSpacing(16);
georef_layout->setAlignment(Qt::AlignTop);
georef_present_value_ = makeReadOnlyValue(georef_body);
georef_type_value_ = makeReadOnlyValue(georef_body);
georef_project_unit_value_ = makeReadOnlyValue(georef_body);
georef_map_unit_value_ = makeReadOnlyValue(georef_body);
georef_easting_value_ = makeReadOnlyValue(georef_body);
georef_northing_value_ = makeReadOnlyValue(georef_body);
georef_height_value_ = makeReadOnlyValue(georef_body);
georef_x_axis_abscissa_value_ = makeReadOnlyValue(georef_body);
georef_x_axis_ordinate_value_ = makeReadOnlyValue(georef_body);
georef_rotation_dd_value_ = makeReadOnlyValue(georef_body);
georef_rotation_dms_value_ = makeReadOnlyValue(georef_body);
georef_scale_value_ = makeReadOnlyValue(georef_body);
georef_factor_x_value_ = makeReadOnlyValue(georef_body);
georef_factor_y_value_ = makeReadOnlyValue(georef_body);
georef_factor_z_value_ = makeReadOnlyValue(georef_body);
auto* georef_col_1 = new QFormLayout();
georef_col_1->setContentsMargins(0, 0, 0, 0);
georef_col_1->setHorizontalSpacing(12);
georef_col_1->setVerticalSpacing(8);
georef_col_1->addRow("Georeferenced", georef_present_value_);
georef_col_1->addRow("Coordinate Operation", georef_type_value_);
georef_col_1->addRow("Project Unit", georef_project_unit_value_);
georef_col_1->addRow("Map Unit", georef_map_unit_value_);
georef_col_1->addRow("Easting", georef_easting_value_);
georef_col_1->addRow("Northing", georef_northing_value_);
georef_col_1->addRow("OrthogonalHeight", georef_height_value_);
auto* georef_col_2 = new QFormLayout();
georef_col_2->setContentsMargins(0, 0, 0, 0);
georef_col_2->setHorizontalSpacing(12);
georef_col_2->setVerticalSpacing(8);
georef_col_2->addRow("XAxisAbscissa", georef_x_axis_abscissa_value_);
georef_col_2->addRow("XAxisOrdinate", georef_x_axis_ordinate_value_);
georef_col_2->addRow("Rotation (DD)", georef_rotation_dd_value_);
georef_col_2->addRow("Rotation (DMS)", georef_rotation_dms_value_);
auto* georef_col_3 = new QFormLayout();
georef_col_3->setContentsMargins(0, 0, 0, 0);
georef_col_3->setHorizontalSpacing(12);
georef_col_3->setVerticalSpacing(8);
georef_col_3->addRow("Scale", georef_scale_value_);
georef_col_3->addRow("FactorX", georef_factor_x_value_);
georef_col_3->addRow("FactorY", georef_factor_y_value_);
georef_col_3->addRow("FactorZ", georef_factor_z_value_);
auto* georef_col_1_widget = new QWidget(georef_body);
georef_col_1_widget->setLayout(georef_col_1);
auto* georef_col_2_widget = new QWidget(georef_body);
georef_col_2_widget->setLayout(georef_col_2);
auto* georef_col_3_widget = new QWidget(georef_body);
georef_col_3_widget->setLayout(georef_col_3);
georef_layout->addWidget(georef_col_1_widget, 1);
georef_layout->addWidget(georef_col_2_widget, 1);
georef_layout->addWidget(georef_col_3_widget, 1);
georef_section->addBodyWidget(georef_body);
auto* table_section =
new components::Section("Model Transformations", components::SectionHeaderMode::Visible, model_tab);
auto* table_body = new QWidget(table_section);
auto* table_layout = new QVBoxLayout(table_body);
table_layout->setContentsMargins(0, 0, 0, 0);
table_layout->setSpacing(components::style::metrics::padding);
model_table_ = new QTableWidget(table_body);
model_table_->setObjectName("modelCoordinatesTable");
model_table_->setColumnCount(6);
model_table_->setHorizontalHeaderLabels(
{"Model", "From", "From Point", "To Point", "Rotate", "Pivot Point"});
model_table_->verticalHeader()->setVisible(false);
model_table_->horizontalHeader()->setStretchLastSection(false);
model_table_->horizontalHeader()->setSectionsMovable(false);
model_table_->horizontalHeader()->setSectionsClickable(true);
model_table_->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
model_table_->horizontalHeader()->resizeSection(0, 180);
model_table_->horizontalHeader()->resizeSection(1, 150);
model_table_->horizontalHeader()->resizeSection(2, 180);
model_table_->horizontalHeader()->resizeSection(3, 180);
model_table_->horizontalHeader()->resizeSection(4, 180);
model_table_->horizontalHeader()->resizeSection(5, 180);
model_table_->setSelectionBehavior(QAbstractItemView::SelectRows);
model_table_->setSelectionMode(QAbstractItemView::SingleSelection);
model_table_->setShowGrid(true);
model_table_->setWordWrap(false);
model_table_->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
model_table_->setAlternatingRowColors(false);
model_table_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
auto* table_hint = new QLabel(
"This section lets you override model coordinates by specifying an optional translation from a point to "
"another desired point, and an optional rotation.",
table_section);
table_hint->setProperty("textRole", "secondary");
table_hint->setWordWrap(true);
table_layout->addWidget(model_table_, 1);
table_section->addBodyWidget(table_hint);
table_section->addBodyWidget(table_body);
model_layout->addWidget(georef_section);
model_layout->addWidget(table_section);
addTab("Federation", federation_tab);
addTab("Model", model_tab);
connect(model_table_, &QTableWidget::currentCellChanged, this,
[this](int /*current_row*/, int /*current_column*/, int /*previous_row*/, int /*previous_column*/) {
updateSelectedModelGeoref();
});
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
if (auto* ok = buttons->button(QDialogButtonBox::Ok)) {
ok->setText("OK");
ok->setIcon(components::icons::makeSvgIcon(":/icons/check.svg"));
}
if (auto* cancel = buttons->button(QDialogButtonBox::Cancel)) {
cancel->setText("Cancel");
cancel->setIcon(components::icons::makeSvgIcon(":/icons/xmark-circle.svg"));
}
connect(buttons, &QDialogButtonBox::accepted, this, [this]() { onAccepted(); });
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
addFooterWidget(buttons);
}
void SettingsDialog::syncFromFederation() {
if (!federation_) return;
const auto& cfg = federation_->config();
int idx = -1;
for (int i = 0; i < unit_combo_->count(); ++i) {
const QStringList data = unit_combo_->itemData(i).toStringList();
if (data.size() == 2 &&
data[0].toStdString() == cfg.unit_prefix &&
data[1].toStdString() == cfg.unit_name) {
idx = i;
break;
}
}
unit_combo_->setCurrentIndex(idx >= 0 ? idx : 0);
const auto& origin = federation_->federatedFalseOrigin();
xyz_x_->setText(formatNumber(origin.xyz.x()));
xyz_y_->setText(formatNumber(origin.xyz.y()));
xyz_z_->setText(formatNumber(origin.xyz.z()));
rz_deg_->setText(formatNumber(origin.rz_deg));
}
void SettingsDialog::populateModelTable() {
model_rows_.clear();
const QSignalBlocker blocker(model_table_);
model_table_->clearContents();
model_table_->setRowCount(0);
if (!federation_) return;
int row = 0;
for (const auto& model : federation_->models()) {
const auto& xf = model.model_transformation;
model_table_->insertRow(row);
auto* model_item = new QTableWidgetItem(model.display_name.isEmpty() ? model.id : model.display_name);
model_item->setData(Qt::UserRole, model.id);
model_table_->setItem(row, 0, model_item);
ModelRowWidgets widgets;
widgets.fed_id = model.id;
widgets.frame = new QComboBox(model_table_);
widgets.frame->addItem("Local", static_cast<int>(AFrame::ModelLocal));
widgets.frame->addItem("Global", static_cast<int>(AFrame::ModelGlobal));
widgets.frame->setCurrentIndex(xf.a_frame == AFrame::ModelGlobal ? 1 : 0);
model_table_->setCellWidget(row, 1, widgets.frame);
widgets.from_point = new QTableWidgetItem(formatVector3(xf.a));
widgets.to_point = new QTableWidgetItem(formatVector3(xf.b));
widgets.rotate = new QTableWidgetItem(formatVector3(xf.rxyz_deg));
widgets.pivot = new QTableWidgetItem(formatVector3(xf.pivot));
model_table_->setItem(row, 2, widgets.from_point);
model_table_->setItem(row, 3, widgets.to_point);
model_table_->setItem(row, 4, widgets.rotate);
model_table_->setItem(row, 5, widgets.pivot);
model_rows_.push_back(widgets);
model_table_->setRowHeight(row, 42);
++row;
}
int table_height = model_table_->frameWidth() * 2 + model_table_->horizontalHeader()->height();
for (int i = 0; i < model_table_->rowCount(); ++i) {
table_height += model_table_->rowHeight(i);
}
if (model_table_->horizontalScrollBar()->isVisible()) {
table_height += model_table_->horizontalScrollBar()->sizeHint().height();
}
model_table_->setMinimumHeight(table_height);
model_table_->setMaximumHeight(table_height);
if (model_table_->rowCount() > 0) {
model_table_->setCurrentCell(0, 0);
}
updateSelectedModelGeoref();
}
void SettingsDialog::renderSelectedModelGeoref(const SelectedModelGeorefState& state) {
georef_present_value_->setText(state.georef_present);
georef_type_value_->setText(state.coordinate_operation_type);
georef_project_unit_value_->setText(state.project_unit);
georef_map_unit_value_->setText(state.map_unit);
georef_easting_value_->setText(state.easting);
georef_northing_value_->setText(state.northing);
georef_height_value_->setText(state.height);
georef_x_axis_abscissa_value_->setText(state.x_axis_abscissa);
georef_x_axis_ordinate_value_->setText(state.x_axis_ordinate);
georef_rotation_dd_value_->setText(state.rotation_dd);
georef_rotation_dms_value_->setText(state.rotation_dms);
georef_scale_value_->setText(state.scale);
georef_factor_x_value_->setText(state.factor_x);
georef_factor_y_value_->setText(state.factor_y);
georef_factor_z_value_->setText(state.factor_z);
}
void SettingsDialog::updateSelectedModelGeoref() {
const int row = model_table_->currentRow();
if (row < 0 || row >= static_cast<int>(model_rows_.size())) {
renderSelectedModelGeoref(
{"No model selected", "", "", "", "", "", "", "", "", "", "", "", "", "", ""});
return;
}
if (!settings_view_) {
renderSelectedModelGeoref(
{"Unavailable", "No settings view", "", "", "", "", "", "", "", "", "", "", "", "", ""});
return;
}
settings_view_->refresh(model_rows_[row].fed_id);
}
void SettingsDialog::onAccepted() {
if (federation_) {
const QStringList data = unit_combo_->currentData().toStringList();
FederationConfig cfg;
if (data.size() == 2) {
cfg.unit_prefix = data[0].toStdString();
cfg.unit_name = data[1].toStdString();
}
federation_->setConfig(cfg);
FederatedFalseOrigin origin;
origin.xyz = Eigen::Vector3d(parseNumber(xyz_x_), parseNumber(xyz_y_), parseNumber(xyz_z_));
origin.rz_deg = parseNumber(rz_deg_);
federation_->setFederatedFalseOrigin(origin);
for (const auto& row : model_rows_) {
ModelTransformation xf;
xf.a_frame = static_cast<AFrame>(row.frame->currentData().toInt());
xf.a = parseVector3(row.from_point->text());
xf.b = parseVector3(row.to_point->text());
xf.rxyz_deg = parseVector3(row.rotate->text());
xf.pivot = parseVector3(row.pivot->text());
federation_->setModelTransformation(row.fed_id, xf);
}
if (session_state_) {
session_state_->notifyFederationChanged();
}
}
accept();
}
} // namespace bonsaiviewer::modules::models
@@ -0,0 +1,105 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_MODELS_SETTINGSDIALOG_H
#define IFCINTERFACE_MODULES_MODELS_SETTINGSDIALOG_H
#include "../../components/Dialog.h"
#include "Types.h"
#include <QString>
#include <vector>
class Federation;
class SceneLoader;
class QComboBox;
class QLabel;
class QLineEdit;
class QShowEvent;
class QTableWidget;
class QTableWidgetItem;
namespace bonsaiviewer {
class SessionState;
}
namespace bonsaiviewer::modules::models {
class SettingsView;
class SettingsDialog : public components::TabbedDialog {
Q_OBJECT
public:
explicit SettingsDialog(bonsaiviewer::SessionState* session_state, QWidget* parent = nullptr);
void renderSelectedModelGeoref(const SelectedModelGeorefState& state);
protected:
void showEvent(QShowEvent* event) override;
private:
struct ModelRowWidgets {
QString fed_id;
QComboBox* frame = nullptr;
QTableWidgetItem* from_point = nullptr;
QTableWidgetItem* to_point = nullptr;
QTableWidgetItem* rotate = nullptr;
QTableWidgetItem* pivot = nullptr;
};
void setupUi();
void syncFromFederation();
void populateModelTable();
void updateSelectedModelGeoref();
void onAccepted();
bonsaiviewer::SessionState* session_state_ = nullptr;
Federation* federation_ = nullptr;
SceneLoader* loader_ = nullptr;
QComboBox* unit_combo_ = nullptr;
QLineEdit* xyz_x_ = nullptr;
QLineEdit* xyz_y_ = nullptr;
QLineEdit* xyz_z_ = nullptr;
QLineEdit* rz_deg_ = nullptr;
QLabel* georef_present_value_ = nullptr;
QLabel* georef_type_value_ = nullptr;
QLabel* georef_project_unit_value_ = nullptr;
QLabel* georef_map_unit_value_ = nullptr;
QLabel* georef_easting_value_ = nullptr;
QLabel* georef_northing_value_ = nullptr;
QLabel* georef_height_value_ = nullptr;
QLabel* georef_x_axis_abscissa_value_ = nullptr;
QLabel* georef_x_axis_ordinate_value_ = nullptr;
QLabel* georef_rotation_dd_value_ = nullptr;
QLabel* georef_rotation_dms_value_ = nullptr;
QLabel* georef_scale_value_ = nullptr;
QLabel* georef_factor_x_value_ = nullptr;
QLabel* georef_factor_y_value_ = nullptr;
QLabel* georef_factor_z_value_ = nullptr;
QTableWidget* model_table_ = nullptr;
std::vector<ModelRowWidgets> model_rows_;
SettingsView* settings_view_ = nullptr;
};
} // namespace bonsaiviewer::modules::models
#endif
@@ -0,0 +1,246 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "SettingsView.h"
#include "SettingsDialog.h"
#include "../../SessionState.h"
#include "../../../ifcviewer/Federation.h"
#include "../../../ifcviewer/Geolocation.h"
#include "../../../ifcviewer/SceneLoader.h"
#include "../../../ifcviewer/Unit.h"
#include <cmath>
namespace bonsaiviewer::modules::models {
namespace {
QString formatNumber(double value) {
return QString::number(value, 'f', 6);
}
QString formatAngleDms(double degrees) {
const double absolute = std::fabs(degrees);
const int d = static_cast<int>(absolute);
const double minutes_total = (absolute - static_cast<double>(d)) * 60.0;
const int m = static_cast<int>(minutes_total);
const double s = (minutes_total - static_cast<double>(m)) * 60.0;
const QString sign = degrees < 0.0 ? "-" : "";
return QString("%1%2° %3' %4\"").arg(sign).arg(d).arg(m, 2, 10, QChar('0')).arg(formatNumber(s));
}
SelectedModelGeorefState unknownState(const QString& georef, const QString& type) {
return {
georef,
type,
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
};
}
QString formatCachedUnitScale(double meters_per_unit) {
return QString("Cached scale: 1 unit = %1 m").arg(formatNumber(meters_per_unit));
}
std::string enumString(const attribute_value& av) {
if (av.isNull()) return {};
if (av.type() != ifcopenshell::Argument_ENUMERATION) return {};
enumeration_reference er = av;
return std::string(er.value() ? er.value() : "");
}
QString formatNamedUnit(const express::Base& unit) {
if (!unit) return "";
auto entity = unit.as<express::Entity>();
if (unit.declaration().is("IfcSIUnit")) {
const std::string prefix = enumString(entity.get("Prefix"));
const std::string name = enumString(entity.get("Name"));
QString text;
if (!prefix.empty()) {
text += QString::fromStdString(prefix) + " ";
}
text += QString::fromStdString(name);
auto symbol_it = kUnitSymbols.find(name);
if (symbol_it != kUnitSymbols.end()) {
text += " (" + QString::fromStdString(symbol_it->second) + ")";
}
return text;
}
auto name_attr = entity.get("Name");
if (name_attr.isNull()) return "";
const std::string name = static_cast<std::string>(name_attr);
QString text = QString::fromStdString(name);
auto symbol_it = kUnitSymbols.find(name);
if (symbol_it != kUnitSymbols.end()) {
text += " (" + QString::fromStdString(symbol_it->second) + ")";
}
return text;
}
std::optional<QString> coordinateOperationType(ifcopenshell::file* ifc_file) {
if (!ifc_file) return std::nullopt;
try {
const auto coordops = ifc_file->instances_by_type("IfcCoordinateOperation");
if (!coordops.empty()) {
return QString::fromStdString(coordops[0].declaration().name());
}
} catch (...) {
return std::nullopt;
}
if (ifc_file->schema()->name() == "IFC2X3") {
if (getHelmertTransformationParameters(ifc_file)) {
return QStringLiteral("ePSet_MapConversion");
}
}
return QStringLiteral("None");
}
SelectedModelGeorefState stateFromLiveFile(ifcopenshell::file* ifc_file) {
if (!ifc_file) return unknownState("Not available yet", "No data source");
const auto params = getHelmertTransformationParameters(ifc_file);
const auto coordop_type = coordinateOperationType(ifc_file);
const auto project_unit_value = getProjectUnit(ifc_file, "LENGTHUNIT");
const auto map_unit_value = getMapUnit(ifc_file);
const QString project_unit = project_unit_value ? formatNamedUnit(*project_unit_value) : QString("");
const QString map_unit = map_unit_value ? formatNamedUnit(*map_unit_value) : project_unit;
if (!params) {
auto state = unknownState("No", coordop_type.value_or("Unknown"));
state.project_unit = project_unit;
state.map_unit = map_unit;
return state;
}
const double rotation_dd = xaxis2angleDeg(params->xaa, params->xao);
return {
"Yes",
coordop_type.value_or("Unknown"),
project_unit,
map_unit,
formatNumber(params->e),
formatNumber(params->n),
formatNumber(params->h),
formatNumber(params->xaa),
formatNumber(params->xao),
formatNumber(rotation_dd),
formatAngleDms(rotation_dd),
formatNumber(params->scale),
formatNumber(params->factor_x),
formatNumber(params->factor_y),
formatNumber(params->factor_z),
};
}
SelectedModelGeorefState stateFromCachedGeoref(const ModelGeoref& georef) {
if (!georef.has_coordinate_operation) {
return unknownState("No", "None");
}
const Eigen::Matrix4d& m = georef.coordinate_operation_meters;
const Eigen::Vector3d translation = m.block<3, 1>(0, 3);
const Eigen::Vector3d x_axis = m.block<3, 1>(0, 0);
const Eigen::Vector3d y_axis = m.block<3, 1>(0, 1);
const double factor_x = x_axis.norm();
const double factor_y = y_axis.norm();
const double factor_z = m.block<3, 1>(0, 2).norm();
const double scale = (factor_x + factor_y) * 0.5;
const double x_axis_abscissa = factor_x > 0.0 ? x_axis.x() / factor_x : 1.0;
const double x_axis_ordinate = factor_x > 0.0 ? x_axis.y() / factor_x : 0.0;
constexpr double kRadiansToDegrees = 57.29577951308232;
const double rotation_dd = std::atan2(x_axis_ordinate, x_axis_abscissa) * kRadiansToDegrees;
return {
"Yes",
"Cached coordinate operation",
formatCachedUnitScale(georef.units.project_length_to_meters),
formatCachedUnitScale(georef.units.map_unit_to_meters),
formatNumber(translation.x()),
formatNumber(translation.y()),
formatNumber(translation.z()),
formatNumber(x_axis_abscissa),
formatNumber(x_axis_ordinate),
formatNumber(rotation_dd),
formatAngleDms(rotation_dd),
formatNumber(scale),
formatNumber(factor_x),
formatNumber(factor_y),
formatNumber(factor_z),
};
}
} // namespace
SettingsView::SettingsView(SettingsDialog* widget,
bonsaiviewer::SessionState* session_state)
: widget_(widget), session_state_(session_state)
{
}
void SettingsView::refresh(const QString& fed_id) const {
if (!widget_) {
return;
}
if (!session_state_) {
widget_->renderSelectedModelGeoref(unknownState("Unavailable", "No session state"));
return;
}
SceneLoader* loader = session_state_->loader();
if (!loader) {
widget_->renderSelectedModelGeoref(unknownState("Unavailable", "No loader"));
return;
}
const uint32_t mid = session_state_->modelIdForFedId(fed_id);
if (mid == 0) {
widget_->renderSelectedModelGeoref(unknownState("Not loaded", "No live model"));
return;
}
if (auto* ifc_file = loader->ifcFile(mid)) {
widget_->renderSelectedModelGeoref(stateFromLiveFile(ifc_file));
return;
}
const ModelGeoref* georef = loader->modelGeoref(mid);
if (!georef) {
widget_->renderSelectedModelGeoref(unknownState("Not available yet", "No data source"));
return;
}
widget_->renderSelectedModelGeoref(stateFromCachedGeoref(*georef));
}
} // namespace bonsaiviewer::modules::models
@@ -0,0 +1,48 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_MODELS_SETTINGSVIEW_H
#define IFCINTERFACE_MODULES_MODELS_SETTINGSVIEW_H
#include "Types.h"
namespace bonsaiviewer {
class SessionState;
}
namespace bonsaiviewer::modules::models {
class SettingsDialog;
class SettingsView {
public:
explicit SettingsView(SettingsDialog* widget,
bonsaiviewer::SessionState* session_state);
void refresh(const QString& fed_id) const;
private:
SettingsDialog* widget_ = nullptr;
bonsaiviewer::SessionState* session_state_ = nullptr;
};
} // namespace bonsaiviewer::modules::models
#endif
+69
View File
@@ -0,0 +1,69 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_PANELS_MODELSPANELTYPES_H
#define IFCINTERFACE_PANELS_MODELSPANELTYPES_H
#include <QList>
#include <QString>
namespace bonsaiviewer::modules::models {
enum class ItemKind {
Group,
Model,
};
struct TreeNode {
QString id;
QString name;
ItemKind kind = ItemKind::Group;
bool visible = true;
QList<TreeNode> children;
};
// One entry in a "move to..." menu. Computed by the View from federation state
// and passed into the Panel so menu construction has no domain knowledge.
struct GroupOption {
QString id;
QString display_name;
};
struct SelectedModelGeorefState {
QString georef_present;
QString coordinate_operation_type;
QString project_unit;
QString map_unit;
QString easting;
QString northing;
QString height;
QString x_axis_abscissa;
QString x_axis_ordinate;
QString rotation_dd;
QString rotation_dms;
QString scale;
QString factor_x;
QString factor_y;
QString factor_z;
};
} // namespace bonsaiviewer::modules::models
#endif
+75
View File
@@ -0,0 +1,75 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "View.h"
#include "FederationItemModel.h"
#include "Panel.h"
#include "../../ViewerSettings.h"
#include "../../SessionState.h"
#include "../../../ifcviewer/Federation.h"
namespace bonsaiviewer::modules::models {
namespace {
void collectGroupsRecursive(const Federation::Group* group,
const QString& exclude_subtree_root,
QList<GroupOption>& out) {
if (group->id == exclude_subtree_root) return;
out.append({group->id, group->display_name});
for (const auto& child : group->children) {
collectGroupsRecursive(child.get(), exclude_subtree_root, out);
}
}
} // namespace
QList<GroupOption> validMoveTargets(const Federation& federation,
const QString& exclude_subtree_root) {
QList<GroupOption> out;
for (const auto& root : federation.rootGroups()) {
collectGroupsRecursive(root.get(), exclude_subtree_root, out);
}
return out;
}
ModelsPanelView::ModelsPanelView(ModelsPanel* widget,
bonsaiviewer::SessionState* session_state,
QObject* parent)
: QObject(parent)
, widget_(widget)
, session_state_(session_state)
, model_(new FederationItemModel(session_state->federation(), this))
{
widget_->setModel(model_);
// Coarse signals: full rebuild + re-style. The granular Federation
// signals are handled inside FederationItemModel and don't reach here.
auto rebuild = [this]() { model_->rebuildAll(); };
connect(session_state_, &SessionState::projectReset, this, rebuild);
connect(session_state_, &SessionState::projectOpened, this, rebuild);
connect(&bonsaiviewer::ViewerSettings::instance(),
&bonsaiviewer::ViewerSettings::themeChanged,
this, rebuild);
}
} // namespace bonsaiviewer::modules::models
+63
View File
@@ -0,0 +1,63 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_PANELS_MODELSPANELVIEW_H
#define IFCINTERFACE_PANELS_MODELSPANELVIEW_H
#include "Types.h"
#include <QObject>
class Federation;
namespace bonsaiviewer { class SessionState; }
namespace bonsaiviewer::modules::models {
class FederationItemModel;
class ModelsPanel;
// Pure derivation used by ModelsPanel when building its "move to..." menus.
// Walks the federation's group tree and returns every group except those in
// the subtree rooted at exclude_subtree_root (skip a group's own subtree to
// prevent a cyclic move). Pass an empty exclude_subtree_root to get every
// group back.
QList<GroupOption> validMoveTargets(const Federation& federation,
const QString& exclude_subtree_root);
// Owns the FederationItemModel, hands it to the panel, and listens to the
// coarse session signals (project open/reset, theme change) — those are the
// "rebuild from scratch" cases the model itself doesn't subscribe to.
// Granular Federation events are handled inside the model.
class ModelsPanelView : public QObject {
Q_OBJECT
public:
explicit ModelsPanelView(ModelsPanel* widget,
bonsaiviewer::SessionState* session_state,
QObject* parent = nullptr);
private:
ModelsPanel* widget_ = nullptr;
bonsaiviewer::SessionState* session_state_ = nullptr;
FederationItemModel* model_ = nullptr;
};
} // namespace bonsaiviewer::modules::models
#endif
@@ -0,0 +1,671 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "Commands.h"
#include "SaveProjectDialog.h"
#include "../../ElementRegistry.h"
#include "../../SessionState.h"
#include "../connectors/PickerDialog.h"
#include "../connectors/Process.h"
#include "../connectors/Registry.h"
#include "../models/Commands.h"
#include "../../../ifcviewer/Federation.h"
#include "../../../ifcviewer/SceneLoader.h"
#include "../../../ifcviewer/ViewportWindow.h"
#include <QDebug>
#include <QDir>
#include <QFileDialog>
#include <QFileInfo>
#include <QHash>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QMessageBox>
#include <QPointer>
#include <QTemporaryDir>
#include <memory>
namespace bonsaiviewer::modules::project::commands {
namespace {
// Pure helper — clears the loaded scene without emitting any signals. The
// caller (newProject / openProject) emits projectReset / projectOpened once
// the whole flow finishes.
void clearScene(SessionState& s, ViewportWindow& vp) {
vp.setSelectedObjectId(0);
s.setSelectedObjectId(0);
for (uint32_t mid : s.modelIds()) {
vp.removeModel(mid);
s.loader()->removeModel(mid);
}
s.clearModelMappings();
s.elementRegistry()->clear();
}
// Returns false if the user cancelled (i.e. don't proceed with the destructive
// op). Handles the Save → Discard → Cancel branch including a follow-on save.
bool confirmDiscardIfDirty(SessionState& s, QWidget& host) {
if (!s.federation()->isDirty()) return true;
const auto result = QMessageBox::question(
&host, "Unsaved Project",
"The current project has unsaved changes. Save before continuing?",
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save);
if (result == QMessageBox::Cancel) return false;
if (result == QMessageBox::Save) return saveProject(s, host);
return true;
}
// Fire-and-forget async resolution of any non-local models in the
// federation. Groups by source_connector and issues one pull_models per
// group. For each returned entry:
// - if the fed_id already has a scene entry pointed at the same path,
// just refresh cloud metadata (no reload, preserves view state);
// - if the path differs, tear down the stale scene entry and queue a
// fresh load (federation entry is preserved either way);
// - if no scene entry exists yet (initial open), queue a load.
// Per spec, connector errors are not surfaced to the user; the connector
// has already shown its own UI.
void resolveCloudModels(SessionState& s, ViewportWindow& vp) {
auto* fed = s.federation();
QHash<QString, QStringList> connector_to_fed_ids;
for (const auto& m : fed->models()) {
if (m.source_connector == "local") continue;
connector_to_fed_ids[m.source_connector].push_back(m.id);
}
if (connector_to_fed_ids.isEmpty()) return;
auto* registry = s.connectorRegistry();
QPointer<SessionState> sguard(&s);
QPointer<ViewportWindow> vguard(&vp);
for (auto it = connector_to_fed_ids.constBegin();
it != connector_to_fed_ids.constEnd(); ++it) {
const QString connector_id = it.key();
const QStringList fed_ids = it.value();
auto* proc = registry->get(connector_id);
if (!proc) {
qWarning() << "resolveCloudModels: cannot launch connector"
<< connector_id << ":" << registry->lastError();
continue;
}
QJsonArray params;
for (const QString& fed_id : fed_ids) {
const Federation::Model* m = fed->findById(fed_id);
if (!m) continue;
QJsonObject source = m->source_data;
source["connector"] = m->source_connector;
QJsonObject entry;
entry["display_name"] = m->display_name;
entry["id"] = m->id;
entry["source"] = source;
params.append(entry);
}
proc->call("pull_models", params,
[sguard, vguard, fed_ids](const QJsonValue& result) {
if (!sguard) return;
const QJsonArray arr = result.toArray();
QStringList paths_to_load;
QStringList fed_ids_to_load;
bool any_detached = false;
for (int i = 0; i < arr.size() && i < fed_ids.size(); ++i) {
if (arr[i].isNull()) continue;
const QJsonObject obj = arr[i].toObject();
const QString new_path = obj.value("path").toString();
if (new_path.isEmpty()) continue;
const QString fed_id = fed_ids[i];
const QJsonObject meta = obj.value("metadata").toObject();
const uint32_t existing_mid = sguard->modelIdForFedId(fed_id);
if (existing_mid != 0 && sguard->loader()) {
const QString existing_path = sguard->loader()->filePath(existing_mid);
if (QDir::cleanPath(existing_path) == QDir::cleanPath(new_path)) {
sguard->setCloudMetadata(fed_id, meta.toVariantMap());
continue;
}
// Path changed (new revision lives in a fresh cache dir).
// Detach the stale scene entry; federation entry stays.
if (vguard) vguard->removeModel(existing_mid);
sguard->loader()->removeModel(existing_mid);
sguard->elementRegistry()->removeModel(existing_mid);
sguard->removeModelMappingByFedId(fed_id);
any_detached = true;
}
sguard->setCloudMetadata(fed_id, meta.toVariantMap());
paths_to_load << new_path;
fed_ids_to_load << fed_id;
}
if (any_detached) {
if (vguard) vguard->setSelectedObjectId(0);
sguard->setSelectedObjectId(0);
sguard->notifySelectionChanged();
}
if (!paths_to_load.isEmpty()) {
modules::models::commands::detail::loadModels(
*sguard, paths_to_load, fed_ids_to_load);
sguard->notifyModelsChanged();
}
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "pull_models from" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
}
int total = 0;
for (auto it = connector_to_fed_ids.constBegin();
it != connector_to_fed_ids.constEnd(); ++it) {
total += it.value().size();
}
s.setStatusMessage("Cloud", QString("Resolving %1 model(s)...").arg(total));
}
// Byte-equality check for "is this .ifcfed the same as what we have loaded?"
// — used by Sync From Cloud to skip the full reload when the connector
// served an unchanged revision.
bool isIfcfedUnchanged(const QString& current_path, const QString& candidate_path) {
if (current_path.isEmpty() || candidate_path.isEmpty()) return false;
if (QDir::cleanPath(current_path) == QDir::cleanPath(candidate_path)) return true;
QFile a(current_path);
QFile b(candidate_path);
if (!a.open(QIODevice::ReadOnly) || !b.open(QIODevice::ReadOnly)) return false;
if (a.size() != b.size()) return false;
return a.readAll() == b.readAll();
}
bool openProjectAt(SessionState& s, QWidget& host, ViewportWindow& vp, const QString& path) {
SceneLoader* loader = s.loader();
if (loader && loader->isLoading()) {
QMessageBox::information(
&host, "Open Project",
"Wait until the current model load finishes before opening another project.");
return false;
}
if (!confirmDiscardIfDirty(s, host)) return false;
QStringList warnings;
QString err;
if (!s.federation()->load(path, &warnings, &err)) {
QMessageBox::warning(&host, "Open Project",
QString("Could not open project:\n%1").arg(err));
return false;
}
clearScene(s, vp);
QStringList paths;
QStringList fed_ids;
for (const auto& model : s.federation()->models()) {
if (model.source_connector != "local") continue;
if (!QFileInfo::exists(model.source_path)) {
warnings << QString("Source not found, kept in project: %1").arg(model.source_path);
continue;
}
paths << model.source_path;
fed_ids << model.id;
}
modules::models::commands::detail::loadModels(s, paths, fed_ids);
if (!warnings.isEmpty()) {
QMessageBox::warning(&host, "Open Project",
"Project opened with warnings:\n\n" + warnings.join("\n"));
}
s.federation()->markClean();
if (s.federation()->hasHomeView()) {
const auto& hv = s.federation()->homeView();
vp.setCamera(hv.target.x(), hv.target.y(), hv.target.z(),
hv.distance, hv.yaw, hv.pitch);
}
s.setStatusMessage("Project", QFileInfo(path).fileName());
s.notifyProjectOpened(path);
resolveCloudModels(s, vp);
return true;
}
bool saveProjectTo(SessionState& s, QWidget& host, const QString& path) {
QString err;
if (!s.federation()->save(path, &err)) {
QMessageBox::warning(&host, "Save Project",
QString("Could not save project:\n%1").arg(err));
return false;
}
s.setStatusMessage("Project", QFileInfo(path).fileName());
s.notifyProjectSaved(path);
return true;
}
} // namespace
bool newProject(SessionState& s, QWidget& host, ViewportWindow& vp) {
SceneLoader* loader = s.loader();
if (loader && loader->isLoading()) {
QMessageBox::information(
&host, "New Project",
"Wait until the current model load finishes before creating a new project.");
return false;
}
if (!confirmDiscardIfDirty(s, host)) return false;
clearScene(s, vp);
s.federation()->clear();
s.setStatusMessage("Project", "Untitled");
s.notifyProjectReset();
return true;
}
bool openProject(SessionState& s, QWidget& host, ViewportWindow& vp) {
QFileDialog file_dialog(&host, "Open Project");
file_dialog.setFileMode(QFileDialog::ExistingFile);
file_dialog.setNameFilter("IFC Federation (*.ifcfed);;All Files (*)");
file_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (file_dialog.exec() != QDialog::Accepted) return false;
const QString path = file_dialog.selectedFiles().value(0);
if (path.isEmpty()) return false;
return openProjectAt(s, host, vp, path);
}
bool openCloudProject(SessionState& s, QWidget& host, ViewportWindow& vp) {
SceneLoader* loader = s.loader();
if (loader && loader->isLoading()) {
QMessageBox::information(
&host, "Open from Cloud",
"Wait until the current model load finishes before opening another project.");
return false;
}
if (!confirmDiscardIfDirty(s, host)) return false;
auto* registry = s.connectorRegistry();
const auto& manifests = registry->available();
if (manifests.empty()) {
QMessageBox::information(&host, "Open from Cloud",
"No connectors are installed. Install one under your user connectors "
"directory.");
return false;
}
modules::connectors::ConnectorPickerDialog picker(
manifests, "Open from Cloud",
"Pick a connector to browse a project on.", &host);
if (picker.exec() != QDialog::Accepted) return false;
const QString connector_id = picker.selectedId();
if (connector_id.isEmpty()) return false;
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Open from Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return false;
}
s.beginProgress(QString("Opening project from %1...").arg(connector_id));
s.setStatusMessage("Cloud", QString("Browsing %1...").arg(connector_id));
QPointer<SessionState> sguard(&s);
QPointer<QWidget> hguard(&host);
QPointer<ViewportWindow> vguard(&vp);
proc->call("pull_ifcfed_interactive", QJsonValue(),
[sguard, hguard, vguard, connector_id](const QJsonValue& result) {
if (!sguard) return;
sguard->endProgress();
const QString path = result.toObject().value("path").toString();
if (path.isEmpty()) {
if (hguard) {
QMessageBox::warning(hguard, "Open from Cloud",
QString("Connector '%1' returned no path.").arg(connector_id));
}
return;
}
if (hguard && vguard) {
openProjectAt(*sguard, *hguard, *vguard, path);
}
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "pull_ifcfed_interactive from" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->endProgress();
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
return true;
}
bool syncCloudProject(SessionState& s, QWidget& host, ViewportWindow& vp) {
auto* fed = s.federation();
// Per spec, sync has two independent phases — refreshing the .ifcfed
// (requires manifest) and refreshing cloud models (requires any
// non-local source). Either is sufficient.
const bool has_manifest = fed->hasManifest();
bool has_cloud_models = false;
for (const auto& m : fed->models()) {
if (m.source_connector != "local") { has_cloud_models = true; break; }
}
if (!has_manifest && !has_cloud_models) {
QMessageBox::information(&host, "Sync From Cloud",
"Nothing to sync — this project has no cloud resources.");
return false;
}
SceneLoader* loader = s.loader();
if (loader && loader->isLoading()) {
QMessageBox::information(&host, "Sync From Cloud",
"Wait until the current model load finishes before syncing.");
return false;
}
// No manifest: skip the pull_ifcfed phase entirely (spec step 2-4
// skipped). Just refresh cloud-sourced models against the .ifcfed
// already on disk. Federation state is preserved, so no dirty prompt.
if (!has_manifest) {
s.setStatusMessage("Cloud", "Refreshing cloud models...");
resolveCloudModels(s, vp);
return true;
}
// Manifest path: the .ifcfed itself may be replaced. Confirm dirty —
// even though we'll attempt to preserve the session if the returned
// .ifcfed is byte-equal, that's not known until after the round-trip.
if (!confirmDiscardIfDirty(s, host)) return false;
const QString connector_id = fed->manifestConnectorId();
if (connector_id.isEmpty()) {
QMessageBox::warning(&host, "Sync From Cloud",
"The project's manifest does not name a connector.");
return false;
}
auto* registry = s.connectorRegistry();
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Sync From Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return false;
}
s.beginProgress(QString("Syncing from %1...").arg(connector_id));
s.setStatusMessage("Cloud", QString("Syncing from %1...").arg(connector_id));
QPointer<SessionState> sguard(&s);
QPointer<QWidget> hguard(&host);
QPointer<ViewportWindow> vguard(&vp);
const QString current_path = fed->filePath();
proc->call("pull_ifcfed", fed->manifest(),
[sguard, hguard, vguard, connector_id, current_path](const QJsonValue& result) {
if (!sguard) return;
sguard->endProgress();
const QString new_path = result.toObject().value("path").toString();
if (new_path.isEmpty()) {
if (hguard) {
QMessageBox::warning(hguard, "Sync From Cloud",
QString("Connector '%1' returned no path.").arg(connector_id));
}
return;
}
// Per spec: if the returned .ifcfed is unchanged from the one
// already loaded, preserve the current session — just repoint
// if the cache path moved and resync models.
if (isIfcfedUnchanged(current_path, new_path)) {
if (QDir::cleanPath(current_path) != QDir::cleanPath(new_path)) {
sguard->federation()->repointTo(new_path);
}
sguard->setStatusMessage("Cloud",
"Project up to date; refreshing cloud models...");
if (vguard) resolveCloudModels(*sguard, *vguard);
return;
}
// Content differs — fall through to the standard open path,
// which clears the scene and triggers resolveCloudModels for
// any cloud-sourced models in the freshly loaded federation.
if (hguard && vguard) {
openProjectAt(*sguard, *hguard, *vguard, new_path);
}
},
[sguard, connector_id](int code, const QString& message) {
qWarning() << "pull_ifcfed from" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->endProgress();
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
return true;
}
bool saveProject(SessionState& s, QWidget& host) {
if (s.federation()->filePath().isEmpty()) return saveProjectAs(s, host);
return saveProjectTo(s, host, s.federation()->filePath());
}
bool saveProjectAs(SessionState& s, QWidget& host) {
QString suggested = s.federation()->filePath();
if (suggested.isEmpty()) suggested = "project.ifcfed";
QFileDialog file_dialog(&host, "Save Project As", suggested);
file_dialog.setAcceptMode(QFileDialog::AcceptSave);
file_dialog.setFileMode(QFileDialog::AnyFile);
file_dialog.setNameFilter("IFC Federation (*.ifcfed);;All Files (*)");
file_dialog.setOption(QFileDialog::DontUseNativeDialog, true);
if (file_dialog.exec() != QDialog::Accepted) return false;
QString path = file_dialog.selectedFiles().value(0);
if (path.isEmpty()) return false;
if (!path.endsWith(".ifcfed", Qt::CaseInsensitive)) path += ".ifcfed";
return saveProjectTo(s, host, path);
}
namespace {
// Writes the current federation to a fresh QTemporaryDir as a `.ifcfed`
// without touching Federation's state, returning the temp dir (so callers
// can keep it alive through the async RPC) and the resolved file path.
struct TempProjectFile {
std::shared_ptr<QTemporaryDir> dir;
QString path;
};
TempProjectFile writeProjectToTemp(SessionState& s, QWidget& host, const QString& op_title) {
TempProjectFile out;
out.dir = std::make_shared<QTemporaryDir>();
if (!out.dir->isValid()) {
QMessageBox::warning(&host, op_title,
QString("Could not create a temporary directory:\n%1")
.arg(out.dir->errorString()));
out.dir.reset();
return out;
}
const QString name = s.federation()->filePath().isEmpty()
? "project.ifcfed"
: QFileInfo(s.federation()->filePath()).fileName();
const QString tmp_path = QDir(out.dir->path()).filePath(name);
QString err;
if (!s.federation()->writeCopyTo(tmp_path, &err)) {
QMessageBox::warning(&host, op_title,
QString("Failed to write temporary project:\n%1").arg(err));
out.dir.reset();
return out;
}
out.path = tmp_path;
return out;
}
// Shared continuation for push_ifcfed[_interactive]: on success, repoint
// Federation to the returned path and notify; on error, log + status.
void onPushIfcfedResult(SessionState& s,
QWidget& host,
const QString& op_title,
const QString& connector_id,
const QJsonValue& result) {
s.endProgress();
const QString new_path = result.toObject().value("path").toString();
if (new_path.isEmpty()) {
QMessageBox::warning(&host, op_title,
QString("Connector '%1' returned no path.").arg(connector_id));
return;
}
QStringList warnings;
s.federation()->repointTo(new_path, &warnings);
s.setStatusMessage("Cloud",
QString("Saved to %1 via %2")
.arg(QFileInfo(new_path).fileName(), connector_id));
s.notifyProjectSaved(new_path);
}
} // namespace
bool saveCloudProject(SessionState& s, QWidget& host) {
auto* fed = s.federation();
if (!fed->hasManifest()) {
QMessageBox::information(&host, "Save To Cloud",
"This project has no cloud target. Use \"Save As To Cloud\" first.");
return false;
}
const QString connector_id = fed->manifestConnectorId();
auto* registry = s.connectorRegistry();
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Save To Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return false;
}
auto tmp = writeProjectToTemp(s, host, "Save To Cloud");
if (!tmp.dir) return false;
QJsonObject params;
params["path"] = tmp.path;
params["manifest"] = fed->manifest();
s.beginProgress(QString("Saving to %1...").arg(connector_id));
s.setStatusMessage("Cloud", QString("Saving to %1...").arg(connector_id));
QPointer<SessionState> sguard(&s);
QPointer<QWidget> hguard(&host);
proc->call("push_ifcfed", params,
[sguard, hguard, connector_id, tmp_keepalive = tmp.dir](const QJsonValue& result) {
(void)tmp_keepalive;
if (!sguard || !hguard) return;
onPushIfcfedResult(*sguard, *hguard, "Save To Cloud", connector_id, result);
},
[sguard, connector_id, tmp_keepalive = tmp.dir](int code, const QString& message) {
(void)tmp_keepalive;
qWarning() << "push_ifcfed to" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->endProgress();
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
return true;
}
bool saveAsCloudProject(SessionState& s, QWidget& host) {
auto* registry = s.connectorRegistry();
const auto& manifests = registry->available();
if (manifests.empty()) {
QMessageBox::information(&host, "Save As To Cloud",
"No connectors are installed.");
return false;
}
modules::connectors::ConnectorPickerDialog picker(
manifests, "Save As To Cloud",
"Pick a connector to push this project to.", &host);
if (picker.exec() != QDialog::Accepted) return false;
const QString connector_id = picker.selectedId();
if (connector_id.isEmpty()) return false;
auto* proc = registry->get(connector_id);
if (!proc) {
QMessageBox::warning(&host, "Save As To Cloud",
QString("Could not launch connector '%1':\n%2")
.arg(connector_id, registry->lastError()));
return false;
}
auto tmp = writeProjectToTemp(s, host, "Save As To Cloud");
if (!tmp.dir) return false;
QJsonObject params;
params["path"] = tmp.path;
s.beginProgress(QString("Pushing to %1...").arg(connector_id));
s.setStatusMessage("Cloud", QString("Pushing to %1...").arg(connector_id));
QPointer<SessionState> sguard(&s);
QPointer<QWidget> hguard(&host);
proc->call("push_ifcfed_interactive", params,
[sguard, hguard, connector_id, tmp_keepalive = tmp.dir](const QJsonValue& result) {
(void)tmp_keepalive;
if (!sguard || !hguard) return;
onPushIfcfedResult(*sguard, *hguard, "Save As To Cloud", connector_id, result);
},
[sguard, connector_id, tmp_keepalive = tmp.dir](int code, const QString& message) {
(void)tmp_keepalive;
qWarning() << "push_ifcfed_interactive to" << connector_id
<< "failed:" << code << message;
if (sguard) {
sguard->endProgress();
sguard->setStatusMessage("Cloud",
QString("%1 reported an error (see connector UI)").arg(connector_id));
}
});
return true;
}
bool saveProjectDialog(SessionState& s, QWidget& host) {
SaveProjectDialog dialog(s.federation()->hasManifest(), &host);
if (dialog.exec() != QDialog::Accepted) return false;
switch (dialog.selectedTarget()) {
case SaveTarget::Local: return saveProject(s, host);
case SaveTarget::LocalAs: return saveProjectAs(s, host);
case SaveTarget::Cloud: return saveCloudProject(s, host);
case SaveTarget::CloudAs: return saveAsCloudProject(s, host);
case SaveTarget::None: return false;
}
return false;
}
} // namespace bonsaiviewer::modules::project::commands
@@ -0,0 +1,63 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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/>. *
* *
********************************************************************************/
#ifndef IFCINTERFACE_MODULES_PROJECT_COMMANDS_H
#define IFCINTERFACE_MODULES_PROJECT_COMMANDS_H
#include <QString>
class QWidget;
class ViewportWindow;
namespace bonsaiviewer { class SessionState; }
namespace bonsaiviewer::modules::project::commands {
// User-facing commands. Each owns its own dialogs and confirmations; each
// emits exactly one notify() at the end (projectReset / projectOpened /
// projectSaved) so views refresh once per command.
bool newProject(SessionState& s, QWidget& host, ViewportWindow& vp);
bool openProject(SessionState& s, QWidget& host, ViewportWindow& vp);
// Pick a connector, then call pull_ifcfed_interactive and open the resulting
// .ifcfed as a fresh project. Non-local models in the loaded federation are
// resolved asynchronously via pull_models.
bool openCloudProject(SessionState& s, QWidget& host, ViewportWindow& vp);
// pull_ifcfed using the current project's .ifcfed.manifest. Re-downloads
// the .ifcfed from the same cloud target it came from (typically without
// user interaction), then opens it like a fresh project — discarding any
// local edits after the usual dirty-check prompt.
bool syncCloudProject(SessionState& s, QWidget& host, ViewportWindow& vp);
bool saveProject(SessionState& s, QWidget& host);
bool saveProjectAs(SessionState& s, QWidget& host);
// Push the current federation to the cloud target named in its manifest
// (push_ifcfed). No user prompt for destination. Caller is responsible for
// gating this on Federation::hasManifest.
bool saveCloudProject(SessionState& s, QWidget& host);
// Pick a connector and push the current federation to a fresh cloud target
// (push_ifcfed_interactive). The connector returns a new path + manifest;
// Federation repoints to that location.
bool saveAsCloudProject(SessionState& s, QWidget& host);
// Show the four-way Save dialog (Local / Save As Local / To Cloud / Save
// As To Cloud) and dispatch to one of the above. This is what the "Save
// Project" ribbon button is wired to.
bool saveProjectDialog(SessionState& s, QWidget& host);
} // namespace bonsaiviewer::modules::project::commands
#endif
@@ -0,0 +1,148 @@
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* 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 "SaveProjectDialog.h"
#include "../../components/Buttons.h"
#include "../../components/Section.h"
#include "../../components/Style.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QVBoxLayout>
namespace bonsaiviewer::modules::project {
namespace {
class HoverDescriptionFilter : public QObject {
public:
HoverDescriptionFilter(QLabel* label, QString hover_text, QString default_text)
: label_(label), hover_text_(std::move(hover_text)), default_text_(std::move(default_text)) {}
protected:
bool eventFilter(QObject*, QEvent* event) override {
if (event->type() == QEvent::Enter) label_->setText(hover_text_);
else if (event->type() == QEvent::Leave) label_->setText(default_text_);
return false;
}
private:
QLabel* label_ = nullptr;
QString hover_text_;
QString default_text_;
};
} // namespace
SaveProjectDialog::SaveProjectDialog(bool has_manifest, QWidget* parent)
: components::Dialog(parent)
{
setObjectName("appDialog");
setWindowTitle("Save Project");
setModal(true);
setupUi(has_manifest);
}
void SaveProjectDialog::setupUi(bool has_manifest) {
if (auto* root = qobject_cast<QVBoxLayout*>(layout())) {
root->setSizeConstraint(QLayout::SetFixedSize);
}
const QString default_description = "Choose where to save this project";
auto* description_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* description = new QLabel(default_description, description_section);
description->setProperty("textRole", "secondary");
description->setWordWrap(true);
description->setAlignment(Qt::AlignCenter);
description->setMinimumWidth((90 * 4) + (components::style::metrics::padding * 3));
description->setMinimumHeight(description->fontMetrics().lineSpacing() * 2 + 4);
description_section->addBodyWidget(description);
auto* choices_section = new components::Section("", components::SectionHeaderMode::Hidden, this);
auto* choices = new QWidget(choices_section);
auto* row = new QHBoxLayout(choices);
row->setContentsMargins(0, 0, 0, 0);
row->setSpacing(components::style::metrics::padding);
auto* save_local = components::buttons::makeButton(
"Save Local", ":/icons/floppy-disk.svg", choices);
connect(save_local, &QToolButton::clicked, this, [this]() {
selected_target_ = SaveTarget::Local;
accept();
});
save_local->installEventFilter(new HoverDescriptionFilter(
description,
"Save to the project's current file on disk (prompts for a path if none).",
default_description));
auto* save_as_local = components::buttons::makeButton(
"Save As\nLocal", ":/icons/floppy-disk-arrow-in.svg", choices);
connect(save_as_local, &QToolButton::clicked, this, [this]() {
selected_target_ = SaveTarget::LocalAs;
accept();
});
save_as_local->installEventFilter(new HoverDescriptionFilter(
description,
"Save the project to a new file on disk.",
default_description));
auto* save_cloud = components::buttons::makeButton(
"Save To\nCloud", ":/icons/cloud-square.svg", choices);
save_cloud->setEnabled(has_manifest);
if (!has_manifest) {
save_cloud->setToolTip(
"This project has no cloud target yet. Use \"Save As To Cloud\" first.");
}
connect(save_cloud, &QToolButton::clicked, this, [this]() {
selected_target_ = SaveTarget::Cloud;
accept();
});
save_cloud->installEventFilter(new HoverDescriptionFilter(
description,
has_manifest
? "Push back to the cloud location this project came from."
: "Disabled until this project has a cloud target (use Save As To Cloud).",
default_description));
auto* save_as_cloud = components::buttons::makeButton(
"Save As\nTo Cloud", ":/icons/cloud-square.svg", choices);
connect(save_as_cloud, &QToolButton::clicked, this, [this]() {
selected_target_ = SaveTarget::CloudAs;
accept();
});
save_as_cloud->installEventFilter(new HoverDescriptionFilter(
description,
"Pick a connector and push this project to a fresh cloud location.",
default_description));
row->addWidget(components::buttons::makeButtonGroup(
"LOCAL", {save_local, save_as_local}, choices, true, 8));
row->addWidget(components::buttons::makeButtonGroup(
"CLOUD", {save_cloud, save_as_cloud}, choices, false, 8));
choices_section->addBodyWidget(choices);
addBodyWidget(description_section);
addBodyWidget(choices_section);
}
} // namespace bonsaiviewer::modules::project

Some files were not shown because too many files have changed in this diff Show More