1 // Copyright (C) 2006-2024 CEA, EDF
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)
48 // SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
50 _servNode = dynamic_cast<YACS::ENGINE::ServiceNode*>(_subElemNode->getNode());
52 // --- create property editor panel
53 _propeditor=new PropertyEditor(_subject);
54 _wid->gridLayout1->addWidget(_propeditor);
56 // --- create container and component panels
58 _wContainer = new FormContainerDecorator(_servNode->getContainer(),this);
59 _wid->gridLayout1->addWidget(_wContainer);
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
66 _wComponent = new FormComponent(this);
67 _wid->gridLayout1->addWidget(_wComponent);
69 connect(_wComponent->cb_instance, SIGNAL(mousePressed()),
70 this, SLOT(fillComponentPanel()));
71 connect(_wComponent->cb_instance, SIGNAL(activated(int)),
72 this, SLOT(changeInstance(int)));
74 connect(_wComponent->cb_container, SIGNAL(mousePressed()),
75 this, SLOT(fillContainerPanel()));
76 connect(_wComponent->cb_container, SIGNAL(activated(int)),
77 this, SLOT(changeContainer(int)));
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
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:");
94 _le_method->setText((_servNode->getMethod()).c_str());
95 _le_method->setReadOnly(true);
97 // --- fill component panel
101 createTablePorts(_wid->gridLayout1);
104 EditionSalomeNode::~EditionSalomeNode()
108 void EditionSalomeNode::update(GuiEvent event, int type, Subject* son)
110 DEBTRACE("EditionSalomeNode::update ");
111 EditionElementaryNode::update(event, type, son);
112 SubjectReference* subref= 0;
117 subref = dynamic_cast<SubjectReference*>(son);
119 DEBTRACE(subref->getName() << " " << subref->getReference()->getName());
120 fillComponentPanel();
121 fillContainerPanel();
125 DEBTRACE("ASSOCIATE");
126 fillContainerPanel();
130 _propeditor->update();
138 void EditionSalomeNode::synchronize()
140 EditionElementaryNode::synchronize();
141 _wContainer->synchronizeCheckContainer();
142 _wComponent->tb_component->setChecked(FormComponent::_checked);
143 fillComponentPanel();
144 fillContainerPanel();
147 /*! must be updated when associate service to component instance, or when the list of
148 * available component instances changes.
150 void EditionSalomeNode::fillComponentPanel()
152 ComponentInstance *compoInst = _servNode->getComponent();
155 _wComponent->le_name ->setText(compoInst->getCompoName().c_str());
156 Proc* proc = GuiContext::getCurrent()->getProc();
158 _wComponent->cb_instance->clear();
159 map<string,ComponentInstance*>::const_iterator it = proc->componentInstanceMap.begin();
160 for(; it != proc->componentInstanceMap.end(); ++it)
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()));
169 int index = _wComponent->cb_instance->findText(compoInst->getInstanceName().c_str());
170 //DEBTRACE("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " << index);
171 _wComponent->cb_instance->setCurrentIndex(index);
175 void EditionSalomeNode::fillContainerPanel()
177 DEBTRACE("EditionSalomeNode::fillContainerPanel");
178 ComponentInstance *compoInst = _servNode->getComponent();
181 Proc* proc = GuiContext::getCurrent()->getProc();
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()));
188 Container * cont = compoInst->getContainer();
191 int index = _wComponent->cb_container->findText(cont->getName().c_str());
192 _wComponent->cb_container->setCurrentIndex(index);
193 _wContainer->FillPanel(cont);
199 void EditionSalomeNode::changeInstance(int index)
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);
209 if (newCompoInst && (newCompoInst != oldCompoInst))
211 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(newCompoInst));
212 SubjectServiceNode *ssn = dynamic_cast<SubjectServiceNode*>(_subject);
213 if(!ssn->associateToComponent(GuiContext::getCurrent()->_mapOfSubjectComponent[newCompoInst]))
218 void EditionSalomeNode::changeContainer(int index)
220 string contName = _wComponent->cb_container->itemText(index).toStdString();
222 ComponentInstance *compoInst = _servNode->getComponent();
223 Container *oldContainer = compoInst->getContainer();
225 Container *newContainer = 0;
226 Proc* proc = GuiContext::getCurrent()->getProc();
227 if (proc->containerMap.count(contName))
228 newContainer = proc->containerMap[contName];
231 DEBTRACE("-------------> not found : " << contName);
234 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(newContainer));
235 SubjectContainerBase *scnt(GuiContext::getCurrent()->_mapOfSubjectContainer[newContainer]);
237 SubjectServiceNode *ssn(dynamic_cast<SubjectServiceNode*>(_subject));
238 SubjectComponent *sco(dynamic_cast<SubjectComponent*>(ssn->getSubjectReference()->getReference()));
240 sco->associateToContainer(scnt);
243 void EditionSalomeNode::changeHost(int index)
245 string hostName = _wContainer->getHostName(index);
249 void EditionSalomeNode::onApply()
251 DEBTRACE("EditionSalomeNode::onApply");
253 if (_wContainer->onApply())
255 _isEdited = _isEdited || edited;
256 EditionElementaryNode::onApply();
259 void EditionSalomeNode::onCancel()
261 DEBTRACE("EditionSalomeNode::onCancel");
262 ComponentInstance *compoInst = _servNode->getComponent();
265 _wContainer->FillPanel(compoInst->getContainer());
267 EditionElementaryNode::onApply();