mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
You can now specify user coordinates to ResetAbsoluteCoordinates recipe
This commit is contained in:
@@ -3,11 +3,23 @@ class Patcher:
|
|||||||
self.src = src
|
self.src = src
|
||||||
self.file = file
|
self.file = file
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
|
self.args = args
|
||||||
|
|
||||||
def patch(self):
|
def patch(self):
|
||||||
# 12D can have some funky coordinates out of any sensible range. This
|
# Arbitrary threshold based on experience
|
||||||
# method will not work all the time, but will catch most issues.
|
self.threshold = 1000000
|
||||||
|
if self.args and len(self.args) == 1:
|
||||||
|
self.threshold = float(self.args[0])
|
||||||
|
elif self.args and len(self.args) == 4:
|
||||||
|
self.threshold = float(self.args[3])
|
||||||
|
|
||||||
|
# This method will not work all the time, but will catch most issues. It
|
||||||
|
# assumes that absolute coordinates are easily recognisable based on
|
||||||
|
# having a large absolute value above a threshold. This is not always
|
||||||
|
# the case, but is very fast to run, and works for most cases.
|
||||||
offset_point = None
|
offset_point = None
|
||||||
|
if self.args and len(self.args) >= 3:
|
||||||
|
offset_point = (float(self.args[0]),float(self.args[1]),float(self.args[2]))
|
||||||
try:
|
try:
|
||||||
point_lists = self.file.by_type('IfcCartesianPointList3D')
|
point_lists = self.file.by_type('IfcCartesianPointList3D')
|
||||||
except:
|
except:
|
||||||
@@ -20,12 +32,12 @@ class Patcher:
|
|||||||
coord_list[i] = point
|
coord_list[i] = point
|
||||||
continue
|
continue
|
||||||
if not offset_point:
|
if not offset_point:
|
||||||
offset_point = (point[0], point[1], point[2])
|
offset_point = (-point[0], -point[1], -point[2])
|
||||||
self.logger.info(f'Resetting absolute coordinates by {point}')
|
self.logger.info(f'Resetting absolute coordinates by {point}')
|
||||||
point = (
|
point = (
|
||||||
point[0] - offset_point[0],
|
point[0] + offset_point[0],
|
||||||
point[1] - offset_point[1],
|
point[1] + offset_point[1],
|
||||||
point[2] - offset_point[2]
|
point[2] + offset_point[2]
|
||||||
)
|
)
|
||||||
coord_list[i] = point
|
coord_list[i] = point
|
||||||
point_list.CoordList = coord_list
|
point_list.CoordList = coord_list
|
||||||
@@ -33,20 +45,19 @@ class Patcher:
|
|||||||
if len(point.Coordinates) == 2 or not self.is_point_far_away(point):
|
if len(point.Coordinates) == 2 or not self.is_point_far_away(point):
|
||||||
continue
|
continue
|
||||||
if not offset_point:
|
if not offset_point:
|
||||||
offset_point = (point.Coordinates[0], point.Coordinates[1], point.Coordinates[2])
|
offset_point = (-point.Coordinates[0], -point.Coordinates[1], -point.Coordinates[2])
|
||||||
self.logger.info(f'Resetting absolute coordinates by {point}')
|
self.logger.info(f'Resetting absolute coordinates by {point}')
|
||||||
point.Coordinates = (
|
point.Coordinates = (
|
||||||
point.Coordinates[0] - offset_point[0],
|
point.Coordinates[0] + offset_point[0],
|
||||||
point.Coordinates[1] - offset_point[1],
|
point.Coordinates[1] + offset_point[1],
|
||||||
point.Coordinates[2] - offset_point[2]
|
point.Coordinates[2] + offset_point[2]
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_point_far_away(self, point):
|
def is_point_far_away(self, point):
|
||||||
# Arbitrary threshold based on experience
|
|
||||||
if hasattr(point, 'Coordinates'):
|
if hasattr(point, 'Coordinates'):
|
||||||
return abs(point.Coordinates[0]) > 1000000 \
|
return abs(point.Coordinates[0]) > self.threshold \
|
||||||
or abs(point.Coordinates[1]) > 1000000 \
|
or abs(point.Coordinates[1]) > self.threshold \
|
||||||
or abs(point.Coordinates[2]) > 1000000
|
or abs(point.Coordinates[2]) > self.threshold
|
||||||
return abs(point[0]) > 1000000 \
|
return abs(point[0]) > self.threshold \
|
||||||
or abs(point[1]) > 1000000 \
|
or abs(point[1]) > self.threshold \
|
||||||
or abs(point[2]) > 1000000
|
or abs(point[2]) > self.threshold
|
||||||
|
|||||||
Reference in New Issue
Block a user