async def update_action_logic_cb(req: rpc.project.UpdateActionLogicRequest, ui: WsClient) -> None: assert glob.PROJECT assert glob.SCENE action = glob.PROJECT.action(req.args.action_id) allowed_values = glob.PROJECT.action_ids() | common.ActionIOEnum.set() | { "" } for inp in req.args.inputs: if inp.default not in allowed_values: raise Arcor2Exception("Unknown input value.") for out in req.args.outputs: if out.default not in allowed_values: raise Arcor2Exception("Unknown output value.") action.inputs = req.args.inputs action.outputs = req.args.outputs glob.PROJECT.update_modified() asyncio.ensure_future( notif.broadcast_event( events.ActionChanged(events.EventType.UPDATE, data=action))) return None
async def update_action_cb(req: rpc.project.UpdateActionRequest, ui: WsClient) -> None: assert glob.PROJECT assert glob.SCENE updated_project = copy.deepcopy(glob.PROJECT) updated_action = updated_project.action(req.args.action_id) updated_action.parameters = req.args.parameters check_action_params(updated_project, updated_action, find_object_action(updated_action)) if req.dry_run: return None orig_action = glob.PROJECT.action(req.args.action_id) orig_action.parameters = updated_action.parameters glob.PROJECT.update_modified() asyncio.ensure_future( notif.broadcast_event( events.ActionChanged(events.EventType.UPDATE, data=updated_action))) return None
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
async def remove_action_cb(req: rpc.project.RemoveActionRequest, ui: WsClient) -> None: assert glob.PROJECT assert glob.SCENE ap, action = glob.PROJECT.action_point_and_action(req.args.id) check_action_usage(action) if req.dry_run: return None ap.actions = [act for act in ap.actions if act.id != req.args.id] glob.PROJECT.update_modified() asyncio.ensure_future( notif.broadcast_event( events.ActionChanged(events.EventType.REMOVE, data=action.bare()))) return None
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
async def update_project_has_logic_cb( req: rpc.project.UpdateProjectHasLogicRequest, ui: WsClient) -> None: async with managed_project(req.args.project_id) as project: if project.has_logic and not req.args.new_has_logic: for act in project.actions(): act.inputs.clear() act.outputs.clear() if glob.PROJECT and glob.PROJECT.id == req.args.project_id: asyncio.ensure_future( notif.broadcast_event( events.ActionChanged(events.EventType.UPDATE, data=act))) project.has_logic = req.args.new_has_logic project.update_modified() asyncio.ensure_future( notif.broadcast_event( events.ProjectChanged(events.EventType.UPDATE_BASE, data=project.bare()))) return None