Salome HOME
Merge from V6_main 11/02/2013
authorvsr <vsr@opencascade.com>
Tue, 12 Feb 2013 12:05:25 +0000 (12:05 +0000)
committervsr <vsr@opencascade.com>
Tue, 12 Feb 2013 12:05:25 +0000 (12:05 +0000)
17 files changed:
src/engine/PropertyInterface.cxx
src/engine/PropertyInterface.hxx
src/engine_swig/engtypemaps.i
src/genericgui/GenericGui.cxx
src/genericgui/GenericGui.hxx
src/genericgui/GuiEditor.cxx
src/genericgui/GuiEditor.hxx
src/genericgui/Menus.cxx
src/genericgui/Menus.hxx
src/hmi/commandsProc.cxx
src/hmi/commandsProc.hxx
src/hmi/guiObservers.cxx
src/hmi/guiObservers.hxx
src/runtime/RuntimeSALOME.cxx
src/salomegui/Yacsgui.cxx
src/salomegui/resources/YACS_msg_fr.ts
src/salomewrap/SalomeWrap_Module.cxx

index 9b18de3949796807cc35615aa5dafa4a050a5355..2103d15f225125b2ca75d7b55efbe09324034d04 100644 (file)
@@ -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);
index 86d76e85f539b1d8a9ee3f43c2fc1734b713a7f9..8cc690bf4b711795f2fd0362b3a9dbd840d265fb 100644 (file)
@@ -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<std::string,std::string> getProperties() { return _propertyMap; };
index 6bfebfcef44eae4b230f3000da3e8c28748c3d47..08f92a8564d13b8d784396359b11d61a8c6ae555 100644 (file)
@@ -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
  */
index 4975ee469933aecb6794cec2f06c68492caccdcc..b59571c1052cc8e17a81b606e277f826fa248e19 100644 (file)
@@ -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");
index 9058250019a25600bc7878dc2d23f7dd2a68628f..35010bebaa8bc12be4f02568dffc24d743e0abfa 100644 (file)
@@ -76,6 +76,7 @@ namespace YACS
       CatalogWidget* getCatalogWidget() { return _catalogsWidget; };
       std::list<std::string> 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();
index 786280204621a5699e9196f4f861145eeb54cd8f..239c6f0dc0feb474e3002a121fe1aca6f18f1e5e 100644 (file)
@@ -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<Node *> children = proc->getChildren();
+
+  //get the set of children node names
+  std::set<std::string> names;
+  for (std::list<Node*>::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<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+    {
+      snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
+      snode->saveLinks();
+      snode->putInComposedNode(blocname,"Bloc", false);
+    }
+  for (std::list<Node*>::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...
index 0c92b8ae6aeba3683339c42fec821a18ffe50f5c..9915582a2511488f7906a0e077d2655392bb608c 100644 (file)
@@ -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);
index 48509553a787257ef06d6975d4bf25bd2f267550..94e6632987ef6d0f553e99666ce0daa8928eaa3b 100644 (file)
@@ -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);
index d09aee96631ebaca8ad855d9f65e1e6b08f9938f..0fbcaeb9fa98bf3e7606abb5131b03e81d1fe1eb 100644 (file)
@@ -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;
     };
index 68dfa00b67afee0692012d45f299ff5bfe6ff22b..7ee146b04896484b247f654562949abecb01558c 100644 (file)
@@ -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<SubjectComposedNode*>(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<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->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<YACS::ENGINE::ComposedNode*>(composednode))->edAddChild(node);
@@ -560,8 +587,8 @@ bool CommandPutInComposedNode::localExecute()
       //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);
index 46e9689be7a6c970f70e871a1120a1c92cc48673..e2ea623098b212d50176b93cef41f91fdc224fb9 100644 (file)
@@ -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
index ebbd9d325b3749df82bfb6d097840cc5186accf9..2e906e1ab1bc05b0a5d90bc1b503e3d8460727a6 100644 (file)
@@ -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<Proc*>(_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);
index 08f72e050c4c5a791e52963b3850c294f3b9a47b..ff132ffde78b65aa0c94875859708e532ec33278 100644 (file)
@@ -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);
index cacfd292e89f21e3d6a0e9192bf299a673f674f2..2eb797e3cb31512ce16b65901f5fcd2f444123ac 100644 (file)
@@ -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
index 3d460cb0f1d3e93e742bdf049af470e5434134c4..65d6783b4c4c3461d5f5093b0f9206b0104eeb27 100644 (file)
@@ -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;
index 4d7ff1b99e35a60c14b9623282ee78f99b8fcadf..c25ad03d2eeff16306b0c1becdd492a74a387871 100644 (file)
         <source>Put node in block</source>
         <translation>Poser le noeud au bloc</translation>
     </message>
+    <message>
+        <source>Put Graph Content in Node</source>
+        <translation type="unfinished">Put Graph Content in Node</translation>
+    </message>
     <message>
         <source>arrange nodes on that bloc level, without recursion</source>
         <translation>ranger les noeuds au niveau de ce bloc, sans rĂ©cursion </translation>
index 0dab3e2ad31bf43dd1aaa65d055168421c4af288..e69ccb9ddbe705f3b82b9db44ba6bb643e29e3ab 100644 (file)
@@ -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();
 }