void RS_GraphicView::zoomAutoY(bool axis) { if (container) { double visibleHeight = 0.0; double minY = RS_MAXDOUBLE; double maxY = RS_MINDOUBLE; bool noChange = false; for(auto e: *container){ if (e->rtti()==RS2::EntityLine) { RS_Line* l = (RS_Line*)e; double x1, x2; x1 = toGuiX(l->getStartpoint().x); x2 = toGuiX(l->getEndpoint().x); if ( ((x1 > 0.0) && (x1 < (double) getWidth())) || ((x2 > 0.0) && (x2 < (double) getWidth()))) { minY = std::min(minY, l->getStartpoint().y); minY = std::min(minY, l->getEndpoint().y); maxY = std::max(maxY, l->getStartpoint().y); maxY = std::max(maxY, l->getEndpoint().y); } } } if (axis) { visibleHeight = std::max(maxY, 0.0) - std::min(minY, 0.0); } else { visibleHeight = maxY-minY; } if (visibleHeight<1.0) { noChange = true; } double fy = 1.0; if (visibleHeight>1.0e-6) { fy = (getHeight()-borderTop-borderBottom) / visibleHeight; if (factor.y<0.000001) { noChange = true; } } if (noChange==false) { setFactorY(fy); //centerOffsetY(); offsetY = (int)((getHeight()-borderTop-borderBottom - (visibleHeight*factor.y))/2.0 - (minY*factor.y)) + borderBottom; adjustOffsetControls(); adjustZoomControls(); // updateGrid(); } RS_DEBUG->print("Auto zoom y ok"); } }
/** * This virtual method can be overwritten to draw the absolute * zero. It's called from within drawIt(). The default implemetation * draws a simple red cross on the zero of thge sheet * THis function can ONLY be called from within a paintEvent because it will * use the painter * * @see drawIt() */ void RS_GraphicView::drawAbsoluteZero(RS_Painter *painter) { int zr = 20; RS_Pen p(QColor(255,0,0), 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)); }
/** * 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. This is the point that was last created by the user, end of a line for example * THis function can ONLY be called from within a paintEvent because it will * use the painter * * @see drawIt() */ void RS_GraphicView::drawRelativeZero(RS_Painter *painter) { if (relativeZero.valid==false) { return; } RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine); p.setScreenWidth(0); painter->setPen(p); 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); }
/** * Translates a vector in real coordinates to a vector in screen coordinates. */ RS_Vector RS_GraphicView::toGui(RS_Vector v) const{ return RS_Vector(toGuiX(v.x), toGuiY(v.y)); }
/** * Draws the meta grid. * * @see drawIt() */ void RS_GraphicView::drawMetaGrid(RS_Painter *painter) { if (!(grid && isGridOn()) /*|| grid->getMetaSpacing()<0.0*/) { return; } //draw grid after metaGrid to avoid overwriting grid points by metaGrid lines //bug# 3430258 grid->updatePointArray(); RS_Pen pen(metaGridColor, RS2::Width00, RS2::DotLine); painter->setPen(pen); RS_Vector dv=grid->getMetaGridWidth().scale(factor); double dx=fabs(dv.x); double dy=fabs(dv.y); //potential bug, need to recover metaGrid.width // draw meta grid: auto mx = grid->getMetaX(); for(auto const& x: mx){ painter->drawLine(RS_Vector(toGuiX(x), 0), RS_Vector(toGuiX(x), getHeight())); if(grid->isIsometric()){ painter->drawLine(RS_Vector(toGuiX(x)+0.5*dx, 0), RS_Vector(toGuiX(x)+0.5*dx, getHeight())); } } auto my = grid->getMetaY(); if(grid->isIsometric()){//isometric metaGrid dx=fabs(dx); dy=fabs(dy); if(!my.size()|| dx<1||dy<1) return; RS_Vector baseMeta(toGui(RS_Vector(mx[0],my[0]))); // x-x0=k*dx, x-remainder(x-x0,dx) RS_Vector vp0(-remainder(-baseMeta.x,dx)-dx,getHeight()-remainder(getHeight()-baseMeta.y,dy)+dy); RS_Vector vp1(vp0); RS_Vector vp2(getWidth()-remainder(getWidth()-baseMeta.x,dx)+dx,vp0.y); RS_Vector vp3(vp2); int cmx = round((vp2.x - vp0.x)/dx); int cmy = round((vp0.y +remainder(-baseMeta.y,dy)+dy)/dy); for(int i=cmx+cmy+2;i>=0;i--){ if ( i <= cmx ) { vp0.x += dx; vp2.y -= dy; }else{ vp0.y -= dy; vp2.x -= dx; } if ( i <= cmy ) { vp1.y -= dy; vp3.x -= dx; }else{ vp1.x += dx; vp3.y -= dy; } painter->drawLine(vp0,vp1); painter->drawLine(vp2,vp3); } }else{//orthogonal for(auto const& y: my){ painter->drawLine(RS_Vector(0, toGuiY(y)), RS_Vector(getWidth(), toGuiY(y))); } } }
void RS_GraphicView::drawEntity(RS_Painter *painter, RS_Entity* e, double& patternOffset) { // update is diabled: // given entity is nullptr: if (!e) { return; } // entity is not visible: if (!e->isVisible()) { return; } if( isPrintPreview() || isPrinting() ) { // do not draw construction layer on print preview or print if( ! e->isPrint() || e->isConstruction()) return; } // test if the entity is in the viewport if (!isPrinting() && e->rtti() != RS2::EntityGraphic && e->rtti() != RS2::EntityLine && (toGuiX(e->getMax().x)<0 || toGuiX(e->getMin().x)>getWidth() || toGuiY(e->getMin().y)<0 || toGuiY(e->getMax().y)>getHeight())) { return; } // set pen (color): setPenForEntity(painter, e ); //RS_DEBUG->print("draw plain"); if (isDraftMode()) { switch(e->rtti()){ case RS2::EntityMText: case RS2::EntityText: painter->drawRect(toGui(e->getMin()), toGui(e->getMax())); break; case RS2::EntityImage: // all images as rectangles: painter->drawRect(toGui(e->getMin()), toGui(e->getMax())); break; case RS2::EntityHatch: //skip hatches break; default: drawEntityPlain(painter, e, patternOffset); } } else { drawEntityPlain(painter, e, patternOffset); } // draw reference points: if (e->isSelected()) { if (!e->isParentSelected()) { RS_VectorSolutions const& s = e->getRefPoints(); for (size_t i=0; i<s.getNumber(); ++i) { int sz = -1; RS_Color col = handleColor; if (i == 0) { col = startHandleColor; } else if (i == s.getNumber() - 1) { col = endHandleColor; } if (getDeleteMode()) { painter->drawHandle(toGui(s.get(i)), background, sz); } else { painter->drawHandle(toGui(s.get(i)), col, sz); } } } } //RS_DEBUG->print("draw plain OK"); //RS_DEBUG->print("RS_GraphicView::drawEntity() end"); }