Exemple #1
0
//=====================================
// main program...
//-------------------------------------
int main(int argc,char*argv[]) {
	//=====================================
	// init variables...
	//-------------------------------------
	bool uniFont    = false;
	bool noBorder   = false;
	bool fastSetup  = false;
	bool withDialog = false;
	bool yastMode   = false;
	bool useHwData  = false;
	bool fullScreen = false;
	bool setInfo    = false;
	bool set3D      = false;
	bool setXIdle   = false;
	bool checkPacs  = false;
	for (int n=0;n<argc;n++) {
	if (strcmp(argv[n],"-style") == 0) {
		globalStyle = (char*) malloc (sizeof(char) * 128);
		sprintf(globalStyle,"%s",argv[n+1]);
		break;
	}
	}

	//=====================================
	// check for root priviliges...
	//-------------------------------------
	if (! accessAllowed()) {
		fprintf (stderr,"xapi: only root can do this\n");
		usage();
	}

	//=====================================
	// start logging...
	//-------------------------------------
	logInit();

	//=====================================
	// allocate main qt object...
	//-------------------------------------
	for (int i=0;i<argc;i++) {
	QString item (argv[i]);
	if ((item == "-h") || (item == "--help")) {
		logExit(); usage(); exit(0);
	}
	}
	QApplication app(argc,argv);

	//=====================================
	// get additional options...
	//-------------------------------------
	QString* idlePID     = NULL;
	QString* cardName3D  = NULL;
	QString* popUpDialog = NULL;
	QString* cardDriver  = NULL;
	while (1) {
	int option_index = 0;
	static struct option long_options[] =
	{
		{"usehwdata"  , 0 , 0 , 'u'},
		{"fullscreen" , 0 , 0 , 'l'},
		{"info"       , 0 , 0 , 'i'},
		{"yast"       , 0 , 0 , 'y'},
		{"checkpacs"  , 0 , 0 , 'c'},
		{"noborder"   , 0 , 0 , 'n'},
		{"3d"         , 1 , 0 , 'D'},
		{"driver"     , 1 , 0 , 'd'},
		{"frameWidth" , 1 , 0 , 'w'},
		{"dialog"     , 1 , 0 , 'O'},
		{"unifont"    , 0 , 0 , 'U'},
		{"xidle"      , 0 , 0 , 'x'},
		{"pid"        , 1 , 0 , 'p'},
		{"fast"       , 0 , 0 , 'f'},
		{"help"       , 0 , 0 , 'h'},
		{0            , 0 , 0 , 0  }
	};
	int c = getopt_long (
		argc, argv, "uicD:fhxlw:d:yp:nUO:",long_options, &option_index
	);
	if (c == -1)
	break;

	switch (c) {
	case 0:
		fprintf (stderr,"xapi: option %s", long_options[option_index].name);
		if (optarg)
		fprintf (stderr," with arg %s", optarg);
		fprintf (stderr,"\n");
	break;

	case 'f':
		fastSetup  = true;
	break;

	case 'U':
		uniFont  = true;
	break;

	case 'O':
		withDialog  = true;
		popUpDialog = new QString (optarg);
	break;

	case 'n':
		noBorder = true;
	break;

	case 'y':
		yastMode = true;
	break;

	case 'w':
		globalFrameWidth = atoi (optarg);
	break;

	case 'u':
		useHwData  = true;
	break;

	case 'l':
		fullScreen = true;
	break;

	case 'i':
		setInfo    = true;
	break;

	case 'c':
		checkPacs  = true;
	break;

	case 'D':
		set3D      = true;
		cardName3D = new QString (optarg);
	break;

	case 'p':
		idlePID    = new QString (optarg);
	break;

	case 'd':
		cardDriver = new QString (optarg);
	break;

	case 'x':
		setXIdle   = true;
	break;

	case 'h':
		logExit(); usage();
	break;
	default:
		logExit(); exit(1);
	}
	}

	//=====================================
	// check if xapi should act as xidle
    //-------------------------------------
	if (setXIdle) {
		XTimeElapsed* idleTimer = new XTimeElapsed ( idlePID );
		app.setMainWidget (idleTimer);
		idleTimer->show();
		return app.exec();
	}

	//=====================================
	// check md5 sum of current config
	//-------------------------------------
	if ((! setInfo) && (! set3D) && (! checkPacs) &&
		(! useHwData) && (! fastSetup)
	) {
	bool createMD5sum = false;
	QFileInfo xc (MD5CONFIG);
	if (xc.exists()) {
		QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG);
		QFile mHandle (MD5CONFIG); 
		if (mHandle.open(IO_ReadOnly)) {
		QString compare;
		mHandle.readLine(compare,MAX_LINE_LENGTH);
		mHandle.close();
		compare = compare.stripWhiteSpace();
		if (compare == mD5Sum) {
			fastSetup = true;
		} else {
			fastSetup = false;
		}
		} 
	} else {
		fastSetup = false;
	}
	if (createMD5sum) {
		QString mD5Sum = qx(MD5,STDOUT,1,"%s",XCONFIG);
		QFile mHandle (MD5CONFIG);
		if (mHandle.open(IO_WriteOnly)) {
			mHandle.writeBlock (mD5Sum.ascii(),mD5Sum.length());
			mHandle.close();
		}
	}
	} 

	//=====================================
	// check option combinations...
	//-------------------------------------
	if (useHwData == true) {
		fastSetup = false;
	}

	//=====================================
	// set root window cursor to the watch
	//-------------------------------------
	setMouseCursor ("watch");

	//=====================================
	// init program...
	//-------------------------------------
	QWidget::WFlags wflags = Qt::WType_TopLevel;
	if (noBorder) {
		wflags |= Qt::WStyle_Customize | Qt::WStyle_NoBorder;
	}
	if (uniFont) {
		QFont currentFont = QFont( "Helvetica", 12 );
		currentFont.setStyleHint( QFont::SansSerif, QFont::PreferBitmap );
		currentFont.setRawName (UNIFONT);
		qApp->setFont (currentFont);
	}
	xapi = new XFrame (
		globalFrameWidth, wflags
	);
	if (setInfo) {
		signal (SIGHUP ,gotKill);
		signal (SIGKILL,gotKill);
		signal (SIGABRT,gotKill);
		signal (SIGTERM,gotKill);
		XInfo infoBox (xapi);
		infoBox.showIntroBox();
		logExit();
		setMouseCursor ();
		exit (
			infoBox.returnCode()
		);
	}
	if (set3D) {
		XInfo infoBox (xapi);
		infoBox.show3DBox (*cardName3D,cardDriver);
		printf("%d\n",infoBox.returnCode());
		logExit();
		setMouseCursor ();
		exit (
			infoBox.returnCode()
		);
	}
	if (fastSetup) {
		xapi->fastSetup  = true;
	}
	if (useHwData) {
		xapi->useHwData  = true;
	}
	if (fullScreen) {
		xapi->fullScreen = true;
	}
	if (yastMode) {
		xapi->yastMode   = true;
	}

	//=====================================
	// check 3D environment
	//-------------------------------------
	XStringList packageInfo ( qx (GET3D,STDOUT) );
	packageInfo.setSeperator (":");
	QString package = packageInfo.getList().at(0);
	QString real3d  = packageInfo.getList().at(1);
	QString soft3d  = packageInfo.getList().at(2);
	QString general = packageInfo.getList().at(3);
	QString active  = packageInfo.getList().at(4);
	QString answer  = packageInfo.getList().at(5);
	QString flag    = packageInfo.getList().at(6);
	global3DActive  = active.toInt();
	QString status1 ("1");
	if (checkPacs) {
		// ...
		// if the 3D Answer was no, there is no need
		// to check for any packages or scripts
		// ---
		if (answer == "no") {
			setMouseCursor (); exit (0);
		}
		// ...
		// install the missing packages using YaST2
		// sw_single mode
		// ---
		if (package != "<none>") {
		if (setMessage("InstallPackage",xapi)) {
		status1 = qx (
			GETINSTALLED,STDOUT,1,"%s",package.ascii()
		);
		}
		}
		setMouseCursor ();
		exit (0);
	}

	//=====================================
	// remove lilo code file...
	//-------------------------------------
	unlink (LILOCODE);

	//=====================================
	// init main frame...
	//-------------------------------------
	if (! xapi->frameInitialized()) {
		xapi->setFrame ();
	}

	//=====================================
	// set signal handler...
	//-------------------------------------
	signal (SIGUSR2,SIG_IGN);
	signal (SIGINT ,gotInterrupted);

	//=====================================
	// init dialogs...
	//-------------------------------------
	XIntro*			intro    = new XIntro();
	XAccessX*		xaccess  = new XAccessX();
	XMouse*			mouse    = new XMouse();
	XCard*			card     = new XCard();
	XDesktop*		desktop  = new XDesktop();
	XDisplayGeometry*	geo  = new XDisplayGeometry();
	XKeyboard*		keyboard = new XKeyboard();
	XLayout*		layout   = new XLayout();
	XMonitor*		monitor  = new XMonitor();
	XMultihead*		multi    = new XMultihead();
	XTablet*		tablet   = new XTablet();
	XTouchScreen*	toucher  = new XTouchScreen();
	XOpenGL*        opengl   = new XOpenGL();
	XVirtual*       virtuals = new XVirtual();
	Xvnc*           vnc      = new Xvnc();

	intro     -> addTo (xapi);
	xaccess   -> addTo (xapi,intro);
	mouse     -> addTo (xapi,intro);
	card      -> addTo (xapi,intro);
	desktop   -> addTo (xapi,intro);
	geo       -> addTo (xapi,intro);
	keyboard  -> addTo (xapi,intro);
	layout    -> addTo (xapi,intro);
	monitor   -> addTo (xapi,intro);
	multi     -> addTo (xapi,intro);
	tablet    -> addTo (xapi,intro);
	toucher   -> addTo (xapi,intro);
	opengl    -> addTo (xapi,intro);
	virtuals  -> addTo (xapi,intro);
	vnc       -> addTo (xapi,intro);

	//=====================================
	// save intro pointer...
	//-------------------------------------
	introPointer = intro;

	//=====================================
	// make sure the serverlayout structure
	// is created at least one time
	//-------------------------------------
	XLayout* layoutDialog;
	layoutDialog = (XLayout*) intro -> retrieve (Layout);
	layoutDialog -> setupLayout();

	//=====================================
	// make sure the card dialog was build
	// in init stage
	//-------------------------------------
	XCard* cardDialog;
	cardDialog = (XCard*) intro -> retrieve (Card);
	cardDialog -> showSetupWindow (false);
	cardDialog -> slotRun (Card);
	cardDialog -> showSetupWindow (true);

	//=====================================
	// call resetPage of the desktop dialog
	// to check for framebuffer usage
	//-------------------------------------
	XDesktop* desktopDialog;
	desktopDialog = (XDesktop*) intro -> retrieve (Colors);
	desktopDialog -> resetPage ( PAGE_RELOAD );

	//=====================================
	// add margin around pushbutton texts 
	// this is only needed for QT3 
	//------------------------------------- 
	#if 1
	QObject* obj;
	QObjectList* l = xapi->queryList( "QPushButton" );
	QObjectListIt it( *l );
	QDict<char>* mText = xapi->getTextPointer();
	while ( (obj=it.current()) != 0 ) {
	++it;
	QPushButton* btn = (QPushButton*) obj;
	QString text = btn->text();
	if (! text.isNull()) {
		QDictIterator<char> n (*mText);
		for (; n.current(); ++n) {
		if (n.current() == text) {
			QString* newText = new QString();
			QTextOStream (newText) << "  " << text << "  ";
			mText->replace (n.currentKey(),*newText);
			break;
		}
		}
		QString addText;
		QTextOStream (&addText) << "  " << text << "  ";
		btn->setText (addText);
	}
	}
	delete l;
	// ...
	// special keys which are used dynamically on widgets
	// with initially other texts
	// ---
	QList<char> keyList;
	keyList.append ( "finish" );
	keyList.append ( "Next" );
	QListIterator<char> io ( keyList );
	for (; io.current(); ++io) {
		QString key ( io.current() );
		QString curText (mText->operator[](key));
		QString* newText = new QString();
		QTextOStream (newText) << "  " << curText << "  ";
		mText->replace (key,*newText);
	}
	#endif

	//=====================================
	// remove xfine cache directory...
	//-------------------------------------
	removeXFineCache();

	//=====================================
    // go to main event loop...
    //-------------------------------------
	app.setMainWidget(xapi);
	xapi -> show();
	xapi -> enterEvent ( 0 );
	xapi -> activateFirstItem();
	setMouseCursor();
	if (! withDialog) {
		intro -> checkDetected();
	} else {
		if ( *popUpDialog == "Monitor" ) {
			xapi -> runDialog (Monitor);
		} else
		if ( *popUpDialog == "Card") {
			xapi -> runDialog (Card);
		} else {
			fprintf (stderr,"xapi: no such dialog: %s\n",popUpDialog->ascii());
			exit (1);
		}
	}
	return app.exec();
}
int DoIt(const char* outFile, const char* regFile, const char* maskFile, const char* resultFile,
          int mask_x, int mask_y, int mask_size_x, int mask_size_y)
{
  // Read maskfile
  FILE *mfp = fopen(maskFile, "r");
//      FILE *mfp=fopen("/project/geoaida/tmp/mask.pbm","r");

  if (!mfp) {
    fprintf(stderr, "mask file %s not found\n", maskFile);
    return 1;
  }
  GaMaskImage mask;
  mask.read(mfp);
  fclose(mfp);

  QList<ArgDict> *regionSourceList=readRegionFile(regFile);
  if (!regionSourceList) return 1;
  QList<ArgDict> regionList;

  // Process regions
  for (ArgDict* arg = regionSourceList->first();
       arg;
       arg=regionSourceList->next()) {
    ArgDict* args=new ArgDict(*arg);
    if (processRegion
	(*args, mask, mask_x, mask_y, mask_size_x, mask_size_y))
      regionList.append(args);
    else
      delete args;
  }
  
  // Write labels
  QFile rfp(outFile ? outFile : regFile);
  if (outFile) {
    if (labelImageDict.count() > 1) {
      fprintf(stderr, "regionmask: Cannot generate multiple labelfiles\n");
      return 1;
    }
    else {
      if (regionList.count()>0) {
        ArgDict *dict = regionList.first();
        QString *oldfile = (*dict)["file"];
        QString *labelfile = new QString();
        if (resultFile)
          labelfile->sprintf("%s", resultFile);
        else
          labelfile->sprintf("%s.plm", outFile);
        LabelImage *im = labelImageDict.take(*oldfile);
        labelImageDict.replace(*labelfile, im);
        QListIterator < ArgDict > it(regionList);
        for (; it.current(); ++it) {
          ArgDict *argDict = it.current();
          assert(argDict);
          argDict->replace("file", labelfile);
        }
      }
    }
  }
  else {
    printf("regionmask: overwriting %s\n",regFile);
    outFile = regFile;
  }
  QDictIterator < LabelImage > git(labelImageDict);
  if (regionList.count()>0) {
    for (; git.current(); ++git) {
      LabelImage *im = git.current();
      qDebug("Writing %s", git.currentKey().latin1());
      im->image.write(git.currentKey().latin1());
    }
  }
  // Write regions
  if (!rfp.open(IO_WriteOnly)) {
    fprintf(stderr, "cannot open regionfile %s for writing\n", outFile);
    return 1;
  }
  if (regionList.count()>0) {
    QListIterator < ArgDict > it(regionList);
    QTextStream ts(&rfp);
    for (; it.current(); ++it) {
      ArgDict *argDict = it.current();
      assert(argDict);
      ts << "<region ";
      ts << (*argDict);
      ts << " />" << endl;
    }
  }
  rfp.close();
  labelImageDict.setAutoDelete(true);
  labelImageDict.clear();
  regionList.setAutoDelete(true);
  return 0;
}
int DoIt(const char* outFile, const char* regFile, const char* maskFile, const char* resultFile,
          int mask_x, int mask_y, int mask_size_x, int mask_size_y)
{
  // Read maskfile
  FILE *mfp = fopen(maskFile, "r");
//      FILE *mfp=fopen("/project/geoaida/tmp/mask.pbm","r");

  if (!mfp) {
    fprintf(stderr, "mask file %s not found\n", maskFile);
    return 1;
  }
  GaMaskImage mask;
  mask.read(mfp);
  fclose(mfp);

  // read regionfile
//  QFile rfp("/project/geoaida/tmp/reglist.dest");
  QFile rfp(regFile);
  if (!rfp.open(IO_ReadOnly)) {
    fprintf(stderr, "regionfile %s not founed\n", regFile);
    return 1;
  }
  // Read and process regions
  QList < ArgDict > regionList;
  regionList.setAutoDelete(true);
  MLParser parser(&rfp);
  QString keywords[] = { "region", "" };
  const MLTagTable nodeTagTable(keywords);
  const int TOK_REGION = 1;
  int tag;
  do {
    tag = parser.tag(nodeTagTable);
    ArgDict *args;
    switch (tag) {
    case TOK_REGION:{
        args = parser.args();
        if (processRegion
            (*args, mask, mask_x, mask_y, mask_size_x, mask_size_y))
          regionList.append(args);
        else
          delete args;
        break;
      }
    case -TOK_REGION:
      break;
    case MLParser::END_OF_FILE:
      break;
    default:{
        args = parser.args();
        delete args;
        qDebug("Unknown keyword %s in line %d", parser.lasttagstr().latin1(),
               parser.lineNumber());
        break;
      }
    }
  } while (tag != MLParser::END_OF_FILE);
  rfp.close();
  // Write labels
  if (outFile) {
    if (labelImageDict.count() > 1) {
      fprintf(stderr, "regionmask: Cannot generate multiple labelfiles\n");
      return 1;
    }
    else {
      if (regionList.count()>0) {
        ArgDict *dict = regionList.first();
        QString *oldfile = (*dict)["file"];
        QString *labelfile = new QString();
        if (resultFile)
          labelfile->sprintf("%s", resultFile);
        else
          labelfile->sprintf("%s.plm", outFile);
        LabelImage *im = labelImageDict.take(*oldfile);
        labelImageDict.replace(*labelfile, im);
        QListIterator < ArgDict > it(regionList);
        for (; it.current(); ++it) {
          ArgDict *argDict = it.current();
          assert(argDict);
          argDict->replace("file", labelfile);
        }
      }
    }
    rfp.setName(outFile);
  }
  else {
    printf("regionmask: overwriting %s\n",regFile);
    outFile = regFile;
  }
  QDictIterator < LabelImage > git(labelImageDict);
  if (regionList.count()>0) {
    for (; git.current(); ++git) {
      LabelImage *im = git.current();
      qDebug("Writing %s", git.currentKey().latin1());
      im->image.write(git.currentKey().latin1());
    }
  }
  // Write regions
  if (!rfp.open(IO_WriteOnly)) {
    fprintf(stderr, "cannot open regionfile %s for writing\n", outFile);
    return 1;
  }
  if (regionList.count()>0) {
    QListIterator < ArgDict > it(regionList);
    QTextStream ts(&rfp);
    for (; it.current(); ++it) {
      ArgDict *argDict = it.current();
      assert(argDict);
      ts << "<region ";
      ts << (*argDict);
      ts << " />" << endl;
    }
  }
  rfp.close();
  labelImageDict.setAutoDelete(true);
  labelImageDict.clear();
  regionList.setAutoDelete(true);
  return 0;
}
Exemple #4
0
Indicator * CUS::calculate ()
{
  Config config;
  QStringList varList;
  QDict<PlotLine> lines;
  lines.setAutoDelete(TRUE);

  checkIncludes();

  Indicator *output = new Indicator;
  output->setDateFlag(dateFlag);
  output->setLogScale(logScale);
  
  int loop;
  for (loop = 0; loop < (int) formulaList.count(); loop++)
  {
    // check if whole line is a comment
    QString s = formulaList[loop].left(2);
    if ( ! s.compare("//"))
      continue;

    if (formulaList[loop].contains(":="))
    {
      QStringList l = QStringList::split(":=", formulaList[loop], FALSE);
      if (l.count() != 2)
      {
        qDebug("CUS::calculate: line %i parm missing", loop);
        return output;
      }
      
      QString var = l[0].stripWhiteSpace();
      if (varList.findIndex(var) != -1)
      {
        qDebug("CUS::calculate: line %i duplicate variable: %s", loop, var.latin1());
        return output;
      }
      varList.append(var);

      QStringList l2 = QStringList::split("(", l[1], FALSE);
      if (l2.count() != 2)
      {
        qDebug("CUS::calculate: line %i bad indicator format", loop);
        return output;
      }
      
      QString plugin = l2[0].stripWhiteSpace();
      QString parms = l2[1];
      parms.truncate(parms.find(")", 0, TRUE));
      parms = parms.stripWhiteSpace();
      while(parms.contains(" "))
        parms = parms.remove(parms.find(" ", 0, TRUE), 1);

      IndicatorPlugin *plug = config.getIndicatorPlugin(plugin);
      if (! plug)
      {
        qDebug("CUS::calculate: %s plugin not loaded", plugin.latin1());
        config.closePlugin(plugin);
        return output;
      }
      plug->setIndicatorInput(data);

      l = QStringList::split(",", parms, FALSE);
      int loop2;
      QPtrList<PlotLine> inList;
      inList.setAutoDelete(FALSE);
      for (loop2 = 0; loop2 < (int) l.count(); loop2++)
      {
        if (varList.findIndex(l[loop2]) != -1)
          inList.append(lines.find(l[loop2]));
        else
        {
          int itype = inputTypeList.findIndex(l[loop2]);
          if (itype != -1)
          {
            PlotLine *in = data->getInput((BarData::InputType) itype);
            if (! in)
            {
              qDebug("CUS::calculate:line%i parm%i: input not found", loop, loop2);
              return output;
            }

            lines.replace(l[loop2], in);
            inList.append(in);
          }
        }
      }

      PlotLine *out = plug->calculateCustom(parms, inList);
      if (! out)
      {
        qDebug("CUS::calculate: line %i: no PlotLine returned: %s", loop, parms.latin1());
        config.closePlugin(plugin);
        return output;
      }

      lines.replace(var, out);
    }

    createPlot(formulaList[loop], lines, output);
  }

  return output;
}