Adding objects in a batch

Discussion forum for contributors and developers who are using the QCAD version 3 ECMAScript development platform or the C++ plugin interface or who are otherwise looking to contribute to QCAD (translations, documentation, etc).

Moderator: andrew

Adding objects in a batch

Postby hungerburg » Mon Feb 06, 2012 4:03 pm

In my scripts I add objects one primitive by one primitive. They execute quite fast. Still I want to ask:

For performance reasons, can one join several RAddObject Operations into one RAddObjects Operation? When I switch layers inbetween those, will the entities end up in the right ones then? Or does qcad optimze already?
User avatar
hungerburg
Senior Member
 
Posts: 117
Joined: Fri May 28, 2010 7:35 pm

Postby andrew » Sun Feb 12, 2012 8:54 pm

Yes, you can add multiple objects in one transaction. Setting the current to a different takes effect immediately and is not part of the transaction (i.e. changing the current layer cannot be undone).
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

Postby hungerburg » Tue Feb 14, 2012 4:59 pm

Seems I am a little confused by RAddObjectsOperation and RAddObjectOperation. In fact I only use the first plural one and never the second singular one.

These operations I call from helper functions, that draw geometric primitives, that create both operation and objects internally only.

Code: Select all
   var operation = new RAddObjectsOperation(false);
   var linie = new RLineData(linien[l][0], linien[l][1]);
   var entity = new RLineEntity(zeichnung.document, linie);
   operation.addObject(entity);
   zeichnung.documentInterface.applyOperation(operation);


If instead I kept on adding objects to the operation, and applied it only later, then would all objects end up in the same layer? Or in the layer, that was active, at the time they were added to the operation? Could it be about useCurrentAttributes?

I know it is trivial to find out myself, but I am lazy right now, please excuse the many words too, but maybe its interesting for others too. It may prove a performance benefit, especially when the script runs in the GUI.
User avatar
hungerburg
Senior Member
 
Posts: 117
Joined: Fri May 28, 2010 7:35 pm

Postby andrew » Tue Feb 14, 2012 8:41 pm

hungerburg wrote:If instead I kept on adding objects to the operation, and applied it only later, then would all objects end up in the same layer? Or in the layer, that was active, at the time they were added to the operation? Could it be about useCurrentAttributes?


To the layer that was the current layer when the object was added if 'useCurrentAttributes' is true (default) or to the layer explicitly set on the entity (setLayer(...)) if 'useCurrentAttributes' is false.
User avatar
andrew
Site Admin
 
Posts: 2383
Joined: Fri Mar 30, 2007 6:07 am

Postby hungerburg » Wed Feb 15, 2012 5:11 pm

Thank You Andrew, with this information I started to refactor. I nearly gave in, as everything would end up in the same layer. But now it works :)

Code: Select all
var operation = new RAddObjectsOperation(false); // not undo-able
document.setCurrentLayer("A");
// […] create some entity
operation.addObject(entity, false); // stick it to current layer
document.setCurrentLayer("B");
// […] add some more objects to the operation
operation.addObject(entity, false); // stick it to current layer
// […] add some more objects to the operation
documentInterface.applyOperation(operation);

The useCurrentAttributes flag works like this:
    false: use attributes current at the time of the "add"
    true: use attributes current at the time of the "apply"

The performance gain is not noticeable though in command line mode or in linux GUI. I will see in windows GUI, because that is a little sluggish, when running scripts, compared to the linux one. Maybe that is only the grafics card though…
User avatar
hungerburg
Senior Member
 
Posts: 117
Joined: Fri May 28, 2010 7:35 pm


Return to QCAD 3 Developers and Contributors

Who is online

Users browsing this forum: No registered users and 1 guest

cron