Commit 077e9aa1 authored by Matthias Möller's avatar Matthias Möller

add "groupObject" scriptfunction which adds objects to an existing group

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16235 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2b93a236
......@@ -365,6 +365,9 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn
*/
int groupObjects(IdList _objectIDs, QString _groupName = "");
/// add an object to an existing group
bool groupObject(int _objectId, int _groupId);
/** remove an object from its group and place it at the toplevel group
*
* @return successfull
......
......@@ -122,6 +122,10 @@ void DataControlPlugin::setDescriptions(){
emit setSlotDescription("printObjectInfoToLog()",tr("Print info about all objects to log"),
QStringList(), QStringList());
emit setSlotDescription("groupObject(int,int)",tr("Add an Object to an existing group"),
QStringList(tr("objectId,groupId").split(",")),
QStringList(tr("ID of an object.,ID of an group where the object has to be added.").split(",")));
}
......@@ -380,7 +384,6 @@ bool DataControlPlugin::unGroupObject(int _id) {
emit log( LOGERR, tr( "Unable to get Object with id %1 for ungrouping").arg(_id) );
return false;
}
}
......@@ -598,3 +601,34 @@ QStringList DataControlPlugin::availableDataTypeNames() const {
}
//******************************************************************************
/** \brief add an object to an existing group
*
* add the object with _objectId to the group with _groupId
*
* @return success
*/
bool DataControlPlugin::groupObject(int _objectId, int _groupId)
{
BaseObject* obj = 0;
BaseObject* group = 0;
PluginFunctions::getObject(_objectId,obj);
PluginFunctions::getObject(_groupId,group);
if ( obj && group)
{
if (group->isGroup())
{
obj->setParent(group);
return true;
}
else
emit log( LOGERR, tr(" Object with id %1 is not a group").arg(_groupId));
} else {
if (!obj)
emit log( LOGERR, tr( "Unable to get Object with id %1").arg(_objectId) );
if (!_groupId)
emit log( LOGERR, tr( "Unable to get Group with id %1").arg(_groupId) );
}
return false;
}
core.clearAll()
//Group 20 Objects
for (i=0; i < 20;++i)
primitivesgenerator.addSphere()
{
primitivesgenerator.addSphere()
}
datacontrol.setAllTarget()
var list = datacontrol.getTargetObjects(DataType("TriangleMesh"));
//Check, if group was created
groupid = datacontrol.groupObjects(list)
if (groupid == -1)
{
print("unable to create a group with 20 objects")
core.exitFailure()
}
if (datacontrol.groupCount() != 1)
{
print("Group 20 Objects failed")
print("unexpected group count")
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 1")
core.exitFailure()
print("unexpected group count")
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 1")
core.exitFailure()
}
datacontrol.clearAllTarget()
......@@ -21,10 +32,10 @@ datacontrol.groupObjects(list)
if (datacontrol.groupCount() != 2)
{
print("Group Object and Group failed")
print("unexpected group count")
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 2")
core.exitFailure()
print("unexpected group count")
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 2")
core.exitFailure()
}
datacontrol.clearAllTarget()
......@@ -52,4 +63,29 @@ if (datacontrol.groupCount() != 2)
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 2")
core.exitFailure()
}
//add object to existing group
core.clearAll()
id1 = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
id3 = primitivesgenerator.addSphere()
groupid = datacontrol.groupObjects([id1,id2])
datacontrol.groupObject(id3,groupid)
datacontrol.groupObjects([id1,id2,id3])//Can be done, if all objects are in the same group
if (datacontrol.groupCount() != 2)
{
print("Add to Group failed.")
print("unexpected group count")
print("number of groups: " + datacontrol.groupCount())
print("expected number of groups: 2")
core.exitFailure()
}
if (datacontrol.groupObject(id3,id2))
{
print("Could add an object to an object which is not a Group.")
core.exitFailure();
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment