Function Order

Discussions around the CAM Add-On of QCAD version 3

Moderator: andrew

Function Order

Postby jthornton » Sun Nov 17, 2013 4:17 pm

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
jthornton
Full Member
 
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Postby andrew » Sun Nov 17, 2013 10:09 pm

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.
User avatar
andrew
Site Admin
 
Posts: 2538
Joined: Fri Mar 30, 2007 6:07 am

Re: Function Order

Postby jthornton » Mon Nov 18, 2013 1:42 pm

Andrew,

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

JT
jthornton
Full Member
 
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Postby jthornton » Mon Nov 18, 2013 11:31 pm

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
jthornton
Full Member
 
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Postby andrew » Mon Nov 18, 2013 11:39 pm

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.
User avatar
andrew
Site Admin
 
Posts: 2538
Joined: Fri Mar 30, 2007 6:07 am

Re: Function Order

Postby jthornton » Tue Nov 19, 2013 1:28 pm

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
jthornton
Full Member
 
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm

Re: Function Order

Postby andrew » Tue Nov 19, 2013 2:27 pm

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
User avatar
andrew
Site Admin
 
Posts: 2538
Joined: Fri Mar 30, 2007 6:07 am

Re: Function Order

Postby jthornton » Tue Nov 19, 2013 11:37 pm

Andrew, thanks again... I forgot about the script debugger with so much new info floating between my ears.

JT
jthornton
Full Member
 
Posts: 66
Joined: Fri Oct 25, 2013 1:31 pm


Return to QCAD 3 CAM Add-On

Who is online

Users browsing this forum: No registered users and 0 guests

cron