source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_abstractElement.cc @ 488

Last change on this file since 488 was 488, checked in by lemeur, 10 years ago

lecture fichier sauvegarde AML

File size: 5.8 KB
Line 
1
2#include <iostream>
3#include <string>
4#include <boost/variant.hpp>
5#include <boost/variant/get.hpp>
6
7#include "GWt_abstractElement.h"
8#include "GWt_elementLigneFaisceau.h"
9
10#include "GWt_draggableImage.h"
11#include "GWt_ligneFaisceau.h"
12
13#include "mixedTools.h"
14#include "nomdElements.h"
15#include "nomDeLogiciel.h"
16#include <Wt/WText>
17#include <Wt/WLineEdit>
18#include <Wt/WBreak>
19#include <Wt/WApplication>
20#include <Wt/WMessageBox>
21
22
23GWt_abstractElement::GWt_abstractElement(abstractElement* elem)
24  : WContainerWidget()
25{
26  abstractElement_ = elem;
27}
28
29void GWt_abstractElement::initialize()
30{
31  image_ = new WImage(getBigImageURL(),this); // make image 
32  addWidget(image_);
33  updateLabelAndToolTipWidget();
34}
35
36string* GWt_abstractElement::beginDialog()
37{
38  string* param = abstractElement_->getParametersString();
39 
40  if ( param == NULL ) {
41    if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
42      GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
43      console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getExpandedName());
44    }
45  }
46
47  int nbparam = atoi(param->c_str());
48  if ( nbparam != abstractElement_->getNbParams()) {
49    if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) {
50      GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));
51      console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getExpandedName());
52    }
53  }
54 
55  dialog_ = new WDialog("element "+abstractElement_->getNomdElement().getExpandedName());
56  new WText(" label of the element : ",dialog_->contents());
57  labelEdit_ = new WLineEdit( (++param)->c_str(),dialog_->contents());
58  new WBreak(dialog_->contents());
59  return ++param;
60}
61
62void GWt_abstractElement::updateLabelAndToolTipWidget()
63{
64  if (abstractElement_ != NULL) {
65    elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel());
66    setToolTip(print());
67  }
68}
69
70void GWt_abstractElement::showParameters()
71{
72  initilializeDialog();
73  dialog_->show();
74}
75
76void GWt_abstractElement::deleteElement()
77{
78  StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel);
79 
80  if (result == Cancel) {
81    return;
82  }
83  // get LigneFaiseau widget and add new elementLigneFaiseau
84  GWt_ligneFaisceau* ligneFaisceau = NULL;
85  if ( static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
86    ligneFaisceau = static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
87  } else {
88    return;
89  }
90 
91  ligneFaisceau->removeElement(this);
92}
93
94void GWt_abstractElement::createDragImage(WContainerWidget* w)
95{
96  unsigned k;
97  GWt_draggableImage *result= new GWt_draggableImage(getBigImageURL(),w);
98 
99  /*
100   * Set the image to be draggable, showing the other image (dragImage)
101   * to be used as the widget that is visually dragged.
102   */
103  result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true);
104  vector<string> acceptes;
105  vector<string> ignores;
106  for ( k=0; k < nomDeLogiciel::getNumberOfSoftwares() ; k++) {
107    trivaluedBool tb = nomDeLogiciel(k).doAcceptElement(nomdElements::getTypeFromLabel(getName()) );
108    if (tb  == TBoolOk ) {
109      acceptes.push_back(nomDeLogiciel(k).getString());
110    } else if (tb  == TBoolIgnore ) {
111      ignores.push_back(nomDeLogiciel(k).getString());
112    }
113  }
114  string textToolTip = getName();
115  if ( acceptes.size() ) textToolTip += string("\n") + "accepted by softwares : ";
116  for (k=0; k < acceptes.size(); k++) textToolTip += string("\n") +  acceptes.at(k);
117  if ( ignores.size() ) textToolTip += string("\n") + "ignored by softwares : ";
118  for (k=0; k < ignores.size(); k++) textToolTip += string("\n")  + ignores.at(k);
119 
120  //  result->setToolTip(getName());
121  result->setToolTip(textToolTip);
122}
123
124// void GWt_abstractElement::FileInput(ifstream& ifs)
125// {
126//   getAbstractElement()->FileInput(ifs);
127//   initilializeDialog();
128//   updateLabelAndToolTipWidget();
129 
130//   // update parameters
131//   GWt_ligneFaisceau* ligneFaisceau = NULL;
132//   if ( static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) {
133//     ligneFaisceau = static_cast<GWt_ligneFaisceau*> (wApp->findWidget ("ligneFaisceau"));
134//     ligneFaisceau->update();
135//   }
136// }
137
138abstractElement* GWt_abstractElement::getAbstractElement() {
139  return abstractElement_;
140}
141
142WContainerWidget* GWt_abstractElement::getWidget() {
143  return wc_;
144}
145
146WImage* GWt_abstractElement::getImage() {
147  return image_;
148}
149
150variant<int, string, bool, float, NullType> GWt_abstractElement::getParamValue(string elem) 
151{
152  if(parameterMapValue.find(elem) == parameterMapValue.end()) {
153    return new NullType();
154  }
155 
156  std::map<std::string, variant<int, string, bool, float, NullType> >::iterator it;
157  it = parameterMapValue.find(elem);
158  variant <int, string, bool, float, NullType> value = it->second;
159 
160  try {
161    int pi = boost::get<int>(value);
162    printf("%s Type is int\n",elem.c_str());
163    return pi;
164  }
165  catch (boost::bad_get v) {
166    try {
167      string si = boost::get<string>(value);
168      printf("%s Type is string\n",elem.c_str());
169      return si;
170    }
171    catch (boost::bad_get v) {
172      try {
173        bool bi = boost::get<bool>(value);
174        printf("%s Type is bool\n",elem.c_str());
175        return bi;
176      }
177      catch (boost::bad_get v) {
178        printf("%s Type is NULL\n",elem.c_str());
179        return new NullType();
180      }
181    }
182  }
183  printf("%s Type is NULL NULL\n",elem.c_str());
184  return new NullType();
185}
186
187string GWt_abstractElement::getParamDescription(string elem)
188{   
189  if(parameterMapDescription.find(elem) == parameterMapDescription.end() ) {
190    printf("%s Descr is NULL NULL\n",elem.c_str());
191    return "";
192  } else {
193    printf("%s Descr is %s\n",elem.c_str(),parameterMapDescription.find(elem)->second.c_str());
194    return parameterMapDescription.find(elem)->second;
195  }
196}
Note: See TracBrowser for help on using the repository browser.