Changeset 393 in PSPA


Ignore:
Timestamp:
Mar 18, 2013, 5:10:46 PM (11 years ago)
Author:
touze
Message:

unification des traces

Location:
Interface_Web/trunk/pspaWT/sources/userInterface
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/userInterface/include/GWt_pspaApplication.h

    r386 r393  
    9191  void faireDessinEnveloppe(WContainerWidget* toto, string type);
    9292  //  void scatterPlot1D(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor);
     93
    9394  void chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints, string title, string legendx, string legendy, int width, int height, bool makeIcon=false);
     95  void chartPlot2vec(WContainerWidget* toto,vector<double>& xcor,vector<double>& ycor,Wt::Chart::SeriesType seriesType,Wt::Chart::FillRangeType fillRange,Wt::Chart::AxisValue value,bool isGridLinesEnables,string title,string legendx,string legendy,int width,int height,bool makeIcon = false);
     96
    9497  bool removePathFromConfigName(string& config);
    9598  bool removeExtensionFromConfigName(string& config);
     
    99102  void dessinerEnveloppe();
    100103  void dessinerPhaseSpace();
     104
     105  void old_dessinerHistogramme();
    101106  void dessinerHistogramme();
    102107
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc

    r386 r393  
    568568void PspaApplication::faireDessinEnveloppe(WContainerWidget* toto, string type)
    569569{
    570    
     570 
    571571  GWt_dialog* envDialog = new GWt_dialog("enveloppe",toto,false);
    572572  eDialog_.push_back(envDialog);
     
    578578  vector<double> xcor;
    579579  vector<double> ycor;
    580     string titre;
    581     string legendx;
    582     string legendy;
    583     dtmanage_->donneesRmsEnveloppe(type,xcor,ycor, titre, legendx, legendy);
    584     chartPlot2vec(envDialog->contents(), xcor, ycor, false,titre, legendx, legendy,500,300);
    585 
     580  string titre;
     581  string legendx;
     582  string legendy;
     583  dtmanage_->donneesRmsEnveloppe(type,xcor,ycor,titre,legendx,legendy);
     584
     585  Wt::Chart::SeriesType seriesType = LineSeries;
     586  Wt::Chart::FillRangeType fillRange = NoFill;
     587  Wt::Chart::AxisValue location = ZeroValue;
     588  bool isGridLinesEnabled = false;
     589  chartPlot2vec(envDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,legendx,legendy,500,300);
    586590}
    587591
     
    593597  vector<string> legende;
    594598  string titre;
    595   bool pointsDrawing;
     599  Wt::Chart::SeriesType seriesType;
     600 
    596601  if ( typeFaisceau == 0 ) {
    597     pointsDrawing = false;
     602    seriesType = LineSeries;
    598603    titre = "phase space rms";
    599     beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey);
     604    beam->donneesDessinEllipse(xcor,ycor,legende,namex,namey);
    600605  } else if (  typeFaisceau == 1 ) {
    601     pointsDrawing = true;
     606    seriesType = PointSeries;
    602607    titre = " phase space ";
    603     beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey);
     608    beam->particlesPhaseSpaceData(xcor,ycor,legende,namex,namey);
    604609  } else {
    605         GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
    606         warningBeamState.exec();
    607         return;
    608   }
    609 
     610    GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
     611    warningBeamState.exec();
     612    return;
     613  }
    610614
    611615  GWt_dialog* phaseSpaceDialog = new GWt_dialog("phase space",toto,false);
     
    614618  phaseSpaceDialog->setClosable(true);
    615619  new WText(nameOfCase_, phaseSpaceDialog->contents());
    616  
    617620
    618621  for (int k=0 ; k < legende.size(); k++) {
     
    620623    new WText(legende.at(k), phaseSpaceDialog->contents());
    621624  }
    622   chartPlot2vec(phaseSpaceDialog->contents(), xcor, ycor,pointsDrawing ,titre, namex, namey,500,300);
     625
     626  Wt::Chart::FillRangeType fillRange = NoFill;
     627  Wt::Chart::AxisValue location = ZeroValue;
     628  bool isGridLinesEnabled = false;
     629  chartPlot2vec(phaseSpaceDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,namex,namey,500,300);
     630 
    623631  phaseSpaceDialog->show();
    624 
    625632}
    626633
     
    715722
    716723    // Provide space for the X and Y axis and title.
    717       chart->setPlotAreaPadding(80, Left);  // ?
    718       chart->setPlotAreaPadding(40, Bottom);
    719       chart->setPlotAreaPadding(60, Top);
    720       if ( drawPoints ) {
    721        WDataSeries s(1, PointSeries, Y1Axis);
    722        chart->addSeries(s);   
    723       } else {
    724        WDataSeries s(1, LineSeries, Y1Axis);
    725        chart->addSeries(s);   
    726       }
    727        chart->resize(width, height); // WPaintedWidget must be given explicit size
    728 
    729 
    730        WAxis& axis = chart->axis(XAxis);
    731        axis.setLabelFormat("%.3f");
    732        //       axis.setGridLinesEnabled(true);
    733        axis.setTitle(legendx);
    734 
    735        WAxis& axey = chart->axis(YAxis);
    736        axey.setTitle(legendy);
    737        // axis = chart->axis(YAxis);
    738        // axis.setLabelFormat("%.3f");
    739        // axis.setGridLinesEnabled(true);
    740        // axis.setTitle(legendy);
    741 
     724    chart->setPlotAreaPadding(80, Left);  // ?
     725    chart->setPlotAreaPadding(40, Bottom);
     726    chart->setPlotAreaPadding(60, Top);
     727    if ( drawPoints ) {
     728      WDataSeries s(1, PointSeries, Y1Axis);
     729      chart->addSeries(s);   
     730    } else {
     731      WDataSeries s(1, LineSeries, Y1Axis);
     732      chart->addSeries(s);   
     733    }
     734    chart->resize(width, height); // WPaintedWidget must be given explicit size
     735   
     736   
     737    WAxis& axis = chart->axis(XAxis);
     738    axis.setLabelFormat("%.3f");
     739    //       axis.setGridLinesEnabled(true);
     740    axis.setTitle(legendx);
     741   
     742    WAxis& axey = chart->axis(YAxis);
     743    axey.setTitle(legendy);
     744    // axis = chart->axis(YAxis);
     745    // axis.setLabelFormat("%.3f");
     746    // axis.setGridLinesEnabled(true);
     747    // axis.setTitle(legendy);
     748   
    742749    if (makeIcon) {
    743         chart->setPlotAreaPadding(0);
    744         chart->setAxisPadding(0);
    745         WFont xAxisFont = chart->axis(XAxis).labelFont();
    746         xAxisFont.setSize(8);
    747         WFont yAxisFont = chart->axis(YAxis).labelFont();
    748         yAxisFont.setSize(8);
    749         chart->axis(XAxis).setLabelFont(xAxisFont);
    750         chart->axis(YAxis).setLabelFont(yAxisFont);
     750      chart->setPlotAreaPadding(0);
     751      chart->setAxisPadding(0);
     752      WFont xAxisFont = chart->axis(XAxis).labelFont();
     753      xAxisFont.setSize(8);
     754      WFont yAxisFont = chart->axis(YAxis).labelFont();
     755      yAxisFont.setSize(8);
     756      chart->axis(XAxis).setLabelFont(xAxisFont);
     757      chart->axis(YAxis).setLabelFont(yAxisFont);
    751758    }
    752759
     
    761768    new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
    762769   
    763      Wt::WPdfImage pdfImage("30cm", "30cm");
    764      Wt::WPainter p1(&pdfImage);
     770    Wt::WPdfImage pdfImage("30cm", "30cm");
     771    Wt::WPainter p1(&pdfImage);
    765772    pdfImage.init();
    766773    chart->paint(p1);
    767      name = workingDir_ + "/chart-"+sessionId ()+".pdf";
    768      std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
    769      pdfImage.write(f1);
     774    name = workingDir_ + "/chart-"+sessionId ()+".pdf";
     775    std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
     776    pdfImage.write(f1);
    770777#endif
    771778}
     
    839846}
    840847
    841 void PspaApplication::dessinerHistogramme()
     848void PspaApplication::old_dessinerHistogramme()
    842849{
    843850  // pour mon test : histo en energie
     
    974981  createBeamLine();
    975982}
     983
     984void PspaApplication::chartPlot2vec(WContainerWidget* toto,vector<double>& xcor,vector<double>& ycor,SeriesType seriesType,FillRangeType fillRange,AxisValue value,bool isGridLinesEnables,string title,string legendx,string legendy,int width,int height,bool makeIcon)
     985{
     986  int nbpts = xcor.size();
     987  cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl;
     988
     989  WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
     990  for (int i = 0; i < nbpts; ++i) {
     991    model->setData(i, 0, xcor.at(i));
     992    model->setData(i, 1, ycor.at(i));
     993    //    cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
     994  }
     995   
     996  WCartesianChart *chart = new WCartesianChart(toto);
     997  if (!makeIcon) chart->setTitle(title);
     998
     999  chart->initLayout(); 
     1000  chart->setModel(model);        // set the model
     1001  chart->setXSeriesColumn(0);    // set the column that holds the X data
     1002 
     1003  chart->setType(ScatterPlot);   // set type to ScatterPlot
     1004  chart->setLegendEnabled(false); // enable the legend 
     1005
     1006  // Provide space for the X and Y axis and title.
     1007  chart->setPlotAreaPadding(80, Left);
     1008  chart->setPlotAreaPadding(40, Bottom);
     1009  chart->setPlotAreaPadding(60, Top);
     1010 
     1011  // Typically, for mathematical functions, you want the axes to cross
     1012  // at the 0 mark (value= ZeroValue)
     1013  chart->axis(XAxis).setLocation(value);
     1014  chart->axis(YAxis).setLocation(value);
     1015 
     1016  WDataSeries s(1,seriesType);
     1017  s.setFillRange(fillRange);
     1018  chart->addSeries(s);
     1019 
     1020  WAxis& axis = chart->axis(XAxis);
     1021  axis.setLabelFormat("%.3f");
     1022  axis.setTitle(legendx);
     1023   
     1024  chart->axis(Y1Axis).setTitle(legendy);
     1025
     1026  if(isGridLinesEnables) {
     1027    axis.setGridLinesEnabled(true);
     1028    chart->axis(Y1Axis).setGridLinesEnabled(true);
     1029  }
     1030 
     1031  chart->resize(width,height); // WPaintedWidget must be given explicit size
     1032  chart->setMargin(10, Top | Bottom); // ?
     1033  chart->setMargin(WLength::Auto, Left | Right); //?
     1034
     1035  if (makeIcon) {
     1036    chart->setLegendEnabled(false); // enable the legend
     1037    chart->setPlotAreaPadding(0);
     1038    chart->setAxisPadding(0);
     1039    WFont xAxisFont = chart->axis(XAxis).labelFont();
     1040    xAxisFont.setSize(8);
     1041    WFont yAxisFont = chart->axis(YAxis).labelFont();
     1042    yAxisFont.setSize(8);
     1043    chart->axis(XAxis).setLabelFont(xAxisFont);
     1044    chart->axis(YAxis).setLabelFont(yAxisFont);
     1045  }
     1046 
     1047#ifdef HAS_IMAGEMAGIC
     1048  Wt::WRasterImage pngImage("png", 600, 600);
     1049  Wt::WPainter p(&pngImage);
     1050  chart->paint(p);
     1051  std::string name;
     1052  name = workingDir_ + "/chart-"+sessionId ()+".png";
     1053  std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
     1054  pngImage.write(f);   
     1055  new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
     1056 
     1057  Wt::WPdfImage pdfImage("30cm", "30cm");
     1058  Wt::WPainter p1(&pdfImage);
     1059  pdfImage.init();
     1060  chart->paint(p1);
     1061  name = workingDir_ + "/chart-"+sessionId ()+".pdf";
     1062  std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
     1063  pdfImage.write(f1);
     1064#endif
     1065}
     1066
     1067void PspaApplication::dessinerHistogramme()
     1068{
     1069  toto_->clear();
     1070 
     1071  GWt_dialog* histoDialog = new GWt_dialog("histogramme",toto_,false);
     1072  eDialog_.push_back(histoDialog);
     1073  histoDialog->setMinimumSize(400,400);
     1074  histoDialog->setClosable(true);
     1075
     1076  string elementLabel = choixHistoDessin_->currentText().toUTF8();   
     1077  particleBeam* beam = dtmanage_->getDiagnosticBeam(elementLabel);
     1078  if (beam == NULL) {
     1079    GWt_dialog warningBeamState("histogram","the beam does not exist at the end of this element !", GWt_dialog::Error, false,true);
     1080    warningBeamState.exec();
     1081    return;
     1082  }
     1083 
     1084  if (!beam->particleRepresentationOk()) {
     1085    GWt_dialog warningBeamState("histogram", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
     1086    warningBeamState.exec();
     1087    return;
     1088  }
     1089
     1090  histoDialog->show();
     1091  vector<double> xcor;
     1092  vector<int> hist;
     1093  double out[3]= {0.0};
     1094  unsigned iabs= choixVariableHisto_->currentIndex(); 
     1095  beam->histogramme(iabs,xcor,hist,out);
     1096
     1097  cout<<"xcor.size()= "<<xcor.size()<<", hist.size()= "<<hist.size()<<endl;
     1098  //////////////////////////////////////////////////////////////////////////////////
     1099 
     1100  int n = hist.size();
     1101  vector<double> x;
     1102  x.resize(2*n+2);
     1103  vector<double> y;
     1104  y.resize(2*n+2);
     1105
     1106  int j= 0;
     1107  x.at(j)= xcor[0];
     1108  y.at(j)= 0.0;
     1109  j++;
     1110  x.at(j)= xcor[0];
     1111  y.at(j)= hist[0];
     1112  j++;
     1113 
     1114  for (int i = 1; i < n; ++i) {
     1115    x.at(j)= xcor[i];
     1116    y.at(j)= hist[i-1];
     1117    j++;
     1118    x.at(j)= xcor[i];
     1119    y.at(j)= hist[i];
     1120    j++;
     1121  }
     1122
     1123  x.at(j)= xcor[n];
     1124  y.at(j)= hist[n-1];
     1125  j++;
     1126  x.at(j)= xcor[n];
     1127  y.at(j)= 0.0;
     1128  //////////////////////////////////////////////////////////////////////////////////
     1129
     1130  WContainerWidget *w= histoDialog->contents();
     1131
     1132  // legendes
     1133  string unites[2];
     1134  if(iabs == 0 || iabs == 1 || iabs == 2) {
     1135    unites[0]= unites[1]= " mm";
     1136  }
     1137  if(iabs == 3 || iabs == 4) {
     1138    unites[0]= unites[1]= " mrad";
     1139  }
     1140  if(iabs == 5) {
     1141    unites[0]= " MeV"; unites[1]= " KeV";
     1142  }
     1143
     1144  new WText(" entries : "+ mixedTools::intToString((int)out[0]),w);
     1145  new WBreak(w);
     1146  new WText(" mean : "+ mixedTools::doubleToString(out[1])+unites[0],w);
     1147  new WBreak(w);
     1148  new WText(" sigma rms : "+ mixedTools::doubleToString(out[2])+unites[1],w);
     1149  //////////////////////////////////////////////////////////////////////////////////
     1150
     1151  string titre;
     1152  if(iabs == 0) titre="x-coordinate";
     1153  if(iabs == 1) titre="y-coordinate";
     1154  if(iabs == 2) titre="z-coordinate";
     1155  if(iabs == 3) titre="xp-divergence";
     1156  if(iabs == 4) titre="yp-devergence";
     1157  if(iabs == 5) titre="kinetic energy";
     1158
     1159  string xname;
     1160  if(iabs == 0) xname=" x (mm)";
     1161  if(iabs == 1) xname=" y (mm)";
     1162  if(iabs == 2) xname=" z (mm)";
     1163  if(iabs == 3) xname=" xp (mrad)";
     1164  if(iabs == 4) xname=" yp (mrad)";
     1165  if(iabs == 5) xname=" dEcin/Ecin (%)";
     1166
     1167  string yname;
     1168  Wt::Chart::SeriesType seriesType = LineSeries;
     1169  Wt::Chart::FillRangeType fillRange = ZeroValueFill;
     1170  Wt::Chart::AxisValue location = MinimumValue;
     1171  bool isGridLinesEnabled = true;
     1172  chartPlot2vec(w,x,y,seriesType,fillRange,location,isGridLinesEnabled,titre,xname,yname,500,300);
     1173}
Note: See TracChangeset for help on using the changeset viewer.