コード例 #1
0
ファイル: template.cpp プロジェクト: kshji/mapper
bool Template::tryToFindAndReloadTemplateFile(QString map_directory, bool* out_loaded_from_map_dir)
{
	if (!map_directory.isEmpty() && !map_directory.endsWith('/'))
		map_directory.append('/');
	if (out_loaded_from_map_dir)
		*out_loaded_from_map_dir = false;
	
	const QString old_absolute_path = getTemplatePath();
	
	// First try relative path (if this information is available)
	if (!getTemplateRelativePath().isEmpty() && !map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateRelativePath());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
			return true;
	}
	
	// Then try absolute path
	loadTemplateFile(false);
	if (getTemplateState() == Template::Loaded)
		return true;
	
	// Then try the template filename in the map's directory
	if (!map_directory.isEmpty())
	{
		setTemplatePath(map_directory + getTemplateFilename());
		loadTemplateFile(false);
		if (getTemplateState() == Template::Loaded)
		{
			if (out_loaded_from_map_dir)
				*out_loaded_from_map_dir = true;
			return true;
		}
	}
	
	setTemplatePath(old_absolute_path);
	return false;
}
コード例 #2
0
ファイル: NDFileNexus.cpp プロジェクト: dhickin/ADCore
/** Called when asyn clients call pasynOctet->write().
  * Catch parameter changes.  If the user changes the path or name of the template file
  * load the new template file.
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Address of the string to write.
  * \param[in] nChars Number of characters to write.
  * \param[out] nActual Number of characters actually written. */
asynStatus NDFileNexus::writeOctet(asynUser *pasynUser, const char *value,
                                   size_t nChars, size_t *nActual)
{
  int addr=0;
  int function = pasynUser->reason;
  asynStatus status = asynSuccess;
  static const char *functionName = "writeOctet";

  status = getAddress(pasynUser, &addr); if (status != asynSuccess) return(status);
  /* Set the parameter in the parameter library. */
  status = (asynStatus)setStringParam(addr, function, (char *)value);

  if (function == NDFileNexusTemplatePath) {
    loadTemplateFile();
  }
  if (function == NDFileNexusTemplateFile) {
    loadTemplateFile();
  }
  else {
    /* If this parameter belongs to a base class call its method */
    if (function < FIRST_NDFILE_NEXUS_PARAM)
    status = NDPluginFile::writeOctet(pasynUser, value, nChars, nActual);
  }

   /* Do callbacks so higher layers see any changes */
  status = (asynStatus)callParamCallbacks(addr, addr);

  if (status)
    epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
                  "%s:%s: status=%d, function=%d, value=%s",
                  driverName, functionName, status, function, value);
  else
    asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
              "%s:%s: function=%d, value=%s\n",
              driverName, functionName, function, value);
  *nActual = nChars;
  return status;
}
コード例 #3
0
ファイル: template.cpp プロジェクト: kshji/mapper
void Template::switchTemplateFile(const QString& new_path, bool load_file)
{
	if (template_state == Loaded)
	{
		setTemplateAreaDirty();
		unloadTemplateFile();
	}
	
	template_path          = new_path;
	template_file          = QFileInfo(new_path).fileName();
	template_relative_path = QString();
	template_state         = Template::Unloaded;
	
	if (load_file)
		loadTemplateFile(false);
}
コード例 #4
0
ファイル: template.cpp プロジェクト: kshji/mapper
bool Template::configureAndLoad(QWidget* dialog_parent, MapView* view)
{
	bool center_in_view = true;
	
	if (!preLoadConfiguration(dialog_parent))
		return false;
	if (!loadTemplateFile(true))
		return false;
	if (!postLoadConfiguration(dialog_parent, center_in_view))
	{
		unloadTemplateFile();
		return false;
	}
	
	// If the template is not georeferenced, position it at the viewport midpoint
	if (!isTemplateGeoreferenced() && center_in_view)
	{
		auto offset = MapCoord { calculateTemplateBoundingBox().center() };
		setTemplatePosition(view->center() - offset);
	}
	
	return true;
}
コード例 #5
0
void TemplateMap::loadTemplates(const char *proto, const char *filename) {
	loadTemplateFile(proto, filename, false);
}
コード例 #6
0
TemplateMap* TemplateMap::loadTemplates(const char *id, const char *filename, bool onlyInfo) {
	return loadTemplateFile(id, filename, onlyInfo);
}
コード例 #7
0
/** Called when asyn clients call pasynOctet->write().
 * Catch parameter changes.  If the user changes the path or name of the template file
 * load the new template file.
 * \param[in] pasynUser pasynUser structure that encodes the reason and address.
 * \param[in] value Address of the string to write.
 * \param[in] nChars Number of characters to write.
 * \param[out] nActual Number of characters actually written. */
asynStatus NDFileHDF5XML::writeOctet(asynUser *pasynUser, const char *value,
      size_t nChars, size_t *nActual)
{
   int addr = 0;
   int function = pasynUser->reason;
   asynStatus status = asynSuccess;
   const char *functionName = "writeOctet";
char pathstr[512];

   status = getAddress(pasynUser, &addr);
   if (status != asynSuccess)
      return (status);
   /* Set the parameter in the parameter library. */
   status = (asynStatus) setStringParam(addr, function, (char *) value);

   char mesx[256];
   char *mesx2;
   
   getParamName(function, (const char**)&mesx2);
   
     sprintf(longmsg,"NDFileHDF5XML::writeOctet, param=%s, value=%s",mesx2,value);
   lf.log(longmsg);
   
  
    if (function == NDFilePath) {

            int is_makedirs;
            int statx;
            
            getStringParam(NDFilePath, sizeof(pathstr), pathstr);
            getIntegerParam(NDFileHDF5XML_createDirs,&is_makedirs);
            statx = recursePath(pathstr, (bool)is_makedirs);
            printf("HDF5 Recurse path: statis = %d\n",statx);

            if (statx==0)
                setIntegerParam(NDFilePathExists, 1);
            else
                setIntegerParam(NDFilePathExists, 0);


    } 
   
   if (function == NDFileHDF5XML_templatepath)
   {
      loadTemplateFile();
   }
   if (function == NDFileHDF5XML_templatefile)
   {
      loadTemplateFile();
   }
   else
   {
      /* If this parameter belongs to a base class call its method */
      status = NDPluginFile::writeOctet(pasynUser, value, nChars, nActual);
   }

   /* Do callbacks so higher layers see any changes */
   status = (asynStatus) callParamCallbacks(addr, addr);

   if (status)
      epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
            "%s:%s: status=%d, function=%d, value=%s", driverName, functionName,
            status, function, value);
   else
      asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
            "%s:%s: function=%d, value=%s\n", driverName, functionName,
            function, value);
   *nActual = nChars;
   return status;
}
コード例 #8
0
/** This is called to open a TIFF file.
 */
asynStatus NDFileHDF5XML::openFile(const char *fileName,
      NDFileOpenMode_t openMode, NDArray *pArray)
{
   char str0[256];
   char str1[256];
   int fn0, fn1;
   int is_update;
   static const char *functionName = "openFile";
/*   if (lockConfigFile() != asynSuccess)
   {
      return asynError;
   }
*/
   //enable retrig capture strat
   capture_trig = 1;

   
   lf.log("NDFileHDF5XML::openFile");
   
   
   this->openModesave = openMode;

   /* We don't support reading yet */
   if (openMode & NDFileModeRead)
      return (asynError);

   /* We don't support opening an existing file for appending yet */
   if (openMode & NDFileModeAppend)
      return (asynError);

   /* Set the next record in the file to 0 */

   //num_bad_fpgaheads=0;
   this->nextRecord = 0;

#if 0
   getStringParam(NDFileName,255,str0);
   getStringParam(NDFilePath,255,str1);
   getIntegerParam(NDFileNumber,&fn0);
   getIntegerParam(NDFileNumCapture,&fn1);

   // this is a kludge because base class uincs the NDFileNumber for us. we are negating that so
   // we can keep track ourselves here.
   getIntegerParam(NDAutoIncrement,&is_update);
   if (is_update==1 && filenum_kludge==0)
   {
      fn0=fn0-1;
      setIntegerParam(NDFileNumber,fn0);
   }

// keep track of filenumber so if base class messes it up we are not consused...
   //            last_filenumber = fn0;

   if (openMode&NDFileModeMultiple)
   {

      sprintf(hdf_fullname,"%s%s_%05d_%05d.hdf",str1,str0,fn0,fn1);
   }
   else
   {
      sprintf(hdf_fullname,"%s%s_%05d.hdf",str1,str0,fn0);
   }

#endif
   strcpy(hdf_fullname, fileName);

   loadTemplateFile();

   hdf_interface->pArray = pArray;

   hdfSetup->setFileName(hdf_fullname);
   hdfSetup->setLeaveOpen(true);
  //!!  lock();
   if (!configDoc->Accept(hdfSetup)){
      return (asynError);
      is_file_open = false;
   }
   else{
      is_file_open = true;
   }
   //!!unlock();
   hdf5Writer->setFileName(hdf_fullname);
   hdf5Writer->setLeaveOpen(true);
   hdf5Writer->setHDFFilePtr(hdfSetup->getHDFFilePtr());
   hdf5Writer->setHDFAccess(hdf_append);

   hdf5Closer->setFileName(hdf_fullname);
   hdf5Closer->setLeaveOpen(false);
   hdf5Closer->setHDFFilePtr(hdfSetup->getHDFFilePtr());
   hdf5Closer->setHDFAccess(hdf_append);

   setStringParam(NDFullFileName, hdf_fullname);

   return (asynSuccess);
}
コード例 #9
0
QDomElement TrendPw::getWindowXml( VtlWidget * p )
{
  

    Figures * par = dynamic_cast<Figures *>(p);
  
    if ( !par ) {
qDebug ( "Bad class of widget!! %s ", __PRETTY_FUNCTION__ );
      return QDomElement();
    }
  

  if ( !loadTemplateFile() ) {
qDebug ( "template file dont loaded!!! %s", __PRETTY_FUNCTION__ );
    return QDomElement();
  }


  
  QDomElement root_elem = pw_xml_template.documentElement();    

  if (buttonType() == LeftButton )
    root_elem.setAttribute ("popup", "lb");
  else if (buttonType() == RightButton )
    root_elem.setAttribute ("popup", "rb");

  
  QDomNodeList widgets = pw_xml_template.elementsByTagName( "widget" );
  QDomElement wnd_prop_elem = widgets.item(0).firstChild().toElement();  
  
  while ( !wnd_prop_elem.isNull() ) {
  /*  if ( wnd_prop_elem.attribute("name") == "caption" ) {
      wnd_prop_elem.firstChild().firstChild().setNodeValue ( par->toolTip() ) ;
    }
    else*/ if ( wnd_prop_elem.attribute("name") == "geometry" ) {
      int w = wnd_prop_elem.firstChild().firstChild().nextSibling().nextSibling().nodeValue().toInt();
      int h = wnd_prop_elem.firstChild().firstChild().nextSibling().nextSibling().nextSibling().nodeValue().toInt();

      int x = 0, y = 0;
      calculatePwPos( p, w, h, x, y );

      wnd_prop_elem.firstChild().firstChild().nextSibling().setNodeValue( QString::number(x) );
      wnd_prop_elem.firstChild().firstChild().nextSibling().nextSibling().setNodeValue( QString::number(y) );
    } else
    if( wnd_prop_elem.nodeName() == "sourcer" ){
    	wnd_prop_elem.setAttribute("i", p->sourcer()->getIp());
    	wnd_prop_elem.setAttribute("n", p->sourcerName());
    }
        
    wnd_prop_elem = wnd_prop_elem.nextSibling().toElement();
  }
  
  for(int i = 1; i <= widgets.count(); i++){

    if (widgets.item(i).toElement().attribute("class") == "Graph"){
      qDebug("----------------------------------->find widget Graph!!!!!!!!!!!");
      QDomElement wdg_prop_elem = widgets.item(i).firstChild().toElement();

      while( !wdg_prop_elem.isNull() ) {
        if ( wdg_prop_elem.attribute("n") == "GR_LS" ) {
            qDebug()<<"in GR_LS";

            wdg_prop_elem = wdg_prop_elem.firstChild().firstChild().firstChild().toElement();
            while(!wdg_prop_elem.isNull()){

              if ( wdg_prop_elem.attribute("n") == "s_name"){
                wdg_prop_elem.firstChild().firstChild().setNodeValue( par->sourcerName() );
              }
              else if ( wdg_prop_elem.attribute("n") == "color"){
                wdg_prop_elem.firstChild().firstChild().setNodeValue( par->backColor().name() );
              }
                wdg_prop_elem = wdg_prop_elem.nextSibling().toElement();
              }
            }

          wdg_prop_elem = wdg_prop_elem.nextSibling().toElement();
        }
      }


	  if (widgets.item(i).toElement().attribute("class") == "Text"){ /*ok*/

		QDomElement wdg_prop_elem = widgets.item(i).firstChild().toElement();

		while( !wdg_prop_elem.isNull()  ) {
		  if ( wdg_prop_elem.attribute("n") == "TEXT" ) {
		    wdg_prop_elem.firstChild().firstChild().setNodeValue( par->toolTip()  );
		  }
		    wdg_prop_elem = wdg_prop_elem.nextSibling().toElement();
	    }
      }


	  if (widgets.item(i).toElement().attribute("class") == "Figures"){  /*ok*/
		  qDebug("----------------------------------->find widget Figures!!!!!!!!!!!");

		  QDomElement wdg_prop_elem = widgets.item(i).firstChild().toElement();


		    while( !wdg_prop_elem.isNull()  ) {

		      if ( wdg_prop_elem.attribute("n") == "SRC" ) {
		        wdg_prop_elem.firstChild().firstChild().setNodeValue( par->sourcerName() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "TLTP" ) {
		        wdg_prop_elem.firstChild().firstChild().setNodeValue( par->toolTip() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "BCKG_C"){
		    	  wdg_prop_elem.firstChild().firstChild().setNodeValue( par->backColor().name() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "NRM_C"){
		      	  wdg_prop_elem.firstChild().firstChild().setNodeValue( par->normColor().name() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "ATT_C"){
		      	  wdg_prop_elem.firstChild().firstChild().setNodeValue( par->attColor().name() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "CR_C"){
   		      	  wdg_prop_elem.firstChild().firstChild().setNodeValue( par->criColor().name() );
   		      }
		      else if ( wdg_prop_elem.attribute("n") == "PRF"  )  {
		          wdg_prop_elem.firstChild().firstChild().setNodeValue( par->prefix() );
		      }
		      else if ( wdg_prop_elem.attribute("n") == "SFF"  )  {
		          wdg_prop_elem.firstChild().firstChild().setNodeValue( par->suffix() );
		      }

		      wdg_prop_elem = wdg_prop_elem.nextSibling().toElement();
		    }
	  }
  }
  return root_elem;
}
コード例 #10
0
ファイル: main.c プロジェクト: kazu2012/tmpltr-1
int main(int argc, char *argv[]) {
  FILE *inFile = NULL, *outFile = NULL;
  char inBuf[8192];
  char outFileName[PATH_MAX];
  PRIVATE int c = 0, i, ret;

#ifndef DEBUG
  struct rlimit rlim;

  rlim.rlim_cur = rlim.rlim_max = 0;
  setrlimit( RLIMIT_CORE, &rlim );
#endif

  /* setup config */
  config = ( Config_t * )XMALLOC( sizeof( Config_t ) );
  XMEMSET( config, 0, sizeof( Config_t ) );

  /* force mode to forground */
  config->mode = MODE_INTERACTIVE;

  /* store current pid */
  config->cur_pid = getpid();

  /* get real uid and gid in prep for priv drop */
  config->gid = getgid();
  config->uid = getuid();

  while (1) {
    int this_option_optind = optind ? optind : 1;
#ifdef HAVE_GETOPT_LONG
    int option_index = 0;
    static struct option long_options[] = {
      {"chain", no_argument, 0, 'C' },
      {"cluster", no_argument, 0, 'c' },
      {"greedy", no_argument, 0, 'g' },
      {"version", no_argument, 0, 'v' },
      {"debug", required_argument, 0, 'd' },
      {"help", no_argument, 0, 'h' },
      {"cnum", required_argument, 0, 'n' },
      {"templates", required_argument, 0, 't' },
      {"write", required_argument, 0, 'w' },
      {"match", required_argument, 0, 'm' },
      {"matchfile", required_argument, 0, 'M' },
      {"line", required_argument, 0, 'l' },
      {"linefile", required_argument, 0, 'L' },
      {0, no_argument, 0, 0}
    };
    c = getopt_long(argc, argv, "vd:hn:t:w:cCgm:M:l:L:", long_options, &option_index);
#else
    c = getopt( argc, argv, "vd:htn::w:cCgm:M:l:L:" );
#endif

    if (c EQ -1)
      break;

    switch (c) {

    case 'v':
      /* show the version */
      print_version();
      return( EXIT_SUCCESS );

    case 'c':
      /* enable argument clustering */
      config->cluster = TRUE;
      break;

    case 'C':
      /* enable log chaining */
      config->cluster = TRUE;
      config->chain = TRUE;
      break;
      
    case 'd':
      /* show debig info */
      config->debug = atoi( optarg );
      break;

    case 'g':
      /* ignore quotes */
      config->greedy = TRUE;
      break;

    case 'n':
      /* override default cluster count */
      config->clusterDepth = atoi( optarg );
      break;

    case 't':
      /* load template file */
      if ( loadTemplateFile( optarg ) != TRUE ) {
        fprintf( stderr, "ERR - Problem while loading template file\n" );
        return( EXIT_FAILURE );
      }
      break;

    case 'h':
      /* show help info */
      print_help();
      return( EXIT_SUCCESS );

    case 'w':
      /* save templates to file */
      if ( ( config->outFile_st = fopen( optarg, "w" ) ) EQ NULL ) {
	fprintf( stderr, "ERR - Unable to open template file for write [%s]\n", optarg );
	return( EXIT_FAILURE );
      }
      break;

    case 'M':
      /* load match templates from file */
      config->match = loadMatchTemplates( optarg );
      break;

    case 'm':
      /* add template to match list */
      config->match = addMatchTemplate( optarg );
      break;

    case 'L':
      /* load match lines from file and convert to templates */
      config->match = loadMatchLines( optarg );
      break;

    case 'l':
      /* convert match line and add as template */
      config->match = addMatchLine( optarg );
      break;
	
    default:
      fprintf( stderr, "Unknown option code [0%o]\n", c);
    }
  }

  /* override cluster depth */
  if ( ( config->clusterDepth <= 0 ) | ( config->clusterDepth > 10000 ) )
    config->clusterDepth = MAX_ARGS_IN_FIELD;
  
  /* check dirs and files for danger */

  if ( time( &config->current_time ) EQ -1 ) {
    display( LOG_ERR, "Unable to get current time" );

    /* cleanup buffers */
    cleanup();
    return( EXIT_FAILURE );
  }

  /* initialize program wide config options */
  config->hostname = (char *)XMALLOC( MAXHOSTNAMELEN+1 );

  /* get processor hostname */
  if ( gethostname( config->hostname, MAXHOSTNAMELEN ) != 0 ) {
    display( LOG_ERR, "Unable to get hostname" );
    strcpy( config->hostname, "unknown" );
  }

  config->cur_pid = getpid();

  /* setup current time updater */
  signal( SIGALRM, ctime_prog );
  alarm( ALARM_TIMER );

  /*
   * get to work
   */

  /* process all the files */
  while (optind < argc) {
    processFile( argv[optind++] );
  }

  if ( config->match ) {
    /* XXX should print match metrict */
  } else {
    /* print the templates we have found */
    showTemplates();
  }

  /*
   * finished with the work
   */

  cleanup();

  return( EXIT_SUCCESS );
}