コード例 #1
0
async def rename_action_point_cb(req: srpc.p.RenameActionPoint.Request,
                                 ui: WsClient) -> None:

    assert glob.SCENE
    assert glob.PROJECT

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

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

    hlp.is_valid_identifier(req.args.new_name)
    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()

    evt = sevts.p.ActionPointChanged(ap)
    evt.change_type = Event.Type.UPDATE_BASE
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #2
0
async def add_action_point_orientation_cb(
        req: srpc.p.AddActionPointOrientation.Request, ui: WsClient) -> None:
    """Adds orientation and joints to the action point.

    :param req:
    :return:
    """

    assert glob.SCENE
    assert glob.PROJECT

    ap = glob.PROJECT.bare_action_point(req.args.action_point_id)
    hlp.is_valid_identifier(req.args.name)
    unique_name(req.args.name, glob.PROJECT.ap_orientation_names(ap.id))

    if req.dry_run:
        return None

    orientation = common.NamedOrientation(req.args.name, req.args.orientation)
    glob.PROJECT.upsert_orientation(ap.id, orientation)

    evt = sevts.p.OrientationChanged(orientation)
    evt.change_type = Event.Type.ADD
    evt.parent_id = ap.id
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #3
0
async def add_action_cb(req: srpc.p.AddAction.Request, ui: WsClient) -> None:

    assert glob.PROJECT
    assert glob.SCENE

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

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

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

    action_meta = find_object_action(glob.SCENE, new_action)

    updated_project = copy.deepcopy(glob.PROJECT)
    updated_project.upsert_action(req.args.action_point_id, new_action)

    check_flows(updated_project, new_action, action_meta)
    check_action_params(glob.SCENE, updated_project, new_action, action_meta)

    if req.dry_run:
        return None

    glob.PROJECT.upsert_action(ap.id, new_action)

    evt = sevts.p.ActionChanged(new_action)
    evt.change_type = Event.Type.ADD
    evt.parent_id = ap.id
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #4
0
async def add_action_point_joints_using_robot_cb(
        req: srpc.p.AddActionPointJointsUsingRobot.Request,
        ui: WsClient) -> None:

    ensure_scene_started()

    assert glob.SCENE
    assert glob.PROJECT

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

    hlp.is_valid_identifier(req.args.name)
    unique_name(req.args.name, glob.PROJECT.ap_joint_names(ap.id))

    new_joints = await get_robot_joints(req.args.robot_id)

    if req.dry_run:
        return None

    prj = common.ProjectRobotJoints(req.args.name, req.args.robot_id,
                                    new_joints, True)
    glob.PROJECT.upsert_joints(ap.id, prj)

    evt = sevts.p.JointsChanged(prj)
    evt.change_type = Event.Type.ADD
    evt.parent_id = ap.id
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #5
0
ファイル: scene.py プロジェクト: Croolman/arcor2
async def rename_scene_cb(req: srpc.s.RenameScene.Request,
                          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

        evt = sevts.s.SceneChanged(scene.bare)
        evt.change_type = Event.Type.UPDATE_BASE
        asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #6
0
async def copy_project_cb(req: srpc.p.CopyProject.Request,
                          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

        evt = sevts.p.ProjectChanged(project.bare)
        evt.change_type = Event.Type.UPDATE_BASE
        asyncio.ensure_future(notif.broadcast_event(evt))

    return None
コード例 #7
0
async def rename_project_cb(req: srpc.p.RenameProject.Request,
                            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()

        evt = sevts.p.ProjectChanged(project.bare)
        evt.change_type = Event.Type.UPDATE_BASE
        asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #8
0
async def rename_scene_cb(req: srpc.s.RenameScene.Request,
                          ui: WsClient) -> None:

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

    user_name = glob.USERS.user_name(ui)
    await ensure_locked(req.args.id, ui)

    if req.dry_run:
        return None

    async with managed_scene(req.args.id) as scene:
        scene.name = req.args.new_name

        evt = sevts.s.SceneChanged(scene.bare)
        evt.change_type = Event.Type.UPDATE_BASE
        asyncio.ensure_future(notif.broadcast_event(evt))

    asyncio.create_task(glob.LOCK.write_unlock(req.args.id, user_name, True))
    return None
コード例 #9
0
async def rename_action_cb(req: srpc.p.RenameAction.Request,
                           ui: WsClient) -> None:

    assert glob.PROJECT

    unique_name(req.args.new_name, glob.PROJECT.action_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()

    evt = sevts.p.ActionChanged(act)
    evt.change_type = Event.Type.UPDATE_BASE
    asyncio.ensure_future(notif.broadcast_event(evt))

    return None
コード例 #10
0
async def rename_action_point_joints_cb(
        req: srpc.p.RenameActionPointJoints.Request, ui: WsClient) -> None:

    assert glob.PROJECT

    ap, joints = glob.PROJECT.ap_and_joints(req.args.joints_id)
    hlp.is_valid_identifier(req.args.new_name)
    unique_name(req.args.new_name, glob.PROJECT.ap_joint_names(ap.id))

    if req.dry_run:
        return None

    joints.name = req.args.new_name
    glob.PROJECT.update_modified()

    evt = sevts.p.JointsChanged(joints)
    evt.change_type = Event.Type.UPDATE_BASE
    asyncio.ensure_future(notif.broadcast_event(evt))

    return None
コード例 #11
0
async def new_project_cb(req: srpc.p.NewProject.Request, ui: WsClient) -> None:

    if glob.PACKAGE_STATE.state in PackageState.RUN_STATES:
        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():
            glob.SCENE.modified = await storage.update_scene(glob.SCENE.scene)
    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)

    project.PREV_RESULTS.clear()
    glob.PROJECT = UpdateableCachedProject(
        common.Project(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(
            sevts.p.OpenProject(
                sevts.p.OpenProject.Data(glob.SCENE.scene,
                                         glob.PROJECT.project))))
    return None
コード例 #12
0
async def add_action_point_cb(req: srpc.p.AddActionPoint.Request,
                              ui: WsClient) -> None:

    assert glob.SCENE
    assert glob.PROJECT

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

    if req.dry_run:
        return None

    ap = glob.PROJECT.upsert_action_point(common.ActionPoint.uid(),
                                          req.args.name, req.args.position,
                                          req.args.parent)

    evt = sevts.p.ActionPointChanged(ap)
    evt.change_type = Event.Type.ADD
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None
コード例 #13
0
async def rename_action_point_orientation_cb(
        req: srpc.p.RenameActionPointOrientation.Request,
        ui: WsClient) -> None:

    assert glob.PROJECT

    ap, ori = glob.PROJECT.bare_ap_and_orientation(req.args.orientation_id)
    hlp.is_valid_identifier(req.args.new_name)
    unique_name(req.args.new_name, glob.PROJECT.ap_orientation_names(ap.id))

    if req.dry_run:
        return None

    ori.name = req.args.new_name
    glob.PROJECT.update_modified()

    evt = sevts.p.OrientationChanged(ori)
    evt.change_type = Event.Type.UPDATE_BASE
    asyncio.ensure_future(notif.broadcast_event(evt))

    return None
コード例 #14
0
async def add_action_point_orientation_using_robot_cb(
        req: srpc.p.AddActionPointOrientationUsingRobot.Request,
        ui: WsClient) -> None:
    """Adds orientation and joints to the action point.

    :param req:
    :return:
    """

    ensure_scene_started()

    assert glob.SCENE
    assert glob.PROJECT

    ap = glob.PROJECT.bare_action_point(req.args.action_point_id)
    hlp.is_valid_identifier(req.args.name)
    unique_name(req.args.name, glob.PROJECT.ap_orientation_names(ap.id))

    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(req.args.name, new_pose.orientation)
    glob.PROJECT.upsert_orientation(ap.id, orientation)

    evt = sevts.p.OrientationChanged(orientation)
    evt.change_type = Event.Type.ADD
    evt.parent_id = ap.id
    asyncio.ensure_future(notif.broadcast_event(evt))
    return None