/** * Zooms the area given by v1 and v2. * * @param keepAspectRatio true: keeps the aspect ratio 1:1 * false: zooms exactly the selected range to the * current graphic view */ void RS_GraphicView::zoomWindow(RS_Vector v1, RS_Vector v2, bool keepAspectRatio) { double zoomX=480.0; // Zoom for X-Axis double zoomY=640.0; // Zoom for Y-Axis (Set smaller one) int zoomBorder = 0; // Switch left/right and top/bottom is necessary: if(v1.x>v2.x) { std::swap(v1.x,v2.x); } if(v1.y>v2.y) { std::swap(v1.y,v2.y); } // Get zoom in X and zoom in Y: if(v2.x-v1.x>1.0e-6) { zoomX = getWidth() / (v2.x-v1.x); } if(v2.y-v1.y>1.0e-6) { zoomY = getHeight() / (v2.y-v1.y); } // Take smaller zoom: if (keepAspectRatio) { if(zoomX<zoomY) { if(getWidth()!=0) { zoomX = zoomY = ((double)(getWidth()-2*zoomBorder)) / (double)getWidth()*zoomX; } } else { if(getHeight()!=0) { zoomX = zoomY = ((double)(getHeight()-2*zoomBorder)) / (double)getHeight()*zoomY; } } } zoomX=fabs(zoomX); zoomY=fabs(zoomY); // Borders in pixel after zoom int pixLeft =(int)(v1.x*zoomX); int pixTop =(int)(v2.y*zoomY); int pixRight =(int)(v2.x*zoomX); int pixBottom=(int)(v1.y*zoomY); if( pixLeft == INT_MIN || pixLeft== INT_MAX || pixRight == INT_MIN || pixRight== INT_MAX || pixTop == INT_MIN || pixTop== INT_MAX || pixBottom == INT_MIN || pixBottom== INT_MAX ) { RS_DIALOGFACTORY->commandMessage("Requested zooming factor out of range. Zooming not changed"); return; } saveView(); // Set new offset for zero point: offsetX = - pixLeft + (getWidth() -pixRight +pixLeft)/2; offsetY = - pixTop + (getHeight() -pixBottom +pixTop)/2; factor.x = zoomX; factor.y = zoomY; adjustOffsetControls(); adjustZoomControls(); // updateGrid(); redraw(); }
/** * performs autozoom * * @param axis include axis in zoom * @param keepAspectRatio true: keep aspect ratio 1:1 * false: factors in x and y are stretched to the max */ void RS_GraphicView::zoomAuto(bool axis, bool keepAspectRatio) { RS_DEBUG->print("RS_GraphicView::zoomAuto"); if (container!=NULL) { container->calculateBorders(); double sx, sy; if (axis) { sx = std::max(container->getMax().x, 0.0) - std::min(container->getMin().x, 0.0); sy = std::max(container->getMax().y, 0.0) - std::min(container->getMin().y, 0.0); } else { sx = container->getSize().x; sy = container->getSize().y; } // std::cout<<" RS_GraphicView::zoomAuto("<<axis<<","<<keepAspectRatio<<")"<<std::endl; double fx=1., fy=1.; unsigned short fFlags=0; if (sx>RS_TOLERANCE) { fx = (getWidth()-borderLeft-borderRight) / sx; } else { fFlags += 1; //invalid x factor } if (sy>RS_TOLERANCE) { fy = (getHeight()-borderTop-borderBottom) / sy; } else { fFlags += 2; //invalid y factor } // std::cout<<"0: fx= "<<fx<<"\tfy="<<fy<<std::endl; RS_DEBUG->print("f: %f/%f", fx, fy); switch(fFlags){ case 1: fx=fy; break; case 2: fy=fx; break; case 3: return; //do not do anything, invalid factors default: if (keepAspectRatio) { fx = fy = std::min(fx, fy); } // break; } // std::cout<<"1: fx= "<<fx<<"\tfy="<<fy<<std::endl; RS_DEBUG->print("f: %f/%f", fx, fy); //exclude invalid factors fFlags=0; if (fx<RS_TOLERANCE||fx>RS_MAXDOUBLE) { fx=1.0; fFlags += 1; } if (fy<RS_TOLERANCE||fy>RS_MAXDOUBLE) { fy=1.0; fFlags += 2; } if(fFlags == 3 ) return; saveView(); // std::cout<<"2: fx= "<<fx<<"\tfy="<<fy<<std::endl; setFactorX(fx); setFactorY(fy); RS_DEBUG->print("f: %f/%f", fx, fy); // RS_DEBUG->print("adjustOffsetControls"); adjustOffsetControls(); // RS_DEBUG->print("adjustZoomControls"); adjustZoomControls(); // RS_DEBUG->print("centerOffsetX"); centerOffsetX(); // RS_DEBUG->print("centerOffsetY"); centerOffsetY(); // RS_DEBUG->print("updateGrid"); // updateGrid(); redraw(); } RS_DEBUG->print("RS_GraphicView::zoomAuto OK"); }
void Viewer::on_actionSave_4_triggered() { saveView(3); }
void Viewer::on_actionSave_3_triggered() { saveView(2); }
void Viewer::on_actionSave_2_triggered() { saveView(1); }
void Viewer::on_actionSave_1_triggered() { saveView(0); }