mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Merge branch 'v0.6.0' of https://github.com/IfcOpenShell/IfcOpenShell into v0.6.0
This commit is contained in:
@@ -8,17 +8,27 @@ classes = (
|
||||
operator.LoadResources,
|
||||
operator.AddCrewResource,
|
||||
operator.AddSubcontractResource,
|
||||
operator.AddEquipementResource,
|
||||
operator.AddLaborResource,
|
||||
operator.AddProductResource,
|
||||
operator.AddMaterialResource,
|
||||
operator.EditResource,
|
||||
operator.RemoveResource,
|
||||
operator.EnableEditingNestedResource,
|
||||
operator.LoadNestedResourceProperties,
|
||||
operator.DisableNestedResourceEditingUI,
|
||||
prop.Resource,
|
||||
prop.BIMResourceProperties,
|
||||
prop.BIMResourceTreeProperties,
|
||||
ui.BIM_PT_resources,
|
||||
ui.BIM_UL_resources,
|
||||
ui.BIM_UL_nested_resources,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.types.Scene.BIMResourceProperties = bpy.props.PointerProperty(type=prop.BIMResourceProperties)
|
||||
bpy.types.Scene.BIMResourceTreeProperties = bpy.props.PointerProperty(type=prop.BIMResourceTreeProperties)
|
||||
|
||||
def unregister():
|
||||
del bpy.types.Scene.BIMResourceProperties
|
||||
del bpy.types.Scene.BIMResourceTreeProperties
|
||||
|
||||
@@ -17,7 +17,7 @@ class LoadResources(bpy.types.Operator):
|
||||
new = props.resources.add()
|
||||
new.ifc_definition_id = ifc_definition_id
|
||||
new.name = resource["Name"] or "Unnamed"
|
||||
props.is_editing = True
|
||||
props.is_loaded = True
|
||||
bpy.ops.bim.disable_editing_resource()
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -27,16 +27,21 @@ class EnableEditingResource(bpy.types.Operator):
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.BIMResourceProperties
|
||||
while len(props.resource_attributes) > 0:
|
||||
props.resource_attributes.remove(0)
|
||||
self.props = context.scene.BIMResourceProperties
|
||||
self.props.active_resource_id = self.resource
|
||||
while len(self.props.resource_attributes) > 0:
|
||||
self.props.resource_attributes.remove(0)
|
||||
self.enable_editing_resource()
|
||||
self.props.is_editing = "RESOURCE"
|
||||
return {"FINISHED"}
|
||||
|
||||
def enable_editing_resource(self):
|
||||
data = Data.resources[self.resource]
|
||||
for attribute in IfcStore.get_schema().declaration_by_name("IfcConstructionResource").all_attributes():
|
||||
for attribute in IfcStore.get_schema().declaration_by_name("IfcResource").all_attributes():
|
||||
data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
|
||||
if data_type == "entity":
|
||||
continue
|
||||
new = props.resource_attributes.add()
|
||||
new = self.props.resource_attributes.add()
|
||||
new.name = attribute.name()
|
||||
new.is_null = data[attribute.name()] is None
|
||||
new.is_optional = attribute.optional()
|
||||
@@ -47,15 +52,65 @@ class EnableEditingResource(bpy.types.Operator):
|
||||
new.enum_items = json.dumps(ifcopenshell.util.attribute.get_enum_items(attribute))
|
||||
if data[attribute.name()]:
|
||||
new.enum_value = data[attribute.name()]
|
||||
props.active_resource_id = self.resource
|
||||
|
||||
|
||||
class EnableEditingNestedResource(bpy.types.Operator):
|
||||
bl_idname = "bim.enable_editing_nested_resources"
|
||||
bl_label = "Enable Editing Nested Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.props = context.scene.BIMResourceProperties
|
||||
self.tprops = context.scene.BIMResourceTreeProperties
|
||||
self.props.active_resource_id = self.resource
|
||||
while len(self.tprops.nested_resources) > 0:
|
||||
self.tprops.nested_resources.remove(0)
|
||||
|
||||
self.contracted_nested_resources = json.loads(self.props.contracted_nested_resources)
|
||||
for related_object_id in Data.resources[self.resource]["RelatedObjects"]:
|
||||
self.create_new_nested_resource_li(related_object_id, 0)
|
||||
bpy.ops.bim.load_nested_resource_properties()
|
||||
self.props.is_editing = "NESTED_RESOURCE"
|
||||
return {"FINISHED"}
|
||||
|
||||
def create_new_nested_resource_li(self, related_object_id, level_index):
|
||||
nested_resource = Data.nested_resources[related_object_id]
|
||||
new = self.tprops.nested_resources.add()
|
||||
new.ifc_definition_id = related_object_id
|
||||
new.is_expanded = related_object_id not in self.contracted_nested_resources
|
||||
new.level_index = level_index
|
||||
if nested_resource["RelatedObjects"]:
|
||||
new.has_children = True
|
||||
if new.is_expanded:
|
||||
for related_object_id in nested_resource["RelatedObjects"]:
|
||||
self.create_new_nested_resource_li(related_object_id, level_index + 1)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class LoadNestedResourceProperties(bpy.types.Operator):
|
||||
bl_idname = "bim.load_nested_resource_properties"
|
||||
bl_label = "Load nested_resource Properties"
|
||||
nested_resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
self.props = context.scene.BIMResourceProperties
|
||||
self.tprops = context.scene.BIMResourceTreeProperties
|
||||
self.props.is_nested_resource_update_enabled = False
|
||||
for item in self.tprops.nested_resources:
|
||||
if self.nested_resource and item.ifc_definition_id != self.nested_resource:
|
||||
continue
|
||||
nested_resource = Data.nested_resources[item.ifc_definition_id]
|
||||
item.name = nested_resource["Name"] or "Unnamed"
|
||||
self.props.is_nested_resource_update_enabled = True
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class DisableEditingResource(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_editing_resource"
|
||||
bl_label = "Disable Editing Workplan"
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMWorkPlanProperties.active_resource_id = 0
|
||||
context.scene.BIMResourceProperties.active_resource_id = 0
|
||||
return {"FINISHED"}
|
||||
|
||||
class DisableResourceEditingUI(bpy.types.Operator):
|
||||
@@ -63,16 +118,31 @@ class DisableResourceEditingUI(bpy.types.Operator):
|
||||
bl_label = "Disable Resources Editing UI"
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMResourceProperties.is_editing = False
|
||||
context.scene.BIMResourceProperties.is_loaded = False
|
||||
return {"FINISHED"}
|
||||
|
||||
class DisableNestedResourceEditingUI(bpy.types.Operator):
|
||||
bl_idname = "bim.disable_nested_resource_editing_ui"
|
||||
bl_label = "Disable Task Editing UI"
|
||||
|
||||
def execute(self, context):
|
||||
context.scene.BIMNestedResourceProperties.is_editing = False
|
||||
return {"FINISHED"}
|
||||
|
||||
class AddSubcontractResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_subcontract_resource"
|
||||
bl_label = "Add Subcontract Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run("resource.add_subcontract_resource", IfcStore.get_file())
|
||||
if self.resource:
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_subcontract_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
else:
|
||||
ifcopenshell.api.run("resource.add_subcontract_resource", IfcStore.get_file())
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -80,13 +150,78 @@ class AddSubcontractResource(bpy.types.Operator):
|
||||
class AddCrewResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_crew_resource"
|
||||
bl_label = "Add Crew Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run("resource.add_crew_resource", IfcStore.get_file())
|
||||
if self.resource:
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_crew_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
else:
|
||||
ifcopenshell.api.run("resource.add_crew_resource", IfcStore.get_file())
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddEquipementResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_equipement_resource"
|
||||
bl_label = "Add Equipement Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_equipement_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
class AddLaborResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_labor_resource"
|
||||
bl_label = "Add Labor Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_labor_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
class AddMaterialResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_material_resource"
|
||||
bl_label = "Add Material Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_material_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
class AddProductResource(bpy.types.Operator):
|
||||
bl_idname = "bim.add_product_resource"
|
||||
bl_label = "Add Product Resource"
|
||||
resource: bpy.props.IntProperty()
|
||||
|
||||
def execute(self, context):
|
||||
ifcopenshell.api.run(
|
||||
"resource.add_product_resource",
|
||||
IfcStore.get_file(),
|
||||
resource=IfcStore.get_file().by_id(self.resource)
|
||||
)
|
||||
Data.load(IfcStore.get_file())
|
||||
return {"FINISHED"}
|
||||
|
||||
class EditResource(bpy.types.Operator):
|
||||
bl_idname = "bim.edit_resource"
|
||||
bl_label = "Edit Resource"
|
||||
|
||||
@@ -27,10 +27,11 @@ class Resource(PropertyGroup):
|
||||
class BIMResourceProperties(PropertyGroup):
|
||||
resource_attributes: CollectionProperty(name="Resource Attributes", type=Attribute)
|
||||
is_editing: BoolProperty(name="Is Editing")
|
||||
is_a:StringProperty(name="Contracted Cost Items", default="[]")
|
||||
active_resource_id: IntProperty(name="Active Resource Id")
|
||||
active_resource_index: IntProperty(name="Active Resource Id")
|
||||
is_nested_resource_update_enabled: BoolProperty(name="Is nested_resource Update Enabled", default=True)
|
||||
resources: CollectionProperty(name="Resource", type=Resource)
|
||||
is_loaded: BoolProperty(name="Is Editing")
|
||||
active_nested_resource_id: IntProperty(name="Active Nested Ressource Id")
|
||||
active_nested_resource_index: IntProperty(name="Active Nested Resource Index")
|
||||
nested_resource_attributes: CollectionProperty(name="Nested Resource Attributes", type=Attribute)
|
||||
|
||||
@@ -15,33 +15,49 @@ class BIM_PT_resources(Panel):
|
||||
return IfcStore.get_file()
|
||||
|
||||
def draw(self, context):
|
||||
self.props = context.scene.BIMResourceProperties
|
||||
self.tprops = context.scene.BIMResourceTreeProperties
|
||||
row = self.layout.row()
|
||||
if self.props.is_loaded:
|
||||
row.operator("bim.disable_resource_editing_ui", text="CANCEL EDITING RESOURCES", icon="CANCEL")
|
||||
else:
|
||||
row = self.layout.row()
|
||||
row.operator("bim.load_resources", text="Load Resources", icon="GREASEPENCIL")
|
||||
|
||||
if not Data.is_loaded:
|
||||
Data.load(IfcStore.get_file())
|
||||
self.props = context.scene.BIMResourceProperties
|
||||
if self.props.is_loaded:
|
||||
row = self.layout.row(align=True)
|
||||
row.operator("bim.add_subcontract_resource", text="Add Subcontract", icon="FILE_TICK")
|
||||
row.operator("bim.add_crew_resource", text="Add Crew", icon="COMMUNITY")
|
||||
for resource_id, resource in Data.resources.items():
|
||||
self.draw_resource_ui(resource_id, resource)
|
||||
|
||||
row = self.layout.row(align=True)
|
||||
if self.props.is_editing:
|
||||
row.operator("bim.add_subcontract_resource",emboss=False, text="", icon="FILE_TICK")
|
||||
row.operator("bim.add_crew_resource",emboss=False, text="", icon="COMMUNITY")
|
||||
row.operator("bim.disable_resource_editing_ui", text="", icon="CANCEL")
|
||||
def draw_resource_ui(self, resource_id, resource):
|
||||
row = self.layout.row()
|
||||
row.label(text=resource["Name"] or "Unnamed", icon="BOOKMARKS")
|
||||
if self.props.active_resource_id and self.props.active_resource_id == resource_id:
|
||||
row.operator("bim.add_subcontract_resource", text="", icon="FILE_TICK").resource = resource_id
|
||||
row.operator("bim.add_crew_resource", text="", icon="COMMUNITY").resource = resource_id
|
||||
row.operator("bim.add_equipement_resource", text="", icon="TOOL_SETTINGS").resource = resource_id
|
||||
row.operator("bim.add_labor_resource", text="", icon="ARMATURE_DATA").resource = resource_id
|
||||
row.operator("bim.add_material_resource", text="", icon="MATERIAL").resource = resource_id
|
||||
row.operator("bim.add_product_resource", text="", icon="PACKAGE").resource = resource_id
|
||||
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
||||
row.operator("bim.disable_nested_resource_editing_ui", text="", icon="CANCEL")
|
||||
else:
|
||||
row.operator("bim.load_resources", text="", icon="GREASEPENCIL")
|
||||
row.operator("bim.enable_editing_nested_resources", text="", icon="ACTION").resource = resource_id
|
||||
row.operator("bim.enable_editing_resource", text="", icon="GREASEPENCIL").resource = resource_id
|
||||
row.operator("bim.remove_resource", text="", icon="X").resource = resource_id
|
||||
|
||||
if self.props.is_editing:
|
||||
self.layout.template_list(
|
||||
"BIM_UL_resources",
|
||||
"",
|
||||
self.props,
|
||||
"resources",
|
||||
self.props,
|
||||
"active_resource_index",
|
||||
)
|
||||
if self.props.active_resource_id == resource_id:
|
||||
if self.props.is_editing == "RESOURCE":
|
||||
self.draw_editable_resource_ui()
|
||||
elif self.props.is_editing == "NESTED_RESOURCE":
|
||||
self.draw_editable_nested_resource_ui(resource_id)
|
||||
|
||||
if self.props.active_resource_id:
|
||||
self.draw_editable_ui(context)
|
||||
|
||||
def draw_editable_ui(self, context):
|
||||
for attribute in self.props.resource_attributes:
|
||||
def draw_editable_resource_ui(self):
|
||||
for attribute in self.props.resources:
|
||||
row = self.layout.row(align=True)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
@@ -56,18 +72,59 @@ class BIM_PT_resources(Panel):
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
def draw_editable_nested_resource_ui(self, resource_id):
|
||||
self.layout.template_list(
|
||||
"BIM_UL_nested_resources",
|
||||
"",
|
||||
self.tprops,
|
||||
"nested_resources",
|
||||
self.props,
|
||||
"active_nested_resource_index",
|
||||
)
|
||||
if self.props.active_nested_resource_id:
|
||||
self.draw_editable_nested_resource_attributes_ui()
|
||||
|
||||
class BIM_UL_resources(UIList):
|
||||
|
||||
def draw_editable_nested_resource_attributes_ui(self):
|
||||
for attribute in self.props.nested_resource_attributes:
|
||||
row = self.layout.row(align=True)
|
||||
if attribute.data_type == "string":
|
||||
row.prop(attribute, "string_value", text=attribute.name)
|
||||
elif attribute.data_type == "boolean":
|
||||
row.prop(attribute, "bool_value", text=attribute.name)
|
||||
elif attribute.data_type == "integer":
|
||||
row.prop(attribute, "int_value", text=attribute.name)
|
||||
elif attribute.data_type == "enum":
|
||||
row.prop(attribute, "enum_value", text=attribute.name)
|
||||
if attribute.is_optional:
|
||||
row.prop(attribute, "is_null", icon="RADIOBUT_OFF" if attribute.is_null else "RADIOBUT_ON", text="")
|
||||
|
||||
|
||||
class BIM_UL_nested_resources(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
if item:
|
||||
props = context.scene.BIMResourceProperties
|
||||
row = layout.row(align=True)
|
||||
row.label(text=item.name)
|
||||
if context.scene.BIMResourceProperties.active_resource_id == item.ifc_definition_id:
|
||||
row.operator("bim.edit_resource", text="", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_resource", text="", icon="X")
|
||||
elif context.scene.BIMResourceProperties.active_resource_id:
|
||||
row.operator("bim.remove_resource", text="", icon="X").resource = item.ifc_definition_id
|
||||
for i in range(0, item.level_index):
|
||||
row.label(text="", icon="BLANK1")
|
||||
if item.has_children:
|
||||
if item.is_expanded:
|
||||
row.operator(
|
||||
"bim.contract_nested_resource", text="", emboss=False, icon="DISCLOSURE_TRI_DOWN"
|
||||
).nested_resource = item.ifc_definition_id
|
||||
else:
|
||||
row.operator(
|
||||
"bim.expand_nested_resource", text="", emboss=False, icon="DISCLOSURE_TRI_RIGHT"
|
||||
).nested_resource = item.ifc_definition_id
|
||||
|
||||
if props.active_nested_resource_id == item.ifc_definition_id:
|
||||
row.operator("bim.edit_nested_resource", text="", icon="CHECKMARK")
|
||||
row.operator("bim.disable_editing_nested_resource", text="", icon="CANCEL")
|
||||
elif props.active_nested_resource_id:
|
||||
row.operator("bim.add_nested_resource", text="", icon="ADD").nested_resource = item.ifc_definition_id
|
||||
row.operator("bim.remove_nested_resource", text="", icon="X").nested_resource = item.ifc_definition_id
|
||||
else:
|
||||
op = row.operator("bim.enable_editing_resource", text="", icon="GREASEPENCIL")
|
||||
op.resource = item.ifc_definition_id
|
||||
row.operator("bim.remove_resource", text="", icon="X").resource = item.ifc_definition_id
|
||||
row.operator("bim.enable_editing_nested_resource_time", text="", icon="TIME").nested_resource = item.ifc_definition_id
|
||||
row.operator("bim.enable_editing_nested_resource", text="", icon="GREASEPENCIL").nested_resource = item.ifc_definition_id
|
||||
row.operator("bim.add_nested_resource", text="", icon="ADD").nested_resource = item.ifc_definition_id
|
||||
row.operator("bim.remove_nested_resource", text="", icon="X").nested_resource = item.ifc_definition_id
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# IFCCityJSON
|
||||
Converter for CityJSON files and IFC. Currently only supports one-way conversion from CityJSON to IFC.
|
||||
|
||||
-- WARNING --
|
||||
|
||||
IFCCityJSON only came into being 14/04/2021. Be prepared for lots of bugs, unfinished implementations and little to no documentation!
|
||||
|
||||
## Dependencies
|
||||
- [IfcOpenShell](https://github.com/IfcOpenShell/IfcOpenShell)
|
||||
- [CJIO](https://github.com/cityjson/cjio)
|
||||
|
||||
## Usage of IFCCityJSON
|
||||
Following command will execute a conversion from CityJSON to IFC
|
||||
|
||||
python ifccityjson.py [-i input file] [-o output file] [-n name of identification attribute]
|
||||
|
||||
The example file that could be used is example/3D_BAG_example.json
|
||||
|
||||
python ifccityjson.py -i example/3DBAG_example.json -o example/3DBAG_example.ifc -n identificatie
|
||||
|
||||
## Implemented geometries
|
||||
- [ ] "MultiPoint"
|
||||
- [ ] "MultiLineString"
|
||||
- [x] "MultiSurface"
|
||||
- [ ] "CompositeSurface"
|
||||
- [x] "Solid": exterior shell
|
||||
- [ ] "Solid": interior shell
|
||||
- [x] "MultiSolid"
|
||||
- [x] "CompositeSolid"
|
||||
- [ ] "GeometryInstance"
|
||||
|
||||
## TODO
|
||||
- [x] CityJSON Attributes as IFC properties in 'CityJSON_attributes' pset
|
||||
- [x] Implement georeferencing
|
||||
- [ ] Do not use template IFC for new IFC file, but make IFC file from scratch
|
||||
@@ -0,0 +1,190 @@
|
||||
import ifcopenshell
|
||||
import warnings
|
||||
from geometry import GeometryIO
|
||||
|
||||
JSON_TO_IFC = {
|
||||
"Building": ["IfcBuilding"],
|
||||
"BuildingPart": ["IfcBuilding", {"CompositionType": "Partial"}], # CompositionType: Partial
|
||||
"BuildingInstallation": ["IfcDistributionElement"],
|
||||
"Road": ["IfcCivilElement"],
|
||||
"TransportSquare": ["IfcSpace"],
|
||||
"TINRelief": ["IfcGeographicElement"],
|
||||
"WaterBody": ["IfcGeographicElement"],
|
||||
"LandUse": ["IfcGeographicElement"],
|
||||
"PlantCover": ["IfcGeographicElement"],
|
||||
"SolitaryVegetationObject": ["IfcGeographicElement"],
|
||||
"CityFurniture": ["IfcFurnishingElement"],
|
||||
"GenericCityObject": ["IfcCivilElement"],
|
||||
"Bridge": ["IfcCivilElement"],
|
||||
"BridgePart": ["IfcCivilElement"],
|
||||
"BridgeInstallation": ["IfcCivilElement"],
|
||||
"BridgeConstructionElement": ["IfcCivilElement"],
|
||||
"Tunnel": ["IfcCivilElement"],
|
||||
"TunnelPart": ["IfcCivilElement"],
|
||||
"TunnelInstallation": ["IfcCivilElement"],
|
||||
"CityObjectGroup": ["IfcCivilElement"],
|
||||
"GroundSurface": ["IfcSlab"],
|
||||
"RoofSurface": ["IfcRoof"],
|
||||
"WallSurface": ["IfcWall"]
|
||||
}
|
||||
|
||||
class Cityjson2ifc:
|
||||
def __init__(self):
|
||||
self.city_model = None
|
||||
self.IFC_model = None
|
||||
self.properties = {}
|
||||
self.geometry = GeometryIO()
|
||||
self.configuration()
|
||||
|
||||
|
||||
def configuration(self, file_destination="output.ifc", name_attribute=None):
|
||||
self.properties["file_destination"] = file_destination
|
||||
self.properties["name_attribute"] = name_attribute
|
||||
|
||||
|
||||
def convert(self, city_model):
|
||||
self.city_model = city_model
|
||||
self.create_new_file()
|
||||
self.create_metadata()
|
||||
self.geometry.build_vertices(self.IFC_model,
|
||||
coords=city_model.j["vertices"],
|
||||
scale=self.properties["local_scale"])
|
||||
# self.build_vertices()
|
||||
self.create_IFC_classes()
|
||||
self.write_file()
|
||||
|
||||
def create_metadata(self):
|
||||
# Georeferencing
|
||||
self.properties["local_translation"] = None
|
||||
self.properties["local_scale"] = None
|
||||
if self.city_model.is_transform():
|
||||
self.properties["local_scale"] = self.city_model.j['transform']['scale']
|
||||
local_translation = self.city_model.j['transform']['translate']
|
||||
self.properties["local_translation"] = {
|
||||
"Eastings": local_translation[0],
|
||||
"Northings": local_translation[1],
|
||||
"OrthogonalHeight": local_translation[2]
|
||||
}
|
||||
|
||||
epsg = self.city_model.get_epsg()
|
||||
if epsg:
|
||||
# Meter is assumed as unit for now
|
||||
unit = self.IFC_model.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")
|
||||
crs = self.IFC_model.create_entity("IfcProjectedCrs", Name=f"epsg:{epsg}")
|
||||
self.IFC_model.create_entity("IfcMapConversion", self.IFC_representation_context, **self.properties["local_translation"])
|
||||
|
||||
self.properties["owner_history"] = self.IFC_model.by_type("IfcOwnerHistory")[0]
|
||||
|
||||
def create_new_file(self):
|
||||
self.IFC_model = ifcopenshell.open('example/template.ifc')
|
||||
self.IFC_site = self.IFC_model.by_type('IfcSite')[0]
|
||||
self.IFC_representation_sub_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONSUBCONTEXT")[0]
|
||||
self.IFC_representation_context = self.IFC_model.by_type("IFCGEOMETRICREPRESENTATIONCONTEXT")[0]
|
||||
# self.IFC_model = ifcopenshell.file(schema='IFC4')
|
||||
|
||||
def write_file(self):
|
||||
self.IFC_model.write(self.properties["file_destination"])
|
||||
|
||||
def create_IFC_classes(self):
|
||||
for obj_id, obj in self.city_model.get_cityobjects().items():
|
||||
|
||||
# CityJSON type to class
|
||||
mapping = JSON_TO_IFC[obj.type]
|
||||
IFC_class = mapping[0]
|
||||
data = {}
|
||||
# Add attributes if it is specified in mapping
|
||||
# Example: BuildingPart to IfcBuilding with CompositionType: Partial
|
||||
if len(mapping) > 1:
|
||||
data.update(mapping[1])
|
||||
|
||||
# attributes
|
||||
IFC_name = None
|
||||
if "name_attribute" in self.properties and self.properties["name_attribute"] in obj.attributes:
|
||||
IFC_name = obj.attributes[self.properties["name_attribute"]]
|
||||
|
||||
# TODO children
|
||||
|
||||
# TODO parents
|
||||
|
||||
# TODO geometry_type
|
||||
|
||||
# geometry_lod
|
||||
lod = 0
|
||||
geometry = None
|
||||
for geom in obj.geometry:
|
||||
if geom.lod > lod:
|
||||
geometry = geom
|
||||
lod = geom.lod
|
||||
|
||||
IFC_children = []
|
||||
if geometry.surfaces:
|
||||
for surface_id in geometry.surfaces:
|
||||
IFC_child_class = JSON_TO_IFC[geometry.surfaces[surface_id]["type"]][0]
|
||||
child_data = {"GlobalId": ifcopenshell.guid.new(),
|
||||
"Name": IFC_child_class
|
||||
}
|
||||
# CREATE ENTITY
|
||||
surface_geometry = self.geometry.create_IFC_surface(self.IFC_model, geometry, surface_id)
|
||||
if surface_geometry:
|
||||
child_data["Representation"] = self.create_IFC_representation(surface_geometry)
|
||||
IFC_children.append(self.IFC_model.create_entity(IFC_child_class, **child_data))
|
||||
|
||||
else:
|
||||
IFC_geometry = self.geometry.create_IFC_geometry(self.IFC_model, geometry)
|
||||
if IFC_geometry:
|
||||
data["Representation"] = self.create_IFC_representation(IFC_geometry)
|
||||
data["GlobalId"] = ifcopenshell.guid.new()
|
||||
data["Name"] = IFC_name
|
||||
|
||||
IFC_object = self.IFC_model.create_entity(IFC_class, **data)
|
||||
# Define aggregation
|
||||
self.IFC_model.create_entity("IfcRelAggregates",
|
||||
**{"GlobalId": ifcopenshell.guid.new(),
|
||||
"RelatedObjects": [IFC_object],
|
||||
"RelatingObject": self.IFC_site}
|
||||
)
|
||||
if IFC_children:
|
||||
self.IFC_model.create_entity("IfcRelAggregates",
|
||||
**{"GlobalId": ifcopenshell.guid.new(),
|
||||
"RelatedObjects": IFC_children,
|
||||
"RelatingObject": IFC_object})
|
||||
|
||||
self.create_property_set(obj.attributes, IFC_object)
|
||||
|
||||
def create_IFC_representation(self, IFC_geometry):
|
||||
shape_representation = self.IFC_model.create_entity("IfcShapeRepresentation",
|
||||
self.IFC_representation_sub_context, 'Body', 'Brep',
|
||||
[IFC_geometry])
|
||||
product_representation = self.IFC_model.create_entity("IfcProductDefinitionShape",
|
||||
Representations=[shape_representation])
|
||||
return product_representation
|
||||
|
||||
def create_property_set(self, CJ_attributes, IFC_entity):
|
||||
IFC_object_properties = []
|
||||
for property, val in CJ_attributes.items():
|
||||
if val == None:
|
||||
continue
|
||||
|
||||
if type(val) == int:
|
||||
IFC_type = "IfcInteger"
|
||||
elif type(val) == float:
|
||||
IFC_type = "IfcReal"
|
||||
elif type(val) == bool:
|
||||
IFC_type = "IfcBoolean"
|
||||
else:
|
||||
IFC_type = "IfcText"
|
||||
|
||||
IFC_object_properties.append(
|
||||
self.IFC_model.createIfcPropertySingleValue(property, property,
|
||||
self.IFC_model.create_entity(IFC_type, val), None)
|
||||
)
|
||||
property_set = self.IFC_model.createIfcPropertySet(ifcopenshell.guid.new(),
|
||||
self.properties["owner_history"],
|
||||
"CityJSON_attributes",
|
||||
None,
|
||||
IFC_object_properties)
|
||||
|
||||
self.IFC_model.createIfcRelDefinesByProperties(ifcopenshell.guid.new(),
|
||||
self.properties["owner_history"],
|
||||
None, None, [IFC_entity],
|
||||
property_set)
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,39 @@
|
||||
ISO-10303-21;
|
||||
HEADER;
|
||||
FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1');
|
||||
FILE_NAME('template.ifc','2021-03-17T14:54:00+11:00',(),(),'IfcOpenShell 0.6.0b0','BlenderBIM 0.0.999999','Nobody');
|
||||
FILE_SCHEMA(('IFC4'));
|
||||
ENDSEC;
|
||||
DATA;
|
||||
#1=IFCPERSON('HSeldon','Seldon','Hari',$,$,$,$,$);
|
||||
#2=IFCORGANIZATION('APTR','Aperture Science',$,$,$);
|
||||
#3=IFCPERSONANDORGANIZATION(#1,#2,$);
|
||||
#4=IFCACTORROLE(.USERDEFINED.,'CONTRIBUTOR',$);
|
||||
#5=IFCTELECOMADDRESS(.USERDEFINED.,'The main webpage of the software collection.','WEBPAGE',$,$,$,$,'https://ifcopenshell.org',$);
|
||||
#6=IFCTELECOMADDRESS(.USERDEFINED.,'The CJ2IFC webpage of the software collection.','WEBPAGE',$,$,$,$,'https://github.com/LaurensJN/IFC2JS',$);
|
||||
#7=IFCTELECOMADDRESS(.USERDEFINED.,'The source code repository of the software collection.','REPOSITORY',$,$,$,$,'https://github.com/IfcOpenShell/IfcOpenShell.git',$);
|
||||
#8=IFCORGANIZATION($,'IfcOpenShell','IfcOpenShell is an open source (LGPL) software library that helps users and software developers to work with the IFC file format.',(#4),(#5,#6,#7));
|
||||
#9=IFCAPPLICATION(#8,'0.0.999999','CityJSON to IFC converter','CJ2IFC');
|
||||
#10=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
||||
#11=IFCPROJECT('2yjpApQSX3ZAZudc2AGHb3',#10,'My Project',$,$,$,$,(#20,#27),#15);
|
||||
#12=IFCSIUNIT(*,.LENGTHUNIT.,$,.METRE.);
|
||||
#13=IFCSIUNIT(*,.AREAUNIT.,$,.SQUARE_METRE.);
|
||||
#14=IFCSIUNIT(*,.VOLUMEUNIT.,$,.CUBIC_METRE.);
|
||||
#15=IFCUNITASSIGNMENT((#12,#13,#14));
|
||||
#16=IFCCARTESIANPOINT((0.,0.,0.));
|
||||
#17=IFCDIRECTION((0.,0.,1.));
|
||||
#18=IFCDIRECTION((1.,0.,0.));
|
||||
#19=IFCAXIS2PLACEMENT3D(#16,#17,#18);
|
||||
#20=IFCGEOMETRICREPRESENTATIONCONTEXT($,'Model',3,1.E-05,#19,$);
|
||||
#21=IFCGEOMETRICREPRESENTATIONSUBCONTEXT('Body','Model',*,*,*,*,#20,$,.MODEL_VIEW.,$);
|
||||
#22=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
||||
#23=IFCSITE('1maxFQa9z7q8w50tN19Dw9',#22,'My Site',$,$,#30,$,$,$,$,$,$,$,$);
|
||||
#24=IFCOWNERHISTORY(#3,#9,.READWRITE.,.ADDED.,1615934569,#3,#9,1615934569);
|
||||
#25=IFCRELAGGREGATES('1GuJ2jz2TA49gFFSYhrqGa',#24,$,$,#11,(#23));
|
||||
#26=IFCCARTESIANPOINT((0.,0.,0.));
|
||||
#27=IFCDIRECTION((0.,0.,1.));
|
||||
#28=IFCDIRECTION((1.,0.,0.));
|
||||
#29=IFCAXIS2PLACEMENT3D(#26,#27,#28);
|
||||
#30=IFCLOCALPLACEMENT($,#29);
|
||||
ENDSEC;
|
||||
END-ISO-10303-21;
|
||||
@@ -0,0 +1,81 @@
|
||||
import warnings
|
||||
|
||||
class GeometryIO:
|
||||
def __init__(self):
|
||||
self.vertices = {}
|
||||
|
||||
def build_vertices(self, IFC_model, coords, scale=None):
|
||||
for coord in coords:
|
||||
if scale:
|
||||
IFC_vertex = tuple([float(xyz) * coord_scale
|
||||
for xyz, coord_scale
|
||||
in zip(coord, scale)])
|
||||
else:
|
||||
IFC_vertex = [float(xyz) for xyz in coord]
|
||||
|
||||
IFC_cartesian_point = IFC_model.create_entity("IfcCartesianPoint", IFC_vertex)
|
||||
self.vertices[tuple(coord)] = IFC_cartesian_point
|
||||
|
||||
def create_IFC_geometry(self, IFC_model, geometry):
|
||||
if geometry.type == "Solid":
|
||||
return self.create_IFC_closed_shell(IFC_model, geometry)
|
||||
elif geometry.type in ["CompositeSolid", "MultiSolid"]:
|
||||
return self.create_IFC_composite_closed_shell(IFC_model, geometry)
|
||||
else:
|
||||
warnings.warn("Types other than solids are not yet supported")
|
||||
return
|
||||
|
||||
def create_IFC_composite_closed_shell(self, IFC_model, geometry):
|
||||
shells = []
|
||||
for shell in geometry.boundaries:
|
||||
outershell = shell[0]
|
||||
faces = []
|
||||
for face in outershell: # exterior shell
|
||||
for triangle in face:
|
||||
faces.append(self.create_IFC_face(IFC_model, triangle))
|
||||
|
||||
shells.append(IFC_model.create_entity("IfcClosedShell", faces))
|
||||
IFC_geometry = IFC_model.create_entity("IfcShellBasedSurfaceModel", shells)
|
||||
return IFC_geometry
|
||||
|
||||
def create_IFC_closed_shell(self, IFC_model, geometry):
|
||||
outershell = geometry.boundaries[0]
|
||||
# print(geometry.surfaces[0]['surface_idx'][0])
|
||||
faces = []
|
||||
for face in outershell: # exterior shell
|
||||
for triangle in face:
|
||||
faces.append(self.create_IFC_face(IFC_model, triangle))
|
||||
|
||||
if len(geometry.boundaries) == 1:
|
||||
shell = IFC_model.create_entity("IfcClosedShell", faces)
|
||||
IFC_geometry = IFC_model.create_entity("IfcShellBasedSurfaceModel", [shell])
|
||||
return IFC_geometry
|
||||
|
||||
# TODO: INTERIOR SHELL
|
||||
warnings.warn("Solid interior shell not yet supported")
|
||||
return
|
||||
# for boundary in geometry.boundaries[1]: # interior shell
|
||||
# for face in boundary:
|
||||
# for triangle in face:
|
||||
# print(triangle)
|
||||
# print(geometry.boundaries)
|
||||
|
||||
def create_IFC_surface(self, IFC_model, geometry, surface_id):
|
||||
face_ids = geometry.surfaces[surface_id]["surface_idx"]
|
||||
faces = []
|
||||
|
||||
for shell, face_id in face_ids:
|
||||
for triangle in geometry.boundaries[shell][face_id]:
|
||||
faces.append(self.create_IFC_face(IFC_model, triangle))
|
||||
|
||||
shell = IFC_model.create_entity("IfcOpenShell", faces)
|
||||
IFC_geometry = IFC_model.create_entity("IfcShellBasedSurfaceModel", [shell])
|
||||
return IFC_geometry
|
||||
|
||||
def create_IFC_face(self, IFC_model, face):
|
||||
vertices = []
|
||||
for vertex in face:
|
||||
vertices.append(self.vertices[tuple(vertex)])
|
||||
polyloop = IFC_model.create_entity("IfcPolyLoop", vertices)
|
||||
outerbound = IFC_model.create_entity("IfcFaceOuterBound", polyloop, True)
|
||||
return IFC_model.create_entity("IfcFace", [outerbound])
|
||||
@@ -0,0 +1,24 @@
|
||||
import argparse
|
||||
from cjio import cityjson
|
||||
from cityjson2ifc import Cityjson2ifc
|
||||
|
||||
# Press the green button in the gutter to run the script.
|
||||
if __name__ == '__main__':
|
||||
# Example:
|
||||
# python ifccityjson.py -i example/3DBAG_example.json -o example/output.ifc -n identificatie
|
||||
parser = argparse.ArgumentParser(description="")
|
||||
parser.add_argument("-i", "--input", type=str, help="input CityJSON file", required=True)
|
||||
parser.add_argument("-o", "--output", type=str, help="output IFC file. Standard is output.ifc")
|
||||
parser.add_argument("-n", "--name", type=str, help="Attribute containing the name")
|
||||
args = parser.parse_args()
|
||||
|
||||
city_model = cityjson.load(args.input)
|
||||
data = {}
|
||||
if args.name:
|
||||
data["name_attribute"] = args.name
|
||||
if args.output:
|
||||
data["file_destination"] = args.output
|
||||
|
||||
converter = Cityjson2ifc()
|
||||
converter.configuration(**data)
|
||||
converter.convert(city_model)
|
||||
Reference in New Issue
Block a user