def set_systems(ifcfile, project, version, branch): IfcSystem = ifcfile.by_type("IfcSystem") m = mongo.MongoDb() m.define_collection('system') client = m.get_mongo_client() i = 0 for system in IfcSystem: c = { 'pid': system.id(), 'systemCode': system[2], 'description': system[3], 'project': project, 'version': version, 'branch': branch, 'products': [] } m.insert_one(c) i = i + 1 print(i) IfcRelAssigns = ifcfile.by_type("IfcRelAssigns") print("Starting system product mapping") sys = {} for relSystem in IfcRelAssigns: syst = m.query({ 'project': project, 'version': version, 'pid': relSystem[6].id() }) if syst.count() > 0: for prod in relSystem[4]: prod = client['product'].find({ 'project': project, 'version': version, 'pid': prod.id() }) if prod.count() > 0: sys[prod.id()] = str(syst[0]['_id']) i = i + 1 print(i) return sys
def set_storey_relations(ifcfile, project, version, branch): site = ['IfcSite'] building = ['IfcBuilding'] floor = ['IfcBuildingStorey'] structure = [ 'IfcBeam', 'IfcBeamStandardCase', 'IfcColumn', 'IfcColumnStandardCase', 'IfcSlab', 'IfcFooting', 'IfcPile', 'IfcTendon' ] wall = ['IfcWall', 'IfcWallStandardCase', 'IfcCurtainWall'] window = ['IfcWindow', 'IfcWindowStandardCase'] door = ['IfcDoor', 'IfcDoorStandardCase'] roof = ['IfcRoof'] stairs = ['IfcStair', 'IfcStairFlight', 'IfcRamp', 'IfcRampFlight'] space = ['IfcSpace'] rebar = ['IfcReinforcingBar'], panel = ['IfcPlate'] equipment = [ 'IfcFurnishingElement', 'IfcSanitaryTerminal', 'IfcFlowTerminal', 'IfcElectricAppliance' ] pipe = ['IfcPipeSegment'] pipeConnector = ['IfcPipeFitting'] floors = ifcfile.by_type("IfcBuildingStorey") IfcRelAggregates = ifcfile.by_type("IfcRelAggregates") IfcRelContainedInSpatialStructure = ifcfile.by_type( "IfcRelContainedInSpatialStructure") m = mongo.MongoDb() client = m.get_mongo_client() relStorey = {} relSpace = {} for rel in IfcRelAggregates: if rel[4].is_a() == "IfcBuildingStorey": storey = client['storey'].find({ 'project': project, 'pid': rel[4].id() }) if storey.count() > 0: for r in rel[5]: relStorey[r.id()] = str(storey[0]['_id']) for rel in IfcRelContainedInSpatialStructure: if rel[5].is_a() == "IfcBuildingStorey": storey = client['storey'].find({ 'project': project, 'pid': rel[5].id() }) if storey.count() > 0: for r in rel[4]: relStorey[r.id()] = str(storey[0]['_id']) if rel[5].is_a() == "IfcSpace": for r in rel[4]: relSpace[r.id()] = rel[5].id() rooms = ifcfile.by_type("IfcSpace") for room in rooms: if len(room.ContainsElements) > 0: for r in room.ContainsElements[0][4]: relSpace[r.id()] = room.id() return relStorey, relSpace
def iterate_shape(product, colors, project, ifcfile, length, prefix, count, branch, version, relStorey, relSpace, relSystem): site = ['IfcSite'] building = ['IfcBuilding'] floor = ['IfcBuildingStorey'] structure = [ 'IfcBeam', 'IfcBeamStandardCase', 'IfcColumn', 'IfcColumnStandardCase', 'IfcSlab', 'IfcFooting', 'IfcPile', 'IfcTendon' ] wall = ['IfcWall', 'IfcWallStandardCase', 'IfcCurtainWall'] window = ['IfcWindow', 'IfcWindowStandardCase'] door = ['IfcDoor', 'IfcDoorStandardCase'] roof = ['IfcRoof'] stairs = ['IfcStair', 'IfcStairFlight', 'IfcRamp', 'IfcRampFlight'] space = ['IfcSpace'] rebar = ['IfcReinforcingBar'], panel = ['IfcPlate'] equipment = [ 'IfcFurnishingElement', 'IfcSanitaryTerminal', 'IfcFlowTerminal', 'IfcElectricAppliance' ] pipe = ['IfcPipeSegment', 'IfcFlowSegment'] pipeConnector = ['IfcPipeFitting'] opening = ['IfcOpeningElement'] # Prepere mongoDB m = mongo.MongoDb() pid = product.id() guid = product.GlobalId ptype = product.is_a() name = "" if product.Name: name = product.Name if ptype not in floor: if pid in relStorey: stor = relStorey[pid] else: stor = [] if ptype not in space: if pid in relSpace: s = m.get_mongo_client['space'].find({ 'version': version, 'pid': relSpace[pid] }) if s.count() > 0: space = str(s[0]['_id']) else: space = [] if pid in relSystem: system = relSystem[pid] else: system = [] #if product.Representation: # 2D footprint -if we need 2D # for r in product.Representation.Representations: # if r.RepresentationIdentifier == "FootPrint": # print("annotation") try: shape = get_shape(product) except: shape = None if shape is not None: if ptype in building: m.define_collection('building') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name } m.insert_one(dict) elif ptype in floor: # IFC Building storey or IfcRoof top = correctLengt( product.ObjectPlacement.RelativePlacement.Location. Coordinates[2], length, prefix) bottom = correctLengt( product.ObjectPlacement.RelativePlacement.Location. Coordinates[1], length, prefix) vertices = get_vertices(shape, length) corners = get_corners(vertices, False) bbox = get_bbox(shape, length) m.define_collection('storey') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name, 'top': top, 'bottom': bottom, 'vertices': vertices, 'corners': corners, 'bbox': bbox } m.insert_one(dict) elif ptype in space: # IFCSpaces - building rooms / zones area = calc_area(product) vertices = get_vertices(shape, length) corners = get_corners(vertices, True) bbox = get_bbox(shape, length) m.define_collection('space') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name, 'longName': product.LongName, 'area': area, 'vertices': vertices, 'corners': corners, 'bbox': bbox, 'storey': stor } m.insert_one(dict) elif ptype in opening: # IFCWalls vertices = get_vertices(shape, length) corners = get_corners(vertices, False) bbox = get_bbox(shape, length) m.define_collection('opening') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name, 'vertices': vertices, 'corners': corners, 'bbox': bbox, 'storey': stor } m.insert_one(dict) else: # IFC objects / products - rest av all products vertices = get_vertices(shape, length) corners = get_corners(vertices, False) bbox = get_bbox(shape, length) m.define_collection('product') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name, 'vertices': vertices, 'corners': corners, 'bbox': bbox, 'storey': stor, 'space': space, 'system': system } m.insert_one(dict) else: if ptype in floor: top = correctLengt( product.ObjectPlacement.RelativePlacement.Location. Coordinates[2], length, prefix) bottom = correctLengt( product.ObjectPlacement.RelativePlacement.Location. Coordinates[1], length, prefix) m.define_collection('storey') dict = { 'project': project, 'branch': branch, 'version': version, 'pid': pid, 'guid': guid, 'ptype': ptype, 'name': name, 'top': top, 'bottom': bottom } m.insert_one(dict) else: print("No shape and not IfcBuildingStorey") print(ptype) print(guid) print(count)
def import_ifc(datafile, project, branch): #if kwargs.get(created, False): # file = kwargs.get('instance') print("Start") # which IFC type must create which Connected Properties type #ifcfiles = IfcFile.objects.filter(project=project) #version = len(ifcfiles)-1 ifcfile = ifcopenshell.open(datafile) #ifcfile = ifcopenshell.open(ifcfiles[version].datafile.path) #project = datafile.project.all()[0] # building relations tables prodrepr = {} # product/representations table mattable = {} # { objid:matid } floorAnnotations = {} # { host:[child,...], ... } additions = {} # { host:[child,...], ... } colors = {} # { id:(r,g,b)} groups = {} # { host:[child,...], ... } # used in structural IFC subtractions = [] # [ [opening,host], ... ] properties = {} # { obj : { cat : [property, ... ], ... }, ... } pMatrix = [] floors = ifcfile.by_type("IfcBuildingStorey") products = ifcfile.by_type("IfcProduct") openings = ifcfile.by_type("IfcOpeningElement") annotations = ifcfile.by_type("IfcAnnotation") materials = ifcfile.by_type("IfcMaterial") rooms = ifcfile.by_type("IfcSpace") relFillsElements = ifcfile.by_type("IfcRelFillsElement") relVoidsElements = ifcfile.by_type("IfcRelVoidsElement") ifcProject = ifcfile.by_type("IfcProject")[0] unit = ifcfile.by_type("IfcSIUnit")[0] length = unit.Name prefix = unit.Prefix # Query version version = 0 m = mongo.MongoDb() m.define_collection('version') q = {'project': project, 'branch': branch} query = m.query(q) if len(query) == 0: version = 0 else: for q in query: if q['version'] > version: version = q['version'] version = version + 1 vId = m.insert_one({ 'project': project, 'branch': branch, 'version': version }) count = 0 print("loading storeys") for product in floors: count = count + 1 iterate_shape(product, colors, project, ifcfile, length, prefix, count, branch, vId, None, None, None) relStorey, relSpace = set_storey_relations(ifcfile, project, vId, branch) relSystem = set_systems(ifcfile, project, vId, branch) print("loading rooms") for product in rooms: count = count + 1 iterate_shape(product, colors, project, ifcfile, length, prefix, count, branch, vId, relStorey, relSpace, relSystem) print("loading products") for product in products: count = count + 1 iterate_shape(product, colors, project, ifcfile, length, prefix, count, branch, vId, relStorey, relSpace, relSystem)
def __init__(self, project): self.db = m.MongoDb() self.db.define_collection('tag_structure') self.project = project self.tags_before_running_index = []