Ignore:
Timestamp:
Feb 22, 2013, 10:07:46 AM (11 years ago)
Author:
lemeur
Message:

fin dessins esp. phase + noms de fichiers

File:
1 edited

Legend:

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

    r340 r341  
    7070    useStyleSheet       ("htdocs/pspa.css");
    7171    dtmanage_ = new dataManager(this);
    72     dtmanage_->setWorkingDir(workingDir_);
     72    //    dtmanage_->setWorkingDir(workingDir_);
    7373    /*
    7474     * The main layout is a 3x2 grid layout.
     
    346346  else { console_->addConsoleMessage("sauvegarde sur repertoire : " + workingDir_);}
    347347  nameOfCase_ = saveNameEdit_->text().toUTF8();
    348   cout << " PspaApplication::dialogSaveDone() nameOfCase_= " << nameOfCase_ << endl;
     348  cout << " PspaApplication::dialogSaveDone() sur fichier = " << nameOfCase_ << endl;
    349349  delete dialogSave_;
    350350  dialogSave_ = NULL;
     
    359359{
    360360    GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_);
    361     nameOfCase_ = fs->exec();
    362    
     361    string fileName = fs->exec();
     362     nameOfCase_ = fileName;
     363   
     364    removePathFromConfigName(nameOfCase_ );
     365    cout << " nom sans path " << nameOfCase_ << endl;
     366    removeExtensionFromConfigName(nameOfCase_);
     367    cout << " nom sans extension " << nameOfCase_ << endl;
    363368    if (nameOfCase_ == "")
    364369        return;
    365    
     370    cout << " je restaure le fichier " << fileName << endl;
    366371    dialogSave_ = NULL;
    367372   
    368     bool test = dtmanage_->restoreElements(nameOfCase_);
     373    bool test = dtmanage_->restoreElements(fileName);
    369374    if ( !test ) {
    370         GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
     375        GWt_dialog restoreWarning(" element restoring", "failure in restoring elements from file : " + fileName , GWt_dialog::Error, false,true);
    371376        restoreWarning.exec();
    372377    }
     
    466471void PspaApplication::dessinerPhaseSpace()
    467472{   
    468   toto_->clear();
    469473   
    470474  int typeFaisceau = choixTypeDessinFaisceau_->currentIndex();
     
    472476  unsigned xabs = choixAbsPhase_->currentIndex();
    473477  unsigned yord = choixOrdPhase_->currentIndex();
    474        
     478  if ( xabs == yord ) {
     479        GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true);
     480        phaseSpaceError.exec();
     481        return;
     482  }
     483  string nameAbs = choixAbsPhase_->currentText().toUTF8();
     484  string nameOrd = choixOrdPhase_->currentText().toUTF8();
     485
    475486  particleBeam* beam = dtmanage_->getDiagnosticBeam(index);
    476487   
     
    481492  }
    482493   
    483    
     494    toto_->clear();
     495 
    484496  if ( typeFaisceau == 0 )
    485497    {
    486498      if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation();
    487       faireDessinTransport(toto_, beam);
     499      faireDessinTransport(toto_, beam, xabs, yord, nameAbs, nameOrd );
    488500    }
    489501  else if ( typeFaisceau == 1 )
    490502    {
    491       if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, xabs, yord);
     503      if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, xabs, yord, nameAbs, nameOrd );
    492504      else {
    493505        GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true);
     
    533545}
    534546
    535 
    536 void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd )
     547void PspaApplication::setModelComponentForPhaseSpace(WStandardItemModel* model, vector<bareParticle>& partic, unsigned indexParticleComponent, unsigned modelComponent) {
     548  double valeur;
     549  if ( indexParticleComponent > 5  ) return;
     550
     551  if ( indexParticleComponent <= 2 ) {
     552    for (unsigned i = 0; i < partic.size(); ++i) {
     553      valeur = partic.at(i).getPosition().getComponent(indexParticleComponent);
     554      model->setData(i, modelComponent, valeur);
     555    }
     556  } else {
     557    if ( indexParticleComponent == 5 ) {
     558      cout << " PspaApplication::faireDessinParmela : deltap non programme " << endl;
     559      return;
     560    } else {
     561      for (unsigned i = 0; i < partic.size(); ++i) {
     562        double begamz = partic.at(i).getBetaGamma().getComponent(2);
     563        if ( begamz != 0.0) {
     564          valeur = 1.e3*partic.at(i).getBetaGamma().getComponent(indexParticleComponent-3)/begamz;
     565        } else {
     566          valeur = 0.0;
     567        }
     568        model->setData(i, modelComponent, valeur);
     569      }
     570    }
     571  }
     572}
     573
     574void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey )
    537575{
    538576  cout << " faireDessinParmela " << endl;
     
    542580  pointsDialog->setClosable(true);
    543581  // pointsDialog->show();
    544  
    545    
    546    
    547     vector<bareParticle>& partic = beam->getParticleVector();
    548     new WText(nameOfCase_ + " : espace de phase x,x' "+ " nb partic. "+ mixedTools::intToString(partic.size()), pointsDialog->contents());
    549     WStandardItemModel *model = new WStandardItemModel(partic.size(), 2, pointsDialog->contents());
    550     //    model->setHeaderData(0, WString("X"));
    551     //   model->setHeaderData(1, WString("Y = sin(X)"));
    552    
    553     if ( indexAbs > 5 || indexOrd > 5 ) return;
    554 
    555     for (unsigned i = 0; i < partic.size(); ++i) {
    556       double valAbs, valOrd;
    557       double begamz = partic.at(i).getBetaGamma().getComponent(2);
    558       if ( indexAbs <= 2 ) {
    559         valAbs = partic.at(i).getPosition().getComponent(indexAbs);
    560         cout << " i= " << i << " valabs = " << valAbs << endl;
    561       } else {
    562         if ( indexAbs == 5 ) {
    563           cout << " PspaApplication::faireDessinParmela : deltap non programme " << endl;
    564           return;
    565         } else {
    566           if ( begamz != 0.0) {
    567             valAbs = 1.e3*partic.at(i).getBetaGamma().getComponent(indexAbs-3)/begamz;
    568           } else {
    569             valAbs = 0.0;
    570           }
    571         }
    572       }
    573 
    574       if ( indexOrd <= 2 ) {
    575         valOrd = partic.at(i).getPosition().getComponent(indexOrd);
    576       } else {
    577         if ( indexOrd == 5 ) {
    578           cout << " PspaApplication::faireDessinParmela : deltap non programme " << endl;
    579           return;
    580         } else {
    581 
    582 
    583           if ( begamz != 0.0) {
    584             valOrd = 1.e3*partic.at(i).getBetaGamma().getComponent(indexOrd-3)/begamz;
    585           } else {
    586             valOrd = 0.0;
    587           }
    588         cout << " i= " << i << " valord = " << valOrd << endl;
    589         }
    590       }
    591582     
    592 
    593         // double x= partic.at(i).getPosition().getComponent(0);
    594         // double begamz = partic.at(i).getBetaGamma().getComponent(2);
    595         // double xp;
    596         // if ( begamz != 0.0) {
    597         //   xp = partic.at(i).getBetaGamma().getComponent(0)/begamz;
    598         // } else {
    599         //   xp = 0.0;
    600         // }
    601         // //    cout << "x = " << x << " xp= " << xp << endl;
    602         // model->setData(i, 0, x);
    603         // model->setData(i, 1,1.e3*xp);
    604         // model->setData(i, 2,2.e3*xp);
    605         model->setData(i, 0, valAbs);
    606         model->setData(i, 1,  valOrd);
    607     }
    608       cout << " faireDessinParmela : FAISCEAU VU  " << endl;
    609 
    610     WCartesianChart *chart = new WCartesianChart(pointsDialog->contents());
    611     chart->setModel(model);        // set the model
    612     chart->setXSeriesColumn(0);    // set the column that holds the X data
    613     chart->setLegendEnabled(true); // enable the legend
    614    
    615     chart->setType(ScatterPlot);   // set type to ScatterPlot
    616    
    617     // Typically, for mathematical functions, you want the axes to cross
    618     // at the 0 mark:
    619     chart->axis(XAxis).setLocation(ZeroValue);
    620     chart->axis(YAxis).setLocation(ZeroValue);
    621    
    622     // Provide space for the X and Y axis and title.
    623     chart->setPlotAreaPadding(80, Left);
    624     chart->setPlotAreaPadding(40, Top | Bottom);
    625     // Add the curves
    626     WDataSeries s(1, PointSeries, Y1Axis);
    627     //  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
    628     //    s.setMarker(SquareMarker);
    629     //  s.setMarkerSize(600.);
    630     //  cout << "le marker est : " << s.marker() << endl;
    631     chart->addSeries(s);
    632    
    633     chart->resize(400, 400); // WPaintedWidget must be given explicit size
     583  vector<bareParticle>& partic = beam->getParticleVector();
     584  new WText(nameOfCase_ + " : phase space " + namex + " ," + namey + " ; particle number : "+ mixedTools::intToString(partic.size()), pointsDialog->contents());
     585
     586  WStandardItemModel *model = new WStandardItemModel(partic.size(), 2, pointsDialog->contents());
     587
     588
     589  setModelComponentForPhaseSpace(model, partic, indexAbs, 0);
     590  setModelComponentForPhaseSpace(model, partic, indexOrd, 1);
     591
     592  cout << " faireDessinParmela : FAISCEAU VU  " << endl;
     593
     594  WCartesianChart *chart = new WCartesianChart(pointsDialog->contents());
     595  chart->setModel(model);        // set the model
     596  chart->setXSeriesColumn(0);    // set the column that holds the X data
     597  chart->setLegendEnabled(true); // enable the legend
     598   
     599  chart->setType(ScatterPlot);   // set type to ScatterPlot
     600   
     601  // Typically, for mathematical functions, you want the axes to cross
     602  // at the 0 mark:
     603  chart->axis(XAxis).setLocation(ZeroValue);
     604  chart->axis(YAxis).setLocation(ZeroValue);
     605   
     606  // Provide space for the X and Y axis and title.
     607  chart->setPlotAreaPadding(80, Left);
     608  chart->setPlotAreaPadding(40, Top | Bottom);
     609  // Add the curves
     610  WDataSeries s(1, PointSeries, Y1Axis);
     611  //  s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
     612  //    s.setMarker(SquareMarker);
     613  //  s.setMarkerSize(600.);
     614  //  cout << "le marker est : " << s.marker() << endl;
     615  chart->addSeries(s);
     616   
     617  chart->resize(400, 400); // WPaintedWidget must be given explicit size
    634618   
    635619   
    636620#ifdef HAS_IMAGEMAGIC
    637     Wt::WRasterImage pngImage("png", 600, 600);
    638     Wt::WPainter p(&pngImage);
    639     chart->paint(p);
    640     std::string name;
    641     name = workingDir_ + "/chart-"+sessionId ()+".png";
    642     std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
    643     pngImage.write(f);
    644     new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
     621  Wt::WRasterImage pngImage("png", 600, 600);
     622  Wt::WPainter p(&pngImage);
     623  chart->paint(p);
     624  std::string name;
     625  name = workingDir_ + "/chart-"+sessionId ()+".png";
     626  std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
     627  pngImage.write(f);
     628  new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
    645629#endif
    646630   
    647     pointsDialog->show();
    648    
    649     //  chart->setMargin(10, Top | Bottom);            // add margin vertically
    650     //  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
    651 }
    652 
    653 void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam)
     631  pointsDialog->show();
     632   
     633  //  chart->setMargin(10, Top | Bottom);            // add margin vertically
     634  //  chart->setMargin(WLength::Auto, Left | Right); // center horizontally
     635}
     636
     637void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey)
    654638{
    655639  GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false);
     
    659643  ellipseDialog->show();
    660644   
    661   new WText(nameOfCase_ + " : emittance x,x' " + mixedTools::doubleToString(beam->getUnnormalizedEmittanceX()) + " pi.mm.mrad" , ellipseDialog->contents());
     645  new WText(nameOfCase_ + " : emittance " + namex + " , " + namey + " : " + mixedTools::doubleToString(beam->getUnnormalizedEmittanceX()) + " pi.mm.mrad" , ellipseDialog->contents());
    662646  new WBreak(ellipseDialog->contents());
    663647  new WText(" xmax = " + mixedTools::doubleToString(beam->getSigmaTransportij(1,1)) + " cm ", ellipseDialog->contents());
     
    669653  vector<double> xcor;
    670654  vector<double> ycor;
    671   //  dtmanage_->getCurrentBeam()->donneesDessinEllipseXxp(xcor,ycor);
    672   beam->donneesDessinEllipseXxp(xcor,ycor);
     655  beam->donneesDessinEllipse(xcor,ycor,indexAbs, indexOrd);
     656  //  beam->donneesDessinEllipseXxp(xcor,ycor);
    673657  scatterPlot1D(ellipseDialog->contents(),xcor,ycor); 
    674658}
    675659
    676 // void PspaApplication::scatterPlot1D(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor)
    677 // {
    678 //   int nbpts = xcor.size();
    679 //   cout << " PspaApplication::scatterPlot1D nbpts = " << nbpts << endl;
    680 //   WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto);
    681 //   for (int i = 0; i < nbpts; ++i) {
    682 //     model->setData(i, 0, xcor.at(i));
    683 //     model->setData(i, 1, ycor.at(i));
    684 //     //    cout << " PspaApplication::scatterPlot1D el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl;
    685 //   }
    686 
    687 //   WCartesianChart *chart = new WCartesianChart(toto);
    688 
    689 //   chart->initLayout();
    690 
    691 //   chart->setModel(model);        // set the model
    692 //   chart->setXSeriesColumn(0);    // set the column that holds the X data
    693 //   chart->setLegendEnabled(true); // enable the legend
    694 
    695 //   chart->setType(ScatterPlot);   // set type to ScatterPlot
    696 
    697 //   // Typically, for mathematical functions, you want the axes to cross
    698 //   // at the 0 mark:
    699 //    chart->axis(XAxis).setLocation(ZeroValue);
    700 //    chart->axis(YAxis).setLocation(ZeroValue);
    701 
    702 //   // Provide space for the X and Y axis and title.
    703 // //   chart->setPlotAreaPadding(80, Left);
    704 // //   chart->setPlotAreaPadding(40, Top | Bottom);
    705 //   // Add the curves
    706 //   WDataSeries s(1, CurveSeries, Y1Axis);
    707 //   chart->addSeries(s);
    708 
    709 //   // chart->setBackground (WBrush(WColor("blue")));
    710 //   chart->resize(300, 300); // WPaintedWidget must be given explicit size
    711 
    712 // #ifdef HAS_IMAGEMAGIC
    713 //  Wt::WRasterImage pngImage("png", 600, 600);
    714 //  Wt::WPainter p(&pngImage);
    715 
    716 //  chart->paint(p);
    717 //  std::string name;
    718 //  name = workingDir_ + "/chart-"+sessionId ()+".png";
    719 //  std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary);
    720 //  pngImage.write(f);
    721 
    722 //  new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto);
    723 
    724 //  /*
    725 //  Wt::WPdfImage pdfImage("30cm", "30cm");
    726 //  Wt::WPainter p1(&pdfImage);
    727 //  chart->paint(p1);
    728 //  std::ofstream f1("chart.pdf", std::ios::out | std::ios::binary);
    729 //  pdfImage.write(f1);
    730 //  */
    731 // #endif
    732 // }
    733660
    734661
     
    818745
    819746// }
     747
     748bool PspaApplication::removePathFromConfigName(string& config) {
     749  string toExtract = workingDir_ + "/";
     750  string::size_type nn = config.find(toExtract);
     751  if ( nn == string::npos ) {
     752        GWt_dialog checkremovePath(" checking config file name", " failed to recognize path name for file  " + config, GWt_dialog::Error,true,true);
     753        checkremovePath.exec();
     754    return false;
     755  }
     756  config.replace(nn, toExtract.size(), "");
     757  return true;
     758}
    820759
    821760bool PspaApplication::removeExtensionFromConfigName(string& config)
Note: See TracChangeset for help on using the changeset viewer.