1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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
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"
35 #include "YacsTrace.hxx"
40 using namespace YACS::ENGINE;
41 using namespace YACS::HMI;
43 EditionSalomeNode::EditionSalomeNode(Subject* subject,
46 : EditionElementaryNode(subject, parent, name)
49 // --- create property editor panel
50 _propeditor=new PropertyEditor(_subject);
51 _wid->gridLayout1->addWidget(_propeditor);
53 // --- create container and component panels
55 _wContainer = new FormContainer(this);
56 _wid->gridLayout1->addWidget(_wContainer);
58 connect(_wContainer->cb_resource, SIGNAL(mousePressed()),
59 this, SLOT(fillContainerPanel()));
60 connect(_wContainer->cb_resource, SIGNAL(activated(int)),
61 this, SLOT(changeHost(int)));
62 connect(_wContainer->tb_container, SIGNAL(toggled(bool)),
63 this, SLOT(fillContainerPanel())); // --- to update display of current selection
65 _wComponent = new FormComponent(this);
66 _wid->gridLayout1->addWidget(_wComponent);
68 connect(_wComponent->cb_instance, SIGNAL(mousePressed()),
69 this, SLOT(fillComponentPanel()));
70 connect(_wComponent->cb_instance, SIGNAL(activated(int)),
71 this, SLOT(changeInstance(int)));
73 connect(_wComponent->cb_container, SIGNAL(mousePressed()),
74 this, SLOT(fillContainerPanel()));
75 connect(_wComponent->cb_container, SIGNAL(activated(int)),
76 this, SLOT(changeContainer(int)));
78 connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
79 this, SLOT(fillComponentPanel())); // --- to update display of current selection
80 connect(_wComponent->tb_component, SIGNAL(toggled(bool)),
81 this, SLOT(fillContainerPanel())); // --- to update display of current selection
85 _hbl_method = new QHBoxLayout();
86 _la_method = new QLabel(this);
87 _hbl_method->addWidget(_la_method);
88 _le_method = new QLineEdit(this);
89 _hbl_method->addWidget(_le_method);
90 _wid->gridLayout1->addLayout(_hbl_method, _wid->gridLayout1->rowCount(), 0, 1, 1);
91 _la_method->setText("Method:");
92 // SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
95 dynamic_cast<YACS::ENGINE::ServiceNode*>(_subElemNode->getNode());
97 _le_method->setText((_servNode->getMethod()).c_str());
98 _le_method->setReadOnly(true);
100 // --- fill component panel
102 fillComponentPanel();
104 createTablePorts(_wid->gridLayout1);
107 EditionSalomeNode::~EditionSalomeNode()
111 void EditionSalomeNode::update(GuiEvent event, int type, Subject* son)
113 DEBTRACE("EditionSalomeNode::update ");
114 EditionElementaryNode::update(event, type, son);
115 SubjectReference* subref= 0;
120 subref = dynamic_cast<SubjectReference*>(son);
122 DEBTRACE(subref->getName() << " " << subref->getReference()->getName());
123 fillComponentPanel();
124 fillContainerPanel();
128 DEBTRACE("ASSOCIATE");
129 fillContainerPanel();
133 _propeditor->update();
141 void EditionSalomeNode::synchronize()
143 EditionElementaryNode::synchronize();
144 _wContainer->tb_container->setChecked(FormContainer::_checked);
145 _wComponent->tb_component->setChecked(FormComponent::_checked);
146 fillComponentPanel();
147 fillContainerPanel();
150 /*! must be updated when associate service to component instance, or when the list of
151 * available component instances changes.
153 void EditionSalomeNode::fillComponentPanel()
155 ComponentInstance *compoInst = _servNode->getComponent();
158 _wComponent->le_name ->setText(compoInst->getCompoName().c_str());
159 Proc* proc = GuiContext::getCurrent()->getProc();
161 _wComponent->cb_instance->clear();
162 map<string,ComponentInstance*>::const_iterator it = proc->componentInstanceMap.begin();
163 for(; it != proc->componentInstanceMap.end(); ++it)
165 ComponentInstance *inst=(*it).second;
166 QString compoName = inst->getCompoName().c_str();
167 if (! QString::compare(compoInst->getCompoName().c_str(), compoName)) // if same component name
168 //instanceMap[inst->getInstanceName()] = inst;
169 _wComponent->cb_instance->addItem( QString(inst->getInstanceName().c_str()));
172 int index = _wComponent->cb_instance->findText(compoInst->getInstanceName().c_str());
173 //DEBTRACE("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " << index);
174 _wComponent->cb_instance->setCurrentIndex(index);
178 void EditionSalomeNode::fillContainerPanel()
180 DEBTRACE("EditionSalomeNode::fillContainerPanel");
181 ComponentInstance *compoInst = _servNode->getComponent();
184 Proc* proc = GuiContext::getCurrent()->getProc();
186 _wComponent->cb_container->clear();
187 map<string,Container*>::const_iterator it = proc->containerMap.begin();
188 for(; it != proc->containerMap.end(); ++it)
189 _wComponent->cb_container->addItem( QString((*it).first.c_str()));
191 Container * cont = compoInst->getContainer();
194 int index = _wComponent->cb_container->findText(cont->getName().c_str());
195 _wComponent->cb_container->setCurrentIndex(index);
196 _wContainer->FillPanel(cont);
202 void EditionSalomeNode::changeInstance(int index)
204 string instName = _wComponent->cb_instance->itemText(index).toStdString();
205 Proc* proc = GuiContext::getCurrent()->getProc();
206 ComponentInstance *newCompoInst = 0;
207 ComponentInstance *oldCompoInst = _servNode->getComponent();
208 if (proc->componentInstanceMap.count(instName))
209 newCompoInst = proc->componentInstanceMap[instName];
210 else DEBTRACE("-------------> not found : " << instName);
212 if (newCompoInst && (newCompoInst != oldCompoInst))
214 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(newCompoInst));
215 SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
216 if(!ssn->associateToComponent(GuiContext::getCurrent()->_mapOfSubjectComponent[newCompoInst]))
221 void EditionSalomeNode::changeContainer(int index)
223 string contName = _wComponent->cb_container->itemText(index).toStdString();
225 ComponentInstance *compoInst = _servNode->getComponent();
226 Container *oldContainer = compoInst->getContainer();
228 Container *newContainer = 0;
229 Proc* proc = GuiContext::getCurrent()->getProc();
230 if (proc->containerMap.count(contName))
231 newContainer = proc->containerMap[contName];
234 DEBTRACE("-------------> not found : " << contName);
237 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(newContainer));
238 SubjectContainer *scnt = GuiContext::getCurrent()->_mapOfSubjectContainer[newContainer];
240 SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
241 SubjectComponent *sco =
242 dynamic_cast<SubjectComponent*>(ssn->getSubjectReference()->getReference());
244 sco->associateToContainer(scnt);
247 void EditionSalomeNode::changeHost(int index)
249 string hostName = _wContainer->cb_resource->itemText(index).toStdString();
253 void EditionSalomeNode::onApply()
255 DEBTRACE("EditionSalomeNode::onApply");
257 if (_wContainer->onApply())
259 _isEdited = _isEdited || edited;
260 EditionElementaryNode::onApply();
263 void EditionSalomeNode::onCancel()
265 DEBTRACE("EditionSalomeNode::onCancel");
266 ComponentInstance *compoInst = _servNode->getComponent();
269 _wContainer->FillPanel(compoInst->getContainer());
271 EditionElementaryNode::onApply();