/**
 * Get the current position of a layer in the layer list.
 *
 * @param[in] [1]
 *            The name of the layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return The 0 based position of the layer in the layer list.
 * @usage idx = get_layer_position("data.tif")
 * @endusage
 */
IDL_VPTR get_layer_position(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
   } KW_RESULT;

   //IDL_KW_FAST_SCAN is the type of scan we are using, following it is the
   //name of the keyword, followed by the type, the mask(which should be 1),
   //flags, a boolean whether the value was populated and finally the value itself
   static IDL_KW_PAR kw_pars[] = {
      IDL_KW_FAST_SCAN,
      {"WINDOW", IDL_TYP_STRING, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(windowName))},
      {NULL}
   };

   IdlFunctions::IdlKwResource<KW_RESULT> kw(argc, pArgv, pArgk, kw_pars, 0, 1);

   std::string windowName;
   std::string name;
   int index = -1;

   if (kw->windowExists)
   {
      windowName = IDL_STRING_STR(&kw->windowName);
   }

   if (argc < 1)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "get_layer_position takes a layer name as a parameter with a "
         "window as an optional keyword to specify a non current window.");
   }
   else
   {
      //layer name passed in as a parameter
      name = IDL_VarGetString(pArgv[0]);
      SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName));
      if (pView != NULL)
      {
         Layer* pLayer = IdlFunctions::getLayerByName(windowName, name, false);
         if (pLayer != NULL)
         {
            index = pView->getLayerDisplayIndex(pLayer);
         }
      }
   }
   return IDL_GettmpInt(index);
}
Exemple #2
0
 uint32_t getLayerDisplayIndex(Layer* pLayer)
 {
    if (pLayer == NULL)
    {
       setLastError(SIMPLE_BAD_PARAMS);
       return 0;
    }
    SpatialDataView* pView = dynamic_cast<SpatialDataView*>(pLayer->getView());
    if (pView == NULL)
    {
       setLastError(SIMPLE_WRONG_VIEW_TYPE);
       return 0;
    }
    setLastError(SIMPLE_NO_ERROR);
    return pView->getLayerDisplayIndex(pLayer);
 }