black format

This commit is contained in:
Andrej730
2024-04-05 16:05:11 +05:00
parent 02aaf1b409
commit 78abca16e6
6 changed files with 47 additions and 66 deletions
@@ -402,7 +402,7 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
"GlobalId": ifcopenshell.guid.new(),
"RelatingElement": element,
"RelatedFeatureElement": subelement,
}
},
)
ifcopenshell.api.run(
"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,
)
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
# old placement should be removed to avoid orphaned entities
with pytest.raises(RuntimeError):
@@ -609,7 +611,9 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
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(subelement.ObjectPlacement), shifted_submatrix)
assert numpy.array_equal(
ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), shifted_submatrix
)
assert subelement.ObjectPlacement.PlacementRelTo == element.ObjectPlacement
# old placement should be removed to avoid orphaned entities
with pytest.raises(RuntimeError):
@@ -196,8 +196,14 @@ class TestCopyClass(test.bootstrap.IFC4):
new = ifcopenshell.api.run("root.copy_class", self.file, product=element)
assert new.HasAssociations[0].RelatingMaterial.is_a("IfcMaterialLayerSet")
assert new.HasAssociations[0].RelatingMaterial != element.HasAssociations[0].RelatingMaterial
assert 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
assert (
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):
type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
+3 -1
View File
@@ -30,9 +30,11 @@ bl_info = {
import importlib
import logging
logger = logging.getLogger('sverchok.ifc')
logger = logging.getLogger("sverchok.ifc")
from sverchok.ui.nodeview_space_menu import add_node_menu
def nodes_index():
return [
(
@@ -36,9 +36,7 @@ from sverchok.data_structure import (
)
class SvIfcAddSpatialElement(
bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore
):
class SvIfcAddSpatialElement(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcAddSpatialElement"
bl_label = "IFC Add Spatial Element"
node_dict = {}
@@ -68,16 +66,14 @@ class SvIfcAddSpatialElement(
self.node_dict[hash(self)] = {}
def draw_buttons(self, context, layout):
layout.operator(
"node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False
).tooltip = "Add IfcElements to an IfcSpatialElement."
layout.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = (
"Add IfcElements to an IfcSpatialElement."
)
def process(self):
self.sv_input_names = [i.name for i in self.inputs]
if hash(self) not in self.node_dict:
self.node_dict[
hash(self)
] = {} # happens if node is already on canvas when blender loads
self.node_dict[hash(self)] = {} # happens if node is already on canvas when blender loads
if not self.node_dict[hash(self)]:
self.node_dict[hash(self)].update(dict.fromkeys(self.sv_input_names, 0))
@@ -86,9 +82,7 @@ class SvIfcAddSpatialElement(
edit = False
edit_elements = False
for i in range(len(self.inputs)):
input = self.inputs[self.sv_input_names[i]].sv_get(
deepcopy=True, default=[]
)
input = self.inputs[self.sv_input_names[i]].sv_get(deepcopy=True, default=[])
if (
isinstance(self.node_dict[hash(self)][self.inputs[i].name], list)
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.names = flatten_data(self.inputs["Names"].sv_get(), target_level=1)
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[
0
]
self.ifc_class = flatten_data(self.inputs["IfcClass"].sv_get(), target_level=1)[0]
self.elements = ensure_min_nesting(self.inputs["Elements"].sv_get(), 2)
if isinstance(self.elements[0][0], list):
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.')
return
self.file = SvIfcStore.get_file()
self.elements = [
[self.file.by_id(step_id) for step_id in element]
for element in self.elements
]
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)]:
self.node_dict[hash(self)]["len"] = 0
self.names = self.repeat_input_unique(self.names, len(self.elements))
if (self.node_id not in SvIfcStore.id_map) or (
len(self.elements) != self.node_dict[hash(self)]["len"]
):
if (self.node_id not in SvIfcStore.id_map) or (len(self.elements) != self.node_dict[hash(self)]["len"]):
self.remove()
elements = self.create()
self.node_dict[hash(self)]["len"] = len(self.elements)
@@ -144,9 +131,7 @@ class SvIfcAddSpatialElement(
ifc_class=self.ifc_class,
)
for items in self.elements[i]:
if items.is_a("IfcSpatialElement") or items.is_a(
"IfcSpatialStructureElement"
):
if items.is_a("IfcSpatialElement") or items.is_a("IfcSpatialStructureElement"):
ifcopenshell.api.run(
"aggregate.assign_object",
self.file,
@@ -182,9 +167,9 @@ class SvIfcAddSpatialElement(
for element in self.elements[i]:
element_set = set([element])
for removed_element in subelements - element_set:
if removed_element.is_a(
"IfcSpatialElement"
) or removed_element.is_a("IfcSpatialStructureElement"):
if removed_element.is_a("IfcSpatialElement") or removed_element.is_a(
"IfcSpatialStructureElement"
):
ifcopenshell.api.run(
"aggregate.unassign_object",
self.file,
@@ -199,9 +184,7 @@ class SvIfcAddSpatialElement(
relating_object=result,
)
for added_element in element_set - subelements:
if added_element.is_a(
"IfcSpatialElement"
) or added_element.is_a("IfcSpatialStructureElement"):
if added_element.is_a("IfcSpatialElement") or added_element.is_a("IfcSpatialStructureElement"):
ifcopenshell.api.run(
"aggregate.assign_object",
self.file,
@@ -230,8 +213,7 @@ class SvIfcAddSpatialElement(
input = repeat_last_for_length(input, count, deepcopy=False)
if input[0]:
input = [
a if not (s := sum(j == a for j in input[:i])) else f"{a}-{s+1}"
for i, a in enumerate(input)
a if not (s := sum(j == a for j in input[:i])) else f"{a}-{s+1}" for i, a in enumerate(input)
] # add number to duplicates
return input
+13 -26
View File
@@ -28,9 +28,7 @@ from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, flatten_data
class SvIfcWriteFile(
bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore
):
class SvIfcWriteFile(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
"""
Triggers: Ifc write to file
Tooltip: Write active Sverchok Ifc file to path
@@ -41,9 +39,7 @@ class SvIfcWriteFile(
self.process()
self.refresh_local = False
refresh_local: BoolProperty(
name="Write", description="Write to file", update=refresh_node_local
)
refresh_local: BoolProperty(name="Write", description="Write to file", update=refresh_node_local)
bl_idname = "SvIfcWriteFile"
bl_label = "IFC Write File"
@@ -59,9 +55,12 @@ class SvIfcWriteFile(
def draw_buttons(self, context, layout):
row = layout.row(align=True)
row.operator(
"node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False
).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."
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."
)
row.operator("node.sv_ifc_tooltip", text="", icon="QUESTION", emboss=False).tooltip = tooltip
row.prop(self, "refresh_local", icon="FILE_REFRESH")
def process(self):
@@ -81,21 +80,15 @@ class SvIfcWriteFile(
def ensure_hirarchy(self, file):
elements_in_buildings = []
if not 0 <= 0 < len(file.by_type("IfcBuilding")):
my_building = ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcBuilding", name="My Building"
)
my_building = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcBuilding", name="My Building")
elements = ifcopenshell.util.element.get_decomposition(my_building)
else:
for building in file.by_type("IfcBuilding"):
elements = ifcopenshell.util.element.get_decomposition(building)
elements_in_buildings.extend(elements)
for spatial in file.by_type("IfcSpatialElement") or file.by_type(
"IfcSpatialStructureElement"
):
if not (spatial.is_a("IfcSite") or spatial.is_a("IfcBuilding")) and (
spatial not in elements_in_buildings
):
for spatial in file.by_type("IfcSpatialElement") or file.by_type("IfcSpatialStructureElement"):
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)
ifcopenshell.api.run(
"aggregate.assign_object",
@@ -123,9 +116,7 @@ class SvIfcWriteFile(
elements = ifcopenshell.util.element.get_decomposition(building)
if not building.Decomposes:
if not 0 <= 0 < len(file.by_type("IfcSite")):
ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcSite", name="My Site"
)
ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
ifcopenshell.api.run(
"aggregate.assign_object",
file,
@@ -133,11 +124,7 @@ class SvIfcWriteFile(
relating_object=file.by_type("IfcSite")[0],
)
try:
if (
file.by_type("IfcSite")[0]
.Decomposes[0]
.RelatingObject.is_a("IfcProject")
):
if file.by_type("IfcSite")[0].Decomposes[0].RelatingObject.is_a("IfcProject"):
continue
except IndexError:
pass
+1 -1
View File
@@ -84,7 +84,7 @@ class FacetDocGenerator:
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
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.requirements.append(facet)
specs.specifications.append(spec)