Arch: IFC exporter now exports cloned Arch objects with shared geometry
This commit is contained in:
parent
27dc80c846
commit
d13179b63f
|
@ -649,7 +649,14 @@ def pruneIncluded(objectslist):
|
||||||
if parent.isDerivedFrom("Part::Feature"):
|
if parent.isDerivedFrom("Part::Feature"):
|
||||||
if not parent.isDerivedFrom("Part::Part2DObject"):
|
if not parent.isDerivedFrom("Part::Part2DObject"):
|
||||||
# don't consider 2D objects based on arch elements
|
# don't consider 2D objects based on arch elements
|
||||||
toplevel = False
|
if hasattr(parent,"CloneOf"):
|
||||||
|
if parent.CloneOf:
|
||||||
|
if parent.CloneOf.Name != obj.Name:
|
||||||
|
toplevel = False
|
||||||
|
else:
|
||||||
|
toplevel = False
|
||||||
|
else:
|
||||||
|
toplevel = False
|
||||||
if toplevel:
|
if toplevel:
|
||||||
newlist.append(obj)
|
newlist.append(obj)
|
||||||
return newlist
|
return newlist
|
||||||
|
|
|
@ -522,9 +522,12 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||||
obj.CloneOf = clone
|
obj.CloneOf = clone
|
||||||
if shape:
|
if shape:
|
||||||
v = shape.Solids[0].CenterOfMass.sub(clone.Shape.Solids[0].CenterOfMass)
|
v = shape.Solids[0].CenterOfMass.sub(clone.Shape.Solids[0].CenterOfMass)
|
||||||
p = FreeCAD.Placement(obj.Placement)
|
r = getRotation(product)
|
||||||
p.move(v)
|
if not r.isNull():
|
||||||
obj.Placement = p
|
v = v.add(clone.Shape.Solids[0].CenterOfMass)
|
||||||
|
v = v.add(r.multVec(clone.Shape.Solids[0].CenterOfMass.negative()))
|
||||||
|
obj.Placement.Rotation = r
|
||||||
|
obj.Placement.move(v)
|
||||||
else:
|
else:
|
||||||
obj = getattr(Arch,"make"+freecadtype)(baseobj=baseobj,name=name)
|
obj = getattr(Arch,"make"+freecadtype)(baseobj=baseobj,name=name)
|
||||||
if store:
|
if store:
|
||||||
|
@ -596,7 +599,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||||
|
|
||||||
# color
|
# color
|
||||||
if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"):
|
if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"):
|
||||||
if DEBUG: print " setting color: ",colors[pid]
|
if DEBUG: print " setting color: ",int(colors[pid][0]*255),"/",int(colors[pid][1]*255),"/",int(colors[pid][2]*255)
|
||||||
obj.ViewObject.ShapeColor = colors[pid]
|
obj.ViewObject.ShapeColor = colors[pid]
|
||||||
|
|
||||||
# if DEBUG is on, recompute after each shape
|
# if DEBUG is on, recompute after each shape
|
||||||
|
@ -810,7 +813,7 @@ def export(exportList,filename):
|
||||||
of = pyopen(templatefile,"wb")
|
of = pyopen(templatefile,"wb")
|
||||||
of.write(template.encode("utf8"))
|
of.write(template.encode("utf8"))
|
||||||
of.close()
|
of.close()
|
||||||
global ifcfile, surfstyles
|
global ifcfile, surfstyles, clones, sharedobjects
|
||||||
ifcfile = ifcopenshell.open(templatefile)
|
ifcfile = ifcopenshell.open(templatefile)
|
||||||
history = ifcfile.by_type("IfcOwnerHistory")[0]
|
history = ifcfile.by_type("IfcOwnerHistory")[0]
|
||||||
context = ifcfile.by_type("IfcGeometricRepresentationContext")[0]
|
context = ifcfile.by_type("IfcGeometricRepresentationContext")[0]
|
||||||
|
@ -824,10 +827,13 @@ def export(exportList,filename):
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
# build clones table
|
# build clones table
|
||||||
for o in objectlist:
|
for o in objectslist:
|
||||||
b = Draft.getCloneBase(o,strict=True)
|
b = Draft.getCloneBase(o,strict=True)
|
||||||
if b:
|
if b:
|
||||||
clones.setdefault(b.Name,[]).append(o.Name)
|
clones.setdefault(b.Name,[]).append(o.Name)
|
||||||
|
|
||||||
|
print "clones table: ",clones
|
||||||
|
print objectslist
|
||||||
|
|
||||||
# products
|
# products
|
||||||
for obj in objectslist:
|
for obj in objectslist:
|
||||||
|
@ -1017,8 +1023,29 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||||
placement = None
|
placement = None
|
||||||
productdef = None
|
productdef = None
|
||||||
shapetype = "no shape"
|
shapetype = "no shape"
|
||||||
|
tostore = False
|
||||||
|
|
||||||
|
# check for clones
|
||||||
|
for k,v in clones.items():
|
||||||
|
if (obj.Name == k ) or (obj.Name in v):
|
||||||
|
if k in sharedobjects:
|
||||||
|
# base shape already exists
|
||||||
|
repmap = sharedobjects[k]
|
||||||
|
pla = obj.Placement
|
||||||
|
axis1 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(1,0,0))))
|
||||||
|
axis2 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(0,1,0))))
|
||||||
|
axis3 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(0,0,1))))
|
||||||
|
origin = ifcfile.createIfcCartesianPoint(tuple(FreeCAD.Vector(pla.Base).multiply(0.001)))
|
||||||
|
transf = ifcfile.createIfcCartesianTransformationOperator3D(axis1,axis2,origin,1.0,axis3)
|
||||||
|
mapitem = ifcfile.createIfcMappedItem(repmap,transf)
|
||||||
|
shapes = [mapitem]
|
||||||
|
solidType = "MappedRepresentation"
|
||||||
|
shapetype = "clone"
|
||||||
|
else:
|
||||||
|
# base shape not yet created
|
||||||
|
tostore = k
|
||||||
|
|
||||||
if not forcebrep:
|
if (not shapes) and (not forcebrep):
|
||||||
profile = None
|
profile = None
|
||||||
if hasattr(obj,"Proxy"):
|
if hasattr(obj,"Proxy"):
|
||||||
if hasattr(obj.Proxy,"getProfiles"):
|
if hasattr(obj.Proxy,"getProfiles"):
|
||||||
|
@ -1119,7 +1146,6 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||||
shapetype = "extrusion"
|
shapetype = "extrusion"
|
||||||
|
|
||||||
if not shapes:
|
if not shapes:
|
||||||
|
|
||||||
# brep representation
|
# brep representation
|
||||||
fcshape = None
|
fcshape = None
|
||||||
solidType = "Brep"
|
solidType = "Brep"
|
||||||
|
@ -1200,6 +1226,24 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||||
|
|
||||||
if shapes:
|
if shapes:
|
||||||
|
|
||||||
|
if tostore:
|
||||||
|
subrep = ifcfile.createIfcShapeRepresentation(context,'Body',solidType,shapes)
|
||||||
|
xvc = ifcfile.createIfcDirection((1.0,0.0,0.0))
|
||||||
|
zvc = ifcfile.createIfcDirection((0.0,0.0,1.0))
|
||||||
|
ovc = ifcfile.createIfcCartesianPoint((0.0,0.0,0.0))
|
||||||
|
gpl = ifcfile.createIfcAxis2Placement3D(ovc,zvc,xvc)
|
||||||
|
repmap = ifcfile.createIfcRepresentationMap(gpl,subrep)
|
||||||
|
pla = FreeCAD.ActiveDocument.getObject(k).Placement
|
||||||
|
axis1 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(1,0,0))))
|
||||||
|
axis2 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(0,1,0))))
|
||||||
|
origin = ifcfile.createIfcCartesianPoint(tuple(FreeCAD.Vector(pla.Base).multiply(0.001)))
|
||||||
|
axis3 = ifcfile.createIfcDirection(tuple(pla.Rotation.multVec(FreeCAD.Vector(0,0,1))))
|
||||||
|
transf = ifcfile.createIfcCartesianTransformationOperator3D(axis1,axis2,origin,1.0,axis3)
|
||||||
|
mapitem = ifcfile.createIfcMappedItem(repmap,transf)
|
||||||
|
shapes = [mapitem]
|
||||||
|
sharedobjects[k] = repmap
|
||||||
|
solidType = "MappedRepresentation"
|
||||||
|
|
||||||
# set surface style
|
# set surface style
|
||||||
if FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeColor"):
|
if FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeColor"):
|
||||||
# only set a surface style if the object has no material.
|
# only set a surface style if the object has no material.
|
||||||
|
@ -1222,7 +1266,6 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||||
for shape in shapes:
|
for shape in shapes:
|
||||||
isi = ifcfile.createIfcStyledItem(shape,[psa],None)
|
isi = ifcfile.createIfcStyledItem(shape,[psa],None)
|
||||||
|
|
||||||
|
|
||||||
xvc = ifcfile.createIfcDirection((1.0,0.0,0.0))
|
xvc = ifcfile.createIfcDirection((1.0,0.0,0.0))
|
||||||
zvc = ifcfile.createIfcDirection((0.0,0.0,1.0))
|
zvc = ifcfile.createIfcDirection((0.0,0.0,1.0))
|
||||||
ovc = ifcfile.createIfcCartesianPoint((0.0,0.0,0.0))
|
ovc = ifcfile.createIfcCartesianPoint((0.0,0.0,0.0))
|
||||||
|
@ -1277,4 +1320,18 @@ def setRepresentation(representation):
|
||||||
e.rotate(bc.Curve.Center,FreeCAD.Vector(0,0,1),math.degrees(a))
|
e.rotate(bc.Curve.Center,FreeCAD.Vector(0,0,1),math.degrees(a))
|
||||||
result.append(e)
|
result.append(e)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def getRotation(entity):
|
||||||
|
"returns a FreeCAD rotation from an IfcProduct with a IfcMappedItem representation"
|
||||||
|
try:
|
||||||
|
rmap = entity.Representation.Representations[0].Items[0].MappingTarget
|
||||||
|
u = FreeCAD.Vector(rmap.Axis1.DirectionRatios)
|
||||||
|
v = FreeCAD.Vector(rmap.Axis2.DirectionRatios)
|
||||||
|
w = FreeCAD.Vector(rmap.Axis3.DirectionRatios)
|
||||||
|
except AttributeError:
|
||||||
|
return FreeCAD.Rotation()
|
||||||
|
import WorkingPlane
|
||||||
|
p = WorkingPlane.plane(u=u,v=v,w=w)
|
||||||
|
return p.getRotation().Rotation
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user