Version: 9.16.0
YACS::HMI::CommandSetOutPortValue Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandSetOutPortValue:
Collaboration diagram for YACS::HMI::CommandSetOutPortValue:

Public Member Functions

 CommandSetOutPortValue (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 395 of file commandsProc.hxx.

Constructor & Destructor Documentation

◆ CommandSetOutPortValue()

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

Definition at line 2230 of file commandsProc.cxx.

2233 : Command(), _node(node), _port(port), _value(value)
2234{
2235 DEBTRACE("CommandSetOutPortValue::CommandSetOutPortValue " << node << " " << port << " " << value);
2236 _oldValue = "";
2237}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _oldValue, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandSetOutPortValue::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2239 of file commandsProc.cxx.

2240{
2241 string ret ="CommandSetOutPortValue " + _node + " " + _port + " " + _value;
2242 return ret;
2243}

References _node, _port, and _value.

◆ localExecute()

bool CommandSetOutPortValue::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2245 of file commandsProc.cxx.

2246{
2247 DEBTRACE("CommandSetOutPortValue::localExecute");
2248 OutputPresetPort *outpp = 0;
2249 OutputStudyPort *outsp = 0;
2250 DataNode *dnode = 0;
2251 SubjectDataPort *soutp = 0;
2252 try
2253 {
2254 Proc* proc = GuiContext::getCurrent()->getProc();
2255 Node* node = proc->getChildByName(_node);
2256 OutputPort* outp = node->getOutputPort(_port);
2257 outpp = dynamic_cast<OutputPresetPort*>(outp);
2258 outsp = dynamic_cast<OutputStudyPort*>(outp);
2259 dnode = dynamic_cast<DataNode*>(node);
2260 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2262 }
2263 catch (Exception& ex)
2264 {
2265 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2266 setErrorMsg(ex);
2267 return false;
2268 }
2269
2270 if (!outpp && !outsp)
2271 {
2272 DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2273 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2274 return false;
2275 }
2276
2277 if (!dnode)
2278 {
2279 DEBTRACE("Set value on output port only possible on a dataNode");
2280 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2281 return false;
2282 }
2283
2284 if(outsp)
2285 {
2286 //It's a study port
2287 _oldValue = outsp->getAsString();
2288 DEBTRACE("old value="<< _oldValue);
2289 dnode->setData(outsp, _value );
2290 soutp->update(SETVALUE, 0, soutp);
2291 return true;
2292 }
2293
2294 PyObject *result;
2295 try
2296 {
2297 _oldValue = outpp->getAsString();
2298 if (_oldValue == "None") _oldValue = "";
2299 DEBTRACE("old value="<< _oldValue);
2300 std::string strval;
2301 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2302 strval = "\"" + _value + "\"";
2303 else
2304 strval = _value;
2305 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2306 }
2307 catch (Exception& ex)
2308 {
2309 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2310 setErrorMsg(ex);
2311 return false;
2312 }
2313
2314 string val;
2315 PyGILState_STATE gstate = PyGILState_Ensure();
2316 try
2317 {
2318 DEBTRACE(PyObject_Str(result));
2319 val = convertPyObjectXml(outpp->edGetType(), result);
2320 DEBTRACE(val);
2321 dnode->setData(outpp, val );
2322 soutp->update(SETVALUE, 0, soutp);
2323 }
2324 catch (Exception& ex)
2325 {
2326 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2327 setErrorMsg(ex);
2328 Py_DECREF(result);
2329 PyGILState_Release(gstate);
2330 return false;
2331 }
2332
2333 Py_DECREF(result);
2334 PyGILState_Release(gstate);
2335 return true;
2336}
#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
Base class for all nodes.
Definition: Node.hxx:70
virtual OutputPort * getOutputPort(const std::string &name) const =0
Class for PRESET output Ports.
Definition: PresetPorts.hxx:33
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Class for Study output Ports.
Definition: StudyPorts.hxx:33
virtual std::string getAsString()
returns port value as a string that can be used in a GUI for example
Definition: StudyPorts.cxx:134
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::string _lastErrorMessage
Definition: guiContext.hxx:79
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()
std::string convertPyObjectXml(const TypeCode *t, PyObject *data)

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::convertPyObjectXml(), YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), testCppPluginInvokation::ex, YACS::ENGINE::OutputPresetPort::getAsString(), YACS::ENGINE::OutputStudyPort::getAsString(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getOutputPort(), 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 CommandSetOutPortValue::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2338 of file commandsProc.cxx.

2339{
2340 DEBTRACE("CommandSetOutPortValue::localReverse");
2341 OutputPresetPort *outpp = 0;
2342 OutputStudyPort *outsp = 0;
2343 DataNode *dnode = 0;
2344 SubjectDataPort *soutp = 0;
2345 try
2346 {
2347 Proc* proc = GuiContext::getCurrent()->getProc();
2348 Node* node = proc->getChildByName(_node);
2349 OutputPort* outp = node->getOutputPort(_port);
2350 outpp = dynamic_cast<OutputPresetPort*>(outp);
2351 outsp = dynamic_cast<OutputStudyPort*>(outp);
2352 dnode = dynamic_cast<DataNode*>(node);
2353 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2355 }
2356 catch (Exception& ex)
2357 {
2358 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2359 setErrorMsg(ex);
2360 return false;
2361 }
2362
2363 if (!outpp && !outsp)
2364 {
2365 DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2366 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2367 return false;
2368 }
2369
2370 if (!dnode)
2371 {
2372 DEBTRACE("Set value on output port only possible on a dataNode");
2373 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2374 return false;
2375 }
2376
2377 if(outsp)
2378 {
2379 //It's a study port
2380 _value = outsp->getAsString();
2381 DEBTRACE("value="<< _value);
2382 DEBTRACE("old value="<< _oldValue);
2383 dnode->setData(outsp, _oldValue );
2384 soutp->update(SETVALUE, 0, soutp);
2385 return true;
2386 }
2387
2388 PyObject *result = Py_None;
2389 try
2390 {
2391 _value = outpp->getAsString();
2392 DEBTRACE("value="<< _value);
2393 DEBTRACE("old value="<< _oldValue);
2394 if (!_oldValue.empty())
2395 {
2396 std::string strval;
2397 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2398 strval = "\"" + _value + "\"";
2399 else
2400 strval = _value;
2401 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2402 }
2403 }
2404 catch (Exception& ex)
2405 {
2406 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2407 setErrorMsg(ex);
2408 return false;
2409 }
2410
2411 string val;
2412 PyGILState_STATE gstate = PyGILState_Ensure();
2413 try
2414 {
2415 DEBTRACE(PyObject_Str(result));
2416 val = convertPyObjectXml(outpp->edGetType(), result);
2417 DEBTRACE(val);
2418 dnode->setData(outpp, val );
2419 soutp->update(SETVALUE, 0, soutp);
2420 }
2421 catch (Exception& ex)
2422 {
2423 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2424 setErrorMsg(ex);
2425 Py_DECREF(result);
2426 PyGILState_Release(gstate);
2427 return false;
2428 }
2429
2430 Py_DECREF(result);
2431 PyGILState_Release(gstate);
2432 return true;
2433}

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectDataPort, _node, _oldValue, _port, _value, YACS::ENGINE::convertPyObjectXml(), YACS::ENGINE::RuntimeSALOME::convertStringToPyObject(), DEBTRACE, YACS::ENGINE::DataPort::edGetType(), testCppPluginInvokation::ex, YACS::ENGINE::OutputPresetPort::getAsString(), YACS::ENGINE::OutputStudyPort::getAsString(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getOutputPort(), 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::CommandSetOutPortValue::_node
protected

Definition at line 405 of file commandsProc.hxx.

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

◆ _oldValue

std::string YACS::HMI::CommandSetOutPortValue::_oldValue
protected

Definition at line 408 of file commandsProc.hxx.

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

◆ _port

std::string YACS::HMI::CommandSetOutPortValue::_port
protected

Definition at line 406 of file commandsProc.hxx.

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

◆ _value

std::string YACS::HMI::CommandSetOutPortValue::_value
protected

Definition at line 407 of file commandsProc.hxx.

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


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