Postprocessor: Retrieving data from CamProfileToolpathDialog

Discussions around the CAM Add-On of QCAD.

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Indicate the post processor used.

Attach drawing files and screenshots.

Post one question per topic.

Post Reply
Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Sat Oct 29, 2022 2:39 pm

Hello all! :)

I use 2 custom properties in each of my toolpath's for managing options of writing M07/M08 according to each toolpath.
It works well for camexport, I can insert M07, M08 and M09 at the right places automatically.
But so far, I have to add these custom properties manually for each toolpath :? .

Now, I want to set these options from the CamProfileToolpathDialog
So, I have added 2 checkBoxe's to the bottom of the CamProfileToolpathDialog.
I can initialize these checkbox's successfully from custom properties without any problem.
My problem is that I could not find how to store the result of the dialog back to to the custom properties when clicking "OK".

Something that could look like this...

Code: Select all

LinuxCNCEvanCNC2.prototype.onDialogOK = function(dialog) {
    // onDialogOK is a fully hypothetical name
    if (dialog.objectName==="CamProfileToolpathDialog") {
		if (dialog.cbToolpathWriteM07.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",1);
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",0);
			
		if (dialog.cbToolpathWriteM08.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",1);
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",0);
	}
}
Any idea how to do :?:
Or maybe I should do something totally different...
Any suggestion would be welcome!
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by CVH » Sat Oct 29, 2022 4:16 pm

Hi,

First it eludes me what the purpose is.
The custom properties are taken from where?
Storing them back would do what exactly?
You need them to adapt automatically for certain toolpaths ... :shock:

What you set in the dialog box is basically always retrievable as some variable.
That is stored from the point on that you change them.
I don't expect that you need an additional write function ... :?

Perhaps you want to share the LinuxCNCEvanCNC2 postprocessor so we can help you more efficiently.
Please elaborate on how you need them to act in certain cases.

Regards,
CVH

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Sat Oct 29, 2022 6:36 pm

Hi CVH,

My goal is to dynamically update toolpathHeader and toolpathFooter in order to insert M07/M08/M09 depending on two flags ToolpathWriteM07 and TollpathWriteM08.
I have defined these two flags as custom properties as shown bellow
Image

Here is my CamProfileToolpathDialog:
Image

and my postprocessor

Code: Select all

include("GCodeBase.js");

/**
 * This configuration provides:
 * 	- Outputs the computed offset path instead of using
 * the tool radius compensation feature of the controller (G41/G42).
 * 
 * 	- Output in Millimeter.
 * 
 * 	- No line numbering
 * 
 * 	- Added M7/M8 and M9 management for each toolPath using two custom
 * attibutes ToolpathWriteM07 and ToolpathWriteM08.
 * But so far, I don't know how to affect these attributes from
 * the toolpath dialog CamProfileToolpathDialog.
 * 
 * Flags ToolpathWriteM07 and ToolpathWriteM08 are used for to update toopathHeader and toolpathFooter dynamivally
 * 
 * 	- Set defaut cutting depth to 0.001
 * 
 * 	- Set defeult overCut length to 0
 * 
* 
 * 
 * TODO:
 *  - Apply M07/M08 from the tool plunge.
 *  - Retrieve M07/M08 from the dialog and apply store them into custom
 * attibutes ToolpathWriteM07 and ToolpathWriteM08.
 */
 function LinuxCNCEvanCNC2(cadDocumentInterface, camDocumentInterface) {
    GCodeBase.call(this, cadDocumentInterface, camDocumentInterface);

 	this.lineNumber = undefined; // No line numbers

    this.fileExtensions = ["ngc"];
    this.outputOffsetPath = true;

    this.header=[
        "[N] (File: [FILENAME] -- [DATETIME])"
    ];
    this.linearMoveCompensationOff = "[N] G40 G1 [X] [Y]";

    this.debugging = true;
}

LinuxCNCEvanCNC2.prototype = new GCodeBase();
LinuxCNCEvanCNC2.displayName = "LinuxCNC EvanCNC2";
LinuxCNCEvanCNC2.description = "LinuxCNC G-Code without tool radius compensation, neither line numbers, and with M07/M08 options";


LinuxCNCEvanCNC2.prototype.initDialog = function(dialog, di, resourceBlock) {
    
    if (dialog.objectName==="CamProfileToolpathDialog") {
        // change default cutting depth
        dialog.findChild("CamZCuttingDepth").setValue(0.001);

		// change default overcut length
        dialog.findChild("CamOvercut").setValue(0)



		
		// retrieve the Layout of the dialog 
		var mainLayout = dialog.layout();
		
        // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox("G-Code");
        // bind it to the Layout of the dialog
        mainLayout.addWidget(gcodeGroup,3,0);

		// retrieve the Layout of the new QGroupBox
		var vBoxLayout = gcodeGroup.layout();

		// add a HBoxLayout for grouping checkboxes in
		var hBoxLayout = new QHBoxLayout(gcodeGroup);




		// create a new checkbox for managing M07:
		var cbToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
		cbToolpathWriteM07.objectName = "ToolpathWriteM07";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbToolpathWriteM07,0,0);

		// try to retrieve the state of the option, and init the CheckBox accordingly
		if (resourceBlock.getCustomProperty("QCAD","ToolpathWriteM07",0) == 1)
			cbToolpathWriteM07.setCheckState(Qt.Checked);
		else
			cbToolpathWriteM07.setCheckState(Qt.Unchecked);
			



		// create a new checkbox for managing M08:
		var cbToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
		cbToolpathWriteM08.objectName = "ToolpathWriteM08";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbToolpathWriteM08,0,1);

		// try to retrieve the state of the option, and init the CheckBox accordingly
		if (resourceBlock.getCustomProperty("QCAD","ToolpathWriteM08",0) == 1)
			cbToolpathWriteM08.setCheckState(Qt.Checked);
		else
			cbToolpathWriteM08.setCheckState(Qt.Unchecked);
    }
};


LinuxCNCEvanCNC2.prototype.onDialogOK = function(dialog) {
    if (dialog.objectName==="CamProfileToolpathDialog") {
		if (dialog.cbToolpathWriteM07.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",1);
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",0);
			
		if (dialog.cbToolpathWriteM08.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",1);
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",0);
	}
}


LinuxCNCEvanCNC2.prototype.writeToolpathHeader = function(filename) {

	// Dynamic update of toolpathHeader and toolpathFooter in order to insert M07/M08/M09
	// according to custom options ToolpathWriteM07 and ToolpathWriteM07
	
    this.toolpathHeader = [
		"[N] (-------------------- Begin Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)",
    ];
    
    this.toolpathFooter = [
		"[N] (-------------------- End Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)"
    ];
	
	if (this.getToolpathOption("ToolpathWriteM07", "0")==="1") 
		this.toolpathHeader.push("[N] M07");
		
	if (this.getToolpathOption("ToolpathWriteM08", "0")==="1") 
		this.toolpathHeader.push("[N] M08");
		
	if ((this.getToolpathOption("ToolpathWriteM07", "0")==="1") || (this.getToolpathOption("ToolpathWriteM08", "0")==="1"))
		this.toolpathFooter.unshift("[N] M09");

	GCodeBase.prototype.writeToolpathHeader.call(this,filename);
};


Attachments
CamProfileToolpathDialog.png
CamProfileToolpathDialog.png (57.92 KiB) Viewed 15837 times
Property Editor.png
Property Editor.png (59.23 KiB) Viewed 15837 times
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by CVH » Sat Oct 29, 2022 8:36 pm

Hi,

there is already something wrong with with your is .. else clauses
It should read:

Code: Select all

if (conditions) {
    // Code of the if clause, all ending with ;
}
else {
    // Code of the else clause, all ending with ;
}

// OR
else if (other conditions) {
    // Code of the second if clause, all ending with ;
}
else {
    // Code of the else clause, all ending with ;
}
After the closing curly brackets a ';' is not mandatory.
It is common in QCAD that they are included after the closing curly bracket of a function.

CamZCuttingDepth is a system defined parameter.
You may already see that CamZCuttingDepth is part of the dialog and that it is set for the created toolpath with your value.
Very similar one can include the M8 and/or M9 but then intended for the header of a toolpath.
Meaning that all toolpaths that are created will be with M8 and/or M9 depending what is set.
It still eludes me why that should be written to a custom property of a Block after the toolpath is already created.

What is funny is that you include the placeholder [N] in your exports but that is set to undefined.
Have you read what Andrew provided to not export line numbers?

I would base my post on something already proven meaning on LinuxCNCOffsetMM.js and not directly on GCodeBase.js ...
... But you are fully free in that choice.

Regards,
CVH

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Sun Oct 30, 2022 9:50 pm

Hello,
Thank you so much for the time you spend for me.
Sorry that my explanations are rather confusing. My skill regarding English language is far from what I would like it to be.
And my code was mixing to many topics at a time.

Therefor I have reviewed both my description of the problem, and my code.

What I need:
The goal of this postprocessor is to allow the optional insertion of G-Codes M07/M08 and M09 for each toolpath.

For example, I need to be able to
- Start the first toolpath with M07 only, and finish with M09
- Start the second toolpath with M08 only, and finish with M09
- Start a third toolpath with both M07 and M08, and finish with M09
- Start a fourth toolpath without M07 neither M08, and of course finish without M09

How I am trying to do it
The only solution I found so far for doing so is to dynamically update the definition of the toolpathHeader and toolpathFooter for each toolpath.

For that, each toolpath have its own flags defined as custom properties:
- ToolpathWriteM07 : Defines wherther we have to insert M07 and M09 or not for the current toolpath.
- ToolpathWriteM08 : Defines wherther we have to insert M07 and M09 or not for the current toolpath.
At camexport, both toolpathHeader and toolpathFooter are dynamically updated accordingly by function writeToolpathHeader.

Doing so, camexport works pretty well as expected.

In a first time, I have defined these two flags manually for each toolpath.
Now, I need to be able to set/reset these flags from the dialog "CamProfileToolpathDialog" when defining all parameters of each toolpath.

Therefore, I have added two checkBox's to the "CamProfileToolpathDialog" dialog.

At initialisation of this dialog, I can use these two flags ToolpathWriteM07 and ToolpathWriteM08 to set these two new checkBox's correctly.

What my problem is:
My problem is that when I close the dialog by clicking button "OK", I have no idea on how to store the result of the two checkbox's into the two flags of the toolpath on concern (I mean into the DXF).
I have tried to follow the way original data of a toolpath is managed, but the only relation I can see between the dialog widgets and custom properties of a toolpath is by their object names that are identical. So I try to give to my CheckBox's the same names as their relative custom properties, but it seams to have no effect at all. This is the reason why I try to set and retrieve the state of these CheckBoxes the way I do.

Code: Select all

include("LinuxCNCOffsetMM.js");

[b]And my questions are:[/b]
    - Do you know any function that I could hack at the closing of the dialog box and where I could retrieve its data by myself (as shown in my hypothetical function by the end of my code) ?
    - Do you know any much better way of doing what I want to do?
    
[code]

/**
 * This configuration provides:
 * 	- M7, M8 and M9 management for each toolPath.
 * 
 * On camexport, toopathHeader and toolpathFooter are dynamically updated
 * depending on flags ToolpathWriteM07 and ToolpathWriteM08, in order to include or not
 * include G-Codes M7, M8 and M9 separatly for each toolpath.
 * 
 */
 function LinuxCNCEvanCNC2(cadDocumentInterface, camDocumentInterface) {
    LinuxCNCOffsetMM.call(this, cadDocumentInterface, camDocumentInterface);

    this.debugging = true;
	}

LinuxCNCEvanCNC2.prototype = new LinuxCNCOffsetMM();
LinuxCNCEvanCNC2.displayName = "LinuxCNC EvanCNC2";

LinuxCNCEvanCNC2.prototype.writeToolpathHeader = function(filename) {

	// Dynamic update of toolpathHeader and toolpathFooter in order to insert M07/M08/M09
	// depending on custom options ToolpathWriteM07 and ToolpathWriteM08
	
    this.toolpathHeader = [
		"[N] (------------ Begin Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------)",
    ];
    
    this.toolpathFooter = [
		"[N] (------------ End Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------)"
    ];
	
	if (this.getToolpathOption("ToolpathWriteM07", 0) == 1) 
		this.toolpathHeader.push("[N] M07");
		
	if (this.getToolpathOption("ToolpathWriteM08", 0) == 1) 
		this.toolpathHeader.push("[N] M08");
		
	if ((this.getToolpathOption("ToolpathWriteM07", 0) == 1) || (this.getToolpathOption("ToolpathWriteM08", 0) == 1))
		this.toolpathFooter.unshift("[N] M09");

	LinuxCNCOffsetMM.prototype.writeToolpathHeader.call(this,filename);
}


LinuxCNCEvanCNC2.prototype.initDialog = function(dialog, di, resourceBlock) {
    
    if (dialog.objectName==="CamProfileToolpathDialog") {
		// ********** add a G-Code group ********
		//
		// retrieve the Layout of the dialog 
		var mainLayout = dialog.layout();
		
		 // add a QGoupBox for G-Codes
		var gcodeGroup = new QGroupBox("G-Code");
		// bind it to the Layout of the dialog
		mainLayout.addWidget(gcodeGroup,3,0);

		// retrieve the Layout of the new QGroupBox
		var vBoxLayout = gcodeGroup.layout();

		// add a HBoxLayout for grouping checkboxes in
		var hBoxLayout = new QHBoxLayout(gcodeGroup);

    		// ******* add a CheckBox for M07 option ********
		//
		// create a new checkbox for managing M07:
		var cbToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
		cbToolpathWriteM07.objectName = "ToolpathWriteM07";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbToolpathWriteM07,0,0);

		// try to retrieve the state of the option, and init the CheckBox accordingly
		if (resourceBlock.getCustomProperty("QCAD","ToolpathWriteM07",0) == 1)
			cbToolpathWriteM07.setCheckState(Qt.Checked);
		else
			cbToolpathWriteM07.setCheckState(Qt.Unchecked);
			
		// ******* add a CheckBox for M08 option ********
		//
		// create a new checkbox for managing M08:
		var cbToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
		cbToolpathWriteM08.objectName = "ToolpathWriteM08";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbToolpathWriteM08,0,1);

		// try to retrieve the state of the option, and init the CheckBox accordingly
		if (resourceBlock.getCustomProperty("QCAD","ToolpathWriteM08",0) == 1)
			cbToolpathWriteM08.setCheckState(Qt.Checked);
		else
			cbToolpathWriteM08.setCheckState(Qt.Unchecked);
    }
}

// I am just missing a function that would be called when button OK of the dialog is clicked
// and where I could do as follow:
LinuxCNCEvanCNC2.prototype.hypoteticalNameOnButtonOkClicked = function(dialog) {
	if (dialog.objectName==="CamProfileToolpathDialog") {
		if (dialog.cbToolpathWriteM07.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",1)
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",0);
			
		if (dialog.cbToolpathWriteM08.checkState() == Qt.Checked)
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",1)
		else
			dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",0);
	}
}
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Sun Oct 30, 2022 9:53 pm

And another problem I have is with formating code on this forum:


And my questions are:
- Do you know any function that I could hack at the closing of the dialog box and where I could retrieve its data by myself (as shown in my hypothetical function by the end of my code) ?
- Do you know any much better way of doing what I want to do?
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by CVH » Mon Oct 31, 2022 11:08 am

Evan,

Remind that I writing this while I am exploring ... :wink:

The options in the CAM Configuration dialog are used to configure QCAM.
For example:
Entity conversion tells QCAM what to do with the original shapes when creating a toolpath.
'Always write G1' will always export a 'G1' even knowing G1 is or should be modal.

In the same way an option here to include M7/M8 & M9 would add these in your export ... Every export.

These things are customized using .prototype.initConfigDialog
Additional things are then handled in .prototype.writeFile using this.getGlobalOption()
Example here: https://www.qcad.org/rsforum/viewtopic. ... 411#p36411

What you are trying to achieve is profile related.
Rather something intended for the CAM Profile Toolpath dialog or the CAM Drill Toolpath dialog.

For that you are on the right track with dialog.objectName==="CamProfileToolpathDialog"
And retrieving data is with this.getToolpathOption()
Example here: https://www.qcad.org/rsforum/viewtopic. ... 575#p38575

The question remains why additional custom widgets are not transferred to custom properties of the toolpath block.

...
:idea: Could it be that they all start with 'Cam'?
...

To test this I altered your last code:
- Renamed widgets and properties
- included curly brackets ... :roll:
- Remarked non functional code out with /* ### CVH: ...... */
- Added a remark for vBoxLayout

It seems functional :P ... But it needs some extra care, without a cutting tool the warning is in the G-code box ... :?
Maybe just a TAB stop issue.

Code: Select all

include("LinuxCNCOffsetMM.js");
/* ### CVH: This is no valid code ###
[b]And my questions are:[/b]
    - Do you know any function that I could hack at the closing of the dialog box and where I could retrieve its data by myself (as shown in my hypothetical function by the end of my code) ?
    - Do you know any much better way of doing what I want to do?
    
[code]
*/

/**
 * This configuration provides:
 *  - M7, M8 and M9 management for each toolPath.
 * 
 * On camexport, toopathHeader and toolpathFooter are dynamically updated
 * depending on flags ToolpathWriteM07 and ToolpathWriteM08, in order to include or not
 * include G-Codes M7, M8 and M9 separatly for each toolpath.
 * 
 */
function LinuxCNCEvanCNC2(cadDocumentInterface, camDocumentInterface) {
    LinuxCNCOffsetMM.call(this, cadDocumentInterface, camDocumentInterface);

    this.debugging = true;
};

LinuxCNCEvanCNC2.prototype = new LinuxCNCOffsetMM();
LinuxCNCEvanCNC2.displayName = "LinuxCNC EvanCNC2";

LinuxCNCEvanCNC2.prototype.writeToolpathHeader = function(filename) {

    // Dynamic update of toolpathHeader and toolpathFooter in order to insert M07/M08/M09
    // depending on custom options ToolpathWriteM07 and ToolpathWriteM08
    
    this.toolpathHeader = [
        "[N] (------------ Begin Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------)",
    ];
    
    this.toolpathFooter = [
        "[N] (------------ End Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------)"
    ];
    
    if (this.getToolpathOption("CamToolpathWriteM07", 0) == 1) {
        this.toolpathHeader.push("[N] M07");
    }
    if (this.getToolpathOption("CamToolpathWriteM08", 0) == 1) {
        this.toolpathHeader.push("[N] M08");
    }
    if ((this.getToolpathOption("CamToolpathWriteM07", 0) == 1) || (this.getToolpathOption("CamToolpathWriteM08", 0) == 1)) {
        this.toolpathFooter.unshift("[N] M09");
    }

    LinuxCNCOffsetMM.prototype.writeToolpathHeader.call(this,filename);
}


LinuxCNCEvanCNC2.prototype.initDialog = function(dialog, di, resourceBlock) {
    if (dialog.objectName==="CamProfileToolpathDialog") {
        // ********** add a G-Code group ********
        //
        // retrieve the Layout of the dialog 
        var mainLayout = dialog.layout();
        
         // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox("G-Code");
        // bind it to the Layout of the dialog
        mainLayout.addWidget(gcodeGroup, 3, 0);

        // retrieve the Layout of the new QGroupBox
// ### CVH: Unused!??? ###
        var vBoxLayout = gcodeGroup.layout();

        // add a HBoxLayout for grouping checkboxes in
        var hBoxLayout = new QHBoxLayout(gcodeGroup);

            // ******* add a CheckBox for M07 option ********
        //
        // create a new checkbox for managing M07:
        var cbToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
        cbToolpathWriteM07.objectName = "CamToolpathWriteM07";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbToolpathWriteM07, 0, 0);

/* ### CVH: This trows an exception: 'resourceBlock' [undefined] is not an object ###
        // try to retrieve the state of the option, and init the CheckBox accordingly
        if (resourceBlock.getCustomProperty("QCAD","CamToolpathWriteM07", 0) == 1) {
            cbToolpathWriteM07.setCheckState(Qt.Checked);
        }
        else {
            cbToolpathWriteM07.setCheckState(Qt.Unchecked);
        }
*/

        // ******* add a CheckBox for M08 option ********
        //
        // create a new checkbox for managing M08:
        var cbToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
        cbToolpathWriteM08.objectName = "CamToolpathWriteM08";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbToolpathWriteM08, 0, 1);

/* ### CVH: This trows an exception: 'resourceBlock' [undefined] is not an object ###
        // try to retrieve the state of the option, and init the CheckBox accordingly
        if (resourceBlock.getCustomProperty("QCAD","CamToolpathWriteM07", 0) == 1) {
            cbToolpathWriteM08.setCheckState(Qt.Checked);
        }
        else {
            cbToolpathWriteM08.setCheckState(Qt.Unchecked);
        }
*/

    }
};

// I am just missing a function that would be called when button OK of the dialog is clicked
// and where I could do as follow:
/* ### CVH: This is no valid code ###
LinuxCNCEvanCNC2.prototype.hypoteticalNameOnButtonOkClicked = function(dialog) {
    if (dialog.objectName==="CamProfileToolpathDialog") {
        if (dialog.cbToolpathWriteM07.checkState() == Qt.Checked)
            dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",1)
        else
            dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM07",0);
            
        if (dialog.cbToolpathWriteM08.checkState() == Qt.Checked)
            dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",1)
        else
            dialog.resourceBlock.setCustomProperty("QCAD","ToolpathWriteM08",0);
    }
}
*/
Please report back with a cleaned up and functional postprocessor so others may benefit of all this work. :P

Regards,
CVH

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Mon Oct 31, 2022 2:22 pm

Yeah! fantastic!
Many many thank's CVH. It works perfectly.

So, to sum up, in order a widget to establish its relation with its relative custom property, we just have to prefix the object name of this widget with "Cam", and everything works like magic!

I am currently cleaning my code for sharing (ASAP).
Next step for me will be to do the same for the "CAM Drill Toolpath" dialog.

Many thanks' again, best regards! :)
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Mon Oct 31, 2022 3:46 pm

Here is my code, but alas not clean yet
I have included the initialization of Cam Drill Toolpath dialog, but I have a problem with the position of the GroupBox G-Code.
I fail to place it between the Cutting Depths group and buttons Cancel/OK

Code: Select all

include("LinuxCNCOffsetMM.js");

/**
 * This configuration provides individual management of M7, M8 and M9 for each toolPath.
 * 
 * On camexport, toopathHeader and toolpathFooter are dynamically updated
 * depending on flags CamToolpathWriteM07 and CamToolpathWriteM08, in order to include or not
 * include G-Codes M7, M8 and M9 separatly for each toolpath.
 * 
 * 2 checkBox's have been added to the "CAM Profile Toolpath" dialog for editing these options.
 * 
 * Please not that the relation between a widgets and there relative custom property is automatically
 * established by the fact that the object names of widgets are prefixed "Cam", as in "CamToolpathWriteM07" for example.
 * 
 * Many thank's to CVH for revealing this key detail.
 * 
 * A further development would be to do the same for the "CAM Drill Toolpath" dialog
 */
 function LinuxCNCEvanCNC2(cadDocumentInterface, camDocumentInterface) {
    LinuxCNCOffsetMM.call(this, cadDocumentInterface, camDocumentInterface);

    this.debugging = true;
	}

LinuxCNCEvanCNC2.prototype = new LinuxCNCOffsetMM();
LinuxCNCEvanCNC2.displayName = "LinuxCNC EvanCNC2";

LinuxCNCEvanCNC2.prototype.writeToolpathHeader = function(filename) {

	// Dynamic update of toolpathHeader and toolpathFooter in order to insert M07/M08/M09
	// depending on custom options CamToolpathWriteM07 and CamToolpathWriteM08
	
    this.toolpathHeader = [
		"[N] (-------------------- Begin Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)",
    ];
    
    this.toolpathFooter = [
		"[N] (-------------------- End Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)"
    ];
	
	if (this.getToolpathOption("CamToolpathWriteM07", 0) == 1) 
		this.toolpathHeader.push("[N] M07");
		
	if (this.getToolpathOption("CamToolpathWriteM08", 0) == 1) 
		this.toolpathHeader.push("[N] M08");
		
	if ((this.getToolpathOption("CamToolpathWriteM07", 0) == 1) || (this.getToolpathOption("CamToolpathWriteM08", 0) == 1))
		this.toolpathFooter.unshift("[N] M09");

	LinuxCNCOffsetMM.prototype.writeToolpathHeader.call(this,filename);
}


LinuxCNCEvanCNC2.prototype.initDialog = function(dialog, di, resourceBlock) {
    
    if (dialog.objectName==="CamProfileToolpathDialog") {
		// ***** add a G-Code group *****
		//
		// retrieve the Layout of the dialog 
		var mainLayout = dialog.layout();
		
        // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox("G-Code");
        // bind it to the Layout of the dialog
        mainLayout.addWidget(gcodeGroup,3,0);

		// retrieve the Layout of the new QGroupBox
		var vBoxLayout = gcodeGroup.layout();

		// add a HBoxLayout for grouping checkboxes in
		var hBoxLayout = new QHBoxLayout(gcodeGroup);

		// ***** add a CheckBox for M07 option *****
		//
		// create a new checkbox for managing M07:
		var cbCamToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
		cbCamToolpathWriteM07.objectName = "CamToolpathWriteM07";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbCamToolpathWriteM07,0,0);

		// ***** add a CheckBox for M08 option *****
		//
		// create a new checkbox for managing M08:
		var cbCamToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
		cbCamToolpathWriteM08.objectName = "CamToolpathWriteM08";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbCamToolpathWriteM08,0,1);
    }

    if (dialog.objectName==="CamDrillToolpathDialog") {
		// ***** add a G-Code group *****
		//
		// retrieve the Layout of the dialog 
		var mainLayout = dialog.layout();
		
        // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox("G-Code");
        // bind it to the Layout of the dialog
        mainLayout.addWidget(gcodeGroup,2,0);

		// retrieve the Layout of the new QGroupBox
		var vBoxLayout = gcodeGroup.layout();

		// add a HBoxLayout for grouping checkboxes in
		var hBoxLayout = new QHBoxLayout(gcodeGroup);

		// ***** add a CheckBox for M07 option *****
		//
		// create a new checkbox for managing M07:
		var cbCamToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
		cbCamToolpathWriteM07.objectName = "CamToolpathWriteM07";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbCamToolpathWriteM07,0,0);

		// ***** add a CheckBox for M08 option *****
		//
		// create a new checkbox for managing M08:
		var cbCamToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
		cbCamToolpathWriteM08.objectName = "CamToolpathWriteM08";

		// bind the CheckBox to the HBoxLayout
		hBoxLayout.addWidget(cbCamToolpathWriteM08,0,1);
    }
}
CAM Drill Toolpath.png
CAM Drill Toolpath.png (31.31 KiB) Viewed 15656 times
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by CVH » Tue Nov 01, 2022 6:44 am

Evan,
In a way this is a secondary question.
See Forum rules above.
Evan wrote:
Mon Oct 31, 2022 3:46 pm
I have included the initialization of Cam Drill Toolpath dialog, but I have a problem with the position of the GroupBox G-Code.
I fail to place it between the Cutting Depths group and buttons Cancel/OK
For that we need to verify the setup of the CamDrillToolpathDialog.ui file.
A search on the Forum reveals no available resource.
Also see my recent reply on the PROprietary parts of QCAD:
https://www.qcad.org/rsforum/viewtopic. ... 026#p39016

That didn't hold me back before but right now all attempts to locate such remained empty.

In the end I modded LinuxCNCEvanCNC2.js temporarily.
(Yet again included curly brackets & ';' where common ... tabs2spaces ... Removed/Added space for readability ...)
- When dialog.objectName==="CamDrillToolpathDialog" loaded UI into textstream
- Exported the stream and cleaned up
Et voila:
CamDrillToolpathDialog.ui
(10.11 KiB) Downloaded 338 times

After some consideration it would be better to insert a widget before the (error) message label instead of just adding it.
There are some (open source) references for that:
- WidgetFactory.js
- PropertyEditor.js
- StatusBar.js

Seems functional for CamDrillToolpathDialog and now we don't get in the way of the message label :P
But one can't use that for CamProfileToolpathDialog because that is a QGridLayout and not a QBoxLayout.
I am not an ace in these things, sorry. :oops:

Pity that Andrew didn't provided in a GroupCustom widget like in the CAM Configuration dialog. :(
Maybe something for a Feature Request on BugTracker ...
Remark that var vBoxLayout isn't used at all, twice. :wink:
I think that the third parameter of addWidget() has more to do with alignment ... and not with position.

Code: Select all

/**
 * This configuration provides individual management of M7, M8 and M9 for each toolPath.
 * 
 * On camexport, toopathHeader and toolpathFooter are dynamically updated
 * depending on flags CamToolpathWriteM07 and CamToolpathWriteM08, in order to include or not
 * include G-Codes M7, M8 and M9 separatly for each toolpath.
 * 
 * 2 checkBox's have been added to the "CAM Profile Toolpath" dialog for editing these options.
 * 
 * Please not that the relation between a widgets and there relative custom property is automatically
 * established by the fact that the object names of widgets are prefixed "Cam", as in "CamToolpathWriteM07" for example.
 * 
 * Many thank's to CVH for revealing this key detail.
 * 
 * A further development would be to do the same for the "CAM Drill Toolpath" dialog
 */

include("LinuxCNCOffsetMM.js");

function LinuxCNCEvanCNC2(cadDocumentInterface, camDocumentInterface) {
    LinuxCNCOffsetMM.call(this, cadDocumentInterface, camDocumentInterface);

    this.debugging = true;
};

LinuxCNCEvanCNC2.prototype = new LinuxCNCOffsetMM();
LinuxCNCEvanCNC2.displayName = "LinuxCNC EvanCNC2";

LinuxCNCEvanCNC2.prototype.writeToolpathHeader = function(filename) {
    // Dynamic update of toolpathHeader and toolpathFooter in order to insert M07/M08/M09
    // depending on custom options CamToolpathWriteM07 and CamToolpathWriteM08

    this.toolpathHeader = [
        "[N] (-------------------- Begin Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)",
    ];

    this.toolpathFooter = [
        "[N] (-------------------- End Tool Path [TOOLPATH_INDEX]: [TOOLPATH_NAME] --------------------)"
    ];

    if (this.getToolpathOption("CamToolpathWriteM07", 0) == 1) {
        this.toolpathHeader.push("[N] M07");
    }

    if (this.getToolpathOption("CamToolpathWriteM08", 0) == 1) {
        this.toolpathHeader.push("[N] M08");
    }

    if ((this.getToolpathOption("CamToolpathWriteM07", 0) == 1) || (this.getToolpathOption("CamToolpathWriteM08", 0) == 1)) {
        this.toolpathFooter.unshift("[N] M09");
    }

    LinuxCNCOffsetMM.prototype.writeToolpathHeader.call(this,filename);
};


LinuxCNCEvanCNC2.prototype.initDialog = function(dialog, di, resourceBlock) {
    if (dialog.objectName === "CamProfileToolpathDialog") {
        // ***** add a G-Code group *****
        //
        // retrieve the Layout of the dialog 
        var mainLayout = dialog.layout();

        // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox(qsTr("G-Code"));
        // bind it to the Layout of the dialog
        mainLayout.addWidget(gcodeGroup, 3, 0);

        // retrieve the Layout of the new QGroupBox
        var vBoxLayout = gcodeGroup.layout();

        // add a HBoxLayout for grouping checkboxes in
        var hBoxLayout = new QHBoxLayout(gcodeGroup);

        // ***** add a CheckBox for M07 option *****
        //
        // create a new checkbox for managing M07:
        var cbCamToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
        cbCamToolpathWriteM07.objectName = "CamToolpathWriteM07";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbCamToolpathWriteM07, 0, 0);

        // ***** add a CheckBox for M08 option *****
        //
        // create a new checkbox for managing M08:
        var cbCamToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
        cbCamToolpathWriteM08.objectName = "CamToolpathWriteM08";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbCamToolpathWriteM08, 0, 1);
    }

    if (dialog.objectName==="CamDrillToolpathDialog") {
        // ***** add a G-Code group *****
        //
        // retrieve the Layout of the dialog 
        var mainLayout = dialog.layout();

        // add a QGoupBox for G-Codes
        var gcodeGroup = new QGroupBox(qsTr("G-Code"));
        // bind it to the Layout of the dialog
        mainLayout.insertWidget(2, gcodeGroup);

        // retrieve the Layout of the new QGroupBox
        var vBoxLayout = gcodeGroup.layout();

        // add a HBoxLayout for grouping checkboxes in
        var hBoxLayout = new QHBoxLayout(gcodeGroup);

        // ***** add a CheckBox for M07 option *****
        //
        // create a new checkbox for managing M07:
        var cbCamToolpathWriteM07 = new QCheckBox(qsTr("Enable M07"));
        cbCamToolpathWriteM07.objectName = "CamToolpathWriteM07";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbCamToolpathWriteM07, 0, 0);

        // ***** add a CheckBox for M08 option *****
        //
        // create a new checkbox for managing M08:
        var cbCamToolpathWriteM08 = new QCheckBox(qsTr("Enable M08"));
        cbCamToolpathWriteM08.objectName = "CamToolpathWriteM08";

        // bind the CheckBox to the HBoxLayout
        hBoxLayout.addWidget(cbCamToolpathWriteM08, 0, 1);
    }
};
Regards,
CVH

CVH
Premier Member
Posts: 3416
Joined: Wed Sep 27, 2017 4:17 pm

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by CVH » Wed Nov 02, 2022 7:20 am

Filed feature request:
https://qcad.org/bugtracker/index.php?d ... sk_id=2418

When interested, please vote for it ... :wink:

Regards,
CVH

Evan
Newbie Member
Posts: 8
Joined: Tue Jan 04, 2022 5:24 pm
Location: South-East of France

Re: Postprocessor: Retrieving data from CamProfileToolpathDialog

Post by Evan » Thu Dec 15, 2022 11:04 am

Well noted!
Thank you so much CVH. :D
Merry Christmas and a happy new year!
My dream: to see QCAD integrated to FREECAD in place of SKETCHER

Post Reply

Return to “QCAD/CAM”