[41] | 1 | #include <stdio.h> |
---|
[407] | 2 | #include <ctime> |
---|
[198] | 3 | |
---|
[177] | 4 | #include "GWt_pspaApplication.h" |
---|
[223] | 5 | #include "GWt_draggableImage.h" |
---|
[437] | 6 | #include "GWt_abstractElementFactory.h" |
---|
[431] | 7 | #include "GWt_serverFileSelector.h" |
---|
[449] | 8 | #include "GWt_accelerator.h" |
---|
[177] | 9 | #include "particleBeam.h" |
---|
| 10 | #include "bareParticle.h" |
---|
| 11 | #include "nomDeLogiciel.h" |
---|
| 12 | #include "mixedTools.h" |
---|
| 13 | #include "nomdElements.h" |
---|
[185] | 14 | #include "environmentVariables.h" |
---|
[230] | 15 | #include "trivaluedBool.h" |
---|
[177] | 16 | |
---|
[41] | 17 | #include <Wt/WGridLayout> |
---|
| 18 | #include <Wt/WVBoxLayout> |
---|
[54] | 19 | #include <Wt/WHBoxLayout> |
---|
[41] | 20 | #include <Wt/WImage> |
---|
[93] | 21 | #include <Wt/WMenu> |
---|
| 22 | #include <Wt/WStackedWidget> |
---|
[45] | 23 | #include <Wt/WBreak> |
---|
[54] | 24 | #include <Wt/WStandardItemModel> |
---|
[173] | 25 | #include <Wt/WFileUpload> |
---|
[200] | 26 | #include <Wt/WPainter> |
---|
[256] | 27 | #include <Wt/WScrollArea> |
---|
[324] | 28 | #include <Wt/WRadioButton> |
---|
[427] | 29 | #include <Wt/WMessageBox> |
---|
[449] | 30 | #include <Wt/WScrollArea> |
---|
| 31 | #include <Wt/WLabel> |
---|
[427] | 32 | |
---|
[436] | 33 | #define HAS_IMAGEMAGIC 1 |
---|
[416] | 34 | |
---|
[54] | 35 | using namespace Wt::Chart; |
---|
[41] | 36 | |
---|
| 37 | /* |
---|
| 38 | * The env argument contains information about the new session, and |
---|
| 39 | * the initial request. It must be passed to the WApplication |
---|
| 40 | * constructor so it is typically also an argument for your custom |
---|
| 41 | * application constructor. |
---|
[272] | 42 | */ |
---|
[41] | 43 | |
---|
[379] | 44 | PspaApplication::PspaApplication(const WEnvironment& env) : |
---|
| 45 | WApplication(env), |
---|
| 46 | applicationDefaultTitle_("portail PSPA"), |
---|
| 47 | extensionFile_(0) |
---|
[106] | 48 | { |
---|
[379] | 49 | workingDir_ = WApplication::docRoot()+ "/"+WORKINGAREA; |
---|
| 50 | nameOfCase_ = "pspa"; // default |
---|
[246] | 51 | |
---|
[379] | 52 | setTitle(applicationDefaultTitle_); // application title |
---|
| 53 | if (!wApp->environment().javaScript()) { |
---|
| 54 | new WText("<i>This examples requires that javascript support is enabled.</i>",root()); |
---|
| 55 | } |
---|
[272] | 56 | |
---|
[379] | 57 | // register the absractElementFactory |
---|
| 58 | abstractElementFactory_ = new GWt_abstractElementFactory(); |
---|
| 59 | abstractElementFactory_->setRFGunEnable(true); |
---|
| 60 | abstractElementFactory_->setDriftEnable(true); |
---|
| 61 | abstractElementFactory_->setCellEnable(true); |
---|
| 62 | abstractElementFactory_->setBendEnable(true); |
---|
| 63 | abstractElementFactory_->setSolenoEnable(true); |
---|
| 64 | abstractElementFactory_->setBeamEnable(true); |
---|
| 65 | abstractElementFactory_->setFitEnable(true); |
---|
| 66 | abstractElementFactory_->setSnapshotEnable(true); |
---|
[431] | 67 | abstractElementFactory_->setMPoleEnable(true); |
---|
[379] | 68 | |
---|
[431] | 69 | // include the styleSheetcd |
---|
[449] | 70 | WContainerWidget *mainContainerWidget = root(); |
---|
[379] | 71 | useStyleSheet("htdocs/pspa.css"); |
---|
| 72 | dtmanage_ = new dataManager(this); |
---|
[427] | 73 | |
---|
| 74 | // The main layout is a 4x3 grid layout. |
---|
[379] | 75 | WHBoxLayout *toolbarLayout = new WHBoxLayout(); |
---|
| 76 | |
---|
| 77 | WPushButton* boutonSauve = new WPushButton(); |
---|
| 78 | WPushButton* boutonRestaure = new WPushButton(); |
---|
| 79 | WPushButton* boutonLoadNew = new WPushButton(); |
---|
| 80 | WPushButton* boutonTrash = new WPushButton(); |
---|
| 81 | |
---|
| 82 | boutonSauve->setStyleClass("saveButton"); |
---|
| 83 | boutonRestaure->setStyleClass("restoreButton"); |
---|
| 84 | boutonLoadNew->setStyleClass("loadNewButton"); |
---|
| 85 | boutonTrash->setStyleClass("trashButton"); |
---|
| 86 | |
---|
| 87 | boutonSauve->setToolTip ("sauvegarder votre configuration"); |
---|
[427] | 88 | boutonRestaure->setToolTip ("restaurer la configuration depuis le serveur"); |
---|
[379] | 89 | boutonLoadNew->setToolTip ("charger une configuration"); |
---|
[455] | 90 | boutonTrash->setToolTip ("supprimer l'accélerateur"); // FIXME ! a terminer |
---|
[379] | 91 | |
---|
| 92 | boutonSauve->setMaximumSize(38,38); |
---|
| 93 | boutonSauve->setMinimumSize(38,38); |
---|
| 94 | boutonRestaure->setMaximumSize(38,38); |
---|
| 95 | boutonRestaure->setMinimumSize(38,38); |
---|
| 96 | boutonLoadNew->setMaximumSize(38,38); |
---|
| 97 | boutonLoadNew->setMinimumSize(38,38); |
---|
| 98 | boutonTrash->setMaximumSize(38,38); |
---|
| 99 | boutonTrash->setMinimumSize(38,38); |
---|
| 100 | |
---|
| 101 | boutonSauve->clicked().connect(this, &PspaApplication::sauver); |
---|
| 102 | boutonRestaure->clicked().connect(this, &PspaApplication::restaurer); |
---|
[427] | 103 | // Upload when the button is clicked. React to a succesfull upload. |
---|
[379] | 104 | boutonLoadNew->clicked().connect(this, &PspaApplication::openFileSelector); |
---|
| 105 | toolbarLayout->addWidget(boutonSauve , 0,Wt::AlignMiddle); |
---|
| 106 | toolbarLayout->addWidget(boutonRestaure , 0,Wt::AlignMiddle); |
---|
| 107 | toolbarLayout->addWidget(boutonLoadNew , 0,Wt::AlignMiddle); |
---|
| 108 | toolbarLayout->addWidget(boutonTrash , 0,Wt::AlignMiddle); |
---|
| 109 | toolbarLayout->addWidget(new WText("") , 1,Wt::AlignMiddle); |
---|
| 110 | |
---|
[449] | 111 | WGridLayout* gridLayout = new WGridLayout(mainContainerWidget); |
---|
| 112 | |
---|
[401] | 113 | WContainerWidget * toolbarLayoutContainer = new WContainerWidget(); |
---|
| 114 | toolbarLayoutContainer->setLayout(toolbarLayout); |
---|
| 115 | toolbarLayoutContainer->decorationStyle().setBackgroundImage ("/htdocs/fond_toolbar.png"); |
---|
[449] | 116 | // menu menu on the top |
---|
| 117 | gridLayout->addWidget(toolbarLayoutContainer, 1,0,1,2); |
---|
| 118 | // palette on the left |
---|
| 119 | gridLayout->addWidget(createPalette(mainContainerWidget), 2, 0); |
---|
| 120 | |
---|
| 121 | // create accelerator main widget |
---|
[474] | 122 | acceleratorContainerWidget_ = new WContainerWidget(); |
---|
| 123 | gridLayout->addWidget(acceleratorContainerWidget_, 2, 1); |
---|
[401] | 124 | |
---|
[449] | 125 | // Let column 2 take the excess space. |
---|
| 126 | gridLayout->setColumnStretch(1,1); |
---|
| 127 | // Let row 1 take the excess space. |
---|
| 128 | gridLayout->setRowStretch(2,1); |
---|
| 129 | |
---|
| 130 | |
---|
[479] | 131 | // FIXME : Have to be move in GWt_accelerator |
---|
| 132 | createAccelerator(); |
---|
| 133 | |
---|
| 134 | // set auto scrollbar if needed |
---|
| 135 | mainContainerWidget->setOverflow(WContainerWidget::OverflowAuto); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | void PspaApplication::createAccelerator() { |
---|
[474] | 140 | new GWt_accelerator(acceleratorContainerWidget_,dtmanage_); |
---|
| 141 | new WBreak(acceleratorContainerWidget_); |
---|
[449] | 142 | |
---|
[401] | 143 | |
---|
[455] | 144 | // --------------------------------------------------------------- |
---|
| 145 | // ********************* Ancien code : A supprimer *************** |
---|
| 146 | // --------------------------------------------------------------- |
---|
[481] | 147 | |
---|
[455] | 148 | /* |
---|
[474] | 149 | WScrollArea* scroll = new WScrollArea(acceleratorContainerWidget_); |
---|
[455] | 150 | scroll->setWidget(createBeamLine__deprecated()); |
---|
| 151 | scroll->setMinimumSize(300,150); |
---|
| 152 | */ |
---|
| 153 | |
---|
[474] | 154 | new WBreak(acceleratorContainerWidget_); |
---|
[379] | 155 | //----------- |
---|
[427] | 156 | |
---|
[379] | 157 | // A supprimer et a mettre en fenetre |
---|
[427] | 158 | // xx globalParam_ = createGlobalParamWidget(); |
---|
| 159 | // xx mainGridLayout->addWidget(globalParam_,3,1); |
---|
| 160 | |
---|
[428] | 161 | globalParam_ = new GWt_globalParameters(dtmanage_); |
---|
[455] | 162 | sectorParam_ = new GWt_sectorParameters(); |
---|
[474] | 163 | WWidget* dboard = createDashBoard(acceleratorContainerWidget_); |
---|
[427] | 164 | dboard->setMinimumSize(300,100); |
---|
[449] | 165 | |
---|
[474] | 166 | new WBreak(acceleratorContainerWidget_); |
---|
[449] | 167 | |
---|
[427] | 168 | //----------- |
---|
| 169 | |
---|
[379] | 170 | |
---|
[474] | 171 | new WBreak(acceleratorContainerWidget_); |
---|
[449] | 172 | |
---|
[474] | 173 | console_ = new GWt_console(acceleratorContainerWidget_); |
---|
[401] | 174 | console_->setMinimumSize(300,100); |
---|
| 175 | |
---|
| 176 | |
---|
[427] | 177 | } |
---|
[401] | 178 | |
---|
[449] | 179 | WWidget* PspaApplication::createDashBoard(WContainerWidget* parent) |
---|
[427] | 180 | { |
---|
[431] | 181 | WContainerWidget *wt= new WContainerWidget(); |
---|
| 182 | wt->setStyleClass("text"); |
---|
| 183 | WText *st= new WText("Go ahead...",wt); |
---|
[427] | 184 | |
---|
| 185 | WContainerWidget *buttons = new WContainerWidget(); |
---|
| 186 | buttons->setStyleClass("buttons"); |
---|
| 187 | WPushButton *button; |
---|
[431] | 188 | button = new WPushButton("globalParameters",buttons); |
---|
[427] | 189 | button->clicked().connect(this, &PspaApplication::messageBox1); |
---|
[436] | 190 | button = new WPushButton("sectors", buttons); |
---|
[427] | 191 | button->clicked().connect(this, &PspaApplication::messageBox2); |
---|
| 192 | |
---|
| 193 | styleSheet().addRule(".buttons","padding: 5px;"); |
---|
| 194 | styleSheet().addRule(".text", "padding: 4px 8px"); |
---|
| 195 | styleSheet().addRule("body", "margin: 0px;"); |
---|
| 196 | |
---|
[431] | 197 | WContainerWidget *cnt = new WContainerWidget(); |
---|
[427] | 198 | cnt->addWidget(buttons); |
---|
[431] | 199 | cnt->addWidget(wt); |
---|
| 200 | |
---|
[449] | 201 | WContainerWidget *result = new WContainerWidget(parent); |
---|
[431] | 202 | WPanel *panel = new WPanel(result); |
---|
| 203 | panel->setTitle("dashboard"); |
---|
[427] | 204 | panel->setCentralWidget(cnt); |
---|
[431] | 205 | |
---|
| 206 | globalParam_->setText(st); |
---|
| 207 | sectorParam_->setText(st); |
---|
[427] | 208 | return result; |
---|
[106] | 209 | } |
---|
| 210 | |
---|
[427] | 211 | void PspaApplication::messageBox1() |
---|
| 212 | { |
---|
| 213 | globalParam_->initilializeDialog(); |
---|
| 214 | return; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | void PspaApplication::messageBox2() |
---|
| 218 | { |
---|
[455] | 219 | sectorParam_->execDialog_deprecated(); |
---|
[427] | 220 | return; |
---|
| 221 | } |
---|
| 222 | |
---|
[449] | 223 | WWidget* PspaApplication::createPalette(WContainerWidget* parent) |
---|
[41] | 224 | { |
---|
[449] | 225 | WContainerWidget* palette = new WContainerWidget(parent); |
---|
[324] | 226 | vector <GWt_abstractElement*> elems = abstractElementFactory_->getAllElements(); |
---|
| 227 | for (unsigned a = 0; a < elems.size(); a++) { |
---|
| 228 | elems[a]->createDragImage(palette); |
---|
| 229 | new WBreak(palette); |
---|
| 230 | } |
---|
| 231 | return palette; |
---|
[41] | 232 | } |
---|
| 233 | |
---|
[324] | 234 | void PspaApplication::createDragImage(const char *url,const char *smallurl,const char *mimeType,WContainerWidget *p,WString()) |
---|
[106] | 235 | { |
---|
[324] | 236 | GWt_draggableImage *result = new GWt_draggableImage(url,p); |
---|
| 237 | |
---|
| 238 | /* |
---|
| 239 | * Set the image to be draggable, showing the other image (dragImage) |
---|
| 240 | * to be used as the widget that is visually dragged. |
---|
| 241 | */ |
---|
| 242 | result->setDraggable(mimeType,new WImage(smallurl,p),true); |
---|
[106] | 243 | } |
---|
| 244 | |
---|
[455] | 245 | /*Wt::WWidget* PspaApplication::createBeamLine__deprecated() |
---|
[41] | 246 | { |
---|
[379] | 247 | extensionFile_= 0; |
---|
[455] | 248 | if (!beamLine__deprecated_) { |
---|
| 249 | // FIXME : get the one of the first app/sector for the moment |
---|
| 250 | beamLine__deprecated_ = accel_toBeRenameAsLocal->firstSector__deprecated()->getUIBeamLine ? |
---|
[379] | 251 | } else { |
---|
| 252 | beamLine_->clear(); |
---|
| 253 | } |
---|
| 254 | beamLine_->setMinimumSize(300,100); |
---|
| 255 | setTitle(applicationDefaultTitle_); |
---|
[401] | 256 | |
---|
[455] | 257 | return beamLine__deprecated_; |
---|
[41] | 258 | } |
---|
[455] | 259 | */ |
---|
[41] | 260 | |
---|
[50] | 261 | void PspaApplication::sauver() |
---|
| 262 | { |
---|
[431] | 263 | cout << "***********************************" << endl; |
---|
| 264 | cout << " on sauve " << endl<<endl; |
---|
[324] | 265 | |
---|
[431] | 266 | console_->addConsoleMessage("sauvegarde \n"); |
---|
[324] | 267 | dialogSave_ = new WDialog("save"); |
---|
| 268 | new WText("name of case : ",dialogSave_->contents()); |
---|
| 269 | saveNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogSave_->contents()); |
---|
| 270 | WPushButton *annule = new WPushButton("cancel",dialogSave_->contents()); |
---|
| 271 | WPushButton *submit = new WPushButton("OK",dialogSave_->contents()); |
---|
| 272 | annule->clicked().connect(dialogSave_, &Wt::WDialog::reject); |
---|
| 273 | submit->clicked().connect(dialogSave_, &Wt::WDialog::accept); |
---|
| 274 | dialogSave_->finished().connect(this, &PspaApplication::dialogSaveDone); |
---|
| 275 | dialogSave_->show(); |
---|
[179] | 276 | } |
---|
| 277 | |
---|
[185] | 278 | void PspaApplication::dialogSaveDone(WDialog::DialogCode code) |
---|
[179] | 279 | { |
---|
[428] | 280 | if ( code != Wt::WDialog::Accepted ) { |
---|
| 281 | return; |
---|
| 282 | } |
---|
| 283 | nameOfCase_ = saveNameEdit_->text().toUTF8(); |
---|
| 284 | delete dialogSave_; |
---|
| 285 | dialogSave_ = NULL; |
---|
[347] | 286 | |
---|
[431] | 287 | //globalParam_->updateGlobals(); |
---|
[424] | 288 | |
---|
[428] | 289 | // dtmanage_->saveConfiguration(nameOfCase_); |
---|
| 290 | dtmanage_->saveConfiguration(sessionId(),nameOfCase_); |
---|
[424] | 291 | |
---|
[428] | 292 | // en test: j'ajoute la sauvegarde sur .aml |
---|
| 293 | dtmanage_->writeToAMLFile(nameOfCase_); |
---|
[50] | 294 | } |
---|
[41] | 295 | |
---|
[50] | 296 | void PspaApplication::restaurer() |
---|
| 297 | { |
---|
[431] | 298 | cout << "***********************************" << endl; |
---|
| 299 | cout << " on restaure " << endl<<endl; |
---|
| 300 | |
---|
[379] | 301 | GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_); |
---|
| 302 | string fileName = fs->exec(); |
---|
| 303 | nameOfCase_ = fileName; |
---|
| 304 | if (fileName == "") { |
---|
| 305 | return; |
---|
| 306 | } |
---|
[375] | 307 | |
---|
[431] | 308 | removePathFromConfigName(nameOfCase_); |
---|
[379] | 309 | cout << " nom sans path " << nameOfCase_ << endl; |
---|
| 310 | removeExtensionFromConfigName(nameOfCase_); |
---|
| 311 | cout << " nom sans extension " << nameOfCase_ << endl; |
---|
[431] | 312 | if (nameOfCase_ == "") return; |
---|
| 313 | cout << " PspaApplication::restaure le fichier : " << fileName << endl; |
---|
[379] | 314 | dialogSave_ = NULL; |
---|
| 315 | |
---|
| 316 | bool test = dtmanage_->restoreElements(fileName); |
---|
| 317 | if ( !test ) { |
---|
| 318 | GWt_dialog restoreWarning(" element restoring", "failure in restoring elements from file : " + fileName , GWt_dialog::Error, false,true); |
---|
| 319 | restoreWarning.exec(); |
---|
| 320 | } else { |
---|
| 321 | // Change the window title |
---|
| 322 | unsigned long found = fileName.find_last_of("/"); |
---|
| 323 | setTitle(applicationDefaultTitle_+" : "+fileName.substr(found+1)); |
---|
| 324 | } |
---|
| 325 | |
---|
[474] | 326 | // reload new elements in the GUI |
---|
| 327 | // FIXME : Don't do that in the futur ! |
---|
| 328 | // In the futur, we should be able to have lot of accelerator at the same time and each with ONE datamanager |
---|
| 329 | acceleratorContainerWidget_->clear(); |
---|
[479] | 330 | createAccelerator(); |
---|
[474] | 331 | |
---|
| 332 | globalParam_->renew(); |
---|
[436] | 333 | //sectorParam_->renew(); |
---|
[479] | 334 | console_->addConsoleMessage(WString("restauration terminee \n")); |
---|
[50] | 335 | } |
---|
| 336 | |
---|
[174] | 337 | void PspaApplication::openFileSelector() |
---|
| 338 | { |
---|
[324] | 339 | WContainerWidget *result = new WContainerWidget(); |
---|
[431] | 340 | WVBoxLayout* myLayout = new WVBoxLayout(); |
---|
[324] | 341 | uploadFileSelectorWidget_ = new WFileUpload(); |
---|
| 342 | uploadFileSelectorWidget_->setFileTextSize(40); |
---|
| 343 | myLayout->addWidget(new WText("Select the configuration file for pspa : ")); |
---|
| 344 | myLayout->addWidget(uploadFileSelectorWidget_); |
---|
| 345 | result->setLayout (myLayout); |
---|
[272] | 346 | |
---|
[324] | 347 | // Upload automatically when the user entered a file. |
---|
| 348 | uploadFileSelectorWidget_->changed().connect(uploadFileSelectorWidget_, &WFileUpload::upload); |
---|
| 349 | |
---|
| 350 | // React to a succesfull upload. |
---|
| 351 | uploadFileSelectorWidget_->uploaded().connect(this, &PspaApplication::chargerConfig); |
---|
| 352 | |
---|
| 353 | // React to a fileupload problem. |
---|
| 354 | uploadFileSelectorWidget_->fileTooLarge().connect(this, &PspaApplication::fileTooLarge); |
---|
| 355 | |
---|
| 356 | GWt_dialog* fileSelectorDialog = new GWt_dialog("Load a file",result,false); |
---|
| 357 | fileSelectorDialog->exec(); |
---|
[174] | 358 | } |
---|
| 359 | |
---|
[173] | 360 | void PspaApplication::chargerConfig() |
---|
| 361 | { |
---|
[379] | 362 | GWt_dialog* message= new GWt_dialog("File successfully upload","The file has been correctly upload to" + uploadFileSelectorWidget_->spoolFileName(),GWt_dialog::Warning,false,true); |
---|
[272] | 363 | |
---|
[379] | 364 | string nomDuFichier = (uploadFileSelectorWidget_->clientFileName()).toUTF8(); |
---|
| 365 | cout << " fichier client : " << nomDuFichier << endl; |
---|
| 366 | bool test = removeExtensionFromConfigName(nomDuFichier); |
---|
| 367 | cout << " fichier client sans extension : " << nomDuFichier << endl; |
---|
| 368 | |
---|
[431] | 369 | if ( test ) { |
---|
| 370 | nameOfCase_ = nomDuFichier; |
---|
| 371 | console_->addConsoleMessage(string("restauration...")); |
---|
[379] | 372 | |
---|
[431] | 373 | if ( !dtmanage_->restoreElements(uploadFileSelectorWidget_->spoolFileName()) ) { |
---|
| 374 | GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true); |
---|
| 375 | restoreWarning.exec(); |
---|
| 376 | } |
---|
[379] | 377 | |
---|
[431] | 378 | globalParam_->renew(); |
---|
[436] | 379 | //sectorParam_->renew(); |
---|
[431] | 380 | console_->addConsoleMessage(string("rechargement de la config termine")); |
---|
| 381 | message->show(); |
---|
| 382 | } |
---|
[173] | 383 | } |
---|
| 384 | |
---|
[175] | 385 | void PspaApplication::fileTooLarge() |
---|
| 386 | { |
---|
[379] | 387 | std::stringstream stream; |
---|
| 388 | stream << maximumRequestSize (); |
---|
| 389 | std::string maxRequestSize(stream.str()); |
---|
| 390 | |
---|
| 391 | std::string message = "This file is too large, please select a one\n"; |
---|
| 392 | message += "Maximum file size is "+ maxRequestSize; |
---|
| 393 | message += " bytes\n"; |
---|
[272] | 394 | |
---|
[431] | 395 | GWt_dialog* messageBox= new GWt_dialog("Error during upload file" ,message ,GWt_dialog::Error,false,true); |
---|
[379] | 396 | messageBox->show(); |
---|
[175] | 397 | } |
---|
| 398 | |
---|
[343] | 399 | |
---|
| 400 | |
---|
[386] | 401 | // void PspaApplication::faireDessinParmela(WContainerWidget* toto, particleBeam* beam, string namex, string namey ) |
---|
| 402 | // { |
---|
| 403 | // cout << " faireDessinParmela " << endl; |
---|
| 404 | // GWt_dialog* pointsDialog = new GWt_dialog("space phase",toto,false); |
---|
| 405 | // eDialog_.push_back(pointsDialog); |
---|
| 406 | // pointsDialog->setMinimumSize(400,400); |
---|
| 407 | // pointsDialog->setClosable(true); |
---|
| 408 | // // pointsDialog->show(); |
---|
[341] | 409 | |
---|
[386] | 410 | // new WText(nameOfCase_, pointsDialog->contents()); |
---|
[333] | 411 | |
---|
[381] | 412 | |
---|
[386] | 413 | // vector<double> xcor; |
---|
| 414 | // vector<double> ycor; |
---|
| 415 | // vector<string> legende; |
---|
| 416 | // beam->particlesPhaseSpaceData(xcor, ycor, legende, namex, namey); |
---|
| 417 | // for (int k=0 ; k < legende.size(); k++) { |
---|
| 418 | // new WBreak(pointsDialog->contents()); |
---|
| 419 | // new WText(legende.at(k), pointsDialog->contents()); |
---|
| 420 | // } |
---|
| 421 | // string titre = " phase space "; |
---|
| 422 | // chartPlot2vec(pointsDialog->contents(), xcor, ycor, true,titre,namex, namey,400,400); |
---|
[333] | 423 | |
---|
| 424 | |
---|
[272] | 425 | |
---|
[386] | 426 | // pointsDialog->show(); |
---|
[272] | 427 | |
---|
[386] | 428 | // // chart->setMargin(10, Top | Bottom); // add margin vertically |
---|
| 429 | // // chart->setMargin(WLength::Auto, Left | Right); // center horizontally |
---|
| 430 | // } |
---|
[56] | 431 | |
---|
[386] | 432 | // void PspaApplication::faireDessinTransport(WContainerWidget* toto, particleBeam* beam, string namex, string namey) |
---|
| 433 | // { |
---|
| 434 | // GWt_dialog* ellipseDialog = new GWt_dialog("ellipse",toto,false); |
---|
| 435 | // eDialog_.push_back(ellipseDialog); |
---|
| 436 | // ellipseDialog->setMinimumSize(400,400); |
---|
| 437 | // ellipseDialog->setClosable(true); |
---|
| 438 | // ellipseDialog->show(); |
---|
| 439 | // new WText(nameOfCase_, ellipseDialog->contents()); |
---|
[340] | 440 | |
---|
[386] | 441 | // vector<double> xcor; |
---|
| 442 | // vector<double> ycor; |
---|
| 443 | // vector<string> legende; |
---|
| 444 | // beam->donneesDessinEllipse(xcor,ycor,legende, namex, namey); |
---|
[371] | 445 | |
---|
[386] | 446 | // for (int k=0 ; k < legende.size(); k++) { |
---|
| 447 | // new WBreak(ellipseDialog->contents()); |
---|
| 448 | // new WText(legende.at(k), ellipseDialog->contents()); |
---|
| 449 | // } |
---|
| 450 | // string titre = "phase space rms"; |
---|
| 451 | // chartPlot2vec(ellipseDialog->contents(), xcor, ycor, false,titre, namex, namey,500,300); |
---|
| 452 | // } |
---|
[149] | 453 | |
---|
[354] | 454 | |
---|
[417] | 455 | // // parametre drawPoints : true = on trace des points (phase space) ; false = on trace des lignes (enveloppes...) |
---|
| 456 | // void PspaApplication::chartPlot2vec(WContainerWidget* toto, vector<double>& xcor, vector<double>& ycor, bool drawPoints,string title,string legendx, string legendy,int width, int height, bool makeIcon) |
---|
| 457 | // { |
---|
| 458 | // int nbpts = xcor.size(); |
---|
| 459 | // cout << " PspaApplication::chartPlot2vec nbpts = " << nbpts << endl; |
---|
| 460 | // WStandardItemModel *model = new WStandardItemModel(nbpts, 2, toto); |
---|
| 461 | // for (int i = 0; i < nbpts; ++i) { |
---|
| 462 | // model->setData(i, 0, xcor.at(i)); |
---|
| 463 | // model->setData(i, 1, ycor.at(i)); |
---|
| 464 | // // cout << " PspaApplication::chartPlot2vec el= " << i+1 << " x= " << xcor.at(i) << " y= " << ycor.at(i) << endl; |
---|
| 465 | // } |
---|
[272] | 466 | |
---|
[417] | 467 | // WCartesianChart *chart = new WCartesianChart(toto); |
---|
| 468 | // if (!makeIcon) { |
---|
| 469 | // chart->setTitle(title); |
---|
| 470 | // } |
---|
| 471 | // chart->initLayout(); |
---|
[272] | 472 | |
---|
[417] | 473 | // chart->setModel(model); // set the model |
---|
| 474 | // chart->setXSeriesColumn(0); // set the column that holds the X data |
---|
| 475 | // if (!makeIcon) { |
---|
| 476 | // chart->setLegendEnabled(true); // enable the legend |
---|
| 477 | // } else { |
---|
| 478 | // chart->setLegendEnabled(false); // enable the legend |
---|
| 479 | // } |
---|
[272] | 480 | |
---|
[417] | 481 | // chart->setType(ScatterPlot); // set type to ScatterPlot |
---|
[272] | 482 | |
---|
[417] | 483 | // // Typically, for mathematical functions, you want the axes to cross |
---|
| 484 | // // at the 0 mark: |
---|
| 485 | // chart->axis(XAxis).setLocation(ZeroValue); |
---|
| 486 | // chart->axis(YAxis).setLocation(ZeroValue); |
---|
[370] | 487 | |
---|
[417] | 488 | // // Provide space for the X and Y axis and title. |
---|
| 489 | // chart->setPlotAreaPadding(80, Left); // ? |
---|
| 490 | // chart->setPlotAreaPadding(40, Bottom); |
---|
| 491 | // chart->setPlotAreaPadding(60, Top); |
---|
| 492 | // if ( drawPoints ) { |
---|
| 493 | // WDataSeries s(1, PointSeries, Y1Axis); |
---|
| 494 | // chart->addSeries(s); |
---|
| 495 | // } else { |
---|
| 496 | // WDataSeries s(1, LineSeries, Y1Axis); |
---|
| 497 | // chart->addSeries(s); |
---|
| 498 | // } |
---|
| 499 | // chart->resize(width, height); // WPaintedWidget must be given explicit size |
---|
[393] | 500 | |
---|
| 501 | |
---|
[417] | 502 | // WAxis& axis = chart->axis(XAxis); |
---|
| 503 | // axis.setLabelFormat("%.3f"); |
---|
| 504 | // // axis.setGridLinesEnabled(true); |
---|
| 505 | // axis.setTitle(legendx); |
---|
[393] | 506 | |
---|
[417] | 507 | // WAxis& axey = chart->axis(YAxis); |
---|
| 508 | // axey.setTitle(legendy); |
---|
| 509 | // // axis = chart->axis(YAxis); |
---|
| 510 | // // axis.setLabelFormat("%.3f"); |
---|
| 511 | // // axis.setGridLinesEnabled(true); |
---|
| 512 | // // axis.setTitle(legendy); |
---|
[393] | 513 | |
---|
[417] | 514 | // if (makeIcon) { |
---|
| 515 | // chart->setPlotAreaPadding(0); |
---|
| 516 | // chart->setAxisPadding(0); |
---|
| 517 | // WFont xAxisFont = chart->axis(XAxis).labelFont(); |
---|
| 518 | // xAxisFont.setSize(8); |
---|
| 519 | // WFont yAxisFont = chart->axis(YAxis).labelFont(); |
---|
| 520 | // yAxisFont.setSize(8); |
---|
| 521 | // chart->axis(XAxis).setLabelFont(xAxisFont); |
---|
| 522 | // chart->axis(YAxis).setLabelFont(yAxisFont); |
---|
| 523 | // } |
---|
[370] | 524 | |
---|
[417] | 525 | // #ifdef HAS_IMAGEMAGIC |
---|
| 526 | // /* Wt::WRasterImage pngImage("png", 600, 600); |
---|
| 527 | // Wt::WPainter p(&pngImage); |
---|
| 528 | // chart->paint(p); |
---|
| 529 | // std::string name; |
---|
| 530 | // name = workingDir_ + "/chart-"+sessionId ()+".png"; |
---|
| 531 | // std::ofstream f(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); |
---|
| 532 | // pngImage.write(f); |
---|
| 533 | // new WText("<a href='workingArea/chart-"+sessionId ()+".png' target='_blank'>Afficher l'image</a>",toto); |
---|
[272] | 534 | |
---|
[417] | 535 | // Wt::WPdfImage pdfImage("30cm", "30cm"); |
---|
| 536 | // Wt::WPainter p1(&pdfImage); |
---|
| 537 | // pdfImage.init(); |
---|
| 538 | // chart->paint(p1); |
---|
| 539 | // name = workingDir_ + "/chart-"+sessionId ()+".pdf"; |
---|
| 540 | // std::ofstream f1(name.c_str(), std::ios::out |std::ios::trunc | std::ios::binary); |
---|
| 541 | // pdfImage.write(f1); |
---|
| 542 | // */ |
---|
| 543 | // #endif |
---|
| 544 | // } |
---|
[86] | 545 | |
---|
[58] | 546 | |
---|
[272] | 547 | WText* PspaApplication::createTitle(const WString& title) |
---|
[106] | 548 | { |
---|
[324] | 549 | WText *result = new WText(title); |
---|
| 550 | result->setInline(false); |
---|
| 551 | result->setStyleClass("title"); |
---|
| 552 | result->setMinimumSize(30,30); |
---|
| 553 | |
---|
| 554 | return result; |
---|
[93] | 555 | } |
---|
[177] | 556 | |
---|
[226] | 557 | // void PspaApplication::addConsoleMessage(WString msg) { |
---|
| 558 | // WText *w = new WText(console_); |
---|
| 559 | // w->setTextFormat(PlainText); |
---|
| 560 | // w->setText(msg); |
---|
| 561 | // w->setInline(false); |
---|
[272] | 562 | |
---|
[226] | 563 | // /* |
---|
| 564 | // * Little javascript trick to make sure we scroll along with new content |
---|
| 565 | // */ |
---|
| 566 | // WApplication *app = WApplication::instance(); |
---|
| 567 | // app->doJavaScript(console_->jsRef() + ".scrollTop += " |
---|
| 568 | // + console_->jsRef() + ".scrollHeight;"); |
---|
[272] | 569 | |
---|
[226] | 570 | // } |
---|
[185] | 571 | |
---|
[341] | 572 | bool PspaApplication::removePathFromConfigName(string& config) { |
---|
| 573 | string toExtract = workingDir_ + "/"; |
---|
| 574 | string::size_type nn = config.find(toExtract); |
---|
| 575 | if ( nn == string::npos ) { |
---|
| 576 | GWt_dialog checkremovePath(" checking config file name", " failed to recognize path name for file " + config, GWt_dialog::Error,true,true); |
---|
| 577 | checkremovePath.exec(); |
---|
| 578 | return false; |
---|
| 579 | } |
---|
| 580 | config.replace(nn, toExtract.size(), ""); |
---|
| 581 | return true; |
---|
| 582 | } |
---|
| 583 | |
---|
[185] | 584 | bool PspaApplication::removeExtensionFromConfigName(string& config) |
---|
| 585 | { |
---|
[272] | 586 | // string configName; |
---|
| 587 | string extension(".save"); |
---|
| 588 | bool test = true; |
---|
[185] | 589 | string::size_type nn = config.rfind('.'); |
---|
[272] | 590 | if ( nn == string::npos ) |
---|
| 591 | { |
---|
| 592 | // pas de point |
---|
| 593 | test = false; |
---|
| 594 | } |
---|
[185] | 595 | string fin = config.substr(nn); |
---|
[272] | 596 | if ( fin != extension ) |
---|
| 597 | { |
---|
| 598 | // l'extension n'est pas la bonne |
---|
| 599 | test = false; |
---|
| 600 | } |
---|
[185] | 601 | if ( test ) |
---|
[272] | 602 | { |
---|
| 603 | string::size_type count = config.length() - extension.length(); |
---|
| 604 | config = config.substr(0, count); |
---|
| 605 | } |
---|
[185] | 606 | else |
---|
[272] | 607 | { |
---|
| 608 | GWt_dialog checkConfigNameDialog(" checking config file name", " the file must have the extension " + extension, GWt_dialog::Error,true,true); |
---|
| 609 | checkConfigNameDialog.exec(); |
---|
| 610 | } |
---|
[185] | 611 | return test; |
---|
| 612 | } |
---|
[224] | 613 | |
---|
[324] | 614 | |
---|
[455] | 615 | /* |
---|
[376] | 616 | void PspaApplication::removeBeamLine() { |
---|
[455] | 617 | createBeamLine__deprecated(); |
---|
[401] | 618 | executeWidget_->updateSections(); |
---|
[376] | 619 | } |
---|
[455] | 620 | */ |
---|
[393] | 621 | |
---|