예제 #1
0
/**
 * Zooms the view in a way that the given window is visible and fills the view.
 * The view is updated.
 */
void RGraphicsView::zoomTo(const RBox& window, int margin) {
    if (!window.isValid()) {
        return;
    }

    saveViewport();

    RVector f(RMAXDOUBLE, RMAXDOUBLE);
    double w = window.getWidth();
    double h = window.getHeight();

    if (w<1.0e-6 && h<1.0e-6) {
        return;
    }

    if (w>1.0e-6) {
        f.x = (getWidth() - 2 * margin) / w;
    }
    if (h>1.0e-6) {
        f.y = (getHeight() - 2 * margin) / h;
    }

    f.x = f.y = qMin(f.x, f.y);

    if (RSettings::getLimitZoomAndScroll() && f.x < 1.0e-9) {
        //f.x = f.y = 1.0;
        return;
    }

    setFactor(f.x);

    /*
    RBox viewWindow = mapToView(window);
    qDebug() << "viewWindow: " << viewWindow;
    RVector size = viewWindow.getSize();
    RVector f;

    if (size.x > 1.0e-6) {
        f.x = (getWidth() - 2 * margin) / size.x;
    } else {
        f.x = RMAXDOUBLE;
    }

    if (size.y > 1.0e-6) {
        f.y = (getHeight() - 2 * margin) / size.y;
    } else {
        f.y = RMAXDOUBLE;
    }

    f.x = f.y = qMin(f.x, f.y);

    if (f.x < 1.0e-6 || f.x == RMAXDOUBLE) {
        f.x = f.y = 1.0;
    }

    setFactor(factor * f.x);
    */

    centerToBox(window);
}
예제 #2
0
bool RGraphicsView::zoomToSelection() {
    RDocument* document = getDocument();
    if (document == NULL) {
        return false;
    }
    RBox selectionBox = document->getSelectionBox();
    if (selectionBox.isValid() && (selectionBox.getWidth()>RS::PointTolerance || selectionBox.getHeight()>RS::PointTolerance)) {
        zoomTo(selectionBox, getMargin());
        return true;
    }
    return false;
}
예제 #3
0
/**
 * \return The bounding box that contains this entity.
 */
RBox REntityData::getBoundingBox() const {
    RBox bb;
    QList<QSharedPointer<RShape> > shapes = getShapes();
    for (int i=0; i<shapes.size(); i++) {
        if (!bb.isValid()) {
            bb = shapes.at(i)->getBoundingBox();
        }
        else {
            bb.growToInclude(shapes.at(i)->getBoundingBox());
        }
    }
    return bb;
}
예제 #4
0
/**
 * \return List of bezier spline segments which together represent this curve.
 */
QList<RSpline> RSpline::getBezierSegments(const RBox& queryBox) const {
    // spline is a single bezier segment:
    if (countControlPoints()==getDegree()+1) {
        return QList<RSpline>() << *this;
    }

    updateInternal();

    QList<RSpline> ret;
#ifndef R_NO_OPENNURBS
    ON_NurbsCurve* dup = dynamic_cast<ON_NurbsCurve*>(curve.DuplicateCurve());
    if (dup==NULL) {
        return ret;
    }

    dup->MakePiecewiseBezier();
    for (int i=0; i<=dup->CVCount() - dup->Order(); ++i) {
        ON_BezierCurve bc;
        if (!dup->ConvertSpanToBezier(i, bc)) {
            continue;
        }

        QList<RVector> ctrlPts;
        for (int cpi=0; cpi<bc.CVCount(); cpi++) {
            ON_3dPoint onp;
            bc.GetCV(cpi, onp);
            ctrlPts.append(RVector(onp.x, onp.y, onp.z));
        }
        RSpline bezierSegment(ctrlPts, degree);

        if (!queryBox.isValid() || queryBox.intersects(bezierSegment.getBoundingBox())) {
            ret.append(bezierSegment);
        }
    }
    delete dup;
 #endif

    return ret;
}