Example #1
0
    def upsert_action_point(
        self, ap_id: str, name: str, position: cmn.Position, parent: Optional[str] = None
    ) -> cmn.BareActionPoint:

        try:
            ap = self.bare_action_point(ap_id)
            ap.name = name
            if position != ap.position:
                self.invalidate_joints(ap_id)
            ap.position = position
            ap.parent = parent
        except CachedProjectException:
            ap = cmn.BareActionPoint(name, position, parent, id=ap_id)
            self._action_points[ap_id] = ap
        self._upsert_child(parent, ap_id)
        self.update_modified()
        return ap
Example #2
0
    def __init__(self, project: Union[cmn.Project, CachedProject]):

        super().__init__(project)

        self.scene_id: str = project.scene_id
        self.has_logic: bool = project.has_logic
        self.project_objects_ids: Optional[list[str]] = project.project_objects_ids

        self._action_points: dict[str, cmn.BareActionPoint] = {}

        self._actions: dict[str, ApAction] = {}
        self._joints: dict[str, ApJoints] = {}
        self._orientations: dict[str, ApOrientation] = {}

        self._parameters: dict[str, cmn.ProjectParameter] = {}
        self._logic_items: dict[str, cmn.LogicItem] = {}
        self._functions: dict[str, cmn.ProjectFunction] = {}

        self.overrides: dict[str, list[cmn.Parameter]] = {}

        self._childs: dict[str, set[str]] = {}

        if isinstance(project, CachedProject):
            self._action_points = project._action_points
            self._actions = project._actions
            self._joints = project._joints
            self._orientations = project._orientations
            self._parameters = project._parameters
            self._logic_items = project._logic_items
            self._functions = project._functions
            self.overrides = project.overrides
            self._childs = project._childs

        else:

            for ap in project.action_points:

                if ap.id in self._action_points:
                    raise CachedProjectException(f"Duplicate AP id: {ap.id}.")

                bare_ap = cmn.BareActionPoint(ap.name, ap.position, ap.parent, id=ap.id)
                self._action_points[ap.id] = bare_ap
                self._upsert_child(ap.parent, ap.id)

                for ac in ap.actions:

                    if ac.id in self._actions:
                        raise CachedProjectException(f"Duplicate action id: {ac.id}.")

                    self._actions[ac.id] = ApAction(bare_ap, ac)
                    self._upsert_child(ap.id, ac.id)

                for joints in ap.robot_joints:

                    if joints.id in self._joints:
                        raise CachedProjectException(f"Duplicate joints id: {joints.id}.")

                    self._joints[joints.id] = ApJoints(bare_ap, joints)
                    self._upsert_child(ap.id, joints.id)

                for orientation in ap.orientations:

                    if orientation.id in self._orientations:
                        raise CachedProjectException(f"Duplicate orientation id: {orientation.id}.")

                    self._orientations[orientation.id] = ApOrientation(bare_ap, orientation)
                    self._upsert_child(ap.id, orientation.id)

            for override in project.object_overrides:
                self.overrides[override.id] = override.parameters

            for param in project.parameters:
                self._parameters[param.id] = param

            for logic_item in project.logic:
                self._logic_items[logic_item.id] = logic_item

            for function in project.functions:
                self._functions[function.id] = function
Example #3
0
    def __init__(self, project: cmn.Project):

        self.id: str = project.id
        self.name: str = project.name
        self.scene_id: str = project.scene_id
        self.desc: str = project.desc
        self.has_logic: bool = project.has_logic
        self.modified: Optional[datetime] = project.modified
        self._int_modified: Optional[datetime] = project.int_modified

        self._action_points: Dict[str, cmn.BareActionPoint] = {}

        self._actions = Actions()
        self._joints = Joints()
        self._orientations = Orientations()

        self._constants: Dict[str, cmn.ProjectConstant] = {}
        self._logic_items: Dict[str, cmn.LogicItem] = {}
        self._functions: Dict[str, cmn.ProjectFunction] = {}

        self.overrides: Dict[str, List[cmn.Parameter]] = {}

        for ap in project.action_points:

            if ap.id in self._action_points:
                raise CachedProjectException(f"Duplicate AP id: {ap.id}.")

            bare_ap = cmn.BareActionPoint(ap.name,
                                          ap.position,
                                          ap.parent,
                                          id=ap.id)
            self._action_points[ap.id] = bare_ap

            for ac in ap.actions:

                if ac.id in self._actions.data:
                    raise CachedProjectException(
                        f"Duplicate action id: {ac.id}.")

                self._actions.data[ac.id] = ac
                self._actions.parent[ac.id] = bare_ap

            for joints in ap.robot_joints:

                if joints.id in self._joints.data:
                    raise CachedProjectException(
                        f"Duplicate joints id: {joints.id}.")

                self._joints.data[joints.id] = joints
                self._joints.parent[joints.id] = bare_ap

            for orientation in ap.orientations:

                if orientation.id in self._orientations.data:
                    raise CachedProjectException(
                        f"Duplicate orientation id: {orientation.id}.")

                self._orientations.data[orientation.id] = orientation
                self._orientations.parent[orientation.id] = bare_ap

        for override in project.object_overrides:
            self.overrides[override.id] = override.parameters

        for constant in project.constants:
            self._constants[constant.id] = constant

        for logic_item in project.logic:
            self._logic_items[logic_item.id] = logic_item

        for function in project.functions:
            self._functions[function.id] = function