Formating for better readability

The changes affect code in the exportIFCStructuralTools.py file and aims to improve only the readability for later planed export of SurfaceMembers
This commit is contained in:
balrobs
2021-06-04 15:54:17 +02:00
committed by Bernd Hahnebach
parent be8d2c4625
commit 81f19b50c1

View File

@@ -32,24 +32,26 @@ structural_nodes = {} # this keeps track of nodes during this session
scaling = 1.0 # this keeps track of scaling during this session
def setup(ifcfile,ifcbin,scale):
def setup(ifcfile, ifcbin, scale):
"""Creates all the needed setup for structural model."""
global structural_nodes,scaling
global structural_nodes, scaling
structural_nodes = {}
scaling = scale
import ifcopenshell
uid = ifcopenshell.guid.new
owh = ifcfile.by_type("IfcOwnerHistory")[0]
prj = ifcfile.by_type("IfcProject")[0]
ctx = createStructuralContext(ifcfile)
ownerHistory = ifcfile.by_type("IfcOwnerHistory")[0]
project = ifcfile.by_type("IfcProject")[0]
structContext = createStructuralContext(ifcfile)
if ifcfile.wrapped_data.schema_name() == "IFC2X3":
mod = ifcfile.createIfcStructuralAnalysisModel(uid(),owh,"Structural Analysis Model",None,None,"NOTDEFINED",None,None,None)
mod = ifcfile.createIfcStructuralAnalysisModel(
uid(), ownerHistory, "Structural Analysis Model", None, None, "NOTDEFINED", None, None, None)
else:
pla = ifcbin.createIfcLocalPlacement()
mod = ifcfile.createIfcStructuralAnalysisModel(uid(),owh,"Structural Analysis Model",None,None,"NOTDEFINED",None,None,None,pla)
rel = ifcfile.createIfcRelDeclares(uid(),owh,None,None,prj,[mod])
localPlacement = ifcbin.createIfcLocalPlacement()
structModel = ifcfile.createIfcStructuralAnalysisModel(
uid(), ownerHistory, "Structural Analysis Model", None, None, "NOTDEFINED", None, None, None, localPlacement)
relation = ifcfile.createIfcRelDeclares(uid(), ownerHistory, None, None, project, [structModel])
def createStructuralContext(ifcfile):
@@ -59,9 +61,10 @@ def createStructuralContext(ifcfile):
contexts = ifcfile.by_type("IfcGeometricRepresentationContext")
# filter out subcontexts
contexts = [c for c in contexts if c.is_a() == "IfcGeometricRepresentationContext"]
ctx = contexts[0] # arbitrarily take the first one...
structcontext = ifcfile.createIfcGeometricRepresentationSubContext('Analysis','Axis',None,None,None,None,ctx,None,"GRAPH_VIEW",None)
return structcontext
geomContext = contexts[0] # arbitrarily take the first one...
structContext = ifcfile.createIfcGeometricRepresentationSubContext(
'Analysis', 'Axis', None, None, None, None, geomContext, None, "GRAPH_VIEW", None)
return structContext
def getStructuralContext(ifcfile):
@@ -72,42 +75,46 @@ def getStructuralContext(ifcfile):
return c
def createStructuralNode(ifcfile,ifcbin,point):
def createStructuralNode(ifcfile, ifcbin, point):
"""Creates a connection node at the given point"""
import ifcopenshell
uid = ifcopenshell.guid.new
owh = ifcfile.by_type("IfcOwnerHistory")[0]
ctx = getStructuralContext(ifcfile)
cpt = ifcbin.createIfcCartesianPoint(tuple(point))
vtx = ifcfile.createIfcVertexPoint(cpt)
rep = ifcfile.createIfcTopologyRepresentation(ctx,'Analysis','Vertex',[vtx])
psh = ifcfile.createIfcProductDefinitionShape(None,None,[rep])
ownerHistory = ifcfile.by_type("IfcOwnerHistory")[0]
structContext = getStructuralContext(ifcfile)
cartPoint = ifcbin.createIfcCartesianPoint(tuple(point))
vertPoint = ifcfile.createIfcVertexPoint(cartPoint)
topologyRep = ifcfile.createIfcTopologyRepresentation(structContext, 'Analysis', 'Vertex', [vertPoint])
prodDefShape = ifcfile.createIfcProductDefinitionShape(None, None, [topologyRep])
# boundary conditions serve for ex. to create fixed nodes
#cnd = ifcfile.createIfcBoundaryNodeCondition("Fixed",ifcfile.createIfcBoolean(True),ifcfile.createIfcBoolean(True),ifcfile.createIfcBoolean(True),ifcfile.createIfcBoolean(True),ifcfile.createIfcBoolean(True),ifcfile.createIfcBoolean(True))
# appliedCondition = ifcfile.createIfcBoundaryNodeCondition(
# "Fixed",ifcfile.createIfcBoolean(True), ifcfile.createIfcBoolean(True), ifcfile.createIfcBoolean(True),
# ifcfile.createIfcBoolean(True), ifcfile.createIfcBoolean(True), ifcfile.createIfcBoolean(True))
# for now we don't create any boundary condition
cnd = None
pla = ifcbin.createIfcLocalPlacement()
appliedCondition = None
localPlacement = ifcbin.createIfcLocalPlacement()
if ifcfile.wrapped_data.schema_name() == "IFC2X3":
prd = ifcfile.createIfcStructuralPointConnection(uid(),owh,'Vertex',None,None,pla,psh,cnd)
structPntConn = ifcfile.createIfcStructuralPointConnection(
uid(), ownerHistory, 'Vertex', None, None, localPlacement, prodDefShape, appliedCondition)
else:
prd = ifcfile.createIfcStructuralPointConnection(uid(),owh,'Vertex',None,None,pla,psh,cnd,None)
return prd
structPntConn = ifcfile.createIfcStructuralPointConnection(
uid(), ownerHistory, 'Vertex', None, None, localPlacement, prodDefShape, appliedCondition, None)
return structPntConn
def createStructuralMember(ifcfile,ifcbin,obj):
def createStructuralMember(ifcfile, ifcbin, obj):
"""Creates a structural member if possible. Returns the member"""
global structural_nodes
prd = None
structuralMember = None
import Draft
import Part
import ifcopenshell
uid = ifcopenshell.guid.new
owh = ifcfile.by_type("IfcOwnerHistory")[0]
ctx = getStructuralContext(ifcfile)
ownerHistory = ifcfile.by_type("IfcOwnerHistory")[0]
structContext = getStructuralContext(ifcfile)
# find edges to convert into structural members
edges = None
@@ -136,56 +143,59 @@ def createStructuralMember(ifcfile,ifcbin,obj):
for edge in edges:
if len(edge.Vertexes) > 1:
# we don't care about curved edges just now...
v0 = edge.Vertexes[0].Point.multiply(scaling)
v1 = edge.Vertexes[-1].Point.multiply(scaling)
cp1 = ifcbin.createIfcCartesianPoint(tuple(v0))
cp2 = ifcbin.createIfcCartesianPoint(tuple(v1))
pla = ifcbin.createIfcLocalPlacement()
vp1 = ifcfile.createIfcVertexPoint(cp1)
vp2 = ifcfile.createIfcVertexPoint(cp2)
edg = ifcfile.createIfcEdge(vp1,vp2)
rep = ifcfile.createIfcTopologyRepresentation(ctx,'Analysis','Edge',[edg])
psh = ifcfile.createIfcProductDefinitionShape(None,None,[rep])
vert0 = edge.Vertexes[ 0].Point.multiply(scaling)
vert1 = edge.Vertexes[-1].Point.multiply(scaling)
cartPoint1 = ifcbin.createIfcCartesianPoint(tuple(vert0))
cartPoint2 = ifcbin.createIfcCartesianPoint(tuple(vert1))
localPlacement = ifcbin.createIfcLocalPlacement()
vertPoint1 = ifcfile.createIfcVertexPoint(cartPoint1)
vertPoint2 = ifcfile.createIfcVertexPoint(cartPoint2)
newEdge = ifcfile.createIfcEdge(vertPoint1, vertPoint2)
topologyRep = ifcfile.createIfcTopologyRepresentation(structContext, 'Analysis', 'Edge', [newEdge])
prodDefShape = ifcfile.createIfcProductDefinitionShape(None, None, [topologyRep])
if ifcfile.wrapped_data.schema_name() == "IFC2X3":
prd = ifcfile.createIfcStructuralCurveMember(uid(),owh,obj.Label,None,None,pla,psh,"RIGID_JOINED_MEMBER")
structuralMember = ifcfile.createIfcStructuralCurveMember(
uid(), ownerHistory, obj.Label, None, None, localPlacement, prodDefShape, "RIGID_JOINED_MEMBER")
else:
upv = ifcbin.createIfcDirection((0,0,1))
prd = ifcfile.createIfcStructuralCurveMember(uid(),owh,obj.Label,None,None,pla,psh,"RIGID_JOINED_MEMBER",upv)
localZAxis = ifcbin.createIfcDirection((0, 0, 1))
structuralMember = ifcfile.createIfcStructuralCurveMember(
uid(), ownerHistory, obj.Label, None, None, localPlacement, prodDefShape, "RIGID_JOINED_MEMBER", localZAxis)
# check for existing connection nodes
for v in [v0,v1]:
vk = tuple(v)
if vk in structural_nodes:
if structural_nodes[vk]:
for vert in [vert0, vert1]:
vertCoord = tuple(vert)
if vertCoord in structural_nodes:
if structural_nodes[vertCoord]:
# there is already another member using this point
n = structural_nodes[vk]
structPntConn = structural_nodes[vertCoord]
else:
# there is another member with same point, create a new node
n = createStructuralNode(ifcfile,ifcbin,v)
structural_nodes[vk] = n
ifcfile.createIfcRelConnectsStructuralMember(uid(),owh,None,None,prd,n,None,None,None,None)
structPntConn = createStructuralNode(ifcfile, ifcbin, vert)
structural_nodes[vertCoord] = structPntConn
ifcfile.createIfcRelConnectsStructuralMember(
uid(), ownerHistory, None, None, structuralMember, structPntConn, None, None, None, None)
else:
# just add the point, no other member using it yet
structural_nodes[vk] = None
return prd
structural_nodes[vertCoord] = None
return structuralMember
def createStructuralGroup(ifcfile):
"Assigns all structural objects found in the file to the structural model"""
"""Assigns all structural objects found in the file to the structural model"""
import ifcopenshell
uid = ifcopenshell.guid.new
owh = ifcfile.by_type("IfcOwnerHistory")[0]
edges = ifcfile.by_type("IfcStructuralCurveMember")
verts = ifcfile.by_type("IfcStructuralPointConnection")
model = ifcfile.by_type("IfcStructuralAnalysisModel")[0]
if model:
members = edges + verts
ownerHistory = ifcfile.by_type("IfcOwnerHistory")[0]
structCrvMember = ifcfile.by_type("IfcStructuralCurveMember")
structPntConn = ifcfile.by_type("IfcStructuralPointConnection")
structModel = ifcfile.by_type("IfcStructuralAnalysisModel")[0]
if structModel:
members = structCrvMember + structPntConn
if members:
ifcfile.createIfcRelAssignsToGroup(uid(),owh,None,None,members,"PRODUCT",model)
ifcfile.createIfcRelAssignsToGroup(uid(), ownerHistory, None, None, members, "PRODUCT", structModel)
def associates(ifcfile,aobj,sobj):
def associates(ifcfile, aobj, sobj):
"""Associates an arch object with a struct object"""
@@ -194,5 +204,5 @@ def associates(ifcfile,aobj,sobj):
import ifcopenshell
uid = ifcopenshell.guid.new
owh = ifcfile.by_type("IfcOwnerHistory")[0]
ifcfile.createIfcRelAssignsToProduct(uid(),owh,None,None,[sobj],None,aobj)
ownerHistory = ifcfile.by_type("IfcOwnerHistory")[0]
ifcfile.createIfcRelAssignsToProduct(uid(), ownerHistory, None, None, [sobj], None, aobj)