mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 21:50:01 +00:00
typing
This commit is contained in:
@@ -140,6 +140,8 @@ class IfcStore:
|
|||||||
def update_cache():
|
def update_cache():
|
||||||
if not IfcStore.cache:
|
if not IfcStore.cache:
|
||||||
return
|
return
|
||||||
|
assert IfcStore.cache_path
|
||||||
|
assert IfcStore.file
|
||||||
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
ifc_key = IfcStore.path + IfcStore.file.wrapped_data.header.file_name.time_stamp
|
||||||
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
ifc_hash = hashlib.md5(ifc_key.encode("utf-8")).hexdigest()
|
||||||
new_cache_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache", f"{ifc_hash}.h5")
|
new_cache_path = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache", f"{ifc_hash}.h5")
|
||||||
|
|||||||
@@ -17,15 +17,24 @@
|
|||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
def parse_express(debug, filename):
|
from __future__ import annotations
|
||||||
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import bpy
|
||||||
|
import ifcopenshell
|
||||||
|
import bonsai.tool as tool
|
||||||
|
|
||||||
|
|
||||||
|
def parse_express(debug: tool.Debug, filename: str) -> None:
|
||||||
debug.add_schema_identifier(debug.load_express(filename))
|
debug.add_schema_identifier(debug.load_express(filename))
|
||||||
|
|
||||||
|
|
||||||
def purge_hdf5_cache(debug):
|
def purge_hdf5_cache(debug: tool.Debug) -> None:
|
||||||
debug.purge_hdf5_cache()
|
debug.purge_hdf5_cache()
|
||||||
|
|
||||||
|
|
||||||
def purge_unused_elements(ifc, debug, ifc_class):
|
def purge_unused_elements(ifc, debug: tool.Debug, ifc_class: str) -> int:
|
||||||
ifc_file = ifc.get()
|
ifc_file = ifc.get()
|
||||||
unused_elements = [i for i in ifc_file.by_type(ifc_class) if ifc_file.get_total_inverses(i) == 0]
|
unused_elements = [i for i in ifc_file.by_type(ifc_class) if ifc_file.get_total_inverses(i) == 0]
|
||||||
unused_elements_amount = len(unused_elements)
|
unused_elements_amount = len(unused_elements)
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ def switch_representation(
|
|||||||
return
|
return
|
||||||
|
|
||||||
entity = ifc.get_entity(obj)
|
entity = ifc.get_entity(obj)
|
||||||
|
assert entity
|
||||||
current_obj_data = geometry.get_object_data(obj)
|
current_obj_data = geometry.get_object_data(obj)
|
||||||
|
|
||||||
if not current_obj_data and geometry.is_text_literal(representation):
|
if not current_obj_data and geometry.is_text_literal(representation):
|
||||||
|
|||||||
@@ -19,31 +19,37 @@
|
|||||||
import os
|
import os
|
||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell.express
|
import ifcopenshell.express
|
||||||
|
import ifcopenshell.express.schema
|
||||||
|
import ifcopenshell.express.schema_class
|
||||||
|
import ifcopenshell.util.element
|
||||||
import bonsai.core.tool
|
import bonsai.core.tool
|
||||||
import bonsai.tool as tool
|
import bonsai.tool as tool
|
||||||
from bonsai.bim.ifc import IfcStore
|
from bonsai.bim.ifc import IfcStore
|
||||||
|
from mathutils import Vector
|
||||||
|
|
||||||
|
|
||||||
class Debug(bonsai.core.tool.Debug):
|
class Debug(bonsai.core.tool.Debug):
|
||||||
@classmethod
|
@classmethod
|
||||||
def add_schema_identifier(cls, schema):
|
def add_schema_identifier(cls, schema: ifcopenshell.express.schema_class.SchemaClass) -> None:
|
||||||
IfcStore.schema_identifiers.append(schema.schema_name)
|
IfcStore.schema_identifiers.append(schema.schema_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def load_express(cls, filename):
|
def load_express(cls, filename: str) -> ifcopenshell.express.schema_class.SchemaClass:
|
||||||
schema = ifcopenshell.express.parse(filename)
|
schema = ifcopenshell.express.parse(filename)
|
||||||
ifcopenshell.register_schema(schema)
|
ifcopenshell.register_schema(schema)
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def purge_hdf5_cache(cls):
|
def purge_hdf5_cache(cls) -> None:
|
||||||
cache_dir = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache")
|
cache_dir = os.path.join(bpy.context.scene.BIMProperties.data_dir, "cache")
|
||||||
filelist = [f for f in os.listdir(cache_dir) if f.endswith(".h5")]
|
filelist = [f for f in os.listdir(cache_dir) if f.endswith(".h5")]
|
||||||
for f in filelist:
|
for f in filelist:
|
||||||
os.remove(os.path.join(cache_dir, f))
|
os.remove(os.path.join(cache_dir, f))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def debug_geometry(cls, verts=[], edges=[], name="Debug"):
|
def debug_geometry(
|
||||||
|
cls, verts: list[Vector] = [], edges: list[tuple[int, int]] = [], name: str = "Debug"
|
||||||
|
) -> bpy.types.Object:
|
||||||
mesh = bpy.data.meshes.new("Debug")
|
mesh = bpy.data.meshes.new("Debug")
|
||||||
mesh.from_pydata(verts, edges, [])
|
mesh.from_pydata(verts, edges, [])
|
||||||
obj = bpy.data.objects.new(name, mesh)
|
obj = bpy.data.objects.new(name, mesh)
|
||||||
@@ -51,13 +57,13 @@ class Debug(bonsai.core.tool.Debug):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def remove_unused_elements(cls, elements):
|
def remove_unused_elements(cls, elements: list[ifcopenshell.entity_instance]) -> None:
|
||||||
ifc_file = tool.Ifc.get()
|
ifc_file = tool.Ifc.get()
|
||||||
for element in elements:
|
for element in elements:
|
||||||
ifcopenshell.util.element.remove_deep2(ifc_file, element)
|
ifcopenshell.util.element.remove_deep2(ifc_file, element)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def print_unused_elements_stats(cls, requested_ifc_class="", ignore_classes=tuple()):
|
def print_unused_elements_stats(cls, requested_ifc_class: str = "", ignore_classes: tuple[str] = tuple()) -> int:
|
||||||
ifc_file = tool.Ifc.get()
|
ifc_file = tool.Ifc.get()
|
||||||
|
|
||||||
# get list of ifc classes used in model
|
# get list of ifc classes used in model
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ from pytest_bdd import scenarios, given, when, then, parsers
|
|||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from math import radians
|
from math import radians
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union
|
from typing import Union, Any
|
||||||
|
|
||||||
scenarios("feature")
|
scenarios("feature")
|
||||||
|
|
||||||
@@ -49,18 +49,18 @@ webbrowser.open = lambda x: True
|
|||||||
|
|
||||||
|
|
||||||
class PanelSpy:
|
class PanelSpy:
|
||||||
def __init__(self, panel):
|
def __init__(self, panel: type[bpy.types.Panel]):
|
||||||
self.is_spy_dirty = True
|
self.is_spy_dirty = True
|
||||||
self.panel = panel
|
self.panel = panel
|
||||||
|
|
||||||
def refresh_spy(self):
|
def refresh_spy(self):
|
||||||
if self.is_spy_dirty:
|
if self.is_spy_dirty:
|
||||||
self.is_spy_dirty = False
|
self.is_spy_dirty = False
|
||||||
self.spied_attr = None
|
self.spied_attr: Union[str, None] = None
|
||||||
self.spied_labels = []
|
self.spied_labels: list[str] = []
|
||||||
self.spied_props = []
|
self.spied_props: list[dict[str, Any]] = []
|
||||||
self.spied_operators = []
|
self.spied_operators: list[dict[str, Any]] = []
|
||||||
self.spied_lists = []
|
self.spied_lists: list[dict[str, Any]] = []
|
||||||
self.panel.draw(self, bpy.context)
|
self.panel.draw(self, bpy.context)
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
@@ -91,6 +91,7 @@ class PanelSpy:
|
|||||||
return self
|
return self
|
||||||
elif self.spied_attr == "prop":
|
elif self.spied_attr == "prop":
|
||||||
props, name = args
|
props, name = args
|
||||||
|
props: bpy.types.bpy_struct
|
||||||
text = kwargs.get("text", props.bl_rna.properties[name].name)
|
text = kwargs.get("text", props.bl_rna.properties[name].name)
|
||||||
icon = kwargs.get("icon", None)
|
icon = kwargs.get("icon", None)
|
||||||
prop_type = props.bl_rna.properties[name].type
|
prop_type = props.bl_rna.properties[name].type
|
||||||
@@ -152,7 +153,7 @@ class TemplateListSpy:
|
|||||||
|
|
||||||
|
|
||||||
panel_name_cache = {}
|
panel_name_cache = {}
|
||||||
panel_spy = None
|
panel_spy: PanelSpy = None
|
||||||
|
|
||||||
|
|
||||||
def replace_variables(value):
|
def replace_variables(value):
|
||||||
|
|||||||
@@ -16,9 +16,14 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import schema_class
|
||||||
|
|
||||||
d = os.path.abspath(os.path.dirname(__file__))
|
d = os.path.abspath(os.path.dirname(__file__))
|
||||||
sys.path.append(d)
|
sys.path.append(d)
|
||||||
@@ -30,8 +35,9 @@ if not os.path.exists(exp_parser_fn):
|
|||||||
subprocess.call([sys.executable, "bootstrap.py"], cwd=d, stdout=f)
|
subprocess.call([sys.executable, "bootstrap.py"], cwd=d, stdout=f)
|
||||||
|
|
||||||
|
|
||||||
def parse(fn):
|
def parse(fn: str) -> schema_class.SchemaClass:
|
||||||
import express_parser
|
import express_parser
|
||||||
import schema_class
|
import schema_class
|
||||||
|
|
||||||
mapping = express_parser.parse(fn)
|
mapping = express_parser.parse(fn)
|
||||||
return schema_class.SchemaClass(mapping, schema_class.LateBoundSchemaInstantiator).code
|
return schema_class.SchemaClass(mapping, schema_class.LateBoundSchemaInstantiator).code
|
||||||
|
|||||||
Reference in New Issue
Block a user