void MeasurementObjectImp::updateGeoreferenceAttachment()
{
   if (mpGeoreference.get() != NULL)
   {
      return;
   }

   RasterElement* pGeoreference = NULL;

   // Must find Georeference through the view, since the GraphicElement is a root element.
   GraphicLayer* pLayer = getLayer();
   if (pLayer != NULL)
   {
      SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView());
      if (pView != NULL)
      {
         LayerList* pLayerList = pView->getLayerList();
         VERIFYNRV(pLayerList != NULL);
         pGeoreference = pLayerList->getPrimaryRasterElement();
      }
   }

   if (pGeoreference != NULL && pGeoreference->isGeoreferenced())
   {
      mpGeoreference.reset(pGeoreference);
      enableGeo();
      generateGeoStrings();
   }
}
Example #2
0
void FrameLabelObjectImp::updateAnimationList(bool force)
{
   if (getAutoMode() == false)
   {
      return;
   }

   const bool wasLocked = getLocked();
   if (force == true)
   {
      setLocked(false);
   }

   if (getLocked() == false)
   {
      View* pView = NULL;
      GraphicLayer* pLayer = getLayer();
      if (pLayer != NULL)
      {
         pView = pLayer->getView();
      }

      setAnimations(pView);
   }

   if (force == true)
   {
      setLocked(wasLocked);
   }
}
Example #3
0
AddVertices::AddVertices(MultipointObjectImp* pObject, const vector<LocationType>& oldVertices,
                         const vector<LocationType>& oldGeoVertices, const vector<LocationType>& newVertices,
                         const vector<LocationType>& newGeoVertices) :
   UndoAction(dynamic_cast<SessionItem*>(pObject)),
   mOldVertices(oldVertices),
   mOldGeoVertices(oldGeoVertices),
   mNewVertices(newVertices),
   mNewGeoVertices(newGeoVertices)
{
   if (pObject != NULL)
   {
      GraphicLayer* pLayer = pObject->getLayer();
      if (pLayer != NULL)
      {
         View* pView = pLayer->getView();
         if (pView != NULL)
         {
            mViewId = pView->getId();
         }

         mLayerId = pLayer->getId();
      }
   }

   setText("Add Vertices");
}
Example #4
0
void ScaleBarObjectImp::updateAttachments()
{
   if (mpGeoreference.get() == NULL)
   {
      const RasterElement* pGeoreference = getGeoreferenceElement();
      if (pGeoreference != NULL)
      {
         mpGeoreference.reset(const_cast<RasterElement*>(pGeoreference));
         mXgsd = GeoAlgorithms::getXaxisGSD(pGeoreference);
         mNeedsLayout = true;
      }
   }

   if (mpView.get() == NULL)
   {
      GraphicLayer* pLayer = getLayer();
      if (pLayer != NULL)
      {
         PerspectiveView* pPerspectiveView = dynamic_cast<PerspectiveView*>(pLayer->getView());
         if (pPerspectiveView != NULL)
         {
            mpView.reset(pPerspectiveView);
            mNeedsLayout = true;
         }
      }
   }
}
Example #5
0
void GroupUngroupGraphicObjects::group()
{
   GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(getSessionItem());
   if (pLayer != NULL)
   {
      list<GraphicObject*> selectedObjects;
      pLayer->getSelectedObjects(selectedObjects);
      pLayer->deselectAllObjects();

      for (list<string>::const_iterator iter = mObjectIds.begin(); iter != mObjectIds.end(); ++iter)
      {
         string objectId = *iter;
         if (objectId.empty() == false)
         {
            string viewId;

            View* pView = pLayer->getView();
            if (pView != NULL)
            {
               viewId = pView->getId();
            }

            GraphicObject* pObject = GraphicUndoUtilities::getObject(viewId, pLayer->getId(), objectId);
            if (pObject != NULL)
            {
               pLayer->selectObject(pObject);
            }
         }
      }

      pLayer->groupSelection();

      list<GraphicObject*> newSelectedObjects;
      pLayer->getSelectedObjects(newSelectedObjects);
      VERIFYNRV(newSelectedObjects.size() == 1);

      GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(newSelectedObjects.front());
      VERIFYNRV(pGroup != NULL);

      for (list<GraphicObject*>::iterator iter = selectedObjects.begin(); iter != selectedObjects.end(); ++iter)
      {
         GraphicObject* pObject = *iter;
         if ((pObject != NULL) && (pGroup->hasObject(pObject) == false))
         {
            pLayer->selectObject(pObject);
         }
      }

      string oldGroupId = mGroupId;
      mGroupId = pGroup->getId();
      emit sessionItemChanged(oldGroupId, mGroupId);
   }
}
Example #6
0
void GroupUngroupGraphicObjects::ungroup()
{
   GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(getSessionItem());
   if ((pLayer != NULL) && (mGroupId.empty() == false))
   {
      string viewId;

      View* pView = pLayer->getView();
      if (pView != NULL)
      {
         viewId = pView->getId();
      }

      GraphicGroup* pGroup = dynamic_cast<GraphicGroup*>(GraphicUndoUtilities::getObject(viewId,
         pLayer->getId(), mGroupId));
      if (pGroup != NULL)
      {
         list<GraphicObject*> selectedObjects;
         pLayer->getSelectedObjects(selectedObjects);

         pLayer->deselectAllObjects();
         pLayer->selectObject(pGroup);
         pLayer->ungroupSelection();

         list<GraphicObject*> objects;
         pLayer->getSelectedObjects(objects);

         mObjectIds.clear();
         for (list<GraphicObject*>::iterator iter = objects.begin(); iter != objects.end(); ++iter)
         {
            GraphicObject* pObject = *iter;
            if (pObject != NULL)
            {
               string objectId = pObject->getId();
               if (objectId.empty() == false)
               {
                  mObjectIds.push_back(objectId);
               }
            }
         }

         for (list<GraphicObject*>::iterator iter = selectedObjects.begin(); iter != selectedObjects.end(); ++iter)
         {
            GraphicObject* pObject = *iter;
            if ((pObject != NULL) && (pObject != pGroup))
            {
               pLayer->selectObject(pObject);
            }
         }
      }
   }
}
Example #7
0
QFont TextObjectImp::getScaledFont(double minSize, double maxSize)
{
   QFont scaledFont = getFont();

   GraphicLayer* pLayer = getLayer();
   if (pLayer != NULL)
   {
      // Scale the point size
      double pointSize = scaledFont.pointSizeF();

      PerspectiveView* pPerspectiveView = dynamic_cast<PerspectiveView*>(pLayer->getView());
      if (pPerspectiveView != NULL)
      {
         // Zoom percentage
         double zoomPercent = pPerspectiveView->getZoomPercentage();
         pointSize *= zoomPercent / 100.0;

         // Product DPI
         ProductView* pProductView = dynamic_cast<ProductView*>(pPerspectiveView);
         if (pProductView != NULL)
         {
            int dpi = pProductView->getDpi();
            pointSize *= dpi / 72.0;
         }
      }

      // Restrict to the minimum size
      if (minSize > 0.0)
      {
         pointSize = max(pointSize, minSize);
      }

      // Restrict to the maximum size
      if (maxSize > 0.0)
      {
         pointSize = min(pointSize, maxSize);
      }

      // Set the scaled point size in the font
      scaledFont.setPointSizeF(pointSize);
   }

   return scaledFont;
}
Example #8
0
NewPath::NewPath(PolylineObjectImp* pObject, unsigned int path) :
   UndoAction(dynamic_cast<SessionItem*>(pObject)),
   mPath(path)
{
   if (pObject != NULL)
   {
      GraphicLayer* pLayer = pObject->getLayer();
      if (pLayer != NULL)
      {
         View* pView = pLayer->getView();
         if (pView != NULL)
         {
            mViewId = pView->getId();
         }

         mLayerId = pLayer->getId();
      }
   }

   setText("New Path");
}
Example #9
0
SetGraphicObjectName::SetGraphicObjectName(GraphicObject *pObject, const string &oldName, const string &newName) :
   UndoAction(pObject),
   mOldName(oldName),
   mNewName(newName)
{
   GraphicObjectImp* pObjectImp = dynamic_cast<GraphicObjectImp*>(pObject);
   if (pObjectImp != NULL)
   {
      GraphicLayer* pLayer = pObjectImp->getLayer();
      if (pLayer != NULL)
      {
         View* pView = pLayer->getView();
         if (pView != NULL)
         {
            mViewId = pView->getId();
         }

         mLayerId = pLayer->getId();
      }
   }
   setText("Rename Graphic Object");
}
Example #10
0
SetGraphicObjectProperty::SetGraphicObjectProperty(GraphicObject* pObject, const GraphicProperty* pOldProperty,
                                                   const GraphicProperty* pNewProperty) :
   UndoAction(pObject),
   mpOldProperty(NULL),
   mpNewProperty(NULL)
{
   GraphicObjectImp* pObjectImp = dynamic_cast<GraphicObjectImp*>(pObject);
   if (pObjectImp != NULL)
   {
      GraphicLayer* pLayer = pObjectImp->getLayer();
      if (pLayer != NULL)
      {
         View* pView = pLayer->getView();
         if (pView != NULL)
         {
            mViewId = pView->getId();
         }

         mLayerId = pLayer->getId();
      }
   }

   QString actionText = "Set Object Property";
   if ((pOldProperty != NULL) && (pNewProperty != NULL))
   {
      string oldName = pOldProperty->getName();
      string newName = pNewProperty->getName();
      if (oldName == newName)
      {
         actionText = "Set Object " + QString::fromStdString(oldName);
         mpOldProperty = pOldProperty->copy();
         mpNewProperty = pNewProperty->copy();
      }
   }

   setText(actionText);
}
void EastArrowObjectImp::orient()
{
   if (isOriented() == true)
   {
      return;
   }

   GraphicLayer* pLayer = NULL;
   pLayer = getLayer();
   if (pLayer == NULL)
   {
      return;
   }

   View* pView = NULL;
   pView = pLayer->getView();
   if (pView == NULL)
   {
      return;
   }

   SpatialDataView* pSpatialDataView = NULL;
   if (pView->isKindOf("SpatialDataView") == true)
   {
      pSpatialDataView = static_cast<SpatialDataView*> (pView);
   }
   else if (pView->isKindOf("ProductView") == true)
   {
      ProductView* pProductView = static_cast<ProductView*> (pView);

      GraphicLayer* pLayoutLayer = NULL;
      pLayoutLayer = pProductView->getLayoutLayer();
      if (pLayoutLayer == pLayer)
      {
         list<GraphicObject*> viewObjects;
         pLayoutLayer->getObjects(VIEW_OBJECT, viewObjects);

         list<GraphicObject*>::iterator iter = viewObjects.begin();
         while (iter != viewObjects.end())
         {
            GraphicObject* pObject = *iter;
            if (pObject != NULL)
            {
               View* pObjectView = pObject->getObjectView();
               if (pObjectView != NULL)
               {
                  if (pObjectView->isKindOf("SpatialDataView") == true)
                  {
                     pSpatialDataView = static_cast<SpatialDataView*> (pObjectView);
                  }
               }
            }

            ++iter;
         }
      }
   }

   if (pSpatialDataView == NULL)
   {
      return;
   }

   LayerList* pLayerList = pSpatialDataView->getLayerList();
   VERIFYNRV(pLayerList != NULL);
   RasterElement* pRaster = pLayerList->getPrimaryRasterElement();
   VERIFYNRV(pRaster != NULL);
   if (!pRaster->isGeoreferenced())
   {
      return;
   }

   // Calculate the angle of the object relative to the pixel coordinates
   updateHandles();

   LocationType pixelStart = mHandles[7];

   ProductView* pProductView = dynamic_cast<ProductView*> (pView);
   if (pProductView != NULL)
   {
      // Convert to the screen coordinate system
      double dScreenX = 0;
      double dScreenY = 0;
      pLayer->translateDataToWorld(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY);
      pProductView->translateWorldToScreen(pixelStart.mX, pixelStart.mY, dScreenX, dScreenY);
      
      // Convert to the spatial data view coordinate system
      pSpatialDataView->translateScreenToWorld(dScreenX,
         dScreenY, pixelStart.mX, pixelStart.mY);
      pLayer->translateWorldToData(pixelStart.mX, pixelStart.mY, pixelStart.mX, pixelStart.mY);
   }

   double dAngle;
   if (GeoAlgorithms::getAngleToNorth(pRaster, dAngle, pixelStart) == false)
   {
      return;
   }

   // Update the angle if the object is in the layout layer
   if (pProductView != NULL)
   {
      // Rotation
      dAngle -= pSpatialDataView->getRotation();

      // Pitch
      double dPitch = pSpatialDataView->getPitch();
      if (dPitch > 0.0)
      {
         dAngle *= -1.0;
      }
   }

   // Rotate the object
   setRotation(dAngle);

   // Update the orientation flag
   DirectionalArrowObjectImp::orient();
}
Example #12
0
void TextObjectImp::updateBoundingBox()
{
   // Get the width and height of the bounding box in screen pixels based on the scaled text image size
   int iWidth = 0;
   int iHeight = 0;

   string text = getSubstitutedText();
   if (text.empty() == false)
   {
      QString strMessage = QString::fromStdString(text);
      QFont scaledFont = getScaledFont();

      int iMaxSize = 0;
      glGetIntegerv(GL_MAX_TEXTURE_SIZE, &iMaxSize);

      int iAlignment = getTextAlignment();

      QFontMetrics ftMetrics(scaledFont);
      QRect boundingBox = ftMetrics.boundingRect(0, 0, iMaxSize, iMaxSize,
         iAlignment | Qt::TextWordWrap, strMessage);

      iWidth = boundingBox.width();
      iHeight = boundingBox.height();
   }

   // Get the current bounding box
   LocationType llCorner = getLlCorner();
   LocationType urCorner = getUrCorner();

   // Use the lower left corner as the anchor and compute the data coordinate of the upper right corner
   GraphicLayer* pLayer = getLayer();
   if (pLayer != NULL)
   {
      // Compute the upper right coordinate
      PerspectiveView* pView = dynamic_cast<PerspectiveView*>(pLayer->getView());
      if (pView != NULL)
      {
         double zoomFactor = 100.0 / pView->getZoomPercentage();
         double xScale = zoomFactor / pLayer->getXScaleFactor();
         double yScale = zoomFactor / pLayer->getYScaleFactor();

         urCorner.mX = llCorner.mX + (iWidth * xScale);
         urCorner.mY = llCorner.mY + (iHeight * yScale);
      }

      if (dynamic_cast<OrthographicView*>(pLayer->getView()) != NULL)
      {
         double dScreenX = 0.0;
         double dScreenY = 0.0;
         pLayer->translateDataToScreen(llCorner.mX, llCorner.mY, dScreenX, dScreenY);
         pLayer->translateScreenToData(dScreenX + iWidth, dScreenY + iHeight, urCorner.mX, urCorner.mY);
      }
   }
   else
   {
      urCorner.mX = llCorner.mX + iWidth;
      urCorner.mY = llCorner.mY + iHeight;
   }

   // Update the bounding box and selection handles
   setBoundingBox(llCorner, urCorner);
   updateHandles();

   mUpdateBoundingBox = false;
}
string MeasurementObjectImp::generateGeoStrings() const
{
   LocationType llCorner = getLlCorner();
   LocationType urCorner = getUrCorner();
   LocationType llCornerLatLon;
   LocationType urCornerLatLon;
   bool unitsValid = false;

   // Get lat lon coordinates and terrain raster
   const RasterElement* pTerrain = NULL;

   bool geoValid(false);
   if (mpGeoreference.get() != NULL)
   {
      GraphicLayer* pLayer = getLayer();
      if (pLayer != NULL)
      {
         SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView());
         if (pView != NULL)
         {
            LayerList* pLayerList = pView->getLayerList();
            VERIFYRV(pLayerList != NULL, "");
            VERIFYRV(pLayerList->getPrimaryRasterElement() == mpGeoreference.get(), "");

            pTerrain = mpGeoreference->getTerrain();

            Layer* pPrimaryRasterLayer = pLayerList->getLayer(RASTER, mpGeoreference.get());
            if (pPrimaryRasterLayer != NULL)
            {
               pPrimaryRasterLayer->translateWorldToData(llCorner.mX, llCorner.mY, llCorner.mX, llCorner.mY);
               pPrimaryRasterLayer->translateWorldToData(urCorner.mX, urCorner.mY, urCorner.mX, urCorner.mY);
            }
         }
      }

      if (mpGeoreference->isGeoreferenced())
      {
         bool llValid(false);
         bool urValid(false);
         llCornerLatLon = mpGeoreference->convertPixelToGeocoord(llCorner, false, &llValid);
         urCornerLatLon = mpGeoreference->convertPixelToGeocoord(urCorner, false, &urValid);
         geoValid = llValid && urValid;
      }
   }

   mUsingInaccurateGeocoords = !geoValid;
   unitsValid = geoValid;

   //String Variables
   string startLoc = "";
   string endLoc = "";
   string distance = "";
   string bearing = "";
   string distanceUnit = "";

   GeoAlgorithms algs;
   double distanceVal = 0;
   double azimuthVal = 0;

   // Create GeoPoint objects
   LatLonPoint startLlPoint = llCornerLatLon;
   LatLonPoint endLlPoint = urCornerLatLon;
   UtmPoint startUtmPoint = startLlPoint;
   UtmPoint endUtmPoint = endLlPoint;
   MgrsPoint startMgrsPoint = startLlPoint;
   MgrsPoint endMgrsPoint = endLlPoint;

   // find elevations
   double elevation1(0.0);
   double elevation2(0.0);
   if (pTerrain != NULL)
   {
      const RasterDataDescriptor* pDescriptor =
         dynamic_cast<const RasterDataDescriptor*>(pTerrain->getDataDescriptor());
      if (pDescriptor != NULL)
      {
         const vector<DimensionDescriptor>& activeRows = pDescriptor->getRows();
         const vector<DimensionDescriptor>& activeColumns = pDescriptor->getColumns();
         if ( llCorner.mY >= 0 && llCorner.mY < activeRows.size() &&
              llCorner.mX >= 0 && llCorner.mX < activeColumns.size() &&
              urCorner.mY >= 0 && urCorner.mY < activeRows.size() &&
              urCorner.mX >= 0 && urCorner.mX < activeColumns.size() )
         {
            DimensionDescriptor llRowDim(activeRows[llCorner.mY]);
            DimensionDescriptor llColumnDim(activeColumns[llCorner.mX]);
            DimensionDescriptor urRowDim(activeRows[urCorner.mY]);
            DimensionDescriptor urColumnDim(activeColumns[urCorner.mX]);
            elevation1 = pTerrain->getPixelValue(llColumnDim, llRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE);
            elevation2 = pTerrain->getPixelValue(urColumnDim, urRowDim, DimensionDescriptor(), COMPLEX_MAGNITUDE);
            const Units* pElevationUnits = pDescriptor->getUnits();
            if (pElevationUnits != NULL)
            {
               double scale = pElevationUnits->getScaleFromStandard();
               elevation1 *= scale;
               elevation2 *= scale;
            }
         }
      }
   }

   if (unitsValid == true)
   {
      // Calculate bearing and distance
      distanceVal = algs.getPythagoreanOrVincentyDistance(startLlPoint.getLatitude().getValue(),
         startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(),
         endLlPoint.getLongitude().getValue(), elevation1, elevation2);
      azimuthVal = algs.getVincentyAzimuth(startLlPoint.getLatitude().getValue(),
         startLlPoint.getLongitude().getValue(), endLlPoint.getLatitude().getValue(),
         endLlPoint.getLongitude().getValue());
      azimuthVal = GeoConversions::convertRadToDeg(azimuthVal);

      // Set distance text
      if (mDrawnDistanceUnit == KILOMETER)
      {
         distanceUnit = "km";
         distanceVal = distanceVal/1000;
      }
      else if (mDrawnDistanceUnit == MILE)
      {
         distanceUnit = "mi";
         distanceVal = GeoConversions::convertMetersToMiles(distanceVal);
      }
      else if (mDrawnDistanceUnit == NAUTICAL_MILE)
      {
         distanceUnit = "Nm";
         distanceVal = GeoConversions::convertMetersToNm(distanceVal);
      }
      else if (mDrawnDistanceUnit == METER)
      {
         distanceUnit = "m";
      }
      else if (mDrawnDistanceUnit == YARD)
      {
         distanceUnit = "yd";
         distanceVal = GeoConversions::convertMetersToFeet(distanceVal)/3;
      }
      else if (mDrawnDistanceUnit == FOOT)
      {
         distanceUnit = "ft";
         distanceVal = GeoConversions::convertMetersToFeet(distanceVal);
      }

      // set location text
      switch (mDrawnGeocoord)
      {
      case GEOCOORD_LATLON:
         startLoc = startLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision);
         endLoc = endLlPoint.getText(mDrawnDmsFormat, mEndPointsPrecision);
         break;

      case GEOCOORD_UTM:
         startLoc = startUtmPoint.getText();
         endLoc = endUtmPoint.getText();
         break;

      case GEOCOORD_MGRS:
         startLoc = startMgrsPoint.getText();
         endLoc = endMgrsPoint.getText();
         break;

      default:
         startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
            QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
         endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
            QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
         break;
      }
   }
   else
   {
      startLoc = "(" + QString::number(llCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
         QString::number(llCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
      endLoc = "(" + QString::number(urCorner.mX, 'f', mEndPointsPrecision).toStdString() + ", " +
         QString::number(urCorner.mY, 'f', mEndPointsPrecision).toStdString() + ")";
      azimuthVal = algs.getPythagoreanAzimuth(llCorner.mX, llCorner.mY, urCorner.mX, urCorner.mY);
      azimuthVal = GeoConversions::convertRadToDeg(azimuthVal);
      distanceVal = algs.getPythagoreanDistance(urCorner.mX, urCorner.mY, llCorner.mX, llCorner.mY);
      distanceUnit = "pix";
   }

   bearing = QString::number(azimuthVal, 'f', mBearingPrecision).toStdString();
   distance = QString::number(distanceVal, 'f', mDistancePrecision).toStdString();

   QString bearingText = QString::fromStdString(bearing) + " deg";
   QString distanceText = QString::fromStdString(distance) + " " + QString::fromStdString(distanceUnit);
   QString startLocText = QString::fromStdString(startLoc);
   QString endLocText = QString::fromStdString(endLoc);

   // Final strings
   if (bearingText != mBearingText)
   {
      mBearingText = bearingText;
      mBearingTextTexture.invalidate();
   }

   if (distanceText != mDistanceText)
   {
      mDistanceText = distanceText;
      mDistanceTextTexture.invalidate();
   }
   if (startLocText != mStartLocText)
   {
      mStartLocText = startLocText;
      mStartLocTextTexture.invalidate();
   }
   if (endLocText != mEndLocText)
   {
      mEndLocText = endLocText;
      mEndLocTextTexture.invalidate();
   }

   string rtnVal = "DISTANCE: " + distanceText.toStdString() + " : LOCATION: " + startLoc + " to " +
      endLoc + " at " + bearingText.toStdString();
   return rtnVal;
}
Example #14
0
bool ArcObjectImp::hit(LocationType pixelCoord) const
{
    int iStart = static_cast<int>(getStartAngle());
    if (iStart < 0)
    {
        iStart--;
    }

    int iStop = static_cast<int>(getStopAngle());
    if (iStop < 0)
    {
        iStop--;
    }

    if (iStart == iStop)
    {
        iStart = 0;
        iStop = 360;
    }

    ArcRegion eArcRegion = getArcRegion();

    DrawUtil::initializeCircle();
    LocationType center = getCenter();

    bool bHit = false;

    // Filled area
    FillStyle eFillStyle = getFillStyle();
    if (eFillStyle != EMPTY_FILL)
    {
        int iSize = abs(iStop - iStart) + 1;
        if (eArcRegion == ARC_CENTER)
        {
            iSize += 2;
        }
        else if (eArcRegion == ARC_CHORD)
        {
            iSize += 1;
        }

        double* pXVertices = new double[iSize];
        double* pYVertices = new double[iSize];

        int i = 0;
        int iIndex = 0;
        for (i = iStart, iIndex = 0; i <= iStop; i++, iIndex++)
        {
            LocationType arcPoint = getLocation(static_cast<double>(i));
            pXVertices[iIndex] = arcPoint.mX;
            pYVertices[iIndex] = arcPoint.mY;
        }

        if ((eArcRegion == ARC_CENTER) || (eArcRegion == ARC_CHORD))
        {
            if (eArcRegion == ARC_CENTER)
            {
                pXVertices[iSize - 2] = center.mX;
                pYVertices[iSize - 2] = center.mY;
            }

            pXVertices[iSize - 1] = pXVertices[0];
            pYVertices[iSize - 1] = pYVertices[0];
        }

        bHit = DrawUtil::isWithin(pixelCoord.mX, pixelCoord.mY, pXVertices, pYVertices, iSize);

        delete [] pXVertices;
        delete [] pYVertices;
    }

    // Line
    if (bHit == false)
    {
        bool bLine = false;
        bLine = getLineState();
        if (bLine == true)
        {
            // Check the arc line
            double size = 1.0;

            GraphicLayer* pLayer = NULL;
            pLayer = getLayer();
            if (pLayer != NULL)
            {
                View* pView = pLayer->getView();
                if (pView != NULL)
                {
                    size = pView->getPixelSize(center, center);
                }

                size *= min(pLayer->getXScaleFactor(), pLayer->getYScaleFactor());
            }

            LocationType basePoint;
            for (int i = iStart; i <= iStop; i++)
            {
                LocationType currentPoint = getLocation(static_cast<double>(i));
                if (i != iStart)
                {
                    bHit = DrawUtil::lineHit(currentPoint, basePoint, pixelCoord, 2.0/size);
                    if (bHit == true)
                    {
                        break;
                    }
                }

                basePoint.mX = currentPoint.mX;
                basePoint.mY = currentPoint.mY;
            }

            // Check the arc region lines
            if (bHit == false)
            {
                LocationType startPoint = getLocation(static_cast<double>(iStart));
                LocationType stopPoint = getLocation(static_cast<double>(iStop));

                if (eArcRegion == ARC_CENTER)
                {
                    bHit = DrawUtil::lineHit(startPoint, center, pixelCoord, 2.0/size);
                    if (bHit == false)
                    {
                        bHit = DrawUtil::lineHit(stopPoint, center, pixelCoord, 2.0/size);
                    }
                }
                else if (eArcRegion == ARC_CHORD)
                {
                    bHit = DrawUtil::lineHit(startPoint, stopPoint, pixelCoord, 2.0/size);
                }
            }
        }
    }

    return bHit;
}
Example #15
0
bool EllipseObjectImp::hit(LocationType pixelCoord) const
{ 
   LocationType llCorner = getLlCorner();
   LocationType urCorner = getUrCorner();

   double xVertices[DrawUtil::VERTEX_COUNT + 1];
   double yVertices[DrawUtil::VERTEX_COUNT + 1];
   DrawUtil::initializeCircle();

   LocationType center;
   center.mX = (llCorner.mX + urCorner.mX) / 2.0;
   center.mY = (llCorner.mY + urCorner.mY) / 2.0;

   LocationType radii;
   radii.mX = fabs (llCorner.mX - urCorner.mX) / 2.0;
   radii.mY = fabs (llCorner.mY - urCorner.mY) / 2.0;

   int i = 0;
   for (i = 0; i < DrawUtil::VERTEX_COUNT; i++)
   {
      xVertices[i] = center.mX + radii.mX * DrawUtil::sCirclePoints[i].mX;
      yVertices[i] = center.mY + radii.mY * DrawUtil::sCirclePoints[i].mY;
   }

   xVertices[DrawUtil::VERTEX_COUNT] = xVertices[0];
   yVertices[DrawUtil::VERTEX_COUNT] = yVertices[0];

   bool bHit = false;

   // Filled area
   FillStyle eFillStyle = getFillStyle();
   if (eFillStyle != EMPTY_FILL)
   {
      bHit = DrawUtil::isWithin(pixelCoord.mX, pixelCoord.mY, xVertices, yVertices, DrawUtil::VERTEX_COUNT+1);
   }

   // Line
   if (bHit == false)
   {
      bool bLine = false;
      bLine = getLineState();
      if (bLine == true)
      {
         double size = 1.0;

         GraphicLayer* pLayer = NULL;
         pLayer = getLayer();
         if (pLayer != NULL)
         {
            View* pView = pLayer->getView();
            if (pView != NULL)
            {
               size = pView->getPixelSize(llCorner, urCorner);
            }
            size *= min(pLayer->getXScaleFactor(), pLayer->getYScaleFactor());
         }

         LocationType basePoint;
         for (i = 0; i < DrawUtil::VERTEX_COUNT; i++)
         {
            LocationType currentPoint(xVertices[i], yVertices[i]);

            if (i != 0)
            {
               bHit = DrawUtil::lineHit(currentPoint, basePoint, pixelCoord, 2.0/size);
               if (bHit == true)
               {
                  break;
               }
            }

            basePoint = currentPoint;
         }
      }
   }

   return bHit;
}