mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
refactor structural module - wip - structural analysis models #1848
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||||
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||||
|
#
|
||||||
|
# This file is part of BlenderBIM Add-on.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
import blenderbim.tool as tool
|
||||||
|
|
||||||
|
|
||||||
|
def refresh():
|
||||||
|
StructuralData.is_loaded = False
|
||||||
|
|
||||||
|
|
||||||
|
class StructuralData:
|
||||||
|
products = {}
|
||||||
|
number_of_structural_analysis_models = 0
|
||||||
|
is_loaded = False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load(cls):
|
||||||
|
cls.load_structural_analysis_models()
|
||||||
|
cls.is_loaded = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load_structural_analysis_models(cls):
|
||||||
|
cls.products = {}
|
||||||
|
cls.number_of_structural_analysis_models = len(tool.Ifc.get().by_type("IfcStructuralAnalysisModel"))
|
||||||
|
|
||||||
|
for model in tool.Ifc.get().by_type("IfcStructuralAnalysisModel"):
|
||||||
|
if model.IsGroupedBy:
|
||||||
|
for rel in model.IsGroupedBy:
|
||||||
|
for product in rel.RelatedObjects:
|
||||||
|
cls.products.setdefault(product.id(), []).append(model.id())
|
||||||
@@ -21,6 +21,8 @@ import json
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import blenderbim.bim.helper
|
import blenderbim.bim.helper
|
||||||
|
import blenderbim.bim.handler
|
||||||
|
import blenderbim.core.structural as core
|
||||||
import blenderbim.tool as tool
|
import blenderbim.tool as tool
|
||||||
import blenderbim.core.context
|
import blenderbim.core.context
|
||||||
from math import degrees
|
from math import degrees
|
||||||
@@ -29,6 +31,14 @@ from blenderbim.bim.ifc import IfcStore
|
|||||||
from blenderbim.bim.module.structural.prop import purge
|
from blenderbim.bim.module.structural.prop import purge
|
||||||
from ifcopenshell.api.structural.data import Data
|
from ifcopenshell.api.structural.data import Data
|
||||||
from ifcopenshell.api.context.data import Data as ContextData
|
from ifcopenshell.api.context.data import Data as ContextData
|
||||||
|
from blenderbim.bim.module.structural.data import StructuralData
|
||||||
|
|
||||||
|
|
||||||
|
class Operator:
|
||||||
|
def execute(self, context):
|
||||||
|
IfcStore.execute_ifc_operator(self, context)
|
||||||
|
blenderbim.bim.handler.refresh_ui_data()
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AddStructuralMemberConnection(bpy.types.Operator):
|
class AddStructuralMemberConnection(bpy.types.Operator):
|
||||||
@@ -233,198 +243,102 @@ class DisableEditingStructuralBoundaryCondition(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class LoadStructuralAnalysisModels(bpy.types.Operator):
|
class LoadStructuralAnalysisModels(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.load_structural_analysis_models"
|
bl_idname = "bim.load_structural_analysis_models"
|
||||||
bl_label = "Load Structural Analysis Models"
|
bl_label = "Load Structural Analysis Models"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMStructuralProperties
|
core.load_structural_analysis_models(tool.Structural)
|
||||||
props.structural_analysis_models.clear()
|
|
||||||
for ifc_definition_id, structural_analysis_model in Data.structural_analysis_models.items():
|
|
||||||
new = props.structural_analysis_models.add()
|
|
||||||
new.ifc_definition_id = ifc_definition_id
|
|
||||||
new.name = structural_analysis_model["Name"] or "Unnamed"
|
|
||||||
props.is_editing = True
|
|
||||||
bpy.ops.bim.disable_editing_structural_analysis_model()
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class DisableStructuralAnalysisModelEditingUI(bpy.types.Operator):
|
class DisableStructuralAnalysisModelEditingUI(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.disable_structural_analysis_model_editing_ui"
|
bl_idname = "bim.disable_structural_analysis_model_editing_ui"
|
||||||
bl_label = "Disable Structural Analysis Model Editing UI"
|
bl_label = "Disable Structural Analysis Model Editing UI"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
context.scene.BIMStructuralProperties.is_editing = False
|
core.disable_structural_analysis_model_editing_ui(tool.Structural)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class AddStructuralAnalysisModel(bpy.types.Operator):
|
class AddStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.add_structural_analysis_model"
|
bl_idname = "bim.add_structural_analysis_model"
|
||||||
bl_label = "Add Structural Analysis Model"
|
bl_label = "Add Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
result = ifcopenshell.api.run("structural.add_structural_analysis_model", IfcStore.get_file())
|
model = core.add_structural_analysis_model(tool.Ifc, tool.Structural)
|
||||||
|
core.load_structural_analysis_model_attributes(tool.Structural, model=model.id())
|
||||||
model = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model")
|
core.enable_editing_structural_analysis_model(tool.Structural, model=model.id())
|
||||||
if not model:
|
|
||||||
model = blenderbim.core.context.add_context(
|
|
||||||
tool.Ifc, context_type="Model", context_identifier="", target_view="", parent=0
|
|
||||||
)
|
|
||||||
graph = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Reference", "GRAPH_VIEW")
|
|
||||||
if not graph:
|
|
||||||
model = blenderbim.core.context.add_context(
|
|
||||||
tool.Ifc, context_type="Model", context_identifier="Reference", target_view="GRAPH_VIEW", parent=model
|
|
||||||
)
|
|
||||||
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
bpy.ops.bim.load_structural_analysis_models()
|
|
||||||
bpy.ops.bim.enable_editing_structural_analysis_model(structural_analysis_model=result.id())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EditStructuralAnalysisModel(bpy.types.Operator):
|
class EditStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.edit_structural_analysis_model"
|
bl_idname = "bim.edit_structural_analysis_model"
|
||||||
bl_label = "Edit Structural Analysis Model"
|
bl_label = "Edit Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMStructuralProperties
|
core.edit_structural_analysis_model(tool.Ifc, tool.Structural)
|
||||||
attributes = blenderbim.bim.helper.export_attributes(props.structural_analysis_model_attributes)
|
|
||||||
self.file = IfcStore.get_file()
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"structural.edit_structural_analysis_model",
|
|
||||||
self.file,
|
|
||||||
**{
|
|
||||||
"structural_analysis_model": self.file.by_id(props.active_structural_analysis_model_id),
|
|
||||||
"attributes": attributes,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
bpy.ops.bim.load_structural_analysis_models()
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class RemoveStructuralAnalysisModel(bpy.types.Operator):
|
class RemoveStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.remove_structural_analysis_model"
|
bl_idname = "bim.remove_structural_analysis_model"
|
||||||
bl_label = "Remove Structural Analysis Model"
|
bl_label = "Remove Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
structural_analysis_model: bpy.props.IntProperty()
|
structural_analysis_model: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMStructuralProperties
|
core.remove_structural_analysis_model(tool.Ifc, tool.Structural, model=self.structural_analysis_model)
|
||||||
self.file = IfcStore.get_file()
|
|
||||||
ifcopenshell.api.run(
|
|
||||||
"structural.remove_structural_analysis_model",
|
|
||||||
self.file,
|
|
||||||
**{"structural_analysis_model": self.file.by_id(self.structural_analysis_model)},
|
|
||||||
)
|
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
bpy.ops.bim.load_structural_analysis_models()
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingStructuralAnalysisModel(bpy.types.Operator):
|
class EnableEditingStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.enable_editing_structural_analysis_model"
|
bl_idname = "bim.enable_editing_structural_analysis_model"
|
||||||
bl_label = "Enable Editing Structural Analysis Model"
|
bl_label = "Enable Editing Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
structural_analysis_model: bpy.props.IntProperty()
|
structural_analysis_model: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
props = context.scene.BIMStructuralProperties
|
core.load_structural_analysis_model_attributes(tool.Structural, model=self.structural_analysis_model)
|
||||||
props.structural_analysis_model_attributes.clear()
|
core.enable_editing_structural_analysis_model(tool.Structural, model=self.structural_analysis_model)
|
||||||
|
|
||||||
data = Data.structural_analysis_models[self.structural_analysis_model]
|
|
||||||
|
|
||||||
for attribute in IfcStore.get_schema().declaration_by_name("IfcStructuralAnalysisModel").all_attributes():
|
|
||||||
data_type = str(attribute.type_of_attribute)
|
|
||||||
if "<entity" in data_type:
|
|
||||||
continue
|
|
||||||
new = props.structural_analysis_model_attributes.add()
|
|
||||||
new.name = attribute.name()
|
|
||||||
new.is_null = data[attribute.name()] is None
|
|
||||||
new.is_optional = attribute.optional()
|
|
||||||
if attribute.name() == "PredefinedType":
|
|
||||||
new.enum_items = json.dumps(attribute.type_of_attribute().declared_type().enumeration_items())
|
|
||||||
new.data_type = "enum"
|
|
||||||
if data[attribute.name()]:
|
|
||||||
new.enum_value = data[attribute.name()]
|
|
||||||
else:
|
|
||||||
new.string_value = "" if new.is_null else data[attribute.name()]
|
|
||||||
new.data_type = "string"
|
|
||||||
props.active_structural_analysis_model_id = self.structural_analysis_model
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class DisableEditingStructuralAnalysisModel(bpy.types.Operator):
|
class DisableEditingStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.disable_editing_structural_analysis_model"
|
bl_idname = "bim.disable_editing_structural_analysis_model"
|
||||||
bl_label = "Disable Editing Structural Analysis Model"
|
bl_label = "Disable Editing Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def execute(self, context):
|
def _execute(self, context):
|
||||||
context.scene.BIMStructuralProperties.active_structural_analysis_model_id = 0
|
core.disable_editing_structural_analysis_model(tool.Structural)
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class AssignStructuralAnalysisModel(bpy.types.Operator):
|
class AssignStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.assign_structural_analysis_model"
|
bl_idname = "bim.assign_structural_analysis_model"
|
||||||
bl_label = "Assign Structural Analysis Model"
|
bl_label = "Assign Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
product: bpy.props.StringProperty()
|
product: bpy.props.StringProperty()
|
||||||
structural_analysis_model: bpy.props.IntProperty()
|
structural_analysis_model: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
product = bpy.data.objects.get(self.product) if self.product else context.active_object
|
core.assign_structural_analysis_model(
|
||||||
self.file = IfcStore.get_file()
|
tool.Ifc, tool.Structural,
|
||||||
ifcopenshell.api.run(
|
product=self.product,
|
||||||
"structural.assign_structural_analysis_model",
|
structural_analysis_model=self.structural_analysis_model
|
||||||
self.file,
|
|
||||||
**{
|
|
||||||
"product": self.file.by_id(product.BIMObjectProperties.ifc_definition_id),
|
|
||||||
"structural_analysis_model": self.file.by_id(self.structural_analysis_model),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class UnassignStructuralAnalysisModel(bpy.types.Operator):
|
class UnassignStructuralAnalysisModel(bpy.types.Operator, Operator):
|
||||||
bl_idname = "bim.unassign_structural_analysis_model"
|
bl_idname = "bim.unassign_structural_analysis_model"
|
||||||
bl_label = "Unassign Structural Analysis Model"
|
bl_label = "Unassign Structural Analysis Model"
|
||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
product: bpy.props.StringProperty()
|
product: bpy.props.StringProperty()
|
||||||
structural_analysis_model: bpy.props.IntProperty()
|
structural_analysis_model: bpy.props.IntProperty()
|
||||||
|
|
||||||
def execute(self, context):
|
|
||||||
return IfcStore.execute_ifc_operator(self, context)
|
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
product = bpy.data.objects.get(self.product) if self.product else context.active_object
|
core.unassign_structural_analysis_model(
|
||||||
self.file = IfcStore.get_file()
|
tool.Ifc, tool.Structural,
|
||||||
ifcopenshell.api.run(
|
product=self.product,
|
||||||
"structural.unassign_structural_analysis_model",
|
structural_analysis_model=self.structural_analysis_model
|
||||||
self.file,
|
|
||||||
**{
|
|
||||||
"product": self.file.by_id(product.BIMObjectProperties.ifc_definition_id),
|
|
||||||
"structural_analysis_model": self.file.by_id(self.structural_analysis_model),
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
Data.load(IfcStore.get_file())
|
|
||||||
return {"FINISHED"}
|
|
||||||
|
|
||||||
|
|
||||||
class EnableEditingStructuralItemAxis(bpy.types.Operator):
|
class EnableEditingStructuralItemAxis(bpy.types.Operator):
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ from bpy.types import Panel, UIList
|
|||||||
from blenderbim.bim.ifc import IfcStore
|
from blenderbim.bim.ifc import IfcStore
|
||||||
from blenderbim.bim.helper import draw_attributes
|
from blenderbim.bim.helper import draw_attributes
|
||||||
from ifcopenshell.api.structural.data import Data
|
from ifcopenshell.api.structural.data import Data
|
||||||
|
from blenderbim.bim.module.structural.data import StructuralData
|
||||||
|
|
||||||
|
|
||||||
def draw_boundary_condition_ui(layout, boundary_condition_id, connection_id, props):
|
def draw_boundary_condition_ui(layout, boundary_condition_id, connection_id, props):
|
||||||
@@ -284,13 +285,14 @@ class BIM_PT_structural_analysis_models(Panel):
|
|||||||
return file and hasattr(file, "schema") and file.schema != "IFC2X3"
|
return file and hasattr(file, "schema") and file.schema != "IFC2X3"
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
if not Data.is_loaded:
|
if not StructuralData.is_loaded:
|
||||||
Data.load(IfcStore.get_file())
|
StructuralData.load()
|
||||||
self.props = context.scene.BIMStructuralProperties
|
self.props = context.scene.BIMStructuralProperties
|
||||||
|
|
||||||
row = self.layout.row(align=True)
|
row = self.layout.row(align=True)
|
||||||
row.label(
|
row.label(
|
||||||
text="{} Structural Analysis Models Found".format(len(Data.structural_analysis_models)), icon="MOD_SIMPLIFY"
|
text="{} Structural Analysis Models Found".format(StructuralData.number_of_structural_analysis_models),
|
||||||
|
icon="MOD_SIMPLIFY",
|
||||||
)
|
)
|
||||||
if self.props.is_editing:
|
if self.props.is_editing:
|
||||||
row.operator("bim.add_structural_analysis_model", text="", icon="ADD")
|
row.operator("bim.add_structural_analysis_model", text="", icon="ADD")
|
||||||
@@ -324,8 +326,8 @@ class BIM_UL_structural_analysis_models(UIList):
|
|||||||
if context.active_object:
|
if context.active_object:
|
||||||
oprops = context.active_object.BIMObjectProperties
|
oprops = context.active_object.BIMObjectProperties
|
||||||
if (
|
if (
|
||||||
oprops.ifc_definition_id in Data.products
|
oprops.ifc_definition_id in StructuralData.products
|
||||||
and item.ifc_definition_id in Data.products[oprops.ifc_definition_id]
|
and item.ifc_definition_id in StructuralData.products[oprops.ifc_definition_id]
|
||||||
):
|
):
|
||||||
op = row.operator(
|
op = row.operator(
|
||||||
"bim.unassign_structural_analysis_model", text="", icon="KEYFRAME_HLT", emboss=False
|
"bim.unassign_structural_analysis_model", text="", icon="KEYFRAME_HLT", emboss=False
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||||
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||||
|
#
|
||||||
|
# This file is part of BlenderBIM Add-on.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
def add_structural_analysis_model(ifc, structural):
|
||||||
|
result = ifc.run("structural.add_structural_analysis_model")
|
||||||
|
structural.load_structural_analysis_models()
|
||||||
|
structural.ensure_representation_contexts()
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def assign_structural_analysis_model(ifc, structural, product=None, structural_analysis_model=None):
|
||||||
|
product = structural.get_product_or_active_object(product)
|
||||||
|
if structural_analysis_model and product:
|
||||||
|
ifc.run(
|
||||||
|
"structural.assign_structural_analysis_model",
|
||||||
|
**{
|
||||||
|
"product": ifc.get().by_id(product.BIMObjectProperties.ifc_definition_id),
|
||||||
|
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def disable_editing_structural_analysis_model(structural):
|
||||||
|
structural.disable_editing_structural_analysis_model()
|
||||||
|
|
||||||
|
|
||||||
|
def disable_structural_analysis_model_editing_ui(structural):
|
||||||
|
structural.disable_structural_analysis_model_editing_ui()
|
||||||
|
|
||||||
|
|
||||||
|
def edit_structural_analysis_model(ifc, structural):
|
||||||
|
attributes = structural.get_structural_analysis_model_attributes()
|
||||||
|
ifc.run(
|
||||||
|
"structural.edit_structural_analysis_model",
|
||||||
|
**{
|
||||||
|
"structural_analysis_model": structural.get_active_structural_analysis_model(),
|
||||||
|
"attributes": attributes,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
structural.load_structural_analysis_models()
|
||||||
|
structural.disable_editing_structural_analysis_model()
|
||||||
|
|
||||||
|
|
||||||
|
def enable_editing_structural_analysis_model(structural, model=None):
|
||||||
|
structural.enable_editing_structural_analysis_model(model)
|
||||||
|
|
||||||
|
|
||||||
|
def enable_structural_analysis_model_editing_ui(structural):
|
||||||
|
structural.enable_structural_analysis_model_editing_ui()
|
||||||
|
|
||||||
|
|
||||||
|
def load_structural_analysis_model_attributes(structural, model=None):
|
||||||
|
data = structural.get_ifc_structural_analysis_model_attributes(model)
|
||||||
|
structural.load_structural_analysis_model_attributes(data)
|
||||||
|
|
||||||
|
|
||||||
|
def load_structural_analysis_models(structural):
|
||||||
|
structural.load_structural_analysis_models()
|
||||||
|
structural.enable_structural_analysis_model_editing_ui()
|
||||||
|
# structural.disable_editing_structural_analysis_model()
|
||||||
|
|
||||||
|
|
||||||
|
def remove_structural_analysis_model(ifc, structural, model=None):
|
||||||
|
ifc.run(
|
||||||
|
"structural.remove_structural_analysis_model",
|
||||||
|
**{"structural_analysis_model": ifc.get().by_id(model)},
|
||||||
|
)
|
||||||
|
structural.load_structural_analysis_models()
|
||||||
|
|
||||||
|
|
||||||
|
def unassign_structural_analysis_model(ifc, structural, product=None, structural_analysis_model=None):
|
||||||
|
product = structural.get_product_or_active_object(product)
|
||||||
|
if structural_analysis_model and product:
|
||||||
|
ifc.run(
|
||||||
|
"structural.unassign_structural_analysis_model",
|
||||||
|
**{
|
||||||
|
"product": ifc.get().by_id(product.BIMObjectProperties.ifc_definition_id),
|
||||||
|
"structural_analysis_model": ifc.get().by_id(structural_analysis_model),
|
||||||
|
},
|
||||||
|
)
|
||||||
@@ -255,6 +255,23 @@ class Spatial:
|
|||||||
def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): pass
|
def set_relative_object_matrix(cls, target_obj, relative_to_obj, matrix): pass
|
||||||
|
|
||||||
|
|
||||||
|
@interface
|
||||||
|
class Structural:
|
||||||
|
def disable_editing_structural_analysis_model(cls): pass
|
||||||
|
def disable_structural_analysis_model_editing_ui(cls): pass
|
||||||
|
def enable_editing_structural_analysis_model(cls, model): pass
|
||||||
|
def enable_structural_analysis_model_editing_ui(cls): pass
|
||||||
|
def enabled_structural_analysis_model_editing_ui(cls): pass
|
||||||
|
def ensure_representation_contexts(cls): pass
|
||||||
|
def get_active_structural_analysis_model(cls): pass
|
||||||
|
def get_ifc_structural_analysis_model_attributes(cls, model): pass
|
||||||
|
def get_ifc_structural_analysis_models(cls): pass
|
||||||
|
def get_product_or_active_object(cls): pass
|
||||||
|
def get_structural_analysis_model_attributes(cls): pass
|
||||||
|
def load_structural_analysis_model_attributes(cls, data): pass
|
||||||
|
def load_structural_analysis_models(cls): pass
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
class Style:
|
class Style:
|
||||||
def disable_editing(cls, obj): pass
|
def disable_editing(cls, obj): pass
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from blenderbim.tool.pset import Pset
|
|||||||
from blenderbim.tool.qto import Qto
|
from blenderbim.tool.qto import Qto
|
||||||
from blenderbim.tool.root import Root
|
from blenderbim.tool.root import Root
|
||||||
from blenderbim.tool.spatial import Spatial
|
from blenderbim.tool.spatial import Spatial
|
||||||
|
from blenderbim.tool.structural import Structural
|
||||||
from blenderbim.tool.style import Style
|
from blenderbim.tool.style import Style
|
||||||
from blenderbim.tool.surveyor import Surveyor
|
from blenderbim.tool.surveyor import Surveyor
|
||||||
from blenderbim.tool.type import Type
|
from blenderbim.tool.type import Type
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
# BlenderBIM Add-on - OpenBIM Blender Add-on
|
||||||
|
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
|
||||||
|
#
|
||||||
|
# This file is part of BlenderBIM Add-on.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# BlenderBIM Add-on is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
import ifcopenshell
|
||||||
|
import json
|
||||||
|
import blenderbim.bim.helper
|
||||||
|
import blenderbim.core.tool
|
||||||
|
import blenderbim.core.structural
|
||||||
|
import blenderbim.tool as tool
|
||||||
|
from blenderbim.bim.ifc import IfcStore
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
|
class Structural(blenderbim.core.tool.Structural):
|
||||||
|
@classmethod
|
||||||
|
def disable_editing_structural_analysis_model(cls):
|
||||||
|
bpy.context.scene.BIMStructuralProperties.active_structural_analysis_model_id = 0
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def disable_structural_analysis_model_editing_ui(cls):
|
||||||
|
bpy.context.scene.BIMStructuralProperties.is_editing = False
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def enable_editing_structural_analysis_model(cls, model):
|
||||||
|
if model:
|
||||||
|
bpy.context.scene.BIMStructuralProperties.active_structural_analysis_model_id = model
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def enable_structural_analysis_model_editing_ui(cls):
|
||||||
|
bpy.context.scene.BIMStructuralProperties.is_editing = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def enabled_structural_analysis_model_editing_ui(cls):
|
||||||
|
return bpy.context.scene.BIMStructuralProperties.is_editing
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def ensure_representation_contexts(cls):
|
||||||
|
model = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model")
|
||||||
|
if not model:
|
||||||
|
model = tool.Ifc.run(
|
||||||
|
"context.add_context",
|
||||||
|
context_type="Model",
|
||||||
|
context_identifier="",
|
||||||
|
target_view="",
|
||||||
|
parent=0,
|
||||||
|
)
|
||||||
|
graph = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Reference", "GRAPH_VIEW")
|
||||||
|
if not graph:
|
||||||
|
model = tool.Ifc.run(
|
||||||
|
"context.add_context",
|
||||||
|
context_type="Model",
|
||||||
|
context_identifier="Reference",
|
||||||
|
target_view="GRAPH_VIEW",
|
||||||
|
parent=model,
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_active_structural_analysis_model(cls):
|
||||||
|
props = bpy.context.scene.BIMStructuralProperties
|
||||||
|
model = tool.Ifc.get().by_id(props.active_structural_analysis_model_id)
|
||||||
|
return model
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_ifc_structural_analysis_model_attributes(cls, model):
|
||||||
|
if model:
|
||||||
|
ifc_model = tool.Ifc.get().by_id(model)
|
||||||
|
data = ifc_model.get_info()
|
||||||
|
|
||||||
|
del data["OwnerHistory"]
|
||||||
|
|
||||||
|
loaded_by = []
|
||||||
|
for load_group in ifc_model.LoadedBy or []:
|
||||||
|
loaded_by.append(load_group.id())
|
||||||
|
data["LoadedBy"] = loaded_by
|
||||||
|
|
||||||
|
has_results = []
|
||||||
|
for result_group in ifc_model.HasResults or []:
|
||||||
|
has_results.append(result_group.id())
|
||||||
|
data["HasResults"] = has_results
|
||||||
|
|
||||||
|
data["OrientationOf2DPlane"] = (
|
||||||
|
ifc_model.OrientationOf2DPlane.id() if ifc_model.OrientationOf2DPlane else None
|
||||||
|
)
|
||||||
|
data["SharedPlacement"] = ifc_model.SharedPlacement.id() if ifc_model.SharedPlacement else None
|
||||||
|
return data
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_ifc_structural_analysis_models(cls):
|
||||||
|
models = {}
|
||||||
|
for model in tool.Ifc.get().by_type("IfcStructuralAnalysisModel"):
|
||||||
|
models[model.id()] = {"Name": model.Name}
|
||||||
|
return models
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_product_or_active_object(cls, product):
|
||||||
|
product = bpy.data.objects.get(product) if product else bpy.context.active_object
|
||||||
|
try:
|
||||||
|
if product.BIMObjectProperties.ifc_definition_id:
|
||||||
|
return product
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_structural_analysis_model_attributes(cls):
|
||||||
|
props = bpy.context.scene.BIMStructuralProperties
|
||||||
|
attributes = blenderbim.bim.helper.export_attributes(props.structural_analysis_model_attributes)
|
||||||
|
return attributes
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load_structural_analysis_model_attributes(cls, data):
|
||||||
|
props = bpy.context.scene.BIMStructuralProperties
|
||||||
|
props.structural_analysis_model_attributes.clear()
|
||||||
|
for attribute in IfcStore.get_schema().declaration_by_name("IfcStructuralAnalysisModel").all_attributes():
|
||||||
|
data_type = str(attribute.type_of_attribute)
|
||||||
|
if "<entity" in data_type:
|
||||||
|
continue
|
||||||
|
new = props.structural_analysis_model_attributes.add()
|
||||||
|
new.name = attribute.name()
|
||||||
|
new.is_null = data[attribute.name()] is None
|
||||||
|
new.is_optional = attribute.optional()
|
||||||
|
if attribute.name() == "PredefinedType":
|
||||||
|
new.enum_items = json.dumps(attribute.type_of_attribute().declared_type().enumeration_items())
|
||||||
|
new.data_type = "enum"
|
||||||
|
if data[attribute.name()]:
|
||||||
|
new.enum_value = data[attribute.name()]
|
||||||
|
else:
|
||||||
|
new.string_value = "" if new.is_null else data[attribute.name()]
|
||||||
|
new.data_type = "string"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def load_structural_analysis_models(cls):
|
||||||
|
models = tool.Structural.get_ifc_structural_analysis_models()
|
||||||
|
props = bpy.context.scene.BIMStructuralProperties
|
||||||
|
props.structural_analysis_models.clear()
|
||||||
|
for ifc_definition_id, model in models.items():
|
||||||
|
new = props.structural_analysis_models.add()
|
||||||
|
new.ifc_definition_id = ifc_definition_id
|
||||||
|
new.name = model["Name"] or "Unnamed"
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
class Data:
|
class Data:
|
||||||
is_loaded = False
|
is_loaded = False
|
||||||
products = {}
|
|
||||||
structural_analysis_models = {}
|
|
||||||
connections = {}
|
connections = {}
|
||||||
boundary_conditions = {}
|
boundary_conditions = {}
|
||||||
connects_structural_members = {}
|
connects_structural_members = {}
|
||||||
@@ -17,8 +15,6 @@ class Data:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def purge(cls):
|
def purge(cls):
|
||||||
cls.is_loaded = False
|
cls.is_loaded = False
|
||||||
cls.products = {}
|
|
||||||
cls.structural_analysis_models = {}
|
|
||||||
cls.connections = {}
|
cls.connections = {}
|
||||||
cls.boundary_conditions = {}
|
cls.boundary_conditions = {}
|
||||||
cls.connects_structural_members = {}
|
cls.connects_structural_members = {}
|
||||||
@@ -44,7 +40,6 @@ class Data:
|
|||||||
return cls.load_structural_member(product_id)
|
return cls.load_structural_member(product_id)
|
||||||
# if product.is_a("IfcStructuralAction"):
|
# if product.is_a("IfcStructuralAction"):
|
||||||
# return cls.load_structural_action(product_id)
|
# return cls.load_structural_action(product_id)
|
||||||
cls.load_structural_analysis_models()
|
|
||||||
cls.load_structural_load_cases()
|
cls.load_structural_load_cases()
|
||||||
cls.load_structural_load_case_combinations()
|
cls.load_structural_load_case_combinations()
|
||||||
cls.load_structural_load_groups()
|
cls.load_structural_load_groups()
|
||||||
@@ -53,34 +48,6 @@ class Data:
|
|||||||
cls.load_boundary_conditions()
|
cls.load_boundary_conditions()
|
||||||
cls.is_loaded = True
|
cls.is_loaded = True
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load_structural_analysis_models(cls):
|
|
||||||
cls.products = {}
|
|
||||||
cls.structural_analysis_models = {}
|
|
||||||
|
|
||||||
for model in cls._file.by_type("IfcStructuralAnalysisModel"):
|
|
||||||
if model.IsGroupedBy:
|
|
||||||
for rel in model.IsGroupedBy:
|
|
||||||
for product in rel.RelatedObjects:
|
|
||||||
cls.products.setdefault(product.id(), []).append(model.id())
|
|
||||||
data = model.get_info()
|
|
||||||
del data["OwnerHistory"]
|
|
||||||
|
|
||||||
loaded_by = []
|
|
||||||
for load_group in model.LoadedBy or []:
|
|
||||||
loaded_by.append(load_group.id())
|
|
||||||
data["LoadedBy"] = loaded_by
|
|
||||||
|
|
||||||
has_results = []
|
|
||||||
for result_group in model.HasResults or []:
|
|
||||||
has_results.append(result_group.id())
|
|
||||||
data["HasResults"] = has_results
|
|
||||||
|
|
||||||
data["OrientationOf2DPlane"] = model.OrientationOf2DPlane.id() if model.OrientationOf2DPlane else None
|
|
||||||
data["SharedPlacement"] = model.SharedPlacement.id() if model.SharedPlacement else None
|
|
||||||
|
|
||||||
cls.structural_analysis_models[model.id()] = data
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_structural_load_cases(cls):
|
def load_structural_load_cases(cls):
|
||||||
cls.load_cases = {}
|
cls.load_cases = {}
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ class Usecase:
|
|||||||
def execute(self):
|
def execute(self):
|
||||||
for name, value in self.settings["attributes"].items():
|
for name, value in self.settings["attributes"].items():
|
||||||
setattr(self.settings["structural_analysis_model"], name, value)
|
setattr(self.settings["structural_analysis_model"], name, value)
|
||||||
|
return self.settings["structural_analysis_model"]
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
class TestAddStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||||
|
def test_adding_a_structural_analysis_model(self):
|
||||||
|
subject = ifcopenshell.api.run("structural.add_structural_analysis_model", self.file)
|
||||||
|
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||||
|
assert subject == models[0]
|
||||||
|
assert subject.is_a("IfcStructuralAnalysisModel")
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
class TestAssignStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||||
|
def test_assigning_a_structural_analysis_model(self):
|
||||||
|
subject = ifcopenshell.api.run("structural.add_structural_analysis_model", self.file)
|
||||||
|
product = ifcopenshell.api.run(
|
||||||
|
"root.create_entity",
|
||||||
|
self.file,
|
||||||
|
ifc_class="IfcStructuralMember",
|
||||||
|
predefined_type=None,
|
||||||
|
name=None
|
||||||
|
)
|
||||||
|
rel = ifcopenshell.api.run(
|
||||||
|
"structural.assign_structural_analysis_model",
|
||||||
|
self.file,
|
||||||
|
product=product,
|
||||||
|
structural_analysis_model=subject,
|
||||||
|
)
|
||||||
|
assert rel.is_a("IfcRelAssignsToGroup")
|
||||||
|
assert rel.RelatingGroup == subject
|
||||||
|
assert product in rel.RelatedObjects
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
class TestEditStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||||
|
def test_editing_a_structural_analysis_model(self):
|
||||||
|
subject = ifcopenshell.api.run("structural.add_structural_analysis_model", self.file)
|
||||||
|
subject = ifcopenshell.api.run(
|
||||||
|
"structural.edit_structural_analysis_model",
|
||||||
|
self.file,
|
||||||
|
structural_analysis_model=subject,
|
||||||
|
attributes={
|
||||||
|
"Name": "My edited model",
|
||||||
|
"Description": "Description of my model"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||||
|
assert subject == models[0]
|
||||||
|
assert subject.is_a("IfcStructuralAnalysisModel")
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
class TestRemoveStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||||
|
def test_removing_a_structural_analysis_model(self):
|
||||||
|
subject = ifcopenshell.api.run("structural.add_structural_analysis_model", self.file)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"structural.remove_structural_analysis_model",
|
||||||
|
self.file,
|
||||||
|
structural_analysis_model=subject,
|
||||||
|
|
||||||
|
)
|
||||||
|
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||||
|
assert len(models) == 0
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
import numpy
|
||||||
|
import pytest
|
||||||
|
import test.bootstrap
|
||||||
|
import ifcopenshell.api
|
||||||
|
|
||||||
|
class TestUnassignStructuralAnalysisModel(test.bootstrap.IFC4):
|
||||||
|
def test_unassigning_a_structural_analysis_model(self):
|
||||||
|
subject = ifcopenshell.api.run("structural.add_structural_analysis_model", self.file)
|
||||||
|
product = ifcopenshell.api.run(
|
||||||
|
"root.create_entity",
|
||||||
|
self.file,
|
||||||
|
ifc_class="IfcStructuralMember",
|
||||||
|
predefined_type=None,
|
||||||
|
name=None
|
||||||
|
)
|
||||||
|
rel = ifcopenshell.api.run(
|
||||||
|
"structural.assign_structural_analysis_model",
|
||||||
|
self.file,
|
||||||
|
product=product,
|
||||||
|
structural_analysis_model=subject,
|
||||||
|
)
|
||||||
|
ifcopenshell.api.run(
|
||||||
|
"structural.unassign_structural_analysis_model",
|
||||||
|
self.file,
|
||||||
|
product=product,
|
||||||
|
structural_analysis_model=subject,
|
||||||
|
)
|
||||||
|
models = self.file.by_type("IfcStructuralAnalysisModel")
|
||||||
|
rels = self.file.by_type("IfcRelAssignsToGroup")
|
||||||
|
assert len(models[0].IsGroupedBy) == 0
|
||||||
|
assert len(rels) == 0
|
||||||
Reference in New Issue
Block a user