#include #include #include #include #include "GWt_pspaApplication.h" #include "GWt_ligneFaisceau.h" #include "GWt_softwarePanel.h" #include "GWt_globalParameters.h" // #include "GWt_dialog.h" #include "GWt_draggableImage.h" #include "particleBeam.h" #include "bareParticle.h" #include "nomDeLogiciel.h" #include "mixedTools.h" #include "nomdElements.h" #include "environmentVariables.h" #include "GWt_console.h" #include "GWt_serverFileSelector.h" #include "trivaluedBool.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define HAS_IMAGEMAGIC 1 using namespace Wt::Chart; /* * The env argument contains information about the new session, and * the initial request. It must be passed to the WApplication * constructor so it is typically also an argument for your custom * application constructor. */ PspaApplication::PspaApplication(const WEnvironment& env) : WApplication(env), applicationDefaultTitle_("portail PSPA"), beamLine_(NULL), extensionFile_(0) { workingDir_ = WApplication::docRoot()+ "/"+WORKINGAREA; nameOfCase_ = "pspa"; // default setTitle(applicationDefaultTitle_); // application title if (!wApp->environment().javaScript()) { new WText("This examples requires that javascript support is enabled.",root()); } // register the absractElementFactory abstractElementFactory_ = new GWt_abstractElementFactory(); abstractElementFactory_->setRFGunEnable(true); abstractElementFactory_->setDriftEnable(true); abstractElementFactory_->setCellEnable(true); abstractElementFactory_->setBendEnable(true); abstractElementFactory_->setSolenoEnable(true); abstractElementFactory_->setBeamEnable(true); abstractElementFactory_->setFitEnable(true); abstractElementFactory_->setSnapshotEnable(true); // include the styleSheet WContainerWidget *widroot = root(); useStyleSheet("htdocs/pspa.css"); dtmanage_ = new dataManager(this); // dtmanage_->setWorkingDir(workingDir_); /* * The main layout is a 4x3 grid layout. */ WGridLayout *mainGridLayout = new WGridLayout(); // layout->addWidget(createTitle(" Menu (In future)"), 0, 0, 1, 2); // layout->addWidget(createTitle("Menu (In future)"), 0, 0, 1, 2); WHBoxLayout *toolbarLayout = new WHBoxLayout(); WPushButton* boutonSauve = new WPushButton(); WPushButton* boutonRestaure = new WPushButton(); WPushButton* boutonLoadNew = new WPushButton(); WPushButton* boutongraphicalAnalysis = new WPushButton(); WPushButton* boutonTrash = new WPushButton(); boutonSauve->setStyleClass("saveButton"); boutonRestaure->setStyleClass("restoreButton"); boutonLoadNew->setStyleClass("loadNewButton"); boutongraphicalAnalysis->setStyleClass("histoButton"); boutonTrash->setStyleClass("trashButton"); boutonSauve->setToolTip ("sauvegarder votre configuration"); boutonRestaure->setToolTip (" restaurer la configuration depuis le serveur"); boutonLoadNew->setToolTip ("charger une configuration"); boutongraphicalAnalysis->setToolTip ("analyse graphique"); boutonTrash->setToolTip ("tout effacer"); boutonSauve->setMaximumSize(38,38); boutonSauve->setMinimumSize(38,38); boutonRestaure->setMaximumSize(38,38); boutonRestaure->setMinimumSize(38,38); boutonLoadNew->setMaximumSize(38,38); boutonLoadNew->setMinimumSize(38,38); boutongraphicalAnalysis->setMaximumSize(38,38); boutongraphicalAnalysis->setMinimumSize(38,38); boutonTrash->setMaximumSize(38,38); boutonTrash->setMinimumSize(38,38); boutonSauve->clicked().connect(this, &PspaApplication::sauver); boutonRestaure->clicked().connect(this, &PspaApplication::restaurer); // Upload when the button is clicked. // React to a succesfull upload. boutonLoadNew->clicked().connect(this, &PspaApplication::openFileSelector); boutongraphicalAnalysis->clicked().connect(this, &PspaApplication::dialogOnGraphics); boutonTrash->clicked().connect(this, &PspaApplication::removeBeamLine); toolbarLayout->addWidget(boutonSauve , 0,Wt::AlignMiddle); toolbarLayout->addWidget(boutonRestaure , 0,Wt::AlignMiddle); toolbarLayout->addWidget(boutonLoadNew , 0,Wt::AlignMiddle); toolbarLayout->addWidget(boutongraphicalAnalysis , 0,Wt::AlignMiddle); toolbarLayout->addWidget(boutonTrash , 0,Wt::AlignMiddle); toolbarLayout->addWidget(new WText("") , 1,Wt::AlignMiddle); WContainerWidget * toolbarLayoutContainer = new WContainerWidget(); toolbarLayoutContainer->setLayout(toolbarLayout); toolbarLayoutContainer->decorationStyle().setBackgroundImage ("/htdocs/fond_toolbar.png"); mainGridLayout->addWidget(toolbarLayoutContainer, 1, 0, 1, 3); mainGridLayout->addWidget(createPalette(), 2, 0, 4, 1); WScrollArea* scroll = new WScrollArea(); scroll->setWidget(createBeamLine()); scroll->setMinimumSize(300,150); mainGridLayout->addWidget(scroll, 2, 1, 1, 2); // console_ = new WContainerWidget(); // console_->decorationStyle().setBackgroundColor (WColor("lightgray")); // console_->setMaximumSize(600,200); // layout->addWidget(console_, 3, 1); // console_->setMinimumSize(300,100); // console_->setOverflow(WContainerWidget::OverflowAuto); //----------- // A supprimer et a mettre en fenetre globalParam_ = createGlobalParamWidget(); // leDessin_ = new WContainerWidget(); // leDessin_ = createDrawingWidget(); graphicsDialog_ = new GWt_dialog("graphical analysis",createDrawingWidget(),false); graphicsDialog_->setMinimumSize(400,400); graphicsDialog_->setClosable(true); graphicsDialog_->hide(); executeWidget_ = new GWt_softwarePanel(dtmanage_,this); mainGridLayout->addWidget( globalParam_, 3, 1); // layout->addWidget( leDessin_, 3, 2); mainGridLayout->addWidget( executeWidget_ , 4, 1); //----------- console_ = new GWt_console(); // manage sizes console_->setMinimumSize(300,100); executeWidget_->setMinimumSize(400,100); mainGridLayout->addWidget(console_, 3, 2,2,1); /* * Let row 2 and column 1 take the excess space. */ mainGridLayout->setRowStretch(4, 1); mainGridLayout->setColumnStretch(2, 1); widroot->setLayout(mainGridLayout); // set auto scrollbar if needed widroot->setOverflow(WContainerWidget::OverflowAuto); } WWidget* PspaApplication::createPalette() { WContainerWidget* palette = new WContainerWidget(); vector elems = abstractElementFactory_->getAllElements(); for (unsigned a = 0; a < elems.size(); a++) { elems[a]->createDragImage(palette); new WBreak(palette); } return palette; } void PspaApplication::createDragImage(const char *url,const char *smallurl,const char *mimeType,WContainerWidget *p,WString()) { GWt_draggableImage *result = new GWt_draggableImage(url,p); /* * Set the image to be draggable, showing the other image (dragImage) * to be used as the widget that is visually dragged. */ result->setDraggable(mimeType,new WImage(smallurl,p),true); } Wt::WWidget* PspaApplication::createBeamLine() { extensionFile_= 0; if (!beamLine_) { beamLine_ = new GWt_LigneFaisceau(this); } else { beamLine_->clear(); } beamLine_->setMinimumSize(300,100); setTitle(applicationDefaultTitle_); return beamLine_; } WWidget* PspaApplication::createGlobalParamWidget() { WContainerWidget* globalParam = new GWt_globalParameters(this); globalParam->setMinimumSize(300,100); return globalParam; } void PspaApplication::dialogOnGraphics() { graphicsDialog_->show(); } WContainerWidget* PspaApplication::createDrawingWidget() { WGridLayout *glayout= new WGridLayout(); WContainerWidget* dessin = new WContainerWidget(); dessin->setLayout(glayout); group_ = new Wt::WButtonGroup(this); ///////////////////////////////////////////////////////////////////// choixEnveloppeDessin_ = new WComboBox(); choixEnveloppeDessin_->addItem("x"); // choixEnveloppeDessin_->addItem("y"); Wt::WRadioButton *button1= new WRadioButton(" enveloppe"); group_->addButton(button1,1); glayout->addWidget(button1,0,1); glayout->addWidget(choixEnveloppeDessin_,0,2); ///////////////////////////////////////////////////////////////////// choixElementDessin_ = new WComboBox(); choixElementDessin_->setMinimumSize(50,10); choixTypeDessinFaisceau_ = new WComboBox(); choixTypeDessinFaisceau_->addItem("courant_snyder"); choixTypeDessinFaisceau_->addItem("macroparticles"); Wt::WRadioButton *button2= new WRadioButton(" phase space after element"); choixAbsPhase_ = new WComboBox(); choixAbsPhase_->addItem("x"); choixAbsPhase_->addItem("y"); choixAbsPhase_->addItem("dz"); choixAbsPhase_->addItem("xp"); choixAbsPhase_->addItem("yp"); choixAbsPhase_->addItem("dE/E"); choixAbsPhase_->setCurrentIndex(0); choixOrdPhase_ = new WComboBox(); choixOrdPhase_->addItem("x"); choixOrdPhase_->addItem("y"); choixOrdPhase_->addItem("dz"); choixOrdPhase_->addItem("xp"); choixOrdPhase_->addItem("yp"); choixOrdPhase_->addItem("dE/E"); choixOrdPhase_->setCurrentIndex(3); group_->addButton(button2,2); glayout->addWidget(button2,1,1); glayout->addWidget(choixElementDessin_,1,2); glayout->addWidget(choixTypeDessinFaisceau_,1,3); // glayout->addWidget(new WText("abs. :"),2,2); glayout->addWidget(choixAbsPhase_,2,2); // glayout->addWidget(new WText("ord. :"),2,4); glayout->addWidget(choixOrdPhase_,2,3); ///////////////////////////////////////////////////////////////////// choixVariableHisto_= new WComboBox(); choixVariableHisto_->addItem("x"); choixVariableHisto_->addItem("y"); choixVariableHisto_->addItem("z"); choixVariableHisto_->addItem("xp"); choixVariableHisto_->addItem("yp"); choixVariableHisto_->addItem("dE/E"); choixVariableHisto_->setCurrentIndex(5); choixHistoDessin_ = new WComboBox(); Wt::WRadioButton *button3= new WRadioButton(" histogram after element "); group_->addButton(button3,3); glayout->addWidget(button3,3,1); glayout->addWidget(choixHistoDessin_,3,2); glayout->addWidget(choixVariableHisto_,3,3); ///////////////////////////////////////////////////////////////////// WPushButton *close= new WPushButton("close"); glayout->addWidget(close,4,1); close->clicked().connect(this,&PspaApplication::closeGraphicDialog); WPushButton *draw= new WPushButton("draw"); glayout->addWidget(draw,4,2,2,1); draw->clicked().connect(this,&PspaApplication::dessiner); ///////////////////////////////////////////////////////////////////// toto_ = new WContainerWidget(); dessin->addWidget(toto_); return dessin; } void PspaApplication::closeGraphicDialog() { cout << " close graphicsDialog_" << endl; for(unsigned i = 0; i < eDialog_.size(); i++) eDialog_[i]->done(WDialog::Rejected); eDialog_.clear(); graphicsDialog_->done(WDialog::Rejected); } void PspaApplication::dessiner() { int k= group_->checkedId(); cout << "dessiner k= " << k << endl; switch(k) { case 1: dessinerEnveloppe(); break; case 2: dessinerPhaseSpace(); break; case 3: dessinerHistogramme(); break; default: GWt_dialog graphicalWarning("graphical analysis","select a button",GWt_dialog::Warning,false,true); graphicalWarning.exec(); break; } } void PspaApplication::sauver() { cout << " on sauve " << endl; console_->addConsoleMessage("sauvegarde"); dialogSave_ = new WDialog("save"); new WText("name of case : ",dialogSave_->contents()); saveNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogSave_->contents()); WPushButton *annule = new WPushButton("cancel",dialogSave_->contents()); WPushButton *submit = new WPushButton("OK",dialogSave_->contents()); annule->clicked().connect(dialogSave_, &Wt::WDialog::reject); submit->clicked().connect(dialogSave_, &Wt::WDialog::accept); dialogSave_->finished().connect(this, &PspaApplication::dialogSaveDone); dialogSave_->show(); } void PspaApplication::dialogSaveDone(WDialog::DialogCode code) { if ( code != Wt::WDialog::Accepted ) { return; } nameOfCase_ = saveNameEdit_->text().toUTF8(); delete dialogSave_; dialogSave_ = NULL; GWt_globalParameters* bibi = static_cast(globalParam_); bibi->updateGlobals(); // dtmanage_->saveConfiguration(nameOfCase_); dtmanage_->saveConfiguration(sessionId(),nameOfCase_); } void PspaApplication::restaurer() { GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_); string fileName = fs->exec(); nameOfCase_ = fileName; if (fileName == "") { return; } removePathFromConfigName(nameOfCase_ ); cout << " nom sans path " << nameOfCase_ << endl; removeExtensionFromConfigName(nameOfCase_); cout << " nom sans extension " << nameOfCase_ << endl; if (nameOfCase_ == "") return; cout << " je restaure le fichier " << fileName << endl; dialogSave_ = NULL; bool test = dtmanage_->restoreElements(fileName); if ( !test ) { GWt_dialog restoreWarning(" element restoring", "failure in restoring elements from file : " + fileName , GWt_dialog::Error, false,true); restoreWarning.exec(); } else { // Change the window title unsigned long found = fileName.find_last_of("/"); setTitle(applicationDefaultTitle_+" : "+fileName.substr(found+1)); } GWt_globalParameters* bibi = static_cast(globalParam_); bibi->renew(); console_->addConsoleMessage(string("restauration terminee \n")); } void PspaApplication::openFileSelector() { WContainerWidget *result = new WContainerWidget(); WVBoxLayout* myLayout = new WVBoxLayout(); uploadFileSelectorWidget_ = new WFileUpload(); uploadFileSelectorWidget_->setFileTextSize(40); myLayout->addWidget(new WText("Select the configuration file for pspa : ")); myLayout->addWidget(uploadFileSelectorWidget_); result->setLayout (myLayout); // Upload automatically when the user entered a file. uploadFileSelectorWidget_->changed().connect(uploadFileSelectorWidget_, &WFileUpload::upload); // React to a succesfull upload. uploadFileSelectorWidget_->uploaded().connect(this, &PspaApplication::chargerConfig); // React to a fileupload problem. uploadFileSelectorWidget_->fileTooLarge().connect(this, &PspaApplication::fileTooLarge); GWt_dialog* fileSelectorDialog = new GWt_dialog("Load a file",result,false); fileSelectorDialog->exec(); } void PspaApplication::chargerConfig() { GWt_dialog* message= new GWt_dialog("File successfully upload","The file has been correctly upload to" + uploadFileSelectorWidget_->spoolFileName(),GWt_dialog::Warning,false,true); string nomDuFichier = (uploadFileSelectorWidget_->clientFileName()).toUTF8(); cout << " fichier client : " << nomDuFichier << endl; bool test = removeExtensionFromConfigName(nomDuFichier); cout << " fichier client sans extension : " << nomDuFichier << endl; if ( test ) { nameOfCase_ = nomDuFichier; console_->addConsoleMessage(string("restauration...")); if ( !dtmanage_->restoreElements(uploadFileSelectorWidget_->spoolFileName()) ) { GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true); restoreWarning.exec(); } GWt_globalParameters* bibi = static_cast(globalParam_); bibi->renew(); console_->addConsoleMessage(string("rechargement de config termine")); message->show(); } } void PspaApplication::fileTooLarge() { std::stringstream stream; stream << maximumRequestSize (); std::string maxRequestSize(stream.str()); std::string message = "This file is too large, please select a one\n"; message += "Maximum file size is "+ maxRequestSize; message += " bytes\n"; GWt_dialog* messageBox= new GWt_dialog("Error during upload file" ,message ,GWt_dialog::Error,false,true); messageBox->show(); } void PspaApplication::faireDessin() { choixElementDessin_->clear(); choixHistoDessin_->clear(); int nombre = dtmanage_->getBeamLineSize(); for(int i = 1; i <= nombre; i++) { abstractElement* elPtr = dtmanage_->getElementPointerFromNumero(i); // if(elPtr->getNomdElement().getElementType() == snapshot) continue; choixElementDessin_->addItem(elPtr->getLabel()); choixHistoDessin_->addItem(elPtr->getLabel()); } } void PspaApplication::dessinerPhaseSpace() { int typeFaisceau = choixTypeDessinFaisceau_->currentIndex(); // int index = choixElementDessin_->currentIndex(); string nameAbs = choixAbsPhase_->currentText().toUTF8(); string nameOrd = choixOrdPhase_->currentText().toUTF8(); if ( nameAbs == nameOrd ) { GWt_dialog phaseSpaceError(" graphical analysis", "the beam coordinates must be different !", GWt_dialog::Error, false,true); phaseSpaceError.exec(); return; } string elementLabel = choixElementDessin_->currentText().toUTF8(); particleBeam* beam = dtmanage_->getDiagnosticBeam(elementLabel); // particleBeam* beam = dtmanage_->getDiagnosticBeam(index); if ( beam == NULL ) { GWt_dialog warningBeamState(" graphical analysis", "the beam does not exist at the end of this element !", GWt_dialog::Error, false,true); warningBeamState.exec(); return; } toto_->clear(); faireDessinPhaseSpace(toto_, beam, elementLabel, nameAbs, nameOrd, typeFaisceau); // if ( typeFaisceau == 0 ) // { // if ( !beam->momentRepresentationOk() ) beam->buildMomentRepresentation(); // faireDessinTransport(toto_, beam, nameAbs, nameOrd ); // } // else if ( typeFaisceau == 1 ) // { // if ( beam->particleRepresentationOk() ) faireDessinParmela(toto_, beam, nameAbs, nameOrd ); // else { // GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); // warningBeamState.exec(); // } // } // else { // GWt_dialog warningTypeDrawing(" graphical analysis", "type of drawing not programmed !", GWt_dialog::Error, false,true); // warningTypeDrawing.exec(); // } } void PspaApplication::dessinerEnveloppe() { toto_->clear(); int typeEnveloppe = choixEnveloppeDessin_->currentIndex(); if ( typeEnveloppe == 0 ) { faireDessinEnveloppe(toto_, "x"); } else { GWt_dialog warningTypeEnveloppe(" graphical analysis", "type of enveloppe drawing not programmed !", GWt_dialog::Error, false,true); warningTypeEnveloppe.exec(); } } void PspaApplication::faireDessinEnveloppe(WContainerWidget* toto, string type) { std::time_t result = std::time(NULL); GWt_dialog* envDialog = new GWt_dialog(WString("enveloppe     (")+std::asctime(std::localtime(&result))+")",toto,false); eDialog_.push_back(envDialog); envDialog->setMinimumSize(400,400); envDialog->setClosable(true); envDialog->show(); // unsigned nbel = dtmanage_->getBeamLineSize(); vector xcor; vector ycor; string titre; string legendx; string legendy; dtmanage_->donneesRmsEnveloppe(type,xcor,ycor,titre,legendx,legendy); Wt::Chart::SeriesType seriesType = LineSeries; Wt::Chart::FillRangeType fillRange = NoFill; Wt::Chart::AxisValue location = ZeroValue; bool isGridLinesEnabled = false; chartPlot2vec(envDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,legendx,legendy,500,300); } void PspaApplication::faireDessinPhaseSpace(WContainerWidget* toto, particleBeam* beam, string elementLabel, string namex, string namey, int typeFaisceau) { vector xcor; vector ycor; vector legende; string titre; Wt::Chart::SeriesType seriesType; if ( typeFaisceau == 0 ) { seriesType = LineSeries; titre = "phase space rms"; beam->donneesDessinEllipse(xcor,ycor,legende,namex,namey); } else if ( typeFaisceau == 1 ) { seriesType = PointSeries; titre = " phase space "; beam->particlesPhaseSpaceData(xcor,ycor,legende,namex,namey); } else { GWt_dialog warningBeamState(" graphical analysis", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); warningBeamState.exec(); return; } std::time_t result = std::time(NULL); GWt_dialog* phaseSpaceDialog = new GWt_dialog(WString("phase space     (")+std::asctime(std::localtime(&result))+")",toto,false); eDialog_.push_back(phaseSpaceDialog); phaseSpaceDialog->setMinimumSize(400,400); phaseSpaceDialog->setClosable(true); new WText(" case : " + nameOfCase_, phaseSpaceDialog->contents()); new WBreak(phaseSpaceDialog->contents()); new WText(" after element : " + elementLabel, phaseSpaceDialog->contents()); for (int k=0 ; k < legende.size(); k++) { new WBreak(phaseSpaceDialog->contents()); new WText(legende.at(k), phaseSpaceDialog->contents()); } Wt::Chart::FillRangeType fillRange = NoFill; Wt::Chart::AxisValue location = ZeroValue; bool isGridLinesEnabled = false; chartPlot2vec(phaseSpaceDialog->contents(),xcor,ycor,seriesType,fillRange,location,isGridLinesEnabled,titre,namex,namey,500,300); phaseSpaceDialog->show(); } // void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, string namex, string namey ) // { // cout << " faireDessinParmela " << endl; // GWt_dialog* pointsDialog = new GWt_dialog("space phase",toto,false); // eDialog_.push_back(pointsDialog); // pointsDialog->setMinimumSize(400,400); // pointsDialog->setClosable(true); // // pointsDialog->show(); // new WText(nameOfCase_, pointsDialog->contents()); // vector xcor; // vector ycor; // vector legende; // beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey); // for (int k=0 ; k < legende.size(); k++) { // new WBreak(pointsDialog->contents()); // new WText(legende.at(k), pointsDialog->contents()); // } // string titre = " phase space "; // chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,titre,namex, namey,400,400); // pointsDialog->show(); // // chart->setMargin(10, Top | Bottom); // add margin vertically // // chart->setMargin(WLength::Auto, Left | Right); // center horizontally // } // void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, string namex, string namey) // { // GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false); // eDialog_.push_back(ellipseDialog); // ellipseDialog->setMinimumSize(400,400); // ellipseDialog->setClosable(true); // ellipseDialog->show(); // new WText(nameOfCase_, ellipseDialog->contents()); // vector xcor; // vector ycor; // vector legende; // beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey); // for (int k=0 ; k < legende.size(); k++) { // new WBreak(ellipseDialog->contents()); // new WText(legende.at(k), ellipseDialog->contents()); // } // string titre = "phase space rms"; // chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,titre, namex, namey,500,300); // } // parametre drawPoints : true = on trace des points (phase space) ; false = on trace des lignes (enveloppes...) void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector& xcor, vector& ycor, bool drawPoints,string title,string legendx, string legendy,int width, int height, bool makeIcon) { int nbpts = xcor.size(); cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl; WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto); for (int i = 0; i < nbpts; ++i) { model->setData(i, 0, xcor.at(i)); model->setData(i, 1, ycor.at(i)); // cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl; } WCartesianChart *chart = new WCartesianChart(toto); if (!makeIcon) { chart->setTitle(title); } chart->initLayout(); chart->setModel(model); // set the model chart->setXSeriesColumn(0); // set the column that holds the X data if (!makeIcon) { chart->setLegendEnabled(true); // enable the legend } else { chart->setLegendEnabled(false); // enable the legend } chart->setType(ScatterPlot); // set type to ScatterPlot // Typically, for mathematical functions, you want the axes to cross // at the 0 mark: chart->axis(XAxis).setLocation(ZeroValue); chart->axis(YAxis).setLocation(ZeroValue); // Provide space for the X and Y axis and title. chart->setPlotAreaPadding(80, Left); // ? chart->setPlotAreaPadding(40, Bottom); chart->setPlotAreaPadding(60, Top); if ( drawPoints ) { WDataSeries s(1, PointSeries, Y1Axis); chart->addSeries(s); } else { WDataSeries s(1, LineSeries, Y1Axis); chart->addSeries(s); } chart->resize(width, height); // WPaintedWidget must be given explicit size WAxis& axis = chart->axis(XAxis); axis.setLabelFormat("%.3f"); // axis.setGridLinesEnabled(true); axis.setTitle(legendx); WAxis& axey = chart->axis(YAxis); axey.setTitle(legendy); // axis = chart->axis(YAxis); // axis.setLabelFormat("%.3f"); // axis.setGridLinesEnabled(true); // axis.setTitle(legendy); if (makeIcon) { chart->setPlotAreaPadding(0); chart->setAxisPadding(0); WFont xAxisFont = chart->axis(XAxis).labelFont(); xAxisFont.setSize(8); WFont yAxisFont = chart->axis(YAxis).labelFont(); yAxisFont.setSize(8); chart->axis(XAxis).setLabelFont(xAxisFont); chart->axis(YAxis).setLabelFont(yAxisFont); } #ifdef HAS_IMAGEMAGIC /* Wt::WRasterImage pngImage("png", 600, 600); Wt::WPainter p(&pngImage); chart->paint(p); std::string name; name = workingDir_ + "/chart-"+sessionId ()+".png"; std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); pngImage.write(f); new WText("Afficher l'image",toto); Wt::WPdfImage pdfImage("30cm", "30cm"); Wt::WPainter p1(&pdfImage); pdfImage.init(); chart->paint(p1); name = workingDir_ + "/chart-"+sessionId ()+".pdf"; std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); pdfImage.write(f1); */ #endif } WText* PspaApplication::createTitle(const WString& title) { WText *result = new WText(title); result->setInline(false); result->setStyleClass("title"); result->setMinimumSize(30,30); return result; } // void PspaApplication::addConsoleMessage(WString msg) { // WText *w = new WText(console_); // w->setTextFormat(PlainText); // w->setText(msg); // w->setInline(false); // /* // * Little javascript trick to make sure we scroll along with new content // */ // WApplication *app = WApplication::instance(); // app->doJavaScript(console_->jsRef() + ".scrollTop += " // + console_->jsRef() + ".scrollHeight;"); // } bool PspaApplication::removePathFromConfigName(string& config) { string toExtract = workingDir_ + "/"; string::size_type nn = config.find(toExtract); if ( nn == string::npos ) { GWt_dialog checkremovePath(" checking config file name", " failed to recognize path name for file " + config, GWt_dialog::Error,true,true); checkremovePath.exec(); return false; } config.replace(nn, toExtract.size(), ""); return true; } bool PspaApplication::removeExtensionFromConfigName(string& config) { // string configName; string extension(".save"); bool test = true; string::size_type nn = config.rfind('.'); if ( nn == string::npos ) { // pas de point test = false; } string fin = config.substr(nn); if ( fin != extension ) { // l'extension n'est pas la bonne test = false; } if ( test ) { string::size_type count = config.length() - extension.length(); config = config.substr(0, count); } else { GWt_dialog checkConfigNameDialog(" checking config file name", " the file must have the extension " + extension, GWt_dialog::Error,true,true); checkConfigNameDialog.exec(); } return test; } void PspaApplication::removeBeamLine() { createBeamLine(); executeWidget_->updateSections(); } void PspaApplication::chartPlot2vec(WContainerWidget* toto,vector& xcor,vector& ycor,SeriesType seriesType,FillRangeType fillRange,AxisValue value,bool isGridLinesEnables,string title,string legendx,string legendy,int width,int height,bool makeIcon) { int nbpts = xcor.size(); cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl; WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto); for (int i = 0; i < nbpts; ++i) { model->setData(i, 0, xcor.at(i)); model->setData(i, 1, ycor.at(i)); // cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl; } WCartesianChart *chart = new WCartesianChart(toto); if (!makeIcon) chart->setTitle(title); chart->initLayout(); chart->setModel(model); // set the model chart->setXSeriesColumn(0); // set the column that holds the X data chart->setType(ScatterPlot); // set type to ScatterPlot chart->setLegendEnabled(false); // enable the legend // Provide space for the X and Y axis and title. chart->setPlotAreaPadding(80, Left); chart->setPlotAreaPadding(40, Bottom); chart->setPlotAreaPadding(60, Top); // Typically, for mathematical functions, you want the axes to cross // at the 0 mark (value= ZeroValue) chart->axis(XAxis).setLocation(value); chart->axis(YAxis).setLocation(value); WDataSeries s(1,seriesType); s.setPen(WColor("red")); s.setFillRange(fillRange); chart->addSeries(s); WAxis& axis = chart->axis(XAxis); axis.setLabelFormat("%.3f"); axis.setTitle(legendx); chart->axis(Y1Axis).setTitle(legendy); if(isGridLinesEnables) { axis.setGridLinesEnabled(true); chart->axis(Y1Axis).setGridLinesEnabled(true); } chart->resize(width,height); // WPaintedWidget must be given explicit size chart->setMargin(10, Top | Bottom); // ? chart->setMargin(WLength::Auto, Left | Right); //? if (makeIcon) { chart->setLegendEnabled(false); // enable the legend chart->setPlotAreaPadding(0); chart->setAxisPadding(0); WFont xAxisFont = chart->axis(XAxis).labelFont(); xAxisFont.setSize(8); WFont yAxisFont = chart->axis(YAxis).labelFont(); yAxisFont.setSize(8); chart->axis(XAxis).setLabelFont(xAxisFont); chart->axis(YAxis).setLabelFont(yAxisFont); } #ifdef HAS_IMAGEMAGIC // no background chart->setBackground(WBrush(Wt::NoBrush)); // axis black chart->axis(XAxis).setPen(WColor("black")); chart->axis(YAxis).setPen(WColor("black")); std::string name; /* Wt::WRasterImage pngImage("png", 1000, 1000); Wt::WPainter p(&pngImage); chart->paint(p); name = workingDir_ + "/chart-"+sessionId ()+".png"; std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); pngImage.write(f); */ Wt::WPdfImage pdfImage("1000", "600"); { Wt::WPainter p1(&pdfImage); chart->paint(p1); } name = workingDir_ + "/chart-"+sessionId ()+".pdf"; std::ofstream f1(name.c_str(), std::ios::out | std::ios::binary); pdfImage.write(f1); new WText("Sauvegarder l'image",toto); #endif } void PspaApplication::dessinerHistogramme() { toto_->clear(); // std::time_t result = std::time(NULL); // GWt_dialog* histoDialog = new GWt_dialog(WString("histogramme     (")+std::asctime(std::localtime(&result))+")",toto_,false); // eDialog_.push_back(histoDialog); // histoDialog->setMinimumSize(400,400); // histoDialog->setClosable(true); string elementLabel = choixHistoDessin_->currentText().toUTF8(); particleBeam* beam = dtmanage_->getDiagnosticBeam(elementLabel); if (beam == NULL) { GWt_dialog warningBeamState("histogram","the beam does not exist at the end of this element !", GWt_dialog::Error, false,true); warningBeamState.exec(); return; } if (!beam->particleRepresentationOk()) { GWt_dialog warningBeamState("histogram", "the beam state does not allow providing a drawing with macroparticles !", GWt_dialog::Error, false,true); warningBeamState.exec(); return; } unsigned iabs= choixVariableHisto_->currentIndex(); vector xcor; vector hist; // double out[3]= {0.0}; vector legende; beam->histogramme(iabs,xcor,hist,legende); cout<<"xcor.size()= "<setMinimumSize(400,400); histoDialog->setClosable(true); histoDialog->show(); WContainerWidget *w= histoDialog->contents(); // // legendes // string unites[2]; // if(iabs == 0 || iabs == 1 || iabs == 2) { // unites[0]= unites[1]= " mm"; // } // if(iabs == 3 || iabs == 4) { // unites[0]= unites[1]= " mrad"; // } // if(iabs == 5) { // unites[0]= " MeV"; unites[1]= " KeV"; // } new WText(" case : " + nameOfCase_, w); new WBreak(w); new WText(" after element : " + elementLabel, w); for (int k=0 ; k < legende.size(); k++) { new WBreak(w); new WText(legende.at(k), w); } // new WText(" entries : "+ mixedTools::intToString((int)out[0]),w); // new WBreak(w); // new WText(" mean : "+ mixedTools::doubleToString(out[1])+unites[0],w); // new WBreak(w); // new WText(" sigma rms : "+ mixedTools::doubleToString(out[2])+unites[1],w); ////////////////////////////////////////////////////////////////////////////////// string titre; if(iabs == 0) titre="x-coordinate"; if(iabs == 1) titre="y-coordinate"; if(iabs == 2) titre="z-coordinate"; if(iabs == 3) titre="xp-divergence"; if(iabs == 4) titre="yp-devergence"; if(iabs == 5) titre="kinetic energy"; string xname; if(iabs == 0) xname=" x (mm)"; if(iabs == 1) xname=" y (mm)"; if(iabs == 2) xname=" z (mm)"; if(iabs == 3) xname=" xp (mrad)"; if(iabs == 4) xname=" yp (mrad)"; if(iabs == 5) xname=" dEcin/Ecin (%)"; string yname; Wt::Chart::SeriesType seriesType = LineSeries; Wt::Chart::FillRangeType fillRange = ZeroValueFill; Wt::Chart::AxisValue location = MinimumValue; bool isGridLinesEnabled = true; chartPlot2vec(w,x,y,seriesType,fillRange,location,isGridLinesEnabled,titre,xname,yname,500,300); }