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

Last change on this file since 347 was 347, checked in by garnier, 11 years ago

Ameliorations pour la sauvegarde des fichiers et autres

File size: 6.3 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 first line :  initialize arrow and link images
87    dropZoneLeft_ = new GWt_dropZoneLigneFaisceau(pspa_);
88    dropZoneRight_ = new GWt_dropZoneLigneFaisceau(pspa_);
89   
90    // change object name in order to manage css :
91    dropZoneLeft_->resize(10,30);
92    dropZoneRight_->resize(10,30);
93   
94    gridLayout->addWidget       (dropZoneLeft_,0,0);
95    gridLayout->addWidget       (dropZoneRight_,0,2);
96   
97    // add the image if present
98   
99    switch (  eType ) {
100        case RFgun :
101            GWt_abstractElement_ = new GWt_rfgun(this);
102            break;
103        case drift :
104            GWt_abstractElement_ = new GWt_drift(this);
105            break;
106        case cell  :
107            GWt_abstractElement_ = new GWt_cell(this);
108            break;
109        case bend  :
110            GWt_abstractElement_ = new GWt_bend(this);
111            break;
112        case soleno  :
113            GWt_abstractElement_ = new GWt_soleno(this);
114            break;
115        case beam  :
116            GWt_abstractElement_ = new GWt_beam(this);
117            break;
118        case fit  :
119            GWt_abstractElement_ = new GWt_fit(this);
120            break;
121        case inconnu :
122            GWt_abstractElement_ = NULL;
123    }
124    if (GWt_abstractElement_ != NULL) {
125        gridLayout->addWidget   (GWt_abstractElement_,0,1);
126        GWt_abstractElement_->setMaximumSize(80,80);
127        GWt_abstractElement_->setMinimumSize(80,80);
128    }
129   
130    // add second line
131
132    if (GWt_abstractElement_ == NULL) {
133      elementLabel_ = new WText();
134    } else {
135      elementLabel_ = new WText(GWt_abstractElement_->getAbstractElement()->getLabel());
136    }
137   
138    gridLayout->addWidget(elementLabel_,1,0,1,3,Wt::AlignCenter |Wt::AlignMiddle);
139   
140    gridLayout->setColumnStretch (0,1);
141    gridLayout->setColumnStretch (2,1);
142   
143    // set layout
144    setLayout(gridLayout);
145}
146
147
148GWt_elementLigneFaisceau::~GWt_elementLigneFaisceau()
149{
150}
151
152void GWt_elementLigneFaisceau::setBGColor(const WColor c) {
153    decorationStyle().setBackgroundColor (c);
154}
155
156
157void GWt_elementLigneFaisceau::removeDone(GWt_abstractElement* gw)
158{
159  if (messageDropZone_->result() == WDialog::Accepted) {
160    // FIXME
161    //    removeDropZone();
162  }
163}
164
165
166void GWt_elementLigneFaisceau::addElement(GWt_abstractElement* elem)
167{   
168  clear();
169  GWt_abstractElement_ = elem;
170  addWidget(GWt_abstractElement_);
171  if (static_cast <WContainerWidget*> (parent())) {
172    WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
173    WBoxLayout* layout = ((WBoxLayout*)(wc->layout()));
174    layout->setStretchFactor(this,0);
175  }
176 
177 
178  firstTimeInsertMessage_ = NULL;
179    dropZoneLeft_ = NULL;
180}
181
182
183std::string GWt_elementLigneFaisceau::getElementNumberInBeamLine(nomdElements elem){
184  string str = "";
185   
186    if (static_cast <WContainerWidget*> (parent())) {
187        WContainerWidget* wc = static_cast <WContainerWidget*> (parent());
188        for (int a=0; a<wc->count(); a++) {
189            if (static_cast <GWt_abstractElement*> (wc->widget (a))) {
190                //        GWt_abstractElement* ab = static_cast <GWt_abstractElement*> (wc->widget (a));
191                /*
192                 printf("1--->%d\n",ab->getElement());
193                 printf("2--->%d\n",ab->getElement()->getLenghtOfElement());
194                 printf("3--->%d\n",ab->getElement()->getName().getElementType());
195                 printf("4--->%d\n",elem.getElementType());
196                 
197                 if (static_cast <GWt_abstractElement*> (wc->widget (a))->getElement()->getName().getElementType() == elem.getElementType()) {
198                 pspa_->addConsoleMessage("type trouvÈ");
199                 } else {
200                 pspa_->addConsoleMessage("type trouvÈ NOT ");
201                 }
202                 */
203               
204            }
205        }
206       
207        int n = 999999;
208       
209        std::stringstream stream;
210        stream << n ;
211        std::string number(stream.str());
212       
213        if(n < 10) {
214            str= elem.getElementLabel()+"0"+number;
215        } else {
216            str= elem.getElementLabel()+number;
217        }
218    }
219   
220    return str;
221}
222
223
224void GWt_elementLigneFaisceau::setElementLabel(std::string label) {
225  if (elementLabel_) {
226    elementLabel_->setText(label);
227  }
228}
Note: See TracBrowser for help on using the repository browser.