📄 rs_graphicview.cpp
字号:
return; } factor.y*=f; offsetY=(int)((offsetY-getHeight()/2)*f)+getHeight()/2; adjustOffsetControls(); adjustZoomControls(); updateGrid(); redraw();}/** * zooms out by factor f */void RS_GraphicView::zoomOut(double f, const RS_Vector& center) { if (f<1.0e-6) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomOut: invalid factor"); return; } if (simulationRunning) { return; } zoomIn(1/f, center);}/** * zooms out by factor f in x */void RS_GraphicView::zoomOutX(double f) { if (f<1.0e-6) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomOutX: invalid factor"); return; } if (simulationRunning) { return; } factor.x/=f; offsetX=(int)(offsetX/f); adjustOffsetControls(); adjustZoomControls(); updateGrid(); redraw();}/** * zooms out by factor f y */void RS_GraphicView::zoomOutY(double f) { if (f<1.0e-6) { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_GraphicView::zoomOutY: invalid factor"); return; } if (simulationRunning) { return; } factor.y/=f; offsetY=(int)(offsetY/f); 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 (simulationRunning) { return; } saveView(); 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; } double fx, fy; if (sx>RS_TOLERANCE) { fx = (getWidth()-borderLeft-borderRight) / sx; } else { fx = 1.0; } if (sy>RS_TOLERANCE) { fy = (getHeight()-borderTop-borderBottom) / sy; } else { fy = 1.0; } RS_DEBUG->print("f: %f/%f", fx, fy); if (keepAspectRatio) { fx = fy = std::min(fx, fy); } RS_DEBUG->print("f: %f/%f", fx, fy); if (fx<RS_TOLERANCE) { fx=fy=1.0; } 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");}/** * Shows previous view. */void RS_GraphicView::zoomPrevious() { RS_DEBUG->print("RS_GraphicView::zoomPrevious"); if (simulationRunning) { return; } if (container!=NULL) { restoreView(); }}/** * Saves the current view as previous view to which we can * switch back later with @see restoreView(). */void RS_GraphicView::saveView() { previousOffsetX = offsetX; previousOffsetY = offsetY; previousFactor = factor;}/** * Restores the view previously saved with * @see saveView(). */void RS_GraphicView::restoreView() { int pox = previousOffsetX; int poy = previousOffsetY; RS_Vector pf = previousFactor; saveView(); offsetX = pox; offsetY = poy; factor = pf; adjustOffsetControls(); adjustZoomControls(); updateGrid(); redraw();}/** * performs autozoom in y only * * @param axis include axis in zoom */void RS_GraphicView::zoomAutoY(bool axis) { if (simulationRunning) { return; } if (container!=NULL) { double visibleHeight = 0.0; double minY = RS_MAXDOUBLE; double maxY = RS_MINDOUBLE; bool noChange = false; for (RS_Entity* e=container->firstEntity(RS2::ResolveNone); e!=NULL; e = container->nextEntity(RS2::ResolveNone)) { 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"); }}/** * 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) { if (simulationRunning) { return; } saveView(); double zoomX=480.0; // Zoom for X-Axis double zoomY=640.0; // Zoom for Y-Axis (Set smaller one) double dum; // Dummy for switching values int zoomBorder = 0; // Switch left/right and top/bottom is necessary: if(v1.x>v2.x) { dum=v1.x; v1.x=v2.x; v2.x=dum; } if(v1.y>v2.y) { dum=v1.y; v1.y=v2.y; v2.y=dum; } // 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; } } } if(zoomX<0.0) { zoomX*=-1; } if(zoomY<0.0) { zoomY*=-1; } // 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); // 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();}/** * Centers the point v1. */void RS_GraphicView::zoomPan(int dx, int dy) { //offsetX+=(int)toGuiDX(v1.x); //offsetY+=(int)toGuiDY(v1.y); if (simulationRunning) { return; } offsetX += dx; offsetY -= dy; disableUpdate(); adjustOffsetControls(); //adjustZoomControls(); updateGrid(); enableUpdate(); redraw();}/** * Scrolls in the given direction. */void RS_GraphicView::zoomScroll(RS2::Direction direction) { if (simulationRunning) { return; } switch (direction) { case RS2::Up: offsetY-=50; break; case RS2::Down: offsetY+=50; break; case RS2::Right: offsetX+=50; break; case RS2::Left: offsetX-=50; break; } adjustOffsetControls(); adjustZoomControls(); updateGrid(); redraw();}/** * Zooms to page extends. */void RS_GraphicView::zoomPage() { RS_DEBUG->print("RS_GraphicView::zoomPage"); if (container==NULL) { return; } if (simulationRunning) { return; } RS_Graphic* graphic = container->getGraphic(); if (graphic==NULL) { return; } RS_Vector s = graphic->getPaperSize(); RS_Vector pinsbase = graphic->getPaperInsertionBase(); double fx, fy; if (s.x>RS_TOLERANCE) { fx = (getWidth()-borderLeft-borderRight) / s.x; } else { fx = 1.0; } if (s.y>RS_TOLERANCE) { fy = (getHeight()-borderTop-borderBottom) / s.y; } else { fy = 1.0; } RS_DEBUG->print("f: %f/%f", fx, fy); fx = fy = std::min(fx, fy); RS_DEBUG->print("f: %f/%f", fx, fy); if (fx<RS_TOLERANCE) { fx=fy=1.0; } setFactorX(fx); setFactorY(fy); RS_DEBUG->print("f: %f/%f", fx, fy); centerOffsetX(); centerOffsetY(); adjustOffsetControls(); adjustZoomControls(); updateGrid(); redraw();}/** * Draws the entities within the given range. */void RS_GraphicView::drawWindow(RS_Vector v1, RS_Vector v2) { RS_DEBUG->print("RS_GraphicView::drawWindow() begin"); if (simulationRunning) { return; } if (container!=NULL) { for (RS_Entity* se=container->firstEntity(RS2::ResolveNone); se!=NULL; se = container->nextEntity(RS2::ResolveNone)) { if (se->isInWindow(v1, v2)) { drawEntity(se); } } } RS_DEBUG->print("RS_GraphicView::drawWindow() end");}/** * Draws the entities. If painter is NULL a new painter will * be created and destroyed. */void RS_GraphicView::drawIt() { if (!isUpdateEnabled()) { return; } if (simulationRunning) { return; } bool painterCreated = false; RS_SETTINGS->beginGroup("/Appearance"); draftMode = (bool)RS_SETTINGS->readNumEntry("/DraftMode", 0); RS_SETTINGS->endGroup(); //RS_DEBUG->print("RS_GraphicView::drawIt() begin"); //RS_DEBUG->print(" factors: %f/%f", factor.x, factor.y); //RS_DEBUG->timestamp(); if (painter==NULL) {#ifdef RS_DIRECTPAINTER createDirectPainter(); painter->erase();#else createPainter();#endif painterCreated = true; } else { painter->erase(); } // drawing paper border: if (isPrintPreview()) { drawPaper(); } // drawing meta grid: if (!isPrintPreview()) { drawMetaGrid(); } //if (draftMode) { // painter->setPen(RS_Pen(foreground, // RS2::Width00, RS2::SolidLine)); //} // drawing entities: drawEntity(container, true); //RS_DEBUG->timestamp(); //RS_DEBUG->print(" draw zero.."); // drawing zero points: if (!isPrintPreview()) { drawAbsoluteZero(); drawRelativeZero(); } //RS_DEBUG->timestamp(); //RS_DEBUG->print(" draw grid.."); // drawing grid: if (!isPrintPreview()) { drawGrid(); } //RS_DEBUG->timestamp(); //RS_DEBUG->print("RS_GraphicView::drawIt() end"); if (painterCreated==true) { destroyPainter(); }}/** * Sets the pen of the painter object to the suitable pen for the given * entity.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -