Skip to content
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

Path: add File source to CustomOp #8892

Merged
merged 11 commits into from Jun 30, 2023

Conversation

morganrallen
Copy link
Contributor

original functionality is the default behavior under Text Source

  • Your Pull Request meets the requirements outlined in section 5 of CONTRIBUTING.md for a Valid PR

original functionality is the default behavior under Text Source
@github-actions github-actions bot added the WB CAM Related to the CAM/Path Workbench label Mar 15, 2023
@luzpaz luzpaz requested a review from sliptonic March 15, 2023 11:45
Copy link
Contributor

@cam72cam cam72cam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I'm looking forward to using this feature. I think the code might need some work on the edge cases, but it's on the right track.

gcode_file = self.findGcodeFile(obj.GcodeFile)

# could not determine the path
if not gcode_file: return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want a console error for this scenario?

prospective_path = os.path.join(doc_path, filename)

if os.path.exists(prospective_path):
return prospective_path

def opExecute(self, obj):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to cache the commandlist so if the file is not found the operation is not wiped, but still shows a warning / error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably dump the output of gcode_file into self.Gcode and keep the same commandlist code that existed before. That also allows someone to switch it to "Text" mode and edit the path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editing is an interesting idea but handling divergence worries me, what would your behavior look like if the user has made an edit, then the Op is recomputed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a fair point, it's 'source' instead of 'import'.


with open(gcode_file) as fd:
for l in fd.readlines():
newcommand = Path.Command(str(l))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This worries me a bit, FreeCAD has a fairly strict definition on what GCode Ops are supported and in what format (line numbers/comments/etc...). When a custom op is normally created from a file, it uses the behavior in Post/scripts/gcode_pre.py to only include the "whitelisted" functionality that the post_processors can handle.

On the other hand, it is allowed to put any custom gcode in here regardless. It just may have some odd side effects.

I guess my main concern is that it differs from the "standard" import workflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I've been approaching this with the goal of minimizing changes in default behavior so I just copied how it was done previously. I guess the bigger picture question is, should all internal gcode be parsed to this standard format?

This could also be put behind a Property switch to enable strict behavior without changing the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a tricky thing to answer. Right now gcode_pre is very limited, but that's by design. You are correct that it's a bigger question of how we should handle this scenario in general.

CustomOp is currently loaded with foot-guns, maybe we keep that for now and don't worry about it here.

obj.addProperty(
"App::PropertyStringList",
"Gcode",
"Path",
QT_TRANSLATE_NOOP("App::Property", "The gcode to be inserted"),
)

obj.Source = [ "Text", "File" ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is correct, it should be done through opPropertyEnumerations if I understand correctly.

obj.Source is the value, not the potential valid values and should probably default to "Text".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot remember which Op I was referencing when I wrote this, but it's done in several places. Main/Job.py#525 for example. I'm looking into opPropertyEnumerations now, looks like I can pass this off to the Base class if used right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've submitted PR #9165. If merged it will allow opPropertyEnumerations to be overridden on a subclass to return it's own enumeration values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#9165 has been merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great I'll update this PR and test to ensure it works as expected.

@luzpaz luzpaz changed the title WIP add File source to CustomOp WIP Path: add File source to CustomOp Mar 18, 2023
@luzpaz
Copy link
Contributor

luzpaz commented Mar 18, 2023

Please prepend Path: to commit title before it gets merge. TIA

@freecadci
Copy link

pipeline status for feature branch PR_8892. Pipeline 812838350 was triggered at 942a72f. All CI branches and pipelines.

@freecadci
Copy link

pipeline status for feature branch PR_8892. Pipeline 823344184 was triggered at ff4388a. All CI branches and pipelines.

@sliptonic sliptonic self-assigned this Apr 13, 2023
@freecadci
Copy link

pipeline status for feature branch PR_8892. Pipeline 843831163 was triggered at ff4388a. All CI branches and pipelines.

@morganrallen morganrallen changed the title WIP Path: add File source to CustomOp Path: add File source to CustomOp Jun 30, 2023
@morganrallen
Copy link
Contributor Author

@sliptonic this should be good to merge now

sliptonic and others added 2 commits June 30, 2023 10:06
handles malformed gcode commands
Adds properties to existing custom ops
@sliptonic sliptonic merged commit 1d02f97 into FreeCAD:master Jun 30, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WB CAM Related to the CAM/Path Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants