Changeset 336 in PSPA


Ignore:
Timestamp:
Feb 20, 2013, 2:55:48 PM (11 years ago)
Author:
garnier
Message:

bug #43 fixed

Location:
Interface_Web/trunk/pspaWT
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/History

    r329 r336  
    55     PSPA - Plateforme de simulation en physique des accélérateurs
    66     =========================================================
     7
     820 Février 2013 Laurent Garnier
     9- requierements : Remise mise en place d'une seule librarie, encore du travail
     10  à faire avant de séparer tout en M-V-C
     11- Ajout de la classe GWt_serverFileSelector pour permettre la lecture de fichiers
     12  de config sur le serveur
    713
    81419 Février 2013 Laurent Garnier
  • Interface_Web/trunk/pspaWT/cmt/requirements

    r335 r336  
    5252 ../sources/userInterface/src/GWt_softwarePanel.cc \
    5353 ../sources/userInterface/src/GWt_draggableImage.cc \
    54  ../sources/userInterface/src/GWt_serverFileSelector
     54 ../sources/userInterface/src/GWt_serverFileSelector.cc
    5555
    5656
     
    5959macro PSPA_Lib_shlibflags   " ${Wt_linkopts} ${boost_linkopts} ${dld_linkopts}"
    6060
    61 macro PSPA_Lib_linkopts     " -L${PSPAWTROOT}/${Platform_bin} -lPSPA_userInterfaceLib "
     61macro PSPA_Lib_linkopts     " -L${PSPAWTROOT}/${Platform_bin} -lPSPA_Lib "
    6262
    6363
  • Interface_Web/trunk/pspaWT/sources/controler/src/beam2Moments.cc

    r257 r336  
    9090    getline(inp, buf);
    9191    stringstream str(buf);
    92     test = str >> bidon >>  bidString >>  bidon >>  ( rij_secondOrderMoments_.at(0) ).at(0) >> bidString;
     92      test = str >> bidon >>  bidString >>  bidon >>  ( rij_secondOrderMoments_.at(0) ).at(0) >> bidString;
    9393    cout << " beam2Moments::readFromTransportOutput TEST= " << test << endl;
    9494  }
  • Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc

    r316 r336  
    240240    cout << "dataManager::restoreElements() fichier " << inputFileName << endl;
    241241    ifstream infile;
    242     string name = workingDir_ + inputFileName + ".save";
     242    string name = inputFileName;
    243243    infile.open(name.c_str(), ios::in);
    244244    if (!infile) {
  • Interface_Web/trunk/pspaWT/sources/controler/src/particleBeam.cc

    r324 r336  
    88#include <sstream>
    99//#include "environmentVariables.h"
    10 #include <Wt/WApplication>
    11 
    1210using namespace std;
    1311
  • Interface_Web/trunk/pspaWT/sources/userInterface/include/GWt_dialog.h

    r299 r336  
    99
    1010/**
    11  Créer une fenêtre de dialogue et permet de la paramètres facilement
    12  @param titre : titre de la fenêtre
    13  @param icon : icone à afficher dans le corps de la boite (Warning, Error, Info, Wait, NoIcon)
    14  @param modal : true si cette fenêtre doit être bloquante
    15  @param okButton : true pour fermer cette fenêtre avec un bouton "ok". false n'affiche aucun bouton
     11 CrÈer une fenÍtre de dialogue et permet de la paramËtres facilement
     12 @param titre : titre de la fenÍtre
     13 @param icon : icone ‡ afficher dans le corps de la boite (Warning, Error, Info, Wait, NoIcon)
     14 @param modal : true si cette fenÍtre doit Ítre bloquante
     15 @param okButton : true pour fermer cette fenÍtre avec un bouton "ok". false n'affiche aucun bouton
    1616 */
    1717
  • Interface_Web/trunk/pspaWT/sources/userInterface/include/GWt_pspaApplication.h

    r333 r336  
    6767  WWidget* createExecuteWidget();
    6868  WContainerWidget* createDrawingWidget();
     69 
    6970  void closeGraphicDialog();
    7071 
     
    7273  void sauver();
    7374  void dialogSaveDone(WDialog::DialogCode code);
    74   void dialogOpenDone(WDialog::DialogCode code);
    7575  void restaurer();
    7676  void chargerConfig();
     
    9090  void dessinerPhaseSpace();
    9191  void dessinerHistogramme();
    92    
    93    
    94      
    9592
    96    
    97  public :
     93    public :
    9894 
    9995  PspaApplication(const WEnvironment& env);
  • Interface_Web/trunk/pspaWT/sources/userInterface/include/GWt_serverFileSelector.h

    r330 r336  
    1 #ifndef GWt_serverFileSelector
    2 #define GWt_serverFileSelector
     1#ifndef GWT_SERVERFILESELECTOR
     2#define GWT_SERVERFILESELECTOR
     3
     4#include "GWt_dialog.h"
    35
    46#include <Wt/WDialog>
    57#include <Wt/WString>
    68#include <Wt/WContainerWidget>
     9#include <Wt/WTree>
    710
    811using namespace Wt;
     
    1619 */
    1720
    18 class GWt_serverFileSelector : public WDialog
     21class GWt_serverFileSelector : public GWt_dialog
    1922{
    20    
     23
    2124    public :
    22    
    23     enum        iconType { Warning, Error, Info, Wait, NoIcon };
    2425   
    2526    /** Add a dialog with the given container inside
     
    2829     @param container: a valid WContainer
    2930     */
    30     GWt_serverFileSelector(WString titre, WContainerWidget* container, bool modal=false);
     31    GWt_serverFileSelector(WString titre, std::string wd);
     32
     33    /**  open this dialog and return the selected file or "" if not
     34     */
     35    std::string exec();
    3136   
    32     /** Add a full dialog window configure with title, message, iconType and button
    33      @param titre: A title displayed on the window title bar
    34      @param message: The message inside this dialog
    35      @param icon: IconType, could be Warning, Error, Info, Wait or NoIcon
    36      @param modal: true for a blocking dialog, false for a non-blocking dialog
    37      @param okButton: true if you want a "ok" button at the end
     37    private :
     38    void buildConfigurationFileTree(Wt::WTreeNode *root, const char* folder, const char* pattern);
     39    Wt::WTree *treeRoot_;
     40
     41    /** working directory for this file selector
    3842     */
    39     GWt_serverFileSelector(WString titre, WString message, iconType icon=NoIcon, bool modal=false, bool okButton=false);
     43    std::string workingDir_;
    4044};
    4145#endif
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_dialog.cc

    r301 r336  
    1313                       bool modal
    1414                       ):
    15 WDialog(titre)
     15WDialog(titre+"   ")
    1616{
    1717   
     
    1919    titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220));
    2020   
    21     WContainerWidget* widgt = new WContainerWidget(contents());
    22     WHBoxLayout* hLayout = new WHBoxLayout();
    23     hLayout->addWidget(wc);
    24     widgt->setLayout(hLayout);
     21    if (wc != NULL) {
     22        WContainerWidget* widgt = new WContainerWidget(contents());
     23        WHBoxLayout* hLayout = new WHBoxLayout();
     24        hLayout->addWidget(wc);
     25        widgt->setLayout(hLayout);
     26    }
    2527   
    2628    setClosable(true);
     
    109111
    110112
     113
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_elementLigneFaisceau.cc

    r310 r336  
    183183                 
    184184                 if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
    185                  pspa_->addConsoleMessage("type trouvé");
     185                 pspa_->addConsoleMessage("type trouvÈ");
    186186                 } else {
    187                  pspa_->addConsoleMessage("type trouvé NOT ");
     187                 pspa_->addConsoleMessage("type trouvÈ NOT ");
    188188                 }
    189189                 */
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_pspaApplication.cc

    r333 r336  
    1616#include "environmentVariables.h"
    1717#include "GWt_console.h"
     18#include "GWt_serverFileSelector.h"
    1819#include "trivaluedBool.h"
    1920
     
    348349}
    349350
     351
    350352void PspaApplication::restaurer()
    351353{
    352     console_->addConsoleMessage(string("on va recharger..."));
    353     dialogOpen_ = new WDialog("open");
    354     new WText("name of case : ",dialogOpen_->contents());
    355     openNameEdit_ = new WLineEdit(nameOfCase_.c_str(), dialogOpen_->contents());
    356     WPushButton *annule = new WPushButton("cancel",dialogOpen_->contents());
    357     WPushButton *submit = new WPushButton("OK",dialogOpen_->contents());
    358     annule->clicked().connect(dialogOpen_, &Wt::WDialog::reject);
    359     submit->clicked().connect(dialogOpen_, &Wt::WDialog::accept);
    360     dialogOpen_->finished().connect(this, &PspaApplication::dialogOpenDone);
    361     dialogOpen_->show();
    362 }
    363 
    364 void PspaApplication::dialogOpenDone(WDialog::DialogCode code)
    365 {   
    366   if (code != Wt::WDialog::Accepted) {
    367     console_->addConsoleMessage(" pas de restauration");
    368     return;
    369   } else {
    370     console_->addConsoleMessage("restauration depuis le repertoire " + workingDir_ );
    371   }
    372    
    373   nameOfCase_ = openNameEdit_->text().toUTF8();
    374   cout << " PspaApplication::dialogOpenDone() nameOfCase_= " << nameOfCase_ << endl;
    375   delete dialogOpen_;
    376   dialogSave_ = NULL;
    377  
    378   bool test = dtmanage_->restoreElements(nameOfCase_);
    379   if ( !test ) {
    380     GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
    381     restoreWarning.exec();
    382   }
    383  
    384   GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
    385   bibi->renew();
    386  
    387   console_->addConsoleMessage(string("...terminee"));
    388 }
     354    GWt_serverFileSelector * fs = new GWt_serverFileSelector("Select a configuration file",workingDir_);
     355    nameOfCase_ = fs->exec();
     356   
     357    dialogSave_ = NULL;
     358   
     359    bool test = dtmanage_->restoreElements(nameOfCase_);
     360    if ( !test ) {
     361        GWt_dialog restoreWarning(" element restoring", "failure in restoring elements !", GWt_dialog::Error, false,true);
     362        restoreWarning.exec();
     363    }
     364   
     365    GWt_globalParameters* bibi = static_cast<GWt_globalParameters*>(globalParam_);
     366    bibi->renew();
     367   
     368    console_->addConsoleMessage(string("...terminee"));
     369}
     370
    389371
    390372void PspaApplication::openFileSelector()
  • Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_serverFileSelector.cc

    r330 r336  
    11#include <Wt/WVBoxLayout>
     2#include <Wt/WHBoxLayout>
    23#include <Wt/WImage>
    34#include <Wt/WText>
     
    67#include <Wt/WPushButton>
    78#include <Wt/WCssDecorationStyle>
     9#include <Wt/WTree>
     10#include <Wt/WTreeNode>
     11#include <Wt/WIconPair>
     12#include <boost/algorithm/string.hpp>
     13#include <dirent.h>             /* readdir(), etc.                    */
     14#include <sys/stat.h>           /* stat(), etc.                       */
     15
    816#include "GWt_serverFileSelector.h"
    917
     18
    1019GWt_serverFileSelector::GWt_serverFileSelector(
    11                        WString titre,
    12                        WContainerWidget* wc,
    13                        bool modal
    14                        ):
    15 WDialog(titre)
     20 WString titre,
     21 std::string wd):
     22GWt_dialog(titre, NULL, true)
    1623{
    1724   
    18     // change the title bar style
    19     titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220));
     25    workingDir_ = wd;
     26       
     27    Wt::WIconPair *folderIcon = new Wt::WIconPair("htdocs/yellow-folder-closed.png",
     28                                                  "htdocs/yellow-folder-open.png", false);
     29   
     30    treeRoot_ = new Wt::WTree();
     31    treeRoot_->setSelectionMode(Wt::SingleSelection);
     32   
     33    /* this structure is used for storing the name of each entry in turn. */
     34    struct dirent* entry;
     35   
     36    /* read the directory's contents, print out the name of each entry.   */
     37    printf("Directory contents:\n");
     38    DIR* dir = opendir(workingDir_.c_str());
     39    if (!dir) {
     40        perror("opendir");
     41        exit(1);
     42    }
     43    struct stat dir_stat;       /* used by stat().                   */
     44    while ( (entry = readdir(dir)) != NULL) {
     45        /* check if the given entry is a directory. */
     46        if (stat(entry->d_name, &dir_stat) == -1) {
     47            perror("stat:");
     48            printf("stat:%s\n",entry->d_name);
     49            continue;
     50        } else {
     51            printf("false%s\n", entry->d_name);
     52        }
     53    }
     54   
     55   
     56    Wt::WTreeNode* treeFileRoot = new Wt::WTreeNode("Workspace", folderIcon);
     57
     58    treeFileRoot->setStyleClass("example-tree");
     59    treeRoot_->setTreeRoot(treeFileRoot);
     60    treeFileRoot->label()->setTextFormat(Wt::PlainText);
     61    treeFileRoot->setImagePack("resources/");
     62    treeFileRoot->setLoadPolicy(Wt::WTreeNode::NextLevelLoading);
     63   
     64    buildConfigurationFileTree(treeFileRoot, workingDir_.c_str(), ".save");
     65   
     66    treeFileRoot->expand();
     67    WContainerWidget *treeContainer = new WContainerWidget();
     68    treeContainer->addWidget(treeRoot_);
     69
     70    WContainerWidget *buttonContainer = new WContainerWidget();
     71    WHBoxLayout* hButtonLayout = new WHBoxLayout();
     72    buttonContainer->setLayout(hButtonLayout);
     73   
     74    WPushButton *annule = new WPushButton("cancel");
     75    WPushButton *submit = new WPushButton("OK");
     76    hButtonLayout->addWidget(annule);
     77    hButtonLayout->addWidget(submit);
     78   
     79    annule->clicked().connect(this, &Wt::WDialog::reject);
     80    submit->clicked().connect(this, &Wt::WDialog::accept);
     81   
     82
     83    // overload the container already present
    2084   
    2185    WContainerWidget* widgt = new WContainerWidget(contents());
    22     WHBoxLayout* hLayout = new WHBoxLayout();
    23     hLayout->addWidget(wc);
    24     widgt->setLayout(hLayout);
     86    WVBoxLayout* vLayout = new WVBoxLayout();
     87    vLayout->addWidget(treeContainer);
     88    vLayout->addWidget(buttonContainer);
     89    widgt->setLayout(vLayout);
    2590   
    26     setClosable(true);
    27     setModal (modal);
    2891}
    2992
    3093
    3194
    32 GWt_serverFileSelector::GWt_serverFileSelector(
    33                        WString titre,
    34                        WString message,
    35                        iconType icon,
    36                        bool modal,
    37                        bool ok
    38                        ):
    39 WDialog(titre)
     95/*
     96 * function: findfile. recusively traverse the current directory, searching
     97 *                     for files with a given string in their name.
     98 * input:    string to match.
     99 * output:   any file found, printed to the screen with a full path.
     100 */
     101void GWt_serverFileSelector::buildConfigurationFileTree(Wt::WTreeNode *treeFileRoot, const char* folder, const char* pattern)
    40102{
     103#define MAX_DIR_PATH 2048 /* maximal full path we support.      */
    41104   
    42     // change the title bar style
    43     titleBar()->decorationStyle().setBackgroundColor (WColor(70,180,220));
     105    DIR* dir;   /* pointer to the scanned directory. */
     106    struct dirent* entry; /* pointer to one directory entry.   */
     107    char cwd[MAX_DIR_PATH+1]; /* current working directory.        */
     108    struct stat dir_stat;       /* used by stat().                   */
    44109   
    45     WContainerWidget* widgt = new WContainerWidget(contents());
    46     WHBoxLayout* hLayout = new WHBoxLayout();
    47    
    48     WImage* tImg = new WImage("icons/error.png");
    49     switch (icon) {
    50         case Warning:
    51             tImg->setImageLink ("icons/warning.png");
    52             tImg->setMaximumSize (70,70);
    53             hLayout->addWidget(tImg);
    54             break;
    55         case Error:
    56             tImg->setImageLink ("icons/error.png");
    57             tImg->setMaximumSize (70,70);
    58             hLayout->addWidget(tImg);
    59             break;
    60         case Info:
    61             tImg->setImageLink ("icons/info.png");
    62             tImg->setMaximumSize (70,70);
    63             hLayout->addWidget(tImg);
    64             break;
    65         case Wait:
    66             tImg->setImageLink ("icons/patientez.gif");
    67             tImg->setMaximumSize (70,70);
    68             hLayout->addWidget(tImg);
    69             break;
    70         case NoIcon:
    71             break;
    72         default:
    73             break;
     110    /* first, save path of current working directory */
     111    if (!getcwd(cwd, MAX_DIR_PATH+1)) {
     112        perror("getcwd:");
     113        return;
    74114    }
    75115   
    76     WContainerWidget* right = new WContainerWidget();
    77     WVBoxLayout* vLayout = new WVBoxLayout();
    78116   
    79     // changement des "\n" par des <br>
    80     size_t pos = message.toUTF8().find("\n", 0);
    81    
    82     while(pos != std::string::npos) {
    83         vLayout->addWidget(new Wt::WText(WString::fromUTF8(message.toUTF8 ().substr(0,pos))));
    84         message = message.toUTF8 ().substr(pos+1);
    85         pos = message.toUTF8 ().find("\n");
    86         vLayout->addWidget(new Wt::WBreak());
    87     }
    88     vLayout->addWidget(new Wt::WText(message));
    89    
    90    
    91     if (ok) {
    92         vLayout->addWidget(new Wt::WBreak);
    93        
    94         Wt::WPushButton *ok = new Wt::WPushButton("Ok");
    95         vLayout->addWidget(ok);
    96        
    97         // this event will accept() the Dialog
    98         ok->clicked().connect(this, &Wt::WDialog::accept);
     117    /* open the directory for reading */
     118    dir = opendir(folder);
     119    if (!dir) {
     120        fprintf(stderr, "Cannot read directory '%s': ", cwd);
     121        perror("");
     122        return;
    99123    }
    100124   
    101     right->setLayout(vLayout);
    102     hLayout->addWidget(right);
    103    
    104     widgt->setLayout(hLayout);
    105    
    106     setClosable(true);
    107     setModal (modal);
     125    /* scan the directory, traversing each sub-directory, and */
     126    /* matching the pattern for each file name.               */
     127    while ((entry = readdir(dir))) {
     128       
     129        /* skip the "." and ".." entries, to avoid loops. */
     130        if (strcmp(entry->d_name, ".") == 0)
     131            continue;
     132        if (strcmp(entry->d_name, "..") == 0)
     133            continue;
     134        if (strcmp(entry->d_name, ".svn") == 0)
     135            continue;
     136        /* check if the given entry is a directory. */
     137        if (entry->d_type == DT_DIR) {
     138            printf("++DIR %s\n",entry->d_name);
     139            Wt::WIconPair *folderIcon = new Wt::WIconPair("htdocs/yellow-folder-closed.png",
     140                                                          "htdocs/yellow-folder-open.png", false);
     141            Wt::WTreeNode *child = new Wt::WTreeNode(entry->d_name, folderIcon);
     142            treeFileRoot->addChildNode(child);
     143            buildConfigurationFileTree(child,(std::string(folder)+entry->d_name).c_str(), pattern);
     144           
     145        } else {
     146            printf("++FILE %s\n",entry->d_name);
     147           
     148            /* check if the pattern matchs. */
     149            if (boost::algorithm::ends_with(entry->d_name, pattern)) {
     150                treeFileRoot->addChildNode(new Wt::WTreeNode(entry->d_name));
     151                printf("-----%s/%s\n", cwd, entry->d_name);
     152            }
     153        }
     154    }
    108155}
    109156
     157std::string GWt_serverFileSelector::exec() {
     158   
     159    Wt::WDialog::DialogCode dc = WDialog::exec();
     160    if (dc == Rejected) {
     161        return "";
     162    }
     163    const Wt::WTree::WTreeNodeSet& tr = treeRoot_->selectedNodes();
     164    if (tr.empty()) {
     165        return "";
     166    }
     167    std::string path = (*tr.begin())->label()->text().toUTF8();
    110168
     169    Wt::WTreeNode* parent = (*tr.begin())->parentNode();
     170    while (parent) {
     171        parent = parent->parentNode();
     172        if( parent) {
     173            path = parent->label()->text().toUTF8()+"/"+path;
     174        }
     175    }
     176    return workingDir_+path;
     177}
Note: See TracChangeset for help on using the changeset viewer.