Пример #1
0
/**
 * Hide a layer.
 *
 * @param[in] [1]
 *            The name of the layer to hide.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @rsof
 * @usage print,hide_layer("raster.tif")
 * @endusage
 */
IDL_VPTR hide_layer(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   IDL_VPTR idlPtr;
   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 layerName;

   if (kw->windowExists)
   {
      windowName = IDL_STRING_STR(&kw->windowName);
   }
   bool bSuccess = false;
   if (argc < 1)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "function takes a layer name as a parameter with "
         "'window' as an optional keyword.");
      return IDL_StrToSTRING("failure");
   }
   //the layer name as a parameter
   layerName = IDL_VarGetString(pArgv[0]);
   SpatialDataView* pView = dynamic_cast<SpatialDataView*>(IdlFunctions::getViewByWindowName(windowName));
   if (pView != NULL)
   {
      Layer* pLayer = IdlFunctions::getLayerByName(windowName, layerName, false);
      if (pLayer != NULL)
      {
         pView->hideLayer(pLayer);
         bSuccess = true;
      }
   }
   if (bSuccess)
   {
      idlPtr = IDL_StrToSTRING("success");
   }
   else
   {
      idlPtr = IDL_StrToSTRING("failure");
   }
   return idlPtr;
}
Пример #2
0
/**
 * Get the name of the layer in a given position in the layer list.
 *
 * @param[in] INDEX @opt
 *            The 0 based index of the layer. Defaults to the top most layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return The name of the layer.
 * @usage print,get_layer_name(2, WINDOW="Window 1")
 * @endusage
 */
IDL_VPTR get_layer_name(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
      int indexExists;
      IDL_LONG index;
   } 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,
      {"INDEX", IDL_TYP_LONG, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(indexExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(index))},
      {"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;
   int index = -1;
   std::string name;

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

   if (argc < 0)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "Invalid arguments");
      return IDL_StrToSTRING("");
   }
   Layer* pLayer = IdlFunctions::getLayerByIndex(windowName, index);
   if (pLayer != NULL)
   {
      name =  pLayer->getName();
   }
   return IDL_StrToSTRING(const_cast<char*>(name.c_str()));
}
Пример #3
0
static IDL_VPTR IDL_CDECL IDL_mg_tout_pop(int argc, IDL_VPTR *argv) {
  char *output;
  IDL_VPTR result;

  IDL_ToutPop();

  if (outf_buffer_size == 0) {
    fclose(outf_fp);
    return IDL_GettmpLong(-1);
  } else {
    output = (char *) malloc(outf_buffer_loc);
    strncpy(output, outf_buffer, outf_buffer_loc);
    output[outf_buffer_loc - 1] = '\0';

    free(outf_buffer);
    outf_buffer_loc = 0;
    outf_buffer_size = 0;

    result = IDL_StrToSTRING(output);

    free(output);

    return(result);
  }
}
Пример #4
0
/*
  name = MG_NET_HOST2NAME([host])

  Converts the unsigned long host value into an string hostname. If [host]
  is not specified, the local hostname is returned.
*/
static IDL_VPTR IDL_CDECL mg_net_host2name(int argc, IDL_VPTR argv[], char *argk) {
  struct in_addr addr;
  struct hostent *hp;
  char host_name[256];

  if (argc == 0) {
    if (gethostname(host_name, 256) == -1) {
      host_name[0] = '\0';
    }
    return (IDL_StrToSTRING(host_name));
  } else {
    addr.s_addr = IDL_ULongScalar(argv[0]);
    hp = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
    if (!hp) return (IDL_StrToSTRING(""));
  }
  return (IDL_StrToSTRING(hp->h_name));
}
Пример #5
0
// char *IDL_TypeNameFunc(int type)
static IDL_VPTR IDL_CDECL IDL_IDL_TypeNameFunc(int argc, IDL_VPTR *argv, char *argk) {
  char *result;
  IDL_ENSURE_SIMPLE(argv[0]);
  IDL_ENSURE_SCALAR(argv[0])
  MG_ENSURE_TYPE(argv[0], IDL_TYP_LONG, "int type")
  result = (char *) IDL_TypeNameFunc(argv[0]->value.l);   // int type
  return IDL_StrToSTRING(result);
}
Пример #6
0
/*
  err = MG_NET_RECVVAR(socket, variable)

  Reads an IDL variable from the socket in the form written by MG_NET_SENDVAR.
  The complete variable is reconstructed. See MG_NET_SENDVAR for more details.
 */
static IDL_VPTR IDL_CDECL mg_net_recvvar(int argc, IDL_VPTR argv[], char *argk) {
  IDL_LONG i, iRet;
  IDL_LONG swab = 0;
  i_var var;
  IDL_VPTR vpTmp;
  char *pbuffer;

  i = IDL_LongScalar(argv[0]);
  if ((i < 0) || (i >= MAX_SOCKETS)) return (IDL_GettmpLong(-1));
  if (net_list[i].iState != NET_IO) return (IDL_GettmpLong(-1));
  IDL_EXCLUDE_EXPR(argv[1]);

  /* read the header */
  iRet = recv_packet(net_list[i].socket, &var,sizeof(i_var));
  if (iRet == -1) return (IDL_GettmpLong(-1));
  if (var.token == SWAPTOKEN) {
    mg_byteswap(&var, sizeof(i_var), sizeof(IDL_LONG));
    swab = 1;
  }
  if (var.token != TOKEN) return (IDL_GettmpLong(-1));

  /* allocate the variable */
  if (var.type == IDL_TYP_STRING) {
    vpTmp = IDL_StrToSTRING("");
    IDL_StrEnsureLength(&(vpTmp->value.str), var.len);
    vpTmp->value.str.slen = var.len - 1;
    pbuffer = vpTmp->value.str.s;
    memset(pbuffer, 0x20, var.len-1);
    pbuffer[var.len] = '\0';
    IDL_VarCopy(vpTmp, argv[1]);
  } else if (var.ndims != 0) {
    pbuffer = IDL_MakeTempArray(var.type, var.ndims, var.dims, IDL_BARR_INI_NOP, &vpTmp);
    IDL_VarCopy(vpTmp, argv[1]);
  } else {
    vpTmp = IDL_GettmpLong(0);
    IDL_VarCopy(vpTmp, argv[1]);
    IDL_StoreScalarZero(argv[1], var.type);
    pbuffer = &(argv[1]->value.c);
  }

  /* read the data */
  iRet = recv_packet(net_list[i].socket, pbuffer, var.len);
  if (iRet == -1) return (IDL_GettmpLong(-1));
  if (swab) {
    int	swapsize = var.len / var.nelts;
    if ((var.type == IDL_TYP_COMPLEX)
	|| (var.type == IDL_TYP_DCOMPLEX)) {
      swapsize /= 2;
    }
    mg_byteswap(pbuffer, var.len, swapsize);
  }

  return (IDL_GettmpLong(1));
}
Пример #7
0
static void IDL_CDECL IDL_mg_print(int argc, IDL_VPTR *argv, char *argk) {
  int nargs;
  char *format, *cformat;
  IDL_VPTR origFormat, vcformat;

  typedef struct {
    IDL_KW_RESULT_FIRST_FIELD;
    IDL_VPTR format;
    int format_present;
  } KW_RESULT;

  static IDL_KW_PAR kw_pars[] = {
    { "FORMAT", IDL_TYP_STRING, 1, IDL_KW_VIN,
      IDL_KW_OFFSETOF(format_present), IDL_KW_OFFSETOF(format) },
    { NULL }
  };

  KW_RESULT kw;

  nargs = IDL_KWProcessByOffset(argc, argv, argk, kw_pars, NULL, 1, &kw);

  if (kw.format_present) {
    origFormat = argv[argc - 1];
    format = IDL_VarGetString(origFormat);
    cformat = (char *) calloc(strlen(format) + 5 + 1, sizeof(char));
    sprintf(cformat, "(%%\"%s\")", format);
    vcformat = IDL_StrToSTRING(cformat);
    argv[argc - 1] = vcformat;
  }

  IDL_Print(argc, argv, argk);

  if (kw.format_present) {
    argv[argc - 1] = origFormat;
    IDL_Deltmp(vcformat);
    free(cformat);
  }

  IDL_KW_FREE;
}
Пример #8
0
/**
 * Get the name of the current data element or window.
 *
 * @param[in] DATASET @opt
 *            This flag gets the primary data element name of the currently active window.
 *            This is the default.
 * @param[in] FILE @opt
 *            This flag gets the currently active window's primary data element's file name.
 * @param[in] WINDOW @opt
 *            This flag gets the name of the currently active window.
 * @return The name of the element.
 * @usage print,get_current_name(/FILE)
 * @endusage
 */
IDL_VPTR get_current_name(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int datasetExists;
      IDL_LONG dataset;
      int fileExists;
      IDL_LONG file;
      int windowExists;
      IDL_LONG window;
   } 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,
      {"DATASET", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(datasetExists)),
            reinterpret_cast<char*>(IDL_KW_OFFSETOF(dataset))},
      {"FILE", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(fileExists)),
            reinterpret_cast<char*>(IDL_KW_OFFSETOF(file))},
      {"WINDOW", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(windowExists)),
            reinterpret_cast<char*>(IDL_KW_OFFSETOF(window))},
      {NULL}
   };

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

   std::string filename;
   std::string wizardName;
   int file = 0;
   int dataset = 0;
   int window = 0;

   if (kw->datasetExists)
   {
      if (kw->dataset != 0)
      {
         dataset = 1;
      }
   }
   else if (kw->fileExists)
   {
      if (kw->file != 0)
      {
         file = 1;
      }
   }
   else if (kw->windowExists)
   {
      if (kw->window != 0)
      {
         window = 1;
      }
   }
   else
   {
      dataset = 1;
   }

   RasterElement* pElement = IdlFunctions::getDataset("");
   if (pElement == NULL)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "Opticks was unable to determine the current in memory dataset.");
      return IDL_StrToSTRING("");
   }
   std::string name;
   if (dataset != 0)
   {
      // get the name of the RasterElement if dataset
      name = pElement->getName();
   }
   else if (file)
   {
      // get the filename associated with the RasterElement
      name = pElement->getFilename();
   }
   else
   {
      // get the window name
      Service<DesktopServices>()->getCurrentWorkspaceWindowName(name);
   }
   return IDL_StrToSTRING(const_cast<char*>(name.c_str()));
}
Пример #9
0
/**
 * Get the names of all the data elements which are children of the primary raster element.
 *
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @return An array of data element names or the string "failure" if an error occurred.
 * @usage names = get_data_element_names()
 * @endusage
 */
IDL_VPTR get_data_element_names(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;
   bool bSuccess = false;
   IDL_VPTR idlPtr;
   unsigned int total = 0;
   IDL_STRING* pStrarr = NULL;

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

   SpatialDataWindow* pWindow = NULL;
   if (windowName.empty())
   {
      pWindow = dynamic_cast<SpatialDataWindow*>(Service<DesktopServices>()->getCurrentWorkspaceWindow());
   }
   else
   {
      pWindow = dynamic_cast<SpatialDataWindow*>(
         Service<DesktopServices>()->getWindow(windowName, SPATIAL_DATA_WINDOW));
   }
   if (pWindow != NULL)
   {
      SpatialDataView* pView = pWindow->getSpatialDataView();
      if (pView != NULL)
      {
         LayerList* pList = pView->getLayerList();
         if (pList != NULL)
         {
            RasterElement* pElement = pList->getPrimaryRasterElement();
            if (pElement != NULL)
            {
               std::vector<std::string> names = Service<ModelServices>()->getElementNames(pElement, "");
               total = names.size();
               if (total > 0)
               {
                  pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total * sizeof(IDL_STRING)));
                  for (unsigned int i=0; i < total; ++i)
                  {
                     IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str()));
                  }
                  bSuccess = true;
               }
            }
         }
      }
   }
   else if (windowName == "all")
   {
      std::vector<std::string> names = Service<ModelServices>()->getElementNames("RasterElement");
      total = names.size();
      if (total > 0)
      {
         pStrarr = reinterpret_cast<IDL_STRING*>(malloc(total* sizeof(IDL_STRING)));
         for (unsigned int i=0; i < total; ++i)
         {
            IDL_StrStore(&(pStrarr[i]), const_cast<char*>(names[i].c_str()));
         }
         bSuccess = true;
      }
   }
   if (!bSuccess)
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "No elements matched.");
      return IDL_StrToSTRING("failure");
   }
   IDL_MEMINT dims[] = {total};
   idlPtr = IDL_ImportArray(1, dims, IDL_TYP_STRING, reinterpret_cast<UCHAR*>(pStrarr),
      reinterpret_cast<IDL_ARRAY_FREE_CB>(free), NULL);
   return idlPtr;
}
Пример #10
0
/**
 * Get the data element name of a specified layer.
 *
 * @param[in] [1] @opt
 *            The name of the layer. Defaults to the top most layer.
 * @param[in] WINDOW @opt
 *            The name of the window. Defaults to the active window.
 * @param[in] DATASET @opt
 *            If \p [1] is not specified and this flag it set, get the
 *            data set name of the top most raster layer.
 * @return The name of the data element.
 * @usage print,get_data_name(/DATASET)
 * @endusage
 */
IDL_VPTR get_data_name(int argc, IDL_VPTR pArgv[], char* pArgk)
{
   typedef struct
   {
      IDL_KW_RESULT_FIRST_FIELD;
      int windowExists;
      IDL_STRING windowName;
      int datasetExists;
      IDL_LONG dataset;
   } 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,
      {"DATASET", IDL_TYP_INT, 1, 0, reinterpret_cast<int*>(IDL_KW_OFFSETOF(datasetExists)),
         reinterpret_cast<char*>(IDL_KW_OFFSETOF(dataset))},
      {"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 layerName;
   std::string name;

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

   //retrieve the layer name passed in as a parameter
   if (argc >= 1)
   {
      layerName = IDL_VarGetString(pArgv[0]);
   }
   //get the layer
   bool datasets = false;
   if (kw->datasetExists)
   {
      if (kw->dataset != 0)
      {
         datasets = true;
      }
   }
   Layer* pLayer = IdlFunctions::getLayerByName(windowName, layerName, datasets);
   if (pLayer != NULL)
   {
      //get the spectral element of the layer and return its name
      DataElement* pElement = pLayer->getDataElement();
      if (pElement != NULL)
      {
         name = pElement->getName();
      }
   }
   else
   {
      IDL_Message(IDL_M_GENERIC, IDL_MSG_RET, "the layer name passed into get_data_name "
         "was invalid.");
      return IDL_StrToSTRING("");
   }

   return IDL_StrToSTRING(const_cast<char*>(name.c_str()));
}
Пример #11
0
// const char *mysql_info(MYSQL *mysql)
static IDL_VPTR IDL_mg_mysql_info(int argc, IDL_VPTR *argv) {
    const char *info = mysql_info((MYSQL *)argv[0]->value.ptrint);
    return IDL_StrToSTRING(info);
}
Пример #12
0
// const char * STDCALL mysql_get_client_info(void);
static IDL_VPTR IDL_mg_mysql_get_client_info(int argc, IDL_VPTR *argv) {
    const char *info = mysql_get_client_info();
    return IDL_StrToSTRING(info);
}
Пример #13
0
// not part of mysql.h, but needed to access the C fields
// typedef char **MYSQL_ROW;
static IDL_VPTR IDL_mg_mysql_get_field(int argc, IDL_VPTR *argv) {
    MYSQL_ROW row = (MYSQL_ROW) argv[0]->value.ptrint;
    IDL_ULONG field_index = IDL_ULongScalar(argv[1]);
    char *field = row[field_index];
    return IDL_StrToSTRING(field);
}
Пример #14
0
// const char * STDCALL mysql_error(MYSQL *mysql);
static IDL_VPTR IDL_mg_mysql_error(int argc, IDL_VPTR *argv) {
    const char *msg = mysql_error((MYSQL *)argv[0]->value.ptrint);
    return IDL_StrToSTRING(msg);
}
Пример #15
0
static IDL_VPTR IDL_CDECL IDL_mg_zlib_version(int argc, IDL_VPTR *argv) {
  return(IDL_StrToSTRING(ZLIB_VERSION));
}