RLinetype::Id REntityData::getLinetypeId(bool resolve, const QStack<RBlockReferenceEntity*>& blockRefStack) const { if (!resolve) { return getLinetypeId(); } if (document!=NULL) { if (document->isByLayer(linetypeId)) { QSharedPointer<RLayer> l = document->queryLayerDirect(layerId); if (l.isNull()) { qWarning() << "REntityData::getLinetypeId: " "line type is ByLayer but layer is invalid"; return RLinetype::INVALID_ID; } return l->getLinetypeId(); } else if (document->isByBlock(linetypeId)) { if (blockRefStack.isEmpty()) { qWarning() << "REntityData::getColor: " "color is ByBlock but entity not in block reference"; return RLinetype::INVALID_ID; } return blockRefStack.top()->getLinetypeId(true, blockRefStack); } } return getLinetypeId(); }
RLinetype::Id REntityData::getLinetypeId(bool resolve, const QStack<REntity*>& blockRefStack) const { if (!resolve) { return getLinetypeId(); } if (document!=NULL) { if (document->isByLayer(linetypeId)) { QSharedPointer<RLayer> l = document->queryLayerDirect(layerId); if (l.isNull()) { qWarning() << "REntityData::getLinetypeId: " "line type is ByLayer but layer is invalid"; return RLinetype::INVALID_ID; } if (RSettings::isLayer0CompatibilityOn()) { // entity in block on layer 0, use attributes of block reference if compatibility mode is on: if (l->getName()=="0") { if (blockRefStack.isEmpty()) { return l->getLinetypeId(); } return blockRefStack.top()->getLinetypeId(true, blockRefStack); } } return l->getLinetypeId(); } else if (document->isByBlock(linetypeId)) { if (blockRefStack.isEmpty()) { // qWarning() << "REntityData::getColor: " // "color is ByBlock but entity not in block reference"; return RLinetype::INVALID_ID; } return blockRefStack.top()->getLinetypeId(true, blockRefStack); } } return getLinetypeId(); }
/** * Stream operator for QDebug */ void REntity::print(QDebug dbg) const { dbg.nospace() << "REntity("; RObject::print(dbg); dbg.nospace() << ", type: " << getType() << ", layerId: " << getLayerId() << ", blockId: " << getBlockId() << ", lineweight: " << getLineweight() << ", linetypeId: " << getLinetypeId() << ", color: " << getColor() << ", drawOrder: " << getDrawOrder() << ", selectionStatus: " << isSelected() << ", boundingBoxes: " << getBoundingBoxes() << ")"; }
/** * Stream operator for QDebug */ void REntity::print(QDebug dbg) const { dbg.nospace() << "REntity("; RObject::print(dbg); dbg.nospace() << ", type: " << getType() << ", layerId: " << getLayerId() << ", blockId: " << getBlockId() << ", parentId: " << getParentId() << ", childIds: " << getDocument()->queryChildEntities(getId()) << ", lineweight: " << getLineweight() << ", linetypeId: " << getLinetypeId() << ", linetypeScale: " << getLinetypeScale() << ", color: " << getColor() << ", drawOrder: " << getDrawOrder() << ", selectionStatus: " << isSelected() << ", boundingBoxes: " << getBoundingBoxes() << ")"; }
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; }