/** * 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); }
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; }
QList<RVector> RSnapTangential::snapEntity( QSharedPointer<REntity> entity, const RVector& point, const RBox& queryBox, RGraphicsView& view) { QList<RVector> ret; RDocumentInterface* di = view.getDocumentInterface(); if (di==NULL) { return ret; } QSharedPointer<RShape> shape = entity->getClosestShape(point, queryBox.getWidth()/2, true); if (shape.isNull()) { return ret; } QSharedPointer<RCircle> circle = shape.dynamicCast<RCircle>(); if (!circle.isNull()) { QList<RLine> lines = circle->getTangents(di->getLastPosition()); for (int i=0; i<lines.length(); i++) { ret.append(lines[i].getEndPoint()); } } QSharedPointer<RArc> arc = shape.dynamicCast<RArc>(); if (!arc.isNull()) { QList<RLine> lines = arc->getTangents(di->getLastPosition()); for (int i=0; i<lines.length(); i++) { ret.append(lines[i].getEndPoint()); } } QSharedPointer<REllipse> ellipse = shape.dynamicCast<REllipse>(); if (!ellipse.isNull()) { QList<RLine> lines = ellipse->getTangents(di->getLastPosition()); for (int i=0; i<lines.length(); i++) { ret.append(lines[i].getEndPoint()); } } return ret; }
QList<RVector> RSnapPerpendicular::snapEntity( QSharedPointer<REntity> entity, const RVector& point, const RBox& queryBox, RGraphicsView& view) { QList<RVector> ret; RDocumentInterface* di = view.getDocumentInterface(); if (di==NULL) { return ret; } QSharedPointer<RShape> shape = entity->getClosestShape(point, queryBox.getWidth()/2, true); if (shape.isNull()) { return ret; } ret.append(shape->getClosestPointOnShape(di->getLastPosition(), false)); return ret; }