//------------------------------------------------------ int main(int argc, char **argv) { Context *ctx = new Context(); const char *fname = NULL; for(int i=1; i<argc; i++) { if(strcmp(argv[i], "-i") == 0) { ctx->flagShowIR = true; } else if(strcmp(argv[i], "-inline") == 0) { i++; ctx->inlinecount = atoi(argv[i]); } else if(strcmp(argv[i], "-worker") == 0) { i++; int n = atoi(argv[i]); if(n >= 1 && n < 20) { ctx->workers = n; } else { fprintf(stderr, "error\n"); exit(1); } } else { fname = argv[i]; } } ctx->sche->initWorkers(); if(fname != NULL) { runFromFile(ctx, fname); } else { runInteractive(ctx); } delete ctx; return 0; }
int main(int argc, char **argv) { int c; // sFlag is TRUE if script is set, otherwise FALSE. // This means that interactive mode is the default. // NOTE: getopt requires flags to have static storage duration. static int sFlag = FALSE; while (1) { static struct option long_options[] = { {"interactive", no_argument, &sFlag, 0}, {"script", no_argument, &sFlag, 1}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int option_index = 0; // holds the index of the long option found c = getopt_long(argc, argv, "h", long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: // Return value is 0 if getopt_long encounts a flag break; case 'h': printHelpMsg(); return 0; default: printf("Unrecognized option\n"); printHelpMsg(); exit(1); } } if (sFlag) { runScript(); } else { runInteractive(); } return 0; }
int main(int argc, char **argv) { #ifdef CONSOLE_APPLICATION QApplication app(argc, argv, QApplication::Tty); #else QApplication app(argc, argv); #endif #ifdef DO_QWS_DEBUGGING qt_show_painter_debug_output = false; #endif DeviceType type = WidgetType; bool checkers_background = true; QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied; QLocale::setDefault(QLocale::c()); QStringList files; bool interactive = false; bool printdlg = false; bool highres = false; bool show_cmp = false; int width = 800, height = 800; bool verboseMode = false; #ifndef QT_NO_OPENGL QGLFormat f = QGLFormat::defaultFormat(); f.setSampleBuffers(true); f.setStencil(true); f.setAlpha(true); f.setAlphaBufferSize(8); QGLFormat::setDefaultFormat(f); #endif char *arg; for (int i=1; i<argc; ++i) { arg = argv[i]; if (*arg == '-') { QString option = QString(arg + 1).toLower(); if (option == "widget") type = WidgetType; else if (option == "bitmap") type = BitmapType; else if (option == "pixmap") type = PixmapType; else if (option == "image") type = ImageType; else if (option == "imageformat") { Q_ASSERT_X(i + 1 < argc, "main", "-imageformat must be followed by a value"); QString format = QString(argv[++i]).toLower(); imageFormat = QImage::Format_Invalid; static const unsigned int formatCount = sizeof(imageFormats) / sizeof(imageFormats[0]); for (int ff = 0; ff < formatCount; ++ff) { if (QLatin1String(imageFormats[ff].name) == format) { imageFormat = imageFormats[ff].format; break; } } if (imageFormat == QImage::Format_Invalid) { printf("Invalid image format. Available formats are:\n"); for (int ff = 0; ff < formatCount; ++ff) printf("\t%s\n", imageFormats[ff].name); return -1; } } else if (option == "imagemono") type = ImageMonoType; else if (option == "imagewidget") type = ImageWidgetType; #ifndef QT_NO_OPENGL else if (option == "opengl") type = OpenGLType; else if (option == "pbuffer") type = OpenGLPBufferType; #endif #ifdef USE_CUSTOM_DEVICE else if (option == "customdevice") type = CustomDeviceType; else if (option == "customwidget") type = CustomWidgetType; #endif else if (option == "pdf") type = PdfType; else if (option == "ps") type = PsType; else if (option == "picture") type = PictureType; else if (option == "printer") type = PrinterType; else if (option == "highres") { type = PrinterType; highres = true; } else if (option == "printdialog") { type = PrinterType; printdlg = true; } else if (option == "grab") type = GrabType; else if (option == "i") interactive = true; else if (option == "v") verboseMode = true; else if (option == "commands") { displayCommands(); return 0; } else if (option == "w") { Q_ASSERT_X(i + 1 < argc, "main", "-w must be followed by a value"); width = atoi(argv[++i]); } else if (option == "h") { Q_ASSERT_X(i + 1 < argc, "main", "-h must be followed by a value"); height = atoi(argv[++i]); } else if (option == "cmp") { show_cmp = true; } else if (option == "bg-white") { checkers_background = false; } } else { #if defined (Q_WS_WIN) QString input = QString::fromLocal8Bit(argv[i]); if (input.indexOf('*') >= 0) { QFileInfo info(input); QDir dir = info.dir(); QFileInfoList infos = dir.entryInfoList(QStringList(info.fileName())); for (int ii=0; ii<infos.size(); ++ii) files.append(infos.at(ii).absoluteFilePath()); } else { files.append(input); } #else files.append(QString(argv[i])); #endif } } PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); QWidget *activeWidget = 0; if (interactive) { runInteractive(); if (!files.isEmpty()) interactive_widget->load(files.at(0)); } else if (files.isEmpty()) { printHelp(); return 0; } else { for (int j=0; j<files.size(); ++j) { const QString &fileName = files.at(j); QStringList content; QFile file(fileName); QFileInfo fileinfo(file); if (file.open(QIODevice::ReadOnly)) { QTextStream textFile(&file); QString script = textFile.readAll(); content = script.split("\n", QString::SkipEmptyParts); } else { printf("failed to read file: '%s'\n", qPrintable(fileName)); continue; } pcmd.setContents(content); if (show_cmp) { QString pmFile = QString(files.at(j)).replace(".qps", "_qps") + ".png"; qDebug() << pmFile << QFileInfo(pmFile).exists(); QPixmap pixmap(pmFile); if (!pixmap.isNull()) { QLabel *label = createLabel(); label->setWindowTitle("VERIFY: " + pmFile); label->setPixmap(pixmap); label->show(); } } switch (type) { case WidgetType: { OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>; qWidget->setVerboseMode(verboseMode); qWidget->setType(type); qWidget->setCheckersBackground(checkers_background); qWidget->m_filename = files.at(j); qWidget->setWindowTitle(fileinfo.filePath()); qWidget->m_commands = content; qWidget->resize(width, height); qWidget->show(); activeWidget = qWidget; break; } case ImageWidgetType: { OnScreenWidget<QWidget> *qWidget = new OnScreenWidget<QWidget>; qWidget->setVerboseMode(verboseMode); qWidget->setType(type); qWidget->setCheckersBackground(checkers_background); qWidget->m_filename = files.at(j); qWidget->setWindowTitle(fileinfo.filePath()); qWidget->m_commands = content; qWidget->resize(width, height); qWidget->show(); activeWidget = qWidget; break; } #ifndef QT_NO_OPENGL case OpenGLPBufferType: { QGLPixelBuffer pbuffer(QSize(width, height)); QPainter pt(&pbuffer); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image = pbuffer.toImage(); QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case OpenGLType: { OnScreenWidget<QGLWidget> *qGLWidget = new OnScreenWidget<QGLWidget>; qGLWidget->setVerboseMode(verboseMode); qGLWidget->setType(type); qGLWidget->setCheckersBackground(checkers_background); qGLWidget->m_filename = files.at(j); qGLWidget->setWindowTitle(fileinfo.filePath()); qGLWidget->m_commands = content; qGLWidget->resize(width, height); qGLWidget->show(); activeWidget = qGLWidget; break; } #else case OpenGLType: printf("OpenGL type not supported in this Qt build\n"); break; #endif #ifdef USE_CUSTOM_DEVICE case CustomDeviceType: { CustomPaintDevice custom(width, height); QPainter pt; pt.begin(&custom); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage *img = custom.image(); if (img) { QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(*img)); label->resize(label->sizeHint()); label->show(); activeWidget = label; img->save("custom_output_pixmap.png", "PNG"); } else { custom.save("custom_output_pixmap.png", "PNG"); } break; } case CustomWidgetType: { OnScreenWidget<CustomWidget> *cWidget = new OnScreenWidget<CustomWidget>; cWidget->setVerboseMode(verboseMode); cWidget->setType(type); cWidget->setCheckersBackground(checkers_background); cWidget->m_filename = files.at(j); cWidget->setWindowTitle(fileinfo.filePath()); cWidget->m_commands = content; cWidget->resize(width, height); cWidget->show(); activeWidget = cWidget; break; } #endif case PixmapType: { QPixmap pixmap(width, height); pixmap.fill(Qt::white); QPainter pt(&pixmap); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); pixmap.save("output_pixmap.png", "PNG"); break; } case BitmapType: { QBitmap bitmap(width, height); QPainter pt(&bitmap); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); bitmap.save("output_bitmap.png", "PNG"); QLabel *label = createLabel(); label->setPixmap(bitmap); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case ImageMonoType: case ImageType: { qDebug() << "Creating image"; QImage image(width, height, type == ImageMonoType ? QImage::Format_MonoLSB : imageFormat); image.fill(0); QPainter pt(&image); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); image.convertToFormat(QImage::Format_ARGB32).save("output_image.png", "PNG"); #ifndef CONSOLE_APPLICATION QLabel *label = createLabel(); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; #endif break; } case PictureType: { QPicture pic; QPainter pt(&pic); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image(width, height, QImage::Format_ARGB32_Premultiplied); image.fill(0); pt.begin(&image); pt.drawPicture(0, 0, pic); pt.end(); QLabel *label = createLabel(); label->setWindowTitle(fileinfo.absolutePath()); label->setPixmap(QPixmap::fromImage(image)); label->resize(label->sizeHint()); label->show(); activeWidget = label; break; } case PrinterType: { PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); pcmd.setContents(content); QString file = QString(files.at(j)).replace(".", "_") + ".ps"; QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); if (printdlg) { QPrintDialog printDialog(&p, 0); if (printDialog.exec() != QDialog::Accepted) break; } else { p.setOutputFileName(file); } QPainter pt(&p); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); if (!printdlg) { printf("wrote file: %s\n", qPrintable(file)); } Q_ASSERT(!p.paintingActive()); break; } case PsType: case PdfType: { PaintCommands pcmd(QStringList(), 800, 800); pcmd.setVerboseMode(verboseMode); pcmd.setType(type); pcmd.setCheckersBackground(checkers_background); pcmd.setContents(content); bool ps = type == PsType; QPrinter p(highres ? QPrinter::HighResolution : QPrinter::ScreenResolution); QFileInfo input(files.at(j)); QString file = QString("%1_%2.%3") .arg(input.baseName()) .arg(input.suffix()) .arg(ps ? "ps" : "pdf"); p.setOutputFormat(ps ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); p.setOutputFileName(file); p.setPageSize(QPrinter::A4); QPainter pt(&p); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); printf("write file: %s\n", qPrintable(file)); break; } case GrabType: { QImage image(width, height, QImage::Format_ARGB32_Premultiplied); image.fill(QColor(Qt::white).rgb()); QPainter pt(&image); pcmd.setPainter(&pt); pcmd.setFilePath(fileinfo.absolutePath()); pcmd.runCommands(); pt.end(); QImage image1(width, height, QImage::Format_RGB32); image1.fill(QColor(Qt::white).rgb()); QPainter pt1(&image1); pt1.drawImage(QPointF(0, 0), image); pt1.end(); QString filename = QString(files.at(j)).replace(".qps", "_qps") + ".png"; image1.save(filename, "PNG"); printf("%s grabbed to %s\n", qPrintable(files.at(j)), qPrintable(filename)); break; } default: break; } } } #ifndef CONSOLE_APPLICATION if (activeWidget || interactive) { QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); app.exec(); } delete activeWidget; #endif return 0; }
int TargetApp::doProcessing () { if ((op & OP_OBS_START) || (op & OP_OBS_END)) { if (tar_names.size () != 1) { std::cerr << "You must specify only a single observation ID." << std::endl; return -1; } char *endp; long obs_id = strtol (tar_names[0], &endp, 10); if (*endp != '\0') { std::cerr << "You must specify observation ID - this must be number." << std::endl; return -1; } rts2db::Observation obs (obs_id); if (op & OP_OBS_START) obs.startObservation (); if (op & OP_OBS_END) obs.endObservation (OBS_BIT_MOVED | OBS_BIT_STARTED | OBS_BIT_PROCESSED); return 0; } if (tar_names.size () == 0) { std::cerr << "No target specified, exiting." << std::endl; return -1; } try { target_set.load (tar_names, matchAll ? rts2db::resolveAll : rts2db::consoleResolver, true, resType); if (op & OP_DELETE) { for (rts2db::TargetSet::iterator iter = target_set.begin (); iter != target_set.end (); iter++) { if (confirmOp) { std::ostringstream os; os << "Delete " << iter->second->getTargetName () << " (yes/no/all)?"; char ch; askForChr (os.str ().c_str (), ch); if (! (ch == 'y' || ch == 'Y' || ch == 'a' || ch == 'A') ) continue; if (ch == 'a' || ch == 'A') confirmOp = false; } std::cout << "Deleting " << iter->second->getTargetName (); iter->second->deleteTarget (); std::cout << "." << std::endl; } return 0; } if ((op & OP_MASK_EN) == OP_ENABLE) { target_set.setTargetEnabled (true, true); } if ((op & OP_MASK_EN) == OP_DISABLE) { target_set.setTargetEnabled (false, true); } if (op & OP_PRIORITY) { target_set.setTargetPriority (new_priority); } if (op & OP_TEMPDISABLE) { setTempdisable (); } if (op & OP_BONUS) { target_set.setTargetBonus (new_bonus); } if (op & OP_BONUS_TIME) { target_set.setTargetBonusTime (&new_bonus_time); } if (op & OP_NEXT_TIME) { target_set.setNextObservable (&new_next_time); } if (op & OP_SCRIPT) { for (std::list < CamScript >::iterator iter = new_scripts.begin (); iter != new_scripts.end (); iter++) { rts2script::Script script = rts2script::Script (iter->script); script.parseScript (((Rts2Target *) target_set.begin ()->second)); int failedCount = script.getFaultLocation (); if (failedCount != -1) { std::cerr << "PARSING of script '" << iter->script << "' FAILED!!! AT " << failedCount << std::endl << std::string (iter->script).substr (0, failedCount + 1) << std::endl; for (; failedCount > 0; failedCount--) std::cerr << ' '; std::cerr << "^ here" << std::endl; } try { target_set.setTargetScript (iter->cameraName, iter->script); } catch (rts2db::CameraMissingExcetion &ex) { std::cerr << "Missing camera " << iter->cameraName << ". Is it filled in \"cameras\" database table?" << std::endl; } } } if (op & OP_CONSTRAINTS) { try { if (op & OP_CONS_RESET) { target_set.setConstraints (constraints); std::cout << "Set constraints for:" << std::endl << target_set << std::endl; } else { target_set.appendConstraints (constraints); std::cout << "Changed constraints for:" << std::endl << target_set << std::endl; } } catch (rts2core::Error f) { std::cerr << "Cannot write target constraint file: " << f << std::endl; } } if (op & OP_NEXT_OBSER) { target_set.setNextObservable (NULL); } if (op & OP_OBS_SLEW) { if (target_set.size () != 1) { std::cerr << "You must specify only single target which observation will be started." << std::endl; return -1; } rts2db::Target *tar = (target_set.begin ())->second; struct ln_equ_posn pos; tar->startSlew (&pos, true); std::cout << tar->getObsId () << std::endl; return target_set.save (true, true); } if (op & OP_PI_NAME) { target_set.setTargetPIName (pi); } if (op & OP_PROGRAM_NAME) { target_set.setTargetProgramName (program); } if (op & OP_SET_PROPER_MOTION) { target_set.setTargetProperMotion (&pm); } if (op == OP_NONE) { return runInteractive (); } return target_set.save (true, true); } catch (rts2db::UnresolvedTarget ut) { std::cerr << "error: " << ut << std::endl; } catch (rts2db::SqlError e) { std::cerr << e << std::endl; } return -1; }