From 8a854805f45cbebbfb506c88527657d39e2ddbdf Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 12 Feb 2013 12:05:25 +0000 Subject: [PATCH] Merge from V6_main 11/02/2013 --- src/engine/PropertyInterface.cxx | 4 ++ src/engine/PropertyInterface.hxx | 2 + src/engine_swig/engtypemaps.i | 6 ++ src/genericgui/GenericGui.cxx | 16 ++++++ src/genericgui/GenericGui.hxx | 4 +- src/genericgui/GuiEditor.cxx | 77 +++++++++++++++++++++++--- src/genericgui/GuiEditor.hxx | 3 + src/genericgui/Menus.cxx | 24 +++++++- src/genericgui/Menus.hxx | 3 + src/hmi/commandsProc.cxx | 59 ++++++++++++++------ src/hmi/commandsProc.hxx | 5 +- src/hmi/guiObservers.cxx | 4 +- src/hmi/guiObservers.hxx | 2 +- src/runtime/RuntimeSALOME.cxx | 8 +++ src/salomegui/Yacsgui.cxx | 3 +- src/salomegui/resources/YACS_msg_fr.ts | 4 ++ src/salomewrap/SalomeWrap_Module.cxx | 3 +- 17 files changed, 194 insertions(+), 33 deletions(-) diff --git a/src/engine/PropertyInterface.cxx b/src/engine/PropertyInterface.cxx index 9b18de394..2103d15f2 100644 --- a/src/engine/PropertyInterface.cxx +++ b/src/engine/PropertyInterface.cxx @@ -30,6 +30,10 @@ using namespace YACS::ENGINE; * */ +PropertyInterface::~PropertyInterface() +{ +} + void PropertyInterface::setProperty(const std::string& name, const std::string& value) { DEBTRACE("PropertyInterface::setProperty " << name << " " << value); diff --git a/src/engine/PropertyInterface.hxx b/src/engine/PropertyInterface.hxx index 86d76e85f..8cc690bf4 100644 --- a/src/engine/PropertyInterface.hxx +++ b/src/engine/PropertyInterface.hxx @@ -32,6 +32,8 @@ namespace YACS class YACSLIBENGINE_EXPORT PropertyInterface { public: + virtual ~PropertyInterface(); + virtual void setProperty(const std::string& name,const std::string& value); virtual std::string getProperty(const std::string& name); std::map getProperties() { return _propertyMap; }; diff --git a/src/engine_swig/engtypemaps.i b/src/engine_swig/engtypemaps.i index 6bfebfcef..08f92a856 100644 --- a/src/engine_swig/engtypemaps.i +++ b/src/engine_swig/engtypemaps.i @@ -736,6 +736,12 @@ static PyObject* convertPort(YACS::ENGINE::Port* port,int owner=0) */ %feature("ref") YACS::ENGINE::RefCounter "" %feature("unref") YACS::ENGINE::RefCounter "$this->decrRef();" + +// Unfortunately, class ComponentInstance inherits from RefCounter AND PropertyInterface. Thus the ref and +// unref features are ambiguous and with swig 2.0.7 at least, we must re-specify those features for class +// ComponentInstance unless the instances are destroyed when the Swig object is unref'ed. +%feature("ref") YACS::ENGINE::ComponentInstance "" +%feature("unref") YACS::ENGINE::ComponentInstance "$this->decrRef();" /* * End of Reference counting section */ diff --git a/src/genericgui/GenericGui.cxx b/src/genericgui/GenericGui.cxx index 4975ee469..b59571c10 100644 --- a/src/genericgui/GenericGui.cxx +++ b/src/genericgui/GenericGui.cxx @@ -416,6 +416,10 @@ void GenericGui::createActions() tr("Put node in block"), tr("Put node in block"), 0, _parent, false, this, SLOT(onPutInBloc())); + _putGraphInOptimizerLoopAct = _wrapper->createAction(getMenuId(), tr("Optimizer Loop"), QIcon("icons:paste.png"), + tr("Optimizer Loop"), tr("Optimizer Loop"), + 0, _parent, false, this, SLOT(onPutGraphInOptimizerLoop())); + _arrangeLocalNodesAct = _wrapper->createAction(getMenuId(), tr("arrange nodes on that bloc level, without recursion"), QIcon("icons:arrange_nodes.png"), tr("arrange local nodes"), tr("arrange nodes on that bloc level, without recursion"), 0, _parent, false, this, SLOT(onArrangeLocalNodes())); @@ -2063,6 +2067,18 @@ void GenericGui::onPutInBloc() _guiEditor->PutSubjectInBloc(); } +void GenericGui::putGraphInForeachLoop(std::string type) +{ + DEBTRACE("GenericGui::PutGraphInForeachLoop"); + _guiEditor->PutGraphInForeachLoop(type); +} + +void GenericGui::onPutGraphInOptimizerLoop() +{ + DEBTRACE("GenericGui::onPutGraphInOptimizerLoop"); + _guiEditor->PutGraphInOptimizerLoop(); +} + void GenericGui::onArrangeLocalNodes() { DEBTRACE("GenericGui::onArrangeLocalNodes"); diff --git a/src/genericgui/GenericGui.hxx b/src/genericgui/GenericGui.hxx index 905825001..35010beba 100644 --- a/src/genericgui/GenericGui.hxx +++ b/src/genericgui/GenericGui.hxx @@ -76,6 +76,7 @@ namespace YACS CatalogWidget* getCatalogWidget() { return _catalogsWidget; }; std::list getMachineList(); void createForEachLoop(std::string type="double"); + void putGraphInForeachLoop(std::string type); virtual void loadSchema(const std::string& filename,bool edit=true, bool arrangeLocalNodes=false); virtual void onHelpContextModule( const QString&, const QString&, const QString& = QString() ); void createContext(YACS::ENGINE::Proc* proc, @@ -149,6 +150,7 @@ namespace YACS QAction *_copyItemAct; QAction *_pasteItemAct; QAction *_putInBlocAct; + QAction *_putGraphInOptimizerLoopAct; QAction *_arrangeLocalNodesAct; QAction *_arrangeRecurseNodesAct; QAction *_computeLinkAct; @@ -284,7 +286,7 @@ namespace YACS void onCopyItem(); void onPasteItem(); void onPutInBloc(); - + void onPutGraphInOptimizerLoop(); void onArrangeLocalNodes(); void onArrangeRecurseNodes(); void onRebuildLinks(); diff --git a/src/genericgui/GuiEditor.cxx b/src/genericgui/GuiEditor.cxx index 786280204..239c6f0dc 100644 --- a/src/genericgui/GuiEditor.cxx +++ b/src/genericgui/GuiEditor.cxx @@ -518,13 +518,13 @@ void GuiEditor::PutSubjectInBloc() std::stringstream tryname; long newid=0; while (newid < 100000) - { - tryname.str(""); - tryname << "Bloc" << newid; - if(names.find(tryname.str()) == names.end())break; - newid++; - } - + { + tryname.str(""); + tryname << "Bloc" << newid; + if(names.find(tryname.str()) == names.end())break; + newid++; + } + if (!snode->putInComposedNode(tryname.str(),"Bloc")) Message mess; @@ -533,6 +533,69 @@ void GuiEditor::PutSubjectInBloc() Message mess("Put in Bloc not possible for this kind of object"); } +void GuiEditor::PutGraphInForeachLoop(std::string typeNode) +{ + // put graph in Bloc node before + std::string blocname = PutGraphInBloc(); + + Proc* proc = GuiContext::getCurrent()->getProc(); + Node* bloc = proc->getChildByShortName(blocname); + SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc]; + //put the built bloc into target node + sbloc->putInComposedNode("ForEachLoop_"+typeNode,"ForEachLoop_"+typeNode); +} + +void GuiEditor::PutGraphInOptimizerLoop() +{ + // put graph in Bloc node before + std::string blocname = PutGraphInBloc(); + + Proc* proc = GuiContext::getCurrent()->getProc(); + Node* bloc = proc->getChildByShortName(blocname); + SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc]; + //put the built bloc into target node + sbloc->putInComposedNode("OptimizerLoop0","OptimizerLoop"); +} + +std::string GuiEditor::PutGraphInBloc() +{ + Proc* proc = GuiContext::getCurrent()->getProc(); + std::list children = proc->getChildren(); + + //get the set of children node names + std::set names; + for (std::list::iterator it = children.begin(); it != children.end(); ++it) + names.insert((*it)->getName()); + + //get the next numbered name + std::stringstream tryname; + long newid=0; + while (newid < 100000) + { + tryname.str(""); + tryname << "Bloc" << newid; + if(names.find(tryname.str()) == names.end())break; + newid++; + } + std::string blocname = tryname.str(); + + //put one by one the child nodes of Proc node into a new Bloc node + SubjectNode * snode; + for (std::list::iterator it = children.begin(); it != children.end(); ++it) + { + snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)]; + snode->saveLinks(); + snode->putInComposedNode(blocname,"Bloc", false); + } + for (std::list::iterator it = children.begin(); it != children.end(); ++it) + { + snode = 0; + snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)]; + snode->restoreLinks(); + } + return blocname; +} + void GuiEditor::rebuildLinks() { // --- only global link redraw for now... diff --git a/src/genericgui/GuiEditor.hxx b/src/genericgui/GuiEditor.hxx index 0c92b8ae6..9915582a2 100644 --- a/src/genericgui/GuiEditor.hxx +++ b/src/genericgui/GuiEditor.hxx @@ -79,6 +79,9 @@ namespace YACS void CopySubject(); void PasteSubject(); void PutSubjectInBloc(); + std::string PutGraphInBloc(); + void PutGraphInForeachLoop(std::string typeNode); + void PutGraphInOptimizerLoop(); void shrinkExpand(); void rebuildLinks(); void arrangeNodes(bool isRecursive); diff --git a/src/genericgui/Menus.cxx b/src/genericgui/Menus.cxx index 48509553a..94e663298 100644 --- a/src/genericgui/Menus.cxx +++ b/src/genericgui/Menus.cxx @@ -69,6 +69,13 @@ void MenusBase::foreachAction(QAction* act) gmain->createForEachLoop(act->text().toStdString()); } +void MenusBase::putGraphInForeachAction(QAction* act) +{ + DEBTRACE(act->text().toStdString()); + GenericGui *gmain = QtGuiContext::getQtCurrent()->getGMain(); + gmain->putGraphInForeachLoop(act->text().toStdString()); +} + void MenusBase::addHeader(QMenu &m, const QString &h) { m.addAction(_dummyAct); @@ -79,7 +86,7 @@ void MenusBase::addHeader(QMenu &m, const QString &h) m.addSeparator(); } -void MenusBase::addForEachMenu(QMenu *m, QActionGroup* actgroup) +void MenusBase::buildForEachMenu(QMenu *m, QActionGroup* actgroup) { QPixmap pixmap; pixmap.load("icons:new_foreach_loop_node.png"); @@ -94,9 +101,18 @@ void MenusBase::addForEachMenu(QMenu *m, QActionGroup* actgroup) act=actgroup->addAction((*it).first.c_str()); ForEachMenu->addAction(act); } +} +void MenusBase::addForEachMenu(QMenu *m, QActionGroup* actgroup) +{ + buildForEachMenu(m, actgroup); connect(actgroup, SIGNAL(triggered(QAction*)), this, SLOT(foreachAction(QAction*))); +} +void MenusBase::addForEachMenuToPutGraph(QMenu *m, QActionGroup* actgroup) +{ + buildForEachMenu(m, actgroup); + connect(actgroup, SIGNAL(triggered(QAction*)), this, SLOT(putGraphInForeachAction(QAction*))); } //======================================================================================= @@ -202,6 +218,7 @@ void ProcMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString QMenu menu(m, caller); addHeader(menu, m); QActionGroup actgroup(this); + QActionGroup actgroup2(this); if (isEdition) { menu.addAction(gmain->_runLoadedSchemaAct); @@ -231,6 +248,11 @@ void ProcMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString CNmenu->addAction(gmain->_OptimizerLoopAct); menu.addSeparator(); menu.addAction(gmain->_pasteItemAct); + + QMenu *PINmenu = menu.addMenu(tr("Put Graph Content in Node")); + addForEachMenuToPutGraph(PINmenu,&actgroup2); + PINmenu->addAction(gmain->_putGraphInOptimizerLoopAct); + menu.addSeparator(); } menu.addAction(gmain->_getYacsContainerLogAct); diff --git a/src/genericgui/Menus.hxx b/src/genericgui/Menus.hxx index d09aee966..0fbcaeb9f 100644 --- a/src/genericgui/Menus.hxx +++ b/src/genericgui/Menus.hxx @@ -39,10 +39,13 @@ namespace YACS const QPoint &globalPos, const QString& m = "MenuBase"); virtual void addForEachMenu(QMenu *m, QActionGroup* actgroup); + virtual void addForEachMenuToPutGraph(QMenu *m, QActionGroup* actgroup); protected slots: void dummyAction(); void foreachAction(QAction*); + void putGraphInForeachAction(QAction*); protected: + virtual void buildForEachMenu(QMenu *m, QActionGroup* actgroup); virtual void addHeader(QMenu &m, const QString &h); QAction *_dummyAct; }; diff --git a/src/hmi/commandsProc.cxx b/src/hmi/commandsProc.cxx index 68dfa00b6..7ee146b04 100644 --- a/src/hmi/commandsProc.cxx +++ b/src/hmi/commandsProc.cxx @@ -504,8 +504,10 @@ bool CommandReparentNode::localReverse() // ---------------------------------------------------------------------------- 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 =""; @@ -513,7 +515,8 @@ CommandPutInComposedNode::CommandPutInComposedNode(std::string position, std::string CommandPutInComposedNode::dump() { - string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type; + string save = _toSaveRestoreLinks ? "true" : "false"; + string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save; return ret; } @@ -532,8 +535,8 @@ bool CommandPutInComposedNode::localExecute() SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node]; Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather]; SubjectComposedNode* sop = dynamic_cast(subo); - //save existing links - snode->saveLinks(); + if (_toSaveRestoreLinks) + snode->saveLinks(); //save existing links //remove external links snode->removeExternalLinks(); snode->removeExternalControlLinks(); @@ -544,15 +547,39 @@ bool CommandPutInComposedNode::localExecute() //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 children = proc->getChildren(); + Node* composednode = 0; + SubjectNode *scomposednode = 0; + for (list::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->clone(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(composednode))->edAddChild(node); @@ -560,8 +587,8 @@ bool CommandPutInComposedNode::localExecute() //add the subject node to subject composednode (dynamic_cast(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); diff --git a/src/hmi/commandsProc.hxx b/src/hmi/commandsProc.hxx index 46e9689be..e2ea62309 100644 --- a/src/hmi/commandsProc.hxx +++ b/src/hmi/commandsProc.hxx @@ -152,7 +152,9 @@ namespace YACS { public: CommandPutInComposedNode(std::string position, - std::string newParent,std::string type); + std::string newParent, + std::string type, + bool toSaveRestoreLinks=true); protected: virtual bool localExecute(); virtual bool localReverse(); @@ -161,6 +163,7 @@ namespace YACS std::string _newParent; std::string _type; std::string _newpos; + bool _toSaveRestoreLinks; }; class CommandCopyNode: public Command diff --git a/src/hmi/guiObservers.cxx b/src/hmi/guiObservers.cxx index ebbd9d325..2e906e1ab 100644 --- a/src/hmi/guiObservers.cxx +++ b/src/hmi/guiObservers.cxx @@ -1099,13 +1099,13 @@ void SubjectNode::restoreLinks() } } -bool SubjectNode::putInComposedNode(std::string name,std::string type) +bool SubjectNode::putInComposedNode(std::string name,std::string type, bool toSaveRestoreLinks) { Proc *proc = GuiContext::getCurrent()->getProc(); string position = ""; if (proc != dynamic_cast(_node)) position = proc->getChildName(_node); - CommandPutInComposedNode *command = new CommandPutInComposedNode(position, name, type); + CommandPutInComposedNode *command = new CommandPutInComposedNode(position, name, type, toSaveRestoreLinks); if (command->execute()) { GuiContext::getCurrent()->getInvoc()->add(command); diff --git a/src/hmi/guiObservers.hxx b/src/hmi/guiObservers.hxx index 08f72e050..ff132ffde 100644 --- a/src/hmi/guiObservers.hxx +++ b/src/hmi/guiObservers.hxx @@ -309,7 +309,7 @@ namespace YACS virtual void removeExternalControlLinks(); virtual void saveLinks(); virtual void restoreLinks(); - virtual bool putInComposedNode(std::string name,std::string type); + virtual bool putInComposedNode(std::string name,std::string type, bool toSaveRestoreLinks=true); virtual int isValid(); void setExecState(int execState); static bool tryCreateLink(SubjectNode *subOutNode, SubjectNode *subInNode); diff --git a/src/runtime/RuntimeSALOME.cxx b/src/runtime/RuntimeSALOME.cxx index cacfd292e..2eb797e3c 100644 --- a/src/runtime/RuntimeSALOME.cxx +++ b/src/runtime/RuntimeSALOME.cxx @@ -1789,7 +1789,15 @@ std::string RuntimeSALOME::convertNeutralAsString(TypeCode * type, Any *data) { ob=convertNeutralPyObject(type,data); std::string s=convertPyObjectToString(ob); + + // Note (Renaud Barate, 8 jan 2013): With Python 2.7, this call to Py_DECREF causes a crash + // (SIGSEGV) when ob is a sequence and the call is not protected with the global interpreter + // lock. I thus added the call to PyGILState_Ensure / PyGILState_Release. It worked fine in + // Python 2.6 without this call. If anyone finds the real reason of this bug and another fix, + // feel free to change this code. + PyGILState_STATE gstate = PyGILState_Ensure(); Py_DECREF(ob); + PyGILState_Release(gstate); return s; } else diff --git a/src/salomegui/Yacsgui.cxx b/src/salomegui/Yacsgui.cxx index 3d460cb0f..65d6783b4 100644 --- a/src/salomegui/Yacsgui.cxx +++ b/src/salomegui/Yacsgui.cxx @@ -60,8 +60,7 @@ using namespace YACS::HMI; int Yacsgui::_oldStudyId = -1; Yacsgui::Yacsgui() : - SalomeWrap_Module( "YACS" ), // default name - LightApp_Module( "YACS" ) + SalomeWrap_Module( "YACS" ) // default name { DEBTRACE("Yacsgui::Yacsgui"); _wrapper = 0; diff --git a/src/salomegui/resources/YACS_msg_fr.ts b/src/salomegui/resources/YACS_msg_fr.ts index 4d7ff1b99..c25ad03d2 100644 --- a/src/salomegui/resources/YACS_msg_fr.ts +++ b/src/salomegui/resources/YACS_msg_fr.ts @@ -541,6 +541,10 @@ Put node in block Poser le noeud au bloc + + Put Graph Content in Node + Put Graph Content in Node + arrange nodes on that bloc level, without recursion ranger les noeuds au niveau de ce bloc, sans récursion diff --git a/src/salomewrap/SalomeWrap_Module.cxx b/src/salomewrap/SalomeWrap_Module.cxx index 0dab3e2ad..e69ccb9dd 100644 --- a/src/salomewrap/SalomeWrap_Module.cxx +++ b/src/salomewrap/SalomeWrap_Module.cxx @@ -39,8 +39,7 @@ using namespace std; SalomeWrap_Module::SalomeWrap_Module(const char* name) : - SalomeApp_Module( name ), - LightApp_Module( name ) + SalomeApp_Module( name ) { _mapOfViewWindow.clear(); } -- 2.39.2