pybullet removeAllParameters (sliders, buttons)

pybullet addUserDebugParameter adds button instead of slider, if min > max.
This commit is contained in:
Erwin Coumans
2020-03-16 21:29:30 -07:00
parent b105764470
commit 27fbbfee7f
7 changed files with 106 additions and 2 deletions
@@ -114,6 +114,8 @@ struct GUIHelperInterface
virtual void removeUserDebugItem(int debugItemUniqueId){};
virtual void removeAllUserDebugItems(){};
virtual void removeAllUserParameters() {};
virtual void setVisualizerFlagCallback(VisualizerFlagCallback callback) {}
//empty name stops dumping video
@@ -4059,6 +4059,20 @@ B3_SHARED_API b3SharedMemoryCommandHandle b3InitUserDebugDrawRemoveAll(b3Physics
return (b3SharedMemoryCommandHandle)command;
}
B3_SHARED_API b3SharedMemoryCommandHandle b3InitUserRemoveAllParameters(b3PhysicsClientHandle physClient)
{
PhysicsClient* cl = (PhysicsClient*)physClient;
b3Assert(cl);
b3Assert(cl->canSubmitCommand());
struct SharedMemoryCommand* command = cl->getAvailableSharedMemoryCommand();
b3Assert(command);
command->m_type = CMD_USER_DEBUG_DRAW;
command->m_updateFlags = USER_DEBUG_REMOVE_ALL_PARAMETERS;
command->m_userDebugDrawArgs.m_parentObjectUniqueId = -1;
return (b3SharedMemoryCommandHandle)command;
}
B3_SHARED_API int b3GetDebugItemUniqueId(b3SharedMemoryStatusHandle statusHandle)
{
const SharedMemoryStatus* status = (const SharedMemoryStatus*)statusHandle;
@@ -236,6 +236,7 @@ extern "C"
B3_SHARED_API b3SharedMemoryCommandHandle b3InitUserDebugDrawRemove(b3PhysicsClientHandle physClient, int debugItemUniqueId);
B3_SHARED_API b3SharedMemoryCommandHandle b3InitUserDebugDrawRemoveAll(b3PhysicsClientHandle physClient);
B3_SHARED_API b3SharedMemoryCommandHandle b3InitUserRemoveAllParameters(b3PhysicsClientHandle physClient);
B3_SHARED_API b3SharedMemoryCommandHandle b3InitDebugDrawingCommand(b3PhysicsClientHandle physClient);
B3_SHARED_API void b3SetDebugObjectColor(b3SharedMemoryCommandHandle commandHandle, int objectUniqueId, int linkIndex, const double objectColorRGB[/*3*/]);
@@ -5644,6 +5644,14 @@ bool PhysicsServerCommandProcessor::processUserDebugDrawCommand(const struct Sha
m_data->m_guiHelper->removeAllUserDebugItems();
serverCmd.m_type = CMD_USER_DEBUG_DRAW_COMPLETED;
}
if (clientCmd.m_updateFlags & USER_DEBUG_REMOVE_ALL_PARAMETERS)
{
m_data->m_guiHelper->removeAllUserParameters();
serverCmd.m_type = CMD_USER_DEBUG_DRAW_COMPLETED;
}
if (clientCmd.m_updateFlags & USER_DEBUG_REMOVE_ONE_ITEM)
{
m_data->m_guiHelper->removeUserDebugItem(clientCmd.m_userDebugDrawArgs.m_itemUniqueId);
+46 -1
View File
@@ -128,6 +128,7 @@ enum MultiThreadedGUIHelperCommunicationEnums
eGUIHelperRemoveTexture,
eGUIHelperSetVisualizerFlagCheckRenderedFrame,
eGUIHelperUpdateShape,
eGUIUserDebugRemoveAllParameters,
};
#include <stdio.h>
@@ -494,6 +495,13 @@ struct UserDebugParameter
int m_itemUniqueId;
};
static void UserButtonToggle(int buttonId, bool buttonState, void* userPointer)
{
UserDebugParameter* param = (UserDebugParameter*)userPointer;
param->m_value += 1;
}
struct UserDebugText
{
char m_text[1024];
@@ -1328,6 +1336,16 @@ public:
workerThreadWait();
}
virtual void removeAllUserParameters()
{
m_cs->lock();
m_cs->setSharedParam(1, eGUIUserDebugRemoveAllParameters);
workerThreadWait();
}
const char* m_mp4FileName;
virtual void dumpFramesToVideo(const char* mp4FileName)
{
@@ -2359,6 +2377,7 @@ void PhysicsServerExample::updateGraphics()
UserDebugParameter* param = new UserDebugParameter(m_multiThreadedHelper->m_tmpParam);
m_multiThreadedHelper->m_userDebugParams.push_back(param);
if (param->m_rangeMin<= param->m_rangeMax)
{
SliderParams slider(param->m_text, &param->m_value);
slider.m_minVal = param->m_rangeMin;
@@ -2367,6 +2386,19 @@ void PhysicsServerExample::updateGraphics()
if (m_multiThreadedHelper->m_childGuiHelper->getParameterInterface())
m_multiThreadedHelper->m_childGuiHelper->getParameterInterface()->registerSliderFloatParameter(slider);
}
else
{
int buttonId = -1;
bool isTrigger = false;
ButtonParams button(param->m_text, buttonId, isTrigger);
button.m_callback = UserButtonToggle;
button.m_userPointer = param;
button.m_initialState = false;
//create a button
if (m_multiThreadedHelper->m_childGuiHelper->getParameterInterface())
m_multiThreadedHelper->m_childGuiHelper->getParameterInterface()->registerButtonParameter(button);
}
m_multiThreadedHelper->m_userDebugParamUid = (*m_multiThreadedHelper->m_userDebugParams[m_multiThreadedHelper->m_userDebugParams.size() - 1]).m_itemUniqueId;
@@ -2424,10 +2456,23 @@ void PhysicsServerExample::updateGraphics()
m_multiThreadedHelper->mainThreadRelease();
break;
}
case eGUIUserDebugRemoveAllParameters:
{
B3_PROFILE("eGUIUserDebugRemoveAllParameters");
if (m_multiThreadedHelper->m_childGuiHelper->getParameterInterface())
m_multiThreadedHelper->m_childGuiHelper->getParameterInterface()->removeAllParameters();
for (int i = 0; i < m_multiThreadedHelper->m_userDebugParams.size(); i++)
{
delete m_multiThreadedHelper->m_userDebugParams[i];
}
m_multiThreadedHelper->m_userDebugParams.clear();
m_multiThreadedHelper->mainThreadRelease();
break;
}
case eGUIUserDebugRemoveAllItems:
{
B3_PROFILE("eGUIUserDebugRemoveAllItems");
m_multiThreadedHelper->m_userDebugLines.clear();
m_multiThreadedHelper->m_userDebugText.clear();
m_multiThreadedHelper->m_uidGenerator = 0;
@@ -811,6 +811,7 @@ enum EnumUserDebugDrawFlags
USER_DEBUG_HAS_TEXT_ORIENTATION = 512,
USER_DEBUG_HAS_PARENT_OBJECT = 1024,
USER_DEBUG_HAS_REPLACE_ITEM_UNIQUE_ID = 2048,
USER_DEBUG_REMOVE_ALL_PARAMETERS = 4096,
};
struct UserDebugDrawArgs
+34 -1
View File
@@ -6096,7 +6096,7 @@ static PyObject* pybullet_removeAllUserDebugItems(PyObject* self, PyObject* args
int physicsClientId = 0;
b3PhysicsClientHandle sm = 0;
static char* kwlist[] = {"physicsClientId", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|i", kwlist, &physicsClientId))
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|i", kwlist, &physicsClientId))
{
return NULL;
}
@@ -6117,6 +6117,36 @@ static PyObject* pybullet_removeAllUserDebugItems(PyObject* self, PyObject* args
return Py_None;
}
static PyObject* pybullet_removeAllUserParameters(PyObject* self, PyObject* args, PyObject* keywds)
{
b3SharedMemoryCommandHandle commandHandle;
b3SharedMemoryStatusHandle statusHandle;
int statusType;
int physicsClientId = 0;
b3PhysicsClientHandle sm = 0;
static char* kwlist[] = { "physicsClientId", NULL };
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|i", kwlist, &physicsClientId))
{
return NULL;
}
sm = getPhysicsClient(physicsClientId);
if (sm == 0)
{
PyErr_SetString(SpamError, "Not connected to physics server.");
return NULL;
}
commandHandle = b3InitUserRemoveAllParameters(sm);
statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle);
statusType = b3GetStatusType(statusHandle);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject* pybullet_startStateLogging(PyObject* self, PyObject* args, PyObject* keywds)
{
b3SharedMemoryStatusHandle statusHandle;
@@ -12270,6 +12300,9 @@ static PyMethodDef SpamMethods[] = {
{"removeAllUserDebugItems", (PyCFunction)pybullet_removeAllUserDebugItems, METH_VARARGS | METH_KEYWORDS,
"remove all user debug draw items"},
{ "removeAllUserParameters", (PyCFunction)pybullet_removeAllUserParameters, METH_VARARGS | METH_KEYWORDS,
"remove all user debug parameters (sliders, buttons)" },
{"setDebugObjectColor", (PyCFunction)pybullet_setDebugObjectColor, METH_VARARGS | METH_KEYWORDS,
"Override the wireframe debug drawing color for a particular object unique id / link index."
"If you ommit the color, the custom color will be removed."},