Version: 8.3.0
YACS::HMI::CommandSetInPortValue Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandSetInPortValue:
Collaboration diagram for YACS::HMI::CommandSetInPortValue:

Public Member Functions

 CommandSetInPortValue (std::string node, std::string port, std::string value)
 
- Public Member Functions inherited from YACS::HMI::Command
 Command ()
 
virtual bool execute ()
 the command is executed a first time after its registration for undo redo, then on redo More...
 
virtual bool reverse (bool isNormal=true)
 Reverse action: undo. More...
 
virtual bool executeSubOnly ()
 execute only sub commands in a reverse action More...
 
std::string recursiveDump (int level=0)
 
void addSubCommand (Command *command)
 
bool isNormalReverse ()
 

Protected Member Functions

virtual bool localExecute ()
 
virtual bool localReverse ()
 
virtual std::string dump ()
 

Protected Attributes

std::string _node
 
std::string _port
 
std::string _value
 
std::string _oldValue
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 379 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandSetInPortValue::CommandSetInPortValue ( std::string  node,
std::string  port,
std::string  value 
)

Definition at line 2078 of file commandsProc.cxx.

References _oldValue, and DEBTRACE.

2081  : Command(), _node(node), _port(port), _value(value)
2082 {
2083  DEBTRACE("CommandSetInPortValue::CommandSetInPortValue " << node << " " << port << " " << value);
2084  _oldValue = "";
2085 }

Member Function Documentation

std::string CommandSetInPortValue::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2087 of file commandsProc.cxx.

References _node, _port, _value, and PMMLBasicsTestLauncher::ret.

2088 {
2089  string ret ="CommandSetInPortValue " + _node + " " + _port + " " + _value;
2090  return ret;
2091 }
bool CommandSetInPortValue::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2093 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InputPort::edInit(), YACS::ENGINE::InputStudyPort::getAsString(), YACS::ENGINE::DataPort::getAsString(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getInputPort(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::getSALOMERuntime(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::DataNode::setData(), setErrorMsg(), YACS::HMI::SETVALUE, YACS::ENGINE::String, YACS::HMI::Subject::update(), YACS::Exception::what(), and YASSERT.

2094 {
2095  DEBTRACE("CommandSetInPortValue::localExecute");
2096  InputPort* inp ;
2097  InputPresetPort *inpp = 0;
2098  InputStudyPort *insp = 0;
2099  DataNode *dnode = 0;
2100  SubjectDataPort *sinp = 0;
2101  try
2102  {
2103  Proc* proc = GuiContext::getCurrent()->getProc();
2104  Node* node = proc->getChildByName(_node);
2105  inp = node->getInputPort(_port);
2106  inpp = dynamic_cast<InputPresetPort*>(inp);
2107  insp = dynamic_cast<InputStudyPort*>(inp);
2108  dnode = dynamic_cast<DataNode*>(node);
2109  YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2111  }
2112  catch (Exception& ex)
2113  {
2114  DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2115  setErrorMsg(ex);
2116  return false;
2117  }
2118 
2119  if(insp && dnode)
2120  {
2121  //It's a study port
2122  _oldValue = insp->getAsString();
2123  DEBTRACE("old value="<< _oldValue);
2124  dnode->setData(insp, _value );
2125  sinp->update(SETVALUE, 0, sinp);
2126  return true;
2127  }
2128 
2129  PyObject *result;
2130  PyGILState_STATE gstate = PyGILState_Ensure();
2131  try
2132  {
2133  _oldValue = inp->getAsString();
2134  if (_oldValue == "None") _oldValue = "";
2135  DEBTRACE("old value="<< _oldValue);
2136  std::string strval;
2137  if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2138  strval = "\"" + _value + "\"";
2139  else
2140  strval = _value;
2141  result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2142  inp->edInit("Python", result);
2143  Py_DECREF(result);
2144 
2145  PyGILState_Release(gstate);
2146  sinp->update(SETVALUE, 0, sinp);
2147  return true;
2148  }
2149  catch (Exception& ex)
2150  {
2151  DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2152  //Py_DECREF(result);
2153  PyGILState_Release(gstate);
2154  setErrorMsg(ex);
2155  return false;
2156  }
2157 }
bool CommandSetInPortValue::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2159 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InputPort::edInit(), YACS::ENGINE::InputStudyPort::getAsString(), YACS::ENGINE::DataPort::getAsString(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getInputPort(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::getSALOMERuntime(), YACS::ENGINE::TypeCode::isA(), YACS::ENGINE::TypeCode::kind(), YACS::ENGINE::DataNode::setData(), setErrorMsg(), YACS::HMI::SETVALUE, YACS::ENGINE::String, YACS::HMI::Subject::update(), YACS::Exception::what(), and YASSERT.

2160 {
2161  DEBTRACE("CommandSetInPortValue::localReverse");
2162  InputPort* inp ;
2163  InputPresetPort *inpp = 0;
2164  InputStudyPort *insp = 0;
2165  DataNode *dnode = 0;
2166  SubjectDataPort *sinp = 0;
2167  try
2168  {
2169  Proc* proc = GuiContext::getCurrent()->getProc();
2170  Node* node = proc->getChildByName(_node);
2171  inp = node->getInputPort(_port);
2172  inpp = dynamic_cast<InputPresetPort*>(inp);
2173  insp = dynamic_cast<InputStudyPort*>(inp);
2174  dnode = dynamic_cast<DataNode*>(node);
2175  YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2177  }
2178  catch (Exception& ex)
2179  {
2180  DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2181  setErrorMsg(ex);
2182  return false;
2183  }
2184 
2185  if(insp && dnode)
2186  {
2187  //It's a study port
2188  _value = insp->getAsString();
2189  DEBTRACE("value="<< _value);
2190  DEBTRACE("old value="<< _oldValue);
2191  dnode->setData(insp, _oldValue );
2192  sinp->update(SETVALUE, 0, sinp);
2193  return true;
2194  }
2195 
2196  PyObject *result = Py_None;
2197  PyGILState_STATE gstate = PyGILState_Ensure();
2198  try
2199  {
2200  _value = inp->getAsString();
2201  DEBTRACE("value="<< _value);
2202  DEBTRACE("old value="<< _oldValue);
2203  if (!_oldValue.empty())
2204  {
2205  std::string strval;
2206  if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2207  strval = "\"" + _oldValue + "\"";
2208  else
2209  strval = _oldValue;
2210  result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2211  }
2212  inp->edInit("Python", result);
2213  Py_DECREF(result);
2214  PyGILState_Release(gstate);
2215  sinp->update(SETVALUE, 0, sinp);
2216  return true;
2217  }
2218  catch (Exception& ex)
2219  {
2220  DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2221  //Py_DECREF(result);
2222  PyGILState_Release(gstate);
2223  setErrorMsg(ex);
2224  return false;
2225  }
2226 }

Member Data Documentation

std::string YACS::HMI::CommandSetInPortValue::_node
protected

Definition at line 389 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

std::string YACS::HMI::CommandSetInPortValue::_oldValue
protected

Definition at line 392 of file commandsProc.hxx.

Referenced by CommandSetInPortValue(), localExecute(), and localReverse().

std::string YACS::HMI::CommandSetInPortValue::_port
protected

Definition at line 390 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

std::string YACS::HMI::CommandSetInPortValue::_value
protected

Definition at line 391 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().


The documentation for this class was generated from the following files: