Files
IfcOpenShell/src/ifcviewer-full/modules/models/View.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
4.9 KiB
C++
Raw Normal View History

2026-05-09 22:00:19 +10:00
// 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 "Panel.h"
2026-05-15 07:22:31 +10:00
#include "../../ViewerSettings.h"
2026-05-09 22:00:19 +10:00
#include "../../SessionState.h"
#include "../../../ifcviewer/Federation.h"
2026-05-15 07:22:31 +10:00
namespace ifcviewerfull::modules::models {
2026-05-09 22:00:19 +10:00
namespace {
TreeNode makeGroupNode(const Federation* federation, const Federation::Group* group) {
TreeNode node;
node.id = group->id;
node.name = group->display_name;
node.kind = ItemKind::Group;
node.visible = group->visible;
for (const auto& child_group : group->children) {
node.children.append(makeGroupNode(federation, child_group.get()));
}
for (const auto& model : federation->models()) {
if (model.group_id != group->id) continue;
node.children.append({
model.id,
model.display_name,
ItemKind::Model,
federation->isModelEffectivelyVisible(model.id),
{}
});
}
return node;
}
2026-05-15 17:08:08 +10:00
// Walks the federation's group tree, appending every group except those under
// exclude_subtree_root (used to prevent a group from being moved into itself).
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);
}
}
2026-05-09 22:00:19 +10:00
} // namespace
ModelsPanelView::ModelsPanelView(ModelsPanel* widget,
2026-05-15 07:22:31 +10:00
ifcviewerfull::SessionState* session_state,
2026-05-09 22:00:19 +10:00
QObject* parent)
2026-05-15 17:08:08 +10:00
: QObject(parent)
, widget_(widget)
, session_state_(session_state)
2026-05-09 22:00:19 +10:00
{
2026-05-15 17:08:08 +10:00
connect(session_state_, &SessionState::modelsChanged, this, &ModelsPanelView::refresh);
connect(session_state_, &SessionState::federationChanged, this, &ModelsPanelView::refresh);
connect(session_state_, &SessionState::visibilityChanged, this, &ModelsPanelView::refresh);
connect(session_state_, &SessionState::projectReset, this, &ModelsPanelView::refresh);
connect(session_state_, &SessionState::projectOpened, this, [this](const QString&) { refresh(); });
2026-05-15 07:22:31 +10:00
connect(&ifcviewerfull::ViewerSettings::instance(),
&ifcviewerfull::ViewerSettings::themeChanged,
2026-05-15 17:08:08 +10:00
this, &ModelsPanelView::refresh);
widget_->setGroupListProvider([this](const QString& exclude_subtree_root) {
return groupListForMove(exclude_subtree_root);
});
2026-05-09 22:00:19 +10:00
2026-05-15 17:08:08 +10:00
refresh();
2026-05-09 22:00:19 +10:00
}
2026-05-15 17:08:08 +10:00
void ModelsPanelView::refresh() {
2026-05-09 22:00:19 +10:00
Federation* federation = session_state_->federation();
QList<TreeNode> nodes;
for (const auto& root_group : federation->rootGroups()) {
nodes.append(makeGroupNode(federation, root_group.get()));
}
for (const auto& model : federation->models()) {
if (!model.group_id.isEmpty()) continue;
nodes.append({
model.id,
model.display_name,
ItemKind::Model,
federation->isModelEffectivelyVisible(model.id),
{}
});
}
widget_->setNodes(nodes);
}
2026-05-15 17:08:08 +10:00
QList<GroupOption> ModelsPanelView::groupListForMove(const QString& exclude_subtree_root) const {
QList<GroupOption> out;
for (const auto& root : session_state_->federation()->rootGroups()) {
collectGroupsRecursive(root.get(), exclude_subtree_root, out);
}
return out;
}
2026-05-15 07:22:31 +10:00
} // namespace ifcviewerfull::modules::models