mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
black ifc2ca
This commit is contained in:
+297
-141
@@ -2,6 +2,7 @@ import json
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class CA2IFC:
|
class CA2IFC:
|
||||||
def __init__(self, inputFilename, outputFilename):
|
def __init__(self, inputFilename, outputFilename):
|
||||||
self.inputFilename = inputFilename
|
self.inputFilename = inputFilename
|
||||||
@@ -30,7 +31,7 @@ class CA2IFC:
|
|||||||
localPlacement = self.f.createIfcLocalPlacement(None, globalAxes)
|
localPlacement = self.f.createIfcLocalPlacement(None, globalAxes)
|
||||||
|
|
||||||
# TODO: create units
|
# TODO: create units
|
||||||
lengthUnit = self.f.createIfcSIUnit(None, 'LENGTHUNIT', None, 'METRE')
|
lengthUnit = self.f.createIfcSIUnit(None, "LENGTHUNIT", None, "METRE")
|
||||||
unitAssignment = self.f.createIfcUnitAssignment((lengthUnit,))
|
unitAssignment = self.f.createIfcUnitAssignment((lengthUnit,))
|
||||||
|
|
||||||
# create owner history
|
# create owner history
|
||||||
@@ -40,132 +41,246 @@ class CA2IFC:
|
|||||||
self.reps = self.create_reference_subrep(globalAxes)
|
self.reps = self.create_reference_subrep(globalAxes)
|
||||||
|
|
||||||
# create project and model
|
# create project and model
|
||||||
project = self.f.createIfcProject(self.guid(), ownerHistory, 'A Project', None, None, None, None, (self.reps['model'],), unitAssignment)
|
project = self.f.createIfcProject(
|
||||||
model = self.f.createIfcStructuralAnalysisModel(self.guid(), ownerHistory, self.data['name'], None, None, 'NOTDEFINED', globalAxes, None, None, localPlacement)
|
self.guid(), ownerHistory, "A Project", None, None, None, None, (self.reps["model"],), unitAssignment
|
||||||
|
)
|
||||||
|
model = self.f.createIfcStructuralAnalysisModel(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
self.data["name"],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"NOTDEFINED",
|
||||||
|
globalAxes,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localPlacement,
|
||||||
|
)
|
||||||
self.f.createIfcRelDeclares(self.guid(), ownerHistory, None, None, project, (model,))
|
self.f.createIfcRelDeclares(self.guid(), ownerHistory, None, None, project, (model,))
|
||||||
|
|
||||||
# create materials
|
# create materials
|
||||||
ifcMaterials = [None for _ in range(len(self.data['db']['materials']))]
|
ifcMaterials = [None for _ in range(len(self.data["db"]["materials"]))]
|
||||||
for i,material in enumerate(self.data['db']['materials']):
|
for i, material in enumerate(self.data["db"]["materials"]):
|
||||||
ifcMaterials[i] = self.create_material(material)
|
ifcMaterials[i] = self.create_material(material)
|
||||||
|
|
||||||
# create profiles
|
# create profiles
|
||||||
ifcProfiles = [None for _ in range(len(self.data['db']['profiles']))]
|
ifcProfiles = [None for _ in range(len(self.data["db"]["profiles"]))]
|
||||||
for i,profile in enumerate(self.data['db']['profiles']):
|
for i, profile in enumerate(self.data["db"]["profiles"]):
|
||||||
ifcProfiles[i] = self.create_profile(profile)
|
ifcProfiles[i] = self.create_profile(profile)
|
||||||
|
|
||||||
# create material-profile sets
|
# create material-profile sets
|
||||||
mpSets = list(set([el['material'] + '-' + el['profile'] for el in self.data['elements'] if el['geometryType'] == 'line']))
|
mpSets = list(
|
||||||
|
set([el["material"] + "-" + el["profile"] for el in self.data["elements"] if el["geometryType"] == "line"])
|
||||||
|
)
|
||||||
ifcMaterialProfileSets = [None for _ in range(len(mpSets))]
|
ifcMaterialProfileSets = [None for _ in range(len(mpSets))]
|
||||||
for i,mpSet in enumerate(mpSets):
|
for i, mpSet in enumerate(mpSets):
|
||||||
materialIndex = [mat['ifcName'] for mat in self.data['db']['materials']].index(mpSet.split('-')[0])
|
materialIndex = [mat["ifcName"] for mat in self.data["db"]["materials"]].index(mpSet.split("-")[0])
|
||||||
profileIndex = [prof['ifcName'] for prof in self.data['db']['profiles']].index(mpSet.split('-')[1])
|
profileIndex = [prof["ifcName"] for prof in self.data["db"]["profiles"]].index(mpSet.split("-")[1])
|
||||||
material = ifcMaterials[materialIndex]
|
material = ifcMaterials[materialIndex]
|
||||||
profile = ifcProfiles[profileIndex]
|
profile = ifcProfiles[profileIndex]
|
||||||
matProf = self.f.createIfcMaterialProfile(self.data['db']['materials'][materialIndex]['name'] + ' | ' + self.data['db']['profiles'][profileIndex]['profileName'], None, material, profile)
|
matProf = self.f.createIfcMaterialProfile(
|
||||||
|
self.data["db"]["materials"][materialIndex]["name"]
|
||||||
|
+ " | "
|
||||||
|
+ self.data["db"]["profiles"][profileIndex]["profileName"],
|
||||||
|
None,
|
||||||
|
material,
|
||||||
|
profile,
|
||||||
|
)
|
||||||
ifcMaterialProfileSets[i] = self.f.createIfcMaterialProfileSet(None, None, (matProf,))
|
ifcMaterialProfileSets[i] = self.f.createIfcMaterialProfileSet(None, None, (matProf,))
|
||||||
|
|
||||||
# create structural elements
|
# create structural elements
|
||||||
ifcElements = [None for _ in range(len(self.data['elements']))]
|
ifcElements = [None for _ in range(len(self.data["elements"]))]
|
||||||
for i,el in enumerate(self.data['elements']):
|
for i, el in enumerate(self.data["elements"]):
|
||||||
# geometry - product definition shape
|
# geometry - product definition shape
|
||||||
prodDefShape = self.create_geometry(el)
|
prodDefShape = self.create_geometry(el)
|
||||||
|
|
||||||
if el['geometryType'] == 'line':
|
if el["geometryType"] == "line":
|
||||||
# z axis TODO: group by elements
|
# z axis TODO: group by elements
|
||||||
localZAxis = self.f.createIfcDirection(tuple(el['orientation'][2]))
|
localZAxis = self.f.createIfcDirection(tuple(el["orientation"][2]))
|
||||||
# element
|
# element
|
||||||
ifcElements[i] = self.f.createIfcStructuralCurveMember(self.guid(), ownerHistory, el['name'], None, None, localPlacement, prodDefShape, el['predefinedType'], localZAxis)
|
ifcElements[i] = self.f.createIfcStructuralCurveMember(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
el["name"],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localPlacement,
|
||||||
|
prodDefShape,
|
||||||
|
el["predefinedType"],
|
||||||
|
localZAxis,
|
||||||
|
)
|
||||||
|
|
||||||
if el['geometryType'] == 'surface':
|
if el["geometryType"] == "surface":
|
||||||
ifcElements[i] = self.f.createIfcStructuralSurfaceMember(self.guid(), ownerHistory, el['name'], None, None, localPlacement, prodDefShape, el['predefinedType'], el['thickness'])
|
ifcElements[i] = self.f.createIfcStructuralSurfaceMember(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
el["name"],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localPlacement,
|
||||||
|
prodDefShape,
|
||||||
|
el["predefinedType"],
|
||||||
|
el["thickness"],
|
||||||
|
)
|
||||||
|
|
||||||
# create structural point connections
|
# create structural point connections
|
||||||
ifcConnections = [None for _ in range(len(self.data['connections']))]
|
ifcConnections = [None for _ in range(len(self.data["connections"]))]
|
||||||
for i,conn in enumerate(self.data['connections']):
|
for i, conn in enumerate(self.data["connections"]):
|
||||||
# geometry - product definition shape
|
# geometry - product definition shape
|
||||||
prodDefShape = self.create_geometry(conn)
|
prodDefShape = self.create_geometry(conn)
|
||||||
|
|
||||||
# boundary conditions
|
# boundary conditions
|
||||||
if conn['appliedCondition']:
|
if conn["appliedCondition"]:
|
||||||
bc = self.create_applied_conditions(conn['appliedCondition'], conn['geometryType'])
|
bc = self.create_applied_conditions(conn["appliedCondition"], conn["geometryType"])
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
appliedCondition = self.f.createIfcBoundaryNodeCondition(None, bc['dx'], bc['dy'], bc['dz'], bc['drx'], bc['dry'], bc['drz'])
|
appliedCondition = self.f.createIfcBoundaryNodeCondition(
|
||||||
if conn['geometryType'] == 'line':
|
None, bc["dx"], bc["dy"], bc["dz"], bc["drx"], bc["dry"], bc["drz"]
|
||||||
appliedCondition = self.f.createIfcBoundaryEdgeCondition(None, bc['dx'], bc['dy'], bc['dz'], bc['drx'], bc['dry'], bc['drz'])
|
)
|
||||||
if conn['geometryType'] == 'surface':
|
if conn["geometryType"] == "line":
|
||||||
appliedCondition = self.f.createIfcBoundaryFaceCondition(None, bc['dx'], bc['dy'], bc['dz'])
|
appliedCondition = self.f.createIfcBoundaryEdgeCondition(
|
||||||
|
None, bc["dx"], bc["dy"], bc["dz"], bc["drx"], bc["dry"], bc["drz"]
|
||||||
|
)
|
||||||
|
if conn["geometryType"] == "surface":
|
||||||
|
appliedCondition = self.f.createIfcBoundaryFaceCondition(None, bc["dx"], bc["dy"], bc["dz"])
|
||||||
else:
|
else:
|
||||||
appliedCondition = None
|
appliedCondition = None
|
||||||
|
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
# local axes
|
# local axes
|
||||||
localAxes = self.create_orientation(conn['orientation'])
|
localAxes = self.create_orientation(conn["orientation"])
|
||||||
# connection
|
# connection
|
||||||
ifcConnections[i] = self.f.createIfcStructuralPointConnection(self.guid(), ownerHistory, conn['name'], None, None, localPlacement, prodDefShape, appliedCondition, localAxes)
|
ifcConnections[i] = self.f.createIfcStructuralPointConnection(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
conn["name"],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localPlacement,
|
||||||
|
prodDefShape,
|
||||||
|
appliedCondition,
|
||||||
|
localAxes,
|
||||||
|
)
|
||||||
|
|
||||||
if conn['geometryType'] == 'line':
|
if conn["geometryType"] == "line":
|
||||||
# z axis TODO: group by elements
|
# z axis TODO: group by elements
|
||||||
localZAxis = self.f.createIfcDirection(tuple(conn['orientation'][2]))
|
localZAxis = self.f.createIfcDirection(tuple(conn["orientation"][2]))
|
||||||
# connection
|
# connection
|
||||||
ifcConnections[i] = self.f.createIfcStructuralCurveConnection(self.guid(), ownerHistory, conn['name'], None, None, localPlacement, prodDefShape, appliedCondition, localZAxis)
|
ifcConnections[i] = self.f.createIfcStructuralCurveConnection(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
conn["name"],
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localPlacement,
|
||||||
|
prodDefShape,
|
||||||
|
appliedCondition,
|
||||||
|
localZAxis,
|
||||||
|
)
|
||||||
|
|
||||||
if conn['geometryType'] == 'surface':
|
if conn["geometryType"] == "surface":
|
||||||
ifcConnections[i] = self.f.createIfcStructuralSurfaceConnection(self.guid(), ownerHistory, conn['name'], None, None, localPlacement, prodDefShape, appliedCondition)
|
ifcConnections[i] = self.f.createIfcStructuralSurfaceConnection(
|
||||||
|
self.guid(), ownerHistory, conn["name"], None, None, localPlacement, prodDefShape, appliedCondition
|
||||||
|
)
|
||||||
|
|
||||||
# assign material-profile-sets
|
# assign material-profile-sets
|
||||||
for i,mpSet in enumerate(mpSets):
|
for i, mpSet in enumerate(mpSets):
|
||||||
groupOfElements = []
|
groupOfElements = []
|
||||||
for j,el in enumerate(self.data['elements']):
|
for j, el in enumerate(self.data["elements"]):
|
||||||
if el['geometryType'] == 'line' and el['material'] + '-' + el['profile'] == mpSet:
|
if el["geometryType"] == "line" and el["material"] + "-" + el["profile"] == mpSet:
|
||||||
groupOfElements.append(ifcElements[j])
|
groupOfElements.append(ifcElements[j])
|
||||||
|
|
||||||
if groupOfElements:
|
if groupOfElements:
|
||||||
self.f.createIfcRelAssociatesMaterial(self.guid(), ownerHistory, None, None, tuple(groupOfElements), ifcMaterialProfileSets[i])
|
self.f.createIfcRelAssociatesMaterial(
|
||||||
|
self.guid(), ownerHistory, None, None, tuple(groupOfElements), ifcMaterialProfileSets[i]
|
||||||
|
)
|
||||||
|
|
||||||
# assign materials
|
# assign materials
|
||||||
for i,mat in enumerate(self.data['db']['materials']):
|
for i, mat in enumerate(self.data["db"]["materials"]):
|
||||||
groupOfElements = []
|
groupOfElements = []
|
||||||
for j,el in enumerate(self.data['elements']):
|
for j, el in enumerate(self.data["elements"]):
|
||||||
if el['geometryType'] == 'surface' and el['material'] == mat['ifcName']:
|
if el["geometryType"] == "surface" and el["material"] == mat["ifcName"]:
|
||||||
groupOfElements.append(ifcElements[j])
|
groupOfElements.append(ifcElements[j])
|
||||||
if groupOfElements:
|
if groupOfElements:
|
||||||
self.f.createIfcRelAssociatesMaterial(self.guid(), ownerHistory, None, None, tuple(groupOfElements), ifcMaterials[i])
|
self.f.createIfcRelAssociatesMaterial(
|
||||||
|
self.guid(), ownerHistory, None, None, tuple(groupOfElements), ifcMaterials[i]
|
||||||
|
)
|
||||||
|
|
||||||
# create connections with elements
|
# create connections with elements
|
||||||
for i,el in enumerate(self.data['elements']):
|
for i, el in enumerate(self.data["elements"]):
|
||||||
for conn in el['connections']:
|
for conn in el["connections"]:
|
||||||
j = [c['ifcName'] for c in self.data['connections']].index(conn['relatedConnection'])
|
j = [c["ifcName"] for c in self.data["connections"]].index(conn["relatedConnection"])
|
||||||
geometryType = self.data['connections'][j]['geometryType']
|
geometryType = self.data["connections"][j]["geometryType"]
|
||||||
|
|
||||||
if conn['appliedCondition']:
|
if conn["appliedCondition"]:
|
||||||
bc = self.create_applied_conditions(conn['appliedCondition'], geometryType)
|
bc = self.create_applied_conditions(conn["appliedCondition"], geometryType)
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
appliedCondition = self.f.createIfcBoundaryNodeCondition(None, bc['dx'], bc['dy'], bc['dz'], bc['drx'], bc['dry'], bc['drz'])
|
appliedCondition = self.f.createIfcBoundaryNodeCondition(
|
||||||
if geometryType == 'line':
|
None, bc["dx"], bc["dy"], bc["dz"], bc["drx"], bc["dry"], bc["drz"]
|
||||||
appliedCondition = self.f.createIfcBoundaryEdgeCondition(None, bc['dx'], bc['dy'], bc['dz'], bc['drx'], bc['dry'], bc['drz'])
|
)
|
||||||
if geometryType == 'surface':
|
if geometryType == "line":
|
||||||
appliedCondition = self.f.createIfcBoundaryFaceCondition(None, bc['dx'], bc['dy'], bc['dz'])
|
appliedCondition = self.f.createIfcBoundaryEdgeCondition(
|
||||||
|
None, bc["dx"], bc["dy"], bc["dz"], bc["drx"], bc["dry"], bc["drz"]
|
||||||
|
)
|
||||||
|
if geometryType == "surface":
|
||||||
|
appliedCondition = self.f.createIfcBoundaryFaceCondition(None, bc["dx"], bc["dy"], bc["dz"])
|
||||||
else:
|
else:
|
||||||
appliedCondition = None
|
appliedCondition = None
|
||||||
|
|
||||||
# local axes
|
# local axes
|
||||||
localAxes = self.create_orientation(conn['orientation'])
|
localAxes = self.create_orientation(conn["orientation"])
|
||||||
|
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
if not conn['eccentricity']:
|
if not conn["eccentricity"]:
|
||||||
self.f.createIfcRelConnectsStructuralMember(self.guid(), ownerHistory, None, None, ifcElements[i], ifcConnections[j], appliedCondition, None, None, localAxes)
|
self.f.createIfcRelConnectsStructuralMember(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
ifcElements[i],
|
||||||
|
ifcConnections[j],
|
||||||
|
appliedCondition,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localAxes,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
pointOnElement = self.f.createIfcCartesianPoint(tuple(conn['eccentricity']['pointOnElement']))
|
pointOnElement = self.f.createIfcCartesianPoint(tuple(conn["eccentricity"]["pointOnElement"]))
|
||||||
vector = conn['eccentricity']['vector']
|
vector = conn["eccentricity"]["vector"]
|
||||||
connPointEcc = self.f.createIfcConnectionPointEccentricity(pointOnElement, None, vector[0], vector[1], vector[2])
|
connPointEcc = self.f.createIfcConnectionPointEccentricity(
|
||||||
self.f.createIfcRelConnectsWithEccentricity(self.guid(), ownerHistory, None, None, ifcElements[i], ifcConnections[j], appliedCondition, None, None, localAxes, connPointEcc)
|
pointOnElement, None, vector[0], vector[1], vector[2]
|
||||||
|
)
|
||||||
|
self.f.createIfcRelConnectsWithEccentricity(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
ifcElements[i],
|
||||||
|
ifcConnections[j],
|
||||||
|
appliedCondition,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localAxes,
|
||||||
|
connPointEcc,
|
||||||
|
)
|
||||||
|
|
||||||
if geometryType in ['line', 'surface']:
|
if geometryType in ["line", "surface"]:
|
||||||
self.f.createIfcRelConnectsStructuralMember(self.guid(), ownerHistory, None, None, ifcElements[i], ifcConnections[j], appliedCondition, None, None, localAxes)
|
self.f.createIfcRelConnectsStructuralMember(
|
||||||
|
self.guid(),
|
||||||
|
ownerHistory,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
ifcElements[i],
|
||||||
|
ifcConnections[j],
|
||||||
|
appliedCondition,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
localAxes,
|
||||||
|
)
|
||||||
|
|
||||||
# assign elements and connections to group
|
# assign elements and connections to group
|
||||||
self.f.createIfcRelAssignsToGroup(self.guid(), ownerHistory, None, None, tuple(ifcElements + ifcConnections), None, model)
|
self.f.createIfcRelAssignsToGroup(
|
||||||
|
self.guid(), ownerHistory, None, None, tuple(ifcElements + ifcConnections), None, model
|
||||||
|
)
|
||||||
|
|
||||||
# finalize ifc file
|
# finalize ifc file
|
||||||
self.f.write(self.outputFilename)
|
self.f.write(self.outputFilename)
|
||||||
@@ -177,10 +292,10 @@ class CA2IFC:
|
|||||||
self.f.wrapped_data.header.file_name.name = os.path.basename(self.outputFilename)
|
self.f.wrapped_data.header.file_name.name = os.path.basename(self.outputFilename)
|
||||||
|
|
||||||
def create_global_axes(self):
|
def create_global_axes(self):
|
||||||
self.xAxis = self.f.createIfcDirection((1., 0., 0.))
|
self.xAxis = self.f.createIfcDirection((1.0, 0.0, 0.0))
|
||||||
self.yAxis = self.f.createIfcDirection((0., 1., 0.))
|
self.yAxis = self.f.createIfcDirection((0.0, 1.0, 0.0))
|
||||||
self.zAxis = self.f.createIfcDirection((0., 0., 1.))
|
self.zAxis = self.f.createIfcDirection((0.0, 0.0, 1.0))
|
||||||
self.origin = self.f.createIfcCartesianPoint((0., 0., 0.))
|
self.origin = self.f.createIfcCartesianPoint((0.0, 0.0, 0.0))
|
||||||
axes = self.f.createIfcAxis2Placement3D(self.origin, self.zAxis, self.xAxis)
|
axes = self.f.createIfcAxis2Placement3D(self.origin, self.zAxis, self.xAxis)
|
||||||
|
|
||||||
return axes
|
return axes
|
||||||
@@ -193,156 +308,197 @@ class CA2IFC:
|
|||||||
return axes
|
return axes
|
||||||
|
|
||||||
def create_owner_history(self):
|
def create_owner_history(self):
|
||||||
actor = self.f.createIfcActorRole('ENGINEER', None, None)
|
actor = self.f.createIfcActorRole("ENGINEER", None, None)
|
||||||
person = self.f.createIfcPerson('Christovasilis', None, 'Ioannis', None, None, None, (actor,))
|
person = self.f.createIfcPerson("Christovasilis", None, "Ioannis", None, None, None, (actor,))
|
||||||
organization = self.f.createIfcOrganization(None, 'IfcOpenShell', 'IfcOpenShell, an open source (LGPL) software library that helps users and software developers to work with the IFC file format.')
|
organization = self.f.createIfcOrganization(
|
||||||
|
None,
|
||||||
|
"IfcOpenShell",
|
||||||
|
"IfcOpenShell, an open source (LGPL) software library that helps users and software developers to work with the IFC file format.",
|
||||||
|
)
|
||||||
p_o = self.f.createIfcPersonAndOrganization(person, organization)
|
p_o = self.f.createIfcPersonAndOrganization(person, organization)
|
||||||
application = self.f.createIfcApplication(organization, 'v0.0.x', 'IFC2CA', 'IFC2CA')
|
application = self.f.createIfcApplication(organization, "v0.0.x", "IFC2CA", "IFC2CA")
|
||||||
ownerHistory = self.f.createIfcOwnerHistory(p_o, application, 'READWRITE', None, None, p_o, application)
|
ownerHistory = self.f.createIfcOwnerHistory(p_o, application, "READWRITE", None, None, p_o, application)
|
||||||
|
|
||||||
return ownerHistory
|
return ownerHistory
|
||||||
|
|
||||||
def create_reference_subrep(self, globalAxes):
|
def create_reference_subrep(self, globalAxes):
|
||||||
modelRep = self.f.createIfcGeometricRepresentationContext(None, 'Model', 3, 1.E-05, globalAxes, None)
|
modelRep = self.f.createIfcGeometricRepresentationContext(None, "Model", 3, 1.0e-05, globalAxes, None)
|
||||||
bodySubRep = self.f.createIfcGeometricRepresentationSubContext('Body', 'Model', None, None, None , None, modelRep, None, 'MODEL_VIEW', None)
|
bodySubRep = self.f.createIfcGeometricRepresentationSubContext(
|
||||||
refSubRep = self.f.createIfcGeometricRepresentationSubContext('Reference', 'Model', None, None, None , None, modelRep, None, 'GRAPH_VIEW', None)
|
"Body", "Model", None, None, None, None, modelRep, None, "MODEL_VIEW", None
|
||||||
|
)
|
||||||
|
refSubRep = self.f.createIfcGeometricRepresentationSubContext(
|
||||||
|
"Reference", "Model", None, None, None, None, modelRep, None, "GRAPH_VIEW", None
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {"model": modelRep, "body": bodySubRep, "reference": refSubRep}
|
||||||
'model': modelRep,
|
|
||||||
'body': bodySubRep,
|
|
||||||
'reference': refSubRep
|
|
||||||
}
|
|
||||||
|
|
||||||
def create_material(self, material):
|
def create_material(self, material):
|
||||||
ifcMaterial = self.f.createIfcMaterial(material['name'], None, material['category'])
|
ifcMaterial = self.f.createIfcMaterial(material["name"], None, material["category"])
|
||||||
|
|
||||||
mechProps = []
|
mechProps = []
|
||||||
if 'youngModulus' in material['mechProps']:
|
if "youngModulus" in material["mechProps"]:
|
||||||
youngModulus = self.f.createIfcPropertySingleValue('YoungModulus', None, self.f.createIfcModulusOfElasticityMeasure(material['mechProps']['youngModulus']))
|
youngModulus = self.f.createIfcPropertySingleValue(
|
||||||
|
"YoungModulus", None, self.f.createIfcModulusOfElasticityMeasure(material["mechProps"]["youngModulus"])
|
||||||
|
)
|
||||||
mechProps.append(youngModulus)
|
mechProps.append(youngModulus)
|
||||||
if 'shearModulus' in material['mechProps']:
|
if "shearModulus" in material["mechProps"]:
|
||||||
shearModulus = self.f.createIfcPropertySingleValue('ShearModulus', None, self.f.createIfcModulusOfElasticityMeasure(material['mechProps']['shearModulus']))
|
shearModulus = self.f.createIfcPropertySingleValue(
|
||||||
|
"ShearModulus", None, self.f.createIfcModulusOfElasticityMeasure(material["mechProps"]["shearModulus"])
|
||||||
|
)
|
||||||
mechProps.append(shearModulus)
|
mechProps.append(shearModulus)
|
||||||
if 'poissonRatio' in material['mechProps']:
|
if "poissonRatio" in material["mechProps"]:
|
||||||
poissonRatio = self.f.createIfcPropertySingleValue('PoissonRatio', None, self.f.createIfcPositiveRatioMeasure(material['mechProps']['poissonRatio']))
|
poissonRatio = self.f.createIfcPropertySingleValue(
|
||||||
|
"PoissonRatio", None, self.f.createIfcPositiveRatioMeasure(material["mechProps"]["poissonRatio"])
|
||||||
|
)
|
||||||
mechProps.append(poissonRatio)
|
mechProps.append(poissonRatio)
|
||||||
if mechProps:
|
if mechProps:
|
||||||
self.f.createIfcMaterialProperties('Pset_MaterialMechanical', material['name'], tuple(mechProps), ifcMaterial)
|
self.f.createIfcMaterialProperties(
|
||||||
|
"Pset_MaterialMechanical", material["name"], tuple(mechProps), ifcMaterial
|
||||||
|
)
|
||||||
|
|
||||||
commonProps = []
|
commonProps = []
|
||||||
if 'massDensity' in material['commonProps']:
|
if "massDensity" in material["commonProps"]:
|
||||||
massDensity = self.f.createIfcPropertySingleValue('MassDensity', None, self.f.createIfcMassDensityMeasure(material['commonProps']['massDensity']))
|
massDensity = self.f.createIfcPropertySingleValue(
|
||||||
|
"MassDensity", None, self.f.createIfcMassDensityMeasure(material["commonProps"]["massDensity"])
|
||||||
|
)
|
||||||
commonProps.append(massDensity)
|
commonProps.append(massDensity)
|
||||||
if commonProps:
|
if commonProps:
|
||||||
self.f.createIfcMaterialProperties('Pset_MaterialCommon', material['name'], tuple(commonProps), ifcMaterial)
|
self.f.createIfcMaterialProperties("Pset_MaterialCommon", material["name"], tuple(commonProps), ifcMaterial)
|
||||||
|
|
||||||
return ifcMaterial
|
return ifcMaterial
|
||||||
|
|
||||||
def create_profile(self, profile):
|
def create_profile(self, profile):
|
||||||
if profile['profileShape'] == 'rectangular':
|
if profile["profileShape"] == "rectangular":
|
||||||
ifcProfile = self.f.createIfcRectangleProfileDef(profile['profileType'], profile['profileName'], None, profile['xDim'], profile['yDim'])
|
ifcProfile = self.f.createIfcRectangleProfileDef(
|
||||||
|
profile["profileType"], profile["profileName"], None, profile["xDim"], profile["yDim"]
|
||||||
|
)
|
||||||
|
|
||||||
if profile['profileShape'] == 'iSymmetrical':
|
if profile["profileShape"] == "iSymmetrical":
|
||||||
ifcProfile = self.f.createIfcIShapeProfileDef(
|
ifcProfile = self.f.createIfcIShapeProfileDef(
|
||||||
profile['profileType'], profile['profileName'], None,
|
profile["profileType"],
|
||||||
profile['commonProps']['overallWidth'],
|
profile["profileName"],
|
||||||
profile['commonProps']['overallDepth'],
|
None,
|
||||||
profile['commonProps']['webThickness'],
|
profile["commonProps"]["overallWidth"],
|
||||||
profile['commonProps']['flangeThickness'],
|
profile["commonProps"]["overallDepth"],
|
||||||
profile['commonProps']['filletRadius']
|
profile["commonProps"]["webThickness"],
|
||||||
|
profile["commonProps"]["flangeThickness"],
|
||||||
|
profile["commonProps"]["filletRadius"],
|
||||||
)
|
)
|
||||||
|
|
||||||
mechProps = []
|
mechProps = []
|
||||||
if 'massPerLength' in profile['mechProps']:
|
if "massPerLength" in profile["mechProps"]:
|
||||||
massPerLength = self.f.createIfcPropertySingleValue('MassPerLength', None, self.f.createIfcMassPerLengthMeasure(profile['mechProps']['massPerLength']))
|
massPerLength = self.f.createIfcPropertySingleValue(
|
||||||
|
"MassPerLength", None, self.f.createIfcMassPerLengthMeasure(profile["mechProps"]["massPerLength"])
|
||||||
|
)
|
||||||
mechProps.append(massPerLength)
|
mechProps.append(massPerLength)
|
||||||
if 'crossSectionArea' in profile['mechProps']:
|
if "crossSectionArea" in profile["mechProps"]:
|
||||||
crossSectionArea = self.f.createIfcPropertySingleValue('CrossSectionArea', None, self.f.createIfcAreaMeasure(profile['mechProps']['crossSectionArea']))
|
crossSectionArea = self.f.createIfcPropertySingleValue(
|
||||||
|
"CrossSectionArea", None, self.f.createIfcAreaMeasure(profile["mechProps"]["crossSectionArea"])
|
||||||
|
)
|
||||||
mechProps.append(crossSectionArea)
|
mechProps.append(crossSectionArea)
|
||||||
if 'momentOfInertiaY' in profile['mechProps']:
|
if "momentOfInertiaY" in profile["mechProps"]:
|
||||||
momentOfInertiaY = self.f.createIfcPropertySingleValue('MomentOfInertiaY', None, self.f.createIfcMomentOfInertiaMeasure(profile['mechProps']['momentOfInertiaY']))
|
momentOfInertiaY = self.f.createIfcPropertySingleValue(
|
||||||
|
"MomentOfInertiaY",
|
||||||
|
None,
|
||||||
|
self.f.createIfcMomentOfInertiaMeasure(profile["mechProps"]["momentOfInertiaY"]),
|
||||||
|
)
|
||||||
mechProps.append(momentOfInertiaY)
|
mechProps.append(momentOfInertiaY)
|
||||||
if 'momentOfInertiaZ' in profile['mechProps']:
|
if "momentOfInertiaZ" in profile["mechProps"]:
|
||||||
momentOfInertiaZ = self.f.createIfcPropertySingleValue('MomentOfInertiaZ', None, self.f.createIfcMomentOfInertiaMeasure(profile['mechProps']['momentOfInertiaZ']))
|
momentOfInertiaZ = self.f.createIfcPropertySingleValue(
|
||||||
|
"MomentOfInertiaZ",
|
||||||
|
None,
|
||||||
|
self.f.createIfcMomentOfInertiaMeasure(profile["mechProps"]["momentOfInertiaZ"]),
|
||||||
|
)
|
||||||
mechProps.append(momentOfInertiaZ)
|
mechProps.append(momentOfInertiaZ)
|
||||||
if 'torsionalConstantX' in profile['mechProps']:
|
if "torsionalConstantX" in profile["mechProps"]:
|
||||||
torsionalConstantX = self.f.createIfcPropertySingleValue('TorsionalConstantX', None, self.f.createIfcMomentOfInertiaMeasure(profile['mechProps']['torsionalConstantX']))
|
torsionalConstantX = self.f.createIfcPropertySingleValue(
|
||||||
|
"TorsionalConstantX",
|
||||||
|
None,
|
||||||
|
self.f.createIfcMomentOfInertiaMeasure(profile["mechProps"]["torsionalConstantX"]),
|
||||||
|
)
|
||||||
mechProps.append(torsionalConstantX)
|
mechProps.append(torsionalConstantX)
|
||||||
if mechProps:
|
if mechProps:
|
||||||
self.f.createIfcProfileProperties('Pset_ProfileMechanical', profile['profileName'], tuple(mechProps), ifcProfile)
|
self.f.createIfcProfileProperties(
|
||||||
|
"Pset_ProfileMechanical", profile["profileName"], tuple(mechProps), ifcProfile
|
||||||
|
)
|
||||||
|
|
||||||
return ifcProfile
|
return ifcProfile
|
||||||
|
|
||||||
def create_geometry(self, object):
|
def create_geometry(self, object):
|
||||||
if object['geometryType'] == 'point':
|
if object["geometryType"] == "point":
|
||||||
point = self.f.createIfcCartesianPoint(tuple(object['geometry']))
|
point = self.f.createIfcCartesianPoint(tuple(object["geometry"]))
|
||||||
vertex = self.f.createIfcVertexPoint(point)
|
vertex = self.f.createIfcVertexPoint(point)
|
||||||
vertexTopologyRep = self.f.createIfcTopologyRepresentation(self.reps['reference'], 'Reference', 'Vertex', (vertex,))
|
vertexTopologyRep = self.f.createIfcTopologyRepresentation(
|
||||||
|
self.reps["reference"], "Reference", "Vertex", (vertex,)
|
||||||
|
)
|
||||||
vertexProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (vertexTopologyRep,))
|
vertexProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (vertexTopologyRep,))
|
||||||
|
|
||||||
return vertexProdDefShape
|
return vertexProdDefShape
|
||||||
|
|
||||||
if object['geometryType'] == 'line':
|
if object["geometryType"] == "line":
|
||||||
startPoint = self.f.createIfcCartesianPoint(tuple(object['geometry'][0]))
|
startPoint = self.f.createIfcCartesianPoint(tuple(object["geometry"][0]))
|
||||||
startVertex = self.f.createIfcVertexPoint(startPoint)
|
startVertex = self.f.createIfcVertexPoint(startPoint)
|
||||||
endPoint = self.f.createIfcCartesianPoint(tuple(object['geometry'][1]))
|
endPoint = self.f.createIfcCartesianPoint(tuple(object["geometry"][1]))
|
||||||
endVertex = self.f.createIfcVertexPoint(endPoint)
|
endVertex = self.f.createIfcVertexPoint(endPoint)
|
||||||
edge = self.f.createIfcEdge(startVertex, endVertex)
|
edge = self.f.createIfcEdge(startVertex, endVertex)
|
||||||
edgeTopologyRep = self.f.createIfcTopologyRepresentation(self.reps['reference'], 'Reference', 'Edge', (edge,))
|
edgeTopologyRep = self.f.createIfcTopologyRepresentation(
|
||||||
|
self.reps["reference"], "Reference", "Edge", (edge,)
|
||||||
|
)
|
||||||
edgeProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (edgeTopologyRep,))
|
edgeProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (edgeTopologyRep,))
|
||||||
|
|
||||||
return edgeProdDefShape
|
return edgeProdDefShape
|
||||||
|
|
||||||
if object['geometryType'] == 'surface':
|
if object["geometryType"] == "surface":
|
||||||
verts = [None for _ in range(len(object['geometry']))]
|
verts = [None for _ in range(len(object["geometry"]))]
|
||||||
for i,p in enumerate(object['geometry']):
|
for i, p in enumerate(object["geometry"]):
|
||||||
point = self.f.createIfcCartesianPoint(tuple(p))
|
point = self.f.createIfcCartesianPoint(tuple(p))
|
||||||
verts[i] = self.f.createIfcVertexPoint(point)
|
verts[i] = self.f.createIfcVertexPoint(point)
|
||||||
|
|
||||||
orientedEdges = [None for _ in range(len(object['geometry']))]
|
orientedEdges = [None for _ in range(len(object["geometry"]))]
|
||||||
for i,v in enumerate(verts):
|
for i, v in enumerate(verts):
|
||||||
v2Index = (i + 1) if i < len(verts) - 1 else 0
|
v2Index = (i + 1) if i < len(verts) - 1 else 0
|
||||||
edge = self.f.createIfcEdge(v, verts[v2Index])
|
edge = self.f.createIfcEdge(v, verts[v2Index])
|
||||||
orientedEdges[i] = self.f.createIfcOrientedEdge(None, None, edge, True)
|
orientedEdges[i] = self.f.createIfcOrientedEdge(None, None, edge, True)
|
||||||
|
|
||||||
edgeLoop = self.f.createIfcEdgeLoop(tuple(orientedEdges))
|
edgeLoop = self.f.createIfcEdgeLoop(tuple(orientedEdges))
|
||||||
localAxes = self.create_orientation(object['orientation'])
|
localAxes = self.create_orientation(object["orientation"])
|
||||||
plane = self.f.createIfcPlane(localAxes)
|
plane = self.f.createIfcPlane(localAxes)
|
||||||
faceBound = self.f.createIfcFaceBound(edgeLoop, True)
|
faceBound = self.f.createIfcFaceBound(edgeLoop, True)
|
||||||
face = self.f.createIfcFaceSurface((faceBound,), plane, True)
|
face = self.f.createIfcFaceSurface((faceBound,), plane, True)
|
||||||
faceTopologyRep = self.f.createIfcTopologyRepresentation(self.reps['reference'], 'Reference', 'Face', (face,))
|
faceTopologyRep = self.f.createIfcTopologyRepresentation(
|
||||||
|
self.reps["reference"], "Reference", "Face", (face,)
|
||||||
|
)
|
||||||
faceProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (faceTopologyRep,))
|
faceProdDefShape = self.f.createIfcProductDefinitionShape(None, None, (faceTopologyRep,))
|
||||||
|
|
||||||
return faceProdDefShape
|
return faceProdDefShape
|
||||||
|
|
||||||
def create_applied_conditions(self, bc, geometryType):
|
def create_applied_conditions(self, bc, geometryType):
|
||||||
for dof in ['dx', 'dy', 'dz']:
|
for dof in ["dx", "dy", "dz"]:
|
||||||
if isinstance(bc[dof], bool):
|
if isinstance(bc[dof], bool):
|
||||||
bc[dof] = self.f.createIfcBoolean(bc[dof])
|
bc[dof] = self.f.createIfcBoolean(bc[dof])
|
||||||
else:
|
else:
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
bc[dof] = self.f.createIfcLinearStiffnessMeasure(bc[dof])
|
bc[dof] = self.f.createIfcLinearStiffnessMeasure(bc[dof])
|
||||||
if geometryType == 'line':
|
if geometryType == "line":
|
||||||
bc[dof] = self.f.createIfcModulusOfLinearSubgradeReactionMeasure(bc[dof])
|
bc[dof] = self.f.createIfcModulusOfLinearSubgradeReactionMeasure(bc[dof])
|
||||||
if geometryType == 'surface':
|
if geometryType == "surface":
|
||||||
bc[dof] = self.f.createIfcModulusOfSubgradeReactionMeasure(bc[dof])
|
bc[dof] = self.f.createIfcModulusOfSubgradeReactionMeasure(bc[dof])
|
||||||
|
|
||||||
for dof in ['drx', 'dry', 'drz']:
|
for dof in ["drx", "dry", "drz"]:
|
||||||
if isinstance(bc[dof], bool):
|
if isinstance(bc[dof], bool):
|
||||||
bc[dof] = self.f.createIfcBoolean(bc[dof])
|
bc[dof] = self.f.createIfcBoolean(bc[dof])
|
||||||
else:
|
else:
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
bc[dof] = self.f.createIfcRotationalStiffnessMeasure(bc[dof])
|
bc[dof] = self.f.createIfcRotationalStiffnessMeasure(bc[dof])
|
||||||
if geometryType == 'line':
|
if geometryType == "line":
|
||||||
bc[dof] = self.f.createIfcModulusOfRotationalSubgradeReactionMeasure(bc[dof])
|
bc[dof] = self.f.createIfcModulusOfRotationalSubgradeReactionMeasure(bc[dof])
|
||||||
|
|
||||||
return bc
|
return bc
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
if __name__ == '__main__':
|
inputFilename = "structure_01.json"
|
||||||
inputFilename = 'structure_01.json'
|
outputFilename = "structure_01.ifc"
|
||||||
outputFilename = 'structure_01.ifc'
|
|
||||||
|
|
||||||
ca2ifc = CA2IFC(inputFilename, outputFilename)
|
ca2ifc = CA2IFC(inputFilename, outputFilename)
|
||||||
ca2ifc.convert()
|
ca2ifc.convert()
|
||||||
|
|||||||
+245
-216
@@ -4,59 +4,59 @@ import json
|
|||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
class IFC2CA:
|
class IFC2CA:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.file = None
|
self.file = None
|
||||||
self.result = {}
|
self.result = {}
|
||||||
self.warnings = []
|
self.warnings = []
|
||||||
self.tol = 1E-06
|
self.tol = 1e-06
|
||||||
|
|
||||||
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"):
|
||||||
elements = self.get_structural_items(model, item_type='IfcStructuralMember')
|
elements = self.get_structural_items(model, item_type="IfcStructuralMember")
|
||||||
connections = self.get_structural_items(model, item_type='IfcStructuralConnection')
|
connections = self.get_structural_items(model, item_type="IfcStructuralConnection")
|
||||||
|
|
||||||
materialdb = []
|
materialdb = []
|
||||||
materials = list(dict.fromkeys([e['material'] for e in elements]))
|
materials = list(dict.fromkeys([e["material"] for e in elements]))
|
||||||
for mat in [mat for mat in materials if mat]:
|
for mat in [mat for mat in materials if mat]:
|
||||||
id = int(mat.split('|')[1])
|
id = int(mat.split("|")[1])
|
||||||
material = self.get_material_properties(self.file.by_id(id))
|
material = self.get_material_properties(self.file.by_id(id))
|
||||||
material['relatedElements'] = [e['ifcName'] for e in elements if 'material' in e and e['material'] == mat]
|
material["relatedElements"] = [
|
||||||
|
e["ifcName"] for e in elements if "material" in e and e["material"] == mat
|
||||||
|
]
|
||||||
materialdb.append(material)
|
materialdb.append(material)
|
||||||
|
|
||||||
profiledb = []
|
profiledb = []
|
||||||
profiles = list(dict.fromkeys([e['profile'] for e in elements if 'profile' in e]))
|
profiles = list(dict.fromkeys([e["profile"] for e in elements if "profile" in e]))
|
||||||
for prof in [prof for prof in profiles if prof]:
|
for prof in [prof for prof in profiles if prof]:
|
||||||
id = int(prof.split('|')[1])
|
id = int(prof.split("|")[1])
|
||||||
profile = self.get_profile_properties(self.file.by_id(id))
|
profile = self.get_profile_properties(self.file.by_id(id))
|
||||||
profile['relatedElements'] = [e['ifcName'] for e in elements if 'profile' in e and e['profile'] == prof]
|
profile["relatedElements"] = [e["ifcName"] for e in elements if "profile" in e and e["profile"] == prof]
|
||||||
profiledb.append(profile)
|
profiledb.append(profile)
|
||||||
|
|
||||||
self.result = {
|
self.result = {
|
||||||
'ifcName': model.is_a() + '|' + str(model.id()),
|
"ifcName": model.is_a() + "|" + str(model.id()),
|
||||||
'name': model.Name,
|
"name": model.Name,
|
||||||
'id': model.GlobalId,
|
"id": model.GlobalId,
|
||||||
'elements': elements,
|
"elements": elements,
|
||||||
'connections': connections,
|
"connections": connections,
|
||||||
'db': {
|
"db": {"materials": materialdb, "profiles": profiledb},
|
||||||
'materials': materialdb,
|
"warnings": self.warnings,
|
||||||
'profiles': profiledb
|
|
||||||
},
|
|
||||||
'warnings': self.warnings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print('Model "%s" converted' % model.Name)
|
print('Model "%s" converted' % model.Name)
|
||||||
print('Number of elements: ', len(elements))
|
print("Number of elements: ", len(elements))
|
||||||
print('Number of connections: ', len(connections))
|
print("Number of connections: ", len(connections))
|
||||||
print('Number of materials: ', len(materialdb))
|
print("Number of materials: ", len(materialdb))
|
||||||
print('Number of profiles: ', len(profiledb))
|
print("Number of profiles: ", len(profiledb))
|
||||||
print('')
|
print("")
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
def get_structural_items(self, model, item_type='IfcStructuralItem'):
|
def get_structural_items(self, model, item_type="IfcStructuralItem"):
|
||||||
items = []
|
items = []
|
||||||
for group in model.IsGroupedBy:
|
for group in model.IsGroupedBy:
|
||||||
for item in group.RelatedObjects:
|
for item in group.RelatedObjects:
|
||||||
@@ -70,100 +70,112 @@ class IFC2CA:
|
|||||||
def get_item_data(self, item):
|
def get_item_data(self, item):
|
||||||
transformation = self.get_transformation(item.ObjectPlacement)
|
transformation = self.get_transformation(item.ObjectPlacement)
|
||||||
|
|
||||||
if item.is_a('IfcStructuralCurveMember'):
|
if item.is_a("IfcStructuralCurveMember"):
|
||||||
representation = self.get_representation(item, 'Edge')
|
representation = self.get_representation(item, "Edge")
|
||||||
material_profile = self.get_material_profile(item)
|
material_profile = self.get_material_profile(item)
|
||||||
if not representation:
|
if not representation:
|
||||||
self.warnings.append('No representation defined for %s. Member excluded' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append(
|
||||||
|
"No representation defined for %s. Member excluded" % (item.is_a() + "|" + str(item.id()))
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if not material_profile:
|
if not material_profile:
|
||||||
self.warnings.append('No material defined for in %s' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append("No material defined for in %s" % (item.is_a() + "|" + str(item.id())))
|
||||||
self.warnings.append('No profile defined for in %s' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append("No profile defined for in %s" % (item.is_a() + "|" + str(item.id())))
|
||||||
materialId = None
|
materialId = None
|
||||||
profileId = None
|
profileId = None
|
||||||
else:
|
else:
|
||||||
material = material_profile.Material
|
material = material_profile.Material
|
||||||
materialId = material.is_a() + '|' + str(material.id())
|
materialId = material.is_a() + "|" + str(material.id())
|
||||||
profile = material_profile.Profile
|
profile = material_profile.Profile
|
||||||
profileId = profile.is_a() + '|' + str(profile.id())
|
profileId = profile.is_a() + "|" + str(profile.id())
|
||||||
|
|
||||||
geometry = self.get_geometry(representation)
|
geometry = self.get_geometry(representation)
|
||||||
orientation = self.get_1D_orientation(geometry, item.Axis)
|
orientation = self.get_1D_orientation(geometry, item.Axis)
|
||||||
connections = self.get_connection_data(item.ConnectedBy)
|
connections = self.get_connection_data(item.ConnectedBy)
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
if not conn['orientation']:
|
if not conn["orientation"]:
|
||||||
conn['orientation'] = orientation
|
conn["orientation"] = orientation
|
||||||
# --> Correct pointOnElement for eccentricity connection for ETABS files
|
# --> Correct pointOnElement for eccentricity connection for ETABS files
|
||||||
length = np.linalg.norm(np.array(geometry[1]) - np.array(geometry[0]))
|
length = np.linalg.norm(np.array(geometry[1]) - np.array(geometry[0]))
|
||||||
for c in connections:
|
for c in connections:
|
||||||
if c['eccentricity']:
|
if c["eccentricity"]:
|
||||||
if np.linalg.norm(np.array(c['eccentricity']['pointOnElement'])) > length + self.tol:
|
if np.linalg.norm(np.array(c["eccentricity"]["pointOnElement"])) > length + self.tol:
|
||||||
print(np.linalg.norm(np.array(c['eccentricity']['pointOnElement'])), '>', length)
|
print(np.linalg.norm(np.array(c["eccentricity"]["pointOnElement"])), ">", length)
|
||||||
self.warnings.append('Eccentricity in %s corrected' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append("Eccentricity in %s corrected" % (item.is_a() + "|" + str(item.id())))
|
||||||
c['eccentricity']['pointOnElement'][0] = length
|
c["eccentricity"]["pointOnElement"][0] = length
|
||||||
# End <--
|
# End <--
|
||||||
if transformation:
|
if transformation:
|
||||||
geometry = self.transform_vectors(geometry, transformation)
|
geometry = self.transform_vectors(geometry, transformation)
|
||||||
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
||||||
for c in connections:
|
for c in connections:
|
||||||
c['orientation'] = self.transform_vectors(c['orientation'], transformation, include_translation=False)
|
c["orientation"] = self.transform_vectors(
|
||||||
if c['eccentricity']:
|
c["orientation"], transformation, include_translation=False
|
||||||
c['eccentricity']['vector'] = self.transform_vectors(c['eccentricity']['vector'], transformation, include_translation=False)
|
)
|
||||||
|
if c["eccentricity"]:
|
||||||
|
c["eccentricity"]["vector"] = self.transform_vectors(
|
||||||
|
c["eccentricity"]["vector"], transformation, include_translation=False
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': item.is_a() + '|' + str(item.id()),
|
"ifcName": item.is_a() + "|" + str(item.id()),
|
||||||
'name': item.Name,
|
"name": item.Name,
|
||||||
'id': item.GlobalId,
|
"id": item.GlobalId,
|
||||||
'geometryType': 'line',
|
"geometryType": "line",
|
||||||
'predefinedType': item.PredefinedType,
|
"predefinedType": item.PredefinedType,
|
||||||
'geometry': geometry,
|
"geometry": geometry,
|
||||||
'orientation': orientation,
|
"orientation": orientation,
|
||||||
'material': materialId,
|
"material": materialId,
|
||||||
'profile': profileId,
|
"profile": profileId,
|
||||||
'connections': connections
|
"connections": connections,
|
||||||
}
|
}
|
||||||
|
|
||||||
elif item.is_a('IfcStructuralSurfaceMember'):
|
elif item.is_a("IfcStructuralSurfaceMember"):
|
||||||
representation = self.get_representation(item, 'Face')
|
representation = self.get_representation(item, "Face")
|
||||||
material = self.get_material_profile(item)
|
material = self.get_material_profile(item)
|
||||||
if not representation:
|
if not representation:
|
||||||
self.warnings.append('No representation defined for %s. Member excluded' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append(
|
||||||
|
"No representation defined for %s. Member excluded" % (item.is_a() + "|" + str(item.id()))
|
||||||
|
)
|
||||||
return
|
return
|
||||||
if not material:
|
if not material:
|
||||||
self.warnings.append('No material defined for in %s' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append("No material defined for in %s" % (item.is_a() + "|" + str(item.id())))
|
||||||
materialId = None
|
materialId = None
|
||||||
else:
|
else:
|
||||||
materialId = material.is_a() + '|' + str(material.id())
|
materialId = material.is_a() + "|" + str(material.id())
|
||||||
|
|
||||||
geometry = self.get_geometry(representation)
|
geometry = self.get_geometry(representation)
|
||||||
orientation = self.get_2D_orientation(representation)
|
orientation = self.get_2D_orientation(representation)
|
||||||
connections = self.get_connection_data(item.ConnectedBy)
|
connections = self.get_connection_data(item.ConnectedBy)
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
if not conn['orientation']:
|
if not conn["orientation"]:
|
||||||
conn['orientation'] = orientation
|
conn["orientation"] = orientation
|
||||||
if transformation:
|
if transformation:
|
||||||
geometry = self.transform_vectors(geometry, transformation)
|
geometry = self.transform_vectors(geometry, transformation)
|
||||||
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
||||||
for c in connections:
|
for c in connections:
|
||||||
c['orientation'] = self.transform_vectors(c['orientation'], transformation, include_translation=False)
|
c["orientation"] = self.transform_vectors(
|
||||||
|
c["orientation"], transformation, include_translation=False
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': item.is_a() + '|' + str(item.id()),
|
"ifcName": item.is_a() + "|" + str(item.id()),
|
||||||
'name': item.Name,
|
"name": item.Name,
|
||||||
'id': item.GlobalId,
|
"id": item.GlobalId,
|
||||||
'geometryType': 'surface',
|
"geometryType": "surface",
|
||||||
'predefinedType': item.PredefinedType,
|
"predefinedType": item.PredefinedType,
|
||||||
'thickness': item.Thickness,
|
"thickness": item.Thickness,
|
||||||
'geometry': geometry,
|
"geometry": geometry,
|
||||||
'orientation': orientation,
|
"orientation": orientation,
|
||||||
'material': materialId,
|
"material": materialId,
|
||||||
'connections': connections
|
"connections": connections,
|
||||||
}
|
}
|
||||||
|
|
||||||
elif item.is_a('IfcStructuralPointConnection'):
|
elif item.is_a("IfcStructuralPointConnection"):
|
||||||
representation = self.get_representation(item, 'Vertex')
|
representation = self.get_representation(item, "Vertex")
|
||||||
if not representation:
|
if not representation:
|
||||||
self.warnings.append('No representation defined for %s. Connection excluded' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append(
|
||||||
|
"No representation defined for %s. Connection excluded" % (item.is_a() + "|" + str(item.id()))
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
geometry = self.get_geometry(representation)
|
geometry = self.get_geometry(representation)
|
||||||
@@ -175,20 +187,22 @@ class IFC2CA:
|
|||||||
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': item.is_a() + '|' + str(item.id()),
|
"ifcName": item.is_a() + "|" + str(item.id()),
|
||||||
'name': item.Name,
|
"name": item.Name,
|
||||||
'id': item.GlobalId,
|
"id": item.GlobalId,
|
||||||
'geometryType': 'point',
|
"geometryType": "point",
|
||||||
'geometry': geometry,
|
"geometry": geometry,
|
||||||
'orientation': orientation,
|
"orientation": orientation,
|
||||||
'appliedCondition': self.get_connection_input(item, 'point'),
|
"appliedCondition": self.get_connection_input(item, "point"),
|
||||||
'relatedElements': [con.is_a() + '|' + str(con.id()) for con in item.ConnectsStructuralMembers]
|
"relatedElements": [con.is_a() + "|" + str(con.id()) for con in item.ConnectsStructuralMembers],
|
||||||
}
|
}
|
||||||
|
|
||||||
elif item.is_a('IfcStructuralCurveConnection'):
|
elif item.is_a("IfcStructuralCurveConnection"):
|
||||||
representation = self.get_representation(item, 'Edge')
|
representation = self.get_representation(item, "Edge")
|
||||||
if not representation:
|
if not representation:
|
||||||
self.warnings.append('No representation defined for %s. Connection excluded' % (item.is_a() + '|' + str(item.id())))
|
self.warnings.append(
|
||||||
|
"No representation defined for %s. Connection excluded" % (item.is_a() + "|" + str(item.id()))
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
geometry = self.get_geometry(representation)
|
geometry = self.get_geometry(representation)
|
||||||
@@ -200,26 +214,26 @@ class IFC2CA:
|
|||||||
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
orientation = self.transform_vectors(orientation, transformation, include_translation=False)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': item.is_a() + '|' + str(item.id()),
|
"ifcName": item.is_a() + "|" + str(item.id()),
|
||||||
'name': item.Name,
|
"name": item.Name,
|
||||||
'id': item.GlobalId,
|
"id": item.GlobalId,
|
||||||
'geometryType': 'line',
|
"geometryType": "line",
|
||||||
'geometry': geometry,
|
"geometry": geometry,
|
||||||
'orientation': orientation,
|
"orientation": orientation,
|
||||||
'appliedCondition': self.get_connection_input(item, 'line'),
|
"appliedCondition": self.get_connection_input(item, "line"),
|
||||||
'relatedElements': [con.is_a() + '|' + str(con.id()) for con in item.ConnectsStructuralMembers]
|
"relatedElements": [con.is_a() + "|" + str(con.id()) for con in item.ConnectsStructuralMembers],
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_transformation(self, placement):
|
def get_transformation(self, placement):
|
||||||
if not placement:
|
if not placement:
|
||||||
return None
|
return None
|
||||||
if placement.is_a('IfcLocalPlacement'):
|
if placement.is_a("IfcLocalPlacement"):
|
||||||
if placement.PlacementRelTo:
|
if placement.PlacementRelTo:
|
||||||
print('Warning! Object Placement with PlacementRelTo attribute is not supported and will be neglected')
|
print("Warning! Object Placement with PlacementRelTo attribute is not supported and will be neglected")
|
||||||
axes = placement.RelativePlacement
|
axes = placement.RelativePlacement
|
||||||
location = np.array(self.get_coordinate(axes.Location))
|
location = np.array(self.get_coordinate(axes.Location))
|
||||||
if axes.Axis and axes.RefDirection:
|
if axes.Axis and axes.RefDirection:
|
||||||
xAxis = np.array(axes.RefDirection.DirectionRatios) # this can be not accurate (in the xz plane)
|
xAxis = np.array(axes.RefDirection.DirectionRatios) # this can be not accurate (in the xz plane)
|
||||||
zAxis = np.array(axes.Axis.DirectionRatios)
|
zAxis = np.array(axes.Axis.DirectionRatios)
|
||||||
zAxis /= np.linalg.norm(zAxis)
|
zAxis /= np.linalg.norm(zAxis)
|
||||||
yAxis = np.cross(zAxis, xAxis)
|
yAxis = np.cross(zAxis, xAxis)
|
||||||
@@ -227,29 +241,30 @@ class IFC2CA:
|
|||||||
xAxis = np.cross(yAxis, zAxis)
|
xAxis = np.cross(yAxis, zAxis)
|
||||||
xAxis /= np.linalg.norm(xAxis)
|
xAxis /= np.linalg.norm(xAxis)
|
||||||
else:
|
else:
|
||||||
if np.allclose(location, np.array([0., 0., 0.])):
|
if np.allclose(location, np.array([0.0, 0.0, 0.0])):
|
||||||
return None
|
return None
|
||||||
xAxis = np.array([1., 0., 0.])
|
xAxis = np.array([1.0, 0.0, 0.0])
|
||||||
yAxis = np.array([0., 1., 0.])
|
yAxis = np.array([0.0, 1.0, 0.0])
|
||||||
zAxis = np.array([0., 0., 1.])
|
zAxis = np.array([0.0, 0.0, 1.0])
|
||||||
if (np.allclose(location, np.array([0., 0., 0.])) and
|
if (
|
||||||
np.allclose(xAxis, np.array([1., 0., 0.])) and
|
np.allclose(location, np.array([0.0, 0.0, 0.0]))
|
||||||
np.allclose(yAxis, np.array([0., 1., 0.])) and
|
and np.allclose(xAxis, np.array([1.0, 0.0, 0.0]))
|
||||||
np.allclose(zAxis, np.array([0., 0., 1.]))):
|
and np.allclose(yAxis, np.array([0.0, 1.0, 0.0]))
|
||||||
|
and np.allclose(zAxis, np.array([0.0, 0.0, 1.0]))
|
||||||
|
):
|
||||||
return None
|
return None
|
||||||
return {
|
return {"location": location, "rotationMatrix": np.array([xAxis, yAxis, zAxis]).transpose()}
|
||||||
'location': location,
|
|
||||||
'rotationMatrix': np.array([xAxis, yAxis, zAxis]).transpose()
|
|
||||||
}
|
|
||||||
else:
|
else:
|
||||||
print('Warning! Object Placement is of type %s, which is not supported. Default considered' % placement.is_a())
|
print(
|
||||||
|
"Warning! Object Placement is of type %s, which is not supported. Default considered" % placement.is_a()
|
||||||
|
)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_representation(self, element, rep_type):
|
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', rep_type)
|
rep = self.get_specific_representation(representation, "Reference", rep_type)
|
||||||
if rep:
|
if rep:
|
||||||
return rep
|
return rep
|
||||||
else:
|
else:
|
||||||
@@ -260,42 +275,45 @@ class IFC2CA:
|
|||||||
return 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 or rep_id is None) \
|
if (
|
||||||
and representation.RepresentationType == rep_type:
|
representation.RepresentationIdentifier == rep_id or rep_id is None
|
||||||
|
) and representation.RepresentationType == rep_type:
|
||||||
return representation
|
return representation
|
||||||
if representation.RepresentationType == 'MappedRepresentation':
|
if representation.RepresentationType == "MappedRepresentation":
|
||||||
return self.get_specific_representation(
|
return self.get_specific_representation(
|
||||||
representation.Items[0].MappingSource.MappedRepresentation,
|
representation.Items[0].MappingSource.MappedRepresentation, rep_id, rep_type
|
||||||
rep_id, rep_type)
|
)
|
||||||
|
|
||||||
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
|
||||||
# can do without it.
|
# can do without it.
|
||||||
item = representation.Items[0]
|
item = representation.Items[0]
|
||||||
if item.is_a('IfcEdge'):
|
if item.is_a("IfcEdge"):
|
||||||
return [
|
return [
|
||||||
self.get_coordinate(item.EdgeStart.VertexGeometry),
|
self.get_coordinate(item.EdgeStart.VertexGeometry),
|
||||||
self.get_coordinate(item.EdgeEnd.VertexGeometry)
|
self.get_coordinate(item.EdgeEnd.VertexGeometry),
|
||||||
]
|
]
|
||||||
|
|
||||||
elif item.is_a('IfcFaceSurface'):
|
elif item.is_a("IfcFaceSurface"):
|
||||||
edges = item.Bounds[0].Bound.EdgeList
|
edges = item.Bounds[0].Bound.EdgeList
|
||||||
coords = []
|
coords = []
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
coords.append(self.get_coordinate(edge.EdgeElement.EdgeStart.VertexGeometry))
|
coords.append(self.get_coordinate(edge.EdgeElement.EdgeStart.VertexGeometry))
|
||||||
return coords
|
return coords
|
||||||
|
|
||||||
elif item.is_a('IfcVertexPoint'):
|
elif item.is_a("IfcVertexPoint"):
|
||||||
return self.get_coordinate(item.VertexGeometry)
|
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 list(point.Coordinates)
|
return list(point.Coordinates)
|
||||||
|
|
||||||
def get_0D_orientation(self, axes):
|
def get_0D_orientation(self, axes):
|
||||||
if axes and axes.Axis and axes.RefDirection:
|
if axes and axes.Axis and axes.RefDirection:
|
||||||
xAxis = np.array(axes.RefDirection.DirectionRatios) # this can be not strictly perpendicular (in the xz plane)
|
xAxis = np.array(
|
||||||
|
axes.RefDirection.DirectionRatios
|
||||||
|
) # this can be not strictly perpendicular (in the xz plane)
|
||||||
zAxis = np.array(axes.Axis.DirectionRatios)
|
zAxis = np.array(axes.Axis.DirectionRatios)
|
||||||
zAxis /= np.linalg.norm(zAxis)
|
zAxis /= np.linalg.norm(zAxis)
|
||||||
yAxis = np.cross(zAxis, xAxis)
|
yAxis = np.cross(zAxis, xAxis)
|
||||||
@@ -304,13 +322,13 @@ class IFC2CA:
|
|||||||
xAxis /= np.linalg.norm(xAxis)
|
xAxis /= np.linalg.norm(xAxis)
|
||||||
|
|
||||||
return [xAxis.tolist(), yAxis.tolist(), zAxis.tolist()]
|
return [xAxis.tolist(), yAxis.tolist(), zAxis.tolist()]
|
||||||
else: # return None and copy the elements orientation
|
else: # return None and copy the elements orientation
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_1D_orientation(self, geometry, zAxis):
|
def get_1D_orientation(self, geometry, zAxis):
|
||||||
xAxis = np.array(geometry[1]) - np.array(geometry[0])
|
xAxis = np.array(geometry[1]) - np.array(geometry[0])
|
||||||
xAxis /= np.linalg.norm(xAxis)
|
xAxis /= np.linalg.norm(xAxis)
|
||||||
zAxis = np.array(zAxis.DirectionRatios) # this can be not strictly perpendicular (in the xz plane)
|
zAxis = np.array(zAxis.DirectionRatios) # this can be not strictly perpendicular (in the xz plane)
|
||||||
yAxis = np.cross(zAxis, xAxis)
|
yAxis = np.cross(zAxis, xAxis)
|
||||||
yAxis /= np.linalg.norm(yAxis)
|
yAxis /= np.linalg.norm(yAxis)
|
||||||
zAxis = np.cross(xAxis, yAxis)
|
zAxis = np.cross(xAxis, yAxis)
|
||||||
@@ -320,7 +338,7 @@ class IFC2CA:
|
|||||||
|
|
||||||
def get_2D_orientation(self, representation):
|
def get_2D_orientation(self, representation):
|
||||||
item = representation.Items[0]
|
item = representation.Items[0]
|
||||||
if item.is_a('IfcFaceSurface'):
|
if item.is_a("IfcFaceSurface"):
|
||||||
item.SameSense
|
item.SameSense
|
||||||
axes = item.FaceSurface.Position
|
axes = item.FaceSurface.Position
|
||||||
orientation = self.get_0D_orientation(axes)
|
orientation = self.get_0D_orientation(axes)
|
||||||
@@ -329,17 +347,17 @@ class IFC2CA:
|
|||||||
return orientation
|
return orientation
|
||||||
|
|
||||||
def transform_vectors(self, geometry, trsf, include_translation=True):
|
def transform_vectors(self, geometry, trsf, include_translation=True):
|
||||||
if not any(isinstance(el, list) for el in geometry): # single point which contains no list
|
if not any(isinstance(el, list) for el in geometry): # single point which contains no list
|
||||||
geometry = [geometry]
|
geometry = [geometry]
|
||||||
globalGeometry = []
|
globalGeometry = []
|
||||||
|
|
||||||
for p in geometry:
|
for p in geometry:
|
||||||
gp = trsf['rotationMatrix'].dot(np.array(p))
|
gp = trsf["rotationMatrix"].dot(np.array(p))
|
||||||
if include_translation:
|
if include_translation:
|
||||||
gp += trsf['location']
|
gp += trsf["location"]
|
||||||
globalGeometry.append(gp.tolist())
|
globalGeometry.append(gp.tolist())
|
||||||
|
|
||||||
if len(globalGeometry) == 1: # single point
|
if len(globalGeometry) == 1: # single point
|
||||||
globalGeometry = globalGeometry[0]
|
globalGeometry = globalGeometry[0]
|
||||||
|
|
||||||
return globalGeometry
|
return globalGeometry
|
||||||
@@ -348,36 +366,36 @@ class IFC2CA:
|
|||||||
if not element.HasAssociations:
|
if not element.HasAssociations:
|
||||||
return None
|
return None
|
||||||
for association in element.HasAssociations:
|
for association in element.HasAssociations:
|
||||||
if not association.is_a('IfcRelAssociatesMaterial'):
|
if not association.is_a("IfcRelAssociatesMaterial"):
|
||||||
continue
|
continue
|
||||||
material = association.RelatingMaterial
|
material = association.RelatingMaterial
|
||||||
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'):
|
if material.is_a("IfcMaterialProfileSetUsage"):
|
||||||
return material.ForProfileSet.MaterialProfiles[0]
|
return material.ForProfileSet.MaterialProfiles[0]
|
||||||
if material.is_a('IfcMaterial'):
|
if material.is_a("IfcMaterial"):
|
||||||
return material
|
return material
|
||||||
|
|
||||||
def get_material_properties(self, material):
|
def get_material_properties(self, material):
|
||||||
psets = material.HasProperties
|
psets = material.HasProperties
|
||||||
|
|
||||||
if self.get_pset_properties(psets, 'Pset_MaterialMechanical'):
|
if self.get_pset_properties(psets, "Pset_MaterialMechanical"):
|
||||||
mechProps = self.get_pset_properties(psets, 'Pset_MaterialMechanical')
|
mechProps = self.get_pset_properties(psets, "Pset_MaterialMechanical")
|
||||||
else:
|
else:
|
||||||
mechProps = self.get_pset_properties(psets, None)
|
mechProps = self.get_pset_properties(psets, None)
|
||||||
|
|
||||||
if self.get_pset_properties(psets, 'Pset_MaterialCommon'):
|
if self.get_pset_properties(psets, "Pset_MaterialCommon"):
|
||||||
commonProps = self.get_pset_properties(psets, 'Pset_MaterialCommon')
|
commonProps = self.get_pset_properties(psets, "Pset_MaterialCommon")
|
||||||
else:
|
else:
|
||||||
commonProps = self.get_pset_properties(psets, None)
|
commonProps = self.get_pset_properties(psets, None)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': material.is_a() + '|' + str(material.id()),
|
"ifcName": material.is_a() + "|" + str(material.id()),
|
||||||
'name': material.Name,
|
"name": material.Name,
|
||||||
'category': material.Category,
|
"category": material.Category,
|
||||||
'mechProps': mechProps,
|
"mechProps": mechProps,
|
||||||
'commonProps':commonProps
|
"commonProps": commonProps,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_pset_property(self, psets, pset_name, prop_name):
|
def get_pset_property(self, psets, pset_name, prop_name):
|
||||||
@@ -397,98 +415,113 @@ class IFC2CA:
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def get_profile_properties(self, profile):
|
def get_profile_properties(self, profile):
|
||||||
if profile.is_a('IfcRectangleProfileDef'):
|
if profile.is_a("IfcRectangleProfileDef"):
|
||||||
return {
|
return {
|
||||||
'ifcName': profile.is_a() + '|' + str(profile.id()),
|
"ifcName": profile.is_a() + "|" + str(profile.id()),
|
||||||
'profileName': profile.ProfileName,
|
"profileName": profile.ProfileName,
|
||||||
'profileType': profile.ProfileType,
|
"profileType": profile.ProfileType,
|
||||||
'profileShape': 'rectangular',
|
"profileShape": "rectangular",
|
||||||
'xDim': profile.XDim,
|
"xDim": profile.XDim,
|
||||||
'yDim': profile.YDim
|
"yDim": profile.YDim,
|
||||||
}
|
}
|
||||||
|
|
||||||
if profile.is_a('IfcIShapeProfileDef'):
|
if profile.is_a("IfcIShapeProfileDef"):
|
||||||
psets = profile.HasProperties
|
psets = profile.HasProperties
|
||||||
|
|
||||||
if self.get_pset_properties(psets, 'Pset_ProfileMechanical'):
|
if self.get_pset_properties(psets, "Pset_ProfileMechanical"):
|
||||||
mechProps = self.get_pset_properties(psets, 'Pset_ProfileMechanical')
|
mechProps = self.get_pset_properties(psets, "Pset_ProfileMechanical")
|
||||||
else:
|
else:
|
||||||
mechProps = self.get_i_section_properties(profile, 'iSymmetrical')
|
mechProps = self.get_i_section_properties(profile, "iSymmetrical")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'ifcName': profile.is_a() + '|' + str(profile.id()),
|
"ifcName": profile.is_a() + "|" + str(profile.id()),
|
||||||
'profileName': profile.ProfileName,
|
"profileName": profile.ProfileName,
|
||||||
'profileType': profile.ProfileType,
|
"profileType": profile.ProfileType,
|
||||||
'profileShape': 'iSymmetrical',
|
"profileShape": "iSymmetrical",
|
||||||
'mechProps': mechProps,
|
"mechProps": mechProps,
|
||||||
'commonProps': {
|
"commonProps": {
|
||||||
'flangeThickness': profile.FlangeThickness,
|
"flangeThickness": profile.FlangeThickness,
|
||||||
'webThickness': profile.WebThickness,
|
"webThickness": profile.WebThickness,
|
||||||
'overallDepth': profile.OverallDepth,
|
"overallDepth": profile.OverallDepth,
|
||||||
'overallWidth': profile.OverallWidth,
|
"overallWidth": profile.OverallWidth,
|
||||||
'filletRadius': profile.FilletRadius,
|
"filletRadius": profile.FilletRadius,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_connection_data(self, itemList):
|
def get_connection_data(self, itemList):
|
||||||
return [{
|
return [
|
||||||
'ifcName': rel.is_a() + '|' + str(rel.id()),
|
{
|
||||||
'id': rel.GlobalId,
|
"ifcName": rel.is_a() + "|" + str(rel.id()),
|
||||||
'relatingElement': rel.RelatingStructuralMember.is_a() + '|' + str(rel.RelatingStructuralMember.id()),
|
"id": rel.GlobalId,
|
||||||
'relatedConnection': rel.RelatedStructuralConnection.is_a() + '|' + str(rel.RelatedStructuralConnection.id()),
|
"relatingElement": rel.RelatingStructuralMember.is_a() + "|" + str(rel.RelatingStructuralMember.id()),
|
||||||
'orientation': self.get_0D_orientation(rel.ConditionCoordinateSystem),
|
"relatedConnection": rel.RelatedStructuralConnection.is_a()
|
||||||
'appliedCondition': self.get_connection_input(rel, self.get_geometry_type_from_connection(rel.RelatedStructuralConnection)),
|
+ "|"
|
||||||
'eccentricity': None if not rel.is_a('IfcRelConnectsWithEccentricity') else {
|
+ str(rel.RelatedStructuralConnection.id()),
|
||||||
'vector': [
|
"orientation": self.get_0D_orientation(rel.ConditionCoordinateSystem),
|
||||||
0.0 if not rel.ConnectionConstraint.EccentricityInX else rel.ConnectionConstraint.EccentricityInX,
|
"appliedCondition": self.get_connection_input(
|
||||||
0.0 if not rel.ConnectionConstraint.EccentricityInY else rel.ConnectionConstraint.EccentricityInY,
|
rel, self.get_geometry_type_from_connection(rel.RelatedStructuralConnection)
|
||||||
0.0 if not rel.ConnectionConstraint.EccentricityInZ else rel.ConnectionConstraint.EccentricityInZ
|
),
|
||||||
|
"eccentricity": None
|
||||||
|
if not rel.is_a("IfcRelConnectsWithEccentricity")
|
||||||
|
else {
|
||||||
|
"vector": [
|
||||||
|
0.0
|
||||||
|
if not rel.ConnectionConstraint.EccentricityInX
|
||||||
|
else rel.ConnectionConstraint.EccentricityInX,
|
||||||
|
0.0
|
||||||
|
if not rel.ConnectionConstraint.EccentricityInY
|
||||||
|
else rel.ConnectionConstraint.EccentricityInY,
|
||||||
|
0.0
|
||||||
|
if not rel.ConnectionConstraint.EccentricityInZ
|
||||||
|
else rel.ConnectionConstraint.EccentricityInZ,
|
||||||
],
|
],
|
||||||
'pointOnElement': self.get_coordinate(rel.ConnectionConstraint.PointOnRelatingElement)
|
"pointOnElement": self.get_coordinate(rel.ConnectionConstraint.PointOnRelatingElement),
|
||||||
}
|
},
|
||||||
} for rel in itemList]
|
}
|
||||||
|
for rel in itemList
|
||||||
|
]
|
||||||
|
|
||||||
def get_geometry_type_from_connection(self, connection):
|
def get_geometry_type_from_connection(self, connection):
|
||||||
if connection.is_a('IfcStructuralPointConnection'):
|
if connection.is_a("IfcStructuralPointConnection"):
|
||||||
return 'point'
|
return "point"
|
||||||
if connection.is_a('IfcStructuralCurveConnection'):
|
if connection.is_a("IfcStructuralCurveConnection"):
|
||||||
return 'line'
|
return "line"
|
||||||
if connection.is_a('IfcStructuralSurfaceConnection'):
|
if connection.is_a("IfcStructuralSurfaceConnection"):
|
||||||
return 'surface'
|
return "surface"
|
||||||
|
|
||||||
def get_connection_input(self, connection, geometryType):
|
def get_connection_input(self, connection, geometryType):
|
||||||
if connection.AppliedCondition:
|
if connection.AppliedCondition:
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
return {
|
return {
|
||||||
'dx': connection.AppliedCondition.TranslationalStiffnessX.wrappedValue,
|
"dx": connection.AppliedCondition.TranslationalStiffnessX.wrappedValue,
|
||||||
'dy': connection.AppliedCondition.TranslationalStiffnessY.wrappedValue,
|
"dy": connection.AppliedCondition.TranslationalStiffnessY.wrappedValue,
|
||||||
'dz': connection.AppliedCondition.TranslationalStiffnessZ.wrappedValue,
|
"dz": connection.AppliedCondition.TranslationalStiffnessZ.wrappedValue,
|
||||||
'drx': connection.AppliedCondition.RotationalStiffnessX.wrappedValue,
|
"drx": connection.AppliedCondition.RotationalStiffnessX.wrappedValue,
|
||||||
'dry': connection.AppliedCondition.RotationalStiffnessY.wrappedValue,
|
"dry": connection.AppliedCondition.RotationalStiffnessY.wrappedValue,
|
||||||
'drz': connection.AppliedCondition.RotationalStiffnessZ.wrappedValue
|
"drz": connection.AppliedCondition.RotationalStiffnessZ.wrappedValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
if geometryType == 'line':
|
if geometryType == "line":
|
||||||
return {
|
return {
|
||||||
'dx': connection.AppliedCondition.TranslationalStiffnessByLengthX.wrappedValue,
|
"dx": connection.AppliedCondition.TranslationalStiffnessByLengthX.wrappedValue,
|
||||||
'dy': connection.AppliedCondition.TranslationalStiffnessByLengthY.wrappedValue,
|
"dy": connection.AppliedCondition.TranslationalStiffnessByLengthY.wrappedValue,
|
||||||
'dz': connection.AppliedCondition.TranslationalStiffnessByLengthZ.wrappedValue,
|
"dz": connection.AppliedCondition.TranslationalStiffnessByLengthZ.wrappedValue,
|
||||||
'drx': connection.AppliedCondition.RotationalStiffnessByLengthX.wrappedValue,
|
"drx": connection.AppliedCondition.RotationalStiffnessByLengthX.wrappedValue,
|
||||||
'dry': connection.AppliedCondition.RotationalStiffnessByLengthY.wrappedValue,
|
"dry": connection.AppliedCondition.RotationalStiffnessByLengthY.wrappedValue,
|
||||||
'drz': connection.AppliedCondition.RotationalStiffnessByLengthZ.wrappedValue
|
"drz": connection.AppliedCondition.RotationalStiffnessByLengthZ.wrappedValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
if geometryType == 'surface':
|
if geometryType == "surface":
|
||||||
return {
|
return {
|
||||||
'dx': connection.AppliedCondition.TranslationalStiffnessByAreaX.wrappedValue,
|
"dx": connection.AppliedCondition.TranslationalStiffnessByAreaX.wrappedValue,
|
||||||
'dy': connection.AppliedCondition.TranslationalStiffnessByAreaY.wrappedValue,
|
"dy": connection.AppliedCondition.TranslationalStiffnessByAreaY.wrappedValue,
|
||||||
'dz': connection.AppliedCondition.TranslationalStiffnessByAreaZ.wrappedValue
|
"dz": connection.AppliedCondition.TranslationalStiffnessByAreaZ.wrappedValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection.AppliedCondition
|
return connection.AppliedCondition
|
||||||
|
|
||||||
def get_i_section_properties(self, profile, profileShape):
|
def get_i_section_properties(self, profile, profileShape):
|
||||||
if profileShape == 'iSymmetrical':
|
if profileShape == "iSymmetrical":
|
||||||
tf = profile.FlangeThickness
|
tf = profile.FlangeThickness
|
||||||
tw = profile.WebThickness
|
tw = profile.WebThickness
|
||||||
h = profile.OverallDepth
|
h = profile.OverallDepth
|
||||||
@@ -499,20 +532,16 @@ class IFC2CA:
|
|||||||
Iz = (2 * tf) * (b ** 3) / 12 + (h - 2 * tf) * (tw ** 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))
|
Jx = 1 / 3 * ((h - tf) * (tw ** 3) + 2 * b * (tf ** 3))
|
||||||
|
|
||||||
return {
|
return {"crossSectionArea": A, "momentOfInertiaY": Iy, "momentOfInertiaZ": Iz, "torsionalConstantX": Jx}
|
||||||
'crossSectionArea': A,
|
|
||||||
'momentOfInertiaY': Iy,
|
|
||||||
'momentOfInertiaZ': Iz,
|
|
||||||
'torsionalConstantX': Jx
|
|
||||||
}
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
fileNames = ['cantilever_01', 'portal_01', 'grid_of_beams', 'slab_01', 'structure_01']
|
if __name__ == "__main__":
|
||||||
|
fileNames = ["cantilever_01", "portal_01", "grid_of_beams", "slab_01", "structure_01"]
|
||||||
files = fileNames
|
files = fileNames
|
||||||
|
|
||||||
for fileName in files:
|
for fileName in files:
|
||||||
BASE_PATH = '/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/ifcFiles/'
|
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/ifcFiles/"
|
||||||
ifc2ca = IFC2CA(BASE_PATH + fileName + '.ifc')
|
ifc2ca = IFC2CA(BASE_PATH + fileName + ".ifc")
|
||||||
ifc2ca.convert()
|
ifc2ca.convert()
|
||||||
with open(BASE_PATH + fileName + '.json', 'w') as f:
|
with open(BASE_PATH + fileName + ".json", "w") as f:
|
||||||
f.write(json.dumps(ifc2ca.result, indent = 4))
|
f.write(json.dumps(ifc2ca.result, indent=4))
|
||||||
|
|||||||
+340
-388
File diff suppressed because it is too large
Load Diff
+222
-167
@@ -11,6 +11,7 @@ import itertools
|
|||||||
|
|
||||||
flatten = itertools.chain.from_iterable
|
flatten = itertools.chain.from_iterable
|
||||||
|
|
||||||
|
|
||||||
class MODEL:
|
class MODEL:
|
||||||
def __init__(self, dataFilename, medFilename, meshSize):
|
def __init__(self, dataFilename, medFilename, meshSize):
|
||||||
self.dataFilename = dataFilename
|
self.dataFilename = dataFilename
|
||||||
@@ -22,20 +23,20 @@ class MODEL:
|
|||||||
self.create()
|
self.create()
|
||||||
|
|
||||||
def getGroupName(self, name):
|
def getGroupName(self, name):
|
||||||
info = name.split('|')
|
info = name.split("|")
|
||||||
sortName = ''.join(c for c in info[0] if c.isupper())
|
sortName = "".join(c for c in info[0] if c.isupper())
|
||||||
return str(sortName + '_' + info[1])
|
return str(sortName + "_" + info[1])
|
||||||
|
|
||||||
def makePoint(self, pl):
|
def makePoint(self, pl):
|
||||||
'''Function to define a Point from
|
"""Function to define a Point from
|
||||||
a polyline (list of 1 point)'''
|
a polyline (list of 1 point)"""
|
||||||
|
|
||||||
(x, y, z) = pl
|
(x, y, z) = pl
|
||||||
return self.geompy.MakeVertex(x, y, z)
|
return self.geompy.MakeVertex(x, y, z)
|
||||||
|
|
||||||
def makeLine(self, pl):
|
def makeLine(self, pl):
|
||||||
'''Function to define a Line from
|
"""Function to define a Line from
|
||||||
a polyline (list of 2 points)'''
|
a polyline (list of 2 points)"""
|
||||||
|
|
||||||
(x, y, z) = pl[0]
|
(x, y, z) = pl[0]
|
||||||
P1 = self.geompy.MakeVertex(x, y, z)
|
P1 = self.geompy.MakeVertex(x, y, z)
|
||||||
@@ -45,8 +46,8 @@ class MODEL:
|
|||||||
return self.geompy.MakeLineTwoPnt(P1, P2)
|
return self.geompy.MakeLineTwoPnt(P1, P2)
|
||||||
|
|
||||||
def makeFace(self, pl):
|
def makeFace(self, pl):
|
||||||
'''Function to define a Face from
|
"""Function to define a Face from
|
||||||
a polyline (list of points)'''
|
a polyline (list of points)"""
|
||||||
|
|
||||||
pointList = [None for _ in range(len(pl))]
|
pointList = [None for _ in range(len(pl))]
|
||||||
for ip, (x, y, z) in enumerate(pl):
|
for ip, (x, y, z) in enumerate(pl):
|
||||||
@@ -60,53 +61,53 @@ class MODEL:
|
|||||||
return self.geompy.MakeFaceWires(LineList, 1)
|
return self.geompy.MakeFaceWires(LineList, 1)
|
||||||
|
|
||||||
def makeObject(self, geometry, geometryType):
|
def makeObject(self, geometry, geometryType):
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
return self.makePoint(geometry)
|
return self.makePoint(geometry)
|
||||||
if geometryType == 'line':
|
if geometryType == "line":
|
||||||
return self.makeLine(geometry)
|
return self.makeLine(geometry)
|
||||||
if geometryType == 'surface':
|
if geometryType == "surface":
|
||||||
return self.makeFace(geometry)
|
return self.makeFace(geometry)
|
||||||
|
|
||||||
def makePartition(self, objects, geometryType):
|
def makePartition(self, objects, geometryType):
|
||||||
if geometryType == 'point':
|
if geometryType == "point":
|
||||||
shapeType = 'VERTEX'
|
shapeType = "VERTEX"
|
||||||
if geometryType == 'line':
|
if geometryType == "line":
|
||||||
shapeType = 'EDGE'
|
shapeType = "EDGE"
|
||||||
if geometryType == 'surface':
|
if geometryType == "surface":
|
||||||
shapeType = 'FACE'
|
shapeType = "FACE"
|
||||||
return self.geompy.MakePartition(objects, [], [], [], self.geompy.ShapeType[shapeType], 0, [], 1)
|
return self.geompy.MakePartition(objects, [], [], [], self.geompy.ShapeType[shapeType], 0, [], 1)
|
||||||
|
|
||||||
def getLinkGeometry(self, ecc, orientation, finalPoint):
|
def getLinkGeometry(self, ecc, orientation, finalPoint):
|
||||||
vector = np.array(orientation).transpose().dot(ecc['vector'])
|
vector = np.array(orientation).transpose().dot(ecc["vector"])
|
||||||
initialPoint = (np.array(finalPoint) - vector).tolist()
|
initialPoint = (np.array(finalPoint) - vector).tolist()
|
||||||
return [initialPoint, finalPoint]
|
return [initialPoint, finalPoint]
|
||||||
|
|
||||||
def length(self, geometry):
|
def length(self, geometry):
|
||||||
return ((
|
return (
|
||||||
(geometry[1][0] - geometry[0][0]) ** 2 + \
|
(geometry[1][0] - geometry[0][0]) ** 2
|
||||||
(geometry[1][1] - geometry[0][1]) ** 2 + \
|
+ (geometry[1][1] - geometry[0][1]) ** 2
|
||||||
(geometry[1][2] - geometry[0][2]) ** 2 \
|
+ (geometry[1][2] - geometry[0][2]) ** 2
|
||||||
) ** 0.5)
|
) ** 0.5
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
# Read data from input file
|
# Read data from input file
|
||||||
with open(self.dataFilename) as dataFile:
|
with open(self.dataFilename) as dataFile:
|
||||||
data = json.load(dataFile)
|
data = json.load(dataFile)
|
||||||
|
|
||||||
elements = data['elements']
|
elements = data["elements"]
|
||||||
connections = data['connections']
|
connections = data["connections"]
|
||||||
# --> Delete this reference data and repopulate it with the objects
|
# --> Delete this reference data and repopulate it with the objects
|
||||||
# while going through elements
|
# while going through elements
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
conn['relatedElements'] = []
|
conn["relatedElements"] = []
|
||||||
# End <--
|
# End <--
|
||||||
|
|
||||||
meshSize = self.meshSize
|
meshSize = self.meshSize
|
||||||
|
|
||||||
dec = 7 # 4 decimals for length in mm
|
dec = 7 # 4 decimals for length in mm
|
||||||
tol = 10**(-dec-3+1)
|
tol = 10 ** (-dec - 3 + 1)
|
||||||
|
|
||||||
self.tolLoc = tol*10*2
|
self.tolLoc = tol * 10 * 2
|
||||||
tolLoc = self.tolLoc
|
tolLoc = self.tolLoc
|
||||||
|
|
||||||
NEW_SALOME = int(salome_version.getVersion()[0]) >= 9
|
NEW_SALOME = int(salome_version.getVersion()[0]) >= 9
|
||||||
@@ -122,7 +123,7 @@ class MODEL:
|
|||||||
import math
|
import math
|
||||||
import SALOMEDS
|
import SALOMEDS
|
||||||
|
|
||||||
gg = salome.ImportComponentGUI('GEOM')
|
gg = salome.ImportComponentGUI("GEOM")
|
||||||
if NEW_SALOME:
|
if NEW_SALOME:
|
||||||
geompy = geomBuilder.New()
|
geompy = geomBuilder.New()
|
||||||
else:
|
else:
|
||||||
@@ -133,81 +134,91 @@ class MODEL:
|
|||||||
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
|
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
|
||||||
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
|
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
|
||||||
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
|
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
|
||||||
geompy.addToStudy( O, 'O' )
|
geompy.addToStudy(O, "O")
|
||||||
geompy.addToStudy( OX, 'OX' )
|
geompy.addToStudy(OX, "OX")
|
||||||
geompy.addToStudy( OY, 'OY' )
|
geompy.addToStudy(OY, "OY")
|
||||||
geompy.addToStudy( OZ, 'OZ' )
|
geompy.addToStudy(OZ, "OZ")
|
||||||
|
|
||||||
if len([e for e in elements if e['geometryType'] == 'line']) > 0:
|
if len([e for e in elements if e["geometryType"] == "line"]) > 0:
|
||||||
buildingShapeType = 'EDGE'
|
buildingShapeType = "EDGE"
|
||||||
if len([e for e in elements if e['geometryType'] == 'surface']) > 0:
|
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
|
||||||
buildingShapeType = 'FACE'
|
buildingShapeType = "FACE"
|
||||||
|
|
||||||
### Define entities ###
|
### Define entities ###
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
print('Defining Object Geometry')
|
print("Defining Object Geometry")
|
||||||
init_time = start_time
|
init_time = start_time
|
||||||
|
|
||||||
# Loop 1
|
# Loop 1
|
||||||
for el in elements:
|
for el in elements:
|
||||||
el['elemObj'] = self.makeObject(el['geometry'], el['geometryType'])
|
el["elemObj"] = self.makeObject(el["geometry"], el["geometryType"])
|
||||||
|
|
||||||
el['connObjs'] = [None for _ in el['connections']]
|
el["connObjs"] = [None for _ in el["connections"]]
|
||||||
el['linkObjs'] = [None for _ in el['connections']]
|
el["linkObjs"] = [None for _ in el["connections"]]
|
||||||
el['linkPointObjs'] = [[None, None] for _ in el['connections']]
|
el["linkPointObjs"] = [[None, None] for _ in el["connections"]]
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
conn = [c for c in connections if c['ifcName'] == rel['relatedConnection']][0]
|
conn = [c for c in connections if c["ifcName"] == rel["relatedConnection"]][0]
|
||||||
if rel['eccentricity']:
|
if rel["eccentricity"]:
|
||||||
rel['index'] = len(conn['relatedElements']) + 1
|
rel["index"] = len(conn["relatedElements"]) + 1
|
||||||
conn['relatedElements'].append(rel)
|
conn["relatedElements"].append(rel)
|
||||||
|
|
||||||
if not rel['eccentricity']:
|
if not rel["eccentricity"]:
|
||||||
el['connObjs'][j] = self.makeObject(conn['geometry'], conn['geometryType'])
|
el["connObjs"][j] = self.makeObject(conn["geometry"], conn["geometryType"])
|
||||||
else:
|
else:
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
geometry = self.getLinkGeometry(rel['eccentricity'], el['orientation'], conn['geometry'])
|
geometry = self.getLinkGeometry(rel["eccentricity"], el["orientation"], conn["geometry"])
|
||||||
el['connObjs'][j] = self.makeObject(geometry[0], conn['geometryType'])
|
el["connObjs"][j] = self.makeObject(geometry[0], conn["geometryType"])
|
||||||
|
|
||||||
el['linkPointObjs'][j][0] = self.geompy.MakeVertex(geometry[0][0], geometry[0][1], geometry[0][2])
|
el["linkPointObjs"][j][0] = self.geompy.MakeVertex(
|
||||||
el['linkPointObjs'][j][1] = self.geompy.MakeVertex(geometry[1][0], geometry[1][1], geometry[1][2])
|
geometry[0][0], geometry[0][1], geometry[0][2]
|
||||||
el['linkObjs'][j] = self.geompy.MakeLineTwoPnt(el['linkPointObjs'][j][0], el['linkPointObjs'][j][1])
|
)
|
||||||
|
el["linkPointObjs"][j][1] = self.geompy.MakeVertex(
|
||||||
|
geometry[1][0], geometry[1][1], geometry[1][2]
|
||||||
|
)
|
||||||
|
el["linkObjs"][j] = self.geompy.MakeLineTwoPnt(
|
||||||
|
el["linkPointObjs"][j][0], el["linkPointObjs"][j][1]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print('Eccentricity defined for a %s geometryType' %conn['geometryType'])
|
print("Eccentricity defined for a %s geometryType" % conn["geometryType"])
|
||||||
|
|
||||||
el['partObj'] = self.makePartition([el['elemObj']] + el['connObjs'], el['geometryType'])
|
el["partObj"] = self.makePartition([el["elemObj"]] + el["connObjs"], el["geometryType"])
|
||||||
|
|
||||||
el['elemObj'] = geompy.GetInPlace(el['partObj'], el['elemObj'])
|
el["elemObj"] = geompy.GetInPlace(el["partObj"], el["elemObj"])
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
el['connObjs'][j] = geompy.GetInPlace(el['partObj'], el['connObjs'][j])
|
el["connObjs"][j] = geompy.GetInPlace(el["partObj"], el["connObjs"][j])
|
||||||
|
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
conn['connObj'] = self.makeObject(conn['geometry'], conn['geometryType'])
|
conn["connObj"] = self.makeObject(conn["geometry"], conn["geometryType"])
|
||||||
|
|
||||||
# Make assemble of Building Object
|
# Make assemble of Building Object
|
||||||
bldObjs = []
|
bldObjs = []
|
||||||
bldObjs.extend([el['partObj'] for el in elements])
|
bldObjs.extend([el["partObj"] for el in elements])
|
||||||
bldObjs.extend(flatten([[link for link in el['linkObjs'] if link] for el in elements]))
|
bldObjs.extend(flatten([[link for link in el["linkObjs"] if link] for el in elements]))
|
||||||
bldObjs.extend([conn['connObj'] for conn in connections])
|
bldObjs.extend([conn["connObj"] for conn in connections])
|
||||||
|
|
||||||
bldComp = geompy.MakeCompound(bldObjs)
|
bldComp = geompy.MakeCompound(bldObjs)
|
||||||
# bldComp = geompy.MakePartition(bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1)
|
# bldComp = geompy.MakePartition(bldObjs, [], [], [], self.geompy.ShapeType[buildingShapeType], 0, [], 1)
|
||||||
geompy.addToStudy(bldComp, 'bldComp')
|
geompy.addToStudy(bldComp, "bldComp")
|
||||||
|
|
||||||
# Loop 2
|
# Loop 2
|
||||||
for el in elements:
|
for el in elements:
|
||||||
# geompy.addToStudy(el['partObj'], self.getGroupName(el['ifcName']))
|
# geompy.addToStudy(el['partObj'], self.getGroupName(el['ifcName']))
|
||||||
geompy.addToStudyInFather(el['partObj'], el['elemObj'], self.getGroupName(el['ifcName']))
|
geompy.addToStudyInFather(el["partObj"], el["elemObj"], self.getGroupName(el["ifcName"]))
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
conn = [c for c in connections if c['ifcName'] == rel['relatedConnection']][0]
|
conn = [c for c in connections if c["ifcName"] == rel["relatedConnection"]][0]
|
||||||
rel['conn_string'] = None
|
rel["conn_string"] = None
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
rel['conn_string'] = '_0DC_'
|
rel["conn_string"] = "_0DC_"
|
||||||
if conn['geometryType'] == 'line':
|
if conn["geometryType"] == "line":
|
||||||
rel['conn_string'] = '_1DC_'
|
rel["conn_string"] = "_1DC_"
|
||||||
if conn['geometryType'] == 'surface':
|
if conn["geometryType"] == "surface":
|
||||||
rel['conn_string'] = '_2DC_'
|
rel["conn_string"] = "_2DC_"
|
||||||
geompy.addToStudyInFather(el['partObj'], el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection']))
|
geompy.addToStudyInFather(
|
||||||
if rel['eccentricity']:
|
el["partObj"],
|
||||||
|
el["connObjs"][j],
|
||||||
|
self.getGroupName(el["ifcName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
)
|
||||||
|
if rel["eccentricity"]:
|
||||||
pass
|
pass
|
||||||
# geompy.addToStudy(el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']))
|
# geompy.addToStudy(el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']))
|
||||||
# geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']))
|
# geompy.addToStudyInFather(el['linkObjs'][j], el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']))
|
||||||
@@ -215,51 +226,67 @@ class MODEL:
|
|||||||
|
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
# geompy.addToStudy(conn['connObj'], self.getGroupName(conn['ifcName']))
|
# geompy.addToStudy(conn['connObj'], self.getGroupName(conn['ifcName']))
|
||||||
geompy.addToStudyInFather(conn['connObj'], conn['connObj'], self.getGroupName(conn['ifcName']))
|
geompy.addToStudyInFather(conn["connObj"], conn["connObj"], self.getGroupName(conn["ifcName"]))
|
||||||
|
|
||||||
elapsed_time = time.time() - init_time
|
elapsed_time = time.time() - init_time
|
||||||
init_time += elapsed_time
|
init_time += elapsed_time
|
||||||
print('Building Geometry Defined in %g sec' % (elapsed_time))
|
print("Building Geometry Defined in %g sec" % (elapsed_time))
|
||||||
|
|
||||||
if len([e for e in elements if e['geometryType'] == 'line']) > 0:
|
if len([e for e in elements if e["geometryType"] == "line"]) > 0:
|
||||||
buildingShapeType = 'EDGE'
|
buildingShapeType = "EDGE"
|
||||||
if len([e for e in elements if e['geometryType'] == 'surface']) > 0:
|
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
|
||||||
buildingShapeType = 'FACE'
|
buildingShapeType = "FACE"
|
||||||
|
|
||||||
# Define and add groups for all curve and surface members
|
# Define and add groups for all curve and surface members
|
||||||
if len([e for e in elements if e['geometryType'] == 'line']) > 0:
|
if len([e for e in elements if e["geometryType"] == "line"]) > 0:
|
||||||
# Make compound of requested group
|
# Make compound of requested group
|
||||||
compoundTemp = geompy.MakeCompound([e['elemObj'] for e in elements if e['geometryType'] == 'line'])
|
compoundTemp = geompy.MakeCompound([e["elemObj"] for e in elements if e["geometryType"] == "line"])
|
||||||
# Define group object and add to study
|
# Define group object and add to study
|
||||||
curveCompound = geompy.GetInPlace(bldComp, compoundTemp)
|
curveCompound = geompy.GetInPlace(bldComp, compoundTemp)
|
||||||
geompy.addToStudyInFather(bldComp, curveCompound, 'CurveMembers')
|
geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers")
|
||||||
|
|
||||||
if len([e for e in elements if e['geometryType'] == 'surface']) > 0:
|
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
|
||||||
# Make compound of requested group
|
# Make compound of requested group
|
||||||
compoundTemp = geompy.MakeCompound([e['elemObj'] for e in elements if e['geometryType'] == 'surface'])
|
compoundTemp = geompy.MakeCompound([e["elemObj"] for e in elements if e["geometryType"] == "surface"])
|
||||||
# Define group object and add to study
|
# Define group object and add to study
|
||||||
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp)
|
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp)
|
||||||
geompy.addToStudyInFather(bldComp, surfaceCompound, 'SurfaceMembers')
|
geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers")
|
||||||
|
|
||||||
# Loop 3
|
# Loop 3
|
||||||
for el in elements:
|
for el in elements:
|
||||||
# el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0]
|
# el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0]
|
||||||
geompy.addToStudyInFather(bldComp, el['elemObj'], self.getGroupName(el['ifcName']))
|
geompy.addToStudyInFather(bldComp, el["elemObj"], self.getGroupName(el["ifcName"]))
|
||||||
|
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
geompy.addToStudyInFather(bldComp, el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection']))
|
geompy.addToStudyInFather(
|
||||||
if rel['eccentricity']: # point geometry
|
bldComp,
|
||||||
geompy.addToStudyInFather(bldComp, el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']))
|
el["connObjs"][j],
|
||||||
geompy.addToStudyInFather(bldComp, el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']))
|
self.getGroupName(el["ifcName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]),
|
||||||
geompy.addToStudyInFather(bldComp, el['linkPointObjs'][j][1], self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index'])
|
)
|
||||||
|
if rel["eccentricity"]: # point geometry
|
||||||
|
geompy.addToStudyInFather(
|
||||||
|
bldComp,
|
||||||
|
el["linkObjs"][j],
|
||||||
|
self.getGroupName(el["ifcName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
)
|
||||||
|
geompy.addToStudyInFather(
|
||||||
|
bldComp,
|
||||||
|
el["linkPointObjs"][j][0],
|
||||||
|
self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["ifcName"]),
|
||||||
|
)
|
||||||
|
geompy.addToStudyInFather(
|
||||||
|
bldComp,
|
||||||
|
el["linkPointObjs"][j][1],
|
||||||
|
self.getGroupName(rel["relatedConnection"]) + "_0DC_%g" % rel["index"],
|
||||||
|
)
|
||||||
|
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
# conn['connObj'] = geompy.RestoreGivenSubShapes(bldComp, [conn['connObj']], GEOM.FSM_GetInPlace, False, False)[0]
|
# conn['connObj'] = geompy.RestoreGivenSubShapes(bldComp, [conn['connObj']], GEOM.FSM_GetInPlace, False, False)[0]
|
||||||
geompy.addToStudyInFather(bldComp, conn['connObj'], self.getGroupName(conn['ifcName']))
|
geompy.addToStudyInFather(bldComp, conn["connObj"], self.getGroupName(conn["ifcName"]))
|
||||||
|
|
||||||
elapsed_time = time.time() - init_time
|
elapsed_time = time.time() - init_time
|
||||||
init_time += elapsed_time
|
init_time += elapsed_time
|
||||||
print('Building Geometry Groups Defined in %g sec' % (elapsed_time))
|
print("Building Geometry Groups Defined in %g sec" % (elapsed_time))
|
||||||
|
|
||||||
###
|
###
|
||||||
### SMESH component
|
### SMESH component
|
||||||
@@ -268,7 +295,7 @@ class MODEL:
|
|||||||
import SMESH
|
import SMESH
|
||||||
from salome.smesh import smeshBuilder
|
from salome.smesh import smeshBuilder
|
||||||
|
|
||||||
print('Defining Mesh Components')
|
print("Defining Mesh Components")
|
||||||
|
|
||||||
if NEW_SALOME:
|
if NEW_SALOME:
|
||||||
smesh = smeshBuilder.New()
|
smesh = smeshBuilder.New()
|
||||||
@@ -278,13 +305,13 @@ class MODEL:
|
|||||||
Regular_1D = bldMesh.Segment()
|
Regular_1D = bldMesh.Segment()
|
||||||
Local_Length_1 = Regular_1D.LocalLength(meshSize, None, tolLoc)
|
Local_Length_1 = Regular_1D.LocalLength(meshSize, None, tolLoc)
|
||||||
|
|
||||||
if buildingShapeType == 'FACE':
|
if buildingShapeType == "FACE":
|
||||||
NETGEN2D_ONLY = bldMesh.Triangle(algo=smeshBuilder.NETGEN_2D)
|
NETGEN2D_ONLY = bldMesh.Triangle(algo=smeshBuilder.NETGEN_2D)
|
||||||
NETGEN2D_Pars = NETGEN2D_ONLY.Parameters()
|
NETGEN2D_Pars = NETGEN2D_ONLY.Parameters()
|
||||||
NETGEN2D_Pars.SetMaxSize(meshSize)
|
NETGEN2D_Pars.SetMaxSize(meshSize)
|
||||||
NETGEN2D_Pars.SetOptimize(1)
|
NETGEN2D_Pars.SetOptimize(1)
|
||||||
NETGEN2D_Pars.SetFineness(2)
|
NETGEN2D_Pars.SetFineness(2)
|
||||||
NETGEN2D_Pars.SetMinSize(meshSize/5.0)
|
NETGEN2D_Pars.SetMinSize(meshSize / 5.0)
|
||||||
NETGEN2D_Pars.SetUseSurfaceCurvature(1)
|
NETGEN2D_Pars.SetUseSurfaceCurvature(1)
|
||||||
NETGEN2D_Pars.SetQuadAllowed(1)
|
NETGEN2D_Pars.SetQuadAllowed(1)
|
||||||
NETGEN2D_Pars.SetSecondOrder(0)
|
NETGEN2D_Pars.SetSecondOrder(0)
|
||||||
@@ -293,102 +320,129 @@ class MODEL:
|
|||||||
isDone = bldMesh.Compute()
|
isDone = bldMesh.Compute()
|
||||||
|
|
||||||
## Set names of Mesh objects
|
## Set names of Mesh objects
|
||||||
smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
|
smesh.SetName(Regular_1D.GetAlgorithm(), "Regular_1D")
|
||||||
smesh.SetName(Local_Length_1, 'Local_Length_1')
|
smesh.SetName(Local_Length_1, "Local_Length_1")
|
||||||
|
|
||||||
if buildingShapeType == 'FACE':
|
if buildingShapeType == "FACE":
|
||||||
smesh.SetName(NETGEN2D_ONLY.GetAlgorithm(), 'NETGEN2D_ONLY')
|
smesh.SetName(NETGEN2D_ONLY.GetAlgorithm(), "NETGEN2D_ONLY")
|
||||||
smesh.SetName(NETGEN2D_Pars, 'NETGEN2D_Pars')
|
smesh.SetName(NETGEN2D_Pars, "NETGEN2D_Pars")
|
||||||
|
|
||||||
smesh.SetName(bldMesh.GetMesh(), 'bldMesh')
|
smesh.SetName(bldMesh.GetMesh(), "bldMesh")
|
||||||
|
|
||||||
elapsed_time = time.time() - init_time
|
elapsed_time = time.time() - init_time
|
||||||
init_time += elapsed_time
|
init_time += elapsed_time
|
||||||
print('Meshing Operations Completed in %g sec' % (elapsed_time))
|
print("Meshing Operations Completed in %g sec" % (elapsed_time))
|
||||||
|
|
||||||
# Define and add groups for all curve and surface members
|
# Define and add groups for all curve and surface members
|
||||||
if len([e for e in elements if e['geometryType'] == 'line']) > 0:
|
if len([e for e in elements if e["geometryType"] == "line"]) > 0:
|
||||||
tempgroup = bldMesh.GroupOnGeom(curveCompound, 'CurveMembers', SMESH.EDGE)
|
tempgroup = bldMesh.GroupOnGeom(curveCompound, "CurveMembers", SMESH.EDGE)
|
||||||
smesh.SetName(tempgroup, 'CurveMembers')
|
smesh.SetName(tempgroup, "CurveMembers")
|
||||||
|
|
||||||
if len([e for e in elements if e['geometryType'] == 'surface']) > 0:
|
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
|
||||||
tempgroup = bldMesh.GroupOnGeom(surfaceCompound, 'SurfaceMembers', SMESH.FACE)
|
tempgroup = bldMesh.GroupOnGeom(surfaceCompound, "SurfaceMembers", SMESH.FACE)
|
||||||
smesh.SetName(tempgroup, 'SurfaceMembers')
|
smesh.SetName(tempgroup, "SurfaceMembers")
|
||||||
|
|
||||||
# Define groups in Mesh
|
# Define groups in Mesh
|
||||||
for el in elements:
|
for el in elements:
|
||||||
if el['geometryType'] == 'line':
|
if el["geometryType"] == "line":
|
||||||
shapeType = SMESH.EDGE
|
shapeType = SMESH.EDGE
|
||||||
if el['geometryType'] == 'surface':
|
if el["geometryType"] == "surface":
|
||||||
shapeType = SMESH.FACE
|
shapeType = SMESH.FACE
|
||||||
tempgroup = bldMesh.GroupOnGeom(el['elemObj'], self.getGroupName(el['ifcName']), shapeType)
|
tempgroup = bldMesh.GroupOnGeom(el["elemObj"], self.getGroupName(el["ifcName"]), shapeType)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(el['ifcName']))
|
smesh.SetName(tempgroup, self.getGroupName(el["ifcName"]))
|
||||||
|
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
tempgroup = bldMesh.GroupOnGeom(el['connObjs'][j], self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection']), SMESH.NODE)
|
tempgroup = bldMesh.GroupOnGeom(
|
||||||
smesh.SetName(tempgroup, self.getGroupName(el['ifcName']) + rel['conn_string'] + self.getGroupName(rel['relatedConnection']))
|
el["connObjs"][j],
|
||||||
rel['node'] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0]
|
self.getGroupName(el["ifcName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]),
|
||||||
if rel['eccentricity']:
|
SMESH.NODE,
|
||||||
tempgroup = bldMesh.GroupOnGeom(el['linkObjs'][j], self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']), SMESH.EDGE)
|
)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(el['ifcName']) + '_1DR_' + self.getGroupName(rel['relatedConnection']))
|
smesh.SetName(
|
||||||
|
tempgroup,
|
||||||
|
self.getGroupName(el["ifcName"]) + rel["conn_string"] + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
)
|
||||||
|
rel["node"] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0]
|
||||||
|
if rel["eccentricity"]:
|
||||||
|
tempgroup = bldMesh.GroupOnGeom(
|
||||||
|
el["linkObjs"][j],
|
||||||
|
self.getGroupName(el["ifcName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
SMESH.EDGE,
|
||||||
|
)
|
||||||
|
smesh.SetName(
|
||||||
|
tempgroup,
|
||||||
|
self.getGroupName(el["ifcName"]) + "_1DR_" + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
)
|
||||||
|
|
||||||
tempgroup = bldMesh.GroupOnGeom(el['linkPointObjs'][j][0], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']), SMESH.NODE)
|
tempgroup = bldMesh.GroupOnGeom(
|
||||||
smesh.SetName(tempgroup, self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(el['ifcName']))
|
el["linkPointObjs"][j][0],
|
||||||
rel['eccNode'] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0]
|
self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["ifcName"]),
|
||||||
|
SMESH.NODE,
|
||||||
tempgroup = bldMesh.GroupOnGeom(el['linkPointObjs'][j][1], self.getGroupName(rel['relatedConnection']) + '_0DC_' + self.getGroupName(rel['relatedConnection']), SMESH.NODE)
|
)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(rel['relatedConnection']) + '_0DC_%g' % rel['index'])
|
smesh.SetName(
|
||||||
|
tempgroup,
|
||||||
|
self.getGroupName(rel["relatedConnection"]) + "_0DC_" + self.getGroupName(el["ifcName"]),
|
||||||
|
)
|
||||||
|
rel["eccNode"] = (bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)).GetIDs()[0]
|
||||||
|
|
||||||
|
tempgroup = bldMesh.GroupOnGeom(
|
||||||
|
el["linkPointObjs"][j][1],
|
||||||
|
self.getGroupName(rel["relatedConnection"])
|
||||||
|
+ "_0DC_"
|
||||||
|
+ self.getGroupName(rel["relatedConnection"]),
|
||||||
|
SMESH.NODE,
|
||||||
|
)
|
||||||
|
smesh.SetName(tempgroup, self.getGroupName(rel["relatedConnection"]) + "_0DC_%g" % rel["index"])
|
||||||
|
|
||||||
for conn in connections:
|
for conn in connections:
|
||||||
tempgroup = bldMesh.GroupOnGeom(conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.NODE)
|
tempgroup = bldMesh.GroupOnGeom(conn["connObj"], self.getGroupName(conn["ifcName"]), SMESH.NODE)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(conn['ifcName']))
|
smesh.SetName(tempgroup, self.getGroupName(conn["ifcName"]))
|
||||||
nodesId = bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)
|
nodesId = bldMesh.GetIDSource(tempgroup.GetNodeIDs(), SMESH.NODE)
|
||||||
tempgroup = bldMesh.Add0DElementsToAllNodes(nodesId, self.getGroupName(conn['ifcName']))
|
tempgroup = bldMesh.Add0DElementsToAllNodes(nodesId, self.getGroupName(conn["ifcName"]))
|
||||||
smesh.SetName(tempgroup, self.getGroupName(conn['ifcName'] + '_0D'))
|
smesh.SetName(tempgroup, self.getGroupName(conn["ifcName"] + "_0D"))
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
conn['node'] = nodesId.GetIDs()[0]
|
conn["node"] = nodesId.GetIDs()[0]
|
||||||
if conn['geometryType'] == 'line':
|
if conn["geometryType"] == "line":
|
||||||
tempgroup = bldMesh.GroupOnGeom(conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.EDGE)
|
tempgroup = bldMesh.GroupOnGeom(conn["connObj"], self.getGroupName(conn["ifcName"]), SMESH.EDGE)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(conn['ifcName']))
|
smesh.SetName(tempgroup, self.getGroupName(conn["ifcName"]))
|
||||||
if conn['geometryType'] == 'surface':
|
if conn["geometryType"] == "surface":
|
||||||
tempgroup = bldMesh.GroupOnGeom(conn['connObj'], self.getGroupName(conn['ifcName']), SMESH.FACE)
|
tempgroup = bldMesh.GroupOnGeom(conn["connObj"], self.getGroupName(conn["ifcName"]), SMESH.FACE)
|
||||||
smesh.SetName(tempgroup, self.getGroupName(conn['ifcName']))
|
smesh.SetName(tempgroup, self.getGroupName(conn["ifcName"]))
|
||||||
|
|
||||||
# create 1D SEG2 spring elements
|
# create 1D SEG2 spring elements
|
||||||
for el in elements:
|
for el in elements:
|
||||||
for j,rel in enumerate(el['connections']):
|
for j, rel in enumerate(el["connections"]):
|
||||||
conn = [c for c in connections if c['ifcName'] == rel['relatedConnection']][0]
|
conn = [c for c in connections if c["ifcName"] == rel["relatedConnection"]][0]
|
||||||
if conn['geometryType'] == 'point':
|
if conn["geometryType"] == "point":
|
||||||
grpName = bldMesh.CreateEmptyGroup(SMESH.EDGE, self.getGroupName(el['ifcName']) + '_1DS_' + self.getGroupName(rel['relatedConnection']))
|
grpName = bldMesh.CreateEmptyGroup(
|
||||||
smesh.SetName(grpName, self.getGroupName(el['ifcName']) + '_1DS_' + self.getGroupName(rel['relatedConnection']))
|
SMESH.EDGE,
|
||||||
if not rel['eccentricity']:
|
self.getGroupName(el["ifcName"]) + "_1DS_" + self.getGroupName(rel["relatedConnection"]),
|
||||||
conn = [conn for conn in connections if conn['ifcName'] == rel['relatedConnection']][0]
|
)
|
||||||
grpName.Add([bldMesh.AddEdge([conn['node'], rel['node']])])
|
smesh.SetName(
|
||||||
|
grpName,
|
||||||
|
self.getGroupName(el["ifcName"]) + "_1DS_" + self.getGroupName(rel["relatedConnection"]),
|
||||||
|
)
|
||||||
|
if not rel["eccentricity"]:
|
||||||
|
conn = [conn for conn in connections if conn["ifcName"] == rel["relatedConnection"]][0]
|
||||||
|
grpName.Add([bldMesh.AddEdge([conn["node"], rel["node"]])])
|
||||||
else:
|
else:
|
||||||
grpName.Add([bldMesh.AddEdge([rel['eccNode'], rel['node']])])
|
grpName.Add([bldMesh.AddEdge([rel["eccNode"], rel["node"]])])
|
||||||
|
|
||||||
self.mesh = bldMesh
|
self.mesh = bldMesh
|
||||||
self.meshNodes = bldMesh.GetNodesId()
|
self.meshNodes = bldMesh.GetNodesId()
|
||||||
|
|
||||||
elapsed_time = time.time() - init_time
|
elapsed_time = time.time() - init_time
|
||||||
init_time += elapsed_time
|
init_time += elapsed_time
|
||||||
print('Mesh Groups Defined in %g sec' % (elapsed_time))
|
print("Mesh Groups Defined in %g sec" % (elapsed_time))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if NEW_SALOME:
|
if NEW_SALOME:
|
||||||
bldMesh.ExportMED(
|
bldMesh.ExportMED(
|
||||||
self.medFilename,
|
self.medFilename, auto_groups=0, minor=40, overwrite=1, meshPart=None, autoDimension=0
|
||||||
auto_groups = 0,
|
|
||||||
minor = 40,
|
|
||||||
overwrite = 1,
|
|
||||||
meshPart = None,
|
|
||||||
autoDimension = 0
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
bldMesh.ExportMED(self.medFilename, 0, SMESH.MED_V2_2, 1, None, 0)
|
bldMesh.ExportMED(self.medFilename, 0, SMESH.MED_V2_2, 1, None, 0)
|
||||||
except:
|
except:
|
||||||
print('ExportMED() failed. Invalid file name?')
|
print("ExportMED() failed. Invalid file name?")
|
||||||
|
|
||||||
if salome.sg.hasDesktop():
|
if salome.sg.hasDesktop():
|
||||||
if NEW_SALOME:
|
if NEW_SALOME:
|
||||||
@@ -397,16 +451,17 @@ class MODEL:
|
|||||||
salome.sg.updateObjBrowser(1)
|
salome.sg.updateObjBrowser(1)
|
||||||
|
|
||||||
elapsed_time = init_time - start_time
|
elapsed_time = init_time - start_time
|
||||||
print('ALL Operations Completed in %g sec' % (elapsed_time))
|
print("ALL Operations Completed in %g sec" % (elapsed_time))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
fileNames = ['structure_01']
|
if __name__ == "__main__":
|
||||||
|
fileNames = ["structure_01"]
|
||||||
files = fileNames
|
files = fileNames
|
||||||
|
|
||||||
meshSize = 0.1
|
meshSize = 0.1
|
||||||
|
|
||||||
for fileName in files:
|
for fileName in files:
|
||||||
BASE_PATH = '/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/'
|
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
|
||||||
DATAFILENAME = BASE_PATH + fileName + '/' + fileName + '.json'
|
DATAFILENAME = BASE_PATH + fileName + "/" + fileName + ".json"
|
||||||
MEDFILENAME = BASE_PATH + fileName + '/' + fileName + '.med'
|
MEDFILENAME = BASE_PATH + fileName + "/" + fileName + ".med"
|
||||||
model = MODEL(DATAFILENAME, MEDFILENAME, meshSize)
|
model = MODEL(DATAFILENAME, MEDFILENAME, meshSize)
|
||||||
|
|||||||
Reference in New Issue
Block a user