Implement getting and setting true north rotation independent of grid north

This commit is contained in:
Dion Moult
2021-04-04 08:58:24 +10:00
parent 12c94fafab
commit 7b5aae9487
6 changed files with 119 additions and 11 deletions
@@ -2,12 +2,14 @@ class Data:
is_loaded = False
map_conversion = {}
projected_crs = {}
true_north = {}
@classmethod
def purge(cls):
cls.is_loaded = False
cls.map_conversion = {}
cls.projected_crs = {}
cls.true_north = None
@classmethod
def load(cls, file):
@@ -15,6 +17,7 @@ class Data:
return
cls.map_conversion = {}
cls.projected_crs = {}
cls.true_north = {}
if file.schema == "IFC2X3":
return
for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
@@ -28,4 +31,9 @@ class Data:
if cls.projected_crs["MapUnit"]:
cls.projected_crs["MapUnit"] = map_conversion.TargetCRS.MapUnit.get_info()
break
for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
if not context.TrueNorth:
continue
cls.true_north = context.TrueNorth.DirectionRatios
break
cls.is_loaded = True
@@ -7,6 +7,7 @@ class Usecase:
self.settings = {
"map_conversion": {},
"projected_crs": {},
"true_north": [],
"map_unit": "",
}
for key, value in settings.items():
@@ -21,6 +22,7 @@ class Usecase:
setattr(projected_crs, name, value)
self.remove_existing_map_unit(projected_crs)
self.set_map_unit(projected_crs)
self.set_true_north()
def remove_existing_map_unit(self, projected_crs):
if projected_crs.MapUnit and len(self.file.get_inverse(projected_crs.MapUnit)) == 1:
@@ -50,3 +52,20 @@ class Usecase:
self.settings["map_unit"],
self.file.createIfcMeasureWithUnit(value_component, si_unit),
)
def set_true_north(self):
if self.settings["true_north"] == []:
return
for context in self.file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
if context.TrueNorth:
if len(self.file.get_inverse(context.TrueNorth)) != 1:
context.TrueNorth = self.file.create_entity("IfcDirection")
else:
context.TrueNorth = self.file.create_entity("IfcDirection")
direction = context.TrueNorth
if self.settings["true_north"] is None:
context.TrueNorth = self.settings["true_north"]
elif context.CoordinateSpaceDimension == 2:
direction.DirectionRatios = self.settings["true_north"][0:2]
else:
direction.DirectionRatios = self.settings["true_north"][0:2] + [0.0]