bool CurveImp::hit(LocationType point) const { PlotViewImp* pPlot = getPlot(); if (pPlot == NULL) { return false; } unsigned int numPoints = mPoints.size(); for (unsigned int i = 0; i < numPoints; i++) { double dScreenX = 0; double dScreenY = 0; pPlot->translateWorldToScreen(point.mX, point.mY, dScreenX, dScreenY); LocationType currentPoint = mPoints.at(i); double dCurrentScreenX = 0; double dCurrentScreenY = 0; pPlot->translateDataToScreen(currentPoint.mX, currentPoint.mY, dCurrentScreenX, dCurrentScreenY); double dXDist = fabs(dCurrentScreenX - dScreenX); double dYDist = fabs(dCurrentScreenY - dScreenY); if ((dXDist < 3.0) && (dYDist < 3.0)) { return true; } } return false; }
bool PointImp::hit(LocationType point) const { PlotViewImp* pPlot = getPlot(); if (pPlot == NULL) { return false; } double dScreenX = 0.0; double dScreenY = 0.0; pPlot->translateWorldToScreen(point.mX, point.mY, dScreenX, dScreenY); double dCurrentScreenX = 0.0; double dCurrentScreenY = 0.0; pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dCurrentScreenX, dCurrentScreenY); double dXDist = fabs(dCurrentScreenX - dScreenX); double dYDist = fabs(dCurrentScreenY - dScreenY); double dDist = mSymbolSize; if (isSelected() == true) { dDist *= 2.0; } if ((dXDist < dDist) && (dYDist < dDist)) { return true; } return false; }
void TextImp::draw() { if (isVisible() == false) { return; } PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot()); if (pPlot != NULL) { glColor3ub(mColor.red(), mColor.green(), mColor.blue()); double dScreenX = 0.0; double dScreenY = 0.0; pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dScreenX, dScreenY); int screenX = static_cast<int>(dScreenX); int screenY = pPlot->height() - static_cast<int>(dScreenY); pPlot->renderText(screenX, screenY, mText, mFont); } }
bool TextImp::getExtents(double& dMinX, double& dMinY, double& dMaxX, double& dMaxY) { PlotViewImp* pPlot = getPlot(); if (pPlot == NULL) { return false; } double dScreenX = 0; double dScreenY = 0; pPlot->translateDataToScreen(mLocation.mX, mLocation.mY, dScreenX, dScreenY); QFontMetrics ftMetrics(mFont); int iHeight = ftMetrics.height(); int iWidth = ftMetrics.width(mText); double dScreenExtentX = dScreenX + iWidth; double dScreenExtentY = dScreenY + iHeight; pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dMinX, dMinY); pPlot->translateScreenToWorld(dScreenExtentX, dScreenExtentY, dMaxX, dMaxY); return true; }
void CurveImp::draw() { if (isVisible() == false) { return; } unsigned int numPoints = mPoints.size(); if (numPoints == 0) { return; } glColor3ub(mColor.red(), mColor.green(), mColor.blue()); glLineWidth(mLineWidth); if (mLineStyle != SOLID_LINE) { glEnable(GL_LINE_STIPPLE); if (mLineStyle == DASHED) { glLineStipple(3, 0x3f3f); } else if (mLineStyle == DOT) { glLineStipple(2, 0x1111); } else if (mLineStyle == DASH_DOT) { glLineStipple(2, 0x11ff); } else if (mLineStyle == DASH_DOT_DOT) { glLineStipple(2, 0x24ff); } } glBegin(GL_LINE_STRIP); PlotViewImp* pPlot = getPlot(); VERIFYNRV(pPlot != NULL); double dWorldX = 0.0; double dWorldY = 0.0; unsigned int i = 0; for (i = 0; i < numPoints; i++) { LocationType point = mPoints.at(i); pPlot->translateDataToWorld(point.mX, point.mY, dWorldX, dWorldY); glVertex2d(dWorldX, dWorldY); } glEnd(); if (mLineStyle != SOLID_LINE) { glDisable(GL_LINE_STIPPLE); } glLineWidth(1); if (isSelected() == true) { for (i = 0; i < numPoints; i++) { LocationType point = mPoints.at(i); double dScreenX = 0; double dScreenY = 0; pPlot->translateDataToScreen(point.mX, point.mY, dScreenX, dScreenY); double dX1 = dScreenX - 4; double dY1 = dScreenY - 4; double dX2 = dScreenX + 4; double dY2 = dScreenY + 4; double dPixelX1 = 0.0; double dPixelY1 = 0.0; double dPixelX2 = 0.0; double dPixelY2 = 0.0; pPlot->translateScreenToWorld(dX1, dY1, dPixelX1, dPixelY1); pPlot->translateScreenToWorld(dX2, dY2, dPixelX2, dPixelY2); glBegin(GL_POLYGON); glVertex2d(dPixelX1, (dPixelY1 + dPixelY2) / 2); glVertex2d((dPixelX1 + dPixelX2) / 2, dPixelY1); glVertex2d(dPixelX2, (dPixelY1 + dPixelY2) / 2); glVertex2d((dPixelX1 + dPixelX2) / 2, dPixelY2); glEnd(); } } }
bool PointSetImp::hit(LocationType point) const { if (mLine == true) { if (mPoints.size() > 0) { PlotViewImp* pPlot = getPlot(); if (pPlot != NULL) { double dPointX = 0.0; double dPointY = 0.0; pPlot->translateWorldToScreen(point.mX, point.mY, dPointX, dPointY); point.mX = dPointX; point.mY = dPointY; LocationType oldLocation; LocationType currentLocation; Point* pPoint = NULL; pPoint = mPoints.front(); if (pPoint != NULL) { const LocationType& location = pPoint->getLocation(); double dLocationX = 0.0; double dLocationY = 0.0; pPlot->translateDataToScreen(location.mX, location.mY, dLocationX, dLocationY); oldLocation.mX = dLocationX; oldLocation.mY = dLocationY; } for (unsigned int i = 1; i < mPoints.size(); i++) { pPoint = mPoints.at(i); if (pPoint != NULL) { const LocationType& location = pPoint->getLocation(); double dLocationX = 0.0; double dLocationY = 0.0; pPlot->translateDataToScreen(location.mX, location.mY, dLocationX, dLocationY); currentLocation.mX = dLocationX; currentLocation.mY = dLocationY; bool bHit = false; bHit = DrawUtil::lineHit(oldLocation, currentLocation, point, 3.0); if (bHit == true) { return true; } oldLocation = currentLocation; } } } } } Point* pPoint = hitPoint(point); return (pPoint != NULL); }
void ArrowImp::updateArrowHead() { // Reset the arrow head mArrowHead.clear(true); mArrowHead.setFillStyle(EMPTY_FILL); // Convert the line points to screen coordinates PlotViewImp* pPlot = getPlot(); if (pPlot == NULL) { return; } LocationType baseLocation = getBaseLocation(); LocationType tipLocation = getTipLocation(); double dBaseX = 0; double dBaseY = 0; double dTipX = 0; double dTipY = 0; pPlot->translateDataToScreen(baseLocation.mX, baseLocation.mY, dBaseX, dBaseY); pPlot->translateDataToScreen(tipLocation.mX, tipLocation.mY, dTipX , dTipY); // Calculate the end points using screen pixels double arrowHeadSize = 10; if ((mStyle == ARROW_LARGE) || (mStyle == ARROW_TRIANGLE_LARGE) || (mStyle == ARROW_TRIANGLE_LARGE_FILL)) { arrowHeadSize *= 2; } double h = arrowHeadSize * sqrt(static_cast<double>(mArrowHead.getLineWidth())); double theta = atan2(dTipY - dBaseY, dTipX - dBaseX); double hcTheta = h * cos(theta); double hsTheta = h * sin(theta); double dScreenEnd1X = dTipX - hcTheta - hsTheta; double dScreenEnd1Y = dTipY + hcTheta - hsTheta; double dScreenEnd2X = dTipX - hcTheta + hsTheta; double dScreenEnd2Y = dTipY - hcTheta - hsTheta; double dScreenEnd3X = dTipX - (2 * hcTheta); double dScreenEnd3Y = dTipY - (2 * hsTheta); double dEnd1X = 0.0; double dEnd1Y = 0.0; double dEnd2X = 0.0; double dEnd2Y = 0.0; double dEnd3X = 0.0; double dEnd3Y = 0.0; pPlot->translateScreenToData(dScreenEnd1X, dScreenEnd1Y, dEnd1X, dEnd1Y); pPlot->translateScreenToData(dScreenEnd2X, dScreenEnd2Y, dEnd2X, dEnd2Y); pPlot->translateScreenToData(dScreenEnd3X, dScreenEnd3Y, dEnd3X, dEnd3Y); // Add the points to the arrow head object if (mStyle != ARROW_NONE) { mArrowHead.addPoint(dEnd1X, dEnd1Y); mArrowHead.addPoint(tipLocation.mX, tipLocation.mY); mArrowHead.addPoint(dEnd2X, dEnd2Y); } if ((mStyle == ARROW_DIAMOND) || (mStyle == ARROW_DIAMOND_FILL)) { mArrowHead.addPoint(dEnd3X, dEnd3Y); } if ((mStyle == ARROW_TRIANGLE_SMALL) || (mStyle == ARROW_TRIANGLE_LARGE) || (mStyle == ARROW_TRIANGLE_SMALL_FILL) || (mStyle == ARROW_TRIANGLE_LARGE_FILL) || (mStyle == ARROW_DIAMOND) || (mStyle == ARROW_DIAMOND_FILL)) { mArrowHead.addPoint(dEnd1X, dEnd1Y); } // Set the fill if ((mStyle == ARROW_TRIANGLE_SMALL_FILL) || (mStyle == ARROW_TRIANGLE_LARGE_FILL) || (mStyle == ARROW_DIAMOND_FILL)) { mArrowHead.setFillStyle(SOLID_FILL); } }