Version: 8.3.0
EditionSalomeNode.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include "EditionSalomeNode.hxx"
21 #include "PropertyEditor.hxx"
22 #include "FormComponent.hxx"
23 #include "FormContainer.hxx"
24 #include "ServiceNode.hxx"
25 #include "ComponentInstance.hxx"
26 #include "QtGuiContext.hxx"
27 #include "Container.hxx"
28 #include "Message.hxx"
29 
30 #include <cassert>
31 #include <map>
32 #include <string>
33 
34 //#define _DEVDEBUG_
35 #include "YacsTrace.hxx"
36 
37 using namespace std;
38 
39 using namespace YACS;
40 using namespace YACS::ENGINE;
41 using namespace YACS::HMI;
42 
43 EditionSalomeNode::EditionSalomeNode(Subject* subject,
44  QWidget* parent,
45  const char* name)
46  : EditionElementaryNode(subject, parent, name)
47 {
48  // SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
49  // YASSERT(ssn);
52  // --- create property editor panel
54  _wid->gridLayout1->addWidget(_propeditor);
55 
56  // --- create container and component panels
57 
59  _wid->gridLayout1->addWidget(_wContainer);
60 
61  connect(_wContainer, SIGNAL(resourceMousePressed()), this, SLOT(fillContainerPanel()));
62  connect(_wContainer, SIGNAL(resourceActivated(int)), this, SLOT(changeHost(int)));
63  connect(_wContainer, SIGNAL(containerToggled(bool)), this, SLOT(fillContainerPanel()));
64  // --- to update display of current selection
65 
66  _wComponent = new FormComponent(this);
67  _wid->gridLayout1->addWidget(_wComponent);
68 
69  connect(_wComponent->cb_instance, SIGNAL(mousePressed()),
70  this, SLOT(fillComponentPanel()));
71  connect(_wComponent->cb_instance, SIGNAL(activated(int)),
72  this, SLOT(changeInstance(int)));
73 
74  connect(_wComponent->cb_container, SIGNAL(mousePressed()),
75  this, SLOT(fillContainerPanel()));
76  connect(_wComponent->cb_container, SIGNAL(activated(int)),
77  this, SLOT(changeContainer(int)));
78 
79  connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
80  this, SLOT(fillComponentPanel())); // --- to update display of current selection
81  connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
82  this, SLOT(fillContainerPanel())); // --- to update display of current selection
83 
84  // --- method
85 
86  _hbl_method = new QHBoxLayout();
87  _la_method = new QLabel(this);
88  _hbl_method->addWidget(_la_method);
89  _le_method = new QLineEdit(this);
90  _hbl_method->addWidget(_le_method);
91  _wid->gridLayout1->addLayout(_hbl_method, _wid->gridLayout1->rowCount(), 0, 1, 1);
92  _la_method->setText("Method:");
93 
94  _le_method->setText((_servNode->getMethod()).c_str());
95  _le_method->setReadOnly(true);
96 
97  // --- fill component panel
98 
100 
101  createTablePorts(_wid->gridLayout1);
102 }
103 
105 {
106 }
107 
108 void EditionSalomeNode::update(GuiEvent event, int type, Subject* son)
109 {
110  DEBTRACE("EditionSalomeNode::update ");
111  EditionElementaryNode::update(event, type, son);
112  SubjectReference* subref= 0;
113  switch (event)
114  {
115  case ADDREF:
116  DEBTRACE("ADDREF");
117  subref = dynamic_cast<SubjectReference*>(son);
118  YASSERT(subref);
119  DEBTRACE(subref->getName() << " " << subref->getReference()->getName());
122  break;
123 
124  case ASSOCIATE:
125  DEBTRACE("ASSOCIATE");
127  break;
128 
129  case SETVALUE:
130  _propeditor->update();
131  break;
132 
133  default:
134  ;
135  }
136 }
137 
139 {
142  _wComponent->tb_component->setChecked(FormComponent::_checked);
145 }
146 
151 {
152  ComponentInstance *compoInst = _servNode->getComponent();
153  if (compoInst)
154  {
155  _wComponent->le_name ->setText(compoInst->getCompoName().c_str());
156  Proc* proc = GuiContext::getCurrent()->getProc();
157 
158  _wComponent->cb_instance->clear();
159  map<string,ComponentInstance*>::const_iterator it = proc->componentInstanceMap.begin();
160  for(; it != proc->componentInstanceMap.end(); ++it)
161  {
162  ComponentInstance *inst=(*it).second;
163  QString compoName = inst->getCompoName().c_str();
164  if (! QString::compare(compoInst->getCompoName().c_str(), compoName)) // if same component name
165  //instanceMap[inst->getInstanceName()] = inst;
166  _wComponent->cb_instance->addItem( QString(inst->getInstanceName().c_str()));
167  }
168 
169  int index = _wComponent->cb_instance->findText(compoInst->getInstanceName().c_str());
170  //DEBTRACE("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " << index);
171  _wComponent->cb_instance->setCurrentIndex(index);
172  }
173 }
174 
176 {
177  DEBTRACE("EditionSalomeNode::fillContainerPanel");
178  ComponentInstance *compoInst = _servNode->getComponent();
179  if (compoInst)
180  {
181  Proc* proc = GuiContext::getCurrent()->getProc();
182 
183  _wComponent->cb_container->clear();
184  map<string,Container*>::const_iterator it = proc->containerMap.begin();
185  for(; it != proc->containerMap.end(); ++it)
186  _wComponent->cb_container->addItem( QString((*it).first.c_str()));
187 
188  Container * cont = compoInst->getContainer();
189  if (cont)
190  {
191  int index = _wComponent->cb_container->findText(cont->getName().c_str());
192  _wComponent->cb_container->setCurrentIndex(index);
193  _wContainer->FillPanel(cont);
194  }
195  }
196 }
197 
198 
200 {
201  string instName = _wComponent->cb_instance->itemText(index).toStdString();
202  Proc* proc = GuiContext::getCurrent()->getProc();
203  ComponentInstance *newCompoInst = 0;
204  ComponentInstance *oldCompoInst = _servNode->getComponent();
205  if (proc->componentInstanceMap.count(instName))
206  newCompoInst = proc->componentInstanceMap[instName];
207  else DEBTRACE("-------------> not found : " << instName);
208 
209  if (newCompoInst && (newCompoInst != oldCompoInst))
210  {
211  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(newCompoInst));
212  SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
213  if(!ssn->associateToComponent(GuiContext::getCurrent()->_mapOfSubjectComponent[newCompoInst]))
214  Message mess;
215  }
216 }
217 
219 {
220  string contName = _wComponent->cb_container->itemText(index).toStdString();
221  DEBTRACE(contName);
222  ComponentInstance *compoInst = _servNode->getComponent();
223  Container *oldContainer = compoInst->getContainer();
224 
225  Container *newContainer = 0;
226  Proc* proc = GuiContext::getCurrent()->getProc();
227  if (proc->containerMap.count(contName))
228  newContainer = proc->containerMap[contName];
229  if (!newContainer)
230  {
231  DEBTRACE("-------------> not found : " << contName);
232  return;
233  }
234  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(newContainer));
235  SubjectContainerBase *scnt(GuiContext::getCurrent()->_mapOfSubjectContainer[newContainer]);
236 
237  SubjectServiceNode *ssn(dynamic_cast<SubjectServiceNode*>(_subject));
238  SubjectComponent *sco(dynamic_cast<SubjectComponent*>(ssn->getSubjectReference()->getReference()));
239  YASSERT(sco);
240  sco->associateToContainer(scnt);
241 }
242 
244 {
245  string hostName = _wContainer->getHostName(index);
246  DEBTRACE(hostName);
247 }
248 
250 {
251  DEBTRACE("EditionSalomeNode::onApply");
252  bool edited = true;
253  if (_wContainer->onApply())
254  edited = false;
255  _isEdited = _isEdited || edited;
257 }
258 
260 {
261  DEBTRACE("EditionSalomeNode::onCancel");
262  ComponentInstance *compoInst = _servNode->getComponent();
263  if (compoInst)
264  {
265  _wContainer->FillPanel(compoInst->getContainer());
266  }
268 }