Salome HOME
0022628: [CEA 1202] The default icon disposition is not correct in french and in...
[modules/yacs.git] / src / genericgui / GenericGui.cxx
index 7f16106662be0c8d272ea1aaab0fb7c062c31aa9..16d08646d96d66c6e6430e8d03481e9cdbd2f323 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2014  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
@@ -153,18 +153,18 @@ GenericGui::GenericGui(YACS::HMI::SuitWrapper* wrapper, QMainWindow *parent)
   _dwTree = new QDockWidget(_parent);
   _dwTree->setVisible(false);
   _dwTree->setWindowTitle("Tree View: edition mode");
-  _dwTree->setObjectName("Tree View");
+  _dwTree->setObjectName("yacsTreeViewDock");
   _parent->addDockWidget(Qt::LeftDockWidgetArea, _dwTree);
   _dwStacked = new QDockWidget(_parent);
   _dwStacked->setVisible(false);
   _dwStacked->setWindowTitle("Input Panel");
-  _dwStacked->setObjectName("Input Panel");
+  _dwStacked->setObjectName("yacsInputPanelDock");
   _dwStacked->setMinimumWidth(270); // --- force a minimum until display
   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwStacked);
   _dwCatalogs = new QDockWidget(_parent);
   _dwCatalogs->setVisible(false);
   _dwCatalogs->setWindowTitle("Catalogs");
-  _dwCatalogs->setObjectName("Catalogs");
+  _dwCatalogs->setObjectName("yacsCatalogsDock");
   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwCatalogs);
   _catalogsWidget = new CatalogWidget(_dwCatalogs,
                                       _builtinCatalog,
@@ -240,8 +240,8 @@ void GenericGui::createActions()
                                                 tr("Load Schema to run"), tr("Load a schema for run"),
                                                 0, _parent, false, this,  SLOT(onLoadAndRunSchema()));
 
-  _chooseBatchJobAct = _wrapper->createAction(getMenuId(), tr("Choose Batch Job for watch"), QIcon("icons:batch.png"),
-                                         tr("Choose Batch Job for watch"), tr("Choose Batch Job for watch"),
+  _chooseBatchJobAct = _wrapper->createAction(getMenuId(), tr("Choose Batch Job to watch"), QIcon("icons:batch.png"),
+                                         tr("Choose Batch Job to watch"), tr("Choose Batch Job to watch"),
                                          0, _parent, false, this,  SLOT(onChooseBatchJob()));
 
   _startResumeAct = _wrapper->createAction(getMenuId(), tr("Start or Resume Schema execution"), QIcon("icons:suspend_resume.png"),
@@ -460,6 +460,14 @@ void GenericGui::createActions()
                                             tr("shrink/expand"), tr("shrink or expand the selected node"),
                                             0, _parent, false, this,  SLOT(onShrinkExpand()));
 
+  _shrinkExpandChildren = _wrapper->createAction(getMenuId(), tr("shrink or expand direct children of the selected node"), QIcon("icons:shrinkExpand.png"),
+                                            tr("shrink/expand children"), tr("shrink or expand direct children of the selected node"),
+                                            0, _parent, false, this,  SLOT(onShrinkExpandChildren()));
+
+  _shrinkExpandElementaryRecursively = _wrapper->createAction(getMenuId(), tr("shrink or expand elementary nodes of the selected node recursively"), QIcon("icons:shrinkExpand.png"),
+                                            tr("shrink/expand elementary"), tr("shrink or expand elementary nodes of the selected node recursively"),
+                                            0, _parent, false, this,  SLOT(onShrinkExpandElementaryRecursively()));
+
   _toggleStraightLinksAct = _wrapper->createAction(getMenuId(), tr("draw straight or orthogonal links"), QIcon("icons:straightLink.png"),
                                                    tr("straight/orthogonal"), tr("draw straight or orthogonal links"),
                                                    0, _parent, true, this,  SLOT(onToggleStraightLinks(bool)));
@@ -670,7 +678,7 @@ void GenericGui::createMenus()
 
 void GenericGui::createTools()
 {
-  int aToolId = _wrapper->createTool ( tr( "YACS Toolbar" ) );
+  int aToolId = _wrapper->createTool ( tr( "YACS Toolbar" ), QString( "YACSToolbar" ) );
   _wrapper->createTool( _newSchemaAct, aToolId );
   _wrapper->createTool( _importSchemaAct, aToolId );
   _wrapper->createTool( _wrapper->separator(), aToolId );
@@ -720,6 +728,14 @@ void GenericGui::initialMenus()
   showBaseMenus(true);
 }
 
+void GenericGui::hideAllMenus()
+{
+  showBaseMenus   (false);
+  showCommonMenus (false);
+  showEditionMenus(false);
+  showExecMenus   (false);
+}
+
 void GenericGui::showBaseMenus(bool show)
 {
   DEBTRACE("GenericGui::showBaseMenus " << show);
@@ -801,12 +817,12 @@ void GenericGui::showCommonMenus(bool show)
   _wrapper->setToolShown(_hideAllLinksAct, show);
 }
 
-void GenericGui::switchContext(QWidget *view)
+void GenericGui::switchContext(QWidget *view, bool onExit)
 {
   DEBTRACE("GenericGui::switchContext " << view);
   if (! _mapViewContext.count(view))
     {
-      initialMenus();
+      onExit ? hideAllMenus() : initialMenus();
       _dwTree->setWidget(0);
       _dwStacked->setWidget(0);
       return;
@@ -959,7 +975,7 @@ bool GenericGui::closeContext(QWidget *view, bool onExit)
         }
       delete context;
       _mapViewContext.erase(view);
-      switchContext(newView);
+      switchContext(newView, onExit);
     }
   return true;
 }
@@ -1205,6 +1221,7 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
 {
   DEBTRACE("GenericGui::setLoadedPresentation");
   QtGuiContext::getQtCurrent()->setLoadingPresentation(true);
+  map<SceneNodeItem*, QPointF> nodesToMove;
   map<YACS::ENGINE::Node*, PrsData> presNodes = _loader->getPrsData(proc);
   if (!presNodes.empty())
     {
@@ -1222,11 +1239,38 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
           inode->setWidth(pres._width);
           inode->setHeight(pres._height);
           inode->setExpanded(pres._expanded);
-          inode->setExpandedPos(QPointF(pres._expx, pres._expy));
+          QPointF anExpandedPos = QPointF(pres._expx, pres._expy);
+          if (anExpandedPos.isNull())
+              anExpandedPos = inode->pos();
+          inode->setExpandedPos(anExpandedPos);
           inode->setExpandedWH(pres._expWidth, pres._expHeight);
           inode->setShownState(shownState(pres._shownState));
+
+          // collect nodes to correct it's Y-position if this collides with parent's header
+          if (inode->getParent() ) {
+              qreal anX = inode->x();
+              qreal anY = inode->y();
+              if (inode->getShownState() == shrinkHidden) {
+                anX = inode->getExpandedX();
+                anY = inode->getExpandedY();
+              }
+              if (anY < inode->getParent()->getHeaderBottom())
+                nodesToMove[inode] = QPointF(anX, inode->getParent()->getHeaderBottom()+1);
+            }
         }
     }
+  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
+  
+  //after loading of presentation:
+
+  //move nodes because of progress bar, if any was added
+  map<SceneNodeItem*, QPointF>::iterator it = nodesToMove.begin();
+  for (; it!= nodesToMove.end(); ++it)
+    {
+      (*it).first->setTopLeft((*it).second);
+    }
+
+  //update links
   if (Scene::_autoComputeLinks)
     _guiEditor->rebuildLinks();
   else
@@ -1236,8 +1280,6 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
       SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
       proc->updateLinks();
     }
-
-  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
 }
 
 // -----------------------------------------------------------------------------
@@ -1268,7 +1310,7 @@ void GenericGui::loadSchema(const std::string& filename,bool edit, bool arrangeL
     {
       DEBTRACE(logger->getStr());
     }
-  QString fn=QString::fromStdString(filename);
+  QString fn=QString::fromUtf8(filename.c_str());
   if(edit)
     createContext(proc, fn, "", true);
   else
@@ -1308,11 +1350,11 @@ void GenericGui::onImportSchema()
       if (!fi.exists() && fi.suffix() != "xml")
         fn += ".xml";
 
-      DEBTRACE("file loaded : " <<fn.toStdString());
+      DEBTRACE("file loaded : " <<fn.toUtf8().constData());
       YACS::ENGINE::Proc *proc = 0;
 
       try {
-         proc = _loader->load(fn.toLatin1());
+         proc = _loader->load(fn.toUtf8().constData());
       }
       catch (...) {
       }
@@ -1506,12 +1548,12 @@ void GenericGui::onExportSchema()
     }
   if (fn.isEmpty()) return;
 
-  DEBTRACE("GenericGui::onExportSchema: " << fn.toStdString());
+  DEBTRACE("GenericGui::onExportSchema: " << fn.toUtf8().constData());
   //to be sure that all pending changes are effective
   _parent->setFocus();
   QtGuiContext::getQtCurrent()->setFileName(fn);
   VisitorSaveGuiSchema aWriter(proc);
-  aWriter.openFileSchema( fn.toStdString() );
+  aWriter.openFileSchema( fn.toUtf8().constData() );
   aWriter.visitProc();
   aWriter.closeFileSchema();
   QtGuiContext::getQtCurrent()->setNotSaved(false);
@@ -1532,10 +1574,10 @@ void GenericGui::onExportSchemaAs()
   QString fn = getSaveFileName(fo);
   if (fn.isEmpty()) return;
 
-  DEBTRACE("GenericGui::onExportSchemaAs: " << fn.toStdString());
+  DEBTRACE("GenericGui::onExportSchemaAs: " << fn.toUtf8().constData());
   QtGuiContext::getQtCurrent()->setFileName(fn);
   VisitorSaveGuiSchema aWriter(proc);
-  aWriter.openFileSchema(fn.toStdString());
+  aWriter.openFileSchema(fn.toUtf8().constData());
   aWriter.visitProc();
   aWriter.closeFileSchema();
   _isSaved = true;
@@ -2148,6 +2190,16 @@ void GenericGui::onShrinkExpand() {
   _guiEditor->shrinkExpand();
 }
 
+void GenericGui::onShrinkExpandChildren() {
+  DEBTRACE("GenericGui::onShrinkExpandChildren");
+  _guiEditor->shrinkExpand(Qt::ControlModifier|Qt::ShiftModifier);
+}
+
+void GenericGui::onShrinkExpandElementaryRecursively() {
+  DEBTRACE("GenericGui::onShrinkExpandElementaryRecursively");
+  _guiEditor->shrinkExpand(Qt::ControlModifier);
+}
+
 void GenericGui::onToggleStraightLinks(bool checked)
 {
   Scene::_straightLinks = checked;