/** * Repaints the view. If the view has been invalidated before, * the view is redrawn from scratch. Otherwise, only a cached * buffer is drawn (very fast). * * \see invalidate */ void RGraphicsViewQt::paintEvent(QPaintEvent* e) { // enable timer for performance monitoring: //RDebug::startTimer(); RDocumentInterface* di = getDocumentInterface(); if (di!=NULL && di->isSuspended()) { QPainter wPainter(this); //wPainter.drawImage(0, 0, graphicsBuffer); wPainter.drawImage(getRect(), graphicsBuffer); //QPixmap pm; //pm.convertFromImage(graphicsBuffer); //wPainter.drawPixmap(this->rect(), pm); wPainter.end(); return; } updateImage(); // event is NULL for fake paint events (testing): if (e!=NULL) { QPainter wPainter(this); //wPainter.drawImage(0, 0, graphicsBufferWithPreview); wPainter.drawImage(getRect(), graphicsBufferWithPreview); //QPixmap pm; //pm.convertFromImage(graphicsBufferWithPreview); //wPainter.drawPixmap(this->rect(), pm); wPainter.end(); } //RDebug::stopTimer("paintEvent"); }
void RMainWindow::notifyListeners(bool withNull) { RDocument* document = NULL; RDocumentInterface* di = NULL; RGraphicsView* view = NULL; if (!withNull) { document = getDocument(); di = getDocumentInterface(); if (di!=NULL) { view = di->getLastKnownViewWithFocus(); } } notifyFocusListeners(di); notifyViewFocusListeners(view); notifyCoordinateListeners(di); notifySnapListeners(di); notifyTransactionListeners(document); notifyPropertyListeners(document); notifySelectionListeners(di); notifyLayerListeners(di); notifyPenListeners(di); notifyBlockListeners(di); notifyViewListeners(di); }
RGraphicsViewQt* RMdiChildQt::getLastKnownViewWithFocus() { RDocumentInterface* di = getDocumentInterface(); if (di==NULL) { return NULL; } return dynamic_cast<RGraphicsViewQt*>(di->getLastKnownViewWithFocus()); }
/** * Called immediately after the user has activated a new UCS to be used as current UCS. */ void RMainWindow::ucsSetEvent(const QString& ucsName) { RDocumentInterface* documentInterface = getDocumentInterface(); if (documentInterface == NULL) { return; } documentInterface->ucsSetEvent(ucsName); }
void RMainWindow::propertyChangeEvent(RPropertyEvent& event) { RDocumentInterface* documentInterface = getDocumentInterface(); if (documentInterface == NULL) { return; } documentInterface->propertyChangeEvent(event); }
/** * Maps the given model position to the grid. */ RVector ROrthoGrid::snapToGrid(const RVector& positionUcs) { RDocumentInterface* documentInterface = view.getDocumentInterface(); if (documentInterface==NULL) { return RVector::invalid; } RVector sp = spacing; if (!sp.isValid()) { sp = metaSpacing; if (isometric) { sp /= 2; } } int x = RMath::mround(positionUcs.x / sp.x); int y = RMath::mround(positionUcs.y / sp.y); int z = RMath::mround(positionUcs.z / sp.z); // closest grid point is not available in isometric grid, // find closest available grid point: if (isometric && (x+y)%2!=0) { int cx, cy; double minDist = RMAXDOUBLE; double dist; for (int ix=-1; ix<=1; ix++) { for (int iy=-1; iy<=1; iy++) { if (qAbs(ix) + qAbs(iy)!=1) { continue; } cx = RMath::mround(positionUcs.x / sp.x) + ix; cy = RMath::mround(positionUcs.y / sp.y) + iy; dist = positionUcs.getDistanceTo(RVector(cx*sp.x, cy*sp.y)); if (dist<minDist) { x = cx; y = cy; minDist = dist; } } } } RVector gridPositionUcs = RVector( x * sp.x, y * sp.y, z * sp.z ); RUcs ucs = documentInterface->getCurrentUcs(); return ucs.mapFromUcs(gridPositionUcs); }
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; }
void REventHandler::drawSnapLabel(QPainter* painter, const RVector& pos, const RVector& posRestriction, const QString& text) { RVector p = graphicsView->mapToView(pos); RVector pr = RVector::invalid; if (posRestriction.isValid()) { pr = graphicsView->mapToView(posRestriction); } RColor color = RSettings::getColor("GraphicsViewColors/TextLabelColor", RColor(249,198,31)); painter->setPen(color); QFont font = RSettings::getSnapLabelFont(); font.setPointSizeF(font.pointSizeF()*graphicsView->getDevicePixelRatio()); QFontMetrics fm(font); painter->setFont(font); int offset = 5 * graphicsView->getDevicePixelRatio(); if (!text.isEmpty()) { painter->drawText( p.x + offset, p.y + offset, fm.width(text)+10, fm.height()+10, Qt::AlignHCenter | Qt::AlignVCenter, text, NULL); } painter->drawEllipse(p.x-offset, p.y-offset, offset*2, offset*2); // restriction position: if (pr.isSane()) { painter->drawLine(pr.x, pr.y-offset, pr.x+offset, pr.y); painter->drawLine(pr.x+offset, pr.y, pr.x, pr.y+offset); painter->drawLine(pr.x, pr.y+offset, pr.x-offset, pr.y); painter->drawLine(pr.x-offset, pr.y, pr.x, pr.y-offset); } // display distance/angle: int display = RSettings::getIntValue("DisplaySettings/DisplayDistanceAngle", 0); if (display == 0) { return; } RDocumentInterface* di = graphicsView->getDocumentInterface(); RDocument* doc = graphicsView->getDocument(); RVector relativeZero = di->getRelativeZero(); double dist, angle; if (posRestriction.isSane()) { dist = relativeZero.getDistanceTo(posRestriction); angle = relativeZero.getAngleTo(posRestriction); } else { dist = relativeZero.getDistanceTo(pos); angle = relativeZero.getAngleTo(pos); } int lp = doc->getLinearPrecision(); QString distStr = RUnit::doubleToString(dist, lp); angle = RMath::rad2deg(angle); int ap = doc->getAnglePrecision(); QString angStr = RUnit::doubleToString(angle, ap); QString sep = RSettings::getStringValue("Input/PolarCoordinateSeparator", "<"); color = RSettings::getColor("GraphicsViewColors/MeasurementToolsColor", RColor(155,220,112)); painter->setPen(color); QString displayText; switch (display) { case 0: displayText = ""; break; case 1: displayText = distStr + sep + angStr + QChar(0x00b0); break; case 2: displayText = distStr; break; case 3: displayText = angStr + QChar(0x00b0); break; default: displayText = ""; } if (!displayText.isEmpty()) { painter->drawText( p.x + offset, p.y - 3*offset - fm.height(), fm.width(displayText)+10, fm.height()+10, Qt::AlignHCenter | Qt::AlignVCenter, displayText, NULL); } }