Skip to content
Snippets Groups Projects
Commit f349ce7d authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding directivity methods (untested)

parent 8a47fab0
No related branches found
No related tags found
No related merge requests found
...@@ -17,10 +17,9 @@ static PyObject* g_pVAError = nullptr; //!< Static pointer to error instance ...@@ -17,10 +17,9 @@ static PyObject* g_pVAError = nullptr; //!< Static pointer to error instance
#define VAPY_CATCH_RETURN } catch (const CVAException& oError) { PyErr_SetString(PyExc_Exception, oError.ToString().c_str()); return NULL; } #define VAPY_CATCH_RETURN } catch (const CVAException& oError) { PyErr_SetString(PyExc_Exception, oError.ToString().c_str()); return NULL; }
//! Helper for API dev //! Helper for API dev
static PyObject* va_not_implemented(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_not_implemented(PyObject*, PyObject*)
{ {
VA_EXCEPT_NOT_IMPLEMENTED; VA_EXCEPT_NOT_IMPLEMENTED;
return NULL;
}; };
//! Raises an exception if core is not available //! Raises an exception if core is not available
...@@ -36,7 +35,56 @@ static void RequireCoreAvailable() ...@@ -36,7 +35,56 @@ static void RequireCoreAvailable()
//! Helper to convert recursively from VAStruct to Python dict //! Helper to convert recursively from VAStruct to Python dict
PyObject* ConvertVAStructToPythonDict(const CVAStruct& oInStruct) PyObject* ConvertVAStructToPythonDict(const CVAStruct& oInStruct)
{ {
return PyLong_FromLong( -1 ); PyObject* pOutDict = PyDict_New();
CVAStruct::const_iterator cit = oInStruct.Begin();
while (cit != oInStruct.End())
{
const std::string sKey((*cit++).first);
const CVAStructValue& oValue(oInStruct[sKey]);
PyObject* pNewValue = nullptr;
if (oValue.IsBool())
{
pNewValue = PyBool_FromLong(bool(oValue));
}
else if (oValue.IsInt())
{
pNewValue = PyLong_FromLong(int(oValue));
}
else if (oValue.IsDouble())
{
pNewValue = PyFloat_FromDouble(double(oValue));
}
else if (oValue.IsString())
{
pNewValue = PyUnicode_FromString(std::string(oValue).c_str());
}
else if (oValue.IsStruct())
{
pNewValue = ConvertVAStructToPythonDict(oValue);
}
else if (oValue.IsData())
{
VA_EXCEPT_NOT_IMPLEMENTED;
}
else if (oValue.IsSampleBuffer())
{
VA_EXCEPT_NOT_IMPLEMENTED;
}
else
{
VA_EXCEPT2(INVALID_PARAMETER, "Could not interpret value of key '" + sKey + "' as a supported python dict type. Value was" + oValue.ToString());
}
if (!pNewValue)
VA_EXCEPT2(INVALID_PARAMETER, "Could not create python object from value of key '" + sKey + "'. Value was" + oValue.ToString());
if (PyDict_SetItemString(pOutDict, sKey.c_str(), pNewValue) == -1)
VA_EXCEPT2(INVALID_PARAMETER, "Could not create python object from value of key '" + sKey + "'. Value was" + oValue.ToString());
}
return pOutDict;
}; };
//! Helper to convert recursively from Python dict to VAStruct //! Helper to convert recursively from Python dict to VAStruct
...@@ -61,7 +109,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict ) ...@@ -61,7 +109,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
} }
else if (PyBool_Check(pValue)) else if (PyBool_Check(pValue))
{ {
oReturn[pcKeyName] = bool(PyLong_AsLong(pValue)); oReturn[pcKeyName] = ( PyLong_AsLong(pValue) != 0 );
} }
else if (PyLong_Check(pValue)) else if (PyLong_Check(pValue))
{ {
...@@ -104,7 +152,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict ) ...@@ -104,7 +152,7 @@ CVAStruct ConvertPythonDictToVAStruct( PyObject* pInDict )
// ------------------------------- Python module extension methods // ------------------------------- Python module extension methods
static PyObject* va_connect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_connect(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{ {
if (!g_pVANetClient) if (!g_pVANetClient)
g_pVANetClient = IVANetClient::Create(); g_pVANetClient = IVANetClient::Create();
...@@ -132,7 +180,7 @@ static PyObject* va_connect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs ...@@ -132,7 +180,7 @@ static PyObject* va_connect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs
return NULL; return NULL;
}; };
static PyObject* va_disconnect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_disconnect(PyObject*, PyObject*)
{ {
if (!g_pVANetClient) if (!g_pVANetClient)
return PyBool_FromLong(0); return PyBool_FromLong(0);
...@@ -140,7 +188,7 @@ static PyObject* va_disconnect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nA ...@@ -140,7 +188,7 @@ static PyObject* va_disconnect(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nA
return PyBool_FromLong(g_pVANetClient->Disconnect()); return PyBool_FromLong(g_pVANetClient->Disconnect());
}; };
static PyObject* va_is_connected(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_is_connected(PyObject*, PyObject*)
{ {
if (!g_pVANetClient) if (!g_pVANetClient)
return PyBool_FromLong(0); return PyBool_FromLong(0);
...@@ -157,7 +205,7 @@ static PyObject* va_reset(PyObject*, PyObject*) ...@@ -157,7 +205,7 @@ static PyObject* va_reset(PyObject*, PyObject*)
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_enumerate_modules(PyObject*, PyObject*)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
...@@ -178,7 +226,7 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi ...@@ -178,7 +226,7 @@ static PyObject* va_enumerate_modules(PyObject* pSelf, PyObject** ppArgs, Py_ssi
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_call_module(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
...@@ -201,7 +249,7 @@ static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t n ...@@ -201,7 +249,7 @@ static PyObject* va_call_module(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t n
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_add_search_path(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_add_search_path(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
...@@ -216,7 +264,7 @@ static PyObject* va_add_search_path(PyObject* pSelf, PyObject** ppArgs, Py_ssize ...@@ -216,7 +264,7 @@ static PyObject* va_add_search_path(PyObject* pSelf, PyObject** ppArgs, Py_ssize
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_create_listener(PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames) static PyObject* va_create_listener(PyObject*, PyObject*)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
...@@ -228,25 +276,106 @@ static PyObject* va_create_listener(PyObject* pSelf, PyObject** ppArgs, Py_ssize ...@@ -228,25 +276,106 @@ static PyObject* va_create_listener(PyObject* pSelf, PyObject** ppArgs, Py_ssize
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_is_scene_locked( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames ) static PyObject* va_is_scene_locked(PyObject*, PyObject*)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
return PyLong_FromLong(g_pVANetClient->GetCoreInstance()->IsSceneLocked()); return PyLong_FromLong(g_pVANetClient->GetCoreInstance()->IsSceneLocked());
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_lock_scene( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames ) static PyObject* va_lock_scene(PyObject* , PyObject*)
{ {
VAPY_REQUIRE_CONN_TRY VAPY_REQUIRE_CONN_TRY;
g_pVANetClient->GetCoreInstance()->LockScene(); g_pVANetClient->GetCoreInstance()->LockScene();
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_unlock_scene( PyObject* pSelf, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames ) static PyObject* va_unlock_scene(PyObject* , PyObject*)
{ {
VAPY_REQUIRE_CONN_TRY; VAPY_REQUIRE_CONN_TRY;
return PyLong_FromLong(g_pVANetClient->GetCoreInstance()->UnlockScene()); return PyLong_FromLong(g_pVANetClient->GetCoreInstance()->UnlockScene());
VAPY_CATCH_RETURN; VAPY_CATCH_RETURN;
}; };
static PyObject* va_load_directivity(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "path", "name", NULL };
static _PyArg_Parser _parser = { "s|s:load_directivity", _keywords, 0 };
char* pcPath = nullptr;
char* pcName = nullptr;
if (!_PyArg_ParseStack(ppArgs, nArgs, pKeywordNames, &_parser, &pcPath, &pcName))
return NULL;
std::string sName = pcName ? std::string(pcName) : "";
return PyBool_FromLong(g_pVANetClient->GetCoreInstance()->LoadDirectivity(std::string(pcPath), sName));
VAPY_CATCH_RETURN;
};
static PyObject* va_free_directivity(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "id", NULL };
static _PyArg_Parser _parser = { "i:free_directivity", _keywords, 0 };
long iID = -1;
if (!_PyArg_ParseStack(ppArgs, nArgs, pKeywordNames, &_parser, &iID))
return NULL;
return PyBool_FromLong(g_pVANetClient->GetCoreInstance()->FreeDirectivity(iID));
VAPY_CATCH_RETURN;
};
static PyObject* va_get_directivity_info(PyObject*, PyObject** ppArgs, Py_ssize_t nArgs, PyObject* pKeywordNames)
{
VAPY_REQUIRE_CONN_TRY;
static const char * const _keywords[] = { "id", NULL };
static _PyArg_Parser _parser = { "i:get_directivity_info", _keywords, 0 };
long iID = -1;
if (!_PyArg_ParseStack(ppArgs, nArgs, pKeywordNames, &_parser, &iID))
return NULL;
CVADirectivityInfo oInfo = g_pVANetClient->GetCoreInstance()->GetDirectivityInfo(iID);
PyObject* pInfo = Py_BuildValue("{s:i,s:s,s:s,s:i,s:s}",
"id", oInfo.iID,
"name", oInfo.sName.c_str(),
"filepath", oInfo.sFilename.c_str(),
"references", oInfo.iReferences,
"description", oInfo.sDesc.c_str());
return pInfo;
VAPY_CATCH_RETURN;
};
static PyObject* va_get_directivity_infos(PyObject*, PyObject*)
{
VAPY_REQUIRE_CONN_TRY;
std::vector< CVADirectivityInfo > voInfos;
g_pVANetClient->GetCoreInstance()->GetDirectivityInfos(voInfos);
PyObject* pInfoList = PyList_New(voInfos.size());
for (size_t i = 0; i < voInfos.size(); i++)
{
CVADirectivityInfo& oInfo(voInfos[i]);
PyObject* pInfo = Py_BuildValue("{s:i,s:s,s:s,s:i,s:s}",
"id", oInfo.iID,
"name", oInfo.sName.c_str(),
"filepath", oInfo.sFilename.c_str(),
"references", oInfo.iReferences,
"description", oInfo.sDesc.c_str());
PyList_SetItem(pInfoList, i, pInfo); // steals reference
}
return pInfoList;
VAPY_CATCH_RETURN;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment