Beispiel #1
0
vector<string> ModelServicesImp::getElementNames(const string& filename, const string& type) const
{
    vector<string> elementNames;

    multimap<Key, DataElement*>::const_iterator iter;
    for (iter = mElements.begin(); iter != mElements.end(); ++iter)
    {
        DataElement* pElement = iter->second;
        if (pElement != NULL)
        {
            string currentFilename = pElement->getFilename();
            string lowerCurrentFilename = StringUtilities::toLower(currentFilename);
            string lowerElementFilename = StringUtilities::toLower(filename);

            if (lowerCurrentFilename == lowerElementFilename)
            {
                if ((type.empty() == true) || (pElement->isKindOf(type) == true))
                {
                    elementNames.push_back(pElement->getName());
                }
            }
        }
    }

    return elementNames;
}
Beispiel #2
0
vector<string> ModelServicesImp::getElementNames(const string& type) const
{
    vector<string> elementNames;

    multimap<Key, DataElement*>::const_iterator iter;
    for (iter = mElements.begin(); iter != mElements.end(); ++iter)
    {
        DataElement* pElement = iter->second;
        if (pElement != NULL)
        {
            if ((type.empty() == true) || (pElement->isKindOf(type) == true))
            {
                elementNames.push_back(pElement->getName());
            }
        }
    }

    return elementNames;
}
Beispiel #3
0
DataElement* LayerListImp::getTopMostElement(const string& elementType) const
{
   if (elementType.empty() == true)
   {
      return NULL;
   }

   for (vector<Layer*>::const_reverse_iterator iter = mLayers.rbegin(); iter != mLayers.rend(); ++iter)
   {
      Layer* pLayer = *iter;
      if ((pLayer != NULL) && (isLayerDisplayed(pLayer) == true))
      {
         DataElement* pElement = pLayer->getDataElement();
         if ((pElement != NULL) && (pElement->isKindOf(elementType) == true))
         {
            return pElement;
         }
      }
   }

   return NULL;
}
Beispiel #4
0
void GetDataElement<T>::populateTreeWidgetItem(QTreeWidgetItem* pRoot)
{
   VERIFYNR(pRoot != NULL);
   QVariant value = pRoot->data(GetSessionItemBase<T>::NameColumn, GetSessionItemBase<T>::SessionItemRole);
   void* pValue = value.value<void*>();
   DataElement* const pRootElement = reinterpret_cast<DataElement*>(pValue);
   const std::vector<DataElement*> elements = Service<ModelServices>()->getElements(pRootElement, std::string());
   for (std::vector<DataElement*>::const_iterator iter = elements.begin(); iter != elements.end(); ++iter)
   {
      DataElement* pChildElement = *iter;
      if (pChildElement == NULL)
      {
         // Disallow NULL elements since that would result in infinite recursion.
         continue;
      }

      std::auto_ptr<QTreeWidgetItem> pChild(new QTreeWidgetItem);
      std::string name = pChildElement->getDisplayName();
      if (name.empty() == true)
      {
         name = pChildElement->getName();
      }

      pChild->setText(GetSessionItemBase<T>::NameColumn, QString::fromStdString(name));
      pChild->setData(GetSessionItemBase<T>::NameColumn,
         GetSessionItemBase<T>::SessionItemRole, QVariant::fromValue<void*>(pChildElement));
      pChild->setText(GetSessionItemBase<T>::TypeColumn, QString::fromStdString(pChildElement->getType()));
      populateTreeWidgetItem(pChild.get());

      const bool isValid = pChildElement->isKindOf(TypeConverter::toString<T>());
      pChild->setFlags(isValid ? Qt::ItemIsEnabled | Qt::ItemIsSelectable : Qt::NoItemFlags);
      if (isValid == true || pChild->childCount() > 0)
      {
         pRoot->addChild(pChild.release());
      }
   }
}
Beispiel #5
0
 DataElement* getDataElement(const char* pName, const char* pType, int create)
 {
    DataElement* pElement = NULL;
    if (pName == NULL || (pType == NULL && create != 0))
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return NULL;
    }
    const std::string name(pName);
    const std::string type(pType == NULL ? std::string() : pType);
    SessionItem* pSessionItem = Service<SessionManager>()->getSessionItem(name);
    if (pSessionItem != NULL)
    {
       pElement = dynamic_cast<DataElement*>(pSessionItem);
       if (pElement == NULL || (!type.empty()  && !pElement->isKindOf(type)))
       {
          pElement = NULL;
          setLastError(SIMPLE_WRONG_TYPE);
          return NULL;
       }
    }
    else
    {
       std::vector<std::string> id = splitIdentifier(name);
       DataElement* pParent = NULL;
       Service<ModelServices> pModel;
       for (size_t idx = 0; idx < id.size(); ++idx)
       {
          DataElement* pTmp = pModel->getElement(id[idx], (idx == id.size() - 1) ? type : std::string(), pParent);
          if (pTmp == NULL)
          {
             std::vector<DataElement*> children =
                pModel->getElements(pParent, (idx == id.size() - 1) ? type : std::string());
             for (std::vector<DataElement*>::iterator child = children.begin(); child != children.end(); ++child)
             {
                if (*child != NULL && (*child)->getDisplayName() == id[idx])
                {
                   pTmp = *child;
                   break;
                }
             }
          }
          if (pTmp == NULL && create != 0 && idx == id.size() - 1)
          {
             // Last component not found and creation has been requested
             if (type == TypeConverter::toString<RasterElement>())
             {
                // Can't use this function to create a RasterElement
                setLastError(SIMPLE_WRONG_TYPE);
                return NULL;
             }
             pTmp = Service<ModelServices>()->createElement(id[idx], type, pParent);
          }
          if ((pParent = pTmp) == NULL)
          {
             break;
          }
       }
       if ((pElement = pParent) == NULL)
       {
          setLastError(SIMPLE_NOT_FOUND);
          return NULL;
       }
    }
    setLastError(SIMPLE_NO_ERROR);
    return pElement;
 }