From 3bd58b7738a92839e37c2a604ac692748f620dfd Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 26 Oct 2020 14:57:35 +1100 Subject: [PATCH] You can now specify user coordinates to ResetAbsoluteCoordinates recipe --- .../recipes/ResetAbsoluteCoordinates.py | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py b/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py index ae8b674448..4cb29b7612 100644 --- a/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py +++ b/src/ifcpatch/recipes/ResetAbsoluteCoordinates.py @@ -3,11 +3,23 @@ class Patcher: self.src = src self.file = file self.logger = logger + self.args = args def patch(self): - # 12D can have some funky coordinates out of any sensible range. This - # method will not work all the time, but will catch most issues. + # Arbitrary threshold based on experience + 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 + if self.args and len(self.args) >= 3: + offset_point = (float(self.args[0]),float(self.args[1]),float(self.args[2])) try: point_lists = self.file.by_type('IfcCartesianPointList3D') except: @@ -20,12 +32,12 @@ class Patcher: coord_list[i] = point continue 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}') point = ( - point[0] - offset_point[0], - point[1] - offset_point[1], - point[2] - offset_point[2] + point[0] + offset_point[0], + point[1] + offset_point[1], + point[2] + offset_point[2] ) coord_list[i] = point point_list.CoordList = coord_list @@ -33,20 +45,19 @@ class Patcher: if len(point.Coordinates) == 2 or not self.is_point_far_away(point): continue 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}') point.Coordinates = ( - point.Coordinates[0] - offset_point[0], - point.Coordinates[1] - offset_point[1], - point.Coordinates[2] - offset_point[2] + point.Coordinates[0] + offset_point[0], + point.Coordinates[1] + offset_point[1], + point.Coordinates[2] + offset_point[2] ) def is_point_far_away(self, point): - # Arbitrary threshold based on experience if hasattr(point, 'Coordinates'): - return abs(point.Coordinates[0]) > 1000000 \ - or abs(point.Coordinates[1]) > 1000000 \ - or abs(point.Coordinates[2]) > 1000000 - return abs(point[0]) > 1000000 \ - or abs(point[1]) > 1000000 \ - or abs(point[2]) > 1000000 + return abs(point.Coordinates[0]) > self.threshold \ + or abs(point.Coordinates[1]) > self.threshold \ + or abs(point.Coordinates[2]) > self.threshold + return abs(point[0]) > self.threshold \ + or abs(point[1]) > self.threshold \ + or abs(point[2]) > self.threshold