Ignore:
Timestamp:
Mar 9, 2013, 5:12:55 PM (11 years ago)
Author:
lemeur
Message:

complements graphiques, legendes et unification unites

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc

    r379 r381  
    512512  int typeFaisceau = choixTypeDessinFaisceau_->currentIndex();
    513513  int index = choixElementDessin_->currentIndex();
    514   unsigned xabs = choixAbsPhase_->currentIndex();
    515   unsigned yord = choixOrdPhase_->currentIndex();
    516   if ( xabs == yord ) {
     514  string nameAbs = choixAbsPhase_->currentText().toUTF8();
     515  string nameOrd = choixOrdPhase_->currentText().toUTF8();
     516  if ( nameAbs == nameOrd ) {
    517517        GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true);
    518518        phaseSpaceError.exec();
    519519        return;
    520520  }
    521   string nameAbs = choixAbsPhase_->currentText().toUTF8();
    522   string nameOrd = choixOrdPhase_->currentText().toUTF8();
    523521
    524522  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
     
    531529   
    532530    toto_->clear();
    533  
    534   if ( typeFaisceau == 0 )
    535     {
    536       if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
    537       cout << " PspaApplication::dessinerPhaseSpace cood cliquees " << xabs << " " << yord << endl;
    538       faireDessinTransport(toto_, beam, xabs, yord, nameAbs, nameOrd );
    539     }
    540   else if ( typeFaisceau == 1 )
    541     {
    542       if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, xabs, yord, nameAbs, nameOrd );
    543       else {
    544         GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
    545         warningBeamState.exec();
    546       }
    547     }
    548   else {
    549     GWt_dialog warningTypeDrawing(" graphical analysis", "type of  drawing not programmed !", GWt_dialog::Error, false,true);
    550     warningTypeDrawing.exec();
    551   }
     531    faireDessinPhaseSpace(toto_, beam, nameAbs, nameOrd, typeFaisceau);
     532
     533  // if ( typeFaisceau == 0 )
     534  //   {
     535  //     if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
     536  //     faireDessinTransport(toto_, beam, nameAbs, nameOrd );
     537  //   }
     538  // else if ( typeFaisceau == 1 )
     539  //   {
     540  //     if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, nameAbs, nameOrd );
     541  //     else {
     542  //    GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
     543  //    warningBeamState.exec();
     544  //     }
     545  //   }
     546  // else {
     547  //   GWt_dialog warningTypeDrawing(" graphical analysis", "type of  drawing not programmed !", GWt_dialog::Error, false,true);
     548  //   warningTypeDrawing.exec();
     549  // }
    552550}
    553551
     
    579577  vector<double> xcor;
    580578  vector<double> ycor;
    581   // dtmanage_->donneesRmsEnveloppe(type,1, nbel, xcor,ycor);
    582     dtmanage_->donneesRmsEnveloppe(type,xcor,ycor);
    583     chartPlot2vec(envDialog->contents(), xcor, ycor, false,500,300);
    584 
    585 }
    586 
    587 void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey )
     579    string titre;
     580    string legendx;
     581    string legendy;
     582    dtmanage_->donneesRmsEnveloppe(type,xcor,ycor, titre, legendx, legendy);
     583    chartPlot2vec(envDialog->contents(), xcor, ycor, false,titre, legendx, legendy,500,300);
     584
     585}
     586
     587void PspaApplication::faireDessinPhaseSpace(WContainerWidget* toto, particleBeam* beam, string namex, string namey, int typeFaisceau)
     588{
     589
     590  vector<double> xcor;
     591  vector<double> ycor;
     592  vector<string> legende;
     593  string titre;
     594  bool pointsDrawing;
     595  if ( typeFaisceau == 0 ) {
     596    pointsDrawing = false;
     597    titre = "phase space rms";
     598    beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey);
     599  } else if (  typeFaisceau == 1 ) {
     600    pointsDrawing = true;
     601    titre = " phase space ";
     602    beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey);
     603  } else {
     604        GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
     605        warningBeamState.exec();
     606        return;
     607  }
     608
     609
     610  GWt_dialog* phaseSpaceDialog = new GWt_dialog("phase space",toto,false);
     611  eDialog_.push_back(phaseSpaceDialog);
     612  phaseSpaceDialog->setMinimumSize(400,400);
     613  phaseSpaceDialog->setClosable(true);
     614  new WText(nameOfCase_, phaseSpaceDialog->contents());
     615 
     616
     617  for (int k=0 ; k < legende.size(); k++) {
     618    new WBreak(phaseSpaceDialog->contents());
     619    new WText(legende.at(k), phaseSpaceDialog->contents());
     620  }
     621  chartPlot2vec(phaseSpaceDialog->contents(), xcor, ycor,pointsDrawing ,titre, namex, namey,500,300);
     622  phaseSpaceDialog->show();
     623
     624}
     625
     626
     627
     628void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, string namex, string namey )
    588629{
    589630  cout << " faireDessinParmela " << endl;
     
    594635  // pointsDialog->show();
    595636     
    596   //    vector<bareParticle>& partic = beam->getParticleVector();
    597   new WText(nameOfCase_ + " : phase space " + namex + " ," + namey + " ; particle number : "+ mixedTools::intToString(beam->getNbParticles()), pointsDialog->contents());
     637  new WText(nameOfCase_, pointsDialog->contents());
     638
    598639
    599640  vector<double> xcor;
    600641  vector<double> ycor;
    601   beam->particlesPhaseSpaceData(xcor, ycor, indexAbs, indexOrd);
    602   chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,400,400);
     642  vector<string> legende;
     643  beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey);
     644  for (int k=0 ; k < legende.size(); k++) {
     645    new WBreak(pointsDialog->contents());
     646    new WText(legende.at(k), pointsDialog->contents());
     647  }
     648  string titre = " phase space ";
     649  chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,titre,namex, namey,400,400);
    603650
    604651
     
    610657}
    611658
    612 void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey)
     659void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, string namex, string namey)
    613660{
    614661  GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false);
     
    622669  vector<double> ycor;
    623670  vector<string> legende;
    624   beam->donneesDessinEllipse(xcor,ycor,legende, indexAbs, indexOrd);
     671  beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey);
    625672
    626673  for (int k=0 ; k < legende.size(); k++) {
     
    628675    new WText(legende.at(k), ellipseDialog->contents());
    629676  }
    630   //  beam->donneesDessinEllipseXxp(xcor,ycor);
    631   //  scatterPlot1D(ellipseDialog->contents(),xcor,ycor); 
    632   chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,500,300);
    633 }
    634 
    635 // void PspaApplication::scatterPlot1D(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor)
    636 // {
    637 //     int nbpts = xcor.size();
    638 //     cout << " PspaApplication::scatterPlot1D nbpts = " << nbpts << endl;
    639 //     WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
    640 //     for (int i = 0; i < nbpts; ++i) {
    641 //         model->setData(i, 0, xcor.at(i));
    642 //         model->setData(i, 1, ycor.at(i));
    643 //         //    cout << " PspaApplication::scatterPlot1D el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
    644 //     }
    645    
    646 //     WCartesianChart *chart = new WCartesianChart(toto);
    647 //     chart->setTitle("titre");
    648    
    649 //     //  chart->initLayout();
    650    
    651 //     chart->setModel(model);        // set the model
    652 //     chart->setXSeriesColumn(0);    // set the column that holds the X data
    653 //     chart->setLegendEnabled(true); // enable the legend
    654    
    655 //     chart->setType(ScatterPlot);   // set type to ScatterPlot
    656    
    657 //     // Typically, for mathematical functions, you want the axes to cross
    658 //     // at the 0 mark:
    659 //     chart->axis(XAxis).setLocation(ZeroValue);
    660 //     chart->axis(YAxis).setLocation(ZeroValue);
    661    
    662 //     // Provide space for the X and Y axis and title.
    663 //     //   chart->setPlotAreaPadding(80, Left);
    664 //     //   chart->setPlotAreaPadding(40, Top | Bottom);
    665 //     // Add the curves
    666 //     WDataSeries s(1, LineSeries, Y1Axis);
    667 //     chart->addSeries(s);
    668    
    669 //     // chart->setBackground (WBrush(WColor("blue")));
    670 //     chart->resize(500, 300); // WPaintedWidget must be given explicit size
    671    
    672 // #ifdef HAS_IMAGEMAGIC
    673 //     Wt::WRasterImage pngImage("png", 600, 600);
    674 //     Wt::WPainter p(&pngImage);
    675    
    676 //     chart->paint(p);
    677 //     std::string name;
    678 //     name = workingDir_ + "/chart-"+sessionId ()+".png";
    679 //     std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
    680 //     pngImage.write(f);
    681    
    682 //     new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
    683    
    684 //     /*
    685 //      Wt::WPdfImage pdfImage("30cm", "30cm");
    686 //      Wt::WPainter p1(&pdfImage);
    687 //      chart->paint(p1);
    688 //      std::ofstream f1("chart.pdf", std::ios::out | std::ios::binary);
    689 //      pdfImage.write(f1);
    690 //      */
    691 // #endif
    692 // }
    693 
    694 // dernier parametre, drawPoints : true = on trace des points (phase space) ; false = on trace des lignes 'enveloppes...)
    695 void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints,int width, int height, bool makeIcon)
     677  string titre = "phase space rms";
     678  chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,titre, namex, namey,500,300);
     679}
     680
     681
     682// parametre drawPoints : true = on trace des points (phase space) ; false = on trace des lignes (enveloppes...)
     683void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints,string title,string legendx, string legendy,int width, int height, bool makeIcon)
    696684{
    697685    int nbpts = xcor.size();
     
    706694    WCartesianChart *chart = new WCartesianChart(toto);
    707695    if (!makeIcon) {
    708         chart->setTitle("titre");
     696        chart->setTitle(title);
    709697    }
    710698    chart->initLayout();
     
    726714
    727715    // Provide space for the X and Y axis and title.
    728     if ( drawPoints ) {
    729       chart->setPlotAreaPadding(80, Left);
    730       chart->setPlotAreaPadding(40, Top | Bottom);
    731       WDataSeries s(1, PointSeries, Y1Axis);
    732       chart->addSeries(s);
    733       chart->resize(width, height); // WPaintedWidget must be given explicit size
    734      } else {
     716      chart->setPlotAreaPadding(80, Left);  // ?
     717      chart->setPlotAreaPadding(40, Bottom);
     718      chart->setPlotAreaPadding(60, Top);
     719      if ( drawPoints ) {
     720       WDataSeries s(1, PointSeries, Y1Axis);
     721       chart->addSeries(s);   
     722      } else {
    735723       WDataSeries s(1, LineSeries, Y1Axis);
    736724       chart->addSeries(s);   
     725      }
    737726       chart->resize(width, height); // WPaintedWidget must be given explicit size
    738      }
     727
     728
     729       WAxis& axis = chart->axis(XAxis);
     730       axis.setLabelFormat("%.3f");
     731       //       axis.setGridLinesEnabled(true);
     732       axis.setTitle(legendx);
     733
     734       WAxis& axey = chart->axis(YAxis);
     735       axey.setTitle(legendy);
     736       // axis = chart->axis(YAxis);
     737       // axis.setLabelFormat("%.3f");
     738       // axis.setGridLinesEnabled(true);
     739       // axis.setTitle(legendy);
    739740
    740741    if (makeIcon) {
     
    903904  string unites[2];
    904905  if(iabs == 0 || iabs == 1 || iabs == 2) {
    905     unites[0]= unites[1]= " cm";
     906    unites[0]= unites[1]= " mm";
    906907  }
    907908  if(iabs == 3 || iabs == 4) {
     
    942943  axis.setGridLinesEnabled(true);
    943944
    944   if(iabs == 0) axis.setTitle(WString(" x (cm)"));
    945   if(iabs == 1) axis.setTitle(WString(" y (cm)"));
    946   if(iabs == 2) axis.setTitle(WString(" z (cm)"));
     945  if(iabs == 0) axis.setTitle(WString(" x (mm)"));
     946  if(iabs == 1) axis.setTitle(WString(" y (mm)"));
     947  if(iabs == 2) axis.setTitle(WString(" z (mm)"));
    947948  if(iabs == 3) axis.setTitle(WString(" xp (mrad)"));
    948949  if(iabs == 4) axis.setTitle(WString(" yp (mrad)"));
Note: See TracChangeset for help on using the changeset viewer.