QGraphicsItem *GridLineFactory::lineItem (const QPointF &posStartScreen,
                                          const QPointF &posEndScreen) const
{
  LOG4CPP_DEBUG_S ((*mainCat)) << "GridLineFactory::lineItem"
                               << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                               << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data();

  return new QGraphicsLineItem (QLineF (posStartScreen,
                                        posEndScreen));
}
示例#2
0
QGraphicsItem *Checker::lineItem (const QPointF &posStartScreen,
                                  const QPointF &posEndScreen) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "Checker::lineItem"
                              << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                              << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data();

  return new QGraphicsLineItem (QLineF (posStartScreen,
                                        posEndScreen));
}
void GridLineFactory::createTransformAlign (const Transformation &transformation,
                                            double radiusLinearCartesian,
                                            const QPointF &posOriginScreen,
                                            QTransform &transformAlign,
                                            double &ellipseXAxis,
                                            double &ellipseYAxis) const
{
  // LOG4CPP_INFO_S is below

  // Compute a minimal transformation that aligns the graph x and y axes with the screen x and y axes. Specifically, shear,
  // translation and rotation are allowed but not scaling. Scaling is bad since it messes up the line thickness of the drawn arc.
  //
  // Assumptions:
  // 1) Keep the graph origin at the same screen coordinates
  // 2) Keep the (+radius,0) the same pixel distance from the origin but moved to the same pixel row as the origin
  // 3) Keep the (0,+radius) the same pixel distance from the origin but moved to the same pixel column as the origin

  // Get (+radius,0) and (0,+radius) points
  QPointF posXRadiusY0Graph (radiusLinearCartesian, 0), posX0YRadiusGraph (0, radiusLinearCartesian);
  QPointF posXRadiusY0Screen, posX0YRadiusScreen;
  transformation.transformLinearCartesianGraphToScreen (posXRadiusY0Graph,
                                                        posXRadiusY0Screen);
  transformation.transformLinearCartesianGraphToScreen (posX0YRadiusGraph,
                                                        posX0YRadiusScreen);

  // Compute arc/ellipse parameters
  QPointF deltaXRadiusY0 = posXRadiusY0Screen - posOriginScreen;
  QPointF deltaX0YRadius = posX0YRadiusScreen - posOriginScreen;
  ellipseXAxis = qSqrt (deltaXRadiusY0.x () * deltaXRadiusY0.x () +
                        deltaXRadiusY0.y () * deltaXRadiusY0.y ());
  ellipseYAxis = qSqrt (deltaX0YRadius.x () * deltaX0YRadius.x () +
                        deltaX0YRadius.y () * deltaX0YRadius.y ());

  // Compute the aligned coordinates, constrained by the rules listed above
  QPointF posXRadiusY0AlignedScreen (posOriginScreen.x() + ellipseXAxis, posOriginScreen.y());
  QPointF posX0YRadiusAlignedScreen (posOriginScreen.x(), posOriginScreen.y() - ellipseYAxis);

  transformAlign = Transformation::calculateTransformFromLinearCartesianPoints (posOriginScreen,
                                                                                posXRadiusY0Screen,
                                                                                posX0YRadiusScreen,
                                                                                posOriginScreen,
                                                                                posXRadiusY0AlignedScreen,
                                                                                posX0YRadiusAlignedScreen);

  LOG4CPP_INFO_S ((*mainCat)) << "GridLineFactory::createTransformAlign"
                              << " transformation=" << QTransformToString (transformation.transformMatrix()).toLatin1().data() << endl
                              << " radiusLinearCartesian=" << radiusLinearCartesian
                              << " posXRadiusY0Screen=" << QPointFToString (posXRadiusY0Screen).toLatin1().data()
                              << " posX0YRadiusScreen=" << QPointFToString (posX0YRadiusScreen).toLatin1().data()
                              << " ellipseXAxis=" << ellipseXAxis
                              << " ellipseYAxis=" << ellipseYAxis
                              << " posXRadiusY0AlignedScreen=" << QPointFToString (posXRadiusY0AlignedScreen).toLatin1().data()
                              << " posX0YRadiusAlignedScreen=" << QPointFToString (posX0YRadiusAlignedScreen).toLatin1().data()
                              << " transformAlign=" << QTransformToString (transformAlign).toLatin1().data();
}
CallbackSearchReturn CallbackDocumentHash::callback (const QString &curveName,
                                                     const Point &point)
{
  // LOG4CPP_DEBUG_S is below

  // Capture all important information about the point into the hash. A single string representing all of the point's details is
  // created, which can be logged, and then that string is added to the hash

  QString details;

  details += curveName.toLatin1();
  details += " " + point.identifier ();
  details += " " + QPointFToString (point.posScreen());

  if (point.hasOrdinal ()) {
    details += " " + QString::number (point.ordinal ());
  }

  if (point.isAxisPoint()) {

    if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) {

      // Axis point has one or coordinate
      if (point.isXOnly()) {

        details += " " + QString::number (point.posGraph().x());

      } else {

        details += " " + QString::number (point.posGraph().y());

      }

    } else {

      // Axis point has two coordinates
      details += " " + QPointFToString (point.posGraph());

    }
  }

  LOG4CPP_DEBUG_S ((*mainCat)) << "CallbackDocumentHash::callback details=" << details.toLatin1().data();

  // Add details to hash
  m_documentHash.addData (details.toLatin1());

  return CALLBACK_SEARCH_RETURN_CONTINUE;
}
void DigitizeStateSelect::handleMouseRelease (CmdMediator *cmdMediator,
                                              QPointF posScreen)
{
  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSelect::handleMouseRelease"
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();

  QPointF deltaScreen = posScreen - m_movingStart;
  QStringList positionHasChangedIdentifers = context().mainWindow().scene().positionHasChangedPointIdentifiers();

  bool positionHasChanged = (positionHasChangedIdentifers.count () > 0);

  if (positionHasChanged && (
        deltaScreen.x () != 0 ||
        deltaScreen.y () != 0)) {

    QString moveText = moveTextFromDeltaScreen (deltaScreen);

    // Create command to move points
    CmdMoveBy *cmd = new CmdMoveBy (context().mainWindow(),
                                    cmdMediator->document(),
                                    deltaScreen,
                                    moveText,
                                    positionHasChangedIdentifers);
    context().appendNewCmd (cmdMediator,
                            cmd);

   } else {

    // Selection probably changed so update the MainWindow controls (especially Cut)
    context().mainWindow().updateAfterMouseRelease();

    showCoordinatesIfSinglePointIsSelected ();
  }
}
示例#6
0
void DigitizeStateSelect::handleMousePress (QPointF posScreen)
{
  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateSelect::handleMousePress"
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ();

  // Note that GraphicsView has already called GraphicsPointAbstract::resetPositionHasChanged on all items

  m_movingStart = posScreen;
}
示例#7
0
void Checker::finishActiveSegment (const DocumentModelCoords &modelCoords,
                                   const QPointF &posStartScreen,
                                   const QPointF &posEndScreen,
                                   double yFrom,
                                   double yTo,
                                   const Transformation &transformation,
                                   SideSegments &sideSegments) const
{
  LOG4CPP_INFO_S ((*mainCat)) << "Checker::finishActiveSegment"
                              << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                              << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
                              << " yFrom=" << yFrom
                              << " yTo=" << yTo;

  QGraphicsItem *item;
  if ((modelCoords.coordsType() == COORDS_TYPE_POLAR) &&
      (yFrom == yTo)) {

    // Linear cartesian radius
    double radiusLinearCartesian = yFrom;
    if (modelCoords.coordScaleYRadius() == COORD_SCALE_LOG) {
      radiusLinearCartesian = transformation.logToLinearRadius(yFrom,
                                                               modelCoords.originRadius());
    } else {
      radiusLinearCartesian -= modelCoords.originRadius();
    }

    // Draw along an arc since this is a side of constant radius, and we have polar coordinates
    item = ellipseItem (transformation,
                        radiusLinearCartesian,
                        posStartScreen,
                        posEndScreen);

  } else {

    // Draw straight line
    item = lineItem (posStartScreen,
                     posEndScreen);
  }

  sideSegments.push_back (item);
  bindItemToScene (item);
}
void GridLineFactory::finishActiveGridLine (const QPointF &posStartScreen,
                                            const QPointF &posEndScreen,
                                            double yFrom,
                                            double yTo,
                                            const Transformation &transformation,
                                            GridLine &gridLine) const
{
  LOG4CPP_DEBUG_S ((*mainCat)) << "GridLineFactory::finishActiveGridLine"
                               << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                               << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
                               << " yFrom=" << yFrom
                               << " yTo=" << yTo;

  QGraphicsItem *item;
  if ((m_modelCoords.coordsType() == COORDS_TYPE_POLAR) &&
      (yFrom == yTo)) {

    // Linear cartesian radius
    double radiusLinearCartesian = yFrom;
    if (m_modelCoords.coordScaleYRadius() == COORD_SCALE_LOG) {
      radiusLinearCartesian = transformation.logToLinearRadius(yFrom,
                                                               m_modelCoords.originRadius());
    } else {
      radiusLinearCartesian -= m_modelCoords.originRadius();
    }

    // Draw along an arc since this is a side of constant radius, and we have polar coordinates
    item = ellipseItem (transformation,
                        radiusLinearCartesian,
                        posStartScreen,
                        posEndScreen);

  } else {

    // Draw straight line
    item = lineItem (posStartScreen,
                     posEndScreen);
  }

  gridLine.add (item);
  bindItemToScene (item);
}
示例#9
0
void CoordSystem::addPointAxisWithSpecifiedIdentifier (const QPointF &posScreen,
                                                       const QPointF &posGraph,
                                                       const QString &identifier,
                                                       double ordinal,
                                                       bool isXOnly)
{
  Point point (AXIS_CURVE_NAME,
               identifier,
               posScreen,
               posGraph,
               ordinal,
               isXOnly);
  m_curveAxes->addPoint (point);

  LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointAxisWithSpecifiedIdentifier"
                              << " ordinal=" << ordinal
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
                              << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
                              << " identifier=" << identifier.toLatin1 ().data ();
}
示例#10
0
void CoordSystem::checkAddPointAxis (const QPointF &posScreen,
                                     const QPointF &posGraph,
                                     bool &isError,
                                     QString &errorMessage,
                                     bool isXOnly)
{
  LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::checkAddPointAxis"
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
                              << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ();

  CallbackCheckAddPointAxis ftor (m_modelCoords,
                                  posScreen,
                                  posGraph,
                                  m_documentAxesPointsRequired,
                                  isXOnly);

  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
                                                                                                     &CallbackCheckAddPointAxis::callback);
  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);

  isError = ftor.isError ();
  errorMessage = ftor.errorMessage ();
}
void GraphicsLinesForCurves::addPoint (const QString &curveName,
                                       const QString &pointIdentifier,
                                       double ordinal,
                                       GraphicsPoint &point)
{
  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::addPoint"
                              << " curve=" << curveName.toLatin1().data()
                              << " identifier=" << pointIdentifier.toLatin1().data()
                              << " ordinal=" << ordinal
                              << " pos=" << QPointFToString (point.pos()).toLatin1().data();

  m_graphicsLinesForCurve [curveName]->addPoint (pointIdentifier,
                                                 ordinal,
                                                 point);
}
CmdAddPointGraph::CmdAddPointGraph (MainWindow &mainWindow,
                                    Document &document,
                                    const QString &curveName,
                                    const QPointF &posScreen,
                                    double ordinal) :
  CmdPointChangeBase (mainWindow,
                      document,
                      CMD_DESCRIPTION),
  m_curveName (curveName),
  m_posScreen (posScreen),
  m_ordinal (ordinal)
{
  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph"
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
                              << " ordinal=" << m_ordinal;
}
示例#13
0
void CoordSystem::addPointGraphWithSpecifiedIdentifier (const QString &curveName,
                                                        const QPointF &posScreen,
                                                        const QString &identifier,
                                                        double ordinal)
{
  Point point (curveName,
               identifier,
               posScreen,
               ordinal);
  m_curvesGraphs.addPoint (point);

  LOG4CPP_INFO_S ((*mainCat)) << "CoordSystem::addPointGraphWithSpecifiedIdentifier"
                              << " ordinal=" << ordinal
                              << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
                              << " identifier=" << identifier.toLatin1 ().data ();
}
QGraphicsItem *GridLineFactory::ellipseItem (const Transformation &transformation,
                                             double radiusLinearCartesian,
                                             const QPointF &posStartScreen,
                                             const QPointF &posEndScreen) const
{
  // LOG4CPP_INFO_S is below

  QPointF posStartGraph, posEndGraph;

  transformation.transformScreenToRawGraph (posStartScreen,
                                            posStartGraph);
  transformation.transformScreenToRawGraph (posEndScreen,
                                            posEndGraph);

  // Get the angles about the origin of the start and end points
  double angleStart = posStartGraph.x() * DEGREES_TO_RADIANS;
  double angleEnd = posEndGraph.x() * DEGREES_TO_RADIANS;
  if (angleEnd < angleStart) {
    angleEnd += TWO_PI;
  }
  double angleSpan = angleEnd - angleStart;

  // Get origin
  QPointF posOriginGraph (0, 0), posOriginScreen;
  transformation.transformLinearCartesianGraphToScreen (posOriginGraph,
                                                        posOriginScreen);

  LOG4CPP_INFO_S ((*mainCat)) << "GridLineFactory::ellipseItem"
                              << " radiusLinearCartesian=" << radiusLinearCartesian
                              << " posStartScreen=" << QPointFToString (posStartScreen).toLatin1().data()
                              << " posEndScreen=" << QPointFToString (posEndScreen).toLatin1().data()
                              << " posOriginScreen=" << QPointFToString (posOriginScreen).toLatin1().data()
                              << " angleStart=" << angleStart / DEGREES_TO_RADIANS
                              << " angleEnd=" << angleEnd / DEGREES_TO_RADIANS
                              << " transformation=" << transformation;

  // Compute rotate/shear transform that aligns linear cartesian graph coordinates with screen coordinates, and ellipse parameters.
  // Transform does not include scaling since that messes up the thickness of the drawn line, and does not include
  // translation since that is not important
  double ellipseXAxis, ellipseYAxis;
  QTransform transformAlign;
  createTransformAlign (transformation,
                        radiusLinearCartesian,
                        posOriginScreen,
                        transformAlign,
                        ellipseXAxis,
                        ellipseYAxis);

  // Create a circle in graph space with the specified radius
  QRectF boundingRect (-1.0 * ellipseXAxis + posOriginScreen.x(),
                       -1.0 * ellipseYAxis + posOriginScreen.y(),
                       2 * ellipseXAxis,
                       2 * ellipseYAxis);
  GraphicsArcItem *item = new GraphicsArcItem (boundingRect);
  item->setStartAngle (angleStart * RADIANS_TO_TICS);
  item->setSpanAngle (angleSpan * RADIANS_TO_TICS);

  item->setTransform (transformAlign.transposed ().inverted ());

  return item;
}