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(); }
bool ChangeUpDirection::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList) { if (pInArgList == NULL || pOutArgList == NULL) { return false; } ProgressTracker progress(pInArgList->getPlugInArgValue<Progress>(Executable::ProgressArg()), "Rotating data.", "app", "{11adadb9-c133-49de-8cf5-a16372da2578}"); RasterElement* pData = pInArgList->getPlugInArgValue<RasterElement>(Executable::DataElementArg()); if (pData == NULL) { progress.report("No data element specified.", 0, ERRORS, true); return false; } bool display = false; if (!pInArgList->getPlugInArgValue("Display Results", display)) { progress.report("Unsure if results should be displayed. Invalid argument.", 0, ERRORS, true); return false; } double rotation = 0.0; SpatialDataView* pOrigView = NULL; if (isBatch()) { if (!pInArgList->getPlugInArgValue("Rotation", rotation)) { progress.report("No rotation specified.", 0, ERRORS, true); return false; } } else { pOrigView = pInArgList->getPlugInArgValue<SpatialDataView>(Executable::ViewArg()); if (pOrigView == NULL) { progress.report("No view specified.", 0, ERRORS, true); return false; } GraphicLayer* pLayer = dynamic_cast<GraphicLayer*>(pOrigView->getActiveLayer()); if (pLayer == NULL) { pLayer = dynamic_cast<GraphicLayer*>(pOrigView->getTopMostLayer(ANNOTATION)); } GraphicObject* pArrow = NULL; if (pLayer != NULL) { std::list<GraphicObject*> objects; pLayer->getObjects(ARROW_OBJECT, objects); if (!objects.empty()) { pArrow = objects.back(); } if (objects.size() > 1) { progress.report("Multiple arrow objects found. Using the most recently added one.", 0, WARNING, true); } } if (pArrow == NULL) { progress.report("Unable to locate up direction. Add an arrow annotation and re-run this plugin.", 0, ERRORS, true); return false; } LocationType ur = pArrow->getUrCorner(); LocationType ll = pArrow->getLlCorner(); double xlen = ur.mX - ll.mX; double ylen = ur.mY - ll.mY; // Initial rotatation value. The 90 degrees is due to the difference // in the "0 point" (right vs. up). Also account for explicit rotation // of the annotation object. Convert this to radians. rotation = GeoConversions::convertDegToRad(90 + pArrow->getRotation()); // Determine a rotation adjustment based on the bounding box rotation += atan2(ylen, xlen); } progress.report("Rotating data.", 10, NORMAL); ModelResource<RasterElement> pRotated(pData->copyShallow(pData->getName() + "_rotated", pData->getParent())); if (pRotated.get() == NULL) { progress.report("Unable to create destination raster element.", 0, ERRORS, true); return false; } int defaultBadValue(0); // the rotate method will handle setting the default bad values into the rotated raster if (!RasterUtilities::rotate(pRotated.get(), pData, rotation, defaultBadValue, INTERP_NEAREST_NEIGHBOR, progress.getCurrentProgress(), &mAbort)) { // error message already reported by rotate() return false; } pOutArgList->setPlugInArgValue("Rotated Element", pRotated.get()); if (display) { SpatialDataWindow* pWindow = static_cast<SpatialDataWindow*>( Service<DesktopServices>()->createWindow(pRotated->getName(), SPATIAL_DATA_WINDOW)); SpatialDataView* pView = (pWindow == NULL) ? NULL : pWindow->getSpatialDataView(); if (pView == NULL) { Service<DesktopServices>()->deleteWindow(pWindow); progress.report("Unable to create view.", 0, ERRORS, true); return false; } pView->setPrimaryRasterElement(pRotated.get()); RasterLayer* pLayer = NULL; { // scope UndoLock lock(pView); pLayer = static_cast<RasterLayer*>(pView->createLayer(RASTER, pRotated.get())); } if (pLayer == NULL) { //#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : This would be cleaner with a WindowResource. If one " \ // "becomes available, use it instead. (tclarke)") Service<DesktopServices>()->deleteWindow(pWindow); progress.report("Unable to create layer.", 0, ERRORS, true); return false; } pOutArgList->setPlugInArgValue("View", pView); } pRotated.release(); progress.report("Rotation complete.", 100, NORMAL); progress.upALevel(); return true; }