📄 rs_graphicview.cpp
字号:
//painter->moveTo(ix1, iy1); for (a=a1-aStep; a>=a2cp; a-=aStep) { k2x = RS_Math::round(center.x+cos(a)*radius); k2y = RS_Math::round(center.y-sin(a)*radius); //if(graphic->isPointOnScreen(k2x, k2y) || // graphic->isPointOnScreen(k1x, k1y) ) { createDirectPainter(); painter->setPen(pen); if ((k2x>=0 && k2x<=painter->getWidth() && k2y>=0 && k2y<=painter->getHeight()) || (k1x>=0 && k1x<=painter->getWidth() && k1y>=0 && k1y<=painter->getHeight())) { //painter->lineTo(k2x, k2y); painter->drawLine(RS_Vector(k1x, k1y), RS_Vector(k2x, k2y)); simulationDelay(); } //createDirectPainter(); //painter->setPen(pen); //painter->moveTo(k2x, k2y); k1x=k2x; k1y=k2y; } createDirectPainter(); painter->setPen(pen); //painter->lineTo(ix2, iy2); painter->drawLine(RS_Vector(k2x, k2y), RS_Vector(ix2, iy2)); } }}/** * @return Pointer to the static pattern struct that belongs to the * given pattern type or NULL. */RS_LineTypePattern* RS_GraphicView::getPattern(RS2::LineType t) { switch (t) { case RS2::SolidLine: return &patternSolidLine; break; case RS2::DotLine: return &patternDotLine; break; case RS2::DotLine2: return &patternDotLine2; break; case RS2::DotLineX2: return &patternDotLineX2; break; case RS2::DashLine: return &patternDashLine; break; case RS2::DashLine2: return &patternDashLine2; break; case RS2::DashLineX2: return &patternDashLineX2; break; case RS2::DashDotLine: return &patternDashDotLine; break; case RS2::DashDotLine2: return &patternDashDotLine2; break; case RS2::DashDotLineX2: return &patternDashDotLineX2; break; case RS2::DivideLine: return &patternDivideLine; break; case RS2::DivideLine2: return &patternDivideLine2; break; case RS2::DivideLineX2: return &patternDivideLineX2; break; case RS2::CenterLine: return &patternCenterLine; break; case RS2::CenterLine2: return &patternCenterLine2; break; case RS2::CenterLineX2: return &patternCenterLineX2; break; case RS2::BorderLine: return &patternBorderLine; break; case RS2::BorderLine2: return &patternBorderLine2; break; case RS2::BorderLineX2: return &patternBorderLineX2; break; case RS2::LineByLayer: return &patternBlockLine; break; case RS2::LineByBlock: return &patternBlockLine; break; default: break; } return NULL;}/** * This virtual method can be overwritten to draw the absolute * zero. It's called from within drawIt(). The default implemetation * draws a simple red round zero point. * * @see drawIt() */void RS_GraphicView::drawAbsoluteZero() { bool painterCreated = false; // create a temporary painter device if (painter==NULL) { createDirectPainter(); painterCreated = true; } int zr = 20; RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine); p.setScreenWidth(0); painter->setPen(p); //painter->setBrush(Qt::NoBrush); painter->drawLine(RS_Vector(toGuiX(0.0)-zr, toGuiY(0.0)), RS_Vector(toGuiX(0.0)+zr, toGuiY(0.0))); painter->drawLine(RS_Vector(toGuiX(0.0), toGuiY(0.0)-zr), RS_Vector(toGuiX(0.0), toGuiY(0.0)+zr)); //painter->drawCircle(toGui(RS_Vector(0.0, 0.0)), 8); /* painter->drawEllipse(toGuiX(0.0)-toGuiDX(zr/2), toGuiY(0.0)-toGuiDY(zr/2), 2*toGuiDX(zr/2), 2*toGuiDY(zr/2)); */ //painter->setBrush(Qt::red); //painter->setPen(Qt::NoPen); /* painter->drawPie(toGuiX(0.0)-toGuiDX(zr/2), toGuiY(0.0)-toGuiDY(zr/2), 2*toGuiDX(zr/2), 2*toGuiDY(zr/2), 2880, 1440); */ //painter->setBrush(NoBrush); //painter->setPen(Qt::black); if (painterCreated) { destroyPainter(); }}/** * This virtual method can be overwritten to draw the relative * zero point. It's called from within drawIt(). The default implemetation * draws a simple red round zero point. * * @see drawIt() */void RS_GraphicView::drawRelativeZero() { bool painterCreated = false; if (relativeZero.valid==false) { return; } // create a temporary painter device if (painter==NULL) { createDirectPainter(); painterCreated = true; } RS_Pen p(Qt::red, RS2::Width00, RS2::SolidLine); p.setScreenWidth(0); painter->setPen(p); painter->setXORMode(); int zr=5; painter->drawLine(RS_Vector(toGuiX(relativeZero.x)-zr, toGuiY(relativeZero.y)), RS_Vector(toGuiX(relativeZero.x)+zr, toGuiY(relativeZero.y))); painter->drawLine(RS_Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y)-zr), RS_Vector(toGuiX(relativeZero.x), toGuiY(relativeZero.y)+zr)); painter->drawCircle(toGui(relativeZero), 5); painter->setNormalMode(); if (painterCreated) { destroyPainter(); }}/** * Draws the paper border (for print previews). * * @see drawIt() */void RS_GraphicView::drawPaper() { bool painterCreated = false; if (container==NULL) { return; } RS_Graphic* graphic = container->getGraphic(); if (graphic==NULL) { return; } if (graphic->getPaperScale()<1.0e-6) { return; } // create a temporary painter device if (painter==NULL) { createDirectPainter(); painterCreated = true; } // draw paper: painter->setPen(Qt::gray); RS_Vector pinsbase = graphic->getPaperInsertionBase(); RS_Vector size = graphic->getPaperSize(); double scale = graphic->getPaperScale(); RS_Vector v1 = toGui((RS_Vector(0,0)-pinsbase)/scale); RS_Vector v2 = toGui((size-pinsbase)/scale); // gray background: painter->fillRect(0,0, getWidth(), getHeight(), RS_Color(200,200,200)); // shadow painter->fillRect( (int)(v1.x)+6, (int)(v1.y)+6, (int)((v2.x-v1.x)), (int)((v2.y-v1.y)), RS_Color(64,64,64)); // border: painter->fillRect( (int)(v1.x), (int)(v1.y), (int)((v2.x-v1.x)), (int)((v2.y-v1.y)), RS_Color(64,64,64)); // paper painter->fillRect( (int)(v1.x)+1, (int)(v1.y)-1, (int)((v2.x-v1.x))-2, (int)((v2.y-v1.y))+2, RS_Color(255,255,255)); if (painterCreated) { destroyPainter(); }}/** * Draws the grid. * * @see drawIt() */void RS_GraphicView::drawGrid() { if (grid==NULL || isGridOn()==false) { return; } bool painterCreated = false; // create a temporary painter device if (painter==NULL) { createDirectPainter(); painterCreated = true; } // draw grid: //painter->setPen(Qt::gray); painter->setPen(gridColor); RS_Vector* pts = grid->getPoints(); if (pts!=NULL) { for (int i=0; i<grid->count(); ++i) { painter->drawGridPoint(toGui(pts[i])); } } // draw grid info: //painter->setPen(Qt::white); RS_String info = grid->getInfo(); //info = RS_String("%1 / %2") // .arg(grid->getSpacing()) // .arg(grid->getMetaSpacing()); updateGridStatusWidget(info); if (painterCreated) { destroyPainter(); }}/** * Draws the meta grid. * * @see drawIt() */void RS_GraphicView::drawMetaGrid() { if (grid==NULL || isGridOn()==false /*|| grid->getMetaSpacing()<0.0*/) { return; } bool painterCreated = false; // create a temporary painter device if (painter==NULL) { createDirectPainter(); painterCreated = true; } RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine); painter->setPen(pen); // draw meta grid: double* mx = grid->getMetaX(); if (mx!=NULL) { for (int i=0; i<grid->countMetaX(); ++i) { painter->drawLine(RS_Vector(toGuiX(mx[i]), 0), RS_Vector(toGuiX(mx[i]), getHeight())); } } double* my = grid->getMetaY(); if (my!=NULL) { for (int i=0; i<grid->countMetaY(); ++i) { painter->drawLine(RS_Vector(0, toGuiY(my[i])), RS_Vector(getWidth(), toGuiY(my[i]))); } } if (painterCreated) { destroyPainter(); }}/** * Updates the grid if there is one. */void RS_GraphicView::updateGrid() { if (grid!=NULL) { grid->update(); }}/** * Sets the default snap mode used by newly created actions. */void RS_GraphicView::setDefaultSnapMode(RS2::SnapMode sm) { defaultSnapMode = sm; if (eventHandler!=NULL) { eventHandler->setSnapMode(sm); }}/** * Sets a snap restriction (e.g. orthogonal). */void RS_GraphicView::setSnapRestriction(RS2::SnapRestriction sr) { defaultSnapRes = sr; if (eventHandler!=NULL) { eventHandler->setSnapRestriction(sr); }}/** * Translates a vector in real coordinates to a vector in screen coordinates. */RS_Vector RS_GraphicView::toGui(RS_Vector v) { return RS_Vector(toGuiX(v.x), toGuiY(v.y), 0.0);}/** * Translates a real coordinate in X to a screen coordinate X. * @param visible Pointer to a boolean which will contain true * after the call if the coordinate is within the visible range. */double RS_GraphicView::toGuiX(double x, bool* visible) { if (visible!=NULL) { double res = x*factor.x+offsetX; if (res>0.0 && res<getWidth()) { *visible = true; } else { *visible = false; } } return x*factor.x + offsetX;}/** * Translates a real coordinate in Y to a screen coordinate Y. */double RS_GraphicView::toGuiY(double y) { return -y*factor.y + getHeight() - offsetY;}/** * Translates a real coordinate distance to a screen coordinate distance. */double RS_GraphicView::toGuiDX(double d) { return d*factor.x;}/** * Translates a real coordinate distance to a screen coordinate distance. */double RS_GraphicView::toGuiDY(double d) { return d*factor.y;}/** * Translates a vector in screen coordinates to a vector in real coordinates. */RS_Vector RS_GraphicView::toGraph(RS_Vector v) { return RS_Vector(toGraphX(RS_Math::round(v.x)), toGraphY(RS_Math::round(v.y)), 0.0);}/** * Translates two screen coordinates to a vector in real coordinates. */RS_Vector RS_GraphicView::toGraph(int x, int y) { return RS_Vector(toGraphX(x), toGraphY(y), 0.0);}/** * Translates a screen coordinate in X to a real coordinate X. */double RS_GraphicView::toGraphX(int x) { return (x - offsetX)/factor.x;}/** * Translates a screen coordinate in Y to a real coordinate Y. */double RS_GraphicView::toGraphY(int y) { return -(y - getHeight() + offsetY)/factor.y;}/** * Translates a screen coordinate distance to a real coordinate distance. */double RS_GraphicView::toGraphDX(int d) { return d/factor.x;}/** * Translates a screen coordinate distance to a real coordinate distance. */double RS_GraphicView::toGraphDY(int d) { return d/factor.y;}/** * Sets the relative zero coordinate (if not locked) * without deleting / drawing the point. */void RS_GraphicView::setRelativeZero(const RS_Vector& pos) { if (relativeZeroLocked==false) { relativeZero = pos; }}/** * Sets the relative zero coordinate, deletes the old position * on the screen and draws the new one. */void RS_GraphicView::moveRelativeZero(const RS_Vector& pos) { bool painterCreated = false; if (painter==NULL) { painter = createDirectPainter(); painterCreated=true; } //painter->setXORMode(); drawRelativeZero(); setRelativeZero(pos); drawRelativeZero(); if (painterCreated) { destroyPainter(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -