mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-29 11:46:33 +00:00
Merge branch 'IfcOpenShell:v0.7.0' into v0.7.0
This commit is contained in:
@@ -36,6 +36,7 @@ classes = (
|
|||||||
operator.RefreshLibrary,
|
operator.RefreshLibrary,
|
||||||
operator.RewindLibrary,
|
operator.RewindLibrary,
|
||||||
operator.SaveLibraryFile,
|
operator.SaveLibraryFile,
|
||||||
|
operator.AppendEntiryLibrary,
|
||||||
operator.SelectLibraryFile,
|
operator.SelectLibraryFile,
|
||||||
operator.ToggleFilterCategories,
|
operator.ToggleFilterCategories,
|
||||||
operator.ToggleLinkVisibility,
|
operator.ToggleLinkVisibility,
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
bl_description = "Select an IFC file that can be used as a library"
|
bl_description = "Select an IFC file that can be used as a library"
|
||||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||||
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
filter_glob: bpy.props.StringProperty(default="*.ifc;*.ifczip;*.ifcxml", options={"HIDDEN"})
|
||||||
|
append_all: bpy.props.BoolProperty(default=False)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
IfcStore.begin_transaction(self)
|
IfcStore.begin_transaction(self)
|
||||||
@@ -87,6 +88,8 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
bpy.ops.bim.refresh_library()
|
bpy.ops.bim.refresh_library()
|
||||||
if context.area:
|
if context.area:
|
||||||
context.area.tag_redraw()
|
context.area.tag_redraw()
|
||||||
|
if self.append_all:
|
||||||
|
bpy.ops.bim.append_entire_library()
|
||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
@@ -105,6 +108,9 @@ class SelectLibraryFile(bpy.types.Operator, IFCFileSelector):
|
|||||||
IfcStore.library_path = data["filepath"]
|
IfcStore.library_path = data["filepath"]
|
||||||
IfcStore.library_file = ifcopenshell.open(data["filepath"])
|
IfcStore.library_file = ifcopenshell.open(data["filepath"])
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
self.layout.prop(self, "append_all", text= "Append Entire Library")
|
||||||
|
|
||||||
|
|
||||||
class RefreshLibrary(bpy.types.Operator):
|
class RefreshLibrary(bpy.types.Operator):
|
||||||
bl_idname = "bim.refresh_library"
|
bl_idname = "bim.refresh_library"
|
||||||
@@ -282,6 +288,27 @@ class SaveLibraryFile(bpy.types.Operator):
|
|||||||
return {"FINISHED"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
|
class AppendEntiryLibrary(bpy.types.Operator):
|
||||||
|
bl_idname = "bim.append_entire_library"
|
||||||
|
bl_label = "Append Entiry Library"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return IfcStore.get_file()
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
return IfcStore.execute_ifc_operator(self, context)
|
||||||
|
|
||||||
|
def _execute(self, context):
|
||||||
|
self.file = IfcStore.get_file()
|
||||||
|
self.library = IfcStore.library_file
|
||||||
|
|
||||||
|
lib_elements = ifcopenshell.util.selector.Selector().parse(self.library, '.IfcTypeProduct | .IfcMaterial | .IfcCostSchedule| .IfcProfileDef')
|
||||||
|
for element in lib_elements:
|
||||||
|
bpy.ops.bim.append_library_element(definition= element.id())
|
||||||
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|
||||||
class AppendLibraryElement(bpy.types.Operator):
|
class AppendLibraryElement(bpy.types.Operator):
|
||||||
bl_idname = "bim.append_library_element"
|
bl_idname = "bim.append_library_element"
|
||||||
bl_label = "Append Library Element"
|
bl_label = "Append Library Element"
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ statements = []
|
|||||||
terminals = reduce(lambda x, y: x | y, (find_bytype(e, Terminal) for id, e in express))
|
terminals = reduce(lambda x, y: x | y, (find_bytype(e, Terminal) for id, e in express))
|
||||||
keywords = list(filter(operator.attrgetter("is_keyword"), terminals))
|
keywords = list(filter(operator.attrgetter("is_keyword"), terminals))
|
||||||
negated_keywords = map(lambda s: "~%s" % s, keywords)
|
negated_keywords = map(lambda s: "~%s" % s, keywords)
|
||||||
no_action = {"letter", "digit", "digits", "real_literal", "integer_literal"}
|
no_action = {"letter", "digit", "digits", "real_literal", "integer_literal", "string_literal", "simple_string_literal", "letter", "not_quote", "not_paren_star_quote_special"}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
emitted_in_loop = set()
|
emitted_in_loop = set()
|
||||||
@@ -199,8 +199,8 @@ for id in to_emit:
|
|||||||
stmt = "(%s)%s" % (stmt, action)
|
stmt = "(%s)%s" % (stmt, action)
|
||||||
statements.append("%s << %s" % (id, stmt))
|
statements.append("%s << %s" % (id, stmt))
|
||||||
|
|
||||||
print(
|
if __name__ == "__main__":
|
||||||
"""
|
print("""
|
||||||
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
# This file is generated by IfcOpenShell ifcexpressparser bootstrap.py
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -238,6 +238,5 @@ if __name__ == "__main__":
|
|||||||
mdl = importlib.import_module(output)
|
mdl = importlib.import_module(output)
|
||||||
mdl.Generator(m).emit()
|
mdl.Generator(m).emit()
|
||||||
sys.stdout.write(m.schema.name)
|
sys.stdout.write(m.schema.name)
|
||||||
"""
|
""" % ("\n ".join(statements))
|
||||||
% ("\n ".join(statements))
|
)
|
||||||
)
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -21,6 +21,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import io
|
import io
|
||||||
import string
|
import string
|
||||||
|
import operator
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
|
|
||||||
@@ -55,6 +56,11 @@ class ListNode:
|
|||||||
def __init__(self, s, loc, tokens, rule=None):
|
def __init__(self, s, loc, tokens, rule=None):
|
||||||
self.rule = rule or (type(self).__name__)
|
self.rule = rule or (type(self).__name__)
|
||||||
self.tokens = tokens.asList()
|
self.tokens = tokens.asList()
|
||||||
|
self.dict_tokens = collections.defaultdict(list)
|
||||||
|
for t in self.tokens:
|
||||||
|
r = getattr(t, 'rule', None)
|
||||||
|
if r:
|
||||||
|
self.dict_tokens[r].append(t)
|
||||||
self.flat = sum([getattr(t, "flat", [t]) for t in self.tokens], [])
|
self.flat = sum([getattr(t, "flat", [t]) for t in self.tokens], [])
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -229,6 +235,41 @@ class NamedType(Node):
|
|||||||
return self.type
|
return self.type
|
||||||
|
|
||||||
|
|
||||||
|
def do_try(fn):
|
||||||
|
try:
|
||||||
|
return fn()
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
|
||||||
|
def to_tree(x, key=None):
|
||||||
|
def get_rule_id(x):
|
||||||
|
from bootstrap import actions
|
||||||
|
ty = type(x).__name__
|
||||||
|
matches = [k for k, v in actions.items() if v == ty]
|
||||||
|
if matches:
|
||||||
|
return matches[0]
|
||||||
|
|
||||||
|
def prune(di):
|
||||||
|
import bootstrap
|
||||||
|
rule_dependencies = {
|
||||||
|
k: list(map(operator.attrgetter('contents'), bootstrap.reduce(lambda x, y: x | y, (bootstrap.find_bytype(e, bootstrap.Keyword) for e in [v])))) \
|
||||||
|
for k, v in bootstrap.express
|
||||||
|
}
|
||||||
|
subrules = list(filter(str.islower, rule_dependencies[key]))
|
||||||
|
return {k: v for k, v in di.items() if k in subrules}
|
||||||
|
|
||||||
|
if isinstance(x, ListNode):
|
||||||
|
return to_tree(x.dict_tokens, key=get_rule_id(x) or key)
|
||||||
|
if isinstance(x, Node,):
|
||||||
|
return to_tree(x.tokens, key=get_rule_id(x) or key)
|
||||||
|
elif isinstance(x, dict):
|
||||||
|
return prune({k: to_tree(v, key=k) for k, v in x.items()})
|
||||||
|
elif isinstance(x, list):
|
||||||
|
return [to_tree(v, key=key) for v in x]
|
||||||
|
else:
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
class AggregationType(Node):
|
class AggregationType(Node):
|
||||||
aggregate_type = property(lambda self: self.flat[0])
|
aggregate_type = property(lambda self: self.flat[0])
|
||||||
bounds = property(lambda self: (list(self.tokens.values())[0][0].bound_spec or [None])[0])
|
bounds = property(lambda self: (list(self.tokens.values())[0][0].bound_spec or [None])[0])
|
||||||
@@ -247,6 +288,8 @@ class AggregationType(Node):
|
|||||||
return v.parameter_type.named_types
|
return v.parameter_type.named_types
|
||||||
elif v.parameter_type.generalized_types.general_aggregation_types:
|
elif v.parameter_type.generalized_types.general_aggregation_types:
|
||||||
return v.parameter_type.generalized_types.general_aggregation_types
|
return v.parameter_type.generalized_types.general_aggregation_types
|
||||||
|
elif do_try(lambda: v.parameter_type.generalized_types.generic_type.generic_type[0].GENERIC):
|
||||||
|
return do_try(lambda: v.parameter_type.generalized_types.generic_type.generic_type[0].GENERIC)
|
||||||
else:
|
else:
|
||||||
import pdb
|
import pdb
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ class Schema:
|
|||||||
return self.types_entities[key]
|
return self.types_entities[key]
|
||||||
|
|
||||||
def __init__(self, parsetree):
|
def __init__(self, parsetree):
|
||||||
|
self.tree = parsetree
|
||||||
self.name = parsetree.syntax[0][0].simple_id
|
self.name = parsetree.syntax[0][0].simple_id
|
||||||
|
|
||||||
sort = lambda d: OrderedCaseInsensitiveDict(sorted(d))
|
sort = lambda d: OrderedCaseInsensitiveDict(sorted(d))
|
||||||
|
|||||||
Reference in New Issue
Block a user