/**
 * @brief setOffset
 * @param ox, offset X
 * @param oy, offset Y
 */
void QG_GraphicView::setOffset(int ox, int oy) {
//    DEBUG_HEADER
//    qDebug()<<"adjusting offset from ("<<getOffsetX()<<","<<getOffsetY()<<") to ("<<ox<<" , "<<oy<<")";
    RS_GraphicView::setOffset(ox, oy);
    // need to adjust offset control for scrollbars when setting graphicview offset
    adjustOffsetControls();
}
Exemple #2
0
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");
	}
}
Exemple #3
0
/**
 * zooms in by factor f in y
 */
void RS_GraphicView::zoomInY(double f) {
	factor.y*=f;
	offsetY=(int)((offsetY-getHeight()/2)*f)+getHeight()/2;
	adjustOffsetControls();
	adjustZoomControls();
	//    updateGrid();
	redraw();
}
Exemple #4
0
/**
 * zooms in by factor f in x
 */
void RS_GraphicView::zoomInX(double f) {
	factor.x*=f;
	offsetX=(int)((offsetX-getWidth()/2)*f)+getWidth()/2;
	adjustOffsetControls();
	adjustZoomControls();
	// updateGrid();
	redraw();
}
void QG_GraphicView::resizeEvent(QResizeEvent* /*e*/) {
    RS_DEBUG->print("QG_GraphicView::resizeEvent begin");
    adjustOffsetControls();
    adjustZoomControls();
//     updateGrid();
        // Small hack, delete teh snapper during resizes
        getOverlayContainer(RS2::Snapper)->clear();
        redraw();
    RS_DEBUG->print("QG_GraphicView::resizeEvent end");
}
Exemple #6
0
/**
 * Centers the point v1.
 */
void RS_GraphicView::zoomPan(int dx, int dy) {
	//offsetX+=(int)toGuiDX(v1.x);
	//offsetY+=(int)toGuiDY(v1.y);

	offsetX += dx;
	offsetY -= dy;

	adjustOffsetControls();
	//adjustZoomControls();
	//    updateGrid();

	redraw();
}
Exemple #7
0
/**
 * 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;
	}
	factor.y/=f;
	offsetY=(int)(offsetY/f);
	adjustOffsetControls();
	adjustZoomControls();
	//    updateGrid();
	redraw();
}
Exemple #8
0
/**
 * Zooms to page extends.
 */
void RS_GraphicView::zoomPage() {

	RS_DEBUG->print("RS_GraphicView::zoomPage");
	if (!container) {
		return;
	}

	RS_Graphic* graphic = container->getGraphic();
	if (!graphic) {
		return;
	}

	RS_Vector s = graphic->getPaperSize()/graphic->getPaperScale();

	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();
}
Exemple #9
0
/**
 * 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();
}
Exemple #10
0
/**
 * Restores the view previously saved with
 * @see saveView().
 */
void RS_GraphicView::restoreView() {
	if(savedViewCount == 0) return;
	savedViewCount --;
	if(savedViewCount==0){
		emit previous_zoom_state(false);
	}
	savedViewIndex = (savedViewIndex + savedViews.size() - 1)%savedViews.size();

	offsetX = std::get<0>(savedViews[savedViewIndex]);
	offsetY = std::get<1>(savedViews[savedViewIndex]);
	factor = std::get<2>(savedViews[savedViewIndex]);

	adjustOffsetControls();
	adjustZoomControls();
	//    updateGrid();

	redraw();
}
Exemple #11
0
/**
 * Restores the view previously saved with
 * @see saveView().
 */
void RS_GraphicView::restoreView() {
	if(savedViewCount == 0) return;
	savedViewCount --;
	if(savedViewCount==0){
		QC_ApplicationWindow::getAppWindow()->setPreviousZoomEnable(false);
	}
	savedViewIndex = (savedViewIndex + savedViews.size() - 1)%savedViews.size();

	offsetX = std::get<0>(savedViews[savedViewIndex]);
	offsetY = std::get<1>(savedViews[savedViewIndex]);
	factor = std::get<2>(savedViews[savedViewIndex]);

	adjustOffsetControls();
	adjustZoomControls();
	//    updateGrid();

	redraw();
}
Exemple #12
0
/**
 * Scrolls in the given direction.
 */
void RS_GraphicView::zoomScroll(RS2::Direction direction) {
	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();
}
Exemple #13
0
/**
 * 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();
}
Exemple #14
0
/**
 * 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) {
		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("adjustZoomControls");
		adjustZoomControls();
		//        RS_DEBUG->print("centerOffsetX");
		centerOffsetX();
		//        RS_DEBUG->print("centerOffsetY");
		centerOffsetY();
		//        RS_DEBUG->print("adjustOffsetControls");
		adjustOffsetControls();
		//        RS_DEBUG->print("updateGrid");
		//    updateGrid();

		redraw();
	}
	RS_DEBUG->print("RS_GraphicView::zoomAuto OK");
}