From 59b6edaad1a3ceb3b288e10904b48f3eec225138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Fri, 8 Feb 2013 09:57:28 +0000 Subject: [PATCH] add "getGroupElements" script function + test git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@16266 383ad7c9-94d9-4d36-a494-682f7c89f535 --- DataControlPlugin.hh | 3 +++ DataControlPluginScripting.cc | 23 +++++++++++++++++++++++ tests/group.ofs | 26 +++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/DataControlPlugin.hh b/DataControlPlugin.hh index 00c0b46..8433543 100644 --- a/DataControlPlugin.hh +++ b/DataControlPlugin.hh @@ -392,6 +392,9 @@ class DataControlPlugin : public QObject, BaseInterface, ToolboxInterface, KeyIn /// Print information about all open objects to the console void printObjectInfoToLog(); + /// Get all elements of the given group + IdList getGroupElements(int _groupId); + /** @} */ public slots: diff --git a/DataControlPluginScripting.cc b/DataControlPluginScripting.cc index bf091d1..9aa7318 100644 --- a/DataControlPluginScripting.cc +++ b/DataControlPluginScripting.cc @@ -101,6 +101,9 @@ void DataControlPlugin::setDescriptions(){ emit setSlotDescription("objectDelete(int)",tr("Delete an object"), QStringList(tr("objectId")), QStringList(tr("Delete the given object."))); + emit setSlotDescription("getGroupElements(int)",tr("Get elements of a group"), + QStringList(tr("groupId")), QStringList(tr("Id of the group."))); + emit setSlotDescription("copyObject(int)",tr("Create a copy of an object"), QStringList(tr("objectId")), QStringList(tr("Object to copy."))); @@ -638,3 +641,23 @@ bool DataControlPlugin::addObjectToGroup(int _objectId, int _groupId) } return false; } + +//****************************************************************************** +/** \brief get all objects of an given group + * + * get all objects of an given group with id _groupId + * + * @return id list of group elements +*/ + +IdList DataControlPlugin::getGroupElements(int _groupId) +{ + BaseObject* group = 0; + PluginFunctions::getObject(_groupId,group); + IdList result; + + for (int i = 0; i < group->childCount(); ++i) + result.push_back(group->child(i)->id()); + + return result; +} diff --git a/tests/group.ofs b/tests/group.ofs index b565183..a344e42 100644 --- a/tests/group.ofs +++ b/tests/group.ofs @@ -88,4 +88,28 @@ if (datacontrol.addObjectToGroup(id3,id2)) { print("Could add an object to an object which is not a Group.") core.exitFailure(); -} \ No newline at end of file +} + +//Get group elements +id1 = primitivesgenerator.addSphere() +id2 = primitivesgenerator.addSphere() +elements = [id1,id2] +groupid = datacontrol.groupObjects(elements) +resuldList = datacontrol.getGroupElements(groupid) + +if (resuldList.length != elements.length) +{ + print("error: getGroupElements") + print("number of received elements is: "+elements.length+" expected was: "+resuldList.length) + core.exitFailure(); +} +for (i = 0; i < resultId; ++i) +{ + if (resuldList[i] != groupId[i]) + { + print("error: getGroupElements") + print("id of received object differs") + print("expected was: "+groupId[i]+" result is: "+resuldIdList[i]) + core.exitFailure(); + } +} -- GitLab