Arch: import IFC and helper, code formating, E261 at least two spaces before inline comment
This commit is contained in:
@@ -45,11 +45,11 @@ import importIFCHelper
|
||||
#
|
||||
# This module provides tools to import IFC files.
|
||||
|
||||
DEBUG = False # Set to True to see debug messages. Otherwise, totally silent
|
||||
ZOOMOUT = True # Set to False to not zoom extents after import
|
||||
DEBUG = False # Set to True to see debug messages. Otherwise, totally silent
|
||||
ZOOMOUT = True # Set to False to not zoom extents after import
|
||||
|
||||
if open.__module__ in ['__builtin__','io']:
|
||||
pyopen = open # because we'll redefine open below
|
||||
pyopen = open # because we'll redefine open below
|
||||
|
||||
|
||||
# ************************************************************************************************
|
||||
@@ -258,12 +258,12 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
materials = ifcfile.by_type("IfcMaterial")
|
||||
products, annotations = importIFCHelper.buildRelProductsAnnotations(ifcfile, preferences['ROOT_ELEMENT'])
|
||||
# empty relation tables
|
||||
objects = {} # { id:object, ... }
|
||||
shapes = {} # { id:shaoe } only used for merge mode
|
||||
structshapes = {} # { id:shaoe } only used for merge mode
|
||||
sharedobjects = {} # { representationmapid:object }
|
||||
parametrics = [] # a list of imported objects whose parametric relationships need processing after all objects have been created
|
||||
profiles = {} # to store reused extrusion profiles {ifcid:fcobj,...}
|
||||
objects = {} # { id:object, ... }
|
||||
shapes = {} # { id:shaoe } only used for merge mode
|
||||
structshapes = {} # { id:shaoe } only used for merge mode
|
||||
sharedobjects = {} # { representationmapid:object }
|
||||
parametrics = [] # a list of imported objects whose parametric relationships need processing after all objects have been created
|
||||
profiles = {} # to store reused extrusion profiles {ifcid:fcobj,...}
|
||||
# filled relation tables
|
||||
# TODO for the following tables might be better use inverse attributes, done for properties
|
||||
# see https://forum.freecadweb.org/viewtopic.php?f=39&t=37892
|
||||
@@ -356,10 +356,10 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
if preferences['MERGE_MODE_STRUCT'] == 3 and not archobj:
|
||||
if preferences['DEBUG']: print(" skipped.")
|
||||
continue
|
||||
if pid in skip: # user given id skip list
|
||||
if pid in skip: # user given id skip list
|
||||
if preferences['DEBUG']: print(" skipped.")
|
||||
continue
|
||||
if ptype in preferences['SKIP']: # preferences-set type skip list
|
||||
if ptype in preferences['SKIP']: # preferences-set type skip list
|
||||
if preferences['DEBUG']: print(" skipped.")
|
||||
continue
|
||||
|
||||
@@ -380,7 +380,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
clone = sharedobjects[originalid]
|
||||
else:
|
||||
sharedobjects[originalid] = None
|
||||
store = originalid # flag this object to be stored later
|
||||
store = originalid # flag this object to be stored later
|
||||
|
||||
# set additional setting for structural entities
|
||||
if hasattr(settings,"INCLUDE_CURVES"):
|
||||
@@ -392,7 +392,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
cr = ifcopenshell.geom.create_shape(settings,product)
|
||||
brep = cr.geometry.brep_data
|
||||
except:
|
||||
pass # IfcOpenShell will yield an error if a given product has no shape, but we don't care, we're brave enough
|
||||
pass # IfcOpenShell will yield an error if a given product has no shape, but we don't care, we're brave enough
|
||||
|
||||
# from now on we have a brep string
|
||||
if brep:
|
||||
@@ -401,7 +401,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
# create a Part shape
|
||||
shape = Part.Shape()
|
||||
shape.importBrepFromString(brep,False)
|
||||
shape.scale(1000.0) # IfcOpenShell always outputs in meters, we convert to mm, the freecad internal unit
|
||||
shape.scale(1000.0) # IfcOpenShell always outputs in meters, we convert to mm, the freecad internal unit
|
||||
|
||||
if shape.isNull():
|
||||
if preferences['DEBUG']: print("null shape ",end="")
|
||||
@@ -428,7 +428,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
# we are not using Arch objects
|
||||
|
||||
# additional tweaks to set when not using Arch objects
|
||||
if ptype == "IfcSpace": # do not add spaces to compounds
|
||||
if ptype == "IfcSpace": # do not add spaces to compounds
|
||||
if preferences['DEBUG']: print("skipping space ",pid,end="")
|
||||
elif structobj:
|
||||
structshapes[pid] = shape
|
||||
@@ -451,7 +451,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
sortmethod = "z"
|
||||
else:
|
||||
sortmethod = "area"
|
||||
ex = Arch.getExtrusionData(shape,sortmethod) # is this an extrusion?
|
||||
ex = Arch.getExtrusionData(shape,sortmethod) # is this an extrusion?
|
||||
if ex:
|
||||
|
||||
# check for extrusion profile
|
||||
@@ -756,7 +756,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
for p in psets[c]:
|
||||
l = ifcfile[p]
|
||||
if l.is_a("IfcPropertySingleValue"):
|
||||
a[l.Name.encode("utf8")] = str(l.NominalValue) # no py3 support here
|
||||
a[l.Name.encode("utf8")] = str(l.NominalValue) # no py3 support here
|
||||
obj.IfcData = a
|
||||
|
||||
# color
|
||||
@@ -818,7 +818,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
|
||||
if preferences['DEBUG']: print("Joining Structural shapes...",end="")
|
||||
|
||||
for host,children in groups.items(): # Structural
|
||||
for host,children in groups.items(): # Structural
|
||||
if ifcfile[host].is_a("IfcStructuralAnalysisModel"):
|
||||
compound = []
|
||||
for c in children:
|
||||
@@ -831,7 +831,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
|
||||
obj.Label = name
|
||||
obj.Shape = Part.makeCompound(compound)
|
||||
if structshapes: # remaining Structural shapes
|
||||
if structshapes: # remaining Structural shapes
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedStruct")
|
||||
obj.Shape = Part.makeCompound(structshapes.values())
|
||||
|
||||
@@ -902,7 +902,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
|
||||
if preferences['DEBUG']: print("Joining Arch shapes...",end="")
|
||||
|
||||
for host,children in additions.items(): # Arch
|
||||
for host,children in additions.items(): # Arch
|
||||
if ifcfile[host].is_a("IfcBuildingStorey"):
|
||||
compound = []
|
||||
for c in children:
|
||||
@@ -920,7 +920,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
|
||||
obj.Label = name
|
||||
obj.Shape = Part.makeCompound(compound)
|
||||
if shapes: # remaining Arch shapes
|
||||
if shapes: # remaining Arch shapes
|
||||
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedArch")
|
||||
obj.Shape = Part.makeCompound(shapes.values())
|
||||
|
||||
@@ -951,7 +951,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
cobs = []
|
||||
for child in children:
|
||||
if child in objects.keys() \
|
||||
and child not in swallowed: # don't add objects already in groups
|
||||
and child not in swallowed: # don't add objects already in groups
|
||||
cobs.append(objects[child])
|
||||
if not cobs:
|
||||
continue
|
||||
@@ -995,9 +995,9 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
if preferences['DEBUG']: print(count,"/",len(annotations),"object #"+str(aid),":",annotation.is_a(),end="")
|
||||
|
||||
if aid in skip:
|
||||
continue # user given id skip list
|
||||
continue # user given id skip list
|
||||
if annotation.is_a() in preferences['SKIP']:
|
||||
continue # preferences-set type skip list
|
||||
continue # preferences-set type skip list
|
||||
if annotation.is_a("IfcGrid"):
|
||||
axes = []
|
||||
uvwaxes = ()
|
||||
@@ -1010,7 +1010,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
for axis in uvwaxes:
|
||||
if axis.AxisCurve:
|
||||
sh = importIFCHelper.get2DShape(axis.AxisCurve,ifcscale)
|
||||
if sh and (len(sh[0].Vertexes) == 2): # currently only straight axes are supported
|
||||
if sh and (len(sh[0].Vertexes) == 2): # currently only straight axes are supported
|
||||
sh = sh[0]
|
||||
l = sh.Length
|
||||
pl = FreeCAD.Placement()
|
||||
@@ -1055,7 +1055,7 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None):
|
||||
anno = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
|
||||
anno.Shape = sh
|
||||
p = importIFCHelper.getPlacement(annotation.ObjectPlacement,ifcscale)
|
||||
if p: # and annotation.is_a("IfcAnnotation"):
|
||||
if p: # and annotation.is_a("IfcAnnotation"):
|
||||
anno.Placement = p
|
||||
else:
|
||||
if preferences['DEBUG']: print(" no shape")
|
||||
|
||||
@@ -166,7 +166,7 @@ def buildRelProductsAnnotations(ifcfile, root_element):
|
||||
def buildRelProductRepresentation(ifcfile):
|
||||
"""build the product/representations relation table"""
|
||||
|
||||
prodrepr = {} # product/representations table
|
||||
prodrepr = {} # product/representations table
|
||||
|
||||
for p in ifcfile.by_type("IfcProduct"):
|
||||
if hasattr(p,"Representation"):
|
||||
@@ -188,7 +188,7 @@ def buildRelProductRepresentation(ifcfile):
|
||||
def buildRelAdditions(ifcfile):
|
||||
"""build the additions relation table"""
|
||||
|
||||
additions = {} # { host:[child,...], ... }
|
||||
additions = {} # { host:[child,...], ... }
|
||||
|
||||
for r in ifcfile.by_type("IfcRelContainedInSpatialStructure"):
|
||||
additions.setdefault(r.RelatingStructure.id(),[]).extend([e.id() for e in r.RelatedElements])
|
||||
@@ -201,7 +201,7 @@ def buildRelAdditions(ifcfile):
|
||||
def buildRelGroups(ifcfile):
|
||||
"""build the groups relation table"""
|
||||
|
||||
groups = {} # { host:[child,...], ... } # used in structural IFC
|
||||
groups = {} # { host:[child,...], ... } # used in structural IFC
|
||||
|
||||
for r in ifcfile.by_type("IfcRelAssignsToGroup"):
|
||||
groups.setdefault(r.RelatingGroup.id(),[]).extend([e.id() for e in r.RelatedObjects])
|
||||
@@ -212,7 +212,7 @@ def buildRelGroups(ifcfile):
|
||||
def buildRelSubtractions(ifcfile):
|
||||
"""build the subtractions relation table"""
|
||||
|
||||
subtractions = [] # [ [opening,host], ... ]
|
||||
subtractions = [] # [ [opening,host], ... ]
|
||||
|
||||
for r in ifcfile.by_type("IfcRelVoidsElement"):
|
||||
subtractions.append([r.RelatedOpeningElement.id(), r.RelatingBuildingElement.id()])
|
||||
@@ -223,7 +223,7 @@ def buildRelSubtractions(ifcfile):
|
||||
def buildRelMattable(ifcfile):
|
||||
"""build the mattable relation table"""
|
||||
|
||||
mattable = {} # { objid:matid }
|
||||
mattable = {} # { objid:matid }
|
||||
|
||||
for r in ifcfile.by_type("IfcRelAssociatesMaterial"):
|
||||
for o in r.RelatedObjects:
|
||||
@@ -249,7 +249,7 @@ def buildRelColors(ifcfile, prodrepr):
|
||||
"""build the colors relation table and"""
|
||||
|
||||
# returns all IfcStyledItem colors, material and product colors
|
||||
colors = {} # { id:(r,g,b) }
|
||||
colors = {} # { id:(r,g,b) }
|
||||
style_material_id = {} # { style_entity_id: material_id) }
|
||||
|
||||
# get style_color_rgb table
|
||||
@@ -311,7 +311,7 @@ def buildRelColors(ifcfile, prodrepr):
|
||||
def buildRelProductColors(ifcfile, prodrepr):
|
||||
|
||||
# gets the colors for the products
|
||||
colors = {} # { id:(r,g,b) }
|
||||
colors = {} # { id:(r,g,b) }
|
||||
|
||||
for p in prodrepr.keys():
|
||||
|
||||
@@ -421,7 +421,7 @@ def buildRelProperties(ifcfile):
|
||||
# this method no longer used by the importer module
|
||||
# but this relation table might be useful anyway for other purposes
|
||||
|
||||
properties = {} # { objid : { psetid : [propertyid, ... ], ... }, ... }
|
||||
properties = {} # { objid : { psetid : [propertyid, ... ], ... }, ... }
|
||||
for r in ifcfile.by_type("IfcRelDefinesByProperties"):
|
||||
for obj in r.RelatedObjects:
|
||||
if not obj.id() in properties:
|
||||
@@ -548,8 +548,8 @@ def getPlacement(entity,scaling=1000):
|
||||
if loc:
|
||||
pl.move(loc)
|
||||
elif entity.is_a("IfcLocalPlacement"):
|
||||
pl = getPlacement(entity.PlacementRelTo,1) # original placement
|
||||
relpl = getPlacement(entity.RelativePlacement,1) # relative transf
|
||||
pl = getPlacement(entity.PlacementRelTo,1) # original placement
|
||||
relpl = getPlacement(entity.RelativePlacement,1) # relative transf
|
||||
if pl and relpl:
|
||||
pl = pl.multiply(relpl)
|
||||
elif relpl:
|
||||
@@ -683,7 +683,7 @@ def get2DShape(representation,scaling=1000):
|
||||
result = preresult
|
||||
elif item.is_a("IfcTextLiteral"):
|
||||
t = Draft.makeText([item.Literal],point=getPlacement(item.Placement,scaling).Base)
|
||||
return t # dirty hack... Object creation should not be done here
|
||||
return t # dirty hack... Object creation should not be done here
|
||||
elif representation.is_a() in ["IfcPolyline","IfcCircle","IfcTrimmedCurve"]:
|
||||
result = getCurveSet(representation)
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user