bool TiePointLayerImp::getExtents(double& x1, double& y1, double& x4, double& y4)
{
   TiePointList* pList = static_cast<TiePointList*>(getDataElement());
   VERIFY(pList != NULL);

   const vector<TiePoint>& points = pList->getTiePoints();
   if (!points.empty())
   {
      int xMinData = numeric_limits<int>::max();
      int yMinData = numeric_limits<int>::max();
      int xMaxData = numeric_limits<int>::min();
      int yMaxData = numeric_limits<int>::min();
      
      for (vector<TiePoint>::const_iterator pPoint = points.begin();
         pPoint != points.end(); ++pPoint)
      {
         xMinData = min(xMinData, pPoint->mReferencePoint.mX);
         yMinData = min(yMinData, pPoint->mReferencePoint.mY);
         xMaxData = max(xMaxData, pPoint->mReferencePoint.mX);
         yMaxData = max(yMaxData, pPoint->mReferencePoint.mY);
      }
      translateDataToWorld(xMinData, yMinData, x1, y1);
      translateDataToWorld(xMaxData, yMaxData, x4, y4);
   }

   return true;
}
bool TiePointLayerImp::fromXml(DOMNode* pDocument, unsigned int version)
{
   if (!LayerImp::fromXml(pDocument, version))
   {
      return false;
   }

   vector<TiePoint> oldPoints;

   TiePointList* pTiePointList = dynamic_cast<TiePointList*>(getDataElement());
   if (pTiePointList != NULL)
   {
      oldPoints = pTiePointList->getTiePoints();
   }

   DOMElement* pElmnt = static_cast<DOMElement*>(pDocument);

   setSymbolSize(StringUtilities::fromXmlString<int>(A(pElmnt->getAttribute(X("symbolSize")))));
   setColor(COLORTYPE_TO_QCOLOR(StringUtilities::fromXmlString<ColorType>(A(pElmnt->getAttribute(X("symbolColor"))))));
   enableLabels(StringUtilities::fromXmlString<bool>(A(pElmnt->getAttribute(X("labelIsEnabled")))));
   setIsMission(StringUtilities::fromXmlString<bool>(A(pElmnt->getAttribute(X("isMission")))));

   View* pView = getView();
   if ((pView != NULL) && (pTiePointList != NULL))
   {
      vector<TiePoint> newPoints = pTiePointList->getTiePoints();
      pView->addUndoAction(new SetTiePoints(pTiePointList, oldPoints, newPoints));
   }

   return true;
}
Exemple #3
0
void TiePointEditor::addPoint()
{
    if (mpLayer.get() == NULL)
    {
        return;
    }

    TiePointList* pTiePointList = dynamic_cast<TiePointList*>(mpLayer->getDataElement());
    if (pTiePointList == NULL)
    {
        return;
    }

    const vector<TiePoint>& oldPoints = pTiePointList->getTiePoints();
    vector<TiePoint> tiePoints = oldPoints;
    tiePoints.push_back(TiePoint());

    View* pView = mpLayer->getView();
    if (pView != NULL)
    {
        pView->addUndoAction(new SetTiePoints(pTiePointList, oldPoints, tiePoints));
    }

    int numTiePoints = static_cast<int>(tiePoints.size());
    pTiePointList->adoptTiePoints(tiePoints);
    goToRow(numTiePoints - 1);
}
void SetTiePoints::executeRedo()
{
   TiePointList* pList = static_cast<TiePointList*>(getSessionItem());
   if (pList != NULL)
   {
      vector<TiePoint> vertices = mNewVertices;
      pList->adoptTiePoints(vertices);
   }
}
Exemple #5
0
void TiePointEditor::deletePoint()
{
    if (mpLayer.get() == NULL)
    {
        return;
    }

    TiePointList* pTiePointList = dynamic_cast<TiePointList*>(mpLayer->getDataElement());
    if (pTiePointList == NULL)
    {
        return;
    }

    QModelIndex index = mpTableView->currentIndex();
    if (index.isValid() == false)
    {
        QMessageBox::warning(this, "Tie Point Editor", "Please select a tie point to delete.");
        return;
    }

    int currentRow = index.row();
    const vector<TiePoint>& oldPoints = pTiePointList->getTiePoints();
    vector<TiePoint> points = oldPoints;

    vector<TiePoint>::iterator pPoint = points.begin() + index.row();
    points.erase(pPoint);

    View* pView = mpLayer->getView();
    if (pView != NULL)
    {
        pView->addUndoAction(new SetTiePoints(pTiePointList, oldPoints, points));
    }

    pTiePointList->adoptTiePoints(points);

    if (currentRow == mpTableModel->rowCount())
    {
        --currentRow;
    }

    goToRow(currentRow);
}
void TiePointLayerImp::draw()
{
   const int labelTolerance = 5000; // only draw labels if <labelTolerance to be drawn
   TiePointList* pList = static_cast<TiePointList*>(getDataElement());
   VERIFYNRV(pList != NULL);

   const vector<TiePoint>& points = pList->getTiePoints();

   glColor3ub(mColor.red(), mColor.green(), mColor.blue());

   // compute the symbol size in scene coordinates
   double sceneSymbolSize = static_cast<double>(mSymbolSize) / DrawUtil::getPixelSize(0.0, 0.0, 1.0, 1.0);

   int viewableBounds[4] = {INT_MIN, INT_MIN, INT_MAX, INT_MAX};
   DrawUtil::restrictToViewport(viewableBounds[0], viewableBounds[1], viewableBounds[2], viewableBounds[3]);

   int visibleCount = drawSymbols(points, sceneSymbolSize, viewableBounds);
   if (mLabelsEnabled && visibleCount < labelTolerance)
   {
      drawLabels(points, sceneSymbolSize, viewableBounds);
   }
}
bool TiePointLayerImp::processMouseRelease(const QPoint& screenCoord, Qt::MouseButton button,
                                           Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
{
   if (mIsMission == false)
   {
      if (button == Qt::LeftButton)
      {
         LocationType point;

         ViewImp* pView = dynamic_cast<ViewImp*>(getView());
         VERIFY(pView != NULL);

         pView->setSelectionBox(QRect());
         pView->translateScreenToWorld(screenCoord.x(), screenCoord.y(), point.mX, point.mY);
         translateWorldToData(point.mX, point.mY, point.mX, point.mY);

         TiePointList* pElement = dynamic_cast<TiePointList*>(getDataElement());

         int bounds[4];
         bounds[0] = sAnchor.mX;
         bounds[1] = sAnchor.mY;
         bounds[2] = point.mX;
         bounds[3] = point.mY;

         if (bounds[0] > bounds[2])
         {
            int temp = bounds[0];
            bounds[0] = bounds[2];
            bounds[2] = temp;
         }
         if (bounds[1] > bounds[3])
         {
            int temp = bounds[1];
            bounds[1] = bounds[3];
            bounds[3] = temp;
         }

         vector<TiePoint> remainingPoints;
         const vector<TiePoint>& oldPoints = pElement->getTiePoints();
         vector<TiePoint>::const_iterator pPoint;
         for (pPoint = oldPoints.begin(); pPoint != oldPoints.end(); ++pPoint)
         {
            LocationType point = getPoint(*pPoint);
            if (!isInBounds(point, bounds))
            {
               remainingPoints.push_back(*pPoint);
            }
         }

         if (remainingPoints != oldPoints)
         {
            pView->addUndoAction(new SetTiePoints(pElement, oldPoints, remainingPoints));
            pElement->adoptTiePoints(remainingPoints);
         }

         return true;
      }
   }

   return false;
}