GraphicObject* GraphicUndoUtilities::getObject(const string& viewId, const string& layerId, const string& objectId) { if ((layerId.empty() == true) || (objectId.empty() == true)) { return NULL; } // Get the layer from the session manager Service<SessionManager> pManager; GraphicLayerImp* pLayer = dynamic_cast<GraphicLayerImp*>(pManager->getSessionItem(layerId)); if (pLayer == NULL) { // The layer could be a layer in a product ProductView* pView = dynamic_cast<ProductView*>(pManager->getSessionItem(viewId)); if (pView != NULL) { GraphicLayerImp* pLayoutLayer = dynamic_cast<GraphicLayerImp*>(pView->getLayoutLayer()); if (pLayoutLayer != NULL) { if (pLayoutLayer->getId() == layerId) { pLayer = pLayoutLayer; } } if (pLayer == NULL) { ClassificationLayer* pClassificationLayer = dynamic_cast<ClassificationLayer*>(pView->getClassificationLayer()); if (pClassificationLayer != NULL) { if (pClassificationLayer->getId() == layerId) { pLayer = dynamic_cast<GraphicLayerImp*>(pClassificationLayer); } } } } } if (pLayer != NULL) { GraphicGroup* pGroup = pLayer->getGroup(); if (pGroup != NULL) { if (pGroup->getId() == objectId) { return pGroup; } return getObject(pGroup, objectId); } } return NULL; }
void GetLayer<T>::populateTreeWidgetItemWithLayers(QTreeWidgetItem* pRoot) { VERIFYNR(pRoot != NULL); QVariant value = pRoot->data(GetSessionItemBase<T>::NameColumn, GetSessionItemBase<T>::SessionItemRole); void* pValue = value.value<void*>(); View* const pView = reinterpret_cast<View*>(pValue); VERIFYNR(pView != NULL); std::vector<Layer*> layers; SpatialDataView* pSpatialDataView = dynamic_cast<SpatialDataView*>(pView); if (pSpatialDataView != NULL) { LayerList* pLayerList = pSpatialDataView->getLayerList(); if (pLayerList != NULL) { pLayerList->getLayers(layers); } } ProductView* pProductView = dynamic_cast<ProductView*>(pView); if (pProductView != NULL) { layers.push_back(pProductView->getLayoutLayer()); layers.push_back(pProductView->getClassificationLayer()); } PlotView* pPlotView = dynamic_cast<PlotView*>(pView); if (pPlotView != NULL) { layers.push_back(pPlotView->getAnnotationLayer()); } // Add the layer items in reverse order so that the top-most layer is added first for (std::vector<Layer*>::reverse_iterator iter = layers.rbegin(); iter != layers.rend(); ++iter) { Layer* pLayer = *iter; if (pLayer == NULL || pLayer->isKindOf(TypeConverter::toString<T>()) == false) { continue; } QTreeWidgetItem* pChild = new QTreeWidgetItem; std::string name = pLayer->getDisplayName(); if (name.empty() == true) { name = pLayer->getName(); } pChild->setText(GetSessionItemBase<T>::NameColumn, QString::fromStdString(name)); pChild->setData(GetSessionItemBase<T>::NameColumn, GetSessionItemBase<T>::SessionItemRole, QVariant::fromValue<void*>(pLayer)); pChild->setText(GetSessionItemBase<T>::TypeColumn, QString::fromStdString(StringUtilities::toDisplayString(pLayer->getLayerType()))); pChild->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); pRoot->addChild(pChild); } }