void RBlockReferenceEntity::exportEntity(RExporter& e, bool preview) const {
    const RDocument* document = getDocument();
    if (document==NULL) {
        qWarning() << "RBlockReferenceEntity::exportEntity: document is NULL";
        return;
    }

    static int recursionDepth = 0;
    if (recursionDepth++>16) {
        recursionDepth--;
        qWarning() << "RBlockReferenceEntity::exportEntity: "
            << "maximum recursion depth reached";
        data.groundReferencedBlockId();
        return;
    }

    data.update();

    QSet<REntity::Id> ids = document->queryBlockEntities(data.referencedBlockId);
//    QSet<REntity::Id> ids = document->queryBlockReferenceEntities(getId());
    //QSet<REntity::Id> idsAttr = document->queryAttributes(objectId);
    //ids.unite(idsAttr);

    QList<REntity::Id> list = document->getStorage().orderBackToFront(ids);
    int i;
    QList<REntity::Id>::iterator it;
    for (it = list.begin(), i = 0; it != list.end(); it++, i++) {
        if (preview && i>RSettings::getPreviewEntities()) {
            break;
        }

        QSharedPointer<REntity> entity = data.queryEntity(*it);
        if (entity.isNull()) {
            continue;
        }
        e.exportEntity(*entity, preview, true);
    }

    // too slow:
//    RDebug::startTimer(4);

//    if (preview) {
//        // TODO: if we interrupted to limit the preview, add bounding box to preview
//        RBox bb = data.getBoundingBox();
//        QList<RLine> l = bb.getLines2d();
//        for (int k=0; k<l.count(); ++k) {
//            e.exportLine(l[k]);
//        }
//    }

//    RDebug::stopTimer(4, "bb");

    recursionDepth--;
}
Exemple #2
0
void RViewportEntity::exportEntity(RExporter& e, bool preview, bool forceSelected) const {
    Q_UNUSED(preview);
    Q_UNUSED(forceSelected);

    RDocument* doc = (RDocument*)getDocument();
    if (doc==NULL) {
        return;
    }

    RBox viewportBox(data.position, data.width, data.height);

    // if layer is visible, export viewport frame
    // viewport contents is always exported (unless viewport if off):
    if (isVisible()) {
        // export viewport frame to layer of viewport:
        e.setBrush(Qt::NoBrush);
        QList<RLine> lines = viewportBox.getLines2d();
        for (int i=0; i<lines.length(); i++) {
            e.exportLine(lines[i]);
        }
    }

    // if viewport is off, we're done:
    if (isOff()) {
        return;
    }

    // clip rectangle export
    e.exportClipRectangle(viewportBox);

    RVector offset(0,0);
    offset -= data.viewCenter * data.scale;
    offset -= data.viewTarget * data.scale;

    // create temporary block reference to model space block:
    RBlockReferenceData modelSpaceData(
        doc,
        RBlockReferenceData(
            doc->getModelSpaceBlockId(),
            data.position + offset,
            RVector(data.scale, data.scale),
            0.0
        )
    );
    modelSpaceData.update();

    // start clipping from here:
    e.setClipping(true);

    // render model space block reference into viewport:
    QSet<REntity::Id> ids = doc->queryBlockEntities(doc->getModelSpaceBlockId());
    QList<REntity::Id> list = doc->getStorage().orderBackToFront(ids);
    int i;
    QList<REntity::Id>::iterator it;
    for (it = list.begin(), i = 0; it != list.end(); it++) {
        if (preview && i>RSettings::getPreviewEntities()) {
            break;
        }

        QSharedPointer<REntity> entity = modelSpaceData.queryEntity(*it);
        if (entity.isNull()) {
            continue;
        }

        entity->rotate(data.rotation, data.position);

        // prevent recursions:
        if (entity->getType()==RS::EntityViewport) {
            continue;
        }

        RBox bb = entity->getBoundingBox();
        if (!viewportBox.intersects(bb)) {
            continue;
        }

        entity->scaleVisualProperties(data.scale);

        e.exportEntity(*entity, preview, true);

        i++;
    }

    e.setClipping(false);
}