[SOLVED] C++,Modifyng entities moves them to current layer

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

[SOLVED] C++,Modifyng entities moves them to current layer

Post by Taygete » Mon Jan 26, 2015 6:39 pm

Hi Andrew,

I am seeing something odd when modifying entities.

If I modify a number of entities (each on a different layer) then call applyOperation it seems to be changing the entities layer to the documents currently selected layer. I thought I could overcome this by calling the entities setProperty(REntity::PropertyLayer...) method but this doesn't seem to make any difference to the outcome.

For instance, say I have three layers named Layer1, Layer2, and Layer3, each layer has a number of entities are assigned to it. I assumed modifying a custom property on each entity would not change the layer it is assigned too but after calling applyOperation this is what seems to be happening and all entities end up on the same layer. I then thought calling setProperty to set the Layer so it stays on the layer it is already assigned to but this doesn't work either. It is as if during the applyOperation method call the modified entities are being moved to the documents current layer rather than leaving them on their current layer.

Assuming the following code below (Note: CadRunItem and CadItem are my classes), which is slightly different to the scenario above to simplify the code:
RModifyObjectsOperation *modOp = new RModifyObjectsOperation();

// Sanity check
if (modOp != NULL) {

    // The layer we want to move the entity into too.
    QString layerName = "Layer3";

    // Loop through each item in the list and change the entities properties
    foreach (CadRunItem rItem, theRunItems.getItems()) {
            CadItem cItem = rItem.getItem();

            QSharedPointer<REntity> entity;
            cItem.convertToEntity(docInterface, entity);

            if (entity.isNull()) {
                continue;
            }

            // Set Layer
            entity->setProperty(REntity::PropertyLayer, layerType);
            // Do other things with entity
            entity->setCustomProperty(...);
            .... 
            modOp->addObject(entity);
    }

    // Apply the changes to the document
    docInterface->applyOperation(modOp);
}
In the code above I assumed the call to setProperty

Code: Select all

entity->setProperty(REntity::PropertyLayer, layerType);
Would set the entities layer property to "Layer3" after calling the applyOperation. However this doesn't seem to be happening and it is setting all the entities in the list to a different layer from "Layer3".

I hope that makes sense please let me know if you want clarification.

Thanks,

Andrew.
Last edited by Taygete on Tue Jan 27, 2015 12:24 pm, edited 1 time in total.

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

Re: C++,Modifyng entities moves them to currently selected l

Post by andrew » Tue Jan 27, 2015 10:45 am

Try:
modOp->addObject(entity, false);
False here indicates that you don't want to use the current attributes and layer for the entity (default).

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

Re: C++,Modifyng entities moves them to currently selected l

Post by Taygete » Tue Jan 27, 2015 12:23 pm

andrew wrote:Try:
modOp->addObject(entity, false);
False here indicates that you don't want to use the current attributes and layer for the entity (default).
Thanks Andrew, that solved the issue :)

Andrew.

Post Reply

Return to “QCAD Programming, Script Programming and Contributing”