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

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

deplacement bouton expand machine vers computing view

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