mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 22:11:36 +00:00
Improve implementation of is_moved so that anywhere we check movement, types and projects are not considered
This commit is contained in:
@@ -155,7 +155,7 @@ class IfcExporter:
|
|||||||
|
|
||||||
def sync_object_placement(self, obj):
|
def sync_object_placement(self, obj):
|
||||||
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
|
||||||
if element.is_a("IfcTypeProduct") or element.is_a("IfcProject") or not tool.Ifc.is_moved(obj):
|
if not tool.Ifc.is_moved(obj):
|
||||||
return
|
return
|
||||||
blender_matrix = np.array(obj.matrix_world)
|
blender_matrix = np.array(obj.matrix_world)
|
||||||
if (obj.scale - Vector((1.0, 1.0, 1.0))).length > 1e-4:
|
if (obj.scale - Vector((1.0, 1.0, 1.0))).length > 1e-4:
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ class Ifc(blenderbim.core.tool.Ifc):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_moved(cls, obj):
|
def is_moved(cls, obj):
|
||||||
|
element = cls.get_entity(obj)
|
||||||
|
if not element or element.is_a("IfcTypeProduct") or element.is_a("IfcProject"):
|
||||||
|
return False
|
||||||
if not obj.BIMObjectProperties.location_checksum:
|
if not obj.BIMObjectProperties.location_checksum:
|
||||||
return True # Let's be conservative
|
return True # Let's be conservative
|
||||||
loc_check = np.frombuffer(eval(obj.BIMObjectProperties.location_checksum))
|
loc_check = np.frombuffer(eval(obj.BIMObjectProperties.location_checksum))
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import bpy
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import test.bim.bootstrap
|
import test.bim.bootstrap
|
||||||
import blenderbim.core.tool
|
import blenderbim.core.tool
|
||||||
|
import blenderbim.tool as tool
|
||||||
from blenderbim.tool.ifc import Ifc as subject
|
from blenderbim.tool.ifc import Ifc as subject
|
||||||
|
|
||||||
|
|
||||||
@@ -64,6 +65,36 @@ class TestGetSchema(test.bim.bootstrap.NewFile):
|
|||||||
assert subject.get_schema() == "IFC4"
|
assert subject.get_schema() == "IFC4"
|
||||||
|
|
||||||
|
|
||||||
|
class TestIsMoved(test.bim.bootstrap.NewFile):
|
||||||
|
def test_run(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
subject.set(ifc)
|
||||||
|
obj = bpy.data.objects.new("Object", None)
|
||||||
|
element = ifc.createIfcWall()
|
||||||
|
subject.link(element, obj)
|
||||||
|
obj.BIMObjectProperties.ifc_definition_id = element.id()
|
||||||
|
assert subject.is_moved(obj) is True
|
||||||
|
tool.Geometry.record_object_position(obj)
|
||||||
|
assert subject.is_moved(obj) is False
|
||||||
|
obj.matrix_world[0][2] += 1
|
||||||
|
assert subject.is_moved(obj) is True
|
||||||
|
|
||||||
|
def test_that_a_type_or_project_never_moves_but_a_grid_axis_does(self):
|
||||||
|
ifc = ifcopenshell.file()
|
||||||
|
subject.set(ifc)
|
||||||
|
obj = bpy.data.objects.new("Object", None)
|
||||||
|
element = ifc.createIfcWallType()
|
||||||
|
subject.link(element, obj)
|
||||||
|
obj.BIMObjectProperties.ifc_definition_id = element.id()
|
||||||
|
assert subject.is_moved(obj) is False
|
||||||
|
element = ifc.createIfcProject()
|
||||||
|
subject.link(element, obj)
|
||||||
|
assert subject.is_moved(obj) is False
|
||||||
|
element = ifc.createIfcGridAxis()
|
||||||
|
subject.link(element, obj)
|
||||||
|
assert subject.is_moved(obj) is True
|
||||||
|
|
||||||
|
|
||||||
class TestGetEntity(test.bim.bootstrap.NewFile):
|
class TestGetEntity(test.bim.bootstrap.NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
ifc = ifcopenshell.file()
|
ifc = ifcopenshell.file()
|
||||||
|
|||||||
Reference in New Issue
Block a user