mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
support assigning bsdd classifications in ifc4x3 too
This commit is contained in:
@@ -117,20 +117,17 @@ class AddClassificationFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
is_ifc2x3 = tool.Ifc.get_schema() == "IFC2X3"
|
|
||||||
|
|
||||||
props = context.scene.BIMBSDDProperties
|
props = context.scene.BIMBSDDProperties
|
||||||
domain = [d for d in props.domains if d.name == props.active_domain][0]
|
domain = [d for d in props.domains if d.name == props.active_domain][0]
|
||||||
for element in tool.Ifc.get().by_type("IfcClassification"):
|
for element in tool.Ifc.get().by_type("IfcClassification"):
|
||||||
if element.Name == props.active_domain or (not is_ifc2x3 and element.Location == domain.uri):
|
if element.Name == props.active_domain or (tool.Classification.get_location(element) == domain.uri):
|
||||||
return
|
return
|
||||||
classification = ifcopenshell.api.run(
|
classification = ifcopenshell.api.run(
|
||||||
"classification.add_classification", tool.Ifc.get(), classification=props.active_domain
|
"classification.add_classification", tool.Ifc.get(), classification=props.active_domain
|
||||||
)
|
)
|
||||||
classification.Source = domain.organization_name_owner
|
classification.Source = domain.organization_name_owner
|
||||||
classification.Edition = domain.version
|
classification.Edition = domain.version
|
||||||
if not is_ifc2x3:
|
tool.Classification.set_location(classification, domain.uri)
|
||||||
classification.Location = domain.uri
|
|
||||||
|
|
||||||
|
|
||||||
class EnableAddingManualClassification(bpy.types.Operator):
|
class EnableAddingManualClassification(bpy.types.Operator):
|
||||||
@@ -400,8 +397,6 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
obj_type: bpy.props.StringProperty()
|
obj_type: bpy.props.StringProperty()
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
is_ifc2x3 = tool.Ifc.get_schema() == "IFC2X3"
|
|
||||||
|
|
||||||
if self.obj_type == "Object":
|
if self.obj_type == "Object":
|
||||||
if context.selected_objects:
|
if context.selected_objects:
|
||||||
objects = [o.name for o in context.selected_objects]
|
objects = [o.name for o in context.selected_objects]
|
||||||
@@ -416,9 +411,8 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
|
|
||||||
classification = None
|
classification = None
|
||||||
for element in tool.Ifc.get().by_type("IfcClassification"):
|
for element in tool.Ifc.get().by_type("IfcClassification"):
|
||||||
if (
|
if element.Name == bsdd_classification.domain_name or (
|
||||||
element.Name == bsdd_classification.domain_name
|
tool.Classification.get_location(element) == bsdd_classification.domain_namespace_uri
|
||||||
or (not is_ifc2x3 and element.Location == bsdd_classification.domain_namespace_uri)
|
|
||||||
):
|
):
|
||||||
classification = element
|
classification = element
|
||||||
break
|
break
|
||||||
@@ -427,8 +421,7 @@ class AddClassificationReferenceFromBSDD(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
classification = ifcopenshell.api.run(
|
classification = ifcopenshell.api.run(
|
||||||
"classification.add_classification", tool.Ifc.get(), classification=bsdd_classification.domain_name
|
"classification.add_classification", tool.Ifc.get(), classification=bsdd_classification.domain_name
|
||||||
)
|
)
|
||||||
if not is_ifc2x3:
|
tool.Classification.set_location(classification, bsdd_classification.domain_namespace_uri)
|
||||||
classification.Location = bsdd_classification.domain_namespace_uri
|
|
||||||
|
|
||||||
for obj in objects:
|
for obj in objects:
|
||||||
ifc_definition_id = tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context)
|
ifc_definition_id = tool.Blender.get_obj_ifc_definition_id(obj, self.obj_type, context)
|
||||||
|
|||||||
@@ -168,6 +168,12 @@ class Clash:
|
|||||||
def look_at(cls, target, location): pass
|
def look_at(cls, target, location): pass
|
||||||
|
|
||||||
|
|
||||||
|
@interface
|
||||||
|
class Classification:
|
||||||
|
def get_location(cls, classification): pass
|
||||||
|
def set_location(cls, classification): pass
|
||||||
|
|
||||||
|
|
||||||
@interface
|
@interface
|
||||||
class Collector:
|
class Collector:
|
||||||
def assign(cls, obj): pass
|
def assign(cls, obj): pass
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from blenderbim.tool.brick import Brick
|
|||||||
from blenderbim.tool.bsdd import Bsdd
|
from blenderbim.tool.bsdd import Bsdd
|
||||||
from blenderbim.tool.cad import Cad
|
from blenderbim.tool.cad import Cad
|
||||||
from blenderbim.tool.clash import Clash
|
from blenderbim.tool.clash import Clash
|
||||||
|
from blenderbim.tool.classification import Classification
|
||||||
from blenderbim.tool.collector import Collector
|
from blenderbim.tool.collector import Collector
|
||||||
from blenderbim.tool.context import Context
|
from blenderbim.tool.context import Context
|
||||||
from blenderbim.tool.debug import Debug
|
from blenderbim.tool.debug import Debug
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
import bpy
|
||||||
|
import ifcopenshell.api
|
||||||
|
import ifcopenshell.util.classification
|
||||||
|
import blenderbim.core.tool
|
||||||
|
import blenderbim.tool as tool
|
||||||
|
import blenderbim.bim
|
||||||
|
from typing import Any, Optional, Union, Literal, Iterable, Callable
|
||||||
|
from typing_extensions import assert_never
|
||||||
|
|
||||||
|
|
||||||
|
class Classification(blenderbim.core.tool.Classification):
|
||||||
|
@classmethod
|
||||||
|
def get_location(cls, classification: ifcopenshell.entity_instance) -> Union[str, None]:
|
||||||
|
schema = classification.file.schema
|
||||||
|
if schema in ("IFC4", "IFC4X3"):
|
||||||
|
return classification[5]
|
||||||
|
elif schema == "IFC2X3":
|
||||||
|
return None
|
||||||
|
assert_never(schema)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_location(cls, classification: ifcopenshell.entity_instance, location: Union[str, None]) -> None:
|
||||||
|
schema = classification.file.schema
|
||||||
|
if schema in ("IFC4", "IFC4X3"):
|
||||||
|
classification[5] = location
|
||||||
|
return
|
||||||
|
elif schema == "IFC2X3":
|
||||||
|
return
|
||||||
|
assert_never(schema)
|
||||||
Reference in New Issue
Block a user