Ejemplo n.º 1
0
async def add_action_point_orientation_using_robot_cb(
        req: rpc.project.AddActionPointOrientationUsingRobotRequest,
        ui: WsClient) -> None:
    """
    Adds orientation and joints to the action point.
    :param req:
    :return:
    """

    assert glob.SCENE and glob.PROJECT

    ap = glob.PROJECT.action_point(req.args.action_point_id)
    unique_name(req.args.name, ap.orientation_names())

    if req.dry_run:
        return None

    new_pose = await get_end_effector_pose(req.args.robot.robot_id,
                                           req.args.robot.end_effector)

    if ap.parent:
        new_pose = tr.make_pose_rel_to_parent(glob.SCENE, glob.PROJECT,
                                              new_pose, ap.parent)

    orientation = common.NamedOrientation(common.uid(), req.args.name,
                                          new_pose.orientation)
    ap.orientations.append(orientation)

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.OrientationChanged(events.EventType.ADD,
                                      ap.id,
                                      data=orientation)))
    return None
Ejemplo n.º 2
0
async def add_action_cb(req: rpc.project.AddActionRequest,
                        ui: WsClient) -> None:

    assert glob.PROJECT
    assert glob.SCENE

    ap = glob.PROJECT.action_point(req.args.action_point_id)

    unique_name(req.args.name, glob.PROJECT.action_user_names())

    if not hlp.is_valid_identifier(req.args.name):
        raise Arcor2Exception("Action name has to be valid Python identifier.")

    new_action = common.Action(common.uid(), req.args.name, req.args.type,
                               req.args.parameters)

    updated_project = copy.deepcopy(glob.PROJECT)
    updated_ap = updated_project.action_point(req.args.action_point_id)
    updated_ap.actions.append(new_action)

    check_action_params(updated_project, new_action,
                        find_object_action(new_action))

    if req.dry_run:
        return None

    ap.actions.append(new_action)

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.ActionChanged(events.EventType.ADD, ap.id,
                                 data=new_action)))
    return None
Ejemplo n.º 3
0
async def rename_action_point_cb(req: rpc.project.RenameActionPointRequest,
                                 ui: WsClient) -> None:

    assert glob.SCENE and glob.PROJECT

    ap = glob.PROJECT.action_point(req.args.action_point_id)

    if req.args.new_name == ap.name:
        return None

    if not hlp.is_valid_identifier(req.args.new_name):
        raise Arcor2Exception("Name has to be valid Python identifier.")

    unique_name(req.args.new_name, glob.PROJECT.action_points_names)

    if req.dry_run:
        return None

    ap.name = req.args.new_name

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.ActionPointChanged(events.EventType.UPDATE_BASE,
                                      data=ap.bare())))
    return None
Ejemplo n.º 4
0
async def add_action_point_orientation_cb(
        req: rpc.project.AddActionPointOrientationRequest,
        ui: WsClient) -> None:
    """
    Adds orientation and joints to the action point.
    :param req:
    :return:
    """

    assert glob.SCENE and glob.PROJECT

    ap = glob.PROJECT.action_point(req.args.action_point_id)

    unique_name(req.args.name, ap.orientation_names())

    if req.dry_run:
        return None

    orientation = common.NamedOrientation(common.uid(), req.args.name,
                                          req.args.orientation)
    ap.orientations.append(orientation)

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.OrientationChanged(events.EventType.ADD,
                                      ap.id,
                                      data=orientation)))
    return None
Ejemplo n.º 5
0
async def rename_scene_cb(req: rpc.scene.RenameSceneRequest,
                          ui: WsClient) -> None:

    unique_name(req.args.new_name, (await scene_names()))

    if req.dry_run:
        return None

    async with managed_scene(req.args.id) as scene:
        scene.name = req.args.new_name
        asyncio.ensure_future(
            notif.broadcast_event(
                events.SceneChanged(events.EventType.UPDATE_BASE,
                                    data=scene.bare())))
    return None
Ejemplo n.º 6
0
async def copy_project_cb(req: rpc.project.CopyProjectRequest,
                          ui: WsClient) -> None:

    unique_name(req.args.target_name, (await project_names()))

    if req.dry_run:
        return None

    async with managed_project(req.args.source_id, make_copy=True) as project:

        project.name = req.args.target_name
        asyncio.ensure_future(
            notif.broadcast_event(
                events.ProjectChanged(events.EventType.UPDATE_BASE,
                                      data=project.bare())))

    return None
Ejemplo n.º 7
0
async def rename_project_cb(req: rpc.project.RenameProjectRequest,
                            ui: WsClient) -> None:

    unique_name(req.args.new_name, (await project_names()))

    if req.dry_run:
        return None

    async with managed_project(req.args.project_id) as project:

        project.name = req.args.new_name
        project.update_modified()

        asyncio.ensure_future(
            notif.broadcast_event(
                events.ProjectChanged(events.EventType.UPDATE_BASE,
                                      data=project.bare())))
    return None
Ejemplo n.º 8
0
async def rename_action_point_orientation_cb(req: rpc.project.RenameActionPointOrientationRequest, ui: WsClient) -> \
        None:

    assert glob.PROJECT

    ap, ori = glob.PROJECT.ap_and_orientation(req.args.orientation_id)
    unique_name(req.args.new_name, ap.orientation_names())

    if req.dry_run:
        return None

    ori.name = req.args.new_name
    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.OrientationChanged(events.EventType.UPDATE_BASE, data=ori)))

    return None
Ejemplo n.º 9
0
async def rename_action_point_joints_cb(
        req: rpc.project.RenameActionPointJointsRequest, ui: WsClient) -> None:

    assert glob.PROJECT

    ap, joints = glob.PROJECT.ap_and_joints(req.args.joints_id)
    unique_name(req.args.new_name, ap.joints_names())

    if req.dry_run:
        return None

    joints.name = req.args.new_name
    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.JointsChanged(events.EventType.UPDATE_BASE, data=joints)))

    return None
Ejemplo n.º 10
0
async def new_project_cb(req: rpc.project.NewProjectRequest,
                         ui: WsClient) -> None:

    if glob.PACKAGE_STATE.state in (common.PackageStateEnum.PAUSED,
                                    common.PackageStateEnum.RUNNING):
        raise Arcor2Exception("Can't create project while package runs.")

    unique_name(req.args.name, (await project_names()))

    if req.dry_run:
        return None

    if glob.SCENE:
        if glob.SCENE.id != req.args.scene_id:
            raise Arcor2Exception("Another scene is opened.")

        if glob.SCENE.has_changes():
            await storage.update_scene(glob.SCENE)
            glob.SCENE.modified = (await
                                   storage.get_scene(glob.SCENE.id)).modified

    else:

        if req.args.scene_id not in {
                scene.id
                for scene in (await storage.get_scenes()).items
        }:
            raise Arcor2Exception("Unknown scene id.")

        await open_scene(req.args.scene_id)

    glob.PROJECT = common.Project(common.uid(),
                                  req.args.name,
                                  req.args.scene_id,
                                  desc=req.args.desc,
                                  has_logic=req.args.has_logic)

    assert glob.SCENE

    asyncio.ensure_future(
        notif.broadcast_event(
            events.OpenProject(
                data=events.OpenProjectData(glob.SCENE, glob.PROJECT))))
    return None
Ejemplo n.º 11
0
async def rename_action_cb(req: rpc.project.RenameActionRequest,
                           ui: WsClient) -> None:

    assert glob.PROJECT

    unique_name(req.args.new_name, glob.PROJECT.action_user_names())

    if req.dry_run:
        return None

    act = glob.PROJECT.action(req.args.action_id)
    act.name = req.args.new_name

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.ActionChanged(events.EventType.UPDATE_BASE, data=act)))

    return None
Ejemplo n.º 12
0
async def add_action_point_joints_cb(
        req: rpc.project.AddActionPointJointsRequest, ui: WsClient) -> None:

    assert glob.SCENE and glob.PROJECT

    ap = glob.PROJECT.action_point(req.args.action_point_id)

    unique_name(req.args.name, ap.joints_names())

    if req.dry_run:
        return None

    new_joints = await get_robot_joints(req.args.robot_id)

    prj = common.ProjectRobotJoints(common.uid(), req.args.name,
                                    req.args.robot_id, new_joints, True)
    ap.robot_joints.append(prj)
    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.JointsChanged(events.EventType.ADD, ap.id, data=prj)))
    return None
Ejemplo n.º 13
0
async def add_action_point_cb(req: rpc.project.AddActionPointRequest,
                              ui: WsClient) -> None:

    assert glob.SCENE
    assert glob.PROJECT

    unique_name(req.args.name, glob.PROJECT.action_points_names)
    check_ap_parent(req.args.parent)

    if not hlp.is_valid_identifier(req.args.name):
        raise Arcor2Exception("Name has to be valid Python identifier.")

    if req.dry_run:
        return None

    ap = common.ProjectActionPoint(common.uid(), req.args.name,
                                   req.args.position, req.args.parent)
    glob.PROJECT.action_points.append(ap)

    glob.PROJECT.update_modified()
    asyncio.ensure_future(
        notif.broadcast_event(
            events.ActionPointChanged(events.EventType.ADD, data=ap)))
    return None