minor changes in ifc2ca scripts

This commit is contained in:
Jesusbill
2021-12-12 19:03:14 +01:00
parent 664c49a07d
commit 4e9a5f246f
5 changed files with 76 additions and 85 deletions
+30 -45
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
@@ -22,6 +21,7 @@ from __future__ import print_function
import json
import ifcopenshell
import numpy as np
from pathlib import Path
class IFC2CA:
@@ -104,19 +104,12 @@ class IFC2CA:
material_profile = self.get_material_profile(item)
if not representation:
self.warnings.append(
"No representation defined for %s. Member excluded"
% (item.is_a() + "|" + str(item.id()))
f"No representation defined for {item.is_a()}|{item.id()}. Member excluded"
)
return
if not material_profile:
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(f"No material defined for {item.is_a()}|{item.id()}")
self.warnings.append(f"No profile defined for {item.is_a()}|{item.id()}")
materialId = None
profileId = None
else:
@@ -143,7 +136,7 @@ class IFC2CA:
f"{np.linalg.norm(np.array(c['eccentricity']['pointOnElement']))} > {length}"
)
self.warnings.append(
f"Eccentricity in {item.is_a()}|{str(item.id())} corrected"
f"Eccentricity in {item.is_a()}|{item.id()} corrected"
)
c["eccentricity"]["pointOnElement"][0] = length
# End <--
@@ -164,7 +157,7 @@ class IFC2CA:
)
return {
"ifcName": item.is_a() + "|" + str(item.id()),
"ifcName": f"{item.is_a()}|{item.id()}",
"name": item.Name,
"id": item.GlobalId,
"geometryType": "line",
@@ -181,15 +174,11 @@ class IFC2CA:
material = self.get_material_profile(item)
if not representation:
self.warnings.append(
"No representation defined for %s. Member excluded"
% (item.is_a() + "|" + str(item.id()))
f"No representation defined for {item.is_a()}|{item.id()}. Member excluded"
)
return
if not material:
self.warnings.append(
"No material defined for in %s"
% (item.is_a() + "|" + str(item.id()))
)
self.warnings.append(f"No material defined for {item.is_a()}|{item.id()}")
materialId = None
else:
materialId = material.is_a() + "|" + str(material.id())
@@ -211,7 +200,7 @@ class IFC2CA:
)
return {
"ifcName": item.is_a() + "|" + str(item.id()),
"ifcName": f"{item.is_a()}|{item.id()}",
"name": item.Name,
"id": item.GlobalId,
"geometryType": "surface",
@@ -227,8 +216,7 @@ class IFC2CA:
representation = self.get_representation(item, "Vertex")
if not representation:
self.warnings.append(
"No representation defined for %s. Connection excluded"
% (item.is_a() + "|" + str(item.id()))
f"No representation defined for {item.is_a()}|{item.id()}. Member excluded"
)
return
@@ -243,7 +231,7 @@ class IFC2CA:
)
return {
"ifcName": item.is_a() + "|" + str(item.id()),
"ifcName": f"{item.is_a()}|{item.id()}",
"name": item.Name,
"id": item.GlobalId,
"geometryType": "point",
@@ -251,8 +239,7 @@ class IFC2CA:
"orientation": orientation,
"appliedCondition": self.get_connection_input(item, "point"),
"relatedElements": [
con.is_a() + "|" + str(con.id())
for con in item.ConnectsStructuralMembers
f"{con.is_a()}|{con.id()}" for con in item.ConnectsStructuralMembers
],
}
@@ -260,8 +247,7 @@ class IFC2CA:
representation = self.get_representation(item, "Edge")
if not representation:
self.warnings.append(
"No representation defined for %s. Connection excluded"
% (item.is_a() + "|" + str(item.id()))
f"No representation defined for {item.is_a()}|{item.id()}. Member excluded"
)
return
@@ -276,7 +262,7 @@ class IFC2CA:
)
return {
"ifcName": item.is_a() + "|" + str(item.id()),
"ifcName": f"{item.is_a()}|{item.id()}",
"name": item.Name,
"id": item.GlobalId,
"geometryType": "line",
@@ -284,8 +270,7 @@ class IFC2CA:
"orientation": orientation,
"appliedCondition": self.get_connection_input(item, "line"),
"relatedElements": [
con.is_a() + "|" + str(con.id())
for con in item.ConnectsStructuralMembers
f"{con.is_a()}|{con.id()}" for con in item.ConnectsStructuralMembers
],
}
@@ -336,9 +321,7 @@ class IFC2CA:
if not element.Representation:
return None
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:
return rep
else:
@@ -419,9 +402,13 @@ class IFC2CA:
def get_2D_orientation(self, representation):
item = representation.Items[0]
if item.is_a("IfcFaceSurface"):
item.SameSense
axes = item.FaceSurface.Position
orientation = self.get_0D_orientation(axes)
if not orientation:
self.warnings.append(
f"No local placement for Plane related to {item.is_a()}|{item.id()}. A unit orientation is considered"
)
return np.eye(3).tolist()
if not item.SameSense:
orientation = [[-v for v in vec] for vec in orientation]
return orientation
@@ -516,7 +503,7 @@ class IFC2CA:
mechProps = self.get_i_section_properties(profile, "iSymmetrical")
return {
"ifcName": profile.is_a() + "|" + str(profile.id()),
"ifcName": f"{profile.is_a()}|{profile.id()}",
"profileName": profile.ProfileName,
"profileType": profile.ProfileType,
"profileShape": "iSymmetrical",
@@ -533,14 +520,10 @@ class IFC2CA:
def get_connection_data(self, itemList):
return [
{
"ifcName": rel.is_a() + "|" + str(rel.id()),
"ifcName": f"{rel.is_a()}|{rel.id()}",
"id": rel.GlobalId,
"relatingElement": rel.RelatingStructuralMember.is_a()
+ "|"
+ str(rel.RelatingStructuralMember.id()),
"relatedConnection": rel.RelatedStructuralConnection.is_a()
+ "|"
+ str(rel.RelatedStructuralConnection.id()),
"relatingElement": f"{rel.RelatingStructuralMember.is_a()}|{rel.RelatingStructuralMember.id()}",
"relatedConnection": f"{rel.RelatedStructuralConnection.is_a()}|{rel.RelatedStructuralConnection.id()}",
"orientation": self.get_0D_orientation(rel.ConditionCoordinateSystem),
"appliedCondition": self.get_connection_input(
rel,
@@ -641,8 +624,10 @@ if __name__ == "__main__":
files = fileNames
for fileName in files:
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/ifcFiles/"
ifc2ca = IFC2CA(BASE_PATH + fileName + ".ifc")
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/ifcFiles/"
)
ifc2ca = IFC2CA(BASE_PATH / f"{fileName}.ifc")
ifc2ca.convert()
with open(BASE_PATH + fileName + ".json", "w") as f:
with open(BASE_PATH / f"{fileName}.json", "w") as f:
f.write(json.dumps(ifc2ca.result, indent=4))
+7 -5
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
@@ -20,6 +19,7 @@
import json
import numpy as np
import itertools
from pathlib import Path
flatten = itertools.chain.from_iterable
@@ -33,7 +33,7 @@ class COMMANDFILE:
def getGroupName(self, name):
info = name.split("|")
sortName = "".join(c for c in info[0] if c.isupper())
return str(sortName + "_" + info[1])
return f"{sortName[2:]}_{info[1]}"
def create(self):
@@ -1083,7 +1083,9 @@ if __name__ == "__main__":
files = fileNames
for fileName in files:
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
DATAFILENAME = BASE_PATH + fileName + "/" + fileName + ".json"
ASTERFILENAME = BASE_PATH + fileName + "/" + fileName + ".comm"
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
ASTERFILENAME = BASE_PATH / fileName / f"{fileName}.comm"
COMMANDFILE(DATAFILENAME, ASTERFILENAME)
+8 -5
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
@@ -20,6 +19,7 @@
import json
import numpy as np
import itertools
from pathlib import Path
flatten = itertools.chain.from_iterable
@@ -27,6 +27,7 @@ ScaleFactor = 1.0
AccelOfGravity = 9.806 * 1000
class COMMANDFILE:
def __init__(self, dataFilename, asterFilename):
self.dataFilename = dataFilename
@@ -36,7 +37,7 @@ class COMMANDFILE:
def getGroupName(self, name):
info = name.split("|")
sortName = "".join(c for c in info[0] if c.isupper())
return str(sortName + "_" + info[1])
return f"{sortName[2:]}_{info[1]}"
def create(self):
# Read data from input file
@@ -568,7 +569,9 @@ if __name__ == "__main__":
files = fileNames
for fileName in files:
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
DATAFILENAME = BASE_PATH + fileName + "/" + fileName + ".json"
ASTERFILENAME = BASE_PATH + fileName + "/" + fileName + ".comm"
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
ASTERFILENAME = BASE_PATH / fileName / f"{fileName}.comm"
COMMANDFILE(DATAFILENAME, ASTERFILENAME)
+15 -16
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
@@ -27,6 +26,7 @@ import salome_notebook
import salome_version
import numpy as np
import itertools
from pathlib import Path
flatten = itertools.chain.from_iterable
@@ -44,7 +44,7 @@ class MODEL:
def getGroupName(self, name):
info = name.split("|")
sortName = "".join(c for c in info[0] if c.isupper())
return str(sortName + "_" + info[1])
return f"{sortName[2:]}_{info[1]}"
def makePoint(self, pl):
"""Function to define a Point from
@@ -212,15 +212,14 @@ class MODEL:
"Eccentricity defined for a %s geometryType"
% conn["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"], True)
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], True
)
for conn in connections:
conn["connObj"] = self.makeObject(conn["geometry"], conn["geometryType"])
@@ -283,7 +282,7 @@ class MODEL:
[e["elemObj"] for e in elements if e["geometryType"] == "line"]
)
# Define group object and add to study
curveCompound = geompy.GetInPlace(bldComp, compoundTemp)
curveCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers")
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
@@ -292,7 +291,7 @@ class MODEL:
[e["elemObj"] for e in elements if e["geometryType"] == "surface"]
)
# Define group object and add to study
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp)
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers")
# Loop 3
@@ -393,9 +392,7 @@ class MODEL:
smesh.SetName(tempgroup, "CurveMembers")
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")
# Define groups in Mesh
@@ -562,7 +559,9 @@ if __name__ == "__main__":
meshSize = 0.1
for fileName in files:
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
DATAFILENAME = BASE_PATH + fileName + "/" + fileName + ".json"
MEDFILENAME = BASE_PATH + fileName + "/" + fileName + ".med"
model = MODEL(DATAFILENAME, MEDFILENAME, meshSize)
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
MEDFILENAME = BASE_PATH / fileName / f"{fileName}.med"
model = MODEL(DATAFILENAME, str(MEDFILENAME), meshSize)
+16 -14
View File
@@ -1,4 +1,3 @@
# Ifc2CA - IFC Code_Aster utility
# Copyright (C) 2020, 2021 Ioannis P. Christovasilis <ipc@aethereng.com>
#
@@ -27,6 +26,7 @@ import salome_notebook
import salome_version
import numpy as np
import itertools
from pathlib import Path
flatten = itertools.chain.from_iterable
@@ -48,7 +48,7 @@ class MODEL:
def getGroupName(self, name):
info = name.split("|")
sortName = "".join(c for c in info[0] if c.isupper())
return str(sortName + "_" + info[1])
return f"{sortName[2:]}_{info[1]}"
def makePoint(self, pl):
"""Function to define a Point from
@@ -234,7 +234,7 @@ class MODEL:
[e["elemObj"] for e in elements if e["geometryType"] == "line"]
)
# Define group object and add to study
curveCompound = geompy.GetInPlace(bldComp, compoundTemp)
curveCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, curveCompound, "CurveMembers")
if len([e for e in elements if e["geometryType"] == "surface"]) > 0:
@@ -243,7 +243,7 @@ class MODEL:
[e["elemObj"] for e in elements if e["geometryType"] == "surface"]
)
# Define group object and add to study
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp)
surfaceCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, surfaceCompound, "SurfaceMembers")
linkObjs = list(
@@ -253,19 +253,21 @@ class MODEL:
# Make compound of requested group
compoundTemp = geompy.MakeCompound(linkObjs)
# Define group object and add to study
rigidCompound = geompy.GetInPlace(bldComp, compoundTemp)
rigidCompound = geompy.GetInPlace(bldComp, compoundTemp, True)
geompy.addToStudyInFather(bldComp, rigidCompound, "RigidMembers")
for el in elements:
# el['partObj'] = geompy.RestoreGivenSubShapes(bldComp, [el['partObj']], GEOM.FSM_GetInPlace, False, False)[0]
el["elemObj"] = geompy.GetInPlace(bldComp, el["elemObj"])
el["elemObj"] = geompy.GetInPlace(bldComp, el["elemObj"], True)
geompy.addToStudyInFather(
bldComp, el["elemObj"], self.getGroupName(el["ifcName"])
)
for j, rel in enumerate(el["connections"]):
if rel["eccentricity"]: # point geometry
el["linkObjs"][j] = geompy.GetInPlace(bldComp, el["linkObjs"][j])
el["linkObjs"][j] = geompy.GetInPlace(
bldComp, el["linkObjs"][j], True
)
geompy.addToStudyInFather(
bldComp,
el["linkObjs"][j],
@@ -337,9 +339,7 @@ class MODEL:
smesh.SetName(tempgroup, "CurveMembers")
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")
if len(linkObjs) > 0:
@@ -423,7 +423,9 @@ if __name__ == "__main__":
zGround = 0
for fileName in files:
BASE_PATH = "/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
DATAFILENAME = BASE_PATH + fileName + "/" + fileName + ".json"
MEDFILENAME = BASE_PATH + fileName + "/" + fileName + ".med"
model = MODEL(DATAFILENAME, MEDFILENAME, meshSize, zGround)
BASE_PATH = Path(
"/home/jesusbill/Dev-Projects/github.com/IfcOpenShell/analysis-models/models/"
)
DATAFILENAME = BASE_PATH / fileName / f"{fileName}.json"
MEDFILENAME = BASE_PATH / fileName / f"{fileName}.med"
model = MODEL(DATAFILENAME, str(MEDFILENAME), meshSize, zGround)