Skip to content

Commit

Permalink
Reinstate unfold unattended command. Issue #426
Browse files Browse the repository at this point in the history
  • Loading branch information
shaise committed Dec 21, 2024
1 parent df8fea1 commit 90019d0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 30 deletions.
6 changes: 6 additions & 0 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import FreeCAD
from FreeCAD import Gui
import SheetMetalTools
from engineering_mode import engineering_mode_enabled

# add translations path
SMWBPath = SheetMetalTools.mod_path
Expand All @@ -41,6 +42,7 @@ class SMWorkbench(Workbench):
global SMIconPath
global SMWBPath
global SHEETMETALWB_VERSION
global engineering_mode_enabled

MenuText = FreeCAD.Qt.translate("SheetMetal", "Sheet Metal")
ToolTip = FreeCAD.Qt.translate(
Expand Down Expand Up @@ -83,6 +85,10 @@ def Initialize(self):
"SheetMetal_Forming",
"SheetMetal_BaseShape",
] # A list of command names created in the line above
if engineering_mode_enabled():
self.list.insert(
self.list.index("SheetMetal_Unfold") + 1, "SheetMetal_UnattendedUnfold"
)
self.appendToolbar(
FreeCAD.Qt.translate("SheetMetal", "Sheet Metal"), self.list
) # creates a new toolbar with your commands
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ Starting from FreeCAD 0.17 it can be installed via the [Addon Manager](https://g
* FreeCAD Forum announcement/discussion [thread](https://forum.freecadweb.org/viewtopic.php?f=3&t=60818)

#### Release notes:
* V0.6.10 20 Dec 2024: Make unfold object parametric.
* V0.6.02 14 Dec 2024: Fix Base Shape UI error when using different language.
* V0.6.01 06 Dec 2024: Add GUI to BaseBend command.
* V0.6.11 20 Dec 2024: Reinstate unattended unfold command.
* V0.6.10 20 Dec 2024: Make unfold object parametric.
* V0.6.02 14 Dec 2024: Fix Base Shape UI error when using different language.
* V0.6.01 06 Dec 2024: Add GUI to BaseBend command.
- Fix detection of basebend belonging to body or not.
- Update translations by [@hasecilu][hasecilu].
- Fix python compatibility by [@Syres916][Syres916].
Expand Down
24 changes: 14 additions & 10 deletions SheetMetalTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,23 @@ def taskLoadUI(*args):
forms.append(Gui.PySideUic.loadUi(path))
return forms

def smGuiExportSketch(sketches, fileType, fileName):
filePath, _ = QtGui.QFileDialog.getSaveFileName(
Gui.getMainWindow(),
translate("SheetMetal","Export unfold sketch"),
fileName, # Default file path
f"Vector Files (*.{fileType})" # File type filters
)
def smGuiExportSketch(sketches, fileType, fileName, useDialog = True):
if useDialog:
filePath, _ = QtGui.QFileDialog.getSaveFileName(
Gui.getMainWindow(),
translate("SheetMetal","Export unfold sketch"),
fileName, # Default file path
f"Vector Files (*.{fileType})" # File type filters
)
else:
filePath = fileName
if filePath:
if fileType == "dxf":
importDXF.export(sketches, filePath)
else:
importSVG.export(sketches, filePath)

def smAddNewObject(baseObj, newObj, activeBody, taskPanel):
def smAddNewObject(baseObj, newObj, activeBody, taskPanel = None):
if activeBody is not None:
activeBody.addObject(newObj)
viewConf = GetViewConfig(baseObj)
Expand All @@ -379,8 +382,9 @@ def smAddNewObject(baseObj, newObj, activeBody, taskPanel):
#newObj.baseObject[0].ViewObject.Visibility = False
baseObj.ViewObject.Visibility = False
FreeCAD.ActiveDocument.recompute()
dialog = taskPanel(newObj)
Gui.Control.showDialog(dialog)
if taskPanel is not None:
dialog = taskPanel(newObj)
Gui.Control.showDialog(dialog)
return

def smCreateNewObject(baseObj, name, allowPartDesign = True):
Expand Down
82 changes: 66 additions & 16 deletions SheetMetalUnfoldCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@
KFACTOR = 0.40


##########################################################################################################
# Helper functions
##########################################################################################################
def smUnfoldExportSketches(obj, useDialog = True):
if len(obj.UnfoldSketches) == 0:
return
sketches = []
if len(obj.UnfoldSketches) == 1:
sketchNames = [obj.UnfoldSketches[0]]
else:
sketchNames = obj.UnfoldSketches[1:]
for name in sketchNames:
sketch = obj.Document.getObject(name)
if sketch is None:
return
sketches.append(sketch)
exptype = obj.Proxy.ExportType
filename = f"{FreeCAD.ActiveDocument.FileName[0:-6]}-{obj.Name}.{exptype}"
SheetMetalTools.smGuiExportSketch(sketches, exptype, filename, useDialog)


##########################################################################################################
# Object class
##########################################################################################################
Expand Down Expand Up @@ -368,22 +389,7 @@ def reject(self):
FreeCAD.ActiveDocument.recompute()

def doExport(self):
obj = self.obj
if len(obj.UnfoldSketches) == 0:
return
sketches = []
if len(obj.UnfoldSketches) == 1:
sketchNames = [obj.UnfoldSketches[0]]
else:
sketchNames = obj.UnfoldSketches[1:]
for name in sketchNames:
sketch = obj.Document.getObject(name)
if sketch is None:
return
sketches.append(sketch)
exptype = self.obj.Proxy.ExportType
filename = f"{FreeCAD.ActiveDocument.FileName[0:-6]}-{obj.Name}.{exptype}"
SheetMetalTools.smGuiExportSketch(sketches, exptype, filename)
smUnfoldExportSketches(self.obj)

def populateMdsList(self):
sheetnames = SheetMetalKfactor.getSpreadSheetNames()
Expand Down Expand Up @@ -514,5 +520,49 @@ def Activated(self):
def IsActive(self):
return len(SheetMetalTools.smObjectsToRecompute) > 0

class SMUnfoldUnattendedCommandClass:
"""Unfold object"""

def GetResources(self):
__dir__ = os.path.dirname(__file__)
iconPath = os.path.join(__dir__, "Resources", "icons")
return {
"Pixmap": os.path.join(
iconPath, "SheetMetal_UnfoldUnattended.svg"
), # the name of a svg file available in the resources
"MenuText": FreeCAD.Qt.translate("SheetMetal", "Unattended Unfold"),
"Accel": "U",
"ToolTip": FreeCAD.Qt.translate(
"SheetMetal",
"Flatten folded sheet metal object with default options\n"
"1. Select flat face on sheetmetal shape.\n"
"2. Click this command to unfold the object with last used parameters.",
),
}

def Activated(self):
sel = Gui.Selection.getSelectionEx()[0]
selobj = sel.Object
newObj, activeBody = SheetMetalTools.smCreateNewObject(selobj, "Unfold", False)
if newObj is None:
return
SMUnfold(newObj, selobj, sel.SubElementNames)
SMUnfoldViewProvider(newObj.ViewObject)
SheetMetalTools.smAddNewObject(selobj, newObj, activeBody)
smUnfoldExportSketches(newObj, False)
return

def IsActive(self):
if (
len(Gui.Selection.getSelection()) != 1
or len(Gui.Selection.getSelectionEx()[0].SubElementNames) != 1
):
return False
selFace = Gui.Selection.getSelectionEx()[0].SubObjects[0]

return isinstance(selFace.Surface, Part.Plane)


Gui.addCommand("SheetMetal_UnattendedUnfold", SMUnfoldUnattendedCommandClass())
Gui.addCommand("SheetMetal_Unfold", SMUnfoldCommandClass())
Gui.addCommand("SheetMetal_UnfoldUpdate", SMRecomputeUnfoldsCommandClass())
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package format="1" xmlns="https://wiki.freecad.org/Package_Metadata">
<name>SheetMetal Workbench</name>
<description>A simple sheet metal tools workbench for FreeCAD.</description>
<version>0.6.10</version>
<version>0.6.11</version>
<date>2024-12-20</date>
<maintainer email="[email protected]">Shai Seger</maintainer>
<license file="LICENSE">LGPL-2.1-or-later</license>
Expand Down

0 comments on commit 90019d0

Please sign in to comment.