C++ Example of using RGuAction and RActionAdapter

Discussion forum for C++ and script developers who are using the QCAD development platform or who are looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Forum rules

Always indicate your operating system and QCAD version.

Attach drawing files, scripts and screenshots.

Post one question per topic.

Post Reply
Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

C++ Example of using RGuAction and RActionAdapter

Post by Taygete » Tue Sep 16, 2014 5:13 pm

Hi,

I have written some scripts which handle the user interaction while building up the drawing and I also have a C++ plugin that makes calls to a database before presenting the user with the information.

The client has asked if it is possible to rewrite the js scripts in C++.

I was wondering if there is an example anywhere which would give me pointers in to how this all fits together, I notice RActionAdapter has the beginEvent, coordinateEvent etc interface I could use but I cannot get these events to fire when the user clicks the menu item.

I create the menu in my plugins postInit() method and add my RGuiActions to the menu, I then create my derived RActionAdapter class and pass in my RGuiAction to it, but nothing gets fired off, I must be missing a step.

I also tried calling setDocumentInterface on my derived RActionAdpater which also didn't work.

Any help would be appreciated.

Thanks,

Andrew.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: C++ Example of using RGuAction and RActionAdapter

Post by andrew » Wed Sep 17, 2014 11:26 am

Implementing GUI actions in C++ is currently not recommended. All menus in QCAD are implemented as scripts at the top level (GUI action, menu, tool buttons, etc).

If a tool requires complex or CPU intensive algorithms, these could be implemented in a C++ plugin which is then called from the script.

May I ask what the motivation is to move things to C++? Performance? Confidentiality of proprietary code? Or something else?

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: C++ Example of using RGuAction and RActionAdapter

Post by Taygete » Wed Sep 17, 2014 2:54 pm

andrew wrote:Implementing GUI actions in C++ is currently not recommended. All menus in QCAD are implemented as scripts at the top level (GUI action, menu, tool buttons, etc).

If a tool requires complex or CPU intensive algorithms, these could be implemented in a C++ plugin which is then called from the script.

May I ask what the motivation is to move things to C++? Performance? Confidentiality of proprietary code? Or something else?
Hi Andrew,

Thanks for the quick response.

It sounds like what we are doing (scripts calling into C++ plugin) is the correct way.

I think the clients motivation is confidentiality of the proprietary code.

Thanks,

Andrew.

User avatar
andrew
Site Admin
Posts: 9037
Joined: Fri Mar 30, 2007 6:07 am

Re: C++ Example of using RGuAction and RActionAdapter

Post by andrew » Mon Sep 22, 2014 8:57 am

Taygete wrote:It sounds like what we are doing (scripts calling into C++ plugin) is the correct way.
Yes, that is certainly the recommended way.
Taygete wrote:I think the clients motivation is confidentiality of the proprietary code.
It is relatively easily possible to compile all scripts as resources into a C++ plugin. You can do this by simply adding all script files and resources (image files, ui files, etc) to the resources of your plugin in the plugin .pro file:

RESOURCES = scripts.qrc

The file scripts.qrc could look like this:
<!DOCTYPE RCC>
<RCC version="1.0">
  <qresource>
    <file alias="scripts/MyScripts/SomeTool/SomeTool.js">../../scripts/MyScripts/SomeTool/SomeTool.js</file>
  </qresource>
</RCC>
Once the plugin is loaded, the effect is the same as if there would be a file located at scripts/MyScripts/SomeTool/SomeTool.js with the contents of the file that was at ../../scripts/MyScripts/SomeTool/SomeTool.js during compilation of the plugin. Note that the plugin has to be recompiled if a script changes.

The idea here is primarily to 'hide' the script files from the user and encapsulate everything (C++ plugin, scripts, resources) properly into one single plugin file.
While this does not prevent the user from extracting script sources from the plugin, it makes it less likely that someone would attempt to do so.

There are also JavaScript code scramblers you could use to make the code less readable (remove comments, rename variables, etc). However, scripts will always be accessible to the end user in one way or another.

Taygete
Full Member
Posts: 50
Joined: Wed May 14, 2014 8:53 am

Re: C++ Example of using RGuAction and RActionAdapter

Post by Taygete » Sat Oct 11, 2014 3:33 pm

andrew wrote:
Taygete wrote:It sounds like what we are doing (scripts calling into C++ plugin) is the correct way.
Yes, that is certainly the recommended way.
Taygete wrote:I think the clients motivation is confidentiality of the proprietary code.
It is relatively easily possible to compile all scripts as resources into a C++ plugin. You can do this by simply adding all script files and resources (image files, ui files, etc) to the resources of your plugin in the plugin .pro file:

RESOURCES = scripts.qrc

The file scripts.qrc could look like this:
<!DOCTYPE RCC>
<RCC version="1.0">
  <qresource>
    <file alias="scripts/MyScripts/SomeTool/SomeTool.js">../../scripts/MyScripts/SomeTool/SomeTool.js</file>
  </qresource>
</RCC>
Once the plugin is loaded, the effect is the same as if there would be a file located at scripts/MyScripts/SomeTool/SomeTool.js with the contents of the file that was at ../../scripts/MyScripts/SomeTool/SomeTool.js during compilation of the plugin. Note that the plugin has to be recompiled if a script changes.

The idea here is primarily to 'hide' the script files from the user and encapsulate everything (C++ plugin, scripts, resources) properly into one single plugin file.
While this does not prevent the user from extracting script sources from the plugin, it makes it less likely that someone would attempt to do so.

There are also JavaScript code scramblers you could use to make the code less readable (remove comments, rename variables, etc). However, scripts will always be accessible to the end user in one way or another.
Hi Andrew,

Sorry for not replying earlier, I hadn't realised you had replied.

Thanks for the info, I hadn't considered putting the scripts in the resources, I will look into this.

Thanks,

Andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”