Example #1
0
void windowManager::openNewImage() {

  const bool warnToSave = !originalImage_.isNull();
  const QString file = ::getNewImageFileName(activeWindow(), warnToSave);
  if (!file.isEmpty()) {
    const QImage newImage(file);
    if (newImage.isNull()) {
      const QList<QByteArray> formats = QImageWriter::supportedImageFormats();
      QString supportedTypes;
      for (QList<QByteArray>::const_iterator it = formats.begin(),
             end = formats.end(); it != end; ++it) {
        supportedTypes += (*it).data() + QString(", ");
      }
      supportedTypes.chop(2);
      const QString errorString = "Unable to load " + file + ";\nplease make sure " +
        "your image is one of the supported types:\n" + supportedTypes;
      QMessageBox::warning(NULL, "Image load failed", errorString);
      return;
    }
    QFile fileDevice(file);
    fileDevice.open(QIODevice::ReadOnly);
    QByteArray byteArray(fileDevice.readAll());
    const QString imageName = QFileInfo(file).fileName();

    reset(newImage, byteArray, imageName);
    setProjectVersion(programVersion_);
    ::showAndRaise(colorChooser_.window());
    colorChooser_.window()->setNewImage(newImage);
    colorChooser_.window()->setWindowTitle(getWindowTitle());
    startOriginalImageColorCount();
  }
}
Example #2
0
/*******************  FUNCTION  *********************/
CMRCmdOptions::CMRCmdOptions ( int width, int height, int iterations )
{
	//default values
	this->iniDic = NULL;
	this->width = width;
	this->height = height;
	this->iterations = iterations;
	this->dumpUsedDic = NULL;
	
	//setup arg parsor
	setProjectName      ("CartesinMeshRuntime");
	setProjectVersion   ("0.0.0");
	setProjectBugAddress("*****@*****.**");
	setProjectDescr     ("Runtime to quicly build parallel (MPI/Threads) stencil numerical simulations.");
	setProjectArgUsage  ("[-w WIDTH] [-h HEIGHT] [-i ITERATIONS] [-c FILE] [-?]");
	
	//declare options
	declareOption('w', "width"     , "WIDTH"     , "Define the mesh width.");
	declareOption('h', "height"    , "HEIGHT"    , "Define the mesh height.");
	declareOption('i', "iterations", "ITERATIONS", "Define the number of iterations to compute.");
	declareOption('c', "config"    , "FILE"      , "Define the configuration file to load.");
	declareOption('d', "dumpconfig", "FILE"      , "Dump the config in FILE at execution end.");
}
Example #3
0
void windowManager::openProject() {

  //const QString fileString = "test.out";
  const QString fileString =
    QFileDialog::getOpenFileName(activeWindow(), tr("Open project"), ".",
                                 "Cstitch files (*.xst)\nAll files (*.*)");
  if (fileString.isEmpty()) {
    return;
  }

  QFile inFile(fileString);
  inFile.open(QIODevice::ReadOnly);
  // the save file starts with xml text, so read that first
  QTextStream textInStream(&inFile);
  QString inString;
  inString = textInStream.readLine() + "\n";
  // (A day after the initial release I changed the program name from
  // stitch to cstitch, so check for either...)
  QRegExp rx("^<(cstitch|stitch) version=");
  rx.indexIn(inString);
  const QString programName = rx.cap(1);
  if (programName != "cstitch" && programName != "stitch") { // uh oh
    QMessageBox::critical(NULL, tr("Bad project file"),
                          tr("Sorry, ") + fileString +
                          tr(" is not a valid project file ") +
                          tr("(diagnostic: wrong first line)"));
    return;
  }

  int lineCount = 0;
  const int maxLineCount = 100000;
  const QString endTag = "</" + programName + ">";
  QString thisString = "";
  do {
    thisString = textInStream.readLine();
    inString += thisString + "\n";
    ++lineCount;
    if (lineCount > maxLineCount) {
      QMessageBox::critical(NULL, tr("Bad project file"),
                            tr("Sorry, ") + fileString +
                            tr(" appears to be corrupted ") +
                            tr("(diagnostic: bad separator)"));
      return;
    }
  } while (thisString != endTag);

  QDomDocument doc;
  const bool xmlLoadSuccess = doc.setContent(inString);
  if (!xmlLoadSuccess) {
    QMessageBox::critical(NULL, tr("Bad project file"),
                          tr("Sorry, ") + fileString +
                          tr(" appears to be corrupted ") +
                          tr("(diagnostic: parse failed)"));
    return;
  }
  // a blank line between the xml and the image
  inString += textInStream.readLine() + "\n";

  // hide everything except progress meters while we regenerate this project
  hideWindows_ = true;
  hideWindows();

  // how many total images are we restoring?
  int imageCount = 1; // one colorChooser image
  imageCount += doc.elementsByTagName("color_compare_image").size();
  imageCount += doc.elementsByTagName("square_window_image").size();
  imageCount += doc.elementsByTagName("pattern_window_image").size();
  groupProgressDialog progressMeter(imageCount);
  progressMeter.setMinimumDuration(2000);
  progressMeter.setWindowModality(Qt::WindowModal);
  progressMeter.show();
  progressMeter.bumpCount();
  altMeter::setGroupMeter(&progressMeter);

  // read the image file name
  const QString fileName = ::getElementText(doc, "image_name");
  // read the project version number
  setProjectVersion(::getElementAttribute(doc, "cstitch", "version"));
  // now read the binary data image
  inFile.seek(inString.length());
  QDataStream imageStream(&inFile);
  QImage newImage;
  imageStream >> newImage;
  inFile.seek(inString.length());
  QDataStream imageData(&inFile);
  QByteArray imageByteArray;
  imageData >> imageByteArray;
  reset(newImage, imageByteArray, fileName);

  //// colorChooser
  colorChooser_.window()->setNewImage(newImage);
  progressMeter.bumpCount();

  //// colorCompare
  QDomElement colorCompareElement =
    doc.elementsByTagName("color_compare").item(0).toElement();
  if (!colorCompareElement.isNull()) {
    colorChooser* colorChooserObject = colorChooser_.window();
    QDomNodeList compareImagesList(colorCompareElement.
                                   elementsByTagName("color_compare_image"));
    for (int i = 0, size = compareImagesList.size(); i < size; ++i) {
      QDomElement thisCompareElement(compareImagesList.item(i).toElement());
      const int hiddenColorCompareIndex = colorChooserObject->
        recreateImage(colorCompareSaver(thisCompareElement));
      progressMeter.bumpCount();
      //// squareWindow
      colorCompare* colorCompareObject = colorCompareWindow_.window();
      QDomNodeList squareImagesList(thisCompareElement.
                                    elementsByTagName("square_window_image"));
      if (!squareImagesList.isEmpty()) {
        for (int ii = 0, iiSize = squareImagesList.size(); ii < iiSize; ++ii) {
          QDomElement thisSquareElement(squareImagesList.item(ii).toElement());
          const int hiddenSquareImageIndex = colorCompareObject->
            recreateImage(squareWindowSaver(thisSquareElement));
          progressMeter.bumpCount();
          squareWindow* squareWindowObject = squareWindow_.window();
          //// patternWindow
          // restore this square image's children before restoring its history
          // (the children may have their own different histories)
          QDomNodeList
            patternImageList(thisSquareElement.
                             elementsByTagName("pattern_window_image"));
          if (!patternImageList.isEmpty()) {
            for (int iii = 0, iiiSize = patternImageList.size();
                 iii < iiiSize; ++iii) {
              QDomElement thisPatternElement(patternImageList.item(iii).
                                             toElement());
              squareWindowObject->
                recreatePatternImage(patternWindowSaver(thisPatternElement));
              patternWindow_.window()->updateHistory(thisPatternElement);
              progressMeter.bumpCount();
            }
          }
          squareWindowObject->updateImageHistory(thisSquareElement);
          // if this image was only created so that one of its children could be
          // recreated, remove it (its data has already been stored away)
          if (hiddenSquareImageIndex != -1) {
            squareWindowObject->removeImage(hiddenSquareImageIndex);
          }
        }
      }
      // if this image was only created so that one of its children could be
      // recreated, remove it (its data has already been stored away)
      if (hiddenColorCompareIndex != -1) {
        colorCompareObject->removeImage(hiddenColorCompareIndex);
      }
    }
  }

  //// restore window wide settings that are independent of a particular image
  QDomElement windowGlobals(doc.elementsByTagName("global_settings").
                            item(0).toElement());
  if (colorChooserAction_->isEnabled() && colorChooser_.window()) {
    colorChooser_.window()->updateCurrentSettings(windowGlobals);
  }
  if (colorCompareAction_->isEnabled() && colorCompareWindow_.window()) {
    colorCompareWindow_.window()->updateCurrentSettings(windowGlobals);
  }
  if (squareWindowAction_->isEnabled() && squareWindow_.window()) {
    squareWindow_.window()->updateCurrentSettings(windowGlobals);
    squareWindow_.window()->checkAllColorLists();
  }
  if (patternWindowAction_->isEnabled() && patternWindow_.window()) {
    patternWindow_.window()->updateCurrentSettings(windowGlobals);
  }
  // read the image number of colors (before the reset)
  const int colorCount = ::getElementText(doc, "color_count").toInt();
  originalImageColorCount_ = colorCount;
  // call while hideWindows_ (if colorCount wasn't 0 it won't be recalculated)
  startOriginalImageColorCount();
  hideWindows_ = false;
  altMeter::setGroupMeter(NULL);
  projectFilename_ = fileString;
  setWindowTitles(QFileInfo(projectFilename_).fileName());
  setNewWidgetGeometryAndRaise(colorChooser_.window());
}