Exemple #1
0
void Generator::generateContent()
{
    std::cout << "<center>\n\n"
              << "<table id=\"values\">\n";

    std::list<Attribute>::iterator ita;
    for (ita = m_attributes.begin(); ita != m_attributes.end(); ++ita) {
        std::cout << "<tr>\n<td><input type=\"checkbox\" id=\""
                  << ita->getIdentifier() << "Toggled"
                  << "\" onclick=\"toggle('"
                  << ita->getIdentifier() << "Toggled"
                  <<"', '" << ita->getIdentifier()
                  << "')\" " << (attributeEnabled(*ita) ? "checked" : "")
                  << "/></td>\n"
                  << "<td>" << splitIdentifier(ita->getIdentifier()) << "</td>\n"
                  << "<td>" << attributeToHtmlElement(*ita)
                  << "</td>\n</tr>\n";
    }

    std::list<Method>::iterator itm;
    for (itm = m_methods.begin(); itm != m_methods.end(); ++itm) {
        std::list<Method::MethodParam>::iterator itp;
        std::list<Method::MethodParam> params = itm->getParams();
        for (itp = params.begin(); itp != params.end(); ++itp) {
            std::cout << "<tr>\n<td><input type=\"checkbox\" id=\""
                      << itm->getIdentifier() << itp->getIdentifier()
                      << "Toggled\" onclick=\"toggle('"
                      << itm->getIdentifier() << itp->getIdentifier()
                      << "Toggled', '" << itm->getIdentifier()
                      << itp->getIdentifier() << "')\""
                      << (methodEnabled(*itm, *itp) ? " checked" : "")
                      << "/></td>\n<td>" << splitIdentifier(itm->getIdentifier())
                      << " - " << splitIdentifier(itp->getIdentifier()) << "</td>\n"
                      << "<td><input id=\"" << itm->getIdentifier() << itp->getIdentifier()
                      << "\" type=\"" << (itp->getType() == Token::T_BOOLEAN ? "checkbox" : "text")
                      << "\" size=\"30\" " << (methodEnabled(*itm, *itp) ? "" : "disabled ")
                      << "/></td>\n</tr>\n";
        }
    }

    std::cout << "</table>\n\n<br/>\n";

    int i = 1;
    for (itm = m_methods.begin(); itm != m_methods.end(); ++itm, ++i) {
        std::cout << "<input type=\"button\" value=\""
                  << splitIdentifier(itm->getIdentifier())
                  << "\" style=\"min-width: 180px\" onclick=\""
                  << itm->getIdentifier()
                  << "()\"/>\n";
        if (i % 3 == 0 && i != static_cast<int>(m_methods.size()))
            std::cout << "<br/>\n";
    }

    std::cout << "\n</center>\n\n";
}
Exemple #2
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;
 }
Exemple #3
0
 Layer* getLayer(const char* pName, const char* pType)
 {
    Layer* pLayer = NULL;
    const std::string name(pName == NULL ? std::string() : pName);
    const std::string type(pType == NULL ? std::string() : pType);
    SessionItem* pSessionItem = Service<SessionManager>()->getSessionItem(name);
    if (pSessionItem != NULL)
    {
       pLayer = dynamic_cast<Layer*>(pSessionItem);
       if (pLayer == NULL || (!type.empty() && !pLayer->isKindOf(type)))
       {
          setLastError(SIMPLE_WRONG_TYPE);
          return NULL;
       }
    }
    else
    {
       std::vector<std::string> id = splitIdentifier(name);
       SpatialDataView* pView = static_cast<SpatialDataView*>(getView(id.size() == 0 ? NULL : id.front().c_str(),
          TypeConverter::toString<SpatialDataView>()));
       LayerList* pLayerList = (pView == NULL) ? NULL : pView->getLayerList();
       if (pLayerList == NULL)
       {
          setLastError(SIMPLE_NOT_FOUND);
          return NULL;
       }
       if (id.size() < 2)
       {
          if (!type.empty() && type == TypeConverter::toString<RasterLayer>())
          {
             pLayer = pLayerList->getLayer(RASTER, pLayerList->getPrimaryRasterElement());
          }
          else
          {
             pLayer = pView->getActiveLayer();
             if (pLayer != NULL && !type.empty() && !pLayer->isKindOf(type))
             {
                pLayer = NULL;
             }
             if (pLayer == NULL)
             {
                if (type.empty())
                {
                   pLayer = pView->getTopMostLayer();
                }
                else
                {
                   pLayer = pView->getTopMostLayer(StringUtilities::fromDisplayString<LayerType>(type));
                }
             }
          }
       }
       if (pLayer == NULL)
       {
          std::vector<Layer*> layers;
          pLayerList->getLayers(layers);
          for (std::vector<Layer*>::reverse_iterator layer = layers.rbegin();
             layer != layers.rend();
             ++layer)
          {
             if ((type.empty() || (*layer)->isKindOf(type)) && 
                (id.empty() || (*layer)->getName() == id.back() || (*layer)->getDisplayName() == id.back()))
             {
                pLayer = *layer;
                break;
             }
          }
       }
       if (pLayer == NULL)
       {
          setLastError(SIMPLE_NOT_FOUND);
          return NULL;
       }
    }
    setLastError(SIMPLE_NO_ERROR);
    return pLayer;
 }
Exemple #4
0
 View* getView(const char* pName, const char* pType)
 {
    View* pView = NULL;
    const std::string name(pName == NULL ? std::string() : pName);
    const std::string type(pType == NULL ? std::string() : pType);
    SessionItem* pSessionItem = Service<SessionManager>()->getSessionItem(name);
    if (pSessionItem != NULL)
    {
       pView = dynamic_cast<View*>(pSessionItem);
       if (pView == NULL || (!type.empty() && !pView->isKindOf(type)))
       {
          setLastError(SIMPLE_WRONG_TYPE);
          return NULL;
       }
    }
    else
    {
       std::vector<std::string> id = splitIdentifier(name);
       if (id.empty() || id.front().empty())
       {
          pView = Service<DesktopServices>()->getCurrentWorkspaceWindowView();
          if (pView == NULL)
          {
             setLastError(SIMPLE_NOT_FOUND);
             return NULL;
          }
          else
          {
             if (!type.empty() && !pView->isKindOf(type))
             {
                setLastError(SIMPLE_WRONG_TYPE);
                return NULL;
             }
          }
       }
       else
       {
          std::vector<Window*> windows;
          Service<DesktopServices>()->getWindows(windows);
          for (std::vector<Window*>::iterator window = windows.begin(); window != windows.end(); ++window)
          {
             ViewWindow* pTmp = dynamic_cast<ViewWindow*>(*window);
             View* pTmpView = pTmp == NULL ? NULL : pTmp->getView();
             if (pTmpView != NULL && (pTmpView->getName() == id.front() || pTmpView->getDisplayName() == id.front()))
             {
                if (!type.empty() && !pTmpView->isKindOf(type))
                {
                   setLastError(SIMPLE_WRONG_TYPE);
                   return NULL;
                }
                else
                {
                   if (id.size() == 1)
                   {
                      pView = pTmpView;
                   }
                   else
                   {
                      SpatialDataView* pSpatialDataView = dynamic_cast<SpatialDataView*>(pTmpView);
                      if (pSpatialDataView != NULL)
                      {
                         LayerList* pLayerList = pSpatialDataView->getLayerList();
                         if (pLayerList != NULL)
                         {
                            std::vector<Layer*> layers;
                            pLayerList->getLayers(layers);
                            for (std::vector<Layer*>::iterator iter = layers.begin(); iter != layers.end(); ++iter)
                            {
                               Layer* pLayer = *iter;
                               if (pLayer != NULL && 
                                  (pLayer->getName() == id.back() || pLayer->getDisplayName() == id.back()))
                               {
                                  pView = pTmpView;
                                  break;
                               }
                            }
                         }
                      }
                   }
                }
                break;
             }
          }
          if (pView == NULL)
          {
             setLastError(SIMPLE_NOT_FOUND);
             return NULL;
          }
       }
    }
    setLastError(SIMPLE_NO_ERROR);
    return pView;
 }