Skip to content

CAM: Post Process only selected Operations #22764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Mod/CAM/CAMTests/TestPathPost.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check warning on line 1 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing module docstring (missing-module-docstring)
# ***************************************************************************
# * Copyright (c) 2016 sliptonic <[email protected]> *
# * Copyright (c) 2022 Larry Woestman <[email protected]> *
Expand Down Expand Up @@ -132,7 +132,7 @@
# def tearDown(self):
# FreeCAD.closeDocument(self.doc.Name)

def test000(self):

Check warning on line 135 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# Test basic name generation with empty string
FreeCAD.setActiveDocument(self.doc.Label)
teststring = ""
Expand All @@ -154,7 +154,7 @@
self, filename, os.path.join(self.testfilepath, f"{self.testfilename}.nc")
)

def test010(self):

Check warning on line 157 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# Substitute current file path
teststring = "%D/testfile.nc"
self.job.PostProcessorOutputFile = teststring
Expand All @@ -167,7 +167,7 @@
print(os.path.normpath(filename))
assertFilePathsEqual(self, filename, f"{self.testfilepath}/testfile.nc")

def test015(self):

Check warning on line 170 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# Test basic string substitution without splitting
teststring = "~/Desktop/%j.nc"
self.job.PostProcessorOutputFile = teststring
Expand All @@ -184,7 +184,7 @@
# filename = PathPost.resolveFileName(self.job, subpart, 0)
assertFilePathsEqual(self, filename, "~/Desktop/MainJob.nc")

def test020(self):

Check warning on line 187 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
teststring = "%d.nc"
self.job.PostProcessorOutputFile = teststring
Path.Preferences.setOutputFileDefaults(teststring, "Append Unique ID on conflict")
Expand All @@ -197,7 +197,7 @@

assertFilePathsEqual(self, filename, expected)

def test030(self):

Check warning on line 200 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
teststring = "%M/outfile.nc"
self.job.PostProcessorOutputFile = teststring
Path.Preferences.setOutputFileDefaults(teststring, "Append Unique ID on conflict")
Expand All @@ -208,7 +208,7 @@

assertFilePathsEqual(self, filename, f"{self.macro}outfile.nc")

def test040(self):

Check warning on line 211 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# unused substitution strings should be ignored
teststring = "%d%T%t%W%O/testdoc.nc"
self.job.PostProcessorOutputFile = teststring
Expand Down Expand Up @@ -244,7 +244,7 @@
filename = next(filename_generator)
assertFilePathsEqual(self, filename, expected_filename)

def test050(self):

Check warning on line 247 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# explicitly using the sequence number should include it where indicated.
teststring = "%S-%d.nc"
self.job.PostProcessorOutputFile = teststring
Expand Down Expand Up @@ -272,7 +272,7 @@
assertFilePathsEqual(self, filename, f"{self.macro}outfile-Tool.nc")


class TestResolvingPostProcessorName(unittest.TestCase):

Check warning on line 275 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing class docstring (missing-class-docstring)
@classmethod
def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
Expand All @@ -291,7 +291,7 @@
def tearDown(self):
pass

def test010(self):

Check warning on line 294 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Missing function or method docstring (missing-function-docstring)
# Test if post is defined in job
with patch("Path.Post.Processor.PostProcessor.exists", return_value=True):
postname = PathCommand._resolve_post_processor_name(self.job)
Expand Down Expand Up @@ -349,20 +349,20 @@

def test020(self):
# test creation of postprocessor object
post = PostProcessorFactory.get_post_processor(self.job, "generic")
post = PostProcessorFactory.get_post_processor(self.job, "generic", None)
self.assertTrue(post is not None)
self.assertTrue(hasattr(post, "export"))
self.assertTrue(hasattr(post, "_buildPostList"))

def test030(self):
# test wrapping of old school postprocessor scripts
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc", None)
self.assertTrue(post is not None)
self.assertTrue(hasattr(post, "_buildPostList"))

def test040(self):
"""Test that the __name__ of the postprocessor is correct."""
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc", None)
self.assertEqual(post.script_module.__name__, "linuxcnc_post")


Expand All @@ -388,21 +388,21 @@

def test010(self):
"""Test the export function."""
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc", None)
sections = post.export()
for sec in sections:
print(sec[0])

def test020(self):
"""Test the export function with splitting."""
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc", None)
sections = post.export()
for sec in sections:
print(sec[0])

def test030(self):
"""Test the export function with splitting."""
post = PostProcessorFactory.get_post_processor(self.job, "generic")
post = PostProcessorFactory.get_post_processor(self.job, "generic", None)
sections = post.export()
for sec in sections:
print(sec[0])
Expand Down Expand Up @@ -576,18 +576,18 @@
def test010(self):
"""Test the utility functions in the PostUtils.py file."""
commands = [
Path.Command("G1 X-7.5 Y5.0 Z0.0"),

Check failure on line 579 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G2 I2.5 J0.0 K0.0 X-5.0 Y7.5 Z0.0"),

Check failure on line 580 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G1 X5.0 Y7.5 Z0.0"),

Check failure on line 581 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G2 I0.0 J-2.5 K0.0 X7.5 Y5.0 Z0.0"),

Check failure on line 582 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G1 X7.5 Y-5.0 Z0.0"),

Check failure on line 583 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G2 I-2.5 J0.0 K0.0 X5.0 Y-7.5 Z0.0"),

Check failure on line 584 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G1 X-5.0 Y-7.5 Z0.0"),

Check failure on line 585 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G2 I0.0 J2.5 K0.0 X-7.5 Y-5.0 Z0.0"),

Check failure on line 586 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
Path.Command("G1 X-7.5 Y0.0 Z0.0"),

Check failure on line 587 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Command' member (no-member)
]

testpath = Path.Path(commands)

Check failure on line 590 in src/Mod/CAM/CAMTests/TestPathPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Module 'Path' has no 'Path' member (no-member)
self.assertTrue(len(testpath.Commands) == 9)
self.assertTrue(len([c for c in testpath.Commands if c.Name in ["G2", "G3"]]) == 4)

Expand Down Expand Up @@ -628,7 +628,7 @@
FreeCAD.closeDocument(cls.doc.Name)

def setUp(self):
self.pp = PathPost.PostProcessor(self.job, "generic", "", "")
self.pp = PathPost.PostProcessor(self.job, None, "generic", "", "")

def tearDown(self):
pass
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredCentroidPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_centroid")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_centroid", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredGrblPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_grbl")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_grbl", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredLinuxCNCPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_linuxcnc")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_linuxcnc", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredMach3Mach4Post.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUpClass(cls) -> None:
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_mach3_mach4")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_mach3_mach4", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredMassoG3Post.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_masso_g3")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_masso_g3", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredTestDressupPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/dressuptest.FCStd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test", None)

# there are 4 operations in dressuptest.FCStd
# every operation uses a different ToolController
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredTestPost.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredTestPostGCodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestRefactoredTestPostMCodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def setUpClass(cls):
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "refactored_test", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/CAMTests/TestSnapmakerPost.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# ***************************************************************************
# * Copyright (c) 2025 Clair-Loup Sergent <[email protected]> *

Check warning on line 3 in src/Mod/CAM/CAMTests/TestSnapmakerPost.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Sergent ==> Sergeant
# * *
# * Licensed under the EUPL-1.2 with the specific provision *
# * (EUPL articles 14 & 15) that the applicable law is the French law. *
Expand Down Expand Up @@ -40,7 +40,7 @@
FreeCAD.ConfigSet("SuppressRecomputeRequiredDialog", "True")
cls.doc = FreeCAD.open(FreeCAD.getHomePath() + "/Mod/CAM/CAMTests/boxtest.fcstd")
cls.job = cls.doc.getObject("Job")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "snapmaker")
cls.post = PostProcessorFactory.get_post_processor(cls.job, "snapmaker", None)
# locate the operation named "Profile"
for op in cls.job.Operations.Group:
if op.Label == "Profile":
Expand Down
17 changes: 14 additions & 3 deletions src/Mod/CAM/InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,18 @@ def Deactivated(self):

def ContextMenu(self, recipient):
menuAppended = False
if len(FreeCADGui.Selection.getSelection()) == 1:
obj = FreeCADGui.Selection.getSelection()[0]
selection = FreeCADGui.Selection.getSelection()
if len(selection) == 1:
obj = selection[0]
if obj.isDerivedFrom("Path::Feature"):
self.appendContextMenu("", "Separator")
self.appendContextMenu("", ["CAM_Post"])
self.appendContextMenu("", ["CAM_Inspect"])
selectedName = obj.Name
if "Remote" in selectedName:
self.appendContextMenu("", ["Refresh_Path"])
if "Job" in selectedName:
self.appendContextMenu("", ["CAM_ExportTemplate"] + self.toolbitctxmenu)
self.appendContextMenu("", ["CAM_ExportTemplate"])
menuAppended = True
if isinstance(obj.Proxy, Path.Op.Base.ObjectOp):
self.appendContextMenu("", ["CAM_OperationCopy", "CAM_OpActiveToggle"])
Expand All @@ -344,6 +346,7 @@ def ContextMenu(self, recipient):
"Profile" in selectedName
or "Contour" in selectedName
or "Dressup" in selectedName
or "Pocket" in selectedName
):
self.appendContextMenu("", "Separator")
# self.appendContextMenu("", ["Set_StartPoint"])
Expand All @@ -354,6 +357,14 @@ def ContextMenu(self, recipient):
if isinstance(obj.Proxy, Path.Tool.ToolBit):
self.appendContextMenu("", ["CAM_ToolBitSave", "CAM_ToolBitSaveAs"])
menuAppended = True

elif len(selection) > 1:
for obj in selection:
if not obj.isDerivedFrom("Path::Feature"):
break
else:
self.appendContextMenu("", ["CAM_Post"])

if menuAppended:
self.appendContextMenu("", "Separator")

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/Path/Main/Gui/PreferencesJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def setupStock(self, index):

def getPostProcessor(self, name):
if not name in self.processor:
processor = PostProcessorFactory.get_post_processor(None, name)
processor = PostProcessorFactory.get_post_processor(None, name, None)
self.processor[name] = processor
return processor
return self.processor[name]
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/CAM/Path/Main/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ def onDocumentRestored(self, obj):

def onChanged(self, obj, prop):
if prop == "PostProcessor" and obj.PostProcessor:
processor = PostProcessorFactory.get_post_processor(obj, obj.PostProcessor)
processor = PostProcessorFactory.get_post_processor(obj, obj.PostProcessor, None)
self.tooltip = processor.tooltip
self.tooltipArgs = processor.tooltipArgs

Expand Down
34 changes: 29 additions & 5 deletions src/Mod/CAM/Path/Post/Command.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def _resolve_post_processor_name(job):

if valid_name and PostProcessor.exists(valid_name):
return valid_name
else:
raise ValueError(f"Post processor not identified.")
raise ValueError("Post processor not identified.")


class DlgSelectPostProcessor:
Expand Down Expand Up @@ -108,12 +107,14 @@ def GetResources(self):
"Pixmap": "CAM_Post",
"MenuText": QT_TRANSLATE_NOOP("CAM_Post", "Post Process"),
"Accel": "P, P",
"ToolTip": QT_TRANSLATE_NOOP("CAM_Post", "Post Process the selected Job"),
"ToolTip": QT_TRANSLATE_NOOP(
"CAM_Post", "Post Process the selected Job or selected operations"
),
}

def IsActive(self):
selected = FreeCADGui.Selection.getSelectionEx()
if len(selected) != 1:
if len(selected) == 0:
return False

selected_object = selected[0].Object
Expand Down Expand Up @@ -203,6 +204,27 @@ def Activated(self):
Path.Log.debug(self.candidate.Name)
FreeCAD.ActiveDocument.openTransaction("Post Process the Selected Job")

selected = FreeCADGui.Selection.getSelection()

operations = []
if len(self.candidate.Operations.Group) > 1 and (
len(selected) > 1 or selected[0] in self.candidate.Operations.Group
):
msgBox = QtGui.QMessageBox()
msgBox.setText("<p align='center'>What needs to be exported?</p>")
msgBox.setWindowTitle("Post Process")
msgBox.findChild(QtGui.QGridLayout).setColumnMinimumWidth(1, 200)
btn1 = msgBox.addButton("Only selected", QtGui.QMessageBox.ButtonRole.YesRole)
btn2 = msgBox.addButton("All", QtGui.QMessageBox.ButtonRole.NoRole)
msgBox.setDefaultButton(btn2)
msgBox.exec()

if msgBox.clickedButton() == btn1:
print("Post process only selected operations")
for op in selected:
if op in self.candidate.Operations.Group:
operations.append(op)

postprocessor_name = _resolve_post_processor_name(self.candidate)
Path.Log.debug(f"Post Processor: {postprocessor_name}")

Expand All @@ -211,7 +233,9 @@ def Activated(self):
return

# get a postprocessor
postprocessor = PostProcessorFactory.get_post_processor(self.candidate, postprocessor_name)
postprocessor = PostProcessorFactory.get_post_processor(
self.candidate, postprocessor_name, operations
)

post_data = postprocessor.export()
# None is returned if there was an error during argument processing
Expand Down
31 changes: 22 additions & 9 deletions src/Mod/CAM/Path/Post/Processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PostProcessorFactory:
"""Factory class for creating post processors."""

@staticmethod
def get_post_processor(job, postname):
def get_post_processor(job, postname, operations):
# Log initial debug message
Path.Log.debug("PostProcessorFactory.get_post_processor()")

Expand All @@ -109,17 +109,19 @@ def get_post_processor(job, postname):

try:
PostClass = getattr(module, class_name)
return PostClass(job)
return PostClass(job, operations)
except AttributeError:
# Return an instance of WrapperPost if no valid module is found
Path.Log.debug(f"Post processor {postname} is a script")
return WrapperPost(job, module_path, module_name)
return WrapperPost(job, operations, module_path, module_name)

return None


class PostProcessor:
"""Base Class. All non-legacy postprocessors should inherit from this class."""

def __init__(self, job, tooltip, tooltipargs, units, *args, **kwargs):
def __init__(self, job, operations, tooltip, tooltipargs, units, *args, **kwargs):
self._tooltip = tooltip
self._tooltipargs = tooltipargs
self._units = units
Expand All @@ -128,6 +130,11 @@ def __init__(self, job, tooltip, tooltipargs, units, *args, **kwargs):
self._kwargs = kwargs
self.reinitialize()

if operations:
self._operations = operations
elif job.Operations:
self._operations = job.Operations.Group

@classmethod
def exists(cls, processor):
return processor in Path.Preferences.allAvailablePostProcessors()
Expand Down Expand Up @@ -193,7 +200,8 @@ def __fixtureSetup(order, fixture, job):
sublist = [__fixtureSetup(index, f, self._job)]

# Now generate the gcode
for obj in self._job.Operations.Group:
# for obj in self._job.Operations.Group:
for obj in self._operations:
tc = PathUtil.toolControllerForOp(obj)
if tc is not None and PathUtil.activeForOp(obj):
if tc.ToolNumber != currTool:
Expand Down Expand Up @@ -230,7 +238,8 @@ def commitToPostlist():
postlist.append((toolstring, sublist))

Path.Log.track(self._job.PostProcessorOutputFile)
for idx, obj in enumerate(self._job.Operations.Group):
# for idx, obj in enumerate(self._job.Operations.Group):
for idx, obj in enumerate(self._operations):
Path.Log.track(obj.Label)

# check if the operation is active
Expand Down Expand Up @@ -276,7 +285,8 @@ def commitToPostlist():
currTool = None

# Now generate the gcode
for obj in self._job.Operations.Group:
# for obj in self._job.Operations.Group:
for obj in self._operations:

# check if the operation is active
if not PathUtil.activeForOp(obj):
Expand Down Expand Up @@ -465,8 +475,11 @@ def reinitialize(self) -> None:
class WrapperPost(PostProcessor):
"""Wrapper class for old post processors that are scripts."""

def __init__(self, job, script_path, module_name, *args, **kwargs):
super().__init__(job, tooltip=None, tooltipargs=None, units=None, *args, **kwargs)
def __init__(self, job, operations, script_path, module_name, *args, **kwargs):
super().__init__(
job, operations, tooltip=None, tooltipargs=None, units=None, *args, **kwargs
)
self.operations = operations
self.script_path = script_path
self.module_name = module_name
Path.Log.debug(f"WrapperPost.__init__({script_path})")
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/CAM/Path/Post/scripts/generic_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@


class Generic(PostProcessor):
def __init__(self, job):
def __init__(self, job, operations):
super().__init__(
job,
operations,
tooltip=translate("CAM", "Generic post processor"),
tooltipargs=["arg1", "arg2"],
units="kg",
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/CAM/Path/Post/scripts/refactored_centroid_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ class Refactored_Centroid(PostProcessor):
def __init__(
self,
job,
operations,
tooltip=translate("CAM", "Refactored Centroid post processor"),
tooltipargs=[""],
units="Metric",
) -> None:
super().__init__(
job=job,
operations=operations,
tooltip=tooltip,
tooltipargs=tooltipargs,
units=units,
Expand Down
Loading
Loading