mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
black .
This commit is contained in:
@@ -20,7 +20,10 @@ import ifcopenshell
|
||||
from ifcopenshell import entity_instance
|
||||
import typing
|
||||
|
||||
def add_survey_point(file: ifcopenshell.file, survey_point: entity_instance, site:entity_instance = None) -> entity_instance:
|
||||
|
||||
def add_survey_point(
|
||||
file: ifcopenshell.file, survey_point: entity_instance, site: entity_instance = None
|
||||
) -> entity_instance:
|
||||
"""
|
||||
Adds a single survey point to the model based on IFC Concept Template 4.1.7.1.2.5.
|
||||
Survey points are located relative to IfcRepresentationContext.WorldCoordinateSystem
|
||||
@@ -34,14 +37,21 @@ def add_survey_point(file: ifcopenshell.file, survey_point: entity_instance, sit
|
||||
|
||||
annotation = ifcopenshell.api.cogo.add_survey_point(file,file.createIfcCartesianPoint(4000.0,3500.0)))
|
||||
"""
|
||||
context = ifcopenshell.util.representation.get_context(file,"Model","Annotation","MODEL_VIEW")
|
||||
shape_representation = file.createIfcShapeRepresentation(ContextOfItems=context,RepresentationIdentifier='Annotation',RepresentationType='Point',Items=[survey_point])
|
||||
context = ifcopenshell.util.representation.get_context(file, "Model", "Annotation", "MODEL_VIEW")
|
||||
shape_representation = file.createIfcShapeRepresentation(
|
||||
ContextOfItems=context, RepresentationIdentifier="Annotation", RepresentationType="Point", Items=[survey_point]
|
||||
)
|
||||
representation = file.createIfcProductDefinitionShape(Representations=[shape_representation])
|
||||
annotation = file.createIfcAnnotation(ifcopenshell.guid.new(),ObjectPlacement=context.WorldCoordinateSystem,Representation=representation,PredefinedType="SURVEY")
|
||||
|
||||
if (site == None):
|
||||
annotation = file.createIfcAnnotation(
|
||||
ifcopenshell.guid.new(),
|
||||
ObjectPlacement=context.WorldCoordinateSystem,
|
||||
Representation=representation,
|
||||
PredefinedType="SURVEY",
|
||||
)
|
||||
|
||||
if site == None:
|
||||
site = file.by_type("IfcSite")[0]
|
||||
|
||||
ifcopenshell.api.spatial.assign_container(file,relating_structure=site,products=[annotation])
|
||||
ifcopenshell.api.spatial.assign_container(file, relating_structure=site, products=[annotation])
|
||||
|
||||
return annotation
|
||||
|
||||
@@ -20,6 +20,7 @@ import ifcopenshell
|
||||
from ifcopenshell import entity_instance
|
||||
import typing
|
||||
|
||||
|
||||
def assign_survey_point(annotation: entity_instance, survey_point: entity_instance):
|
||||
"""
|
||||
Assigns a coordinate point to a survey point annotation
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
|
||||
import ifcopenshell.util.geolocation
|
||||
|
||||
def bearing2dd(bearing: str)->float:
|
||||
|
||||
def bearing2dd(bearing: str) -> float:
|
||||
"""
|
||||
Converts a quadrant bearing string to decimal degrees
|
||||
|
||||
@@ -35,26 +36,26 @@ def bearing2dd(bearing: str)->float:
|
||||
"""
|
||||
error_msg = "Invalid bearing string"
|
||||
|
||||
bearing = bearing.strip() # trim external white space
|
||||
bearing = ' '.join(bearing.split()) # make sure all parts separated by a single space
|
||||
bearing = bearing.strip() # trim external white space
|
||||
bearing = " ".join(bearing.split()) # make sure all parts separated by a single space
|
||||
parts = bearing.split()
|
||||
nParts = len(parts)
|
||||
if nParts < 3 or 5 < nParts:
|
||||
raise ValueError(error_msg)
|
||||
|
||||
|
||||
cY = parts[0]
|
||||
cY = cY.upper()
|
||||
if cY != 'N' and cY != 'S':
|
||||
if cY != "N" and cY != "S":
|
||||
raise ValueError(error_msg)
|
||||
|
||||
cX = parts[-1]
|
||||
cX = cX.upper()
|
||||
if cX != 'E' and cX != 'W':
|
||||
if cX != "E" and cX != "W":
|
||||
raise ValueError(error_msg)
|
||||
|
||||
|
||||
d = 0
|
||||
m = 0
|
||||
s = 0.
|
||||
s = 0.0
|
||||
ms = 0
|
||||
|
||||
if nParts == 3:
|
||||
@@ -69,38 +70,37 @@ def bearing2dd(bearing: str)->float:
|
||||
|
||||
# s in a decimal number
|
||||
# need to break it into whole seconds and milliseconds
|
||||
ms = 100.*(s - int(s))
|
||||
ms = 100.0 * (s - int(s))
|
||||
s = int(s)
|
||||
|
||||
if d < 0 or (m < 0 or 60 <= m) or (s < 0 or 60 <= s) or ms < 0:
|
||||
raise ValueError(error_msg)
|
||||
|
||||
if cY == 'N' and cX == 'E':
|
||||
angle = 90.
|
||||
sign = -1.
|
||||
elif cY == 'N' and cX == 'W':
|
||||
angle = 90.
|
||||
sign = 1.
|
||||
elif cY == 'S' and cX == 'E':
|
||||
angle = 270.
|
||||
sign = 1.
|
||||
elif cY == 'S' and cX == 'W':
|
||||
angle = 270.
|
||||
sign = -1.
|
||||
|
||||
if cY == "N" and cX == "E":
|
||||
angle = 90.0
|
||||
sign = -1.0
|
||||
elif cY == "N" and cX == "W":
|
||||
angle = 90.0
|
||||
sign = 1.0
|
||||
elif cY == "S" and cX == "E":
|
||||
angle = 270.0
|
||||
sign = 1.0
|
||||
elif cY == "S" and cX == "W":
|
||||
angle = 270.0
|
||||
sign = -1.0
|
||||
|
||||
try:
|
||||
dms = ifcopenshell.util.geolocation.dms2dd(d,m,s,ms)
|
||||
dms = ifcopenshell.util.geolocation.dms2dd(d, m, s, ms)
|
||||
except ValueError:
|
||||
raise ValueError(error_msg)
|
||||
|
||||
if dms < 0. or 90. < dms:
|
||||
|
||||
if dms < 0.0 or 90.0 < dms:
|
||||
raise ValueError(error_msg)
|
||||
|
||||
angle += sign*dms
|
||||
angle += sign * dms
|
||||
|
||||
# S 90 E will evaluate to 360
|
||||
if angle == 360.:
|
||||
angle = 0.
|
||||
if angle == 360.0:
|
||||
angle = 0.0
|
||||
|
||||
return angle
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ import ifcopenshell
|
||||
from ifcopenshell import entity_instance
|
||||
import typing
|
||||
|
||||
def edit_survey_point(annotation: entity_instance, x:float,y:float,z:float=0.0):
|
||||
|
||||
def edit_survey_point(annotation: entity_instance, x: float, y: float, z: float = 0.0):
|
||||
"""
|
||||
Edits the location of a previously defined survey point
|
||||
|
||||
@@ -35,6 +36,6 @@ def edit_survey_point(annotation: entity_instance, x:float,y:float,z:float=0.0):
|
||||
ifcopenshell.api.cogo.edit_surve_point(annotation,3500.0,2000.0)
|
||||
"""
|
||||
if annotation.Representation.Representations[0].Items[0].Dim == 2:
|
||||
annotation.Representation.Representations[0].Items[0].Coordinates = ((x,y))
|
||||
annotation.Representation.Representations[0].Items[0].Coordinates = (x, y)
|
||||
else:
|
||||
annotation.Representation.Representations[0].Items[0].Coordinates = ((x,y,z))
|
||||
annotation.Representation.Representations[0].Items[0].Coordinates = (x, y, z)
|
||||
|
||||
@@ -20,6 +20,7 @@ import math
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.unit
|
||||
|
||||
|
||||
def station_as_string(file: ifcopenshell.file, sta: float):
|
||||
"""
|
||||
Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string.
|
||||
@@ -28,18 +29,21 @@ def station_as_string(file: ifcopenshell.file, sta: float):
|
||||
:param station: the station to be stringized
|
||||
:return: stringized station
|
||||
"""
|
||||
|
||||
unit_type = ifcopenshell.util.unit.get_project_unit(file,"LENGTHUNIT")
|
||||
|
||||
unit_type = ifcopenshell.util.unit.get_project_unit(file, "LENGTHUNIT")
|
||||
if unit_type.is_a("IfcConversionBasedUnit"):
|
||||
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=None,to_unit="foot",to_prefix=None)
|
||||
station = ifcopenshell.util.unit.convert(
|
||||
sta, from_unit=unit_type.Name, from_prefix=None, to_unit="foot", to_prefix=None
|
||||
)
|
||||
plus_seperator = 2
|
||||
precision = 2
|
||||
else:
|
||||
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=unit_type.Prefix,to_unit="meter",to_prefix=None)
|
||||
station = ifcopenshell.util.unit.convert(
|
||||
sta, from_unit=unit_type.Name, from_prefix=unit_type.Prefix, to_unit="meter", to_prefix=None
|
||||
)
|
||||
plus_seperator = 3
|
||||
precision = 3
|
||||
|
||||
|
||||
value = math.fabs(station)
|
||||
|
||||
shifter = math.pow(10.0, plus_seperator)
|
||||
@@ -48,7 +52,7 @@ def station_as_string(file: ifcopenshell.file, sta: float):
|
||||
|
||||
# Check to make sure that v2 is not basically the same as shifter
|
||||
# If station = 69500.00000, we sometimes get 694+100.00 instead of 695+00.00
|
||||
if math.isclose(v2-shifter, 0., abs_tol=5.0 * math.pow(10.0, -(precision + 1))):
|
||||
if math.isclose(v2 - shifter, 0.0, abs_tol=5.0 * math.pow(10.0, -(precision + 1))):
|
||||
v2 = 0.0
|
||||
v1 += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user