Skip to content

Commit

Permalink
Fix bug when not generating sketch (issue #42).
Browse files Browse the repository at this point in the history
Support separate color for bend lines (issue #41)
  • Loading branch information
shaise committed Sep 15, 2018
1 parent a8cce0a commit 33a8fb7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ http://theseger.com/projects/2015/06/sheet-metal-addon-for-freecad/
Starting from FreeCAD 0.17 it can be installed via the [Addon Manager](https://github.com/FreeCAD/FreeCAD-addons) (from Tools menu)

#### Release notes:
* V0.2.01 15 Sep 2018: Fix bug when not generating sketch (issue #42). Support separate color for bend lines (issue #41)
* V0.2.00 04 Sep 2018: Make SheetMetal compatible with Python 3 and QT 5
* V0.1.40 20 Aug 2018: Merge Ulrich's V20 unfolder script - supports many more sheet metal cases and more robust
* V0.1.32 25 Jun 2018: New feature: Option to separately unfold bends. Thank you jaisejames!
Expand Down
50 changes: 36 additions & 14 deletions SheetMetalUnfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def main():
from SheetMetalCmd import iconPath

genSketchChecked = True
sepSketchChecked = False
genObjTransparency = 70
manKFactor = -100.0

Expand Down Expand Up @@ -2124,6 +2125,10 @@ def __init__(self):
self.checkSketch = QtGui.QCheckBox(self.form)
self.checkSketch.setObjectName(_fromUtf8("checkSketch"))
self.verticalLayout.addWidget(self.checkSketch)
self.checkSketch.stateChanged.connect(self.checkSketchChange)
self.checkSeparate = QtGui.QCheckBox(self.form)
self.checkSeparate.setObjectName(_fromUtf8("checkSeparate"))
self.verticalLayout.addWidget(self.checkSeparate)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
Expand Down Expand Up @@ -2174,6 +2179,8 @@ def __init__(self):

if genSketchChecked:
self.checkSketch.setCheckState(QtCore.Qt.CheckState.Checked)
if sepSketchChecked:
self.checkSeparate.setCheckState(QtCore.Qt.CheckState.Checked)
if manKFactor < -9.0:
self.kFactSpin.setEnabled(False)
self.kFactSpin.setProperty("value", 0.5)
Expand All @@ -2182,10 +2189,12 @@ def __init__(self):
self.kFactSpin.setProperty("value", manKFactor)
self.transSpin.setProperty("value", genObjTransparency)

self.checkSketchChange()
self.retranslateUi()




#self.grid = QtGui.QGridLayout(self.form)
#self.grid.setObjectName("grid")
#self.title = QtGui.QLabel(self.form)
Expand All @@ -2209,8 +2218,9 @@ def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok)

def accept(self):
global genSketchChecked, genObjTransparency, manKFactor
global genSketchChecked, sepSketchChecked, genObjTransparency, manKFactor
genSketchChecked = self.checkSketch.isChecked()
sepSketchChecked = self.checkSeparate.isChecked()
if self.checkKfact.isChecked():
manKFactor = self.kFactSpin.value()
else:
Expand All @@ -2237,35 +2247,47 @@ def accept(self):
if len(foldLines) > 0:
co = Part.makeCompound(foldLines)
grp2 = Drawing.projectEx(co, norm)
edges.append(grp2[0])
p = Part.makeCompound(edges)
try:
sk = Draft.makeSketch(p.Edges, autoconstraints = True)
sk.Label = "Unfold_Sketch"
except:
skb = doc.ActiveObject
doc.removeObject(skb.Name)
SMWarning("discretizing Sketch")
sk = SMmakeSketchfromEdges(p.Edges,"Unfold_Sketch")
if not sepSketchChecked:
edges.append(grp2[0])
self.generateSketch(edges, "Unfold_Sketch", (0.0,0.0,0.5))
if len(foldLines) > 0 and sepSketchChecked:
foldEdges = []
foldEdges.append(grp2[0])
self.generateSketch(foldEdges, "Unfold_Sketch_bends", (0.5,0.0,0.0))
doc.commitTransaction()
docG = FreeCADGui.ActiveDocument
docG.getObject(a.Name).Transparency = genObjTransparency
docG.getObject(sk.Name).LineColor = (0.0,0.0,0.5)
docG.getObject(sk.Name).PointColor = (0.0,0.0,0.5)
doc.recompute()
FreeCAD.ActiveDocument.recompute()
return True

def generateSketch(self, edges, name, color):
docG = FreeCADGui.ActiveDocument
p = Part.makeCompound(edges)
try:
sk = Draft.makeSketch(p.Edges, autoconstraints = True)
sk.Label = name
except:
skb = doc.ActiveObject
doc.removeObject(skb.Name)
SMWarning("discretizing Sketch")
sk = SMmakeSketchfromEdges(p.Edges,name)
docG.getObject(sk.Name).LineColor = color
docG.getObject(sk.Name).PointColor = color

def getStandardButtons(self):
return int(QtGui.QDialogButtonBox.Ok) + int(QtGui.QDialogButtonBox.Cancel)

def checkKfactChange(self):
self.kFactSpin.setEnabled(self.checkKfact.isChecked())


def checkSketchChange(self):
self.checkSeparate.setEnabled(self.checkSketch.isChecked())

def retranslateUi(self):
self.form.setWindowTitle(_translate("SheetMetal", "Unfold sheet metal onject", None))
self.checkSketch.setText(_translate("SheetMetal", "Generate projection sketch", None))
self.checkSeparate.setText(_translate("SheetMetal", "Separate projection layers", None))
self.checkKfact.setText(_translate("SheetMetal", "Manual K-factor", None))
self.label.setText(_translate("SheetMetal", "Unfold object transparency", None))
self.transSpin.setSuffix(_translate("SheetMetal", "%", None))
Expand Down

0 comments on commit 33a8fb7

Please sign in to comment.