66import time
77import json
88import argparse
9+ import decimal
910
1011
1112class IfcDiff ():
@@ -16,11 +17,14 @@ def __init__(self, old_file, new_file, output_file, inverse_classes=None):
1617 self .change_register = {}
1718 self .representation_ids = []
1819 self .inverse_classes = inverse_classes
20+ self .precision = 2
1921
2022 def diff (self ):
2123 print ('# IFC Diff' )
2224 self .load ()
2325
26+ self .precision = self .get_precision ()
27+
2428 old_elements = set (e .GlobalId for e in self .old .by_type ('IfcProduct' ))
2529 new_elements = set (e .GlobalId for e in self .new .by_type ('IfcProduct' ))
2630
@@ -71,9 +75,19 @@ def load(self):
7175 print ('Loading new file ...' )
7276 self .new = ifcopenshell .open (self .new_file )
7377
78+ def get_precision (self ):
79+ try :
80+ precision = [c for c in self .new .by_type ('IfcGeometricRepresentationContext' ) if c .ContextType == 'Model' ][0 ].Precision
81+ exponent = decimal .Decimal (str (precision )).as_tuple ().exponent
82+ if exponent < 0 :
83+ return abs (exponent )
84+ return 0
85+ except :
86+ return 2
87+
7488 def diff_element (self , old_element , new_element ):
7589 diff = DeepDiff (old_element , new_element ,
76- significant_digits = 2 , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
90+ significant_digits = self . precision , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
7791 exclude_regex_paths = [
7892 r'root.*id$' ,
7993 r'.*Representation.*' ,
@@ -96,7 +110,7 @@ def diff_element_inverse_relationships(self, old_element, new_element):
96110 new_relationships = [x for x in new_relationships_all if x .is_a () in self .inverse_classes ]
97111
98112 diff = DeepDiff (old_relationships , new_relationships ,
99- significant_digits = 2 , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
113+ significant_digits = self . precision , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
100114 exclude_regex_paths = [
101115 r'root.*id$' ,
102116 r'.*GlobalId.*' ,
@@ -113,12 +127,12 @@ def diff_element_geometry(self, old_element, new_element):
113127 try :
114128 DeepDiff (old_element .ObjectPlacement , new_element .ObjectPlacement ,
115129 terminate_on_first = True ,
116- significant_digits = 2 , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
130+ significant_digits = self . precision , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
117131 exclude_regex_paths = r'root.*id$' )
118132 DeepDiff (old_element .Representation , new_element .Representation ,
119133 terminate_on_first = True ,
120134 skip_after_n = 1000 , # Arbitrary value to "skim" check
121- significant_digits = 2 , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
135+ significant_digits = self . precision , ignore_string_type_changes = True , ignore_numeric_type_changes = True ,
122136 exclude_regex_paths = r'root.*id$' )
123137 except :
124138 if new_element .GlobalId :
0 commit comments