Version: 9.16.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...
 
virtual std::string dump ()
 
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 ()
 
virtual bool localExecute ()=0
 
virtual bool localReverse ()=0
 

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::CommandSetInPortValue ( std::string  node,
std::string  port,
std::string  value 
)

Definition at line 2078 of file commandsProc.cxx.

2081 : Command(), _node(node), _port(port), _value(value)
2082{
2083 DEBTRACE("CommandSetInPortValue::CommandSetInPortValue " << node << " " << port << " " << value);
2084 _oldValue = "";
2085}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _oldValue, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandSetInPortValue::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2087 of file commandsProc.cxx.

2088{
2089 string ret ="CommandSetInPortValue " + _node + " " + _port + " " + _value;
2090 return ret;
2091}

References _node, _port, and _value.

◆ localExecute()

bool CommandSetInPortValue::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2093 of file commandsProc.cxx.

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}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
Node * getChildByName(const std::string &name) const
Class for data parameters specification.
Definition: DataNode.hxx:38
virtual void setData(InputPort *port, const std::string &data)
Definition: DataNode.cxx:29
TypeCode * edGetType() const
Definition: DataPort.hxx:53
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: DataPort.cxx:84
Base class for Input Ports.
Definition: InputPort.hxx:44
void edInit(T value)
Definition: InputPort.hxx:129
Class for PRESET input Ports.
Definition: PresetPorts.hxx:50
Class for Study input Ports.
Definition: StudyPorts.hxx:51
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: StudyPorts.cxx:341
Base class for all nodes.
Definition: Node.hxx:70
virtual InputPort * getInputPort(const std::string &name) const
Definition: Node.cxx:260
Base class for all schema objects.
Definition: Proc.hxx:44
virtual PyObject * convertStringToPyObject(const std::string &s)
virtual int isA(const char *repositoryId) const
Definition: TypeCode.cxx:99
DynType kind() const
Definition: TypeCode.cxx:47
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
std::map< YACS::ENGINE::DataPort *, YACS::HMI::SubjectDataPort * > _mapOfSubjectDataPort
Definition: guiContext.hxx:71
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
virtual void update(GuiEvent event, int type, Subject *son)
void setErrorMsg(YACS::Exception &ex)
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()

References YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InputPort::edInit(), testCppPluginInvokation::ex, YACS::ENGINE::DataPort::getAsString(), YACS::ENGINE::InputStudyPort::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(), and YASSERT.

◆ localReverse()

bool CommandSetInPortValue::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2159 of file commandsProc.cxx.

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}

References YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::InputPort::edInit(), testCppPluginInvokation::ex, YACS::ENGINE::DataPort::getAsString(), YACS::ENGINE::InputStudyPort::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(), and YASSERT.

Member Data Documentation

◆ _node

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

Definition at line 389 of file commandsProc.hxx.

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

◆ _oldValue

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

Definition at line 392 of file commandsProc.hxx.

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

◆ _port

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

Definition at line 390 of file commandsProc.hxx.

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

◆ _value

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: