mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
spatial hierarchy from IFC + active-model concept
Build the spatial hierarchy panel from the loaded model's real IFC spatial structure instead of mock data: - helpers/element: add get_spatial_children (IsDecomposedBy -> RelatedObjects, filtered to spatial elements) to walk IfcProject -> IfcSite -> IfcBuilding -> IfcBuildingStorey -> IfcSpace. - SessionState: relay dataSourceReady as modelDataSourceReady (the .ifc for a sidecar hit loads asynchronously, so the tree can only build once it arrives). - spatial_hierarchy/View: walk the active model's IFC file into a TreeNode tree, naming nodes by Name (fallback to class), mapping site/building/storey kinds; siblings sorted with natural (numeric) collation. - spatial_hierarchy/Panel: tree now fills the panel height (setBodyExpanding + Expanding size policy); right-click menu for recursive Expand/Collapse Subtree and Expand/Collapse All. Add the concept of an active model: - SessionState: activeModelId / setActiveModelId / activeModelChanged; the first loaded model is active by default; reassigns/clears on removal. - Models panel: clicking a model makes it active; its cube icon is drawn with the accent colour (makeAccentSvgIcon) via FederationItemModel::setActiveModelId. - The spatial hierarchy reflects only the active model. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -159,6 +159,25 @@ express::Base get_aggregate_s(const express::Base& element) {
|
||||
return relationship.RelatingObject();
|
||||
}
|
||||
|
||||
// The spatial-structure children aggregated under this element (IsDecomposedBy →
|
||||
// RelatedObjects, filtered to spatial elements).
|
||||
template <typename Schema>
|
||||
std::vector<express::Base> get_spatial_children_s(const express::Base& element) {
|
||||
std::vector<express::Base> children;
|
||||
const auto object = element.template as<typename Schema::IfcObjectDefinition>();
|
||||
if (!object) {
|
||||
return children;
|
||||
}
|
||||
for (const auto& relationship : object.IsDecomposedBy()) {
|
||||
for (const auto& related : relationship.RelatedObjects()) {
|
||||
if (related.template as<typename Schema::IfcSpatialStructureElement>()) {
|
||||
children.push_back(related);
|
||||
}
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
// ifcopenshell.util.element.get_container (should_get_direct=false, no
|
||||
// ifc_class): the directly containing spatial element, or the container of the
|
||||
// aggregate parent for an aggregated part.
|
||||
@@ -239,6 +258,20 @@ express::Base get_container(const express::Base& element) {
|
||||
unsupported_schema(name);
|
||||
}
|
||||
|
||||
std::vector<express::Base> get_spatial_children(const express::Base& element) {
|
||||
if (!element) {
|
||||
return {};
|
||||
}
|
||||
const std::string name = schema_name(element);
|
||||
#define IFCOPENSHELL_DISPATCH(Schema, Identifier) \
|
||||
if (name == Identifier) { \
|
||||
return get_spatial_children_s<Schema>(element); \
|
||||
}
|
||||
IFCOPENSHELL_HELPER_FOR_EACH_SCHEMA(IFCOPENSHELL_DISPATCH)
|
||||
#undef IFCOPENSHELL_DISPATCH
|
||||
unsupported_schema(name);
|
||||
}
|
||||
|
||||
// getattr(element, name) for a string- or enum-valued attribute. Reads by name,
|
||||
// so it works uniformly across the various subtypes that carry a given
|
||||
// attribute (PredefinedType, Name, ...).
|
||||
|
||||
Reference in New Issue
Block a user