1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "EditionSalomeNode.hxx"
20 #include "FormComponent.hxx"
21 #include "FormContainer.hxx"
22 #include "ServiceNode.hxx"
23 #include "ComponentInstance.hxx"
24 #include "QtGuiContext.hxx"
25 #include "Container.hxx"
32 #include "YacsTrace.hxx"
37 using namespace YACS::ENGINE;
38 using namespace YACS::HMI;
40 EditionSalomeNode::EditionSalomeNode(Subject* subject,
43 : EditionElementaryNode(subject, parent, name)
46 // --- create container and component panels
48 _wContainer = new FormContainer(this);
49 _wid->gridLayout1->addWidget(_wContainer);
51 connect(_wContainer->cb_host, SIGNAL(mousePressed()),
52 this, SLOT(fillContainerPanel()));
53 connect(_wContainer->cb_host, SIGNAL(activated(int)),
54 this, SLOT(changeHost(int)));
55 connect(_wContainer->tb_container, SIGNAL(toggled(bool)),
56 this, SLOT(fillContainerPanel())); // --- to update display of current selection
58 _wComponent = new FormComponent(this);
59 _wid->gridLayout1->addWidget(_wComponent);
61 connect(_wComponent->cb_instance, SIGNAL(mousePressed()),
62 this, SLOT(fillComponentPanel()));
63 connect(_wComponent->cb_instance, SIGNAL(activated(int)),
64 this, SLOT(changeInstance(int)));
66 connect(_wComponent->cb_container, SIGNAL(mousePressed()),
67 this, SLOT(fillContainerPanel()));
68 connect(_wComponent->cb_container, SIGNAL(activated(int)),
69 this, SLOT(changeContainer(int)));
71 connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
72 this, SLOT(fillComponentPanel())); // --- to update display of current selection
73 connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
74 this, SLOT(fillContainerPanel())); // --- to update display of current selection
78 _hbl_method = new QHBoxLayout();
79 _la_method = new QLabel(this);
80 _hbl_method->addWidget(_la_method);
81 _le_method = new QLineEdit(this);
82 _hbl_method->addWidget(_le_method);
83 _wid->gridLayout1->addLayout(_hbl_method, _wid->gridLayout1->rowCount(), 0, 1, 1);
84 _la_method->setText("Method:");
85 // SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
88 dynamic_cast<YACS::ENGINE::ServiceNode*>(_subElemNode->getNode());
90 _le_method->setText((_servNode->getMethod()).c_str());
91 _le_method->setReadOnly(true);
93 // --- fill component panel
100 EditionSalomeNode::~EditionSalomeNode()
104 void EditionSalomeNode::update(GuiEvent event, int type, Subject* son)
106 DEBTRACE("EditionSalomeNode::update ");
107 EditionElementaryNode::update(event, type, son);
108 SubjectReference* subref= 0;
113 subref = dynamic_cast<SubjectReference*>(son);
115 DEBTRACE(subref->getName() << " " << subref->getReference()->getName());
116 fillComponentPanel();
120 DEBTRACE("ASSOCIATE");
121 fillContainerPanel();
129 /*! must be updated when associate service to component instance, or when the list of
130 * available component instances changes.
132 void EditionSalomeNode::fillComponentPanel()
134 ComponentInstance *compoInst = _servNode->getComponent();
137 _wComponent->le_name ->setText(compoInst->getCompoName().c_str());
138 Proc* proc = GuiContext::getCurrent()->getProc();
140 _wComponent->cb_instance->clear();
141 map<pair<string,int>,ComponentInstance*>::const_iterator it = proc->componentInstanceMap.begin();
142 for(; it != proc->componentInstanceMap.end(); ++it)
144 ComponentInstance *inst=(*it).second;
145 QString compoName = inst->getCompoName().c_str();
146 if (! QString::compare(compoInst->getCompoName().c_str(), compoName)) // if same component name
147 //instanceMap[inst->getInstanceName()] = inst;
148 _wComponent->cb_instance->addItem( QString(inst->getInstanceName().c_str()));
151 int index = _wComponent->cb_instance->findText(compoInst->getInstanceName().c_str());
152 //DEBTRACE("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " << index);
153 _wComponent->cb_instance->setCurrentIndex(index);
157 void EditionSalomeNode::fillContainerPanel()
159 ComponentInstance *compoInst = _servNode->getComponent();
162 Proc* proc = GuiContext::getCurrent()->getProc();
164 _wComponent->cb_container->clear();
165 map<string,Container*>::const_iterator it = proc->containerMap.begin();
166 for(; it != proc->containerMap.end(); ++it)
167 _wComponent->cb_container->addItem( QString((*it).first.c_str()));
169 int index = _wComponent->cb_container->findText(compoInst->getContainer()->getName().c_str());
170 _wComponent->cb_container->setCurrentIndex(index);
172 _wContainer->le_name->setText(compoInst->getContainer()->getName().c_str());
173 _wContainer->le_instance->setReadOnly(true);
175 _wContainer->cb_host->clear();
176 _wContainer->cb_host->addItem(""); // --- when no host selected
177 list<string> machines = QtGuiContext::getQtCurrent()->getGMain()->getMachineList();
178 list<string>::iterator itm = machines.begin();
179 for( ; itm != machines.end(); ++itm)
181 _wContainer->cb_host->addItem(QString((*itm).c_str()));
187 void EditionSalomeNode::changeInstance(int index)
189 string instName = _wComponent->cb_instance->itemText(index).toStdString();
190 int i = instName.find_last_of('_');
193 DEBTRACE(instName << " " << i);
194 string compoName = instName;
196 string inst = instName;
198 DEBTRACE(instName << " " << compoName << " " << inst);
199 i = atoi(inst.c_str());
200 pair<string,int> aKey(compoName,i);
202 Proc* proc = GuiContext::getCurrent()->getProc();
203 ComponentInstance *newCompoInst = 0;
204 ComponentInstance *oldCompoInst = _servNode->getComponent();
205 if (proc->componentInstanceMap.count(aKey))
206 newCompoInst = proc->componentInstanceMap[aKey];
207 else DEBTRACE("-------------> not found : " << instName);
209 if (newCompoInst && (newCompoInst != oldCompoInst))
211 assert(GuiContext::getCurrent()->_mapOfSubjectComponent.count(newCompoInst));
212 SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
213 ssn->associateToComponent(GuiContext::getCurrent()->_mapOfSubjectComponent[newCompoInst]);
217 void EditionSalomeNode::changeContainer(int index)
219 string contName = _wComponent->cb_container->itemText(index).toStdString();
221 ComponentInstance *compoInst = _servNode->getComponent();
222 Container *oldContainer = compoInst->getContainer();
224 Container *newContainer = 0;
225 Proc* proc = GuiContext::getCurrent()->getProc();
226 if (proc->containerMap.count(contName))
227 newContainer = proc->containerMap[contName];
230 DEBTRACE("-------------> not found : " << contName);
233 assert(GuiContext::getCurrent()->_mapOfSubjectContainer.count(newContainer));
234 SubjectContainer *scnt = GuiContext::getCurrent()->_mapOfSubjectContainer[newContainer];
236 SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
237 SubjectComponent *sco =
238 dynamic_cast<SubjectComponent*>(ssn->getSubjectReference()->getReference());
240 sco->associateToContainer(scnt);
243 void EditionSalomeNode::changeHost(int index)
245 string hostName = _wContainer->cb_host->itemText(index).toStdString();