Page 1 of 1

Function Order

Posted: Sun Nov 17, 2013 4:17 pm
by jthornton
Are the functions called in some kind of order in GCode.js or is it top down execution?

When you create a new configuration file do you need to keep the new functions in the same order as GCode.js?

Thanks
JT

Re: Function Order

Posted: Sun Nov 17, 2013 10:09 pm
by andrew
The order in the file is irrelevant (as with any functional programming I am aware of).

The call stack looks roughly like this:
writeHeader
exportFile
    exportDocument
        exportEntities
            exportContour (for each contour)
                exportContourEntity (for each entity in that contour)
                    exportEntity
                        exportLineSegment (for each line segment of the broken down entity)
                            writeRapidLinearMove (if the segment does not connect to the previous segment)
                            writeLinearMove
                        exportArcSegment (for each arc segment of the broken down entity)
                            writeRapidLinearMove (if the segment does not connect to the previous segment)
                            writeCircularMove
writeFooter
There are a lot more functions obviously, but these are the most important ones that are called by QCAD/CAM directly or indirectly by default.
Any of these functions can be overwritten by a machine configuration which can of course change the whole call stack completely.

Re: Function Order

Posted: Mon Nov 18, 2013 1:42 pm
by jthornton
Andrew,

That helps me understand where I was having some difficulty, thanks for posting that.

JT

Re: Function Order

Posted: Mon Nov 18, 2013 11:31 pm
by jthornton
Does writeHeader come before the creation of the CAM Configuration page? Does exportFile or exportDocument create the CAM Configuration page? If so that explains why I could not get my layer options in writeHeader where I was hoping to put a comment stating the torch settings.

JT

Re: Function Order

Posted: Mon Nov 18, 2013 11:39 pm
by andrew
jthornton wrote:Does writeHeader come before the creation of the CAM Configuration page? Does exportFile or exportDocument create the CAM Configuration page?
No and no. The dialog is configured and displayed before anything is being exported.

Re: Function Order

Posted: Tue Nov 19, 2013 1:28 pm
by jthornton
I can't seem to get anything to work in writeHeader that calls another function. The following code fails for some reason that I don't understand.

Code: Select all

// add preamble
Plasma.prototype.writeHeader = function() {
    this.writeLine("G20 G17 G40 G49 G54 G64 P0.005 G80 G90 G94");
    this.torchNozzle = this.getTorchNozzle();
    qDebug(this.torchNozzle);
    this.writeRapidZMove(this.getSafetyZLevel());
    this.toolPosition = GCode.ToolPosition.Clear;
};
// get the nozzle type
Plasma.prototype.getTorchNozzle = function() {
    //You can get the current layer as follows:
    var entity = this.getEntity();
    var layerId = entity.getLayerId();
    var layer = this.document.queryLayer(layerId);
    return layer.getCustomProperty("QCADCAM", "Cam/TorchNozzle", "manual");
};
However if I move the call to writeToolDown it will work.

Code: Select all

// probe for material top and fire the torch
Plasma.prototype.writeToolDown = function() {
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.torchNozzle = this.getTorchNozzle();
    qDebug(this.torchNozzle);
    this.toolPosition = GCode.ToolPosition.Down;
    this.writeLine();
    this.toolIsDown();
};
Thanks
JT

Re: Function Order

Posted: Tue Nov 19, 2013 2:27 pm
by andrew
When writeHeader is called, there is no current entity yet (entities are exported later), so this.getEntity(); probably returns null.

You might also want to use the script debugger to investigate such problems. Simply start QCAD with the command line switch -enable-script-debugger:
qcad -enable-script-debugger

Re: Function Order

Posted: Tue Nov 19, 2013 11:37 pm
by jthornton
Andrew, thanks again... I forgot about the script debugger with so much new info floating between my ears.

JT