Changeset 198 in PSPA


Ignore:
Timestamp:
Dec 17, 2012, 5:34:16 PM (12 years ago)
Author:
garnier
Message:

insertion des elements ok (presque)

Location:
Interface_Web/trunk/pspaWT
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/include/GWt_LigneFaisceau.h

    r188 r198  
    1212#include <Wt/WHBoxLayout>
    1313#include <Wt/WContainerWidget>
    14 #include <Wt/WImage>
    1514
    1615using namespace Wt;
     
    3029  Compteur *nObjets_;
    3130
    32   string createLabel(nomdElements el,int n);
    33 
    3431 public :
    3532 
     
    4441  void clickEvent(WContainerWidget*);
    4542  void deleteElement(WContainerWidget*);
    46   void onClick(GWt_abstractElement*);
    47   void removeDone(GWt_abstractElement*);
    4843
    49  private :
    5044
    51   void dropEvent(WDropEvent evt);
    52   WDialog *message_;
    5345};
    5446
  • Interface_Web/trunk/pspaWT/include/GWt_dropZoneLigneFaiseau.h

    r186 r198  
    22#define GWT_DROPZONELIGNEFAISEAU_SEEN
    33
    4 #include "GWt_LigneFaisceau.h"
     4#include "GWt_dialog.h"
     5#include "GWt_pspaApplication.h"
     6#include "abstractElement.h"
     7#include "GWt_abstractElement.h"
     8
    59#include <Wt/WContainerWidget>
    6 #include "GWt_dialog.h"
    710
    811using namespace Wt;
     
    1316 public :
    1417
    15   GWt_dropZoneLigneFaiseau(PspaApplication*);
     18  GWt_dropZoneLigneFaiseau(PspaApplication*,bool linkImage = true);
    1619  ~GWt_dropZoneLigneFaiseau();
     20  void addElement(WContainerWidget* elem);
    1721
    1822 private:
     
    2630  void onClick(GWt_abstractElement*);
    2731  void removeDone(GWt_abstractElement*);
     32  std::string getElementNumberInBeamLine(nomdElements el);
    2833
    2934  PspaApplication* pspa_;
    30   GWt_LigneFaisceau* ligneFaiseau_;
    3135  GWt_dialog* messageDropZone_;
     36  WText* insertMessage_;
     37  WWidget* linkImage_;
     38
     39  WContainerWidget* abstractElement_;
    3240};
    3341#endif
  • Interface_Web/trunk/pspaWT/src/GWt_LigneFaisceau.cc

    r189 r198  
    1 
    2 
    31#include <iostream>
    42
     3#include "GWt_dropZoneLigneFaiseau.h"
    54#include "GWt_LigneFaisceau.h"
    65#include "GWt_drift.h"
     
    1413
    1514#include <Wt/WVBoxLayout>
    16 #include <Wt/WSignalMapper>
    1715
    1816
     
    2321{
    2422
    25   cout<<"GWt_LigneFaisceau::GWt_LigneFaisceau()"<<endl;
     23  cout<<"GWt_LigneFaisceau::GWt_LigneFaisceau() %d"<< this << "<---------------"<< endl;
    2624
    2725  hbox_ = new WHBoxLayout();
    28   decorationStyle().setBackgroundColor (WColor("orange"));
     26  //  decorationStyle().setBackgroundColor (WColor("orange"));
    2927  setLayout(hbox_);
    3028
     
    3634  }
    3735
     36  // add the first drop zone
     37  hbox_->addWidget(new GWt_dropZoneLigneFaiseau(pspa_,false));
     38
    3839  // add a strech element at the end
    39   hbox_->addStretch(1);
     40  //  hbox_->addStretch(1);
    4041}
    4142 
    42 string GWt_LigneFaisceau::createLabel(nomdElements el,int n)
    43 {
    44   cout<<"GWt_LigneFaisceau::createLabel()"<<endl;
    4543
    46    string str;
    47   if(n < 10) {
    48     str= el.getElementLabel()+"0"+mixedTools::intToString(n);
    49   } else {
    50     str= el.getElementLabel()+mixedTools::intToString(n);
    51   }
    52   return str;
    53 }
    54 
    55 void GWt_LigneFaisceau::dropEvent(WDropEvent evt)
    56 {
    57   nomdElements e(evt.mimeType());
    58   typedElement eType = e.getElementType();
    59   int cnts= pspa_->getDataManager()->beamLineSize();
    60 
    61   cout<<"GWt_LigneFaisceau::dropEvent() : "<<e.getElementName()<<" ("<< cnts <<")"<< endl; 
    62  
    63   if(eType == inconnu) {
    64     cout << "GWt_LigneFaisceau::element type " << eType << " inconnu " << endl;
    65     return;
    66   }
    67 
    68   pspa_->addConsoleMessage(e.getElementName());
    69   abstractElement* ptr = pspa_->getDataManager()->addElement(eType);
    70   if ( ptr == NULL ) {
    71     cerr  << " GWt_LigneFaisceau::dropEvent : failure in creation of type object : " << eType << endl;
    72     return;
    73   }
    74 
    75   ptr->setLabel(createLabel(e,nObjets_[eType].incr()));
    76 
    77   cout << " je vais ajouter l'element  " << ptr->getName().getElementName() << " de type " << ptr->getName().getElementType() << endl;
    78   GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr);
    79   if(gw == NULL) return;
    80   gw->updateLabelWidget();
    81 
    82   //////////////////////////////////////////////////////////////////
    83   // pourVoir
    84 
    85   cout<<"container: "<<gw->getWidget()->id()<<endl;
    86   cout << "number of widgets in this container= " << gw->getWidget()->count() << ": ";
    87   for(int k = 0; k < gw->getWidget()->count(); k++) {
    88     WWidget *w= gw->getWidget()->widget(k);
    89     cout << w->id() << ", ";
    90   }
    91   cout << endl;
    92 
    93   //////////////////////////////////////////////////////////////////
    94 
    95   WSignalMapper<GWt_abstractElement *> *mapper= new WSignalMapper<GWt_abstractElement *>(this);
    96   mapper->mapped().connect(this,&GWt_LigneFaisceau::onClick);
    97   mapper->mapConnect(gw->getButton()->doubleClicked(),gw);
    98 
    99   //////////////////////////////////////////////////////////////////
    100 
    101   hbox_->insertWidget(cnts,gw->getWidget());
    102   //gw->getWidget()->decorationStyle().setBackgroundColor (WColor("blue"));
    103   pspa_->updateSelections();
    104 
    105   //////////////////////////////////////////////////////////////////
    106   // pourVoir
    107 
    108   cout << "number of items in the layout=  " << hbox_->count() << ": ";
    109   for(int k = 0; k < hbox_->count(); k++)
    110     {
    111       WLayoutItem *wi= hbox_->itemAt(k);
    112       WWidget *w= wi->widget();
    113       cout << w->id() << ", ";
    114     }
    115   cout << endl;
    116 
    117   //////////////////////////////////////////////////////////////////
    118   // pourVoir
    119 
    120   int nElts= pspa_->getDataManager()->beamLineSize();
    121   cout << "GWt_LigneFaisceau:: nElts= " << nElts << endl;
    122   unsigned int k;
    123   for(k = 0; k < (unsigned)nElts; k++) {
    124     abstractElement* ptr= pspa_->getDataManager()->getCollection()->getElementPointer(k);
    125     string label= ptr->getLabel();
    126     cout << "GWt_LigneFaisceau:: " << label << " dans la liste" << endl;
    127   }
    128  
    129 }
    130 
    131 void GWt_LigneFaisceau::onClick(GWt_abstractElement* gw)
    132 {
    133   cout << "mouse key was double clicked on this widget " << gw->getWidget()->id()<< endl;
    134 
    135   message_= new GWt_dialog("Question","Are you sure you want to delete the selected item?",GWt_dialog::Warning,true,true);
    136 
    137   WSignalMapper<GWt_abstractElement *> *MyMap = new WSignalMapper<GWt_abstractElement *>(this);
    138   MyMap->mapped().connect(this, &GWt_LigneFaisceau::removeDone);
    139   MyMap->mapConnect(message_->finished(),gw);
    140   message_->exec();
    141 }
    142 
    143 void GWt_LigneFaisceau::removeDone(GWt_abstractElement* gw)
    144 {
    145   if (message_->result() == WDialog::Accepted) {
    146 
    147     cout <<"GWt_LigneFaisceau:: removeDone "<< gw->getWidget()->id() << endl;
    148    
    149     gw->getWidget()->clear();
    150     hbox_->removeWidget(gw->getWidget());
    151    
    152     string label= gw->getElement()->getLabel();
    153     cout << "GWt_LigneFaisceau:: " << label << " a été supprimé" << endl;
    154     pspa_->getDataManager()->getCollection()->eraseElement(label);
    155     pspa_->updateSelections();
    156   }
    157 }
    15844   
    15945void GWt_LigneFaisceau::restoreElementCollection()
     
    17056  int nbElem = pspa_->getDataManager()->beamLineSize();
    17157  unsigned int k;
     58
     59  // add first dropZone
     60  hbox_->addWidget(new GWt_dropZoneLigneFaiseau(pspa_,false));
     61
    17262  for(k = 0; k < (unsigned)nbElem; k++)
    17363    {     
    17464      abstractElement* ptr = pspa_->getDataManager()->getCollection()->getElementPointer(k);
    175       if ( ptr == NULL ) {
    176         GWt_dialog message1("restore element collection ","GWt_LigneFaisceau::restaure element failed ",GWt_dialog::Warning,false,true);
    177         message1.exec();
    178       }
    17965      GWt_abstractElement* gw = GWt_abstractElement::ajoute(pspa_,ptr);
    18066      if(gw == NULL) {
    181         //      cerr << "GWt_LigneFaisceau::restaure element type " << ptr->getName().getElementName() << " est inconnu " << endl;
    182 
    183         GWt_dialog message2("restore element collection ","GWt_LigneFaisceau::restaure element type"+ptr->getName().getElementName(),GWt_dialog::Warning,false,true);
    184         message2.exec();
     67        cerr << "GWt_LigneFaisceau::restaure element type " << ptr->getName().getElementName() << " est inconnu " << endl;
    18568      }
    18669     
    18770      gw->updateLabelWidget();
    18871      nObjets_[ptr->getName().getElementType()].incr();
    189       hbox_->addWidget(gw->getWidget());
    190       WSignalMapper<GWt_abstractElement *> *mapper= new WSignalMapper<GWt_abstractElement *>(this);
    191       mapper->mapped().connect(this,&GWt_LigneFaisceau::onClick);
    192       mapper->mapConnect(gw->getButton()->doubleClicked(),gw);
     72      GWt_dropZoneLigneFaiseau* dropZone = new GWt_dropZoneLigneFaiseau(pspa_);
     73      dropZone->addElement(gw->getWidget());
     74      hbox_->addWidget(dropZone);
     75
     76      if (k < ((unsigned)nbElem-1)) {
     77        hbox_->addWidget(new GWt_dropZoneLigneFaiseau(pspa_));
     78      } else {
     79        hbox_->addWidget(new GWt_dropZoneLigneFaiseau(pspa_,false));
     80      }
    19381    }
    19482
     
    19684}
    19785
    198 
  • Interface_Web/trunk/pspaWT/src/GWt_abstractElement.cc

    r179 r198  
    2424  dropped_->setObjectName("aPushButton");
    2525  dropped_->setIcon(element_->getName().getElementImage());
    26   dropped_->setMaximumSize(50,50);
     26  dropped_->setMaximumSize(50,37);
    2727  dropped_->clicked().connect(this,&GWt_abstractElement::clicked);
    2828
  • Interface_Web/trunk/pspaWT/src/GWt_dropZoneLigneFaiseau.cc

    r186 r198  
    22
    33#include "GWt_dropZoneLigneFaiseau.h"
     4#include "nomdElements.h"
    45
    56#include <Wt/WCssDecorationStyle>
    67#include <Wt/WSignalMapper>
    78#include <Wt/WText>
    8 
    9 GWt_dropZoneLigneFaiseau::GWt_dropZoneLigneFaiseau(PspaApplication* ps)
     9#include <Wt/WImage>
     10#include <Wt/WHBoxLayout>
     11
     12
     13GWt_dropZoneLigneFaiseau::GWt_dropZoneLigneFaiseau(PspaApplication* ps,bool linkImageOk)
    1014  : WContainerWidget(),
    11     pspa_(ps)
    12 {
    13   decorationStyle().setBackgroundColor (WColor("blue"));
     15    pspa_(ps),
     16    insertMessage_(NULL),
     17    linkImage_(NULL),
     18    abstractElement_(NULL)
     19{
     20  // decorationStyle().setBackgroundColor (WColor("yellow"));
    1421  resize(5,5);
    1522  cout<<"new GWt_dropZoneLigneFaiseau"<< endl;
     
    2330  mouseDragged().connect(this, &GWt_dropZoneLigneFaiseau::mouseIsDragged);
    2431
     32  insertMessage_ = new WText("Drag an element here");
     33  addWidget(insertMessage_);
     34  if (linkImageOk) {
     35    linkImage_ = new WImage("icons/link.jpg");
     36    linkImage_->setMargin(4, Top | Bottom);            // add margin vertically
     37    addWidget(linkImage_);
     38  }
     39
     40  insertMessage_->hide();
     41
    2542  // accept drops
    2643  int nElts= nomdElements::getNumberOfElements();
     
    2946    acceptDrops(nomdElements::getImageFromType(eType));
    3047  }
     48
     49
    3150}
    3251
     
    3958void GWt_dropZoneLigneFaiseau::mouseOver(const WMouseEvent& e)
    4059{
    41   resize(50,50);
     60  // Add text
     61  if (insertMessage_) {
     62    if (!abstractElement_) {
     63      insertMessage_->show();
     64      resize(insertMessage_->width(),insertMessage_->height());
     65    }
     66  }
     67  if (linkImage_) {
     68    linkImage_->hide();
     69  }
     70
     71  decorationStyle().setBorder (WBorder (WBorder::Dashed, WBorder::Medium,WColor(blue)));
     72
    4273  pspa_->addConsoleMessage("mouse Over");
    4374  cout << " GWt_dropZoneLigneFaiseau::mouseOver" << endl;
     
    4677void GWt_dropZoneLigneFaiseau::mouseOut(const WMouseEvent& e)
    4778{
    48   resize(5,5);
     79  if (!abstractElement_) {
     80    if (linkImage_) {
     81      resize(linkImage_->width(),linkImage_->height());
     82    } else {
     83      resize(10,10);
     84    }
     85  }
     86  if (insertMessage_) {
     87    insertMessage_->hide();
     88  }
     89  if (linkImage_) {
     90    linkImage_->show();
     91  }
     92  decorationStyle().setBorder (WBorder (WBorder::Dashed, WBorder::Medium,WColor(255,255,255,255)));
    4993  pspa_->addConsoleMessage("GWt_dropZoneLigneFaiseau::mouseOut");
    5094}
     
    81125
    82126  pspa_->addConsoleMessage(e.getElementName());
     127
    83128  abstractElement* ptr = pspa_->getDataManager()->addElement(eType);
    84   // FIXME
    85   //  ptr->setLabel(createLabel(e,nObjets_[eType].incr()));
     129
     130  ptr->setLabel(getElementNumberInBeamLine(e));
    86131
    87132  cout << " je vais ajouter l'element  " << ptr->getName().getElementName() << " de type " << ptr->getName().getElementType() << endl;
     
    116161    WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
    117162
     163    cout<<"add the dropped parent %d"<< wc << " COUNT:"<< count () <<"<---------------"<< endl;
     164    // do not insert new element if some element is already present
     165
     166    WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
     167    bool replaceElement = false;
     168
     169    if (abstractElement_) {
     170      replaceElement = true;
     171    }
     172
     173    // insert one before
     174    if (!replaceElement) {
     175      // if it the first element of the beam line
     176      if (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))) == 0) {
     177        layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))), new GWt_dropZoneLigneFaiseau(pspa_,false));
     178     
     179      } else {
     180        layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))), new GWt_dropZoneLigneFaiseau(pspa_,true));
     181      }
     182    }
     183
     184    // complete widget
     185    clear();
     186    insertMessage_ = NULL;
     187    linkImage_ = NULL;
     188    abstractElement_ = gw->getWidget();
     189    addWidget(abstractElement_);
     190    // change strech (useful if it was the last one)
     191    layout->setStretchFactor(this,0);           
     192
     193
     194    // insert after
     195    // if it is the last, add a strech factor and no link image
     196    cout<<" nb elem:"<< layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1 << " COUNT:"<< wc->count () <<"<---------------"<< endl;
     197    if (!replaceElement) {
     198      if (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1 == wc->count()) {
     199        layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1, new GWt_dropZoneLigneFaiseau(pspa_,false),1);
     200      } else {
     201        layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1, new GWt_dropZoneLigneFaiseau(pspa_));
     202      }
     203    }
     204
     205   
    118206    cout<<"add the dropped parent %d"<< wc << " COUNT:"<< wc->count () <<"<---------------"<< endl;
    119     // insert one before
    120     WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
    121     layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this))), new GWt_dropZoneLigneFaiseau(pspa_));
    122     // complete widget
    123     addWidget(gw->getWidget());
    124     // insert after
    125     layout->insertWidget (layout->indexOf ((WLayoutItem*)(layout->findWidgetItem (this)))+1, new GWt_dropZoneLigneFaiseau(pspa_));
    126 
    127    
    128     cout<<"add the dropped parent %d"<< wc << " COUNT:"<< wc->count () <<"<---------------"<< endl;
    129   }
    130 
    131 
    132   int nElts= nomdElements::getNumberOfElements();
    133   for(int k = 0; k < nElts; k++) {
    134     typedElement eType= (typedElement)k;
    135     stopAcceptDrops(nomdElements::getImageFromType(eType));
    136   }
     207  }
     208
    137209
    138210  //gw->getWidget()->decorationStyle().setBackgroundColor (WColor("blue"));
     
    193265  }
    194266}
     267
     268
     269
     270void GWt_dropZoneLigneFaiseau::addElement(WContainerWidget* elem){
     271  clear();
     272  abstractElement_ = elem;
     273  addWidget(abstractElement_);
     274
     275  insertMessage_ = NULL;
     276  linkImage_ = NULL;
     277}
     278
     279std::string GWt_dropZoneLigneFaiseau::getElementNumberInBeamLine(nomdElements elem){
     280  string str = "";
     281 
     282  if (static_cast <WContainerWidget*> (parent())) {
     283    WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
     284    for (int a=0; a<wc->count(); a++) {
     285      if (static_cast <GWt_abstractElement*> (wc->widget (a))) {
     286        GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a));
     287        /*
     288        printf("1--->%d\n",ab->getElement());
     289        printf("2--->%d\n",ab->getElement()->getLenghtOfElement());
     290        printf("3--->%d\n",ab->getElement()->getName().getElementType());
     291        printf("4--->%d\n",elem.getElementType());
     292
     293        if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
     294          pspa_->addConsoleMessage("type trouvé");
     295        } else {
     296          pspa_->addConsoleMessage("type trouvé NOT ");
     297        }
     298        */
     299
     300      }
     301    }
     302   
     303    int n = 999999;
     304   
     305    std::stringstream stream;
     306    stream << n ;
     307    std::string number(stream.str());
     308   
     309    if(n < 10) {
     310      str= elem.getElementLabel()+"0"+number;
     311    } else {
     312    str= elem.getElementLabel()+" "+number;
     313    }
     314  }
     315
     316  return str;
     317}
  • Interface_Web/trunk/pspaWT/src/GWt_pspaApplication.cc

    r196 r198  
    22#include <string.h>
    33#include <vector>
     4
    45#include "GWt_pspaApplication.h"
    56#include "GWt_LigneFaisceau.h"
     
    5455  WGridLayout *layout = new WGridLayout();
    5556  layout->addWidget(createTitle("Menu (In future)"), 0, 0, 1, 2);
     57
    5658  WHBoxLayout *toolbarLayout = new WHBoxLayout();
    5759  WPushButton* boutonSauve = new WPushButton(" sauvegarder la config");
     
    8082 
    8183  console_ = new WContainerWidget();
    82   console_->decorationStyle().setBackgroundColor (WColor("gray"));
     84  console_->decorationStyle().setBackgroundColor (WColor("lightgray"));
    8385  console_->setMaximumSize(600,200);
    8486  layout->addWidget(console_, 3, 1);
     
    132134
    133135
    134   palette->setMinimumSize(100,300);
     136  //  palette->setMinimumSize(100,300);
    135137  return palette;
    136138}
Note: See TracChangeset for help on using the changeset viewer.