Esempio n. 1
0
RVector RSnapGrid::snap(const RVector& position, RGraphicsView& view, double range) {
    Q_UNUSED(range);

    RGrid* grid = view.getGrid();

    if (grid==NULL) {
        RVector ret = position;
        ret.valid = false;
        return ret;
    }

    lastSnap = grid->snapToGrid(position);
    return lastSnap;
}
Esempio n. 2
0
RVector RRestrictOrthogonal::restrictSnap(const RVector& position, const RVector& relativeZero) {
    RVector ret;
    RVector retX;
    RVector retY;

    if (documentInterface==NULL) {
        return ret;
    }

    RGraphicsView* view = documentInterface->getLastKnownViewWithFocus();
    if (view==NULL) {
        return ret;
    }

    ROrthoGrid* grid = dynamic_cast<ROrthoGrid*>(view->getGrid());
    if (grid!=NULL && grid->isIsometric()) {
        double d1, d2;
        double a1, a2;

        switch (grid->getProjection()) {
        default:
        case RS::IsoTop:
            a1 = RMath::deg2rad(30);
            a2 = RMath::deg2rad(150);
            // d1 = x / cos(30):
            d1 = (position.x - relativeZero.x) / (sqrt(3.0)/2);
            d2 = -d1;
            break;
        case RS::IsoLeft:
            a1 = RMath::deg2rad(150);
            a2 = RMath::deg2rad(90);
            d1 = (position.x - relativeZero.x) / (-sqrt(3.0)/2);
            d2 = (position.y - relativeZero.y);
            break;
        case RS::IsoRight:
            a1 = RMath::deg2rad(30);
            a2 = RMath::deg2rad(90);
            d1 = (position.x - relativeZero.x) / (sqrt(3.0)/2);
            d2 = (position.y - relativeZero.y);
            break;
        }

        retX = relativeZero + RVector::createPolar(d1, a1);
        retY = relativeZero + RVector::createPolar(d2, a2);
    }
    else {
        retX = RVector(relativeZero.x, position.y);
        retY = RVector(position.x, relativeZero.y);
    }

    switch (mode) {
    case RRestrictOrthogonal::Vertical:
        ret = retX;
        break;
    case RRestrictOrthogonal::Horizonal:
        ret = retY;
        break;
    case RRestrictOrthogonal::Orthogonal:
        if (retX.getDistanceTo(position) > retY.getDistanceTo(position)) {
            ret = retY;
        }
        else {
            ret = retX;
        }
        break;
    }

    lastSnap = ret;

    return ret;
}