Ejemplo n.º 1
0
RBox RMemoryStorage::getBoundingBox(bool includeHiddenLayer) {
    if (!boundingBoxChanged) {
        return boundingBox;
    }

    RBlock::Id currentBlockId = getCurrentBlockId();
    boundingBox = RBox();
    maxLineweight = RLineweight::Weight000;
    QHash<RObject::Id, QSharedPointer<REntity> >::iterator it;
    for (it = entityMap.begin(); it != entityMap.end(); ++it) {
        QSharedPointer<REntity> e = *it;
        if (e.isNull() || e->isUndone()) {
            continue;
        }

        if (includeHiddenLayer) {
            QSharedPointer<RLayer> layer = queryLayerDirect(e->getLayerId());
            if (layer.isNull() || layer->isFrozen()) {
                continue;
            }
        }

        if (e->getBlockId() == currentBlockId) {
            boundingBox.growToInclude(e->getBoundingBox());
        }

        // resolve line width ByLayer:
        //QSharedPointer<RLayer> layer =
        //        queryLayerDirect(e->getLayerId());

        // don't resolve block references, if line weight is ByBlock,
        // the maxLinewidth will be adjusted when the block reference
        // is encountered:
        QStack<RBlockReferenceEntity*> blockRefStack;

        RLineweight::Lineweight lw =
                e->getLineweight(true, blockRefStack);
        if (!boundingBox.isValid()) {
            maxLineweight = lw;
        } else {
            maxLineweight = qMax(lw, maxLineweight);
        }
    }

    boundingBoxChanged = false;
    return boundingBox;
}
Ejemplo n.º 2
0
QSet<REntity::Id> RMemoryStorage::queryAllVisibleEntities() {
    QSet<REntity::Id> result;
    result.reserve(entityMap.count());
    RBlock::Id currentBlock = getCurrentBlockId();
    QHash<REntity::Id, QSharedPointer<REntity> >::iterator it;
    for (it = entityMap.begin(); it != entityMap.end(); ++it) {
        QSharedPointer<REntity> e = *it;
        if (e.isNull()) {
            continue;
        }
        if (e->isUndone()) {
            continue;
        }

        RBlock::Id blockId = e->getBlockId();
        if (blockId != currentBlock) {
            continue;
        }
        QSharedPointer<RBlock> block = queryBlockDirect(blockId);
        if (!block.isNull()) {
            if (block->isFrozen()) {
                continue;
            }
        }

        RLayer::Id layerId = e->getLayerId();
        QSharedPointer<RLayer> layer = queryLayerDirect(layerId);
        if (!layer.isNull()) {
            if (layer->isFrozen()) {
                continue;
            }
        }

        result.insert(e->getId());
    }
    return result;
}
Ejemplo n.º 3
0
bool RMemoryStorage::saveObject(QSharedPointer<RObject> object, bool checkBlockRecursion, bool keepHandles) {
    if (object.isNull()) {
        qWarning() << "RMemoryStorage::saveObject: object is NULL";
        return false;
    }

    //qDebug() << "saveObject: " << *object;

    // never allow two layers with identical names, update layer instead:
    QSharedPointer<RLayer> layer = object.dynamicCast<RLayer>();
    if (!layer.isNull()) {
        RLayer::Id id = getLayerId(layer->getName());
        if (id != RLayer::INVALID_ID && id != layer->getId()) {
            setObjectId(*layer, id);

            // never unprotect an existing protected layer:
            QSharedPointer<RLayer> existingLayer = queryLayerDirect(id);
            if (!existingLayer.isNull()) {
                if (existingLayer->isProtected()) {
                    layer->setProtected(true);
                }
            }
        }
    }

    // never allow two blocks with identical names, update block instead:
    QSharedPointer<RBlock> block = object.dynamicCast<RBlock> ();
    if (!block.isNull()) {
        RBlock::Id id = getBlockId(block->getName());
        if (id != RBlock::INVALID_ID && id != block->getId()) {
            setObjectId(*block, id);
        }
    }

    // never allow two linetypes with identical names, update linetype instead:
    QSharedPointer<RLinetype> linetype = object.dynamicCast<RLinetype> ();
    if (!linetype.isNull()) {
        RLinetype::Id id = getLinetypeId(linetype->getName());
        if (id != RLinetype::INVALID_ID && id != linetype->getId()) {
            setObjectId(*linetype, id);
        }
    }

    // avoid block recursions:
    if (checkBlockRecursion) {
        /*
        QSharedPointer<RBlockReferenceEntity> blockRef = object.dynamicCast<RBlockReferenceEntity> ();
        if (!blockRef.isNull()) {
            RBlock::Id id = blockRef->getBlockId();
            RBlock::Id refId = blockRef->getReferencedBlockId();
            // check if block with 'id' may contain a block reference which refers to
            // block with 'refid':
            // 201308: too slow for large, complex drawings:
            if (checkRecursion(id, refId)) {
                qCritical("RMemoryStorage::saveObject: recursion found");
                return false;
            }
        }
        */
    }

    QSharedPointer<REntity> entity = object.dynamicCast<REntity> ();

    if (!entity.isNull()) {
        Q_ASSERT_X(!queryLayerDirect(entity->getLayerId()).isNull(),
            "RMemoryStrorage::saveObject", "Layer of entity is NULL");
    }

    // assign new object ID to new objects:
    if (object->getId() == RObject::INVALID_ID) {
        setObjectId(*object, getNewObjectId());

        // only set new handle if handle is not set already:
        if (!keepHandles || object->getHandle()==RObject::INVALID_HANDLE) {
            setObjectHandle(*object, getNewObjectHandle());
        }

        // assign draw order to new entities:
        if (!entity.isNull() && entity->getDrawOrder()==0) {
            entity->setDrawOrder(getMaxDrawOrder());
            setMaxDrawOrder(getMaxDrawOrder()+1);
        }
    }

    // TODO: save original object for rollback:
    //if (inTransaction) {
        //transactionObjectMap[object->getId()] = object;
    //}

    objectMap[object->getId()] = object;
    objectHandleMap[object->getHandle()] = object;

    if (!entity.isNull()) {
        entityMap[entity->getId()] = entity;
        blockEntityMap.insert(entity->getBlockId(), entity);
        setMaxDrawOrder(qMax(entity->getDrawOrder()+1, getMaxDrawOrder()));
    }

    if (!layer.isNull()) {
        layerMap[object->getId()] = layer;
    }

    if (!block.isNull()) {
        blockMap[object->getId()] = block;
    }

    if (!linetype.isNull()) {
        linetypeMap[object->getId()] = linetype;
    }

    QSharedPointer<RDocumentVariables> docVars = object.dynamicCast<RDocumentVariables> ();
    if (!docVars.isNull()) {
        documentVariables = docVars;
    }

    return true;
}
Ejemplo n.º 4
0
RBox RMemoryStorage::getBoundingBox(bool ignoreHiddenLayers, bool ignoreEmpty) const {
    if (!boundingBoxChanged) {
        return boundingBox[ignoreHiddenLayers][ignoreEmpty];
    }

    RBlock::Id currentBlockId = getCurrentBlockId();
    boundingBox[0][0] = RBox();
    boundingBox[0][1] = RBox();
    boundingBox[1][0] = RBox();
    boundingBox[1][1] = RBox();
    maxLineweight = RLineweight::Weight000;

    QHash<RObject::Id, QSharedPointer<REntity> >::const_iterator it;
    for (it = entityMap.constBegin(); it != entityMap.constEnd(); ++it) {
        QSharedPointer<REntity> e = *it;
        if (e.isNull() || e->isUndone()) {
            continue;
        }

        //if (ignoreHiddenLayers) {
        bool layerHidden = false;
            QSharedPointer<RLayer> layer = queryLayerDirect(e->getLayerId());
            if (layer.isNull() || layer->isFrozen()) {
                layerHidden = true;
            }
        //}

        if (e->getBlockId() == currentBlockId) {
            //bb.growToInclude(e->getBoundingBox(ignoreEmpty));

            RBox bb = e->getBoundingBox(false);
            RBox bbIgnoreEmpty = e->getBoundingBox(true);

            if (!bb.isSane()) {
                continue;
            }

            boundingBox[0][0].growToInclude(bb);
            boundingBox[0][1].growToInclude(bbIgnoreEmpty);
            if (!layerHidden) {
                boundingBox[1][0].growToInclude(bb);
                boundingBox[1][1].growToInclude(bbIgnoreEmpty);
            }
        }

        // don't resolve block references, if line weight is ByBlock,
        // the maxLinewidth will be adjusted when the block reference
        // is encountered:
        QStack<REntity*> blockRefStack;

        RLineweight::Lineweight lw = e->getLineweight(true, blockRefStack);
        maxLineweight = qMax(lw, maxLineweight);
    }

    boundingBoxChanged = false;

//    qDebug() << "\n\nbb: " << boundingBox[0][0];
//    qDebug() << "bb ignoreEmpty: " << boundingBox[0][1];
//    qDebug() << "bb ignoreHiddenLayers: " << boundingBox[1][0];
//    qDebug() << "bb ignoreHiddenLayers, ignoreEmpty: " << boundingBox[1][1];

    return boundingBox[ignoreHiddenLayers][ignoreEmpty];
}