Page 1 of 2

Adding Options to the CAM Configuration Page

Posted: Sat Nov 09, 2013 2:30 pm
by jthornton
How do you add options to the CAM Configuration page in the Configuration Options(per Layer) section? I want to add some options for a plasma torch like pierce height, pierce delay, and cut height.

I also wish to add options for a mill like spindle rpm etc.

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Sat Nov 09, 2013 7:35 pm
by jthornton
I managed to add a combobox to the ui but am failing to get it populated with some defaults.
Screenshot-CAM Configuration-1.png
Screenshot-CAM Configuration-1.png (79.27 KiB) Viewed 34742 times
This is the code that I attempted to add the defaults with:

Code: Select all

// set pierce options
Lcnc_Plasma.prototype.initLayerOptionWidget = function(w) {
    switch (w.objectName) {
    case "ZCutting":
        w.addItems(["default", "-1", "-2", "-3"]);
        w.currentText = "default";
        break;
    case "PierceHeight":
        w.addItems(["default", "1", "2", "3"]);
        w.currentText = "default";
        break;
    }
};

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Mon Nov 11, 2013 7:05 pm
by andrew
Note that the name that is references in the .js file ('PierceHeight') has to match the object name that is defined in the .ui file. Feel free to post the .ui file if you can't get it to work.

Re: Adding Options to the CAM Configuration Page

Posted: Mon Nov 11, 2013 7:30 pm
by jthornton
Andrew,

Thanks for taking the time to look at my files. I've attached both the .ui and the .js file.

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Mon Nov 11, 2013 9:31 pm
by andrew
Thanks.

The problem is that there are two methods called "initLayerOptionWidget" in Lcnc_Plasma.js (lines 43 and 82). The second one simply overwrites the first one.

I've noticed that you are changing 'GCodeLayer.ui'. It would be better to copy and modify that file to add custom options. You can name it whatever you like, but following the current naming convention it would be called 'Lcnc_PlasmaLayer.ui'.

You can then set the name in Lcnc_Plasma.js:
function Lcnc_Plasma(documentInterface, newDocumentInterface) {
    GCode.call(this, documentInterface, newDocumentInterface);

    // set output unit:
    this.unit = RS.Inch;
    // use 'Lcnc_PlasmaLayer.ui' for layer options instead of 'GCodeLayer.ui':
    this.layerOptions = "Lcnc_PlasmaLayer";
}

Re: Adding Options to the CAM Configuration Page

Posted: Tue Nov 12, 2013 12:46 am
by jthornton
Andrew,

Thanks so much for helping me get this to work.

Sorry about the rookie mistake :oops: having two methods with the same name.

I'm really close to understanding how to get what I want from GCad CAM and I'll make some tutorials to show how to modify the output when I'm done to make it easier for others to get exactly what they want from the post processor.

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Tue Nov 12, 2013 2:31 pm
by jthornton
Ok, I got the page working and now I'm trying to sort out how to get the value from the drop down into my G code.

I think this line is a clue but I'm not sure what the options are for?

Code: Select all

var layerValue = layer.getCustomProperty("QCADCAM", "Cam/ZCutting", docValue);
var creates a variable named layerValue and it is assigned the result from layer.getCustomProperty(). I'm unsure what "QCADCAM", "Cam/ZCutting", docValue do. Can you give me a hint? I assume I need to create my function to get the value similar to getToolDownLevel function.

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Tue Nov 12, 2013 2:59 pm
by andrew
Layer specific settings are stored in layers as custom properties.

"QCADCAM" is the application ID (fix for QCAD/CAM to make sure that custom properties never interfere with other QCAD add-ons which would use another App ID).
"Cam" is the group code (also fix in the context of the QCAD/CAM add-on).
"ZCutting" matches the name of the UI element (in your case for example "PierceHeight")

The last parameter (docValue) is the default value to use if no value was explicitly defined for a layer. You can for example have the same option as document wide option and as layer specific option. If no value is defined, the document wide option can be used. You can also simply provide a fixed default value (e.g. 1):
var docValue = this.document.getVariable("Cam/PierceHeight", 1);
var layerValue = layer.getCustomProperty("QCADCAM", "Cam/PierceHeight", docValue);
or
var layerValue = layer.getCustomProperty("QCADCAM", "Cam/PierceHeight", 1);

Re: Adding Options to the CAM Configuration Page

Posted: Thu Nov 14, 2013 1:42 am
by jthornton
I'm trying to capture a couple of things from the custom properties and concatenate them into a string to use with writeline. Seems everything I've tried results in an error and the screen won't load.

Code: Select all

Lcnc_Plasma.prototype.getTorchNozzle = function() {
    return layer.getCustomProperty("QCADCAM", "Cam/TorchNozzle", 1);
};

// add subroutine call to fire the torch
Lcnc_Plasma.prototype.writeToolDown = function() {
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.toolPosition = GCode.ToolPosition.Down;
    this.torchNozzle = Lcnc_Plasma.getTorchNozzle();
    this.writeLine(); // this is the Z down move
    String touchoff = "o<touchoff> call";
    this.writeLine(touchoff);
    this.toolIsDown();
};

Any thoughts?

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Thu Nov 14, 2013 8:05 am
by andrew
Try:
this.torchNozzle = this.getTorchNozzle();
getTorchNozzle() is declared as a member function (attached to prototype), not a class function (attached to class).

Re: Adding Options to the CAM Configuration Page

Posted: Thu Nov 14, 2013 2:57 pm
by jthornton
I tried to add this and I get a loop or something that halts the program.

Code: Select all

// get the nozzle type
Lcnc_Plasma.prototype.getTorchNozzle = function() {
    return layer.getCustomProperty("QCADCAM", "Cam/TorchNozzle", 1);
    // here I'm trying to print to standard out just for debugging when running from the console but it does not work.
    System.out.println("Hello World");
};


// add subroutine call to fire the torch
Lcnc_Plasma.prototype.writeToolDown = function() {
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.toolPosition = GCode.ToolPosition.Down;
    // if I comment out the next line the file processes if not I get a pop up that says qcad-bin Processing paths... 30%
    this.torchNozzle = this.getTorchNozzle(); // this seems to put the program in a loop
    this.writeLine(); // this is the Z down move
    this.writeLine("o<touchoff> call");
    //this.writeLine(this.torchNozzle);
    this.toolIsDown();
};

I attached the entire .js file as well.

Thanks
JT

Re: Adding Options to the CAM Configuration Page

Posted: Thu Nov 14, 2013 3:17 pm
by andrew
jthornton wrote:

Code: Select all

// get the nozzle type
Lcnc_Plasma.prototype.getTorchNozzle = function() {
    return layer.getCustomProperty("QCADCAM", "Cam/TorchNozzle", 1);
    // here I'm trying to print to standard out just for debugging when running from the console but it does not work.
    System.out.println("Hello World");
};
- The "System.out.println" line is never reached. Everything after the return statement is generally ignored since the function already returned to the calling function.

- "System.out.println" is something from Java. Please note that JavaScript has nothing to do with Java (besides the name which is unfortunate and leads to a lot of confusion).
That's why I usually call it ECMAScript which is the official name of what is generally known as JavaScript.

- For debugging, you can use:
qDebug("message");
- The variable "layer" is not defined in function "Lcnc_Plasma.prototype.getTorchNozzle". You can get the current layer as follows:
var entity = this.getCurrentEntity();
var layerId = entity.getLayerId();
var layer = this.document.queryLayer(layerId);
For debugging, you can also use the built-in script debugger if you start QCAD with the command line switch -enable-script-debugger:
./qcad -enable-script-debugger
In your code, you can set a break point with the debugger statement:
debugger;

Re: Adding Options to the CAM Configuration Page

Posted: Fri Nov 15, 2013 4:58 pm
by jthornton
Woopie I'm making progress.

I'm stuck at:

Code: Select all

var entity = this.getCurrentEntity();
I looked in GCode.js for getCurrentEntity and it is not there so processing hangs at that line.

I also grepped for getCurrentEntity and it does not show up anywhere.

I also ran QCad with the debugger switch on and got:

Code: Select all

TypeError: Result of expression 'this.getCurrentEntity' [undefined' is not a function.
Thanks again for all your help.

JT

Re: Adding Options to the CAM Configuration Page

Posted: Fri Nov 15, 2013 7:34 pm
by jthornton
I did some digging and discovered that getEntity() does indeed work. I don't know if it returns the current entity yet but the code does not crash...

JT

Re: Adding Options to the CAM Configuration Page

Posted: Fri Nov 15, 2013 8:24 pm
by jthornton
What I have so far is the following but it returns "FC" no matter what selection I make in the layer options combo box.

Code: Select all

// get the nozzle type
Lcnc_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", "FC");
};

// add subroutine call to fire the torch
Lcnc_Plasma.prototype.writeToolDown = function() {
    this.g = GCode.Mode.Normal;
    this.z = this.getToolDownLevel();
    this.torchNozzle = this.getTorchNozzle();
    qDebug("torch " + this.torchNozzle);
    this.toolPosition = GCode.ToolPosition.Down;
    this.writeLine(); // this is the Z down move
    this.writeLine("o<touchoff> call");
    this.toolIsDown();
};
I've attached the js and ui file in case it is needed.

Thanks
JT