Salome HOME
0022415: [CEA 1007] additional fix according to remarks '0017330' and '0017333':...
[modules/yacs.git] / src / genericgui / EditionScript.cxx
index 55860cb5bdad35f481d8f9c6ec63d1247542278d..0012a4635c0ceb2ce43fed6045fd900b895291ac 100644 (file)
@@ -30,6 +30,7 @@
 #include <qscilexerpython.h>
 #endif
 
+#include <QToolButton>
 #include <QSplitter>
 #include <QTemporaryFile>
 #include <QTextStream>
@@ -97,6 +98,36 @@ EditionScript::EditionScript(Subject* subject,
   _glayout->setMargin(1);
   splitter->addWidget(window);
 
+  //add an options section in ports layout for execution mode (local or remote)
+  QHBoxLayout* hboxLayout = new QHBoxLayout();
+  hboxLayout->setMargin(0);
+  QToolButton* tb_options = new QToolButton();
+  tb_options->setCheckable(true);
+  QIcon icon;
+  icon.addFile("icons:icon_down.png");
+  icon.addFile("icons:icon_up.png", QSize(), QIcon::Normal, QIcon::On);
+  tb_options->setIcon(icon);
+  hboxLayout->addWidget(tb_options);
+
+  QLabel* label = new QLabel("Execution Mode");
+  QFont font;
+  font.setBold(true);
+  font.setWeight(75);
+  label->setFont(font);
+  hboxLayout->addWidget(label);
+
+  _portslayout->addLayout(hboxLayout);
+
+  fr_options = new QFrame();
+  QHBoxLayout* hboxLayout1 = new QHBoxLayout(fr_options);
+  hboxLayout1->setMargin(0);
+  radiolocal= new QRadioButton("YACS");
+  radioremote= new QRadioButton("Container");
+  radiolocal->setChecked(true);
+  hboxLayout1->addWidget(radiolocal);
+  hboxLayout1->addWidget(radioremote);
+  hboxLayout->addWidget(fr_options);
+
   fr_container = new QFrame();
   QHBoxLayout* hboxLayout2 = new QHBoxLayout(fr_container);
   hboxLayout2->setMargin(0);
@@ -156,11 +187,13 @@ EditionScript::EditionScript(Subject* subject,
     }
   connect(_sci, SIGNAL(textChanged()), this, SLOT(onScriptModified()));
 
+  connect(tb_options, SIGNAL(toggled(bool)), this, SLOT(on_tb_options_toggled(bool)));
+  connect(radioremote, SIGNAL(toggled(bool)), this, SLOT(on_remote_toggled(bool)));
   connect(cb_container, SIGNAL(mousePressed()), this, SLOT(fillContainerPanel()));
   connect(cb_container, SIGNAL(activated(int)), this, SLOT(changeContainer(int)));
 
   update(UPDATE,0,0);
-  changeContainer(0);
+  on_tb_options_toggled(false);
 }
 
 EditionScript::~EditionScript()
@@ -287,6 +320,53 @@ void EditionScript::onEdit()
   onApply();
 }
 
+void EditionScript::on_tb_options_toggled(bool checked)
+{
+  DEBTRACE("EditionScript::on_tb_options_toggled " << checked);
+  _checked = checked;
+  if(_checked)
+    {
+      fr_options->show();
+      if(_remote) {
+       fr_container->show();
+       formcontainer->show();
+      }
+    }
+  else
+    {
+      fr_options->hide();
+      fr_container->hide();
+      formcontainer->hide();
+    }
+}
+
+void EditionScript::on_remote_toggled(bool checked)
+{
+  DEBTRACE("EditionScript::on_remote_toggled " << checked);
+  _remote=checked;
+  YACS::ENGINE::InlineNode *pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(_subInlineNode->getNode());
+  std::string mode = pyNode->getExecutionMode();
+  DEBTRACE(mode);
+
+  if(checked)
+    {
+      //remote radio button is checked
+      if(mode != "remote")
+        _subInlineNode->setExecutionMode("remote");
+      fr_container->show();
+      formcontainer->show();
+      fillContainerPanel();
+    }
+  else
+    {
+      //remote radio button is unchecked
+      if(mode != "local")
+        _subInlineNode->setExecutionMode("local");
+      fr_container->hide();
+      formcontainer->hide();
+    }
+}
+
 void EditionScript::fillContainerPanel()
 {
   DEBTRACE("EditionScript::fillContainerPanel ");
@@ -305,7 +385,10 @@ void EditionScript::fillContainerPanel()
       int index = cb_container->findText(cont->getName().c_str());
       cb_container->setCurrentIndex(index);
       formcontainer->FillPanel(cont);
-    }
+    } 
+  else if (cb_container->count()) {
+    changeContainer(0);
+  }
 }
 
 void EditionScript::changeContainer(int index)
@@ -347,6 +430,19 @@ void EditionScript::update(GuiEvent event, int type, Subject* son)
     }
   else if(event == UPDATE)
     {
+      YACS::ENGINE::InlineNode *pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(_subInlineNode->getNode());
+      std::string mode = pyNode->getExecutionMode();
+      if(mode == "remote")
+        {
+          _remote=true;
+          radioremote->setChecked(true);
+        }
+      else if(mode == "local")
+        {
+          _remote=false;
+          radiolocal->setChecked(true);
+        }
+
       fillContainerPanel();
     }
 }