derkork / openscad-graph-editor

OpenSCAD Graph Editor
GNU General Public License v3.0
212 stars 12 forks source link

Possible to add a widget which allows controlling order of operations? #27

Closed WillAdams closed 1 year ago

WillAdams commented 1 year ago

In the context of:

https://github.com/WillAdams/gcodepreview

I am finding that I need to ensure that certain operations occur in a certain order --- trying to figure out a work-around, but nothing is presenting itself --- would a new widget be needed? Or is there something in the UI which I am missing?

derkork commented 1 year ago

I'm not sure i have a firm grasp on the issue right now. Could you make an example that could help me understand better?

WillAdams commented 1 year ago

Here is an example file:

include <C:/Users/willa/OneDrive/Documents/RapCAD/Libraries/gcodepreview.scad>

stocklength = 125;
stockwidth = 75;
stockthickness = 6.35;
toolradius = 1.5875;
zeroheight = "Bottom"; // [Top, Bottom]
stockorigin = "Center"; // [Lower-Left, Center-Left, Top-Left, Center]

generategcode = true;
retractheight = 3;
feedrate = 850;
plungerate = 425;

//add stockthickness if zeroheight = Bottom
safetyheight = retractheight; // + stockthickness;

difference() {
  setupcut(stocklength, stockwidth, stockthickness, zeroheight, stockorigin);

  toolchange(102);
  startspindle (17000);

  writecomment("PREPOSITION FOR RAPID PLUNGE");
  rapid(0,0,safetyheight * 2,0,0,safetyheight);

  plungegcutretract(0, 0, 0, 0, 0, -stockthickness, 102, retractheight, plungerate, feedrate); 

}

closecut();

The command for toolchange must come before the one to start the spindle, then the comment and the rapid command, &c. and finally the closecut command must be the last one --- would it be appropriate to expect a strictly spatial arrangement to work for this sort of thing?

I tried again, and the spatial arrangement seems to be working, so will keep experimenting on that basis.

WillAdams commented 1 year ago

Until I managed an arrangement which didn't work spatially:

image

The order of operations will vary and is dependent on which was first connected --- current is:

toolchange(tool_number = tool);
writecomment(comment = "PREPOSITION FOR RAPID PLUNGE");
rapid(bx = 0, by = 0, bz = (retractheight * 2), ex = 0, ey = 0, ez = retractheight);
startspindle(speed = spindlespeed);

But if I disconnect everything and change the order things are connected:

startspindle(speed = spindlespeed);
rapid(bx = 0, by = 0, bz = (retractheight * 2), ex = 0, ey = 0, ez = retractheight);
writecomment(comment = "PREPOSITION FOR RAPID PLUNGE");
toolchange(tool_number = tool);

Even though everything is in the same position.

flatten.graph.tres.zip

derkork commented 1 year ago

I see, this is indeed a bug, the spatial arrangement works only at the top level but not in nested nodes. I'll make a fix for this.

derkork commented 1 year ago

I also just noticed that you can import a file but there is no way to change that import afterwards. Fixing this as well.

WillAdams commented 1 year ago

Thanks!

I was just deleting and then re-importing, but yes, being able to modify would be nicer.

derkork commented 1 year ago

Okay i just released a fix for this issue. Fixing the imports is a bit more involved and I didn't want to keep you waiting, so 0.5.1 should enable you to continue working.

On an unrelated note, if you add a documentation comment to your functions, OSGE can actually provide you in-editor help and also use the correct type for the parameters:

image

This way you don't need to create extra nodes and can type the values into the module node directly. Another option is to provide default parameters for the module, in which case OSGE will infer the data type from the default value:

image

Another thing that just crossed my mind, if you build your modules like a decorator around their children, you could actually chain the modules from left to right without having to spatially arrange the modules:

image

The "decorator" mode works by first executing the children (children() is the first command) and then executing the actual stuff right after it. OSGE detects that this module is capable of working with childen and will provide a geometry input for it. This way you can just chain them and commands are executed in the order of the chain. The downside of this is that it produces less intuitive OpenScad code:

writecomment(comment = "") { // this is actually executed last
    toolchange(tool_number = undef) { // this is in the middle
        // this is executed first
        setupcut(stocklength = undef, stockwidth = undef, stockthickness = undef, zeroheight = undef, stockorigin = undef);
    }
}
derkork commented 1 year ago

I have now fixed the reimporting, it works a lot better now:

https://user-images.githubusercontent.com/327257/205252887-6b7834e7-6529-4c92-becb-57d7839178c7.mp4