Page 1 of 1

Add new property in property editor for RTextEntity

Posted: Thu Nov 16, 2017 8:03 pm
by sarlaa
Hi, I'm new to QCAD, and I'm wondering how can I extend RTextEntity properties ? I want to add visibility property, so I can show/hide a text.
Thanks in advance

Re: Add new property in property editor for RTextEntity

Posted: Thu Nov 16, 2017 8:24 pm
by andrew
The visibility of an entity would typically be controlled by its layer (preferred).

Text entities don't have a visibility flag. Adding such a feature would require adding this information to DXF/DWG when saving (as a custom property).

As an alternative, you could use block attributes instead of text labels.

Create a block with a single attribute definition:
Screen Shot 2017-11-16 at 19.19.27.png
Screen Shot 2017-11-16 at 19.19.27.png (202.81 KiB) Viewed 13928 times
Insert an instance of that block for each text label in the drawing. This creates a single block attribute for every instance of the block:
Screen Shot 2017-11-16 at 19.20.16.png
Screen Shot 2017-11-16 at 19.20.16.png (225.8 KiB) Viewed 13928 times
Block attributes (unlike text entities) do have a visibility property:
Screen Shot 2017-11-16 at 19.20.28.png
Screen Shot 2017-11-16 at 19.20.28.png (202.06 KiB) Viewed 13928 times

Re: Add new property in property editor for RTextEntity

Posted: Fri Nov 17, 2017 6:11 pm
by sarlaa
Thanks Andrew for your reply. I understand the approch to use block because they have visibility property.
but still i need to know how it is possible to exted class such RLineEntity
because my goal is :
to be able with a custom tool line to develop, to draw a line that automaticaly draw with it dimention of line as text
and that tool line have a custom property further : visibility, that allow showig or hiding line dimension

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 10:55 am
by andrew
You would have to work with custom properties and maybe a transaction listener to react to property changes.

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 12:36 pm
by sarlaa
Thanks for your reply, working with custom properties shows perfecty the property in the editor roperty.
As you said now for tracking property changes, do you have an exemple using RTransactionListener ?
Thanks in advance !

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 12:40 pm
by andrew
Yes, a transaction listener example (as C++ plugin) is available at:
https://github.com/qcad/qcad/tree/maste ... onlistener

And the JS equivalent:
https://github.com/qcad/qcad/tree/maste ... onListener

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 2:11 pm
by sarlaa
I saw the JS transaction listener example, and the given Ids of objects affected.
For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?

A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 5:06 pm
by andrew
sarlaa wrote:For the example transaction listener is applied on RMainWindowQt(appWin) is there a possibility to apply it on REntityLine ?
No. Your transaction listener is global and will always be triggered, for every change in every document. To find out what has changed you need to look into the RTransaction object.
sarlaa wrote:Otherwise I can't figure out how can I detect change made on custom property of REntityLine. Could you give me your instructions ?
I've updated the example:
https://github.com/qcad/qcad/blob/maste ... istener.js
sarlaa wrote:A question related to the given Id objects affected, I try to query the entity by Id as : var entity = doc.queryEntity(objId);
but that gives me a pointer to the entity. How can I get the entity ?
The entity pointer can be used just like the entity to retrieve data or change data. To pass a pointer to a function that expects an entity, you can use .data() to dereference. E.g.:

Code: Select all

entity2.copyAttributesFrom(entity1.data());

Re: Add new property in property editor for RTextEntity

Posted: Mon Nov 20, 2017 6:21 pm
by sarlaa
Again thanks Andrew for your reply, that was very helpful.

Now that I have all these pieces, if you may I have just one a further question, assuming that I have the object RLineEntity and the object RTextEntity (line dimension), is there a way to set the text dimension as an attribute of RLineEntity object by JS ? And reach after the attribute of dimension base on the object RLineEntity ?

Re: Add new property in property editor for RTextEntity

Posted: Tue Nov 21, 2017 10:51 am
by andrew
I'm not sure I understood this question correctly.

If you mean to reference an entity from another entity, the recommended way to do su is through the entity's handle (entity.getHandle()). Handles are persistent and don't change during the lifetime of an object. The dimension entity might have a handle of "0xa1" and the line entity might refer to the dimension entity through a custom property "dimension" with value "0xa1".

You can query objects by handle using

Code: Select all

document.queryObjectByHandle(handle);

Re: Add new property in property editor for RTextEntity

Posted: Mon Dec 04, 2017 12:54 pm
by sarlaa
Hi Andrew,

Doing as you described, i'll need to hide the custom property. Is there a way to do that ?

Re: Add new property in property editor for RTextEntity

Posted: Mon Dec 04, 2017 1:36 pm
by andrew
No, there is currently no easy way to hide custom properties.

Re: Add new property in property editor for RTextEntity

Posted: Mon Dec 04, 2017 3:30 pm
by sarlaa
Okay.

I have 3 questions more please :

1- Can I hide the button : Add Custom Property, from property editor custom section ?
2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener

Thanks in advance.

Re: Add new property in property editor for RTextEntity

Posted: Mon Dec 04, 2017 11:03 pm
by andrew
sarlaa wrote:1- Can I hide the button : Add Custom Property, from property editor custom section ?
You could install an RPropertyListener and look up and hide the button every time the property editor layout is rebuilt:

Code: Select all

var appWin = RMainWindowQt.getMainWindow();
var dock = appWin.findChild("PropertyEditorDock");
var button = dock.findChild("AddCustomProperty");
button.hide();
sarlaa wrote:2- I tried to change text translation in PropertyEditor_fr.ts file, but I don't see my changes (I have Qcad in french), have I to do something more ?
Yes, you'd need to release the translations using lrelease (comes with Qt) to create a qm file. ts files are translation sources.
sarlaa wrote:3- How can I at the start of qcad launch the listener : https://github.com/qcad/qcad/tree/maste ... onListener
Everything in init is called on start up. So you can simply place all code you want to run on start up into ExTransactionListener.init:

Code: Select all

ExTransactionListener.init = function(basePath) {
    ...
    var adapter = new RTransactionListenerAdapter();
    var appWin = EAction.getMainWindow();
    appWin.addTransactionListener(adapter);
    ...
};

Re: Add new property in property editor for RTextEntity

Posted: Tue Dec 05, 2017 12:47 pm
by sarlaa
Thanks very much Andrew, with your orientation all is working !