1 | |
---|
2 | #include <iostream> |
---|
3 | #include <string> |
---|
4 | |
---|
5 | #include "GWt_abstractElement.h" |
---|
6 | #include "GWt_elementLigneFaisceau.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_draggableImage.h" |
---|
15 | #include "GWt_ligneFaisceau.h" |
---|
16 | |
---|
17 | #include "mixedTools.h" |
---|
18 | #include "nomdElements.h" |
---|
19 | |
---|
20 | #include <Wt/WText> |
---|
21 | #include <Wt/WLineEdit> |
---|
22 | #include <Wt/WBreak> |
---|
23 | #include <Wt/WApplication> |
---|
24 | #include <Wt/WMessageBox> |
---|
25 | |
---|
26 | GWt_abstractElement::GWt_abstractElement(abstractElement* elem) |
---|
27 | : WContainerWidget() |
---|
28 | { |
---|
29 | abstractElement_ = elem; |
---|
30 | setStyleClass("beamLineIcon"); |
---|
31 | } |
---|
32 | |
---|
33 | |
---|
34 | void GWt_abstractElement::initialize() |
---|
35 | { |
---|
36 | // make image |
---|
37 | image_ = new WImage(getBigImageURL(),this); |
---|
38 | |
---|
39 | // activate slots |
---|
40 | image_->doubleClicked().connect(this,&GWt_abstractElement::doubleClicked); |
---|
41 | image_->clicked().connect(this,&GWt_abstractElement::clicked); |
---|
42 | addWidget(image_); |
---|
43 | updateLabelAndToolTipWidget(); |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | string* GWt_abstractElement::beginDialog() |
---|
48 | { |
---|
49 | string* param = abstractElement_-> getParametersString(); |
---|
50 | |
---|
51 | if ( param == NULL ) |
---|
52 | { |
---|
53 | if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
54 | GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
55 | console->addConsoleMessage(" GWt_abstractElement::beginDialog : empty parameter set for element " + abstractElement_->getNomdElement().getElementName()); |
---|
56 | } |
---|
57 | } |
---|
58 | // int compteur = -1; |
---|
59 | |
---|
60 | // int nbparam = atoi(param[++compteur].c_str()); |
---|
61 | int nbparam = atoi(param->c_str()); |
---|
62 | if ( nbparam != abstractElement_->getNbParams()) |
---|
63 | { |
---|
64 | if ( static_cast<GWt_console*> (wApp->findWidget ("console"))) { |
---|
65 | GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); |
---|
66 | console->addConsoleMessage(" element seems not to be a " + abstractElement_->getNomdElement().getElementName()); |
---|
67 | } |
---|
68 | } |
---|
69 | |
---|
70 | dialog_ = new WDialog("element " + abstractElement_->getNomdElement().getElementName()); |
---|
71 | new WText(" label of the element : ",dialog_->contents()); |
---|
72 | // labelEdit_ = new WLineEdit(param[++compteur].c_str(), dialog_->contents()); |
---|
73 | |
---|
74 | labelEdit_ = new WLineEdit( (++param)->c_str(), dialog_->contents()); |
---|
75 | new WBreak(dialog_->contents()); |
---|
76 | return ++param; |
---|
77 | } |
---|
78 | |
---|
79 | void GWt_abstractElement::updateLabelAndToolTipWidget() |
---|
80 | { |
---|
81 | elementLigneFaiseauContainer_->setElementLabel(abstractElement_->getLabel()); |
---|
82 | setToolTip(print()); |
---|
83 | } |
---|
84 | |
---|
85 | void GWt_abstractElement::clicked() |
---|
86 | { |
---|
87 | initilializeDialog(); |
---|
88 | dialog_->show(); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | void GWt_abstractElement::doubleClicked() |
---|
93 | { |
---|
94 | StandardButton result = WMessageBox::show("PSPA : Delete element", WString("Delete '")+WString(getAbstractElement()->getLabel())+"' ?", Ok | Cancel); |
---|
95 | |
---|
96 | if (result == Cancel ) { |
---|
97 | return; |
---|
98 | } |
---|
99 | // get LigneFaiseau widget and add new elementLigneFaiseau |
---|
100 | GWt_LigneFaisceau* ligneFaisceau = NULL; |
---|
101 | if ( static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau"))) { |
---|
102 | ligneFaisceau = static_cast<GWt_LigneFaisceau*> (wApp->findWidget ("ligneFaisceau")); |
---|
103 | } else { |
---|
104 | return; |
---|
105 | } |
---|
106 | |
---|
107 | ligneFaisceau->removeElement(this); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | WContainerWidget* GWt_abstractElement::getWidget() { |
---|
112 | return wc_; |
---|
113 | } |
---|
114 | |
---|
115 | abstractElement* GWt_abstractElement::getAbstractElement() { |
---|
116 | return abstractElement_; |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | void GWt_abstractElement::createDragImage(WContainerWidget* w){ |
---|
121 | |
---|
122 | GWt_draggableImage *result = new GWt_draggableImage(getBigImageURL(),w); |
---|
123 | |
---|
124 | /* |
---|
125 | * Set the image to be draggable, showing the other image (dragImage) |
---|
126 | * to be used as the widget that is visually dragged. |
---|
127 | */ |
---|
128 | result->setDraggable(getMimeType(),new WImage(getSmallImageURL(),w),true); |
---|
129 | } |
---|
130 | |
---|
131 | WImage* GWt_abstractElement::getImage() { |
---|
132 | return image_; |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | void GWt_abstractElement::FileInput(ifstream& ifs){ |
---|
137 | getAbstractElement()->FileInput(ifs); |
---|
138 | initilializeDialog(); |
---|
139 | updateLabelAndToolTipWidget(); |
---|
140 | } |
---|