Arch: IFC export and import, some code formating (only very clearly ones)
This commit is contained in:
@@ -961,7 +961,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
for c in objs:
|
||||
if c.Name in products and c.Name not in treated:
|
||||
prod = products[c.Name]
|
||||
if prod.is_a()=='IfcSpace':
|
||||
if prod.is_a() == 'IfcSpace':
|
||||
spaces.append(prod)
|
||||
else:
|
||||
buildingelements.append(prod)
|
||||
@@ -1193,7 +1193,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
if defaulthost:
|
||||
spaces, buildingelements = [],[]
|
||||
for entity in untreated:
|
||||
if entity.is_a()=="IfcSpace":
|
||||
if entity.is_a() == "IfcSpace":
|
||||
spaces.append(entity)
|
||||
else:
|
||||
buildingelements.append(entity)
|
||||
@@ -1214,7 +1214,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
'',
|
||||
buildingelements,
|
||||
defaulthost
|
||||
)
|
||||
)
|
||||
else:
|
||||
# no default host: aggregate unassigned objects directly under the IfcProject - WARNING: NON STANDARD
|
||||
if preferences['DEBUG']: print("WARNING - Default building generation is disabled. You are producing a non-standard file.")
|
||||
@@ -1258,7 +1258,7 @@ def export(exportList, filename, colors=None, preferences=None):
|
||||
rgb = tuple([float(f) for f in m.Material[colorslot].strip("()").split(",")])
|
||||
break
|
||||
if rgb:
|
||||
psa = ifcbin.createIfcPresentationStyleAssignment(l,rgb[0],rgb[1],rgb[2],ifc4=(preferences["SCHEMA"]=="IFC4"))
|
||||
psa = ifcbin.createIfcPresentationStyleAssignment(l,rgb[0],rgb[1],rgb[2],ifc4=(preferences["SCHEMA"] == "IFC4"))
|
||||
isi = ifcfile.createIfcStyledItem(None,[psa],None)
|
||||
isr = ifcfile.createIfcStyledRepresentation(context,"Style","Material",[isi])
|
||||
imd = ifcfile.createIfcMaterialDefinitionRepresentation(None,None,[isr],mat)
|
||||
@@ -1648,7 +1648,7 @@ def getIfcTypeFromObj(obj):
|
||||
if ifctype in translationtable.keys():
|
||||
ifctype = translationtable[ifctype]
|
||||
|
||||
if not "::" in ifctype:
|
||||
if "::" not in ifctype:
|
||||
ifctype = "Ifc" + ifctype
|
||||
elif ifctype == "IfcApp::DocumentObjctGroup":
|
||||
ifctype = "IfcGroup"
|
||||
@@ -1737,7 +1737,6 @@ def buildAddress(obj,ifcfile):
|
||||
|
||||
|
||||
def createCurve(ifcfile,wire,scaling=1.0):
|
||||
|
||||
"creates an IfcCompositeCurve from a shape"
|
||||
|
||||
segments = []
|
||||
@@ -1810,7 +1809,6 @@ def createCurve(ifcfile,wire,scaling=1.0):
|
||||
|
||||
|
||||
def getEdgesAngle(edge1, edge2):
|
||||
|
||||
""" getEdgesAngle(edge1, edge2): returns a angle between two edges."""
|
||||
|
||||
vec1 = vec(edge1)
|
||||
@@ -1821,7 +1819,6 @@ def getEdgesAngle(edge1, edge2):
|
||||
|
||||
|
||||
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
|
||||
when edges do not form a rectangular shape."""
|
||||
@@ -1841,7 +1838,6 @@ def checkRectangle(edges):
|
||||
|
||||
|
||||
def getProfile(ifcfile,p):
|
||||
|
||||
"""returns an IFC profile definition from a shape"""
|
||||
|
||||
import Part
|
||||
@@ -1905,8 +1901,18 @@ def getProfile(ifcfile,p):
|
||||
return profile
|
||||
|
||||
|
||||
def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tessellation=1,colors=None,preferences=None,forceclone=False,skipshape=False):
|
||||
|
||||
def getRepresentation(
|
||||
ifcfile,
|
||||
context,
|
||||
obj,
|
||||
forcebrep=False,
|
||||
subtraction=False,
|
||||
tessellation=1,
|
||||
colors=None,
|
||||
preferences=None,
|
||||
forceclone=False,
|
||||
skipshape=False
|
||||
):
|
||||
"""returns an IfcShapeRepresentation object or None. forceclone can be False (does nothing),
|
||||
"store" or True (stores the object as clone base) or a Vector (creates a clone)"""
|
||||
|
||||
@@ -1924,7 +1930,7 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||
|
||||
if ((not subtraction) and (not forcebrep)) or forceclone:
|
||||
if forceclone:
|
||||
if not obj.Name in clones:
|
||||
if obj.Name not in clones:
|
||||
clones[obj.Name] = []
|
||||
for k,v in clones.items():
|
||||
if (obj.Name == k) or (obj.Name in v):
|
||||
@@ -2051,7 +2057,6 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||
solidType = "SweptSolid"
|
||||
shapetype = "extrusion"
|
||||
|
||||
|
||||
if (not shapes) and (not skipshape):
|
||||
|
||||
# check if we keep a null shape (additions-only object)
|
||||
@@ -2382,7 +2387,6 @@ def getText(field,obj):
|
||||
|
||||
|
||||
def getAxisContext(ifcfile):
|
||||
|
||||
"""gets or creates an axis context"""
|
||||
|
||||
contexts = ifcfile.by_type("IfcGeometricRepresentationContext")
|
||||
@@ -2393,12 +2397,11 @@ def getAxisContext(ifcfile):
|
||||
if ctx.ContextIdentifier == "Axis":
|
||||
return ctx
|
||||
ctx = contexts[0] # arbitrarily take the first one...
|
||||
nctx = ifcfile.createIfcGeometricRepresentationSubContext('Axis','Model',None,None,None,None,ctx,None,"MODEL_VIEW",None);
|
||||
nctx = ifcfile.createIfcGeometricRepresentationSubContext('Axis','Model',None,None,None,None,ctx,None,"MODEL_VIEW",None)
|
||||
return nctx
|
||||
|
||||
|
||||
def createAxis(ifcfile,obj,preferences):
|
||||
|
||||
"""Creates an axis for a given wall, if applicable"""
|
||||
|
||||
if hasattr(obj,"Base") and hasattr(obj.Base,"Shape") and obj.Base.Shape:
|
||||
@@ -2412,7 +2415,6 @@ def createAxis(ifcfile,obj,preferences):
|
||||
|
||||
|
||||
def writeJson(filename,ifcfile):
|
||||
|
||||
"""writes an .ifcjson file"""
|
||||
|
||||
import json
|
||||
|
||||
@@ -38,18 +38,17 @@ def getObjectsOfIfcType(objects, ifcType):
|
||||
|
||||
|
||||
def writeUnits(ifcfile,unit="metre"):
|
||||
|
||||
"""adds additional units settings to the given ifc file if needed"""
|
||||
# so far, only metre or foot possible (which is all revit knows anyway)
|
||||
|
||||
if unit == "foot":
|
||||
d1 = ifcfile.createIfcDimensionalExponents(1,0,0,0,0,0,0);
|
||||
d1 = ifcfile.createIfcDimensionalExponents(1,0,0,0,0,0,0)
|
||||
d2 = ifcfile.createIfcMeasureWithUnit(ifcfile.createIfcRatioMeasure(0.3048),ifcfile[13])
|
||||
d3 = ifcfile.createIfcConversionBasedUnit(d1,'LENGTHUNIT','FOOT',d2)
|
||||
d4 = ifcfile.createIfcDimensionalExponents(2,0,0,0,0,0,0);
|
||||
d4 = ifcfile.createIfcDimensionalExponents(2,0,0,0,0,0,0)
|
||||
d5 = ifcfile.createIfcMeasureWithUnit(ifcfile.createIfcRatioMeasure(0.09290304000000001),ifcfile[14])
|
||||
d6 = ifcfile.createIfcConversionBasedUnit(d4,'AREAUNIT','SQUARE FOOT',d5)
|
||||
d7 = ifcfile.createIfcDimensionalExponents(3,0,0,0,0,0,0);
|
||||
d7 = ifcfile.createIfcDimensionalExponents(3,0,0,0,0,0,0)
|
||||
d8 = ifcfile.createIfcMeasureWithUnit(ifcfile.createIfcRatioMeasure(0.028316846592),ifcfile[15])
|
||||
d9 = ifcfile.createIfcConversionBasedUnit(d7,'VOLUMEUNIT','CUBIC FOOT',d8)
|
||||
ifcfile.createIfcUnitAssignment((d3,d6,d9,ifcfile[18]))
|
||||
|
||||
@@ -415,7 +415,6 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
else:
|
||||
if preferences['DEBUG']: print(" no layer found", ptype,end="")
|
||||
|
||||
|
||||
# checking for full FreeCAD parametric definition, overriding everything else
|
||||
if psets and FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("IfcImportFreeCADProperties",False):
|
||||
if "FreeCADPropertySet" in [ifcfile[pset].Name for pset in psets.keys()]:
|
||||
@@ -465,7 +464,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
if ptype in preferences['SKIP']: # preferences-set type skip list
|
||||
if preferences['DEBUG']: print(" skipped.")
|
||||
continue
|
||||
if preferences['REPLACE_PROJECT']: # options-enabled project/site/building skip
|
||||
if preferences['REPLACE_PROJECT']: # options-enabled project/site/building skip
|
||||
if ptype in ['IfcProject','IfcSite']:
|
||||
if preferences['DEBUG']: print(" skipped.")
|
||||
continue
|
||||
@@ -522,7 +521,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
|
||||
if shape.isNull() and (not preferences['ALLOW_INVALID']):
|
||||
if preferences['DEBUG']: print("null shape ",end="")
|
||||
elif not shape.isValid() and (not preferences['ALLOW_INVALID']):
|
||||
elif not shape.isValid() and (not preferences['ALLOW_INVALID']):
|
||||
if preferences['DEBUG']: print("invalid shape ",end="")
|
||||
else:
|
||||
|
||||
@@ -915,13 +914,13 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
if (pid in colors) and colors[pid]:
|
||||
colordict[obj.Name] = colors[pid]
|
||||
if FreeCAD.GuiUp:
|
||||
# if preferences['DEBUG']: print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255))
|
||||
# if preferences['DEBUG']:
|
||||
# print(" setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255))
|
||||
if hasattr(obj.ViewObject,"ShapeColor"):
|
||||
obj.ViewObject.ShapeColor = tuple(colors[pid][0:3])
|
||||
if hasattr(obj.ViewObject,"Transparency"):
|
||||
obj.ViewObject.Transparency = colors[pid][3]
|
||||
|
||||
|
||||
# if preferences['DEBUG'] is on, recompute after each shape
|
||||
if preferences['DEBUG']: FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
@@ -962,7 +961,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
# But that would actually be an invalid IFC file, because the magnitude
|
||||
# of the (twodimensional) direction vector for TrueNorth shall be greater than zero.
|
||||
(x, y) = modelRC.TrueNorth.DirectionRatios[:2]
|
||||
obj.Declination = ((math.degrees(math.atan2(y,x))-90+180)%360)-180
|
||||
obj.Declination = ((math.degrees(math.atan2(y,x))-90+180) % 360)-180
|
||||
if (FreeCAD.GuiUp):
|
||||
obj.ViewObject.CompassRotation.Value = obj.Declination
|
||||
|
||||
@@ -1123,7 +1122,11 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
if preferences['DEBUG'] and first:
|
||||
print("")
|
||||
first = False
|
||||
if preferences['DEBUG'] and (len(cobs) > 10) and (not(Draft.getType(objects[host]) in ["Site","Building","Floor","BuildingPart","Project"])):
|
||||
if (
|
||||
preferences['DEBUG']
|
||||
and (len(cobs) > 10)
|
||||
and (not(Draft.getType(objects[host]) in ["Site","Building","Floor","BuildingPart","Project"]))
|
||||
):
|
||||
# avoid huge fusions
|
||||
print("more than 10 shapes to add: skipping.")
|
||||
else:
|
||||
@@ -1334,7 +1337,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
# if REPLACE_PROJECT and only one storey and one building both are omitted
|
||||
# the pure objects do not belong to any container, they will be added here
|
||||
# if after Layer they are linked by Layer and will not be added here
|
||||
if preferences['REPLACE_PROJECT'] and filename:
|
||||
if preferences["REPLACE_PROJECT"] and filename:
|
||||
rootgroup = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Group")
|
||||
rootgroup.Label = os.path.basename(filename)
|
||||
# print(objects)
|
||||
@@ -1348,7 +1351,7 @@ def insert(srcfile, docname, skip=[], only=[], root=None, preferences=None):
|
||||
if preferences['DEBUG'] and layers: print("Creating layers...", end="")
|
||||
# print(layers)
|
||||
for layer_name, layer_objects in layers.items():
|
||||
if preferences['IMPORT_LAYER'] is False:
|
||||
if preferences["IMPORT_LAYER"] is False:
|
||||
continue
|
||||
# the method make_layer does some nasty debug prints
|
||||
lay = Draft.make_layer(layer_name)
|
||||
|
||||
@@ -396,6 +396,7 @@ def getColorFromProduct(product):
|
||||
if color:
|
||||
return color
|
||||
|
||||
|
||||
def getColorFromMaterial(material):
|
||||
|
||||
if material.HasRepresentation:
|
||||
@@ -540,6 +541,8 @@ def predefined_to_rgb(rgb_color):
|
||||
|
||||
# ************************************************************************************************
|
||||
# property related methods
|
||||
|
||||
|
||||
def buildRelProperties(ifcfile):
|
||||
"""
|
||||
Builds and returns a dictionary of {object:[properties]} from an IFC file
|
||||
@@ -814,6 +817,7 @@ def get2DShape(representation,scaling=1000):
|
||||
result.append(e)
|
||||
elif el.is_a("IfcIndexedPolyCurve"):
|
||||
coords = el.Points.CoordList
|
||||
|
||||
def index2points(segment):
|
||||
pts = []
|
||||
for i in segment.wrappedValue:
|
||||
@@ -898,7 +902,6 @@ def isRectangle(verts):
|
||||
|
||||
|
||||
def createFromProperties(propsets,ifcfile,parametrics):
|
||||
|
||||
"""
|
||||
Creates a FreeCAD parametric object from a set of properties.
|
||||
"""
|
||||
@@ -986,7 +989,6 @@ def createFromProperties(propsets,ifcfile,parametrics):
|
||||
|
||||
|
||||
def applyColorDict(doc,colordict=None):
|
||||
|
||||
"""applies the contents of a color dict to the objects in the given doc.
|
||||
If no colordict is given, the doc Meta property is searched for a "colordict" entry."""
|
||||
|
||||
@@ -1007,7 +1009,6 @@ def applyColorDict(doc,colordict=None):
|
||||
|
||||
|
||||
def getParents(ifcobj):
|
||||
|
||||
"""finds the parent entities of an IFC entity"""
|
||||
|
||||
parentlist = []
|
||||
|
||||
Reference in New Issue
Block a user