2 #include "ScriptProcessorPy.h"
3 #include "PyEmbedder.h"
5 #if defined(_DEBUG) && defined(SWIG_PYTHON_INTERPRETER_NO_DEBUG)
17 ScriptProcessorPy::ScriptProcessorPy(
void)
21 ScriptProcessorPy::~ScriptProcessorPy(
void)
27 {
Std_TraceMsg(0,
"Caught Error in desctructor of ScriptProcessorPy\r\n",
"", -1,
false,
true);}
30 void ScriptProcessorPy::InitPy(std::string strVal)
36 std::string ScriptProcessorPy::InitPy() {
return m_strInitPy;}
38 void ScriptProcessorPy::ResetSimPy(std::string strVal) {m_strResetSimPy = strVal;}
40 std::string ScriptProcessorPy::ResetSimPy() {
return m_strResetSimPy;}
42 void ScriptProcessorPy::BeforeStepPhysicsEnginePy(std::string strVal) {m_strBeforeStepPhysicsEnginePy = strVal;}
44 std::string ScriptProcessorPy::BeforeStepPhysicsEnginePy() {
return m_strBeforeStepPhysicsEnginePy;}
46 void ScriptProcessorPy::AfterStepPhysicsEnginePy(std::string strVal) {m_strAfterStepPhysicsEnginePy = strVal;}
48 std::string ScriptProcessorPy::AfterStepPhysicsEnginePy() {
return m_strAfterStepPhysicsEnginePy;}
50 void ScriptProcessorPy::BeforeStepNeuralEnginePy(std::string strVal) {m_strBeforeStepNeuralEnginePy = strVal;}
52 std::string ScriptProcessorPy::BeforeStepNeuralEnginePy() {
return m_strBeforeStepNeuralEnginePy;}
54 void ScriptProcessorPy::AfterStepNeuralEnginePy(std::string strVal) {m_strAfterStepNeuralEnginePy = strVal;}
56 std::string ScriptProcessorPy::AfterStepNeuralEnginePy() {
return m_strAfterStepNeuralEnginePy;}
58 void ScriptProcessorPy::KillPy(std::string strVal) {m_strKillPy = strVal;}
60 std::string ScriptProcessorPy::KillPy() {
return m_strKillPy;}
62 void ScriptProcessorPy::KillResetPy(std::string strVal) {m_strKillResetPy = strVal;}
64 std::string ScriptProcessorPy::KillResetPy() {
return m_strKillResetPy;}
66 void ScriptProcessorPy::SimStartingPy(std::string strVal) {m_strSimStartingPy = strVal;}
68 std::string ScriptProcessorPy::SimStartingPy() {
return m_strSimStartingPy;}
70 void ScriptProcessorPy::SimPausingPy(std::string strVal) {m_strSimPausingPy = strVal;}
72 std::string ScriptProcessorPy::SimPausingPy() {
return m_strSimPausingPy;}
74 void ScriptProcessorPy::SimStoppingPy(std::string strVal) {m_strSimStoppingPy = strVal;}
76 std::string ScriptProcessorPy::SimStoppingPy() {
return m_strSimStoppingPy;}
78 bool ScriptProcessorPy::ExecutePythonScript(
const std::string &strPy,
bool bThrowError)
81 static PyEmbedder g_pyEmbedder;
83 return g_pyEmbedder.ExecutePythonScript(strPy, bThrowError);
90 ScriptProcessor::Initialize();
92 ExecutePythonScript(m_strInitPy);
97 ScriptProcessor::ResetSimulation();
98 ExecutePythonScript(m_strResetSimPy);
101 void ScriptProcessorPy::BeforeStepPhysicsEngine()
103 ScriptProcessor::BeforeStepPhysicsEngine();
104 ExecutePythonScript(m_strBeforeStepPhysicsEnginePy);
107 void ScriptProcessorPy::AfterStepPhysicsEngine()
109 ScriptProcessor::AfterStepPhysicsEngine();
110 ExecutePythonScript(m_strAfterStepPhysicsEnginePy);
113 void ScriptProcessorPy::BeforeStepNeuralEngine()
115 ScriptProcessor::BeforeStepNeuralEngine();
116 ExecutePythonScript(m_strBeforeStepNeuralEnginePy);
119 void ScriptProcessorPy::AfterStepNeuralEngine()
121 ScriptProcessor::AfterStepNeuralEngine();
122 ExecutePythonScript(m_strAfterStepNeuralEnginePy);
127 ScriptProcessor::Kill(bState);
130 ExecutePythonScript(m_strKillPy);
132 ExecutePythonScript(m_strKillResetPy);
137 ScriptProcessor::SimStarting();
138 ExecutePythonScript(m_strSimStartingPy);
143 ScriptProcessor::SimPausing();
144 ExecutePythonScript(m_strSimPausingPy);
149 ScriptProcessor::SimStopping();
150 ExecutePythonScript(m_strSimStoppingPy);
157 if(ScriptProcessor::SetData(strDataType, strValue,
false))
160 if(strType ==
"ENABLED")
166 if(strType ==
"RESETSIMPY")
168 ResetSimPy(strValue);
172 if(strType ==
"BEFORESTEPPHYSICSENGINEPY")
174 BeforeStepPhysicsEnginePy(strValue);
178 if(strType ==
"AFTERSTEPPHYSICSENGINEPY")
180 AfterStepPhysicsEnginePy(strValue);
184 if(strType ==
"BEFORESTEPNEURALENGINEPY")
186 BeforeStepNeuralEnginePy(strValue);
190 if(strType ==
"AFTERSTEPNEURALENGINEPY")
192 AfterStepNeuralEnginePy(strValue);
196 if(strType ==
"INITPY")
202 if(strType ==
"KILLPY")
208 if(strType ==
"KILLRESETPY")
210 KillResetPy(strValue);
214 if(strType ==
"SIMSTARTINGPY")
216 SimStartingPy(strValue);
220 if(strType ==
"SIMPAUSINGPY")
222 SimPausingPy(strValue);
226 if(strType ==
"SIMSTOPPINGPY")
228 SimStoppingPy(strValue);
234 THROW_PARAM_ERROR(Al_Err_lInvalidItemType, Al_Err_strInvalidItemType,
"Data Type", strDataType);
239 void ScriptProcessorPy::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
241 ScriptProcessor::QueryProperties(aryProperties);
243 aryProperties.Add(
new TypeProperty(
"Enabled", AnimatPropertyType::Boolean, AnimatPropertyDirection::Set));
244 aryProperties.Add(
new TypeProperty(
"InitPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
245 aryProperties.Add(
new TypeProperty(
"ResetSimPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
246 aryProperties.Add(
new TypeProperty(
"BeforeStepPhysicsEnginePy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
247 aryProperties.Add(
new TypeProperty(
"AfterStepPhysicsEnginePy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
248 aryProperties.Add(
new TypeProperty(
"BeforeStepNeuralEnginePy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
249 aryProperties.Add(
new TypeProperty(
"AfterStepNeuralEnginePy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
250 aryProperties.Add(
new TypeProperty(
"KillPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
251 aryProperties.Add(
new TypeProperty(
"KillResetPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
252 aryProperties.Add(
new TypeProperty(
"SimStartingPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
253 aryProperties.Add(
new TypeProperty(
"SimPausingPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
254 aryProperties.Add(
new TypeProperty(
"SimStoppingPy", AnimatPropertyType::String, AnimatPropertyDirection::Set));
259 ScriptProcessor::Load(oXml);
266 BeforeStepPhysicsEnginePy(oXml.
GetChildString(
"BeforeStepPhysicsEnginePy", m_strBeforeStepPhysicsEnginePy));
267 AfterStepPhysicsEnginePy(oXml.
GetChildString(
"AfterStepPhysicsEnginePy", m_strAfterStepPhysicsEnginePy));
268 BeforeStepNeuralEnginePy(oXml.
GetChildString(
"BeforeStepNeuralEnginePy", m_strBeforeStepNeuralEnginePy));
269 AfterStepNeuralEnginePy(oXml.
GetChildString(
"AfterStepNeuralEnginePy", m_strAfterStepNeuralEnginePy));
271 KillResetPy(oXml.
GetChildString(
"KillResetPy", m_strKillResetPy));
272 SimStartingPy(oXml.
GetChildString(
"SimStartingPy", m_strSimStartingPy));
273 SimPausingPy(oXml.
GetChildString(
"SimPausingPy", m_strSimPausingPy));
274 SimStoppingPy(oXml.
GetChildString(
"SimStoppingPy", m_strSimStoppingPy));
virtual void Kill(bool bState=true)
Kills.
virtual void Initialize()
Initializes this object.
virtual bool IntoElem()
Goes into the next element where the cursor is located.
virtual void SimStopping()
Called just before the simulation stops.
virtual void SimPausing()
Called just before the simulation pauses.
virtual bool Enabled()
Tells whether this item is enabled or not. This is not actually used for all objects, only specific ones. I am putting it in the base class though to prevent numerous duplications.
A standard xml manipulation class.
virtual std::string GetChildString(std::string strElementName)
Gets a string value from the element with the specified name.
bool Std_ToBool(int iVal)
Converts a value toa bool.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
virtual bool GetChildBool(std::string strElementName)
Gets a bool value from the element with the specified name.
bool m_bEnabled
Tells if this item is enabled or not. If it is not enabled then it is not run.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void ResetSimulation()
Resets the simulation back to time 0.
virtual void Load(StdUtils::CStdXml &oXml)
Loads the item using an XML data packet.
virtual bool SetData(const std::string &strDataType, const std::string &strValue, bool bThrowError=true)
Set a variable based on a string data type name.
virtual void SimStarting()
Called just before the simulation starts.