コード例 #1
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project, action_id: str, parameter_id: str) \
            -> List[Any]:

        val = super(ListParameterPlugin, cls).value(type_defs, scene, project,
                                                    action_id, parameter_id)

        if not isinstance(val, list):
            raise ParameterPluginException("Not a list!")
        if val and not isinstance(val[0], cls.type()):
            raise ParameterPluginException(
                "List content does not have expected type!")

        return val
コード例 #2
0
ファイル: relative_pose.py プロジェクト: robofit/arcor2
    def parameter_value(
        cls, type_defs: TypesDict, scene: CScene, project: CProject, action_id: str, parameter_id: str
    ) -> RelativePose:

        try:
            return RelativePose.from_json(project.action(action_id).parameter(parameter_id).value)
        except ValidationError as e:
            raise ParameterPluginException(e)
コード例 #3
0
    def _param_value_list(cls, param: ActionParameter) -> List[str]:

        lst = json.loads(param.value)

        if not isinstance(lst, list):
            raise ParameterPluginException(
                "Parameter value should be list of references to action points."
            )

        return lst
コード例 #4
0
ファイル: joints.py プロジェクト: robofit/arcor2
    def parameter_value(cls, type_defs: TypesDict, scene: CScene,
                        project: CProject, action_id: str,
                        parameter_id: str) -> ProjectRobotJoints:

        try:
            ap, action = project.action_point_and_action(action_id)
            param = action.parameter(parameter_id)
            joints_id = cls._id_from_value(param.value)

            robot_id, action_method_name = action.parse_type()

            joints = project.joints(joints_id)
        except Arcor2Exception as e:
            raise ParameterPluginException(
                "Failed to get necessary data from project.") from e

        if joints.robot_id != robot_id:
            raise ParameterPluginException("Joints are for different robot.")

        return joints
コード例 #5
0
ファイル: integer_enum.py プロジェクト: Croolman/arcor2
    def meta(cls, param_meta: ParameterMeta, action_method: Callable,
             action_node: ast.FunctionDef) -> None:
        super(IntegerEnumPlugin, cls).meta(param_meta, action_method,
                                           action_node)

        ttype = get_type_hints(action_method)[param_meta.name]
        if not issubclass(ttype, cls.type()):
            raise ParameterPluginException(
                f"Type {ttype.__name__} is not subclass of {cls.type().__name__}."
            )

        param_meta.extra = IntegerEnumExtra(ttype.set()).to_json()
コード例 #6
0
ファイル: integer_enum.py プロジェクト: Croolman/arcor2
    def parameter_value(cls, type_defs: TypesDict, scene: CScene,
                        project: CProject, action_id: str,
                        parameter_id: str) -> Enum:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        obj_id, action_type = action.parse_type()
        obj_type_name = scene.object(obj_id).type
        try:
            obj_type = type_defs[obj_type_name]
        except KeyError:
            raise ParameterPluginException(
                f"Unknown object type {obj_type_name}.")

        try:
            method = getattr(obj_type, action_type)
        except AttributeError:
            raise ParameterPluginException(
                f"Object type {obj_type_name} does not have method {action_type}."
            )

        try:
            ttype = get_type_hints(method)[param.name]
        except KeyError:
            raise ParameterPluginException(
                f"Method {obj_type}/{method.__name__} does not have parameter {param.name}."
            )

        if not issubclass(ttype, cls.type()):
            raise ParameterPluginException(
                f"Type {ttype.__name__} is not subclass of {cls.type().__name__}."
            )

        try:
            return ttype(json.loads(param.value))
        except ValueError:
            raise ParameterPluginException(
                f"Parameter {parameter_id} of action {action.name} has invalid value."
            )
コード例 #7
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project,
              action_id: str, parameter_id: str) -> Enum:

        action = project.action(action_id)
        param = action.parameter(parameter_id)
        obj_id, action_type = action.parse_type()
        obj_type = type_defs[scene.object_or_service(obj_id).type]

        method = getattr(obj_type, action_type)
        ttype = get_type_hints(method)[param.id]

        if not issubclass(ttype, cls.type()):
            raise ParameterPluginException(
                f"Type {ttype.__name__} is not subclass of {cls.type().__name__}."
            )

        try:
            return ttype(json.loads(param.value))
        except ValueError:
            raise ParameterPluginException(
                f"Parameter {parameter_id} of action {action.name} has invalid value."
            )
コード例 #8
0
def get_min_max(cls: Type[ParameterPlugin], param_meta: ActionParameterMeta,
                action_method: Callable, action_node: ast.FunctionDef) -> None:

    try:
        minimum, maximum = get_assert_minimum_maximum(
            find_asserts(action_node), param_meta.name)
    except AssertNotFound:
        return

    for var in minimum, maximum:
        if not isinstance(var, cls.type()):
            raise ParameterPluginException(
                "Parameter bounds has incorrect type.")

    param_meta.extra = IntegerParameterExtra(minimum, maximum).to_json()
コード例 #9
0
ファイル: integer_enum.py プロジェクト: Croolman/arcor2
    def need_to_be_imported(cls, type_defs: TypesDict, scene: CScene,
                            project: CProject, action_id: str,
                            parameter_id: str) -> Optional[List[ImportTuple]]:

        enum_cls = cls.parameter_value(type_defs, scene, project, action_id,
                                       parameter_id).__class__
        # TODO does this work as expected in all cases?
        module = inspect.getmodule(enum_cls)
        if not module:
            raise ParameterPluginException("Failed to get the module.")

        # TODO enums are typically defined in the same module as a object type but could be def. elsewhere (arcor2.data)
        return [
            ImportTuple(f"object_types.{module.__name__.split('.')[-1]}",
                        enum_cls.__name__)
        ]
コード例 #10
0
    def value(cls, type_defs: TypesDict, scene: Scene, project: Project, action_id: str, parameter_id: str) -> \
            ProjectRobotJoints:

        ap, action = project.action_point_and_action(action_id)
        param = action.parameter(parameter_id)
        joints_id = cls.param_value(param)

        robot_id, action_method_name = action.parse_type()
        robot_type = scene.object_or_service(robot_id)

        if issubclass(type_defs[robot_type.type], RobotService):

            for param in action.parameters:
                if param.id == "robot_id":
                    robot_id = json.loads(param.value)
                    break
            else:
                raise ParameterPluginException(
                    f"Parameter {param.id} of action {action.id} depends on"
                    f" 'robot_id' parameter, which could not be found.")

        return ap.joints_for_robot(robot_id, joints_id)