mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 14:31:39 +00:00
black format
This commit is contained in:
@@ -402,7 +402,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
|||||||
"GlobalId": ifcopenshell.guid.new(),
|
"GlobalId": ifcopenshell.guid.new(),
|
||||||
"RelatingElement": element,
|
"RelatingElement": element,
|
||||||
"RelatedFeatureElement": subelement,
|
"RelatedFeatureElement": subelement,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
|
"geometry.edit_object_placement", self.file, product=element, matrix=matrix.copy(), is_si=False
|
||||||
@@ -572,7 +572,9 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
|||||||
should_transform_children=False,
|
should_transform_children=False,
|
||||||
)
|
)
|
||||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), submatrix)
|
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), submatrix)
|
||||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix)
|
assert numpy.array_equal(
|
||||||
|
ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix
|
||||||
|
)
|
||||||
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
||||||
# old placement should be removed to avoid orphaned entities
|
# old placement should be removed to avoid orphaned entities
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
@@ -609,7 +611,9 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
|||||||
should_transform_children=False,
|
should_transform_children=False,
|
||||||
)
|
)
|
||||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), submatrix)
|
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(element.ObjectPlacement), submatrix)
|
||||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix)
|
assert numpy.array_equal(
|
||||||
|
ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix
|
||||||
|
)
|
||||||
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
|
||||||
# old placement should be removed to avoid orphaned entities
|
# old placement should be removed to avoid orphaned entities
|
||||||
with pytest.raises(RuntimeError):
|
with pytest.raises(RuntimeError):
|
||||||
|
|||||||
@@ -196,8 +196,14 @@ class TestCopyClass(test.bootstrap.IFC4):
|
|||||||
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
|
||||||
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSet")
|
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSet")
|
||||||
assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial
|
assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial
|
||||||
assert new.HasAssociations[0].RelatingMaterial.MaterialLayers[0] != element.HasAssociations[0].RelatingMaterial.MaterialLayers[0]
|
assert (
|
||||||
assert new.HasAssociations[0].RelatingMaterial.MaterialLayers[0].Material == element.HasAssociations[0].RelatingMaterial.MaterialLayers[0].Material
|
new.HasAssociations[0].RelatingMaterial.MaterialLayers[0]
|
||||||
|
!= element.HasAssociations[0].RelatingMaterial.MaterialLayers[0]
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
new.HasAssociations[0].RelatingMaterial.MaterialLayers[0].Material
|
||||||
|
== element.HasAssociations[0].RelatingMaterial.MaterialLayers[0].Material
|
||||||
|
)
|
||||||
|
|
||||||
def test_copying_a_type_and_purging_type_relationships(self):
|
def test_copying_a_type_and_purging_type_relationships(self):
|
||||||
type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ bl_info = {
|
|||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger('sverchok.ifc')
|
|
||||||
|
logger = logging.getLogger("sverchok.ifc")
|
||||||
from sverchok.ui.nodeview_space_menu import add_node_menu
|
from sverchok.ui.nodeview_space_menu import add_node_menu
|
||||||
|
|
||||||
|
|
||||||
def nodes_index():
|
def nodes_index():
|
||||||
return [
|
return [
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ from sverchok.data_structure import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SvIfcAddSpatialElement(
|
class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
|
||||||
bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore
|
|
||||||
):
|
|
||||||
bl_idname = "SvIfcAddSpatialElement"
|
bl_idname = "SvIfcAddSpatialElement"
|
||||||
bl_label = "IFC Add Spatial Element"
|
bl_label = "IFC Add Spatial Element"
|
||||||
node_dict = {}
|
node_dict = {}
|
||||||
@@ -68,16 +66,14 @@ class SvIfcAddSpatialElement(
|
|||||||
self.node_dict[hash(self)] = {}
|
self.node_dict[hash(self)] = {}
|
||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
layout.operator(
|
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = (
|
||||||
"node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False
|
"Add IfcElements to an IfcSpatialElement."
|
||||||
).tooltip = "Add IfcElements to an IfcSpatialElement."
|
)
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
self.sv_input_names = [i.name for i in self.inputs]
|
self.sv_input_names = [i.name for i in self.inputs]
|
||||||
if hash(self) not in self.node_dict:
|
if hash(self) not in self.node_dict:
|
||||||
self.node_dict[
|
self.node_dict[hash(self)] = {} # happens if node is already on canvas when blender loads
|
||||||
hash(self)
|
|
||||||
] = {} # happens if node is already on canvas when blender loads
|
|
||||||
if not self.node_dict[hash(self)]:
|
if not self.node_dict[hash(self)]:
|
||||||
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
|
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
|
||||||
|
|
||||||
@@ -86,9 +82,7 @@ class SvIfcAddSpatialElement(
|
|||||||
edit = False
|
edit = False
|
||||||
edit_elements = False
|
edit_elements = False
|
||||||
for i in range(len(self.inputs)):
|
for i in range(len(self.inputs)):
|
||||||
input = self.inputs[self.sv_input_names[i]].sv_get(
|
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=True, default=[])
|
||||||
deepcopy=True, default=[]
|
|
||||||
)
|
|
||||||
if (
|
if (
|
||||||
isinstance(self.node_dict[hash(self)][self.inputs[i].name], list)
|
isinstance(self.node_dict[hash(self)][self.inputs[i].name], list)
|
||||||
and input != self.node_dict[hash(self)][self.inputs[i].name]
|
and input != self.node_dict[hash(self)][self.inputs[i].name]
|
||||||
@@ -99,9 +93,7 @@ class SvIfcAddSpatialElement(
|
|||||||
self.node_dict[hash(self)][self.inputs[i].name] = input.copy()
|
self.node_dict[hash(self)][self.inputs[i].name] = input.copy()
|
||||||
|
|
||||||
self.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
|
self.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
|
||||||
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[
|
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[0]
|
||||||
0
|
|
||||||
]
|
|
||||||
self.elements = ensure_min_nesting(self.inputs["Elements"].sv_get(), 2)
|
self.elements = ensure_min_nesting(self.inputs["Elements"].sv_get(), 2)
|
||||||
if isinstance(self.elements[0][0], list):
|
if isinstance(self.elements[0][0], list):
|
||||||
self.elements = [list(chain.from_iterable(el)) for el in self.elements]
|
self.elements = [list(chain.from_iterable(el)) for el in self.elements]
|
||||||
@@ -109,18 +101,13 @@ class SvIfcAddSpatialElement(
|
|||||||
raise Exception('Mandatory input "Element(s)" is missing.')
|
raise Exception('Mandatory input "Element(s)" is missing.')
|
||||||
return
|
return
|
||||||
self.file = SvIfcStore.get_file()
|
self.file = SvIfcStore.get_file()
|
||||||
self.elements = [
|
self.elements = [[self.file.by_id(step_id) for step_id in element] for element in self.elements]
|
||||||
[self.file.by_id(step_id) for step_id in element]
|
|
||||||
for element in self.elements
|
|
||||||
]
|
|
||||||
|
|
||||||
if "len" not in self.node_dict[hash(self)]:
|
if "len" not in self.node_dict[hash(self)]:
|
||||||
self.node_dict[hash(self)]["len"] = 0
|
self.node_dict[hash(self)]["len"] = 0
|
||||||
self.names = self.repeat_input_unique(self.names, len(self.elements))
|
self.names = self.repeat_input_unique(self.names, len(self.elements))
|
||||||
|
|
||||||
if (self.node_id not in SvIfcStore.id_map) or (
|
if (self.node_id not in SvIfcStore.id_map) or (len(self.elements) != self.node_dict[hash(self)]["len"]):
|
||||||
len(self.elements) != self.node_dict[hash(self)]["len"]
|
|
||||||
):
|
|
||||||
self.remove()
|
self.remove()
|
||||||
elements = self.create()
|
elements = self.create()
|
||||||
self.node_dict[hash(self)]["len"] = len(self.elements)
|
self.node_dict[hash(self)]["len"] = len(self.elements)
|
||||||
@@ -144,9 +131,7 @@ class SvIfcAddSpatialElement(
|
|||||||
ifc_class=self.ifc_class,
|
ifc_class=self.ifc_class,
|
||||||
)
|
)
|
||||||
for items in self.elements[i]:
|
for items in self.elements[i]:
|
||||||
if items.is_a("IfcSpatialElement") or items.is_a(
|
if items.is_a("IfcSpatialElement") or items.is_a("IfcSpatialStructureElement"):
|
||||||
"IfcSpatialStructureElement"
|
|
||||||
):
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
@@ -182,9 +167,9 @@ class SvIfcAddSpatialElement(
|
|||||||
for element in self.elements[i]:
|
for element in self.elements[i]:
|
||||||
element_set = set([element])
|
element_set = set([element])
|
||||||
for removed_element in subelements - element_set:
|
for removed_element in subelements - element_set:
|
||||||
if removed_element.is_a(
|
if removed_element.is_a("IfcSpatialElement") or removed_element.is_a(
|
||||||
"IfcSpatialElement"
|
"IfcSpatialStructureElement"
|
||||||
) or removed_element.is_a("IfcSpatialStructureElement"):
|
):
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.unassign_object",
|
"aggregate.unassign_object",
|
||||||
self.file,
|
self.file,
|
||||||
@@ -199,9 +184,7 @@ class SvIfcAddSpatialElement(
|
|||||||
relating_object=result,
|
relating_object=result,
|
||||||
)
|
)
|
||||||
for added_element in element_set - subelements:
|
for added_element in element_set - subelements:
|
||||||
if added_element.is_a(
|
if added_element.is_a("IfcSpatialElement") or added_element.is_a("IfcSpatialStructureElement"):
|
||||||
"IfcSpatialElement"
|
|
||||||
) or added_element.is_a("IfcSpatialStructureElement"):
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
self.file,
|
self.file,
|
||||||
@@ -230,8 +213,7 @@ class SvIfcAddSpatialElement(
|
|||||||
input = repeat_last_for_length(input, count, deepcopy=False)
|
input = repeat_last_for_length(input, count, deepcopy=False)
|
||||||
if input[0]:
|
if input[0]:
|
||||||
input = [
|
input = [
|
||||||
a if not (s := sum(j == a for j in input[:i])) else f"{a}-{s+1}"
|
a if not (s := sum(j == a for j in input[:i])) else f"{a}-{s+1}" for i, a in enumerate(input)
|
||||||
for i, a in enumerate(input)
|
|
||||||
] # add number to duplicates
|
] # add number to duplicates
|
||||||
return input
|
return input
|
||||||
|
|
||||||
|
|||||||
@@ -28,9 +28,7 @@ from sverchok.node_tree import SverchCustomTreeNode
|
|||||||
from sverchok.data_structure import updateNode, flatten_data
|
from sverchok.data_structure import updateNode, flatten_data
|
||||||
|
|
||||||
|
|
||||||
class SvIfcWriteFile(
|
class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
|
||||||
bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Triggers: Ifc write to file
|
Triggers: Ifc write to file
|
||||||
Tooltip: Write active Sverchok Ifc file to path
|
Tooltip: Write active Sverchok Ifc file to path
|
||||||
@@ -41,9 +39,7 @@ class SvIfcWriteFile(
|
|||||||
self.process()
|
self.process()
|
||||||
self.refresh_local = False
|
self.refresh_local = False
|
||||||
|
|
||||||
refresh_local: BoolProperty(
|
refresh_local: BoolProperty(name="Write", description="Write to file", update=refresh_node_local)
|
||||||
name="Write", description="Write to file", update=refresh_node_local
|
|
||||||
)
|
|
||||||
|
|
||||||
bl_idname = "SvIfcWriteFile"
|
bl_idname = "SvIfcWriteFile"
|
||||||
bl_label = "IFC Write File"
|
bl_label = "IFC Write File"
|
||||||
@@ -59,9 +55,12 @@ class SvIfcWriteFile(
|
|||||||
|
|
||||||
def draw_buttons(self, context, layout):
|
def draw_buttons(self, context, layout):
|
||||||
row = layout.row(align=True)
|
row = layout.row(align=True)
|
||||||
row.operator(
|
tooltip = (
|
||||||
"node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False
|
"Writes active Ifc file to path.\n "
|
||||||
).tooltip = "Writes active Ifc file to path.\n It will overwrite an existing file.\n N.B.! It's recommended to create a fresh IFC File using the 're-run all nodes' button in IfcSverchok panel before saving."
|
"It will overwrite an existing file.\n"
|
||||||
|
"N.B.! It's recommended to create a fresh IFC File using the 're-run all nodes' button in IfcSverchok panel before saving."
|
||||||
|
)
|
||||||
|
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = tooltip
|
||||||
row.prop(self, "refresh_local", icon="FILE_REFRESH")
|
row.prop(self, "refresh_local", icon="FILE_REFRESH")
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
@@ -81,21 +80,15 @@ class SvIfcWriteFile(
|
|||||||
def ensure_hirarchy(self, file):
|
def ensure_hirarchy(self, file):
|
||||||
elements_in_buildings = []
|
elements_in_buildings = []
|
||||||
if not 0 <= 0 < len(file.by_type("IfcBuilding")):
|
if not 0 <= 0 < len(file.by_type("IfcBuilding")):
|
||||||
my_building = ifcopenshell.api.run(
|
my_building = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcBuilding", name="My Building")
|
||||||
"root.create_entity", file, ifc_class="IfcBuilding", name="My Building"
|
|
||||||
)
|
|
||||||
elements = ifcopenshell.util.element.get_decomposition(my_building)
|
elements = ifcopenshell.util.element.get_decomposition(my_building)
|
||||||
else:
|
else:
|
||||||
for building in file.by_type("IfcBuilding"):
|
for building in file.by_type("IfcBuilding"):
|
||||||
elements = ifcopenshell.util.element.get_decomposition(building)
|
elements = ifcopenshell.util.element.get_decomposition(building)
|
||||||
elements_in_buildings.extend(elements)
|
elements_in_buildings.extend(elements)
|
||||||
|
|
||||||
for spatial in file.by_type("IfcSpatialElement") or file.by_type(
|
for spatial in file.by_type("IfcSpatialElement") or file.by_type("IfcSpatialStructureElement"):
|
||||||
"IfcSpatialStructureElement"
|
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (spatial not in elements_in_buildings):
|
||||||
):
|
|
||||||
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (
|
|
||||||
spatial not in elements_in_buildings
|
|
||||||
):
|
|
||||||
elements = ifcopenshell.util.element.get_decomposition(spatial)
|
elements = ifcopenshell.util.element.get_decomposition(spatial)
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
@@ -123,9 +116,7 @@ class SvIfcWriteFile(
|
|||||||
elements = ifcopenshell.util.element.get_decomposition(building)
|
elements = ifcopenshell.util.element.get_decomposition(building)
|
||||||
if not building.Decomposes:
|
if not building.Decomposes:
|
||||||
if not 0 <= 0 < len(file.by_type("IfcSite")):
|
if not 0 <= 0 < len(file.by_type("IfcSite")):
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
|
||||||
"root.create_entity", file, ifc_class="IfcSite", name="My Site"
|
|
||||||
)
|
|
||||||
ifcopenshell.api.run(
|
ifcopenshell.api.run(
|
||||||
"aggregate.assign_object",
|
"aggregate.assign_object",
|
||||||
file,
|
file,
|
||||||
@@ -133,11 +124,7 @@ class SvIfcWriteFile(
|
|||||||
relating_object=file.by_type("IfcSite")[0],
|
relating_object=file.by_type("IfcSite")[0],
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
if (
|
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
|
||||||
file.by_type("IfcSite")[0]
|
|
||||||
.Decomposes[0]
|
|
||||||
.RelatingObject.is_a("IfcProject")
|
|
||||||
):
|
|
||||||
continue
|
continue
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class FacetDocGenerator:
|
|||||||
specs = ids.Ids(title=name)
|
specs = ids.Ids(title=name)
|
||||||
|
|
||||||
# todo: to resume IFC2X3 we need to ensure that entities and attributes are consistent with that schema in order to pass audit
|
# todo: to resume IFC2X3 we need to ensure that entities and attributes are consistent with that schema in order to pass audit
|
||||||
spec = ids.Specification(name=name, minOccurs=1, ifcVersion=["IFC4"])
|
spec = ids.Specification(name=name, minOccurs=1, ifcVersion=["IFC4"])
|
||||||
spec.applicability.append(ids.Entity(name=inst.is_a().upper()))
|
spec.applicability.append(ids.Entity(name=inst.is_a().upper()))
|
||||||
spec.requirements.append(facet)
|
spec.requirements.append(facet)
|
||||||
specs.specifications.append(spec)
|
specs.specifications.append(spec)
|
||||||
|
|||||||
Reference in New Issue
Block a user