Commits (3)
......@@ -178,7 +178,7 @@ PYBIND11_EMBEDDED_MODULE(DataControl, m) {
data.def("printObjectInfoToLog", &DataControlPlugin::printObjectInfoToLog,
QCoreApplication::translate("PythonDocDataControl","Print information about all open objects to the console").toLatin1().data() ) ;
data.def("getGroupElements", &DataControlPlugin::unGroupObject,
data.def("getGroupElements", &DataControlPlugin::getGroupElements,
QCoreApplication::translate("PythonDocDataControl","Get all elements of the given group").toLatin1().data(),
py::arg(QCoreApplication::translate("PythonDocDataControl","Id of a group").toLatin1().data()) ) ;
......
# Include Testing package
if(BUILD_TESTING)
include( ${CMAKE_SOURCE_DIR}/OpenFlipper/tests/testGenerators.cmake )
# ========================================================================
# ========================================================================
# Tests
# ========================================================================
# ========================================================================
run_local_script_test("dataType.ofp")
run_local_script_test("group.ofp")
endif()
# Reset everything
core.clearAll()
defaultLights = 3 #define the default lights
# Create triangle mesh
id = primitivesgenerator.addSphere()
#
if datacontrol.dataType(id) != "TriangleMesh":
print("DataType failed.")
print("Object is a " + datacontrol.dataType(id) + ". But expected to be a \"TriangleMesh\"")
core.exitFailure()
else:
print("Datatype TriangleMesh is correct")
targetMeshes = datacontrol.getTargetObjects("TriangleMesh").size
if targetMeshes != 1 :
print("Unexpected number of TriangleMeshes")
print("Expected was 0, the results is "+ str(targetMeshes) )
core.exitFailure()
else:
print("Correct number of target meshes: " + str(targetMeshes))
# Target triangle mesh
datacontrol.setTarget(id,True)
targetMeshes = datacontrol.getTargetObjects("TriangleMesh").size
if targetMeshes!= 1 :
print("Unexpected number of TriangleMeshes")
print("Expected was 1, the results is " + str(targetMeshes) )
core.exitFailure()
else:
print("Target objects correct " + str(targetMeshes))
# Create lights
lightId = typelight.addDefaultLight("MyLight")
lightId2 =typelight.addDefaultLight("MyLight2")
if lightId == -1 or lightId2 == -1 :
print("Unable to create default lights")
core.exitFailure()
else:
print("Lights created.")
if datacontrol.dataType(lightId) != "Light":
print("DataType failed.")
print("Object is a "+datacontrol.dataType(lightId)+". Expected was \"Light\"")
core.exitFailure()
else:
print("Datatype light is correct")
# Set all target and check target counters
datacontrol.setAllTarget()
targetLights = datacontrol.getTargetObjects("Light").size
if targetLights != 2+defaultLights :
print("Unexpected number of lights")
print("Expected was 2, the results is "+ str(targetLights) )
core.exitFailure()
else:
print("Number of target counts is correct: " + str(targetLights))
# Delete one light and one triangle mesh
datacontrol.objectDelete(id)
datacontrol.objectDelete(lightId)
# Target count Lights again
targetLights = datacontrol.getTargetObjects("Light").size
if targetLights != 1+defaultLights :
print("Unexpected number of lights")
print("Expected was 1, the results is " + str(targetLights) )
core.exitFailure()
else:
print("Correct number of target lights: " + str(targetLights))
targetMeshes = datacontrol.getTargetObjects("TriangleMesh").size
if targetMeshes != 0 :
print("Unexpected number of TriangleMeshes")
print("Expected was 0, the results is "+ str(targetMeshes) )
core.exitFailure()
else:
print("Correct number of target meshes: " + str(targetMeshes))
core.clearAll()
# Group 20 Objects
for i in range(0,20):
primitivesgenerator.addSphere()
datacontrol.setAllTarget()
list = datacontrol.getTargetObjects("TriangleMesh");
print("Target mesh ids: ")
print(list)
# Check, if group was created
groupid = datacontrol.groupObjects(list)
if groupid == -1:
print("Unable to create a group with 20 objects")
core.exitFailure()
else:
print("Group created with id: " + str(groupid))
if datacontrol.groupCount() != 1:
print("Group 20 Objects failed")
print("unexpected group count")
print("number of groups: " + str(datacontrol.groupCount()) )
print("expected number of groups: 1")
core.exitFailure()
else:
print("Grouping successfull")
datacontrol.clearAllTarget()
# Group Object and Group
id = primitivesgenerator.addSphere()
list = [groupid,id]
datacontrol.groupObjects(list)
if datacontrol.groupCount() != 2:
print("Group Object and Group failed")
print("unexpected group count")
print("number of groups: " + str(datacontrol.groupCount()) )
print("expected number of groups: 2")
core.exitFailure()
else:
print("Grouping successfull. Groupcount:" + str(datacontrol.groupCount()))
datacontrol.clearAllTarget()
# Group multiple Groups
id = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
list = [id2,id]
groupid2 = datacontrol.groupObjects(list)
if datacontrol.groupCount() != 3 :
print("Group multiple Groups failed")
print("unexpected group count")
print("number of groups: " + str(datacontrol.groupCount()) )
print("expected number of groups: 3")
core.exitFailure()
else:
print("Grouping successfull. Groupcount:" + str(datacontrol.groupCount()))
# Ungroup
datacontrol.unGroupObject(groupid2)
if datacontrol.groupCount() != 2:
print("Ungroup failed")
print("unexpected group count")
print("number of groups: " + str(datacontrol.groupCount()))
print("expected number of groups: 2")
core.exitFailure()
else:
print("Ungrouping successfull. Groupcount:" + str(datacontrol.groupCount()))
# add object to existing group
core.clearAll()
id1 = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
id3 = primitivesgenerator.addSphere()
groupid = datacontrol.groupObjects([id1,id2])
datacontrol.addObjectToGroup(id3,groupid)
# Can be done, if all objects are in the same group
datacontrol.groupObjects([id1,id2,id3])
if datacontrol.groupCount() != 2:
print("Add to Group failed.")
print("unexpected group count")
print("number of groups: " + str(datacontrol.groupCount()))
print("expected number of groups: 2")
core.exitFailure()
else:
print("Grouping with group successfull. Groupcount:" + str(datacontrol.groupCount()))
if (datacontrol.addObjectToGroup(id3,id2)) :
print("Could add an object to an object which is not a Group.")
core.exitFailure();
else:
print("Grouping successfully failed (This is intended!)")
# Get group elements
id1 = primitivesgenerator.addSphere()
id2 = primitivesgenerator.addSphere()
elements = [id1,id2]
groupid = datacontrol.groupObjects(elements)
resultList = datacontrol.getGroupElements(groupid)
if resultList.size != len(elements) :
print("error: getGroupElements")
print("number of received elements is: "+ str(len(elements)) + " expected was: " + str(resultList.size) )
core.exitFailure();
else:
print("Element count correct after grouping")
for i in range(0,len(elements)):
if not elements[i] in resultList:
print("error: getGroupElements")
print("Item not in list!")
print("Element: " + str(elements[i]))
print("List:")
print(resultList)
core.exitFailure();