Changeset 341 in PSPA for Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc
- Timestamp:
- Feb 22, 2013, 10:07:46 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc
r340 r341 70 70 useStyleSheet ("htdocs/pspa.css"); 71 71 dtmanage_ = new dataManager(this); 72 dtmanage_->setWorkingDir(workingDir_);72 // dtmanage_->setWorkingDir(workingDir_); 73 73 /* 74 74 * The main layout is a 3x2 grid layout. … … 346 346 else { console_->addConsoleMessage("sauvegarde sur repertoire : " + workingDir_);} 347 347 nameOfCase_ = saveNameEdit_->text().toUTF8(); 348 cout << " PspaApplication::dialogSaveDone() nameOfCase_= " << nameOfCase_ << endl;348 cout << " PspaApplication::dialogSaveDone() sur fichier = " << nameOfCase_ << endl; 349 349 delete dialogSave_; 350 350 dialogSave_ = NULL; … … 359 359 { 360 360 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; 363 368 if (nameOfCase_ == "") 364 369 return; 365 370 cout << " je restaure le fichier " << fileName << endl; 366 371 dialogSave_ = NULL; 367 372 368 bool test = dtmanage_->restoreElements( nameOfCase_);373 bool test = dtmanage_->restoreElements(fileName); 369 374 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); 371 376 restoreWarning.exec(); 372 377 } … … 466 471 void PspaApplication::dessinerPhaseSpace() 467 472 { 468 toto_->clear();469 473 470 474 int typeFaisceau = choixTypeDessinFaisceau_->currentIndex(); … … 472 476 unsigned xabs = choixAbsPhase_->currentIndex(); 473 477 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 475 486 particleBeam* beam = dtmanage_->getDiagnosticBeam(index); 476 487 … … 481 492 } 482 493 483 494 toto_->clear(); 495 484 496 if ( typeFaisceau == 0 ) 485 497 { 486 498 if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation(); 487 faireDessinTransport(toto_, beam );499 faireDessinTransport(toto_, beam, xabs, yord, nameAbs, nameOrd ); 488 500 } 489 501 else if ( typeFaisceau == 1 ) 490 502 { 491 if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, xabs, yord );503 if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, xabs, yord, nameAbs, nameOrd ); 492 504 else { 493 505 GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); … … 533 545 } 534 546 535 536 void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd ) 547 void 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 574 void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey ) 537 575 { 538 576 cout << " faireDessinParmela " << endl; … … 542 580 pointsDialog->setClosable(true); 543 581 // 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 }591 582 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 634 618 635 619 636 620 #ifdef HAS_IMAGEMAGIC 637 638 639 640 641 642 643 644 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); 645 629 #endif 646 630 647 648 649 650 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 637 void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, unsigned indexAbs, unsigned indexOrd, string namex, string namey) 654 638 { 655 639 GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false); … … 659 643 ellipseDialog->show(); 660 644 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()); 662 646 new WBreak(ellipseDialog->contents()); 663 647 new WText(" xmax = " + mixedTools::doubleToString(beam->getSigmaTransportij(1,1)) + " cm ", ellipseDialog->contents()); … … 669 653 vector<double> xcor; 670 654 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); 673 657 scatterPlot1D(ellipseDialog->contents(),xcor,ycor); 674 658 } 675 659 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 model692 // chart->setXSeriesColumn(0); // set the column that holds the X data693 // chart->setLegendEnabled(true); // enable the legend694 695 // chart->setType(ScatterPlot); // set type to ScatterPlot696 697 // // Typically, for mathematical functions, you want the axes to cross698 // // 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 curves706 // 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 size711 712 // #ifdef HAS_IMAGEMAGIC713 // 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 // #endif732 // }733 660 734 661 … … 818 745 819 746 // } 747 748 bool 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 } 820 759 821 760 bool PspaApplication::removeExtensionFromConfigName(string& config)
Note: See TracChangeset
for help on using the changeset viewer.