Arch: Better support for colors in multicore IFC importer
This commit is contained in:
@@ -383,6 +383,16 @@ def buildRelMaterialColors(ifcfile, prodrepr):
|
||||
pass
|
||||
|
||||
|
||||
def getColorFromProduct(product):
|
||||
|
||||
if product.Representation:
|
||||
for rep in product.Representation.Representations:
|
||||
for item in rep.Items:
|
||||
for style in item.StyledByItem:
|
||||
color = getColorFromStyledItem(style)
|
||||
if color:
|
||||
return color
|
||||
|
||||
def getColorFromMaterial(material):
|
||||
|
||||
if material.HasRepresentation:
|
||||
@@ -410,12 +420,13 @@ def getColorFromStyledItem(styled_item):
|
||||
Return `None` if `styled_item` is not of type `'IfcStyledItem'`
|
||||
or if there is any other problem getting a color.
|
||||
"""
|
||||
if not styled_item.is_a("IfcStyledItem"):
|
||||
return None
|
||||
|
||||
if styled_item.is_a("IfcStyledRepresentation"):
|
||||
styled_item = styled_item.Items[0]
|
||||
|
||||
if not styled_item.is_a("IfcStyledItem"):
|
||||
return None
|
||||
|
||||
rgb_color = None
|
||||
transparency = None
|
||||
col = None
|
||||
|
||||
@@ -41,6 +41,7 @@ materials = {} #ifcid : Arch_Material
|
||||
objects = {} #ifcid : Arch_Component
|
||||
subs = {} #host_ifcid: [child_ifcid,...]
|
||||
adds = {} #host_ifcid: [child_ifcid,...]
|
||||
colors = {} # objname : (r,g,b)
|
||||
|
||||
|
||||
def open(filename):
|
||||
@@ -117,8 +118,11 @@ def insert(filename,docname=None,preferences=None):
|
||||
if not iterator.next():
|
||||
break
|
||||
|
||||
# finished
|
||||
# post-processing
|
||||
processRelationships()
|
||||
storeColorDict()
|
||||
|
||||
# finished
|
||||
progressbar.stop()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
endtime = round(time.time()-starttime,1)
|
||||
@@ -146,7 +150,7 @@ def writeProgress(count=None,total=None,starttime=None):
|
||||
else:
|
||||
eta = "--:--"
|
||||
hashes = '#'*int(r*10)+' '*int(10-r*10)
|
||||
fstring = '\rImporting '+str(total)+' products... [{0}] {1}%, ETA: {2}'
|
||||
fstring = '\rImporting '+str(total)+' products [{0}] {1}%, ETA: {2}'
|
||||
sys.stdout.write(fstring.format(hashes, int(r*100),eta))
|
||||
|
||||
|
||||
@@ -171,6 +175,7 @@ def createProduct(ifcproduct,brep):
|
||||
createMaterial(obj,ifcproduct)
|
||||
createModelStructure(obj,ifcproduct)
|
||||
setRelationships(obj,ifcproduct)
|
||||
setColor(obj,ifcproduct)
|
||||
return obj
|
||||
|
||||
|
||||
@@ -209,6 +214,18 @@ def setProperties(obj,ifcproduct):
|
||||
propvalue = ";;".join(v)
|
||||
|
||||
|
||||
def setColor(obj,ifcproduct):
|
||||
|
||||
"""sets the color of an object"""
|
||||
|
||||
global colors
|
||||
|
||||
color = importIFCHelper.getColorFromProduct(ifcproduct)
|
||||
colors[obj.Name] = color
|
||||
if FreeCAD.GuiUp:
|
||||
obj.ViewObject.ShapeColor = color
|
||||
|
||||
|
||||
def createLayer(obj,ifcproduct):
|
||||
|
||||
"""sets the layer of a component"""
|
||||
@@ -282,7 +299,7 @@ def processRelationships():
|
||||
"""process all stored relationships"""
|
||||
|
||||
for dom in ((subs,"Subtractions"),(adds,"Additions")):
|
||||
for key,vals in dom[0]:
|
||||
for key,vals in dom[0].items():
|
||||
if key in objects:
|
||||
for val in vals:
|
||||
if val in objects:
|
||||
@@ -291,3 +308,12 @@ def processRelationships():
|
||||
g.append(val)
|
||||
setattr(objects[key],dom[1],g)
|
||||
|
||||
def storeColorDict():
|
||||
|
||||
"""stores the color dictionary in the document Meta if non-GUI mode"""
|
||||
|
||||
if colors and not FreeCAD.GuiUp:
|
||||
import json
|
||||
d = FreeCAD.ActiveDocument.Meta
|
||||
d["colordict"] = json.dumps(colors)
|
||||
FreeCAD.ActiveDocument.Meta = d
|
||||
|
||||
Reference in New Issue
Block a user