-// Copyright (C) 2006-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2022 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "PresetPorts.hxx"
#include "ComponentDefinition.hxx"
#include "SalomeContainer.hxx"
+#include "SalomeHPContainer.hxx"
#include "SalomeComponent.hxx"
#include "TypeCode.hxx"
#include "RuntimeSALOME.hxx"
else if (dynamic_cast<YACS::ENGINE::ForLoop*>(node)) nodeType = FORLOOP;
else if (dynamic_cast<YACS::ENGINE::WhileLoop*>(node)) nodeType = WHILELOOP;
else if (dynamic_cast<YACS::ENGINE::Switch*>(node)) nodeType = SWITCH;
- else if (dynamic_cast<YACS::ENGINE::ForEachLoop*>(node)) nodeType = FOREACHLOOP;
+ else if (dynamic_cast<YACS::ENGINE::ForEachLoopGen*>(node)) nodeType = FOREACHLOOP;
else if (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(node)) nodeType = OPTIMIZERLOOP;
else if (dynamic_cast<YACS::ENGINE::PresetNode*>(node)) nodeType = PRESETNODE;
else if (dynamic_cast<YACS::ENGINE::OutNode*>(node)) nodeType = OUTNODE;
(dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
break;
case FOREACHLOOP:
- (dynamic_cast<YACS::ENGINE::ForEachLoop*>(father))->edSetNode(son);
+ (dynamic_cast<YACS::ENGINE::ForEachLoopGen*>(father))->edSetNode(son);
break;
case OPTIMIZERLOOP:
(dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
// ----------------------------------------------------------------------------
CommandPutInComposedNode::CommandPutInComposedNode(std::string position,
- std::string newParent,std::string type)
- : Command(), _position(position), _newParent(newParent), _type(type)
+ std::string newParent,
+ std::string type,
+ bool toSaveRestoreLinks)
+ : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
{
DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
_newpos ="";
std::string CommandPutInComposedNode::dump()
{
- string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type;
+ string save = _toSaveRestoreLinks ? "true" : "false";
+ string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save;
return ret;
}
SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
- //save existing links
- snode->saveLinks();
+ if (_toSaveRestoreLinks)
+ snode->saveLinks(); //save existing links
//remove external links
snode->removeExternalLinks();
snode->removeExternalControlLinks();
//refresh node views
sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
- //create a ComposedNode (type _type) with name _newParent
- YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
- Node* nodeToClone = catalog->_composednodeMap[_type];
- Node* composednode = nodeToClone->clone(0);
- composednode->setName(_newParent);
- //add the new composednode as child of oldfather
- oldFather->edAddChild(composednode);
- //create the subject composednode
- SubjectNode *scomposednode = sop->addSubjectNode(composednode,"",catalog,"",_type);
+ // try to find a node with the given name:
+ // success: use it as target composed node
+ // fail: create such a node and use it
+ std::list<Node*> children = proc->getChildren();
+ Node* composednode = 0;
+ SubjectNode *scomposednode = 0;
+ for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+ {
+ if ( _newParent == (*it)->getName() )
+ {
+ //get an existing ComposedNode with name _newParent
+ composednode = (*it);
+ break;
+ }
+ }
+ // target node was found
+ if ( composednode )
+ {
+ scomposednode = GuiContext::getCurrent()->_mapOfSubjectNode[composednode];
+ }
+ // creation of target node
+ else
+ {
+ //create a ComposedNode (type _type) with name _newParent
+ YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
+ Node* nodeToClone = catalog->_composednodeMap[_type];
+ composednode = nodeToClone->cloneWithoutCompAndContDeepCpy(0);
+ composednode->setName(_newParent);
+ //add the new composednode as child of oldfather
+ oldFather->edAddChild(composednode);
+ //create the subject composednode
+ scomposednode = sop->addSubjectNode(composednode,"",catalog,"",_type);
+ }
//add the old node as child of new composednode
(dynamic_cast<YACS::ENGINE::ComposedNode*>(composednode))->edAddChild(node);
//add the subject node to subject composednode
(dynamic_cast<SubjectComposedNode*>(scomposednode))->houseKeepingAfterCutPaste(false, snode);
snode->setParent(scomposednode);
- //restore links
- snode->restoreLinks();
+ if (_toSaveRestoreLinks)
+ snode->restoreLinks(); //restore links
//refresh all views
scomposednode->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
snode->recursiveUpdate(RENAME, 0, snode);
if (Loop *loop = dynamic_cast<Loop*>(newFather))
if (!loop->edGetDirectDescendants().empty())
throw YACS::Exception("Already a node in a new parent of Loop type");
- //_clone = node->clone(newFather);
- _clone = node->clone(0);
+ //_clone = node->cloneWithoutCompAndContDeepCpy(newFather);
+ _clone = node->cloneWithoutCompAndContDeepCpy(0);
if (!_clone)
throw YACS::Exception("Node cannot be cloned");
int nodeSuffix = -1;
container->setName(_newName);
proc->containerMap[_newName] = container;
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
- SubjectContainer *scont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
+ SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[container]);
scont-> update(RENAME, 0, scont);
scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
}
container->setName(_oldName);
proc->containerMap[_oldName] = container;
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
- SubjectContainer *scont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
+ SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[container]);
scont-> update(RENAME, 0, scont);
scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
}
setErrorMsg(ex);
return false;
}
+ return true;
}
bool CommandSetSwitchSelect::localReverse()
setErrorMsg(ex);
return false;
}
+ return true;
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-CommandAddContainer::CommandAddContainer(std::string name,
- std::string refContainer)
+CommandAddContainerBase::CommandAddContainerBase(std::string name, std::string refContainer)
: Command(), _name(name), _containerToClone(refContainer), _subcont(0)
{
- DEBTRACE("CommandAddContainer::CommandAddContainer " << name << " " << refContainer);
+ DEBTRACE("CommandAddContainerBase::CommandAddContainerBase " << name << " " << refContainer);
}
-std::string CommandAddContainer::dump()
+CommandAddContainerBase::~CommandAddContainerBase()
{
- string ret ="CommandAddContainer " + _name + " " + _containerToClone;
- return ret;
}
-bool CommandAddContainer::localExecute()
+bool CommandAddContainerBase::localExecute()
{
- DEBTRACE("CommandAddContainer::localExecute");
+ DEBTRACE("CommandAddContainerBase::localExecute");
try
{
Proc* proc = GuiContext::getCurrent()->getProc();
GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
return false;
}
- Container *container = new SalomeContainer();
+ Container *container(createNewInstance());
if (! _containerToClone.empty())
{
if (proc->containerMap.count(_containerToClone))
}
catch (Exception& ex)
{
- DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
+ DEBTRACE("CommandAddContainerBase::localExecute() : " << ex.what());
setErrorMsg(ex);
return false;
}
}
-bool CommandAddContainer::localReverse()
+bool CommandAddContainerBase::localReverse()
{
- DEBTRACE("CommandAddContainer::localReverse");
+ DEBTRACE("CommandAddContainerBase::localReverse");
try
{
Proc* proc = GuiContext::getCurrent()->getProc();
// ----------------------------------------------------------------------------
+CommandAddContainer::CommandAddContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
+{
+}
+
+std::string CommandAddContainer::dump()
+{
+ string ret ="CommandAddContainer " + _name + " " + _containerToClone;
+ return ret;
+}
+
+Container *CommandAddContainer::createNewInstance() const
+{
+ return new SalomeContainer;
+}
+
+// ----------------------------------------------------------------------------
+
+CommandAddHPContainer::CommandAddHPContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
+{
+}
+
+std::string CommandAddHPContainer::dump()
+{
+ string ret ="CommandAddHPContainer " + _name + " " + _containerToClone;
+ return ret;
+}
+
+Container *CommandAddHPContainer::createNewInstance() const
+{
+ return new SalomeHPContainer;
+}
+
+// ----------------------------------------------------------------------------
+
CommandSetNodeProperties::CommandSetNodeProperties(std::string position, std::map<std::string,std::string> properties)
: Command(), _position(position), _properties(properties)
{
Proc* proc = GuiContext::getCurrent()->getProc();
if (proc->containerMap.count(_container))
{
- Container *ref = proc->containerMap[_container];
+ Container *ref(proc->containerMap[_container]);
YASSERT(ref);
_oldProp = ref->getProperties();
ref->setProperties(_properties);
+ SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[ref]);
+ scont->update(UPDATE, 0, scont);
+ scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
return true;
}
GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
YASSERT(!_subcompo->hasServices());
Container *cont = compo->getContainer();
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
subcont->detachComponent(_subcompo);
GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
proc->removeComponentInstance(compo);
_oldcont = pyNode->getContainer()->getName();
pyNode->setContainer(cont);
SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
snode->update(ASSOCIATE, 0, subcont);
return true;
}
{
pyNode->setContainer(cont);
SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
snode->update(ASSOCIATE, 0, subcont);
return true;
}
YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
scomp->addSubjectReference(subcont);
if (scomp->_subRefContainer)
subcont->moveComponent(scomp->_subRefContainer);
YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
scomp->addSubjectReference(subcont);
if (scomp->_subRefContainer)
subcont->moveComponent(scomp->_subRefContainer);
{
//component instance does not exist anymore recreate it
ComponentInstance *oldcompo = service->getComponent();
- compo = oldcompo->clone();
+ compo = oldcompo->cloneAlways();
compo->setName(_oldInstance);
proc->addComponentInstance(compo, _oldInstance);
Container *cont = proc->containerMap[_oldcont];
throw YACS::Exception("Component instance with services attached, not removed");
Container *cont = compo->getContainer();
YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
- SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
+ SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
subcont->detachComponent(subCompo);
//remove componentInstance from proc, from context
if (_createdInstance)