source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_elementLigneFaisceau.cc @ 343

Last change on this file since 343 was 343, checked in by touze, 12 years ago

nvx element snapshot

File size: 5.7 KB
Line 
1#include <iostream>
2
3#include "GWt_elementLigneFaisceau.h"
4#include "nomdElements.h"
5#include "GWt_console.h"
6#include "abstractElement.h"
7#include "GWt_rfgun.h"
8#include "GWt_drift.h"
9#include "GWt_cell.h"
10#include "GWt_bend.h"
11#include "GWt_soleno.h"
12#include "GWt_beam.h"
13#include "GWt_fit.h"
14#include "GWt_snapshot.h"
15
16
17#include <Wt/WCssDecorationStyle>
18#include <Wt/WSignalMapper>
19#include <Wt/WText>
20#include <Wt/WImage>
21#include <Wt/WHBoxLayout>
22#include <Wt/WGridLayout>
23#include <Wt/WLength>
24#include <Wt/WVBoxLayout>
25#include <Wt/WApplication>
26
27#define PSPA_DEBUG 1
28
29GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(PspaApplication* pspa)
30  : WContainerWidget(),
31    firstTimeInsertMessage_(NULL),
32    dropZoneLeft_(NULL),
33    dropZoneRight_(NULL),
34    GWt_abstractElement_(NULL),
35    elementLabel_(NULL),
36    pspa_(pspa)
37{
38  initialize_ligneFaisceau(inconnu);
39}
40
41
42GWt_elementLigneFaisceau::GWt_elementLigneFaisceau(typedElement type, PspaApplication* pspa)
43  : WContainerWidget(),
44    firstTimeInsertMessage_(NULL),
45    dropZoneLeft_(NULL),
46    dropZoneRight_(NULL),
47    GWt_abstractElement_(NULL),
48    elementLabel_(NULL),
49    pspa_(pspa)
50{
51  // set the css name
52  setObjectName("elementLigneFaisceau"); 
53  initialize_ligneFaisceau(type);
54}
55
56void GWt_elementLigneFaisceau::initialize_ligneFaisceau(typedElement eType)
57{
58   
59  cout<<"new GWt_elementLigneFaisceau : "<< this << endl;
60   
61  // set layout
62  //     +----------+--------+---------+
63  //     |   (--->) |  ELEM  | (-----) |
64  //     +----------+--------+---------+
65  //     |             NAME            |
66  //     +----------+--------+---------+
67 
68   
69  WGridLayout *gridLayout = new WGridLayout();
70   
71  gridLayout->setContentsMargins(0,0,0,0);
72  gridLayout->setHorizontalSpacing(0);
73  gridLayout->setVerticalSpacing(0);
74 
75  // add first line :  initialize arrow and link images
76  dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_);
77  dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_);
78   
79  // change object name in order to manage css :
80  dropZoneLeft_->resize(10,30);
81  dropZoneRight_->resize(10,30);
82 
83  gridLayout->addWidget (dropZoneLeft_,0,0);
84  gridLayout->addWidget (dropZoneRight_,0,2);
85   
86  // add the image if present
87 
88  switch ( eType ) {
89  case RFgun :
90    GWt_abstractElement_ = new GWt_rfgun(this);
91    break;
92  case drift :
93    GWt_abstractElement_ = new GWt_drift(this);
94    break;
95  case cell  :
96    GWt_abstractElement_ = new GWt_cell(this);
97    break;
98  case bend  :
99    GWt_abstractElement_ = new GWt_bend(this);
100    break;
101  case soleno  :
102    GWt_abstractElement_ = new GWt_soleno(this);
103    break;
104  case beam  :
105    GWt_abstractElement_ = new GWt_beam(this);
106    break;
107  case fit  :
108    GWt_abstractElement_ = new GWt_fit(this);
109    break;
110  case snapshot :
111    GWt_abstractElement_ = new GWt_snapshot(this);
112    break;
113  case inconnu :
114    GWt_abstractElement_ = NULL;
115  }
116
117  if (GWt_abstractElement_ != NULL) {
118    gridLayout->addWidget(GWt_abstractElement_,0,1);
119    GWt_abstractElement_->setMaximumSize(32,32);
120    GWt_abstractElement_->setMinimumSize(32,32);
121  }
122 
123  // add second line
124    if (GWt_abstractElement_ == NULL) {
125      elementLabel_ = new WText();
126    } else {
127      elementLabel_ = new WText(GWt_abstractElement_->getAbstractElement()->getLabel());
128    }
129   
130    gridLayout->addWidget(elementLabel_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle);
131   
132    gridLayout->setColumnStretch (0,1);
133    gridLayout->setColumnStretch (2,1);
134   
135    // set layout
136    setLayout(gridLayout);
137}
138
139
140GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau()
141{
142}
143
144void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw)
145{
146  if (messageDropZone_->result() == WDialog::Accepted) {
147    // FIXME
148    //    removeDropZone();
149  }
150}
151
152
153void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem)
154{   
155  clear();
156  GWt_abstractElement_ = elem;
157  addWidget(GWt_abstractElement_);
158  if (static_cast <WContainerWidget*> (parent())) {
159    WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
160    WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
161    layout->setStretchFactor(this,0);
162  }
163 
164 
165  firstTimeInsertMessage_ = NULL;
166    dropZoneLeft_ = NULL;
167}
168
169
170std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem){
171  string str = "";
172   
173    if (static_cast <WContainerWidget*> (parent())) {
174        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
175        for (int a=0; a<wc->count(); a++) {
176            if (static_cast <GWt_abstractElement*> (wc->widget (a))) {
177                //        GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a));
178                /*
179                 printf("1--->%d\n",ab->getElement());
180                 printf("2--->%d\n",ab->getElement()->getLenghtOfElement());
181                 printf("3--->%d\n",ab->getElement()->getName().getElementType());
182                 printf("4--->%d\n",elem.getElementType());
183                 
184                 if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
185                 pspa_->addConsoleMessage("type trouvÈ");
186                 } else {
187                 pspa_->addConsoleMessage("type trouvÈ NOT ");
188                 }
189                 */
190               
191            }
192        }
193       
194        int n = 999999;
195       
196        std::stringstream stream;
197        stream << n ;
198        std::string number(stream.str());
199       
200        if(n < 10) {
201            str= elem.getElementLabel()+"0"+number;
202        } else {
203            str= elem.getElementLabel()+number;
204        }
205    }
206   
207    return str;
208}
209
210
211void GWt_elementLigneFaisceau::setElementLabel(std::string label) {
212  if (elementLabel_) {
213    elementLabel_->setText(label);
214  }
215}
Note: See TracBrowser for help on using the repository browser.