source: PSPA/Interface_Web/trunk/pspaWT/sources/userInterface/src/GWt_softwarePanel.cc @ 495

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

maj de History

File size: 7.6 KB
Line 
1//  GWt_softwarePanel.cpp
2//  PSPA
3//
4//  Created by Garnier Laurent on 30/01/13.//  Copyright (c) 2013 Garnier Laurent. All rights reserved.
5//
6
7#include <Wt/WLineEdit>
8#include <Wt/WText>
9#include <Wt/WComboBox>
10#include <Wt/WPanel>
11#include <Wt/WBreak>
12#include <Wt/WApplication>
13#include <Wt/WVBoxLayout>
14
15#include "GWt_softwarePanel.h"
16#include "GWt_dialog.h"
17#include "GWt_console.h"
18#include "GWt_computingBlock.h"
19#include "GWt_globalParameters.h"
20#include "GWt_sectionToExecute.h"
21#include "GWt_pspaApplication.h"
22#include "GWt_machine.h"
23#define BAVARD 1
24
25GWt_softwarePanel::GWt_softwarePanel(dataManager* dataManager,GWt_machine* mach)
26  : WContainerWidget(),
27dtmanage_(dataManager),
28UImachine_(mach)
29{
30 
31  // le panel
32  WPanel *panelLogiciels = new WPanel(this);
33  panelLogiciels->setTitle(" Computing blocks ");
34 
35  contenuSections_ = new WContainerWidget();
36  contenuSections_->addWidget(new WBreak());
37  contenuSections_->addWidget(new WBreak());
38  cout << " GWt_softwarePanel::GWt_softwarePanel DISPLAY SOFTWARE PANEL " << endl;
39      displayFromControler();
40 
41  panelLogiciels->setCentralWidget(contenuSections_);
42}
43
44GWt_softwarePanel::~GWt_softwarePanel() {
45}
46
47void GWt_softwarePanel::displayFromControler()
48{     
49  cout << " GWt_softwarePanel::displayFromControler() " << endl<<endl;
50
51  // Clear all
52  contenuSections_->clear();
53
54
55  // Get all sectionsToExecute from this machine
56  if (!UImachine_->getMachineControler()) {
57    cout << " GWt_softwarePanel::displayFromControler() PAS DE MACHINE " << endl;
58    return;
59  } else {
60    cout << " GWt_softwarePanel::displayFromControler() MACHINE TROUVEE " << endl;
61  }
62 
63  if (UImachine_->getMachineControler()->getComputingBlocks().size() == 0) {
64    // FIXME : Add a message to tell the user to add first an element
65    cout << " GWt_softwarePanel::displayFromControler() PAS DE BLOCK " << endl;
66  } else {
67    cout << " GWt_softwarePanel::displayFromControler() NOMBRE DE BLOCK " << UImachine_->getMachineControler()->getComputingBlocks().size() << endl;
68
69    unsigned int firstElemeOfComputingBlockIndex = 0;
70
71    for (unsigned int a=0; a<UImachine_->getMachineControler()->getComputingBlocks().size(); a++) {
72      cout << " GWt_softwarePanel::displayFromControler() BLOC No " << a+1 << endl;
73      abstractElement* premierElement = NULL;
74      abstractElement* dernierElement = NULL;
75      std::string premierElementLabel = "";
76      std::string dernierElementLabel = "";
77
78      if ( !UImachine_->getMachineControler()->getComputingBlocks()[a]->isEmpty() ) {
79        premierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getFirstElement();
80        firstElemeOfComputingBlockIndex = UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfFirstElement();
81        dernierElement = UImachine_->getMachineControler()->getComputingBlocks()[a]->getLastElement();
82      }
83
84
85      if (premierElement) premierElementLabel = premierElement->getLabel();
86      if (dernierElement) dernierElementLabel = dernierElement->getLabel();
87      cout << " GWt_softwarePanel::displayFromControler() dernier element a afficher " << dernierElementLabel << endl;
88     
89      WComboBox* lineFromCombo = new WComboBox();
90      WComboBox* lineToCombo = new WComboBox();
91      fillComboWithElements(lineFromCombo);
92      fillComboWithElements(lineToCombo);
93     
94      // set to first
95      lineFromCombo->setCurrentIndex(firstElemeOfComputingBlockIndex);
96      // set to last
97      lineToCombo->setCurrentIndex(UImachine_->getMachineControler()->getComputingBlocks()[a]->getRankOfLastElement());
98      WComboBox* softCombo = new WComboBox();
99     
100      fillComboWithSoftwares(softCombo,UImachine_->getMachineControler()->getComputingBlocks()[a]->getSoftware()->getName());
101
102      // disable the "to" comboBox
103      lineToCombo->disable();
104
105      // disable the first "from" comboBox
106      // if (a==0) {
107      //   lineFromCombo->disable();
108      // }
109
110      // enable the last "to" comboBox
111      if (a==UImachine_->getMachineControler()->getComputingBlocks().size()-1) {
112                lineToCombo->enable();
113      }
114     
115      // // Add computingBlock Widget
116     
117      //      GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(a),UImachine_->getMachineControler()->getComputingBlocks()[a],UImachine_);
118      computingBlock* blocPtr = UImachine_->getMachineControler()->getComputingBlocks()[a];
119      GWt_computingBlock* newBlock = new GWt_computingBlock(lineFromCombo,lineToCombo,softCombo,createAddDeletePushButtons(blocPtr),blocPtr,UImachine_);
120
121      cout << " GWt_softwarePanel::displayFromControler j'ajoute un bloc : " << newBlock << endl;
122      cout << " GWt_softwarePanel::displayFromControler nb widget avant : " << contenuSections_->count() << endl;
123      contenuSections_->addWidget(newBlock);
124      cout << " GWt_softwarePanel::displayFromControler nb widget apres : " << contenuSections_->count() << endl;
125     
126    }
127  }
128}
129
130void GWt_softwarePanel::fillComboWithElements(Wt::WComboBox* cBox) 
131{
132
133  if (cBox == NULL) return;
134
135  if (!UImachine_->getMachineControler()) {
136    return;
137  }
138    for(unsigned int b=0; b < UImachine_->getMachineControler()->getElements().size(); b++) {
139     
140      abstractElement* abs = UImachine_->getMachineControler()->getElements()[b];
141      if (abs != NULL) {
142        cBox->addItem(abs->getLabel());
143      }
144    }
145}
146
147void GWt_softwarePanel::fillComboWithSoftwares(Wt::WComboBox* cBox, std::string selected)
148{
149#if BAVARD > 0
150  cout << "***********************************" << endl;
151  cout << " GWt_softwarePanel::fillComboWithSoftwares " << endl<<endl;
152#endif
153
154  if (cBox == NULL) return;
155  cBox->clear();
156
157  unsigned nb = nomDeLogiciel::getNumberOfSoftwares();
158  unsigned k;
159  for(k = 0; k <= nb; k++) { //xx
160    cBox->addItem(nomDeLogiciel(k).getString());
161    if (nomDeLogiciel(k).getString() == selected) {
162      cBox->setCurrentIndex(cBox->count()-1);
163    }
164  }
165  cBox->refresh();
166}
167
168
169Wt::WContainerWidget* GWt_softwarePanel::createAddDeletePushButtons(computingBlock* cpbl) 
170{
171  WContainerWidget* buttonContainer= new WContainerWidget();
172 
173  Wt::WHBoxLayout* buttonContainerLayout = new Wt::WHBoxLayout();
174  buttonContainerLayout->setContentsMargins(0,0,0,0);
175  // preparation du bouton add
176  WPushButton* exec_add = new WPushButton("+");
177  //  exec_add->clicked().connect(this, &GWt_softwarePanel::addComputingBlock);
178  exec_add->clicked().connect(boost::bind(&GWt_softwarePanel::addComputingBlock, this, cpbl));
179  exec_add->setStyleClass("roundButton");
180  exec_add->setMaximumSize(20,20);
181  exec_add->setToolTip("Add new section");
182 
183  // preparation du bouton delete
184  WPushButton* exec_delete = new WPushButton("-");
185  //  warningsContainer_->setStyleClass("warningsContainer");
186
187  exec_delete->clicked().connect(boost::bind(&GWt_softwarePanel::deleteComputingBlock, this, cpbl));
188  exec_delete->setStyleClass("roundButton");
189  exec_delete->setMaximumSize(20,20);
190  exec_delete->setToolTip("Remove this section");
191
192  buttonContainerLayout->addWidget(exec_add);
193  buttonContainerLayout->addWidget(exec_delete);
194  buttonContainer->setLayout(buttonContainerLayout);
195
196  return buttonContainer;
197}
198
199void GWt_softwarePanel::addComputingBlock(computingBlock* cpbl) {
200  // We put the last element of the previous sectionToExecute inside
201 
202  if (!UImachine_->getMachineControler()) {
203    return;
204  }
205  //  UImachine_->getMachineControler()->openNewLastBlock();
206    UImachine_->getMachineControler()->openNewBlockAfter(cpbl);
207  displayFromControler();
208}
209
210
211
212void GWt_softwarePanel::deleteComputingBlock(computingBlock* cpbl)
213{
214  cout << " GWt_softwarePanel::deleteComputingBlock(computingBlock*)" << endl;
215
216  UImachine_->getMachineControler()->eraseComputingBlock(cpbl);
217  displayFromControler();
218}
Note: See TracBrowser for help on using the repository browser.