Exemple #1
0
/**
 * The default implementation calls the \ref REntity::exportEntity() function
 * of the entity.
 * This method may use the \c currentEntity stack to access the
 * entity that is currently being exported.
 * Exporters can choose to reimplement this function to export an entity
 * in a target platform specific manner (e.g. to optimize things for
 * a specific platform).
 */
void RExporter::exportCurrentEntity(bool preview) {
    REntity* entity = getEntity();
    if (entity==NULL) {
        return;
    }

    // if this exporter exports a visual
    // representation of the drawing (scene, view, print)...
    if (isVisualExporter()) {
        // ... only export entities on visible layers:
        if (currentLayer!=NULL && currentLayer->isFrozen()) {
            return;
        }

        // ... only export entities in visible blocks:
        RBlockReferenceEntity* blockRef = dynamic_cast<RBlockReferenceEntity*>(entity);
        if (blockRef!=NULL) {
            RBlock::Id blockId = blockRef->getReferencedBlockId();
            if (blockId!=RBlock::INVALID_ID) {
                QSharedPointer<RBlock> block = document->queryBlockDirect(blockId);
                if (!block.isNull() && block->isFrozen()) {
                    return;
                }
            }
        }
    }

    setEntityAttributes();
    entity->exportEntity(*this, preview);
}
Exemple #2
0
/**
 * Sets the current entity to the given entity and calls \ref exportEntity().
 * Note that entity is a temporary clone.
 */
void RExporter::exportEntity(REntity& entity, bool preview, bool allBlocks, bool forceSelected) {
    RDocument* doc = entity.getDocument();
    if (doc==NULL) {
        doc = document;
    }

    // entity not on current block and allBlocks==false, break:
    if (!allBlocks && doc->getCurrentBlockId()!=entity.getBlockId()) {
        //unexportEntity(entity.getId());
        return;
    }

    entityStack.push(&entity);

    // find layer of the current entity
    QSharedPointer<RLayer> layer;
    if (layerSource!=NULL) {
        RLayer::Id layerId = entity.getLayerId();
        layer = layerSource->queryLayerDirect(layerId);
        Q_ASSERT(!layer.isNull());
    }
    else {
        layer = doc->queryLayerDirect(entity.getLayerId());
        if (layer.isNull()) {
            qDebug() << "Document: " << *doc;
            qDebug() << "Layer ID: " << entity.getLayerId();
            Q_ASSERT_X(false, "RExporter::exportEntity", "layer is NULL");
        }
    }
    if (!layer.isNull()) {
        currentLayer = layer.data();
    }

    // find block reference of the current entity, ignore this entity:
    bool blockRefOrViewportSet = false;
    // check if this entity is a block reference:
    RBlockReferenceEntity* blockRef = dynamic_cast<RBlockReferenceEntity*>(&entity);
    if (blockRef!=NULL) {
        blockRefStack.push(blockRef);
        blockRefOrViewportSet = true;
    }
    // check if this entity is a viewport:
    RViewportEntity* viewPort = dynamic_cast<RViewportEntity*>(&entity);
    if (viewPort!=NULL) {
        blockRefStack.push(viewPort);
        blockRefOrViewportSet = true;
    }

    startEntity(/* topLevelEntity = */ blockRefOrViewportSet || blockRefStack.isEmpty());
    exportCurrentEntity(preview, forceSelected);
    endEntity();

    if (blockRefOrViewportSet) {
        blockRefStack.pop();
        //blockRefBS.clear();
    }
    currentLayer = NULL;

    entityStack.pop();
}
Exemple #3
0
void RGraphicsSceneQt::highlightEntity(REntity& entity) {
    beginPreview();
    // get painter paths for closest entity:
    QList<RPainterPath> painterPaths = getPainterPaths(entity.getId());
    for (int i = 0; i < painterPaths.size(); ++i) {
        painterPaths[i].setSelected(entity.isSelected());
        painterPaths[i].setHighlighted(true);
    }
    addToPreview(painterPaths);
    endPreview();
}
Exemple #4
0
void RExporter::setEntityAttributes() {
    REntity* currentEntity = getEntity();
    if (currentEntity == NULL) {
        return;
    }

    setColor(currentEntity->getColor(true, blockRefStack));
    setLineweight(currentEntity->getLineweight(true, blockRefStack));
    setLinetypeId(currentEntity->getLinetypeId(true, blockRefStack));

    setStyle(Qt::SolidLine);
    setBrushStyle(Qt::SolidPattern);
}
QSharedPointer<RLinetype> RClipboardOperation::copyEntityLinetype(
        REntity& entity,
        RDocument& src, RDocument& dest,
        bool overwriteLinetypes,
        RTransaction& transaction) const {

    return copyLinetype(entity.getLinetypeId(), src, dest, overwriteLinetypes, transaction);
}
QSharedPointer<RLayer> RClipboardOperation::copyEntityLayer(
    REntity& entity,
    RDocument& src, RDocument& dest,
    bool overwriteLayers,
    RTransaction& transaction) const {

    return copyLayer(entity.getLayerId(), src, dest, overwriteLayers, transaction);
}
Exemple #7
0
void RExporter::setEntityAttributes(bool forceSelected) {
    REntity* currentEntity = getEntity();
    if (currentEntity == NULL) {
        return;
    }

    if (forceSelected || currentEntity->isSelected()) {
        setColor(RSettings::getSelectionColor());
    }
    else {
        setColor(currentEntity->getColor(true, blockRefStack));
    }
    setLineweight(currentEntity->getLineweight(true, blockRefStack));
    setLinetypeId(currentEntity->getLinetypeId(true, blockRefStack));

    setStyle(Qt::SolidLine);
    setBrushStyle(Qt::SolidPattern);
}
Exemple #8
0
void RModel::addNewEntity( unsigned int blockx, unsigned int blocky, unsigned char bitx, unsigned char bity, std::string id ) {
  if ( dictionary->find( id ) ) {
    // Get the right block.
    RBlock *block = referenceBlockAt( blockx, blocky );
    // Get the right bit.
    RBit::Bit *bit = block->getBit( bitx, bity );
    // Create a new entity.
    REntity entity = dictionary->lookup( id );
    entity.setModel( this );
    entity.setBlock( block );
    entity.setBit( bit );
    // Add the entity to the bit.
    bit->entities.push_back( entity );
    // Finally, add the entity to the block.
    block->setBit( bit );
  }
  return;
}
Exemple #9
0
/**
 * The default implementation calls the \ref REntity::exportEntity() function
 * of the entity.
 * This method may use the \c currentEntity stack to access the
 * entity that is currently being exported.
 * Exporters can choose to reimplement this function to export an entity
 * in a target platform specific manner (e.g. to optimize things for
 * a specific platform).
 */
void RExporter::exportCurrentEntity(bool preview, bool forceSelected) {
    REntity* entity = getEntity();
    if (entity==NULL) {
        return;
    }

    // if this exporter exports a visual
    // representation of the drawing (scene, view, print)...
    if (isVisualExporter()) {
        // ... only export entities on visible layers:
        if (currentLayer!=NULL && currentLayer->isFrozen()) {
            return;
        }

        // ... only export entities in visible blocks:
        RBlockReferenceEntity* blockRef = dynamic_cast<RBlockReferenceEntity*>(entity);
        if (blockRef!=NULL) {
            RBlock::Id blockId = blockRef->getReferencedBlockId();
            if (blockId!=RBlock::INVALID_ID) {
                QSharedPointer<RBlock> block = document->queryBlockDirect(blockId);
                if (!block.isNull() && block->isFrozen()) {
                    return;
                }
            }
        }
    }

    setEntityAttributes(forceSelected);

    //bool sblt = getScreenBasedLinetypes();
    if ((forceSelected || entity->isSelected()) && RSettings::getUseSecondarySelectionColor()) {
        // first part of two color selection:
        //setScreenBasedLinetypes(true);
        twoColorSelectedMode = true;
    }

    entity->exportEntity(*this, preview, forceSelected);

    // selected? export again with second color and pattern:
    if (visualExporter) {
        if ((forceSelected || entity->isSelected()) &&
            RSettings::getUseSecondarySelectionColor() &&
            entity->getType()!=RS::EntityBlockRef &&
            entity->getType()!=RS::EntityText &&
            entity->getType()!=RS::EntityAttribute &&
            entity->getType()!=RS::EntityAttributeDefinition) {

            RColor secondarySelectionColor = RSettings::getColor("GraphicsViewColors/SecondarySelectionColor", RColor(Qt::white));
            setColor(secondarySelectionColor);
            //setStyle(Qt::CustomDashLine);
            setDashPattern(QVector<qreal>() << 2 << 3);
            entity->exportEntity(*this, preview, forceSelected);
        }
    }
    twoColorSelectedMode = false;
    //setScreenBasedLinetypes(sblt);
}
Exemple #10
0
QSharedPointer<RBlock> RClipboardOperation::copyEntityBlock(
    REntity& entity,
    RDocument& src,
    RDocument& dest,
    bool overwriteBlocks,
    bool toCurrentBlock,
    const QString& blockName,
    RTransaction& transaction) const {

    return copyBlock(entity.getBlockId(), src, dest, overwriteBlocks, toCurrentBlock, blockName, transaction);
}
Exemple #11
0
QList<RVector> REntity::getIntersectionPoints(
        const REntity& other, bool limited, const RBox& queryBox, bool ignoreComplex) const {

    bool same = false;

    // avoid intersection finding for intersections of interpolated entities
    // (e.g. splines) with themselves:
    if (getId()!=INVALID_ID && getId()==other.getId() && getDocument()==other.getDocument()) {
        const RShape* shape = getData().castToConstShape();
        if (shape!=NULL && shape->isInterpolated()) {
            same = true;
        }

        const RPolyline* pl = dynamic_cast<const RPolyline*>(shape);
        if (pl!=NULL) {
            same = true;
        }
    }

    return getData().getIntersectionPoints(other.getData(), limited, same, queryBox, ignoreComplex);
}
QSharedPointer<RLayer> RClipboardOperation::copyEntityLayer(
    REntity& entity,
    RDocument& src, RDocument& dest,
    bool overwriteLayers,
    RTransaction& transaction) const {

    // copy parent layers:
    QString layerName = entity.getLayerName();
    if (layerName.contains(" ... ")) {
        QStringList l = layerName.split(" ... ");
        l.removeLast();
        while (!l.isEmpty()) {
            QString parentLayerName = l.join(" ... ");
            QSharedPointer<RLayer> parentLayer = src.queryLayer(parentLayerName);
            if (parentLayer.isNull()) {
                break;
            }
            copyLayer(parentLayer->getId(), src, dest, overwriteLayers, transaction);
            l.removeLast();
        }
    }

    return copyLayer(entity.getLayerId(), src, dest, overwriteLayers, transaction);
}
/**
 * Adds the given entity (and its layer(s) and block reference(s)) to the
 * given document.
 *
 * \param blockName Name of an existing block in dest
 */
void RClipboardOperation::copyEntity(
        REntity& entity,
        RDocument& src, RDocument& dest,
        const RVector& offset,
        double scale,
        double unitScale,
        double rotation,
        bool flipHorizontal,
        bool flipVertical,
        bool toCurrentLayer,
        bool toCurrentBlock,
        bool overwriteLayers,
        bool overwriteBlocks,
        const QString& blockName,
        RTransaction& transaction,
        bool toModelSpaceBlock) const {

    bool overwriteLinetypes = false;

    QSharedPointer<RLayer> destLayer = copyEntityLayer(entity, src, dest, overwriteLayers, transaction);
    QSharedPointer<RLinetype> destLinetype = copyEntityLinetype(entity, src, dest, overwriteLinetypes, transaction);

    // add block the entity belongs to, if the block exists it is overwritten
    // if 'overwriteBlocks' is true:
    QSharedPointer<RBlock> srcBlock =
        src.queryBlock(entity.getBlockId());
    if (srcBlock.isNull()) {
        qWarning("RClipboardOperation::copyToDocument: "
            "block of entity is NULL.");
        return;
    }
    QString srcBlockName = srcBlock->getName();
    QSharedPointer<RBlock> destBlock;
    if (copiedBlocks.contains(srcBlockName)) {
        destBlock = copiedBlocks.value(srcBlockName);
    }
    else {
        QString destBlockName;
        if (!blockName.isNull()) {
            destBlockName = blockName;
        }
        else {
            if (toCurrentBlock) {
                destBlockName = dest.getBlockName(dest.getCurrentBlockId());
            }
            else {
                destBlockName = srcBlock->getName();
            }
        }
        if (!dest.hasBlock(destBlockName) || (overwriteBlocks && blockName.isNull())) {
            destBlock = QSharedPointer<RBlock> (srcBlock->clone());
            dest.getStorage().setObjectId(*destBlock.data(), RObject::INVALID_ID);
            dest.getStorage().setObjectHandle(*destBlock.data(), RObject::INVALID_HANDLE);
            destBlock->setDocument(&dest);
            if (dest.hasBlock(destBlockName)) {
                if (!transaction.overwriteBlock(destBlock)) {
                    destBlock = dest.queryBlock(destBlockName);
                }
            }
            else {
                transaction.addObject(destBlock);
            }
        } else {
            destBlock = dest.queryBlock(destBlockName);
        }

        copiedBlocks.insert(srcBlockName, destBlock);
    }

    Q_ASSERT(destBlock->getId()!=RBlock::INVALID_ID);

    // entity is a block reference:
    // add entities of the block the block reference refers to (the block
    // definition is then added automatically):
    // if block contents has already been copied, do nothing
    RBlockReferenceEntity* blockRef =
        dynamic_cast<RBlockReferenceEntity*>(&entity);
    if (blockRef!=NULL && !copiedBlockContents.contains(blockRef->getReferencedBlockId())) {
        QSharedPointer<RBlock> refBlock =
            src.queryBlock(blockRef->getReferencedBlockId());
        if (refBlock.isNull()) {
            qWarning("RClipboardOperation::copyToDocument: "
                "entity references a NULL block.");
            return;
        }

        copiedBlockContents.insert(blockRef->getReferencedBlockId());

        // TODO: don't do this twice:
        //qDebug() << "RClipboardOperation::copyToDocument: copying block: " << refBlock->getName();
        // if block exists in dest, it has already been copied or was
        // already there and needs to be overwritten:
        QSharedPointer<RBlock> refBlockDest = dest.queryBlock(refBlock->getName());
        if (refBlockDest.isNull() || overwriteBlocks) {
            QSet<REntity::Id> ids = src.queryBlockEntities(refBlock->getId());
            bool first = true;
            QSet<REntity::Id>::iterator it;
            for (it=ids.begin(); it!=ids.end(); ++it) {
                QSharedPointer<REntity> e = src.queryEntityDirect(*it);
                if (e.isNull()) {
                    continue;
                }

                copyEntity(
                    *e.data(),
                    src, dest,
                    RVector::nullVector,
                    1.0,          // scale from user options not applied to block contents 
                                  // but to block reference
                    unitScale, 
                    0.0,
                    false, false, // no flips
                    false, false, // keep original block and layer
                    overwriteLayers, first && overwriteBlocks,
                    QString(),
                    transaction,
                    false         // not to model space but actual block
                );
                first = false;
            }
        }
    }

    // add entity self:
    QSharedPointer<REntity> destEntity = QSharedPointer<REntity>(entity.clone());
    //dest.getStorage().setObjectId(*destEntity.data(), RObject::INVALID_ID);
    dest.getStorage().setObjectHandle(*destEntity.data(), RObject::INVALID_HANDLE);
    destEntity->setSelected(false);

    // apply transformations:
    if (flipHorizontal) {
        destEntity->flipHorizontal();
    }
    if (flipVertical) {
        destEntity->flipVertical();
    }
    if (blockRef!=NULL) {
        destEntity->scale(scale);
    }
    else {
        destEntity->scale(scale * unitScale);
    }
    destEntity->rotate(rotation);
    // correct block reference offset. necessary for unit conversion:
    if (blockRef!=NULL && src.getUnit()!=dest.getUnit()) {
        destEntity->move(-blockRef->getPosition());
        destEntity->move(blockRef->getPosition() * unitScale);
    }
    destEntity->move(offset);

    destEntity->setDocument(&dest);
    if (toCurrentLayer) {
        // paste to current layer:
        destEntity->setLayerId(dest.getCurrentLayerId());
    }
    else {
        // paste to original layer:
        Q_ASSERT(!destLayer.isNull());
        destEntity->setLayerId(destLayer->getId());
    }

    destEntity->setLinetypeId(destLinetype->getId());

    if (toModelSpaceBlock) {
        destEntity->setBlockId(dest.getModelSpaceBlockId());
    }
    else {
        destEntity->setBlockId(destBlock->getId());
    }

    // correct referenced block id of pasted block reference:
    QSharedPointer<RBlockReferenceEntity> destBlockRef =
        destEntity.dynamicCast<RBlockReferenceEntity>();
    if (!destBlockRef.isNull() && blockRef!=NULL) {
        QString bn = src.getBlockName(blockRef->getReferencedBlockId());
        RBlock::Id blockId = dest.getBlockId(bn);
        destBlockRef->setReferencedBlockId(blockId);
//        qDebug() << "not yet updated block ref: " << *destBlockRef;
//        destBlockRef->update();
//        qDebug() << "updated block ref: " << *destBlockRef;
    }

    transaction.addObject(destEntity, false, true);
}
Exemple #14
0
/**
 * Starts a new painter path to export geometry into.
 * \return True if a path has been created, false if there is already a
 *      valid path.
 */
bool RGraphicsSceneQt::beginPath() {
    if (!exportToPreview) {
        Q_ASSERT(getEntity() != NULL);
    }

    if (currentPainterPath.isValid()) {
        return false;
    }

    currentPainterPath = RPainterPath();
    currentPainterPath.setZLevel(0);

    if (screenBasedLinetypes && currentPen.style()==Qt::SolidLine) {
        QVector<qreal> pat = currentLinetypePattern.getScreenBasedLinetype();
        if (!pat.isEmpty()) {
            currentPen.setDashPattern(pat);
        }
    }

    REntity* entity = getEntity();

    if (draftMode || screenBasedLinetypes || twoColorSelectedMode) {
        QPen localPen = currentPen;
        if (twoColorSelectedMode) {
            // fixed width for selected entities in two color selected mode:
            localPen.setCosmetic(true);
            localPen.setWidth(3);
        }
        else {
            if (draftMode) {
                localPen.setWidth(0);
            }
            else {
                // screen based line weights:
                localPen.setCosmetic(true);
                // magic number 4.25 to scale approximately, so 1mm width is 1mm on screen:
                localPen.setWidth(currentPen.widthF()*4.25);
            }
        }
        currentPainterPath.setPen(localPen);
    }
    else {
        if (entity!=NULL && entity->getCustomProperty("QCAD", "ScreenWeight", false)==true) {
            QPen localPen = currentPen;
            localPen.setCosmetic(true);
            localPen.setWidthF(entity->getLineweight()/10);
            currentPainterPath.setPen(localPen);
        }
        else {
            currentPainterPath.setPen(currentPen);
        }
    }

    currentPainterPath.setBrush(QBrush(Qt::NoBrush));
    currentPainterPath.setPixelSizeHint(pixelSizeHint);

    if (!exportToPreview) {
        if (entity!=NULL && entity->isSelected()) {
            currentPainterPath.setSelected(true);
        }
    }
    else {
        if (entity!=NULL && entity->getCustomProperty("QCADCAM", "simulation", false)==true) {
            currentPainterPath.setHighlighted(true);
        }
    }

    return true;
}