Пример #1
0
/**
 * When y-axis is clicked, the pixel coordinates are converted to graph coordinates, and displayed in a pop-up menu.
 * @param &y :: A reference to a click on the y-axis.
 */
void LabelTool::yAxisClicked(const QwtPolygon &y)
{
  populateMantidCurves();

  // Obtains the x value of the pixel coordinate.
  QPoint yy = y.point(0);
  int yPosition = yy.y();

  // Obtains the origins of the graph area and of the axis.
  QPoint canvasOrigin = d_graph->plotWidget()->canvas()->pos();
  int canvasOriginY = canvasOrigin.y();

  QPoint yOrigin = d_graph->plotWidget()->axisWidget(QwtPlot::yLeft)->pos();
  int yAxisOriginYValue = yOrigin.y();
  
/**
 * The difference in the origins is calculated then taken into account when converting the pixel coordinates of the
 * axis into graph coordinates.
 */

  int deltaOrigins = canvasOriginY - yAxisOriginYValue;
  int yPositionCorrected = yPosition - deltaOrigins;

  double yPos = d_graph->plotWidget()->invTransform(QwtPlot::yLeft, yPositionCorrected);
    
  if( yPos < 0)
  {
    return;
  }

  std::stringstream precisionValue;
  precisionValue.precision(6);
  precisionValue << yPos;
  m_yPosSigFigs = precisionValue.str();

  QMenu * clickMenu = new QMenu(d_graph);
  
  QAction * addYAxisLabel = new QAction(tr(QString::fromStdString(m_yPosSigFigs.c_str())), this);
  clickMenu->addAction(addYAxisLabel);
  connect(addYAxisLabel,SIGNAL(triggered()), this, SLOT(insertYCoord()));
  clickMenu->insertSeparator();

  clickMenu->exec(QCursor::pos());
}
Пример #2
0
/**
 * When x-axis is clicked, the pixel coordinates are converted to graph
 * coordinates, and displayed in a pop-up menu.
 * @param &x :: A reference to a click on the x-axis.
 */
void LabelTool::xAxisClicked(const QwtPolygon &x) {
  populateMantidCurves();

  // Obtains the x value of the pixel coordinate.
  QPoint xx = x.point(0);
  int xPosition = xx.x();

  // Obtains the origins of the graph area and of the axis.
  QPoint canvasOrigin = d_graph->plotWidget()->canvas()->pos();
  int canvasOriginX = canvasOrigin.x();

  QPoint xOrigin = d_graph->plotWidget()->axisWidget(QwtPlot::xBottom)->pos();
  int xAxisOriginXValue = xOrigin.x();

  /**
   * The difference in the origins is calculated then taken into account when
   * converting the pixel coordinates of the
   * axis into graph coordinates.
   */

  int deltaOrigins = canvasOriginX - xAxisOriginXValue;
  int xPositionCorrected = xPosition - deltaOrigins;

  double xPos =
      d_graph->plotWidget()->invTransform(QwtPlot::xBottom, xPositionCorrected);

  if (xPos < 0) {
    return;
  }
  m_xPosSigFigs.setNum(xPos, 'f', 6);

  QMenu *clickMenu = new QMenu(d_graph);

  QAction *addXAxisLabel = new QAction(m_xPosSigFigs, this);
  clickMenu->addAction(addXAxisLabel);
  connect(addXAxisLabel, SIGNAL(triggered()), this, SLOT(insertXCoord()));

  clickMenu->exec(QCursor::pos());
}
Пример #3
0
/**
 * When the graph area is clicked, pixel coordinates are found and used to
 * determine graph coordinates.
 * Determines the number of MMCs from the list in populateMantidCurves().
 * For each MMC, determines whether a click on the graph area is within close
 * proximity to a data point.
 * If it is, the coordinates of the data point are stored for display.
 * @param &c :: A reference to a click on the graph area; it is bound by the x
 * and y-axis.
 */
void LabelTool::graphAreaClicked(const QwtPolygon &c) {
  populateMantidCurves();
  m_dataCoords.clear();

  QPoint cc = c.point(0);
  int xPosition = cc.x();
  int yPosition = cc.y();

  // std::cout << "xPosition: " << xPosition << " " << "yPosition: " <<
  // yPosition << '\n';

  m_xPos = d_graph->plotWidget()->invTransform(QwtPlot::xBottom, xPosition);
  m_yPos = d_graph->plotWidget()->invTransform(QwtPlot::yLeft, yPosition);

  // Sets the tolerance value, in pixels, for the range in which to search for a
  // data point.
  int tolerance = 7;

  foreach (MantidMatrixCurve *mantidMatrixCurve, m_mantidMatrixCurves) {
    // Sets the upper and lower limits in pixel coordinates for the x and
    // y-axes.
    int upperLimitX = xPosition + tolerance;
    int lowerLimitX = xPosition - tolerance;
    int upperLimitY = yPosition + tolerance;
    int lowerLimitY = yPosition - tolerance;

    /*
    // Gets the workspace name for which the curve belongs to.
    QString workspaceNameOfCurve = mantidMatrixCurve->workspaceName();
    */

    // Gets the number of data points on the curve.
    auto *mwd = mantidMatrixCurve->mantidData();
    size_t numberOfDataPoints = mwd->size();

    /**
    * Gets the pixel value of the x-coordinate value of each data point within
    * range.
    * Of the data points within range along x-axis, finds out if the pixel
    * values of their y-coordinates are within range.
    * If they are, their position within the iteration - i - is stored in a set.
    */

    QSet<size_t> pointsWithinRange;

    for (size_t i = 0; i < numberOfDataPoints; ++i) {
      // The pixel values of the x and y coordinates of the data points.
      int iPixelValueX =
          d_graph->plotWidget()->transform(QwtPlot::xBottom, mwd->x(i));
      int iPixelvalueY =
          d_graph->plotWidget()->transform(QwtPlot::yLeft, mwd->y(i));

      // Comparing the point of clicking with the positioning of the data
      // points.
      if (((iPixelValueX <= upperLimitX) && (iPixelValueX >= lowerLimitX)) &&
          ((iPixelvalueY <= upperLimitY) && (iPixelvalueY >= lowerLimitY))) {
        pointsWithinRange.insert(i);
      }
    }

    // If there are points within the specified ranges.
    if (!pointsWithinRange.isEmpty()) {
      /**
      * Uses Pythagoras' theorem to calculate the distance between the position
      * of a click and
      * the surrounding data points that lie within both the x and y ranges.
      */

      QMap<double, size_t> map;

      foreach (size_t i, pointsWithinRange) {
        double deltaX = m_xPos - mwd->x(i);
        double deltaY = m_yPos - mwd->y(i);
        double deltaXSquared = deltaX * deltaX;
        double deltaYSquared = deltaY * deltaY;

        double distance = sqrt(deltaXSquared + deltaYSquared);

        map[distance] = i;
      }