Esempio n. 1
0
vector<ImportDescriptor*> LayerImporter::getImportDescriptors(const string& filename, bool reportErrors)
{
   vector<ImportDescriptor*> descriptors;
   if (!filename.empty())
   {
      MessageLog* pLog = NULL;
      if (reportErrors == true)
      {
         Service<MessageLogMgr> pLogMgr;
         pLog = pLogMgr->getLog();
      }

      XmlReader xml(pLog);
      XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* pDoc = xml.parse(filename, "metadata");
      DOMElement* pRootElement = NULL;
      if (pDoc != NULL)
      {
         pRootElement = pDoc->getDocumentElement();
      }
      if (pRootElement != NULL)
      {
         for (DOMNode* pChild = pRootElement->getFirstChild();
            pChild != NULL;
            pChild = pChild->getNextSibling())
         {
            if (pChild->getNodeType() == DOMNode::ELEMENT_NODE)
            {
               DOMElement* pChildElement = static_cast<DOMElement*>(pChild);
               string cNodeName = A(pChildElement->getNodeName());

               ImportDescriptor* pImportDescriptor = ModelImporter::populateImportDescriptor(pChildElement, filename);
               if (pImportDescriptor != NULL)
               {
                  DataDescriptor* pDataDescriptor = pImportDescriptor->getDataDescriptor();
                  if (NULL != pDataDescriptor)
                  {
                     DynamicObject* pMetadataZ = pDataDescriptor->getMetadata();
                     VERIFYRV(pMetadataZ, descriptors);
                     if (!pMetadataZ->getAttributeByPath("Layer/Import Options/Use Pixel Coordinates").isValid())
                     {
                        pMetadataZ->setAttributeByPath("Layer/Import Options/Use Pixel Coordinates", false);
                     }
                  }
                  descriptors.push_back(pImportDescriptor);
               }
            }
         }
      }
   }

   return descriptors;
}
Esempio n. 2
0
string TextObjectImp::getSubstitutedText()
{
   string txt = getText();

   DataElement* pParent = getElement();
   pParent = (pParent == NULL) ? NULL : pParent->getParent();
   DataDescriptor* pParentDesc = (pParent == NULL) ? NULL : pParent->getDataDescriptor();
   DynamicObject* pParentMetadata = (pParentDesc == NULL) ? NULL : pParentDesc->getMetadata();
   for (int i = 0; i < 50; ++i)
   {
      //each pass does replacement of $M(a) currently in the string.
      //do 50 passes to perform sub-expansion at most fifty times, ie. prevent infinite loop
      //for non-terminating recursive expansion
      string::size_type pos = txt.find("$");
      while (pos != string::npos)
      {
         if (pos + 1 >= txt.size())
         {
            break;
         }
         string type = txt.substr(pos+1, 1);
         if (type != "$") //ie. not $$, the escape sequence so continue
         {
            bool replaced = false;
            if (pos+4 < txt.size()) //ie. $M(a)
            {
               if (txt[pos+2] == '(')
               {
                  string::size_type closeParen = txt.find(')', pos+2);
                  if (closeParen == string::npos)
                  {
                     closeParen = txt.size();
                  }
                  string variableName = txt.substr(pos+3, closeParen-(pos+2)-1);
                  string replacementString;
                  if (type == "M" || type == "S")
                  {
                     DataElement* pElmnt = pParent;
                     DynamicObject* pMetadata = pParentMetadata;
                     if (variableName.substr(0, 2) == "//")
                     {
                        string::size_type endNamePos = variableName.find("//", 2);
                        if (endNamePos != string::npos)
                        {
                           string elementName = variableName.substr(2, endNamePos - 2);
                           variableName = variableName.substr(endNamePos + 2);
                           if (!variableName.empty())
                           {
                              if (elementName[0] == '[' && elementName[elementName.size() - 1] == ']')
                              {
                                 elementName = elementName.substr(1, elementName.size() - 2);
                                 std::list<GraphicObject*> objects;
                                 getLayer()->getObjects(VIEW_OBJECT, objects);
                                 for (std::list<GraphicObject*>::iterator object = objects.begin();
                                    object != objects.end(); ++object)
                                 {
                                    GraphicObject* pObj = *object;
                                    if (pObj->getName() == elementName)
                                    {
                                       SpatialDataView* pSdv = dynamic_cast<SpatialDataView*>(pObj->getObjectView());
                                       if (pSdv != NULL)
                                       {
                                          pElmnt = pSdv->getLayerList()->getPrimaryRasterElement();
                                          DataDescriptor* pDesc =
                                             (pElmnt == NULL) ? NULL : pElmnt->getDataDescriptor();
                                          pMetadata = (pDesc == NULL) ? NULL : pDesc->getMetadata();
                                       }
                                       break;
                                    }
                                 }
                              }
                              else
                              {
                                 pElmnt = Service<ModelServices>()->getElement(elementName,
                                    TypeConverter::toString<RasterElement>(), NULL);
                                 DataDescriptor* pDesc = (pElmnt == NULL) ? NULL : pElmnt->getDataDescriptor();
                                 pMetadata = (pDesc == NULL) ? NULL : pDesc->getMetadata();
                              }
                           }
                           else
                           {
                              pElmnt = NULL;
                              pMetadata = NULL;
                           }
                        }
                     }
                     bool success = false;
                     if (type == "M" && pMetadata != NULL)
                     {
                        DataVariant var = pMetadata->getAttributeByPath(variableName);
                        if (var.isValid())
                        {
                           DataVariant::Status status;
                           replacementString = var.toDisplayString(&status);
                           success = (status == DataVariant::SUCCESS);
                           if (mMetadataObjects.find(pMetadata) == mMetadataObjects.end())
                           {
                              mMetadataObjects.insert(make_pair(pMetadata, new AttachmentPtr<DynamicObject>(
                                 pMetadata, SIGNAL_NAME(Subject, Modified),
                                 Slot(this, &TextObjectImp::invalidateTexture))));
                           }
                        }
                     }
                     else if (type == "S" && pElmnt != NULL && variableName == "CLASSIFICATION")
                     {
                        Classification* pClass = pElmnt->getDataDescriptor()->getClassification();
                        pClass->getClassificationText(replacementString);
                        success = true;
                        if (mClassificationObjects.find(pClass) == mClassificationObjects.end())
                        {
                           mClassificationObjects.insert(make_pair(pClass, new AttachmentPtr<Classification>(
                              pClass, SIGNAL_NAME(Subject, Modified),
                              Slot(this, &TextObjectImp::invalidateTexture))));
                        }
                     }
                     if (!success)
                     {
                        replacementString = "Error!";
                     }
                     replaced = true;
                  }
                  if (replaced)
                  {
                     txt.replace(pos, closeParen-pos+1, replacementString);
                     pos = txt.find("$", pos+replacementString.size());
                  }
               }
            }
            if (!replaced)
            {
               pos = txt.find("$", pos+1);
            }
         }
         else
         {
            pos = txt.find("$", pos+2);
         }
      }
   }
   string::size_type pos = txt.find("$$");
   while (pos != string::npos)
   {
      txt.replace(pos, 2, "$");
      pos = txt.find("$$");
   }

   return txt;
}
Esempio n. 3
0
bool SignatureLibraryImp::import(const string &filename, const string &importerName, Progress* pProgress)
{
   ImporterResource importer(importerName, filename, pProgress);
   vector<ImportDescriptor*> descs = importer->getImportDescriptors();

   RasterDataDescriptor* pCubeDescriptor = NULL;
   if (descs.size() == 1 && descs.front() != NULL)
   {
      pCubeDescriptor = dynamic_cast<RasterDataDescriptor*>(descs.front()->getDataDescriptor());
   }

   if (pCubeDescriptor != NULL)
   {
      pCubeDescriptor->setProcessingLocation(ON_DISK);
      bool cubeSuccess = importer->execute();
      if (cubeSuccess)
      {
         vector<DataElement*> importedElements = importer->getImportedElements();
         if (!importedElements.empty())
         {
            RasterElement* pCube = dynamic_cast<RasterElement*>(importedElements.front());
            Service<ModelServices>()->setElementParent(pCube, dynamic_cast<DataElement*>(this));
            if (pCube != NULL)
            {
               clear();
               mpOdre.reset(pCube);
               DynamicObject* pMetadata = getMetadata();
               if (pMetadata != NULL)
               {
                  string pCenterPath[] = { SPECIAL_METADATA_NAME, BAND_METADATA_NAME, 
                     CENTER_WAVELENGTHS_METADATA_NAME, END_METADATA_NAME };
                  mOriginalAbscissa = dv_cast<vector<double> >(
                     pMetadata->getAttributeByPath(pCenterPath), vector<double>());

                  vector<string> sigNames = 
                     dv_cast<vector<string> >(pMetadata->getAttribute("Signature Names"), vector<string>());

                  SignatureLibrary* pLib = dynamic_cast<SignatureLibrary*>(this);
                  VERIFY(pLib != NULL);

                  unsigned int numSigs = pCubeDescriptor->getRowCount();

                  mSignatures.reserve(numSigs);
                  for (unsigned int i = 0; i < numSigs; ++i)
                  {
                     string name;
                     if (i >= sigNames.size())
                     {
                        stringstream stream;
                        stream << "Signature " << i+1;
                        name = stream.str();
                     }
                     else
                     {
                        name = sigNames[i];
                     }
                     DataDescriptor* pDataDesc =
                        Service<ModelServices>()->createDataDescriptor(name, "DataElement", pLib);
                     DataDescriptorImp* pSigDesc = dynamic_cast<DataDescriptorImp*>(pDataDesc);
                     mSignatures.push_back(new LibrarySignatureAdapter(*pSigDesc,
                        SessionItemImp::generateUniqueId(), i, pLib));
                     mSignatureNames[name] = mSignatures.back();
                  }
               }
               notify(SIGNAL_NAME(Subject, Modified));
               return true;
            }
         }
      }
   }

   return false;
}