Logo Search packages:      
Sourcecode: scidavis version File versions  Download package

bool ImportOPJ::importGraphs ( OPJFile  opj  ) 

hack used in order to avoid resize and repaint events

Definition at line 431 of file importOPJ.cpp.

References CurveLayout::aCol, Graph::addErrorBars(), Graph::addFunctionCurve(), MultiLayer::addLayer(), MultiLayer::arrangeLayers(), CurveLayout::aStyle, ApplicationWindow::autoResizeLayers, ApplicationWindow::autoScaleFonts, ColorBox::color(), Graph::curve(), Grid::enableZeroLineX(), Grid::enableZeroLineY(), CurveLayout::fillCol, CurveLayout::filledArea, Graph::grid(), ApplicationWindow::hideWindow(), Graph::initCurveLayout(), Graph::insertCurve(), CurveLayout::lCol, QwtHistogram::loadData(), CurveLayout::lStyle, CurveLayout::lWidth, ApplicationWindow::multilayerPlot(), Graph::newLegend(), CurveLayout::penWidth, Graph::setAutoscaleFonts(), QwtHistogram::setBinning(), Graph::setCurveStyle(), QwtBarCurve::setGap(), Graph::setIgnoreResizeEvents(), Grid::setMajPenX(), Grid::setMajPenY(), Grid::setMinPenX(), Grid::setMinPenY(), Graph::setScale(), MyWidget::setWindowLabel(), Graph::setXAxisTitle(), Graph::setYAxisTitle(), Graph::showAxis(), CurveLayout::sSize, CurveLayout::sType, CurveLayout::symCol, ApplicationWindow::table(), Graph::updateCurveLayout(), and ApplicationWindow::updateFunctionLists().

{
      double pi=3.141592653589793;
      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));
            if (!ml)
                  return false;

            ml->hide();//!hack used in order to avoid resize and repaint events
            ml->setWindowLabel(opj.graphLabel(g));
            for(int l=0; l<opj.numLayers(g); l++)
            {
                  Graph *graph=ml->addLayer();
                  if(!graph)
                        return false;

                  graph->setXAxisTitle(parseOriginText(QString::fromLocal8Bit(opj.layerXAxisTitle(g,l))));
                  graph->setYAxisTitle(parseOriginText(QString::fromLocal8Bit(opj.layerYAxisTitle(g,l))));
                  if(strlen(opj.layerLegend(g,l))>0)
                        graph->newLegend(parseOriginText(QString::fromLocal8Bit(opj.layerLegend(g,l))));
                  int auto_color=0;
                  int auto_color1=0;
                  int style=0;
                  for(int c=0; c<opj.numCurves(g,l); c++)
                  {
                        QString data(opj.curveDataName(g,l,c));
                        int color=0;
                        switch(opj.curveType(g,l,c))
                        {
                        case OPJFile::Line:
                              style=Graph::Line;
                              break;
                        case OPJFile::Scatter:
                              style=Graph::Scatter;
                              break;
                        case OPJFile::LineSymbol:
                              style=Graph::LineSymbols;
                              break;
                        case OPJFile::ErrorBar:
                        case OPJFile::XErrorBar:
                              style=Graph::ErrorBars;
                              break;
                        case OPJFile::Column:
                              style=Graph::VerticalBars;
                              break;
                        case OPJFile::Bar:
                              style=Graph::HorizontalBars;
                              break;
                        case OPJFile::Histogram:
                              style=Graph::Histogram;
                              break;
                        default:
                              continue;
                        }
                        QString tableName;
                        switch(data[0].toAscii())
                        {
                        case 'T':
                              tableName = data.right(data.length()-2);
                              if(style==Graph::ErrorBars)
                              {
                                    int flags=opj.curveSymbolType(g,l,c);
                                    graph->addErrorBars(tableName + "_" + opj.curveXColName(g,l,c), mw->table(tableName), tableName + "_" + opj.curveYColName(g,l,c),
                                          ((flags&0x10)==0x10?0:1), ceil(opj.curveLineWidth(g,l,c)), ceil(opj.curveSymbolSize(g,l,c)), QColor(Qt::black),
                                          (flags&0x40)==0x40, (flags&2)==2, (flags&1)==1);
                              }
                              else if(style==Graph::Histogram)
                                    graph->insertCurve(mw->table(tableName), tableName + "_" + opj.curveYColName(g,l,c), style);
                              else
                                    graph->insertCurve(mw->table(tableName), tableName + "_" + opj.curveXColName(g,l,c), tableName + "_" + opj.curveYColName(g,l,c), style);
                              break;
                        case 'F':
                              QStringList formulas;
                              QList<double> ranges;
                              int s=opj.functionIndex(data.right(data.length()-2).toStdString().c_str());
                              int type;
                              if(opj.functionType(s)==1)//Polar
                              {
                                    type=2;
                                    formulas << opj.functionFormula(s) << "x";
                                    ranges << pi/180*opj.functionBegin(s) << pi/180*opj.functionEnd(s);
                              }
                              else
                              {
                                    type=0;
                                    formulas << opj.functionFormula(s);
                                    ranges << opj.functionBegin(s) << opj.functionEnd(s);
                              }
                              graph->addFunctionCurve(mw, type, formulas, "x", ranges, opj.functionPoints(s), opj.functionName(s));

                              mw->updateFunctionLists(type, formulas);
                              break;
                        }

                        CurveLayout cl = graph->initCurveLayout(style, opj.numCurves(g,l));
                        cl.sSize = ceil(opj.curveSymbolSize(g,l,c));
                        cl.penWidth=opj.curveSymbolThickness(g,l,c);
                        color=opj.curveSymbolColor(g,l,c);
                        if((style==Graph::Scatter||style==Graph::LineSymbols)&&color==0xF7)//0xF7 -Automatic color
                              color=auto_color++;
                        cl.symCol=color;
                        switch(opj.curveSymbolType(g,l,c)&0xFF)
                        {
                        case 0: //NoSymbol
                              cl.sType=0;
                              break;
                        case 1: //Rect
                              cl.sType=2;
                              break;
                        case 2: //Ellipse
                        case 20://Sphere
                              cl.sType=1;
                              break;
                        case 3: //UTriangle
                              cl.sType=6;
                              break;
                        case 4: //DTriangle
                              cl.sType=5;
                              break;
                        case 5: //Diamond
                              cl.sType=3;
                              break;
                        case 6: //Cross +
                              cl.sType=9;
                              break;
                        case 7: //Cross x
                              cl.sType=10;
                              break;
                        case 8: //Snow
                              cl.sType=13;
                              break;
                        case 9: //Horizontal -
                              cl.sType=11;
                              break;
                        case 10: //Vertical |
                              cl.sType=12;
                              break;
                        case 15: //LTriangle
                              cl.sType=7;
                              break;
                        case 16: //RTriangle
                              cl.sType=8;
                              break;
                        case 17: //Hexagon
                        case 19: //Pentagon
                              cl.sType=15;
                              break;
                        case 18: //Star
                              cl.sType=14;
                              break;
                        default:
                              cl.sType=0;
                        }

                        switch(opj.curveSymbolType(g,l,c)>>8)
                        {
                        case 0:
                              cl.fillCol=color;
                              break;
                        case 1:
                        case 2:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                              color=opj.curveSymbolFillColor(g,l,c);
                              if((style==Graph::Scatter||style==Graph::LineSymbols)&&color==0xF7)//0xF7 -Automatic color
                                    color=17;// depend on Origin settings - not stored in file
                              cl.fillCol=color;
                              break;
                        default:
                              cl.fillCol=-1;
                        }

                        cl.lWidth = ceil(opj.curveLineWidth(g,l,c));
                        color=opj.curveLineColor(g,l,c);
                        cl.lCol=(color==0xF7?0:color); //0xF7 -Automatic color
                        int linestyle=opj.curveLineStyle(g,l,c);
                        cl.filledArea=(opj.curveIsFilledArea(g,l,c)||style==Graph::VerticalBars||style==Graph::HorizontalBars||style==Graph::Histogram)?1:0;
                        if(cl.filledArea)
                        {
                              switch(opj.curveFillPattern(g,l,c))
                              {
                              case 0:
                                    cl.aStyle=0;
                                    break;
                              case 1:
                              case 2:
                              case 3:
                                    cl.aStyle=4;
                                    break;
                              case 4:
                              case 5:
                              case 6:
                                    cl.aStyle=5;
                                    break;
                              case 7:
                              case 8:
                              case 9:
                                    cl.aStyle=6;
                                    break;
                              case 10:
                              case 11:
                              case 12:
                                    cl.aStyle=1;
                                    break;
                              case 13:
                              case 14:
                              case 15:
                                    cl.aStyle=2;
                                    break;
                              case 16:
                              case 17:
                              case 18:
                                    cl.aStyle=3;
                                    break;
                              }
                              color=(cl.aStyle==0 ? opj.curveFillAreaColor(g,l,c) : opj.curveFillPatternColor(g,l,c));
                              cl.aCol=(color==0xF7?0:color); //0xF7 -Automatic color
                              if (style == Graph::VerticalBars || style == Graph::HorizontalBars || style == Graph::Histogram)
                              {
                                    color=opj.curveFillPatternBorderColor(g,l,c);
                                    cl.lCol = (color==0xF7?0:color); //0xF7 -Automatic color
                                    color=(cl.aStyle==0 ? opj.curveFillAreaColor(g,l,c) : opj.curveFillPatternColor(g,l,c));
                                    cl.aCol=(color==0xF7?cl.lCol:color); //0xF7 -Automatic color
                                    cl.lWidth = ceil(opj.curveFillPatternBorderWidth(g,l,c));
                                    linestyle=opj.curveFillPatternBorderStyle(g,l,c);
                              }
                        }
                        switch (linestyle)
                        {
                              case OPJFile::Solid:
                                    cl.lStyle=0;
                                    break;
                              case OPJFile::Dash:
                              case OPJFile::ShortDash:
                                    cl.lStyle=1;
                                    break;
                              case OPJFile::Dot:
                              case OPJFile::ShortDot:
                                    cl.lStyle=2;
                                    break;
                              case OPJFile::DashDot:
                              case OPJFile::ShortDashDot:
                                    cl.lStyle=3;
                                    break;
                              case OPJFile::DashDotDot:
                                    cl.lStyle=4;
                                    break;
                        }

                        graph->updateCurveLayout(c, &cl);
                        if (style == Graph::VerticalBars || style == Graph::HorizontalBars)
                        {
                              QwtBarCurve *b = (QwtBarCurve*)graph->curve(c);
                              if (b)
                                    b->setGap(qRound(100-opj.curveSymbolSize(g,l,c)*10));
                        }
                        else if(style == Graph::Histogram)
                        {
                              QwtHistogram *h = (QwtHistogram*)graph->curve(c);
                              if (h)
                              {
                                    vector<double> bin=opj.layerHistogram(g,l);
                                    if(bin.size()==3)
                                          h->setBinning(false, bin[0], bin[1], bin[2]);
                                    h->loadData();
                              }
                        }
                        switch(opj.curveLineConnect(g,l,c))
                        {
                        case OPJFile::NoLine:
                              graph->setCurveStyle(c, QwtPlotCurve::NoCurve);
                              break;
                        case OPJFile::Straight:
                              graph->setCurveStyle(c, QwtPlotCurve::Lines);
                              break;
                        case OPJFile::BSpline:
                        case OPJFile::Bezier:
                        case OPJFile::Spline:
                              graph->setCurveStyle(c, 5);
                              break;
                        case OPJFile::StepHorizontal:
                        case OPJFile::StepHCenter:
                              graph->setCurveStyle(c, QwtPlotCurve::Steps);
                              break;
                        case OPJFile::StepVertical:
                        case OPJFile::StepVCenter:
                              graph->setCurveStyle(c, 6);
                              break;
                        }

                  }
                  vector<double> rangeX=opj.layerXRange(g,l);
                  vector<int>    ticksX=opj.layerXTicks(g,l);
                  vector<double> rangeY=opj.layerYRange(g,l);
                  vector<int>    ticksY=opj.layerYTicks(g,l);
                  if(style==Graph::HorizontalBars)
                  {
                        graph->setScale(0,rangeX[0],rangeX[1],rangeX[2],ticksX[0],ticksX[1],opj.layerXScale(g,l));
                        graph->setScale(2,rangeY[0],rangeY[1],rangeY[2],ticksY[0],ticksY[1],opj.layerYScale(g,l));
                  }
                  else
                  {
                        graph->setScale(2,rangeX[0],rangeX[1],rangeX[2],ticksX[0],ticksX[1],opj.layerXScale(g,l));
                        graph->setScale(0,rangeY[0],rangeY[1],rangeY[2],ticksY[0],ticksY[1],opj.layerYScale(g,l));
                  }

                  //grid
                  vector<graphGrid> grids=opj.layerGrid(g,l);
                  Grid *grid = graph->grid();
                  grid->enableX(grids[0].hidden?0:1);
                  grid->enableXMin(grids[1].hidden?0:1);
                  grid->enableY(grids[2].hidden?0:1);
                  grid->enableYMin(grids[3].hidden?0:1);

                  grid->setMajPenX(QPen(ColorBox::color(grids[0].color), ceil(grids[0].width),
                                          Graph::getPenStyle(translateOrigin2ScidavisLineStyle(grids[0].style))));
                  grid->setMinPenX(QPen(ColorBox::color(grids[1].color), ceil(grids[1].width),
                                          Graph::getPenStyle(translateOrigin2ScidavisLineStyle(grids[1].style))));
                  grid->setMajPenY(QPen(ColorBox::color(grids[2].color), ceil(grids[2].width),
                                          Graph::getPenStyle(translateOrigin2ScidavisLineStyle(grids[2].style))));
                  grid->setMinPenY(QPen(ColorBox::color(grids[3].color), ceil(grids[3].width),
                                          Graph::getPenStyle(translateOrigin2ScidavisLineStyle(grids[3].style))));

                  grid->setAxis(2, 0);
                  grid->enableZeroLineX(0);
                  grid->enableZeroLineY(0);

                  vector<graphAxisFormat> formats=opj.layerAxisFormat(g,l);
                  vector<graphAxisTick> ticks=opj.layerAxisTickLabels(g,l);
                  for(int i=0; i<4; ++i)
                  {
                        QString data(ticks[i].dataName.c_str());
                        QString tableName=data.right(data.length()-2) + "_" + ticks[i].colName.c_str();

                        QString formatInfo;
                        int format;
                        int type;
                        int prec=ticks[i].decimal_places;
                        switch(ticks[i].value_type)
                        {
                        case OPJFile::Numeric:
                              type=Graph::Numeric;
                              switch(ticks[i].value_type_specification)
                              {
                              case 0: //Decimal 1000
                                    format=1;
                                    break;
                              case 1: //Scientific
                                    format=2;
                                    break;
                              case 2: //Engeneering
                              case 3: //Decimal 1,000
                                    format=0;
                                    break;
                              }
                              if(prec==-1)
                                    prec=2;
                              break;
                        case OPJFile::Text: //Text
                              type=Graph::Txt;
                              break;
                        case 2: // Date
                              type=Graph::Date;
                              break;
                        case 3: // Time
                              type=Graph::Time;
                              break;
                        case OPJFile::Month: // Month
                              type=Graph::Month;
                              format=ticks[i].value_type_specification;
                              break;
                        case OPJFile::Day: // Day
                              type=Graph::Day;
                              format=ticks[i].value_type_specification;
                              break;
                        case OPJFile::ColumnHeading:
                              type=Graph::ColHeader;
                              switch(ticks[i].value_type_specification)
                              {
                              case 0: //Decimal 1000
                                    format=1;
                                    break;
                              case 1: //Scientific
                                    format=2;
                                    break;
                              case 2: //Engeneering
                              case 3: //Decimal 1,000
                                    format=0;
                                    break;
                              }
                              prec=2;
                              break;
                        default:
                              type=Graph::Numeric;
                              format=0;
                              prec=2;
                        }

                        graph->showAxis(i, type, tableName, mw->table(tableName), !(formats[i].hidden),
                              tickTypeMap[formats[i].majorTicksType], tickTypeMap[formats[i].minorTicksType],
                              !(ticks[i].hidden),     ColorBox::color(formats[i].color), format, prec,
                              ticks[i].rotation, 0, "", (ticks[i].color==0xF7 ? ColorBox::color(formats[i].color) : ColorBox::color(ticks[i].color)));
                  }


                  graph->setAutoscaleFonts(mw->autoScaleFonts);//restore user defined fonts behaviour
            graph->setIgnoreResizeEvents(!mw->autoResizeLayers);
            }
            //cascade the graphs
            if(!opj.graphHidden(g))
            {
                  int dx=20;
                  int dy=ml->parentWidget()->frameGeometry().height() - ml->height();
                  ml->parentWidget()->move(QPoint(visible_count*dx+xoffset*OBJECTXOFFSET,visible_count*dy));
                  visible_count++;
                  ml->show();
                  ml->arrangeLayers(true,true);
            }
            else
            {
                  ml->show();
                  ml->arrangeLayers(true,true);
                  mw->hideWindow(ml);
            }
      }
      if(visible_count>0)
            xoffset++;
      return true;
}


Generated by  Doxygen 1.6.0   Back to index