Arch: import ifc, code formating, flake8, only the most important ones
This commit is contained in:
@@ -44,43 +44,45 @@ if open.__module__ in ['__builtin__','io']:
|
||||
pyopen = open # because we'll redefine open below
|
||||
|
||||
# which IFC type must create which FreeCAD type
|
||||
typesmap = { "Site": ["IfcSite"],
|
||||
"Building": ["IfcBuilding"],
|
||||
"Floor": ["IfcBuildingStorey"],
|
||||
"Structure": ["IfcBeam", "IfcBeamStandardCase", "IfcColumn", "IfcColumnStandardCase", "IfcSlab", "IfcFooting", "IfcPile", "IfcTendon"],
|
||||
"Wall": ["IfcWall", "IfcWallStandardCase", "IfcCurtainWall"],
|
||||
"Window": ["IfcWindow", "IfcWindowStandardCase", "IfcDoor", "IfcDoorStandardCase"],
|
||||
"Roof": ["IfcRoof"],
|
||||
"Stairs": ["IfcStair", "IfcStairFlight", "IfcRamp", "IfcRampFlight"],
|
||||
"Space": ["IfcSpace"],
|
||||
"Rebar": ["IfcReinforcingBar"],
|
||||
"Panel": ["IfcPlate"],
|
||||
"Equipment": ["IfcFurnishingElement","IfcSanitaryTerminal","IfcFlowTerminal","IfcElectricAppliance"],
|
||||
"Pipe": ["IfcPipeSegment"],
|
||||
"PipeConnector":["IfcPipeFitting"],
|
||||
"BuildingPart": ["IfcElementAssembly"]
|
||||
}
|
||||
typesmap = {
|
||||
"Site": ["IfcSite"],
|
||||
"Building": ["IfcBuilding"],
|
||||
"Floor": ["IfcBuildingStorey"],
|
||||
"Structure": ["IfcBeam", "IfcBeamStandardCase", "IfcColumn", "IfcColumnStandardCase", "IfcSlab", "IfcFooting", "IfcPile", "IfcTendon"],
|
||||
"Wall": ["IfcWall", "IfcWallStandardCase", "IfcCurtainWall"],
|
||||
"Window": ["IfcWindow", "IfcWindowStandardCase", "IfcDoor", "IfcDoorStandardCase"],
|
||||
"Roof": ["IfcRoof"],
|
||||
"Stairs": ["IfcStair", "IfcStairFlight", "IfcRamp", "IfcRampFlight"],
|
||||
"Space": ["IfcSpace"],
|
||||
"Rebar": ["IfcReinforcingBar"],
|
||||
"Panel": ["IfcPlate"],
|
||||
"Equipment": ["IfcFurnishingElement","IfcSanitaryTerminal","IfcFlowTerminal","IfcElectricAppliance"],
|
||||
"Pipe": ["IfcPipeSegment"],
|
||||
"PipeConnector":["IfcPipeFitting"],
|
||||
"BuildingPart": ["IfcElementAssembly"]
|
||||
}
|
||||
|
||||
# which IFC entity (product) is a structural object
|
||||
structuralifcobjects = (
|
||||
"IfcStructuralCurveMember", "IfcStructuralSurfaceMember",
|
||||
"IfcStructuralPointConnection", "IfcStructuralCurveConnection", "IfcStructuralSurfaceConnection",
|
||||
"IfcStructuralAction", "IfcStructuralPointAction",
|
||||
"IfcStructuralLinearAction", "IfcStructuralLinearActionVarying", "IfcStructuralPlanarAction"
|
||||
)
|
||||
"IfcStructuralCurveMember", "IfcStructuralSurfaceMember",
|
||||
"IfcStructuralPointConnection", "IfcStructuralCurveConnection", "IfcStructuralSurfaceConnection",
|
||||
"IfcStructuralAction", "IfcStructuralPointAction",
|
||||
"IfcStructuralLinearAction", "IfcStructuralLinearActionVarying", "IfcStructuralPlanarAction"
|
||||
)
|
||||
|
||||
# specific FreeCAD <-> IFC slang translations
|
||||
translationtable = { "Foundation":"Footing",
|
||||
"Floor":"BuildingStorey",
|
||||
"Rebar":"ReinforcingBar",
|
||||
"HydroEquipment":"SanitaryTerminal",
|
||||
"ElectricEquipment":"ElectricAppliance",
|
||||
"Furniture":"FurnishingElement",
|
||||
"Stair Flight":"StairFlight",
|
||||
"Curtain Wall":"CurtainWall",
|
||||
"Pipe Segment":"PipeSegment",
|
||||
"Pipe Fitting":"PipeFitting"
|
||||
}
|
||||
translationtable = {
|
||||
"Foundation":"Footing",
|
||||
"Floor":"BuildingStorey",
|
||||
"Rebar":"ReinforcingBar",
|
||||
"HydroEquipment":"SanitaryTerminal",
|
||||
"ElectricEquipment":"ElectricAppliance",
|
||||
"Furniture":"FurnishingElement",
|
||||
"Stair Flight":"StairFlight",
|
||||
"Curtain Wall":"CurtainWall",
|
||||
"Pipe Segment":"PipeSegment",
|
||||
"Pipe Fitting":"PipeFitting"
|
||||
}
|
||||
|
||||
# the base IFC template for export
|
||||
ifctemplate = """ISO-10303-21;
|
||||
@@ -153,6 +155,7 @@ def dd2dms(dd):
|
||||
degrees = -degrees
|
||||
return (int(degrees),int(minutes),int(seconds))
|
||||
|
||||
|
||||
def dms2dd(degrees, minutes, seconds, milliseconds=0):
|
||||
|
||||
"converts degrees,minutes,seconds to decimal degrees"
|
||||
@@ -1155,7 +1158,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
cobs = []
|
||||
for child in children:
|
||||
if child in objects.keys():
|
||||
if not child in swallowed: # don't add objects already in groups
|
||||
if child not in swallowed: # don't add objects already in groups
|
||||
cobs.append(objects[child])
|
||||
if cobs:
|
||||
if DEBUG and first:
|
||||
@@ -1327,7 +1330,6 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
return doc
|
||||
|
||||
|
||||
|
||||
class recycler:
|
||||
|
||||
"the compression engine - a mechanism to reuse ifc entities if needed"
|
||||
@@ -1483,7 +1485,6 @@ class recycler:
|
||||
|
||||
def export(exportList,filename):
|
||||
|
||||
|
||||
"exports FreeCAD contents to an IFC file"
|
||||
|
||||
getPreferences()
|
||||
@@ -1779,7 +1780,6 @@ def export(exportList,filename):
|
||||
subproducts[o.Name] = prod2
|
||||
ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Addition','',product,[prod2])
|
||||
|
||||
|
||||
# subtractions
|
||||
|
||||
guests = []
|
||||
@@ -1787,7 +1787,7 @@ def export(exportList,filename):
|
||||
if hasattr(o,"Hosts"):
|
||||
for co in o.Hosts:
|
||||
if co == obj:
|
||||
if not o in guests:
|
||||
if o not in guests:
|
||||
guests.append(o)
|
||||
if hasattr(obj,"Subtractions") and (shapetype in ["extrusion","no shape"]):
|
||||
for o in obj.Subtractions + guests:
|
||||
@@ -2063,7 +2063,7 @@ def export(exportList,filename):
|
||||
# buildingParts can be exported as any "normal" IFC type. In that case, gather their elements first
|
||||
|
||||
for bp in Draft.getObjectsOfType(objectslist,"BuildingPart"):
|
||||
if not bp.IfcRole in ["Site","Building","Building Storey","Space","Undefined"]:
|
||||
if bp.IfcRole not in ["Site","Building","Building Storey","Space","Undefined"]:
|
||||
if bp.Name in products:
|
||||
subs = []
|
||||
for c in bp.Group:
|
||||
@@ -2325,17 +2325,13 @@ def export(exportList,filename):
|
||||
# add remaining 2D objects to default host
|
||||
|
||||
if annos:
|
||||
remaining = [anno for anno in annos.values() if not anno in swallowed]
|
||||
remaining = [anno for anno in annos.values() if anno not in swallowed]
|
||||
if remaining:
|
||||
if not defaulthost:
|
||||
defaulthost = ifcfile.createIfcBuildingStorey(ifcopenshell.guid.compress(uuid.uuid1().hex),history,"Default Storey",'',None,None,None,None,"ELEMENT",None)
|
||||
ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'DefaultStoreyLink','',buildings[0],[defaulthost])
|
||||
ifcfile.createIfcRelContainedInSpatialStructure(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'AnnotationsLink','',remaining,defaulthost)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if DEBUG: print("writing ",filename,"...")
|
||||
|
||||
filename = decode(filename)
|
||||
@@ -2358,7 +2354,6 @@ def export(exportList,filename):
|
||||
|
||||
def buildAddress(obj,ifcfile):
|
||||
|
||||
|
||||
a = obj.Address or None
|
||||
p = obj.PostalCode or None
|
||||
t = obj.City or None
|
||||
@@ -2381,6 +2376,7 @@ def buildAddress(obj,ifcfile):
|
||||
addr = None
|
||||
return addr
|
||||
|
||||
|
||||
def createFromProperties(propsets,ifcfile):
|
||||
|
||||
"creates a FreeCAD parametric object from a set of properties"
|
||||
@@ -2514,6 +2510,7 @@ def createCurve(ifcfile,wire):
|
||||
pol = ifcfile.createIfcCompositeCurve(segments,False)
|
||||
return pol
|
||||
|
||||
|
||||
def getEdgesAngle(edge1, edge2):
|
||||
""" getEdgesAngle(edge1, edge2): returns a angle between two edges."""
|
||||
vec1 = vec(edge1)
|
||||
@@ -2522,6 +2519,7 @@ def getEdgesAngle(edge1, edge2):
|
||||
angle = math.degrees(angle)
|
||||
return angle
|
||||
|
||||
|
||||
def checkRectangle(edges):
|
||||
""" checkRectangle(edges=[]): This function checks whether the given form is a rectangle
|
||||
or not. It will return True when edges form a rectangular shape or return False
|
||||
@@ -2536,6 +2534,7 @@ def checkRectangle(edges):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getProfile(ifcfile,p):
|
||||
|
||||
"""returns an IFC profile definition from a shape"""
|
||||
|
||||
Reference in New Issue
Block a user