Skip to content

Commit

Permalink
Show edges in coin mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Feb 28, 2024
1 parent 52702de commit dc85ff6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
11 changes: 9 additions & 2 deletions ifc_commands.py
Expand Up @@ -121,10 +121,17 @@ def GetResources(self):

def Activated(self):
doc = FreeCAD.ActiveDocument
if hasattr(doc, "Proxy") and hasattr(doc.Proxy, "ifcfile") and doc.Proxy.ifcfile:
FreeCAD.Console.PrintError(translate("BIM","The active document is already an IFC document"))
if (
hasattr(doc, "Proxy")
and hasattr(doc.Proxy, "ifcfile")
and doc.Proxy.ifcfile
):
FreeCAD.Console.PrintError(
translate("BIM", "The active document is already an IFC document")
)
else:
import ifc_tools

ifc_tools.convert_document(doc)


Expand Down
29 changes: 25 additions & 4 deletions ifc_generator.py
Expand Up @@ -72,7 +72,9 @@ def generate_geometry(obj, cached=False):
else:
print_debug(obj)
elif basenode and obj.ShapeMode == "Coin":
node, colors, placement = generate_coin(ifcfile, elements, cached)
node, colors, placement = generate_coin(
ifcfile, elements, cached, obj.ViewObject
)
if node:
basenode.addChild(node)
else:
Expand Down Expand Up @@ -186,7 +188,7 @@ def generate_shape(ifcfile, elements, cached=False):
return shape, colors


def generate_coin(ifcfile, elements, cached=False):
def generate_coin(ifcfile, elements, cached=False, vobj=None):
"""Returns a Coin node for a list of elements"""

# setup
Expand Down Expand Up @@ -275,13 +277,32 @@ def generate_coin(ifcfile, elements, cached=False):
]
faceset = coin.SoIndexedFaceSet()
faceset.coordIndex.setValues(faces)
node.addChild(faceset)

# edges color
mat = coin.SoMaterial()
lcolor = getattr(vobj, "LineColor", (0, 0, 0))
mat.diffuseColor.setValue(lcolor[0], lcolor[1], lcolor[2])
node.addChild(mat)

# edges style
dst = coin.SoDrawStyle()
dst.lineWidth = getattr(vobj, "LineWidth", 1)
node.addChild(dst)

# get edges
edges = list(item.geometry.edges)
edges = [
e for i in range(0, len(edges), 2) for e in edges[i : i + 2] + [-1]
]
edgeset = coin.SoIndexedLineSet()
edgeset.coordIndex.setValues(edges)
node.addChild(edgeset)

# update cahce
cache["Coin"][item.id] = node
cache["Placement"][item.id] = placement

# apply coin node
node.addChild(faceset)
if grouping:
# if we are joining nodes together, their placement
# must be baked in
Expand Down
2 changes: 0 additions & 2 deletions ifc_objects.py
Expand Up @@ -24,7 +24,6 @@


class ifc_object:

"""Base class for all IFC-based objects"""

def __init__(self, otype=None):
Expand Down Expand Up @@ -247,7 +246,6 @@ def edit_group(self, obj):


class document_object:

"""Holder for the document's IFC objects"""

def __init__(self):
Expand Down
13 changes: 10 additions & 3 deletions ifc_observer.py
Expand Up @@ -221,18 +221,24 @@ def propose_conversion(self):
if not params.GetBool("SingleDocAskAgain", True):
if params.GetBool("SingleDoc", True):
self.full = params.GetBool("ProjectFull", False)
QtCore.QTimer.singleShot(1000, self.convert_document)
QtCore.QTimer.singleShot(
1000, self.convert_document
)
return
else:
return
d = os.path.dirname(__file__)
dlg = FreeCADGui.PySideUic.loadUi(
os.path.join(d, "ui", "dialogConvertDocument.ui")
)
dlg.checkStructure.setChecked(params.GetBool("ProjectFull", False))
dlg.checkStructure.setChecked(
params.GetBool("ProjectFull", False)
)
result = dlg.exec_()
self.full = dlg.checkStructure.isChecked()
params.SetBool("SingleDocAskAgain", not dlg.checkAskAgain.isChecked())
params.SetBool(
"SingleDocAskAgain", not dlg.checkAskAgain.isChecked()
)
if result:
params.SetBool("SingleDoc", True)
params.SetBool("ProjectFull", self.full)
Expand All @@ -249,6 +255,7 @@ def convert_document(self):
ifc_tools.convert_document(doc, strategy=2, silent=True)
if self.full:
import Arch

site = ifc_tools.aggregate(Arch.makeSite(), doc)
building = ifc_tools.aggregate(Arch.makeBuilding(), site)
storey = ifc_tools.aggregate(Arch.makeFloor(), building)
Expand Down
13 changes: 9 additions & 4 deletions ifc_viewproviders.py
Expand Up @@ -25,7 +25,6 @@


class ifc_vp_object:

"""Base class for all blenderbim view providers"""

def attach(self, vobj):
Expand All @@ -45,6 +44,15 @@ def onChanged(self, vobj, prop):
for child in vobj.Object.Group:
child.ViewObject.Visibility = vobj.Visibility
return True
elif prop == "LineColor" and vobj.Object.ShapeMode == "Coin":
lc = vobj.LineColor
basenode = vobj.RootNode.getChild(2).getChild(0)
if basenode.getNumChildren() == 5:
basenode[4][0][3].diffuseColor.setValue(lc[0], lc[1], lc[2])
elif prop == "LineWidth" and vobj.Object.ShapeMode == "Coin":
basenode = vobj.RootNode.getChild(2).getChild(0)
if basenode.getNumChildren() == 5:
basenode[4][0][4].lineWidth = vobj.LineWidth

def __getstate__(self):
return None
Expand Down Expand Up @@ -311,7 +319,6 @@ def createGroup(self):


class ifc_vp_document(ifc_vp_object):

"""View provider for the IFC document object"""

def getIcon(self):
Expand Down Expand Up @@ -422,7 +429,6 @@ def diff(self):


class ifc_vp_group:

"""View provider for the IFC group object"""

def getIcon(self):
Expand All @@ -437,7 +443,6 @@ def getIcon(self):


class ifc_vp_material:

"""View provider for the IFC group object"""

def attach(self, vobj):
Expand Down

0 comments on commit dc85ff6

Please sign in to comment.