Пример #1
0
def test_invalid_receive():
    client = SpeckleClient()
    client.account = Account(token="fake_token")
    transport = ServerTransport("fake stream", client)

    with pytest.raises(SpeckleException):
        operations.receive("fake object", transport)
Пример #2
0
def processItem(item):
    client, stream, branch, commit = item
    transport = ServerTransport(stream.id, client)
    stream_data = operations.receive(commit.referencedObject, transport)
    host_name = client.url[8:]
    dynamic_member_names = stream_data.get_dynamic_member_names()
    returnObjects = []
    for i, dynamic_member_name in enumerate(dynamic_member_names):
        obj_collection = stream_data[dynamic_member_name]
        temp_objects = []
        if len(obj_collection) > 0:
            for j, obj in enumerate(obj_collection):
                object_name = host_name + "_" + stream.id + "_" + branch.id + "_" + commit.id + "_" + dynamic_member_name + "_" + str(
                    j + 1)
                try:
                    speckle_mesh = getattr(obj, 'displayValue')[0]
                    units = getattr(obj, "units", None)
                    if units:
                        scale = get_scale_length(
                            units
                        ) / bpy.context.scene.unit_settings.scale_length
                    else:
                        scale = 1.0
                    blender_mesh = mesh_to_native(speckle_mesh,
                                                  name=object_name,
                                                  scale=scale)
                except:
                    blender_mesh = bpy.data.meshes.new(name=object_name)
                    bm = bmesh.new()
                    bm.verts.new((0.0, 0.0, 0.0))
                    bm.to_mesh(blender_mesh)
                    bm.free()
                new_object = bpy.data.objects.new(object_name, blender_mesh)
                member_names = obj.get_member_names()
                for member_name in member_names:
                    attribute = getattr(obj, member_name)
                    if isinstance(attribute, float) or isinstance(
                            attribute, int) or isinstance(attribute, str):
                        new_object[member_name] = attribute
                #temp_objects.append(new_object)
                item = [
                    new_object, new_object.matrix_world, None, obj.id,
                    object_name
                ]
                top_object1 = TopologyByGeometry.processItem(
                    item, 0.001, "Default")
                top_object2 = TopologySelfMerge.processItem(top_object1)
                d = DictionarySetValueAtKey.processItem(
                    top_object1.GetDictionary(), "TOPOLOGIC_type",
                    top_object2.GetTypeAsString())
                d = DictionarySetValueAtKey.processItem(
                    d, "TOPOLOGIC_length_unit",
                    bpy.context.scene.unit_settings.length_unit)
                top_object2.SetDictionary(d)
                temp_objects.append(top_object2)
            returnObjects.append(temp_objects)
    return returnObjects
Пример #3
0
    def test_send_and_receive(self, client, sample_stream, mesh):
        transport = ServerTransport(client=client, stream_id=sample_stream.id)
        hash = operations.send(mesh, transports=[transport])
        # use a fresh memory transport to force receiving from remote
        received = operations.receive(
            hash, remote_transport=transport, local_transport=MemoryTransport()
        )

        assert isinstance(received, FakeMesh)
        assert received.vertices == mesh.vertices
        assert isinstance(received.origin, Point)
        assert received.origin.value == mesh.origin.value
        # not comparing hashes as order is not guaranteed back from server

        mesh.id = hash  # populate with decomposed id for use in proceeding tests
def processItem(item):
	client, stream = item
	transport = ServerTransport(client=client, stream_id=stream.id)

	# get the `globals` branch
	branch = client.branch.get(stream.id, "globals")

	# get the latest commit
	if len(branch.commits.items) > 0:
		latest_commit = branch.commits.items[0]

		# receive the globals object
		globs = operations.receive(latest_commit.referencedObject, transport)
		return processBase(globs)
	return None
Пример #5
0
def runItem(item):
    resetItem(item)
    client, stream, branch, commit = item
    transport = ServerTransport(stream.id, client)
    stream_data = operations.receive(commit.referencedObject, transport)
    host_name = client.url[8:]
    client_collection = addCollectionIfNew("Host " + host_name)
    stream_collection = addCollectionIfNew("Stream " + stream.id)
    branch_collection = addCollectionIfNew("Branch " + branch.id)
    commit_collection = addCollectionIfNew("Commit " + commit.id)
    dynamic_member_names = stream_data.get_dynamic_member_names()
    returnObjects = []
    for i, dynamic_member_name in enumerate(dynamic_member_names):
        obj_collection = stream_data[dynamic_member_name]
        if len(obj_collection) > 0:
            object_collection = addCollectionIfNew(host_name + "_" +
                                                   stream.id + "_" +
                                                   branch.id + "_" +
                                                   commit.id + "_" +
                                                   dynamic_member_name)
            for j, obj in enumerate(obj_collection):
                object_name = host_name + "_" + stream.id + "_" + branch.id + "_" + commit.id + "_" + dynamic_member_name + "_" + str(
                    j + 1)
                try:
                    speckle_mesh = getattr(obj, 'displayValue')[0]
                    blender_mesh = mesh_to_native(speckle_mesh, object_name)
                except:
                    blender_mesh = bpy.data.meshes.new(name=object_name)
                    bm = bmesh.new()
                    bm.verts.new((0.0, 0.0, 0.0))
                    bm.to_mesh(blender_mesh)
                    bm.free()

                # Delete any pre-existing object with the same name
                try:
                    object_to_delete = bpy.data.objects[object_name]
                    bpy.data.objects.remove(object_to_delete, do_unlink=True)
                except:
                    pass
                new_object = bpy.data.objects.new(object_name, blender_mesh)
                member_names = obj.get_member_names()
                for member_name in member_names:
                    attribute = getattr(obj, member_name)
                    if isinstance(attribute, float) or isinstance(
                            attribute, int) or isinstance(attribute, str):
                        new_object[member_name] = attribute
                object_collection.objects.link(new_object)
                returnObjects.append(new_object)
            try:
                commit_collection.children.link(object_collection)
            except:
                pass
    try:
        branch_collection.children.link(commit_collection)
    except:
        pass
    try:
        stream_collection.children.link(branch_collection)
    except:
        pass
    try:
        client_collection.children.link(stream_collection)
    except:
        pass
    try:
        bpy.context.scene.collection.children.link(client_collection)
    except:
        pass
    return returnObjects
Пример #6
0
    def test_receive_local(self, client, mesh):
        hash = operations.send(mesh)  # defaults to SQLiteTransport
        received = operations.receive(hash)

        assert isinstance(received, Base)
        assert mesh.get_id() == received.get_id()