[493] | 1 | |
---|
| 2 | #include <iostream> |
---|
| 3 | |
---|
| 4 | #include <Wt/WText> |
---|
| 5 | #include <Wt/WVBoxLayout> |
---|
| 6 | #include <Wt/WHBoxLayout> |
---|
| 7 | #include <Wt/WGridLayout> |
---|
| 8 | #include <Wt/WContainerWidget> |
---|
| 9 | #include <Wt/WImage> |
---|
| 10 | |
---|
| 11 | #include "GWt_computingBlock.h" |
---|
| 12 | //#include "GWt_softwarePanel.h" |
---|
| 13 | #include "GWt_machine.h" |
---|
| 14 | |
---|
| 15 | using namespace std; |
---|
| 16 | |
---|
| 17 | GWt_computingBlock::GWt_computingBlock(Wt::WComboBox* first,Wt::WComboBox* last,Wt::WComboBox* soft,Wt::WContainerWidget* buttonPanel, computingBlock* block,GWt_machine* machine) |
---|
| 18 | :WContainerWidget(), |
---|
| 19 | firstElement_(first), |
---|
| 20 | lastElement_(last), |
---|
| 21 | softElement_(soft), |
---|
| 22 | cpblock_(block), |
---|
| 23 | UImachine_(machine) |
---|
| 24 | { |
---|
| 25 | Wt::WGridLayout* mainContainerLayout = new Wt::WGridLayout(); |
---|
| 26 | mainContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 27 | |
---|
| 28 | Wt::WContainerWidget* labelAndComboContainer = new Wt::WContainerWidget(); |
---|
| 29 | Wt::WVBoxLayout* labelAndComboContainerLayout = new Wt::WVBoxLayout(); |
---|
| 30 | labelAndComboContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 31 | |
---|
| 32 | Wt::WContainerWidget* labelAndComboInsideContainer = new Wt::WContainerWidget(); |
---|
| 33 | Wt::WHBoxLayout* labelAndComboInsideContainerLayout = new Wt::WHBoxLayout(); |
---|
| 34 | labelAndComboInsideContainerLayout->setContentsMargins(0,0,0,0); |
---|
| 35 | |
---|
| 36 | labelAndComboInsideContainerLayout->addWidget(new Wt::WText("from : ")); |
---|
| 37 | labelAndComboInsideContainerLayout->addWidget(firstElement_); |
---|
| 38 | labelAndComboInsideContainerLayout->addWidget(new Wt::WText("to : ")); |
---|
| 39 | labelAndComboInsideContainerLayout->addWidget(lastElement_); |
---|
| 40 | labelAndComboInsideContainerLayout->addWidget(softElement_); |
---|
| 41 | |
---|
| 42 | // add buttons |
---|
| 43 | labelAndComboInsideContainerLayout->addWidget(buttonPanel); |
---|
| 44 | labelAndComboInsideContainer->setLayout(labelAndComboInsideContainerLayout); |
---|
| 45 | labelAndComboContainerLayout->addWidget(labelAndComboInsideContainer); |
---|
| 46 | labelAndComboContainerLayout->addStretch (10); |
---|
| 47 | labelAndComboContainer->setLayout(labelAndComboContainerLayout); |
---|
| 48 | |
---|
| 49 | // add errors and warning layout |
---|
| 50 | warningsContainer_ = new Wt::WContainerWidget(); |
---|
| 51 | errorsContainer_ = new Wt::WContainerWidget(); |
---|
| 52 | |
---|
| 53 | Wt::WContainerWidget* warningsAndErrorsContainer = new Wt::WContainerWidget(); |
---|
| 54 | Wt::WVBoxLayout* vWarningsAndErrorsLayoutContainer = new Wt::WVBoxLayout(); |
---|
| 55 | |
---|
| 56 | Wt::WHBoxLayout* hLayoutContainerWarnings = new Wt::WHBoxLayout(); |
---|
| 57 | Wt::WHBoxLayout* hLayoutContainerErrors = new Wt::WHBoxLayout(); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | warningsLabel_ = new Wt::WText("",XHTMLText); |
---|
| 61 | errorsLabel_ = new Wt::WText("",XHTMLText); |
---|
| 62 | hLayoutContainerWarnings->addWidget(warningsLabel_); |
---|
| 63 | hLayoutContainerErrors->addWidget(errorsLabel_); |
---|
| 64 | |
---|
| 65 | warningsAndErrorsContainer->addWidget(warningsLabel_); |
---|
| 66 | warningsAndErrorsContainer->addWidget(errorsLabel_); |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | // set Layouts |
---|
| 70 | warningsContainer_->setLayout(hLayoutContainerWarnings); |
---|
| 71 | errorsContainer_->setLayout(hLayoutContainerErrors); |
---|
| 72 | |
---|
| 73 | vWarningsAndErrorsLayoutContainer->addWidget(errorsContainer_); |
---|
| 74 | vWarningsAndErrorsLayoutContainer->addWidget(warningsContainer_); |
---|
| 75 | vWarningsAndErrorsLayoutContainer->addStretch (100); |
---|
| 76 | |
---|
| 77 | warningsAndErrorsContainer->setLayout(vWarningsAndErrorsLayoutContainer); |
---|
| 78 | |
---|
| 79 | // add label and Combo containers |
---|
| 80 | mainContainerLayout->addWidget(labelAndComboContainer,0,0); |
---|
| 81 | // add warnings and errors containers |
---|
| 82 | mainContainerLayout->addWidget(warningsAndErrorsContainer,1,0); |
---|
| 83 | |
---|
| 84 | // manage margins |
---|
| 85 | vWarningsAndErrorsLayoutContainer->setContentsMargins(20,0,0,0); |
---|
| 86 | hLayoutContainerWarnings->setContentsMargins(0,0,0,0); |
---|
| 87 | hLayoutContainerErrors->setContentsMargins(0,0,0,0); |
---|
| 88 | |
---|
| 89 | setLayout(mainContainerLayout); |
---|
| 90 | warningsContainer_->setStyleClass("warningsContainer"); |
---|
| 91 | errorsContainer_->setStyleClass("errorsContainer"); |
---|
| 92 | |
---|
| 93 | // resize combo |
---|
| 94 | firstElement_->setMinimumSize(80,12); |
---|
| 95 | lastElement_->setMinimumSize(80,12); |
---|
| 96 | softElement_->setMinimumSize(80,12); |
---|
| 97 | |
---|
| 98 | firstElement_->activated().connect(this,&GWt_computingBlock::changeFirstElement); |
---|
| 99 | lastElement_->activated().connect(this,&GWt_computingBlock::changeLastElement); |
---|
| 100 | // lastElement->activated().connect(softwarePanel,&GWt_softwarePanel::updateSections); |
---|
| 101 | softElement_->activated().connect(this,&GWt_computingBlock::setSoftware); |
---|
| 102 | this->redraw_.connect(UImachine_,&GWt_machine::displayWidgetComputing); |
---|
| 103 | |
---|
| 104 | manageWarningsAndErrors(); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | void GWt_computingBlock::setFirstElementCurrentSelection_deprecated(Wt::WString txt){ |
---|
| 109 | for (int a=0; a< firstElement_->count(); a++) { |
---|
| 110 | if (firstElement_->itemText(a) == txt) { |
---|
| 111 | firstElement_->setCurrentIndex (a); |
---|
| 112 | return; |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | void GWt_computingBlock::setLastElementCurrentSelection_deprecated(Wt::WString txt){ |
---|
| 118 | for (int a=0; a< lastElement_->count(); a++) { |
---|
| 119 | if (lastElement_->itemText(a) == txt) { |
---|
| 120 | lastElement_->setCurrentIndex (a); |
---|
| 121 | return; |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | void GWt_computingBlock::setSoftwareElementCurrentSelection_deprecated(Wt::WString txt){ |
---|
| 127 | for (int a=0; a< softElement_->count(); a++) { |
---|
| 128 | if (softElement_->itemText(a) == txt) { |
---|
| 129 | softElement_->setCurrentIndex (a); |
---|
| 130 | return; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | void GWt_computingBlock::manageWarningsAndErrors(){ |
---|
| 137 | if (warningsLabel_->text() == "") { |
---|
| 138 | warningsContainer_->hide(); |
---|
| 139 | } else { |
---|
| 140 | warningsContainer_->show(); |
---|
| 141 | } |
---|
| 142 | if (errorsLabel_->text() == "") { |
---|
| 143 | errorsContainer_->hide(); |
---|
| 144 | } else { |
---|
| 145 | errorsContainer_->show(); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | void GWt_computingBlock::setSoftware() |
---|
| 152 | { |
---|
| 153 | |
---|
| 154 | UImachine_->getMachineControler()->setSoftware(softElement_->currentText().toUTF8(), cpblock_); |
---|
| 155 | // UIsector_->getBeamLineWidget()->buildBeamLineWidget(); |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | void GWt_computingBlock::changeFirstElement() |
---|
| 160 | { |
---|
| 161 | if (!cpblock_) return; |
---|
| 162 | if (!UImachine_) return; |
---|
| 163 | |
---|
| 164 | UImachine_->getMachineControler()->setFirstElementOfBlock(cpblock_, firstElement_->currentIndex()); |
---|
| 165 | redraw_.emit(); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | void GWt_computingBlock::changeLastElement() |
---|
| 169 | { |
---|
| 170 | if (!cpblock_) return; |
---|
| 171 | if (!UImachine_) return; |
---|
| 172 | |
---|
| 173 | UImachine_->getMachineControler()->setLastElementOfBlock(cpblock_, lastElement_->currentIndex()); |
---|
| 174 | redraw_.emit(); |
---|
| 175 | } |
---|