GilesBathgate / RapCAD

Rapid prototyping CAD IDE for RepRap and RepStrap 3D printing machines.
https://rapcad.org
GNU General Public License v3.0
153 stars 25 forks source link

Warning for modules that shouldn't have children. #41

Open WillAdams opened 2 years ago

WillAdams commented 2 years ago

If one has modules such as "setupcut" and "gcut" in https://github.com/WillAdams/gcodepreview/blob/main/gcodepreviewing.scad

and one calls them using a file such as:

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

difference() {
  setupcut(9, 4, 1, "Top", "Center")

  gcut(0, 0, 0, 4.5, 2, -1, 390);

}

the text appears out-of-order in the console:

G1 X 0  Y 0 Z 0
G1 X 4.5  Y 2 Z -1
(STOCK/BLOCK,  9 ,  4 ,  1 )
G90
G21
(Move to safe Z to avoid workholding)
G53G0Z-5.000
M05
Total compiling time: 0h 0m 0s 20ms.
Я:

and in the file.

Adding the semicolon:

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

difference() {
  setupcut(9, 4, 1, "Top", "Center");

  gcut(0, 0, 0, 4.5, 2, -1, 390);

}

Outputs things as expected:

(STOCK/BLOCK,  9 ,  4 ,  1 )
G90
G21
(Move to safe Z to avoid workholding)
G53G0Z-5.000
M05
G1 X 0  Y 0 Z 0
G1 X 4.5  Y 2 Z -1
Total compiling time: 0h 0m 0s 76ms.
Я: 
GilesBathgate commented 2 years ago

@WillAdams Well, it's actually a feature.

This allows you to position objects relatively. i.e:

cube([1,1,1])
  translate([0,0,1]cube([2,2,2])
    translate([0,0,2])cube([3,3,3]);

I admit it probably doesn't make sense for writeln, I guess it could emit a warning.

writeln("c") { 
   writeln("a");
   writeln("b");
}

Warning: nested writeln will output in hierarchical order

WillAdams commented 2 years ago

Oh. I would have put all those in groups using {} if writing things out by hand.

The warning makes a lot of sense --- feel free to close this ticket or leave it open as a reminder to implement that.

GilesBathgate commented 2 years ago

I would have put all those in groups using {} if writing things out by hand.

Yes this is probably clearer.

cube([1,1,1]) {
  translate([0,0,1]cube([2,2,2]) {
    translate([0,0,2])cube([3,3,3]);
  }
}

But I have to support both for it to work consistently. The idea is inspired by so called relativity.scad: https://github.com/davidson16807/relativity.scad