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.
C++ Example of using RGuAction and RActionAdapter
Moderator: andrew
Forum rules
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Always indicate your operating system and QCAD version.
Attach drawing files, scripts and screenshots.
Post one question per topic.
Re: C++ Example of using RGuAction and RActionAdapter
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?
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?
Re: C++ Example of using RGuAction and RActionAdapter
Hi Andrew,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?
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.
Re: C++ Example of using RGuAction and RActionAdapter
Yes, that is certainly the recommended way.Taygete wrote:It sounds like what we are doing (scripts calling into C++ plugin) is the correct way.
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:Taygete wrote:I think the clients motivation is confidentiality of the proprietary code.
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.
Re: C++ Example of using RGuAction and RActionAdapter
Hi Andrew,andrew wrote:Yes, that is certainly the recommended way.Taygete wrote:It sounds like what we are doing (scripts calling into C++ plugin) is the correct way.
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:Taygete wrote:I think the clients motivation is confidentiality of the proprietary code.
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.
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.