Exemplo n.º 1
0
bool ImportOPJ::createProjectTree(const OPJFile &opj) {
  const tree<projectNode> *projectTree = opj.project();
  tree<projectNode>::iterator root = projectTree->begin(projectTree->begin());
  if (!root.node)
    return false;
  FolderListItem *item =
      static_cast<FolderListItem *>(mw->folders->firstChild());
  item->setText(0, root->name.c_str());
  item->folder()->setObjectName(root->name.c_str());
  Folder *projectFolder = mw->projectFolder();
  QHash<tree<projectNode>::iterator, Folder *> parent;
  parent[root] = projectFolder;
  for (tree<projectNode>::iterator sib = projectTree->begin(root);
       sib != projectTree->end(root); ++sib) {
    if (sib->type == 1) {
      parent[sib] = mw->addFolder(sib->name.c_str(),
                                  parent.value(projectTree->parent(sib)));
      parent[sib]->setBirthDate(JulianDateTime2String(sib->creation_date));
      parent[sib]->setModificationDate(
          JulianDateTime2String(sib->modification_date));
    } else {
      MdiSubWindow *w = projectFolder->window(sib->name.c_str());
      if (w) {
        parent.value(projectTree->parent(sib))->addWindow(w);
        projectFolder->removeWindow(w);
      }
    }
  }
  mw->changeFolder(projectFolder, true);
  return true;
}
Exemplo n.º 2
0
bool ImportOPJ::importTables(OPJFile opj)
{
    for (int s=0; s<opj.numSpreads(); s++)
    {
        int nr_cols = opj.numCols(s);
        int maxrows = opj.maxRows(s);

        Table *table = mw->newTable(opj.spreadName(s), maxrows, nr_cols);
        if (!table)
            return false;

        for (int j=0; j<nr_cols; j++)
        {
            QString name(opj.colName(s,j));
            table->setColName(j, name.replace(QRegExp(".*_"),""));

            if (QString(opj.colType(s,j)) == "X")
                table->setColPlotDesignation(j, Table::X);
            else if (QString(opj.colType(s,j)) == "Y")
                table->setColPlotDesignation(j, Table::Y);
            else if (QString(opj.colType(s,j)) == "Z")
                table->setColPlotDesignation(j, Table::Z);
            else
                table->setColPlotDesignation(j, Table::None);

            for (int i=0; i<opj.numRows(s,j); i++)
            {
                double val = opj.Data(s,j)[i];
                if(fabs(val) > 2e-300 || val == 0)
                    table->setText(i, j, QString::number(val));
            }
        }
        table->showNormal();
    }
    return true;
}
Exemplo n.º 3
0
bool ImportOPJ::importNotes(const OPJFile &opj) {
  int visible_count = 0;
  for (int n = 0; n < opj.numNotes(); n++) {
    QString name = opj.noteName(n);
    QRegExp rx(R"(^@\((\S+)\)$)");
    if (rx.indexIn(name) == 0)
      name = rx.cap(1);

    Note *note = mw->newNote(name);
    if (!note)
      return false;
    note->setWindowLabel(opj.noteLabel(n));
    note->setText(opj.noteText(n));
    note->setBirthDate(JulianDateTime2String(opj.noteCreationDate(n)));

    // cascade the notes
    int dx = 20;
    int dy = note->frameGeometry().height() - note->height();
    note->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET,
                      visible_count * dy));
    visible_count++;
  }
  if (visible_count > 0)
    xoffset++;
  return true;
}

bool ImportOPJ::importGraphs(const OPJFile &opj) {
  int visible_count = 0;
  int tickTypeMap[] = {0, 3, 1, 2};
  for (int g = 0; g < opj.numGraphs(); ++g) {
    MultiLayer *ml = mw->multilayerPlot(opj.graphName(g), 0, 0, 0);
    if (!ml)
      return false;

    ml->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.graphTitle(g));
    ml->setBirthDate(JulianDateTime2String(opj.graphCreationDate(g)));
    ml->hide(); //! hack used in order to avoid resize and repaint events
    ml->setWindowLabel(opj.graphLabel(g));

    rect graphRect = opj.graphRect(g);
    rect graphWindowRect = opj.graphWindowRect(g);
    ml->resize(graphWindowRect.width() -
                   (ml->frameGeometry().width() - ml->width()),
               graphWindowRect.height() -
                   (ml->frameGeometry().height() - ml->height()));

    double fXScale = (double)ml->width() / (double)graphRect.width();
    double fYScale = (double)ml->height() / (double)graphRect.height();
    fXScale = fYScale = qMin(fXScale, fYScale);

    double fWindowFactor = qMin((double)graphWindowRect.width() / 500.0,
                                (double)graphWindowRect.height() / 350.0);
    double fFontScaleFactor = 0.37 * fWindowFactor;
    double fVectorArrowScaleFactor = 0.08 * fWindowFactor;

    for (int l = 0; l < opj.numLayers(g); ++l) {
      Graph *graph = ml->addLayer();
      if (!graph)
        return false;

      rect layerRect = opj.layerRect(g, l);

      graph->setXAxisTitle(parseOriginText(
          QString::fromLocal8Bit(opj.layerXAxisTitle(g, l).txt.c_str())));
      graph->setYAxisTitle(parseOriginText(
          QString::fromLocal8Bit(opj.layerYAxisTitle(g, l).txt.c_str())));
      LegendWidget *legend = nullptr;
      if (!opj.layerLegend(g, l).txt.empty()) {
        legend = graph->newLegend(parseOriginText(
            QString::fromLocal8Bit(opj.layerLegend(g, l).txt.c_str())));
      }
      int auto_color = 0;
      // int auto_color1=0;
      int style = 0;
      for (int c = 0; c < opj.numCurves(g, l); c++) {
        try {
          QString data(opj.curveDataName(g, l, c));
          int color = 0;
          switch (opj.curveType(g, l, c)) {
          case OPJFile::Line:
            style = GraphOptions::Line;
            break;
          case OPJFile::Scatter:
            style = GraphOptions::Scatter;
            break;
          case OPJFile::LineSymbol:
            style = GraphOptions::LineSymbols;
            break;
          case OPJFile::ErrorBar:
          case OPJFile::XErrorBar:
            style = GraphOptions::ErrorBars;
            break;
          case OPJFile::Column:
            style = GraphOptions::VerticalBars;
            break;
          case OPJFile::Bar:
            style = GraphOptions::HorizontalBars;
            break;
          case OPJFile::Histogram:
            style = GraphOptions::Histogram;
            break;
          case OPJFile::Pie:
            style = GraphOptions::Pie;
            break;
          case OPJFile::Box:
            style = GraphOptions::Box;
            break;
          case OPJFile::FlowVector:
            style = GraphOptions::VectXYXY;
            break;
          case OPJFile::Vector:
            style = GraphOptions::VectXYAM;
            break;
          case OPJFile::Area:
          case OPJFile::AreaStack:
            style = GraphOptions::Area;
            break;
          case OPJFile::TextPlot:
            style = OPJFile::TextPlot;
            break;
          default:
            continue;
          }
          QString tableName;
          QStringList formulas;
          double start, end;
          int s;
          PlotCurve *curve = nullptr;
          switch (data[0].toAscii()) {
          case 'T':
            tableName = data.right(data.length() - 2);
            if (style == GraphOptions::ErrorBars) {
              int flags = opj.curveSymbolType(g, l, c);
              curve = graph->addErrorBars(
                  tableName + "_" + opj.curveXColName(g, l, c),
                  mw->table(tableName),
                  tableName + "_" + opj.curveYColName(g, l, c),
                  ((flags & 0x10) == 0x10 ? 0 : 1),
                  int(ceil(opj.curveLineWidth(g, l, c))),
                  int(ceil(opj.curveSymbolSize(g, l, c))), QColor(Qt::black),
                  (flags & 0x40) == 0x40, (flags & 2) == 2, (flags & 1) == 1);
            } else if (style == GraphOptions::Histogram)
Exemplo n.º 4
0
bool ImportOPJ::importTables(const OPJFile &opj) {
  int visible_count = 0;
  int QtiPlot_scaling_factor = 10; // in Origin width is measured in characters
                                   // while in QtiPlot - pixels --- need to be
                                   // accurate
  for (int s = 0; s < opj.numSpreads(); s++) {
    int nr_cols = opj.numCols(s);
    int maxrows = opj.maxRows(s);
    if (!nr_cols) // remove tables without cols
      continue;

    Table *table =
        (opj.spreadHidden(s) || opj.spreadLoose(s)) && opj.Version() == 7.5
            ? mw->newHiddenTable(opj.spreadName(s), opj.spreadLabel(s), maxrows,
                                 nr_cols)
            : mw->newTable(opj.spreadName(s), maxrows, nr_cols);
    if (!table)
      return false;

    rect windowRect;
    if (opj.Version() == 7.5) {
      windowRect = opj.spreadWindowRect(s);
      table->resize(windowRect.width() -
                        (table->frameGeometry().width() - table->width()),
                    windowRect.height() -
                        (table->frameGeometry().height() - table->height()));
    }

    table->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.spreadTitle(s));
    table->setBirthDate(JulianDateTime2String(opj.spreadCreationDate(s)));

    QLocale locale = mw->locale();
    table->setWindowLabel(opj.spreadLabel(s));
    for (int j = 0; j < nr_cols; j++) {
      QString name(opj.colName(s, j));
      table->setColName(j, name.replace(QRegExp(".*_"), ""));
      table->setCommand(j, QString(opj.colCommand(s, j)));
      table->setColComment(j, QString(opj.colComment(s, j)));
      table->setColumnWidth(j, opj.colWidth(s, j) * QtiPlot_scaling_factor);

      switch (opj.colType(s, j)) {
      case X:
        table->setColPlotDesignation(j, Table::X);
        break;
      case Y:
        table->setColPlotDesignation(j, Table::Y);
        break;
      case Z:
        table->setColPlotDesignation(j, Table::Z);
        break;
      case XErr:
        table->setColPlotDesignation(j, Table::xErr);
        break;
      case YErr:
        table->setColPlotDesignation(j, Table::yErr);
        break;
      case Label:
        table->setColPlotDesignation(j, Table::Label);
        break;
      default:
        table->setColPlotDesignation(j, Table::None);
      }

      table->setHeaderColType(); // update header

      double **d_cells = new double *[nr_cols];
      for (int i = 0; i < nr_cols; ++i)
        d_cells[i] = new double[table->numRows()];

      for (int i = 0; i < opj.numRows(s, j); i++) {
        if (opj.colType(s, j) != Label &&
            opj.colValueType(s, j) != 1) { // number
          double *val = (double *)opj.oData(s, j, i, true);
          if (fabs(*val) > 0 && fabs(*val) < 2.0e-300) // empty entry
            continue;

          table->setText(i, j, locale.toString(*val, 'g', 16));
          d_cells[j][i] = *val;
        } else // label? doesn't seem to work
          table->setText(i, j, QString((char *)opj.oData(s, j, i)));
      }
      table->saveToMemory(d_cells);

      QString format;
      int f = 0;
      switch (opj.colValueType(s, j)) {
      case 0: // Numeric
      case 6: // Text&Numeric
        if (opj.colNumDisplayType(s, j) == 0)
          f = 0;
        else
          switch (opj.colValueTypeSpec(s, j)) {
          case 0: // Decimal 1000
            f = 1;
            break;
          case 1: // Scientific
            f = 2;
            break;
          case 2: // Engeneering
          case 3: // Decimal 1,000
            f = 0;
            break;
          }
        table->setColNumericFormat(f, opj.colDecPlaces(s, j), j);
        break;
      case 1: // Text
        table->setTextFormat(j);
        break;
      case 2: // Date
        switch (opj.colValueTypeSpec(s, j)) {
        case -128:
          format = "dd/MM/yyyy";
          break;
        case -119:
          format = "dd/MM/yyyy HH:mm";
          break;
        case -118:
          format = "dd/MM/yyyy HH:mm:ss";
          break;
        case 0:
        case 9:
        case 10:
          format = "dd.MM.yyyy";
          break;
        case 2:
          format = "MMM d";
          break;
        case 3:
          format = "M/d";
          break;
        case 4:
          format = "d";
          break;
        case 5:
        case 6:
          format = "ddd";
          break;
        case 7:
          format = "yyyy";
          break;
        case 8:
          format = "yy";
          break;
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
          format = "yyMMdd";
          break;
        case 16:
        case 17:
          format = "MMM";
          break;
        case 19:
          format = "M-d-yyyy";
          break;
        default:
          format = "dd.MM.yyyy";
        }
        table->setDateFormat(format, j);
        break;
      case 3: // Time
        switch (opj.colValueTypeSpec(s, j) + 128) {
        case 0:
          format = "hh:mm";
          break;
        case 1:
          format = "hh";
          break;
        case 2:
          format = "hh:mm:ss";
          break;
        case 3:
          format = "hh:mm:ss.zzz";
          break;
        case 4:
          format = "hh ap";
          break;
        case 5:
          format = "hh:mm ap";
          break;
        case 6:
          format = "mm:ss";
          break;
        case 7:
          format = "mm:ss.zzz";
          break;
        case 8:
          format = "hhmm";
          break;
        case 9:
          format = "hhmmss";
          break;
        case 10:
          format = "hh:mm:ss.zzz";
          break;
        }
        table->setTimeFormat(format, j);
        break;
      case 4: // Month
        switch (opj.colValueTypeSpec(s, j)) {
        case 0:
          format = "MMM";
          break;
        case 1:
          format = "MMMM";
          break;
        case 2:
          format = "M";
          break;
        }
        table->setMonthFormat(format, j);
        break;
      case 5: // Day
        switch (opj.colValueTypeSpec(s, j)) {
        case 0:
          format = "ddd";
          break;
        case 1:
          format = "dddd";
          break;
        case 2:
          format = "d";
          break;
        }
        table->setDayFormat(format, j);
        break;
      }
      table->freeMemory();
    }

    if (!(opj.spreadHidden(s) || opj.spreadLoose(s)) || opj.Version() != 7.5) {
      switch (opj.spreadState(s)) {
      case originWindow::Minimized:
        mw->minimizeWindow(table);
        break;
      case originWindow::Maximized:
        mw->maximizeWindow(table);
        break;
      default:
        table->showNormal();
      }

      // cascade the tables
      if (opj.Version() == 7.5) {
        table->move(QPoint(windowRect.left, windowRect.top));
      } else {
        int dx = table->verticalHeaderWidth();
        int dy = table->frameGeometry().height() - table->height();
        table->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET,
                           visible_count * dy));
        visible_count++;
      }
    }
  }

  // Import matrices
  for (int s = 0; s < opj.numMatrices(); s++) {
    int nr_cols = opj.numMatrixCols(s);
    int nr_rows = opj.numMatrixRows(s);

    Matrix *matrix = mw->newMatrix(opj.matrixName(s), nr_rows, nr_cols);
    if (!matrix)
      return false;

    rect windowRect;
    if (opj.Version() == 7.5) {
      windowRect = opj.matrixWindowRect(s);
      matrix->resize(windowRect.width() -
                         (matrix->frameGeometry().width() - matrix->width()),
                     windowRect.height() -
                         (matrix->frameGeometry().height() - matrix->height()));
    }

    matrix->setCaptionPolicy((MdiSubWindow::CaptionPolicy)opj.matrixTitle(s));
    matrix->setBirthDate(JulianDateTime2String(opj.matrixCreationDate(s)));

    matrix->setWindowLabel(opj.matrixLabel(s));
    matrix->setFormula(opj.matrixFormula(s));
    matrix->setColumnsWidth(opj.matrixWidth(s) * QtiPlot_scaling_factor);
    if (opj.matrixViewType(s) == matrix::ImageView)
      matrix->setViewType(Matrix::ImageView);
    if (opj.matrixHeaderViewType(s) == matrix::XY)
      matrix->setHeaderViewType(Matrix::XY);
    vector<double> data = opj.matrixData(s);
    double *matrix_data = matrix->matrixModel()->dataVector();
    int size = matrix->numRows() * matrix->numCols();
    int cell = 0;
    for (int i = 0; i < size; i++) {
      double val = data[cell];
      if (val < 2.0e-300)
        val = GSL_NAN;
      matrix_data[cell] = val;
      cell++;
    }

    QChar format;
    switch (opj.matrixValueTypeSpec(s)) {
    case 0: // Decimal 1000
      format = 'f';
      break;
    case 1: // Scientific
      format = 'e';
      break;
    case 2: // Engeneering
    case 3: // Decimal 1,000
      format = 'g';
      break;
    }
    matrix->setNumericFormat(format, opj.matrixSignificantDigits(s));

    if (!opj.matrixHidden(s) || opj.Version() != 7.5) {
      switch (opj.matrixState(s)) {
      case originWindow::Minimized:
        mw->minimizeWindow(matrix);
        break;
      case originWindow::Maximized:
        mw->maximizeWindow(matrix);
        break;
      default:
        matrix->showNormal();
      }

      // cascade the matrices
      if (opj.Version() == 7.5)
        matrix->move(QPoint(windowRect.left, windowRect.top));
      else {
        int dx = matrix->verticalHeaderWidth();
        int dy = matrix->frameGeometry().height() - matrix->height();
        matrix->move(QPoint(visible_count * dx + xoffset * OBJECTXOFFSET,
                            visible_count * dy));
        visible_count++;
      }
    }
  }

  if (visible_count > 0)
    xoffset++;
  return true;
}