mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Merge pull request #819 from Jesusbill/v0.6.0
udpate ifc2ca.py - major revision
This commit is contained in:
+197
-94
@@ -6,99 +6,102 @@ class IFC2CA:
|
|||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.file = None
|
self.file = None
|
||||||
self.result = {}
|
self.result = {}
|
||||||
self.supports = []
|
|
||||||
|
|
||||||
def convert(self):
|
def convert(self):
|
||||||
self.file = ifcopenshell.open(self.filename)
|
self.file = ifcopenshell.open(self.filename)
|
||||||
for model in self.file.by_type('IfcStructuralAnalysisModel'):
|
for model in self.file.by_type('IfcStructuralAnalysisModel'):
|
||||||
self.result = {
|
self.result = {
|
||||||
'title': model.Name,
|
'ifcName': model.is_a() + '|' + str(model.id()),
|
||||||
'units': self.get_units(),
|
'name': model.Name,
|
||||||
'elements': self.get_elements(model),
|
'id': model.GlobalId,
|
||||||
'mesh': { 'meshSize': 0.2 }, # TODO: unhardcode
|
'elements': self.get_structural_items(model, item_type='IfcStructuralMember'),
|
||||||
'supports': self.get_supports()
|
'connections': self.get_structural_items(model, item_type='IfcStructuralConnection')
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_units(self):
|
print('Number of elements: ', len(self.result['elements']))
|
||||||
# TODO: unhardcode
|
print('Number of connections: ', len(self.result['connections']))
|
||||||
units = {}
|
|
||||||
for unit in self.file.by_type('IfcUnitAssignment')[0].Units:
|
|
||||||
if unit.UnitType == 'LENGTHUNIT':
|
|
||||||
units['length'] = 'm'
|
|
||||||
units['force'] = 'N'
|
|
||||||
units['angle'] = 'deg'
|
|
||||||
return units
|
|
||||||
|
|
||||||
def get_elements(self, model):
|
break
|
||||||
elements = []
|
|
||||||
|
def get_structural_items(self, model, item_type='IfcStructuralItem'):
|
||||||
|
items = []
|
||||||
for group in model.IsGroupedBy:
|
for group in model.IsGroupedBy:
|
||||||
for element in group.RelatedObjects:
|
for item in group.RelatedObjects:
|
||||||
if not element.is_a('IfcStructuralMember'):
|
if not item.is_a(item_type):
|
||||||
continue
|
continue
|
||||||
data = self.get_element_data(element)
|
data = self.get_item_data(item)
|
||||||
if data:
|
if data:
|
||||||
elements.append(data)
|
items.append(data)
|
||||||
return elements
|
return items
|
||||||
|
|
||||||
def get_element_data(self, element):
|
def get_item_data(self, item):
|
||||||
representation = self.get_representation(element)
|
if item.is_a('IfcStructuralCurveMember'):
|
||||||
material_profile = self.get_material_profile(element)
|
representation = self.get_representation(item, 'Edge')
|
||||||
if not representation or not material_profile:
|
material_profile = self.get_material_profile(item)
|
||||||
return
|
if not representation or not material_profile:
|
||||||
for connection in element.ConnectedBy:
|
print(representation, material_profile)
|
||||||
if connection.RelatedStructuralConnection.AppliedCondition:
|
return
|
||||||
self.supports.append(connection.RelatedStructuralConnection)
|
|
||||||
return {
|
|
||||||
'ifcName': element.is_a() + '|' + str(element.id()),
|
|
||||||
'name': element.Name,
|
|
||||||
'id': element.GlobalId,
|
|
||||||
'geometryType': self.get_geometry_type(representation),
|
|
||||||
'geometry': self.get_geometry(representation),
|
|
||||||
'rotation': 0, # TODO: unhardcode
|
|
||||||
'material': self.get_material_properties(material_profile),
|
|
||||||
'section': self.get_material_section(material_profile),
|
|
||||||
'elementType': 'EulerBeam' # TODO: unhardcode
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_supports(self):
|
return {
|
||||||
supports = []
|
'ifcName': item.is_a() + '|' + str(item.id()),
|
||||||
for support in self.supports:
|
'name': item.Name,
|
||||||
supports.append({
|
'id': item.GlobalId,
|
||||||
'ifcName': support.is_a() + '|' + str(support.id()),
|
'geometryType': 'line',
|
||||||
'name': support.Name,
|
'predefinedType': item.PredefinedType,
|
||||||
'id': support.GlobalId,
|
'geometry': self.get_geometry(representation),
|
||||||
'geometryType': self.get_support_geometry_type(support),
|
'material': self.get_material_properties(material_profile.Material),
|
||||||
'geometry': self.get_support_geometry(support),
|
'profile': self.get_profile_properties(material_profile.Profile),
|
||||||
'appliedCondition': self.get_support_input(support)
|
'connections': self.get_connection_data(item.ConnectedBy)
|
||||||
})
|
}
|
||||||
return supports
|
|
||||||
|
|
||||||
def get_support_geometry_type(self, support):
|
elif item.is_a('IfcStructuralSurfaceMember'):
|
||||||
if support.is_a('IfcStructuralPointConnection'):
|
representation = self.get_representation(item, 'Face')
|
||||||
return 'point'
|
material = self.get_material_profile(item)
|
||||||
|
if not representation:
|
||||||
|
print(representation)
|
||||||
|
return
|
||||||
|
|
||||||
def get_support_geometry(self, support):
|
return {
|
||||||
# TODO: make more robust
|
'ifcName': item.is_a() + '|' + str(item.id()),
|
||||||
return support.ObjectPlacement.RelativePlacement.Location.Coordinates
|
'name': item.Name,
|
||||||
|
'id': item.GlobalId,
|
||||||
|
'geometryType': 'surface',
|
||||||
|
'predefinedType': item.PredefinedType,
|
||||||
|
'thickness': item.Thickness,
|
||||||
|
'geometry': self.get_geometry(representation),
|
||||||
|
'material': self.get_material_properties(material),
|
||||||
|
'connections': self.get_connection_data(item.ConnectedBy)
|
||||||
|
}
|
||||||
|
|
||||||
def get_support_input(self, support):
|
elif item.is_a('IfcStructuralPointConnection'):
|
||||||
return {
|
representation = self.get_representation(item, 'Vertex')
|
||||||
'dx': support.AppliedCondition.TranslationalStiffnessX.wrappedValue,
|
if not representation:
|
||||||
'dy': support.AppliedCondition.TranslationalStiffnessY.wrappedValue,
|
print(representation)
|
||||||
'dz': support.AppliedCondition.TranslationalStiffnessZ.wrappedValue,
|
return
|
||||||
'drx': support.AppliedCondition.RotationalStiffnessX.wrappedValue,
|
|
||||||
'dry': support.AppliedCondition.RotationalStiffnessY.wrappedValue,
|
|
||||||
'drz': support.AppliedCondition.RotationalStiffnessZ.wrappedValue
|
|
||||||
}
|
|
||||||
print(support.AppliedCondition)
|
|
||||||
|
|
||||||
def get_representation(self, element):
|
return {
|
||||||
|
'ifcName': item.is_a() + '|' + str(item.id()),
|
||||||
|
'name': item.Name,
|
||||||
|
'id': item.GlobalId,
|
||||||
|
'geometryType': 'point',
|
||||||
|
'geometry': self.get_geometry(representation),
|
||||||
|
'appliedCondition': self.get_connection_input(item),
|
||||||
|
'relatedElements': self.get_connection_data(item.ConnectsStructuralMembers)
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_representation(self, element, rep_type):
|
||||||
if not element.Representation:
|
if not element.Representation:
|
||||||
return None
|
return None
|
||||||
for representation in element.Representation.Representations:
|
for representation in element.Representation.Representations:
|
||||||
rep = self.get_specific_representation(representation, 'Reference', 'Edge')
|
rep = self.get_specific_representation(representation, 'Reference', rep_type)
|
||||||
if rep:
|
if rep:
|
||||||
return rep
|
return rep
|
||||||
|
else:
|
||||||
|
# print('Trying without rep identifier')
|
||||||
|
for representation in element.Representation.Representations:
|
||||||
|
rep = self.get_specific_representation(representation, None, rep_type)
|
||||||
|
if rep:
|
||||||
|
return rep
|
||||||
|
|
||||||
def get_specific_representation(self, representation, rep_id, rep_type):
|
def get_specific_representation(self, representation, rep_id, rep_type):
|
||||||
if representation.RepresentationIdentifier == rep_id \
|
if representation.RepresentationIdentifier == rep_id \
|
||||||
@@ -109,11 +112,6 @@ class IFC2CA:
|
|||||||
representation.Items[0].MappingSource.MappedRepresentation,
|
representation.Items[0].MappingSource.MappedRepresentation,
|
||||||
rep_id, rep_type)
|
rep_id, rep_type)
|
||||||
|
|
||||||
def get_geometry_type(self, representation):
|
|
||||||
if representation.Items[0].is_a('IfcEdgeCurve'):
|
|
||||||
return 'curvedLine' # TODO: Is this correct?
|
|
||||||
return 'straightLine'
|
|
||||||
|
|
||||||
def get_geometry(self, representation):
|
def get_geometry(self, representation):
|
||||||
# Maybe IfcOpenShell can use create_shape here to simplify this, but
|
# Maybe IfcOpenShell can use create_shape here to simplify this, but
|
||||||
# supposedly structural models are very simple anyway, so perhaps we
|
# supposedly structural models are very simple anyway, so perhaps we
|
||||||
@@ -125,6 +123,16 @@ class IFC2CA:
|
|||||||
self.get_coordinate(item.EdgeEnd.VertexGeometry)
|
self.get_coordinate(item.EdgeEnd.VertexGeometry)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
elif item.is_a('IfcFaceSurface'):
|
||||||
|
edges = item.Bounds[0].Bound.EdgeList
|
||||||
|
coords = []
|
||||||
|
for edge in edges:
|
||||||
|
coords.append(self.get_coordinate(edge.EdgeElement.EdgeStart.VertexGeometry))
|
||||||
|
return coords
|
||||||
|
|
||||||
|
elif item.is_a('IfcVertexPoint'):
|
||||||
|
return self.get_coordinate(item.VertexGeometry)
|
||||||
|
|
||||||
def get_coordinate(self, point):
|
def get_coordinate(self, point):
|
||||||
if point.is_a('IfcCartesianPoint'):
|
if point.is_a('IfcCartesianPoint'):
|
||||||
return point.Coordinates
|
return point.Coordinates
|
||||||
@@ -139,34 +147,129 @@ class IFC2CA:
|
|||||||
if material.is_a('IfcMaterialProfileSet'):
|
if material.is_a('IfcMaterialProfileSet'):
|
||||||
# For now, we only deal with a single profile
|
# For now, we only deal with a single profile
|
||||||
return material.MaterialProfiles[0]
|
return material.MaterialProfiles[0]
|
||||||
|
if material.is_a('IfcMaterialProfileSetUsage'):
|
||||||
|
return material.ForProfileSet.MaterialProfiles[0]
|
||||||
|
if material.is_a('IfcMaterial'):
|
||||||
|
return material
|
||||||
|
|
||||||
|
def get_material_properties(self, material):
|
||||||
|
psets = material.HasProperties
|
||||||
|
|
||||||
|
if self.get_pset_properties(psets, 'Pset_MaterialMechanical'):
|
||||||
|
mechProps = self.get_pset_properties(psets, 'Pset_MaterialMechanical')
|
||||||
|
else:
|
||||||
|
mechProps = self.get_pset_properties(psets, None)
|
||||||
|
|
||||||
|
if self.get_pset_properties(psets, 'Pset_MaterialCommon'):
|
||||||
|
commonProps = self.get_pset_properties(psets, 'Pset_MaterialCommon')
|
||||||
|
else:
|
||||||
|
commonProps = self.get_pset_properties(psets, None)
|
||||||
|
|
||||||
def get_material_properties(self, profile):
|
|
||||||
psets = profile.Material.HasProperties
|
|
||||||
return {
|
return {
|
||||||
'ifcName': profile.Material.is_a() + '|' + str(profile.Material.id()),
|
'ifcName': material.is_a() + '|' + str(material.id()),
|
||||||
'materialType': 'isotropic', # TODO: unhardcode
|
'name': material.Name,
|
||||||
'youngModulus': self.get_pset_property(psets, 'Pset_MaterialMechanical', 'YoungModulus'),
|
'mechProps': mechProps,
|
||||||
'poissonRatio': self.get_pset_property(psets, 'Pset_MaterialMechanical', 'PoissonRatio'),
|
'commonProps':commonProps
|
||||||
'massDensity': self.get_pset_property(psets, 'Pset_MaterialCommon', 'MassDensity')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_pset_property(self, psets, pset_name, prop_name):
|
def get_pset_property(self, psets, pset_name, prop_name):
|
||||||
for pset in psets:
|
for pset in psets:
|
||||||
if pset.Name == pset_name:
|
if pset.Name == pset_name or pset_name is None:
|
||||||
for prop in pset.Properties:
|
for prop in pset.Properties:
|
||||||
if prop.Name == prop_name:
|
if prop.Name == prop_name:
|
||||||
return prop.NominalValue.wrappedValue
|
return prop.NominalValue.wrappedValue
|
||||||
|
|
||||||
def get_material_section(self, profile):
|
def get_pset_properties(self, psets, pset_name):
|
||||||
if profile.Profile.is_a('IfcRectangleProfileDef'):
|
for pset in psets:
|
||||||
|
if pset.Name == pset_name or pset_name is None:
|
||||||
|
d = {}
|
||||||
|
for prop in pset.Properties:
|
||||||
|
propName = prop.Name[0].lower() + prop.Name[1:]
|
||||||
|
d[propName] = prop.NominalValue.wrappedValue
|
||||||
|
return d
|
||||||
|
|
||||||
|
def get_profile_properties(self, profile):
|
||||||
|
if profile.is_a('IfcRectangleProfileDef'):
|
||||||
return {
|
return {
|
||||||
'ifcName': profile.Profile.is_a() + '|' + str(profile.Profile.id()),
|
'ifcName': profile.is_a() + '|' + str(profile.id()),
|
||||||
'sectionType': 'rectangular',
|
'profileName': profile.ProfileName,
|
||||||
'sectionVariation': 'constant',
|
'profileType': profile.ProfileType,
|
||||||
'xDim': profile.Profile.XDim,
|
'profileShape': 'rectangular',
|
||||||
'yDim': profile.Profile.YDim
|
'xDim': profile.XDim,
|
||||||
|
'yDim': profile.YDim
|
||||||
}
|
}
|
||||||
|
|
||||||
ifc2ca = IFC2CA('ifc2ca.blend.ifc')
|
if profile.is_a('IfcIShapeProfileDef'):
|
||||||
ifc2ca.convert()
|
psets = profile.HasProperties
|
||||||
print(json.dumps(ifc2ca.result, indent=4))
|
|
||||||
|
if self.get_pset_properties(psets, 'Pset_ProfileMechanical'):
|
||||||
|
mechProps = self.get_pset_properties(psets, 'Pset_ProfileMechanical')
|
||||||
|
else:
|
||||||
|
mechProps = self.get_i_section_properties(profile, 'iSymmetrical')
|
||||||
|
|
||||||
|
return {
|
||||||
|
'ifcName': profile.is_a() + '|' + str(profile.id()),
|
||||||
|
'profileName': profile.ProfileName,
|
||||||
|
'profileType': profile.ProfileType,
|
||||||
|
'profileShape': 'iSymmetrical',
|
||||||
|
'mechProps': mechProps,
|
||||||
|
'commonProps': {
|
||||||
|
'flangeThickness': profile.FlangeThickness,
|
||||||
|
'webThickness': profile.WebThickness,
|
||||||
|
'overallDepth': profile.OverallDepth,
|
||||||
|
'overallWidth': profile.OverallWidth,
|
||||||
|
'filletRadius': profile.FilletRadius,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_connection_data(self, itemList):
|
||||||
|
return [{
|
||||||
|
'ifcName': rel.is_a() + '|' + str(rel.id()),
|
||||||
|
'id': rel.GlobalId,
|
||||||
|
'relatingElement': rel.RelatingStructuralMember.is_a() + '|' + str(rel.RelatingStructuralMember.id()),
|
||||||
|
'relatedConnection': rel.RelatedStructuralConnection.is_a() + '|' + str(rel.RelatedStructuralConnection.id()),
|
||||||
|
'eccentricity': None if not rel.is_a('IfcRelConnectsWithEccentricity') else {
|
||||||
|
'inX': 0.0 if not rel.ConnectionConstraint.EccentricityInX else rel.ConnectionConstraint.EccentricityInX,
|
||||||
|
'inY': 0.0 if not rel.ConnectionConstraint.EccentricityInY else rel.ConnectionConstraint.EccentricityInY,
|
||||||
|
'inZ': 0.0 if not rel.ConnectionConstraint.EccentricityInZ else rel.ConnectionConstraint.EccentricityInZ,
|
||||||
|
'pointOnElement': self.get_coordinate(rel.ConnectionConstraint.PointOnRelatingElement)
|
||||||
|
}
|
||||||
|
# 'geometryPointIndex': None
|
||||||
|
} for rel in itemList]
|
||||||
|
|
||||||
|
def get_connection_input(self, connection):
|
||||||
|
if connection.AppliedCondition:
|
||||||
|
return {
|
||||||
|
'dx': connection.AppliedCondition.TranslationalStiffnessX.wrappedValue,
|
||||||
|
'dy': connection.AppliedCondition.TranslationalStiffnessY.wrappedValue,
|
||||||
|
'dz': connection.AppliedCondition.TranslationalStiffnessZ.wrappedValue,
|
||||||
|
'drx': connection.AppliedCondition.RotationalStiffnessX.wrappedValue,
|
||||||
|
'dry': connection.AppliedCondition.RotationalStiffnessY.wrappedValue,
|
||||||
|
'drz': connection.AppliedCondition.RotationalStiffnessZ.wrappedValue
|
||||||
|
}
|
||||||
|
return connection.AppliedCondition
|
||||||
|
|
||||||
|
def get_i_section_properties(self, profile, profileShape):
|
||||||
|
if profileShape == 'iSymmetrical':
|
||||||
|
tf = profile.FlangeThickness
|
||||||
|
tw = profile.WebThickness
|
||||||
|
h = profile.OverallDepth
|
||||||
|
b = profile.OverallWidth
|
||||||
|
|
||||||
|
A = b * h - (b - tw) * (h - 2 * tf)
|
||||||
|
Iy = b * (h ** 3) / 12 - (b - tw) * ((h - 2 * tf) ** 3) / 12
|
||||||
|
Iz = (2 * tf) * (b ** 3) / 12 + (h - 2 * tf) * (tw ** 3) / 12
|
||||||
|
Jx = 1 / 3 * ((h - tf) * (tw ** 3) + 2 * b * (tf ** 3))
|
||||||
|
|
||||||
|
return {
|
||||||
|
'crossSectionArea': A,
|
||||||
|
'momentOfInertiaY': Iy,
|
||||||
|
'momentOfInertiaZ': Iz,
|
||||||
|
'torsionalConstantX': Jx
|
||||||
|
}
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
IFC_FILENAME = ''
|
||||||
|
ifc2ca = IFC2CA(IFC_FILENAME)
|
||||||
|
ifc2ca.convert()
|
||||||
|
print(json.dumps(ifc2ca.result, indent=4))
|
||||||
|
|||||||
Reference in New Issue
Block a user