Directly use entity doc functions instead of wrappers

This commit is contained in:
Gorgious
2022-10-31 17:57:24 +01:00
parent c0b91848a3
commit ee59d366dc
17 changed files with 96 additions and 69 deletions
@@ -17,7 +17,9 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
from blenderbim.bim.prop import StrProperty, Attribute, get_ifc_entity_description
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.prop import Attribute
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
@@ -32,7 +34,8 @@ from bpy.props import (
def get_available_constraint_types(self, context):
return [(c, c, get_ifc_entity_description(c)) for c in ["IfcObjective"]]
version = tool.Ifc.get_schema()
return [(c, c, get_entity_doc(version, c).get("description", "")) for c in ["IfcObjective"]]
class Constraint(PropertyGroup):
@@ -21,7 +21,6 @@ import bpy
import ifcopenshell
import ifcopenshell.util.schema
import blenderbim.tool as tool
from blenderbim.bim.prop import get_ifc_entity_description
def refresh():
@@ -66,9 +65,12 @@ class MaterialsData:
"IfcMaterialProfileSet",
"IfcMaterialList",
]
if tool.Ifc.get_schema() == "IFC2X3":
version = tool.Ifc.get_schema()
if version == "IFC2X3":
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialList"]
return [(m, m, get_ifc_entity_description(m)) for m in material_types]
return [
(m, m, ifcopenshell.util.doc.get_entity_doc(version, m).get("description", "")) for m in material_types
]
class ObjectMaterialData:
@@ -17,10 +17,12 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
from ifcopenshell.util.doc import get_entity_doc
from ifcopenshell.api.material.data import Data
import blenderbim.tool as tool
from blenderbim.bim.module.material.data import MaterialsData, ObjectMaterialData
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty, Attribute, get_ifc_entity_description
from blenderbim.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
@@ -50,9 +52,11 @@ def purge():
def get_profile_classes(self, context):
global profileclasses_enum
if len(profileclasses_enum) == 0 and IfcStore.get_schema():
version = tool.Ifc.get_schema()
profileclasses_enum.clear()
profileclasses_enum = [
(t.name(), t.name(), get_ifc_entity_description(t.name())) for t in IfcStore.get_schema().declaration_by_name("IfcProfileDef").subtypes()
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name("IfcProfileDef").subtypes()
]
return profileclasses_enum
@@ -60,15 +64,16 @@ def get_profile_classes(self, context):
def get_parameterized_profile_classes(self, context):
global parameterizedprofileclasses_enum
if len(parameterizedprofileclasses_enum) == 0 and IfcStore.get_schema():
version = tool.Ifc.get_schema()
parameterizedprofileclasses_enum.clear()
parameterizedprofileclasses_enum = [
(t.name(), t.name(), get_ifc_entity_description(t.name()))
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name("IfcParameterizedProfileDef").subtypes()
]
for ifc_class in parameterizedprofileclasses_enum:
parameterizedprofileclasses_enum.extend(
[
(t.name(), t.name(), get_ifc_entity_description(t.name()))
(t.name(), t.name(), get_entity_doc(version, t.name()).get("description", ""))
for t in IfcStore.get_schema().declaration_by_name(ifc_class[0]).subtypes() or []
]
)
@@ -93,10 +98,11 @@ def get_object_material_types(self, context):
"IfcMaterialProfileSetUsage",
"IfcMaterialList",
]
if IfcStore.get_file().schema == "IFC2X3":
version = tool.Ifc.get_schema()
if version == "IFC2X3":
material_types = ["IfcMaterial", "IfcMaterialLayerSet", "IfcMaterialLayerSetUsage", "IfcMaterialList"]
materialtypes_enum.clear()
materialtypes_enum = [(m, m, get_ifc_entity_description(m)) for m in material_types]
materialtypes_enum = [(m, m, get_entity_doc(version, m).get("description", "")) for m in material_types]
return materialtypes_enum
@@ -22,10 +22,11 @@ import json
import functools
import ifcopenshell
import ifcopenshell.util.element
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.model.root import ConstrTypeEntityNotFound
from blenderbim.bim.prop import get_ifc_entity_description, get_predefined_type_description
from blenderbim.bim.prop import get_predefined_type_description
def refresh():
@@ -64,7 +65,8 @@ class AuthoringData:
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
names = [d.name() for d in declarations]
names.extend(("IfcDoorStyle", "IfcWindowStyle"))
return [(c, c, get_ifc_entity_description(c)) for c in sorted(names)]
version = tool.Ifc.get_schema()
return [(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted(names)]
@classmethod
def type_predefined_type(cls):
@@ -17,7 +17,9 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
from blenderbim.bim.prop import StrProperty, Attribute, get_ifc_entity_description
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.prop import StrProperty, Attribute
from blenderbim.bim.module.owner.data import OwnerData, ActorData, ObjectActorData
from bpy.types import PropertyGroup
from bpy.props import (
@@ -65,17 +67,19 @@ def update_actor_class(self, context):
def get_actor_class_enum(self, context):
version = tool.Ifc.get_schema()
return [
("IfcActor", "Actor", get_ifc_entity_description("IfcActor")),
("IfcOccupant", "Occupant", get_ifc_entity_description("IfcOccupant")),
("IfcActor", "Actor", get_entity_doc(version, "IfcActor").get("description", "")),
("IfcOccupant", "Occupant", get_entity_doc(version, "IfcOccupant").get("description", "")),
]
def get_actor_type_enum(self, context):
version = tool.Ifc.get_schema()
return [
("IfcPerson", "Person", get_ifc_entity_description("IfcPerson")),
("IfcOrganization", "Organisation", get_ifc_entity_description("IfcOrganization")),
("IfcPersonAndOrganization", "User", get_ifc_entity_description("IfcPersonAndOrganization")),
("IfcPerson", "Person", get_entity_doc(version, "IfcPerson").get("description", "")),
("IfcOrganization", "Organisation", get_entity_doc(version, "IfcOrganization").get("description", "")),
("IfcPersonAndOrganization", "User", get_entity_doc(version, "IfcPersonAndOrganization").get("description", "")),
]
@@ -175,6 +175,6 @@ class AddEditCustomPropertiesData:
schema = tool.Ifc.schema()
version = tool.Ifc.get_schema()
return [
(t, t, ifcopenshell.util.doc.get_type_doc(version, t).get("description"))
(t, t, ifcopenshell.util.doc.get_type_doc(version, t).get("description", ""))
for t in sorted([d.name() for d in schema.declarations() if hasattr(d, "declared_type")])
]
@@ -146,7 +146,7 @@ def get_qto_names(self, context):
def get_template_type(self, context):
version = tool.Ifc.get_schema()
for t in ("IfcPropertySingleValue", "IfcPropertyEnumeratedValue"):
yield (t, t, ifcopenshell.util.doc.get_entity_doc(version, t).get("description"))
yield (t, t, ifcopenshell.util.doc.get_entity_doc(version, t).get("description", ""))
def get_primary_measure_type(self, context):
@@ -21,7 +21,6 @@ import bpy
import ifcopenshell
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import get_ifc_entity_description
def refresh():
@@ -46,7 +45,7 @@ class PsetTemplatesData:
schema = tool.Ifc.schema()
version = tool.Ifc.get_schema()
return [
(t, t, ifcopenshell.util.doc.get_type_doc(version, t).get("description"))
(t, t, ifcopenshell.util.doc.get_type_doc(version, t).get("description", ""))
for t in sorted([d.name() for d in schema.declarations() if hasattr(d, "declared_type")])
]
@@ -19,9 +19,10 @@
from collections import defaultdict
import bpy
import ifcopenshell.util.element
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import get_ifc_entity_description, get_predefined_type_description
from blenderbim.bim.prop import get_predefined_type_description
def refresh():
@@ -57,7 +58,8 @@ class IfcClassData:
"IfcAnnotation",
"IfcRelSpaceBoundary",
]
if tool.Ifc.get_schema() == "IFC2X3":
version = tool.Ifc.get_schema()
if version == "IFC2X3":
products = [
"IfcElement",
"IfcElementType",
@@ -67,7 +69,7 @@ class IfcClassData:
"IfcAnnotation",
"IfcRelSpaceBoundary",
]
return [(e, e, get_ifc_entity_description(e)) for e in products]
return [(e, e, get_entity_doc(version, e).get("description", "")) for e in products]
@classmethod
def ifc_classes(cls):
@@ -77,7 +79,8 @@ class IfcClassData:
names = [d.name() for d in declarations]
if ifc_product == "IfcElementType":
names.extend(("IfcDoorStyle", "IfcWindowStyle"))
return [(c, c, get_ifc_entity_description(c)) for c in sorted(names)]
version = tool.Ifc.get_schema()
return [(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted(names)]
@classmethod
def ifc_predefined_types(cls):
@@ -16,11 +16,13 @@
# 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
from blenderbim.bim.ifc import IfcStore
from math import radians
from blenderbim.bim.prop import StrProperty, Attribute, get_ifc_entity_description
import bpy
from ifcopenshell.api.structural.data import Data
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty, Attribute
from bpy.types import PropertyGroup
from bpy.props import (
PointerProperty,
@@ -89,8 +91,12 @@ def get_structural_load_types(self, context):
file = IfcStore.get_file()
if len(structuralloadtypes_enum) < 1 and file:
declaration = IfcStore.get_schema().declaration_by_name("IfcStructuralLoadStatic")
version = tool.Ifc.get_schema()
structuralloadtypes_enum.extend(
[(d.name(), d.name(), get_ifc_entity_description(d.name())) for d in declaration.subtypes()]
[
(d.name(), d.name(), get_entity_doc(version, d.name()).get("description", ""))
for d in declaration.subtypes()
]
)
return structuralloadtypes_enum
@@ -99,8 +105,10 @@ def get_boundary_condition_types(self, context):
file = IfcStore.get_file()
if file:
declaration = IfcStore.get_schema().declaration_by_name("IfcBoundaryCondition")
version = tool.Ifc.get_schema()
boundaryconditiontypes_enum = [
(d.name(), d.name(), get_ifc_entity_description(d.name())) for d in declaration.subtypes()
(d.name(), d.name(), get_entity_doc(version, d.name()).get("description", ""))
for d in declaration.subtypes()
]
return boundaryconditiontypes_enum
return []
@@ -17,9 +17,9 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import blenderbim.tool as tool
import ifcopenshell
from blenderbim.bim.prop import get_ifc_entity_description
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
def refresh():
@@ -39,7 +39,10 @@ class StylesData:
def style_types(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcPresentationStyle")
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
return [(c, c, get_ifc_entity_description(c)) for c in sorted([d.name() for d in declarations])]
version = tool.Ifc.get_schema()
return [
(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted([d.name() for d in declarations])
]
@classmethod
def total_styles(cls):
@@ -19,8 +19,8 @@
import bpy
import ifcopenshell
import ifcopenshell.util.schema
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.prop import get_ifc_entity_description
def refresh():
@@ -45,9 +45,10 @@ class SystemData:
def system_class(cls):
declaration = tool.Ifc.schema().declaration_by_name("IfcSystem")
declarations = ifcopenshell.util.schema.get_subtypes(declaration)
version = tool.Ifc.get_schema()
# We're only interested in systems for services. Not sure why IFC groups these together.
return [
(c, c, get_ifc_entity_description(c))
(c, c, get_entity_doc(version, c).get("description", ""))
for c in sorted([d.name() for d in declarations])
if c not in ("IfcZone", "IfcStructuralAnalysisModel")
]
@@ -19,8 +19,8 @@
import bpy
import ifcopenshell.util.type
import ifcopenshell.util.element
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.prop import get_ifc_entity_description
def refresh():
@@ -54,8 +54,9 @@ class TypeData:
element = tool.Ifc.get_entity(obj)
if not element:
return []
types = ifcopenshell.util.type.get_applicable_types(element.is_a(), schema=tool.Ifc.get_schema())
results.extend((t, t, get_ifc_entity_description(t)) for t in types)
version = tool.Ifc.get_schema()
types = ifcopenshell.util.type.get_applicable_types(element.is_a(), schema=version)
results.extend((t, t, get_entity_doc(version, t).get("description", "")) for t in types)
return results
@classmethod
@@ -87,7 +88,4 @@ class TypeData:
element = tool.Ifc.get_entity(bpy.context.active_object)
element_type = ifcopenshell.util.element.get_type(element)
if element_type:
return {
"id": element_type.id(),
"name":f"{element_type.is_a()}/{element_type.Name or 'Unnamed'}"
}
return {"id": element_type.id(), "name": f"{element_type.is_a()}/{element_type.Name or 'Unnamed'}"}
@@ -20,8 +20,8 @@ import ifcopenshell
import ifcopenshell.util.unit
import ifcopenshell.util.schema
import ifcopenshell.util.attribute
from ifcopenshell.util.doc import get_entity_doc
import blenderbim.tool as tool
from blenderbim.bim.prop import get_ifc_entity_description
def refresh():
@@ -45,8 +45,20 @@ class UnitsData:
@classmethod
def unit_classes(cls):
declarations = ifcopenshell.util.schema.get_subtypes(tool.Ifc.schema().declaration_by_name("IfcNamedUnit"))
results = [(c, c, get_ifc_entity_description(c)) for c in sorted([d.name() for d in declarations])]
results.extend([("IfcDerivedUnit", "IfcDerivedUnit", ""), ("IfcMonetaryUnit", "IfcMonetaryUnit", "")])
version = tool.Ifc.get_schema()
results = [
(c, c, get_entity_doc(version, c).get("description", "")) for c in sorted([d.name() for d in declarations])
]
results.extend(
[
("IfcDerivedUnit", "IfcDerivedUnit", get_entity_doc(version, "IfcDerivedUnit").get("description", "")),
(
"IfcMonetaryUnit",
"IfcMonetaryUnit",
get_entity_doc(version, "IfcMonetaryUnit").get("description", ""),
),
]
)
return results
@classmethod
+4 -2
View File
@@ -29,7 +29,7 @@ import blenderbim.tool as tool
from . import schema
from blenderbim.bim import import_ifc
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.prop import StrProperty, get_ifc_entity_doc_url
from blenderbim.bim.prop import StrProperty
from blenderbim.bim.ui import IFCFileSelector
from blenderbim.bim.helper import get_enum_items
from mathutils import Vector, Matrix, Euler
@@ -706,7 +706,9 @@ class BIM_OT_show_description(bpy.types.Operator):
wrapper = textwrap.TextWrapper(width=80)
for line in wrapper.wrap(self.description):
layout.label(text=line)
url = get_ifc_entity_doc_url(self.ifc_class)
version = tool.Ifc.get_schema()
doc = ifcopenshell.util.doc.get_entity_doc(version, self.ifc_class)
url = doc.get("spec_url")
if url:
url_op = layout.operator("bim.open_webbrowser", icon="URL", text="Online IFC Documentation")
url_op.url = url
-16
View File
@@ -106,22 +106,6 @@ def cache_string(s):
cache_string.data = {}
def get_ifc_entity_docs(ifc_entity):
schema = tool.Ifc.get_schema()
if schema is not None:
return get_entity_doc(schema, ifc_entity)
def get_ifc_entity_description(ifc_entity):
docs = get_ifc_entity_docs(ifc_entity)
return docs.get("description", "") if docs is not None else ""
def get_ifc_entity_doc_url(ifc_entity):
docs = get_ifc_entity_docs(ifc_entity)
return docs.get("spec_url", "") if docs is not None else ""
def get_predefined_type_description(entity, predefined_type):
schema = tool.Ifc.get_schema()
if schema is not None:
+4 -4
View File
@@ -401,21 +401,21 @@ def draw_custom_context_menu(self, context):
prop_value = getattr(prop, prop_name, None)
if prop_value is None:
return
schema = tool.Ifc.get_schema()
version = tool.Ifc.get_schema()
docs = {}
try:
docs = get_entity_doc(schema, prop_value)
docs = get_entity_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
try:
docs = get_type_doc(schema, prop_value)
docs = get_type_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError:
try:
docs = get_property_set_doc(schema, prop_value)
docs = get_property_set_doc(version, prop_value)
if docs is None:
raise RuntimeError
except RuntimeError: