mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
Implement getting and setting true north rotation independent of grid north
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user