def to_type(handle: int) -> Object: """Converts an object handle to the correct sub-type. :param handle: The internal handle of an object. :return: The sub-type of this object. """ t = sim.simGetObjectType(handle) if t == sim.sim_object_shape_type: return Shape(handle) elif t == sim.sim_object_dummy_type: return Dummy(handle) elif t == sim.sim_object_path_type: return CartesianPath(handle) elif t == sim.sim_object_joint_type: return Joint(handle) elif t == sim.sim_object_visionsensor_type: return VisionSensor(handle) elif t == sim.sim_object_forcesensor_type: return ForceSensor(handle) elif t == sim.sim_object_proximitysensor_type: return ProximitySensor(handle) elif t == sim.sim_object_camera_type: return Camera(handle) elif t == sim.sim_object_octree_type: return Octree(handle) raise ValueError
def get_objects_in_tree(self, object_type=ObjectType.ALL, exclude_base=True, first_generation_only=False) -> List['Object']: """Retrieves the objects in a given hierarchy tree. :param object_type: The object type to retrieve. One of :py:class:`.ObjectType`. :param exclude_base: Exclude the tree base from the returned list. :param first_generation_only: Include in the returned list only the object's first children. Otherwise, entire hierarchy is returned. :return: A list of objects in the hierarchy tree. """ options = 0 if exclude_base: options |= 1 if first_generation_only: options |= 2 handles = sim.simGetObjectsInTree(self._handle, object_type.value, options) objects = [] for h in handles: object_type = ObjectType(sim.simGetObjectType(h)) cls = object_type_to_class.get(object_type, Object) objects.append(cls(h)) return objects
def _create_object(self, name): """Creates pyrep object for the correct type""" # TODO implement other types handle = sim.simGetObjectHandle(name) o_type = sim.simGetObjectType(handle) if ObjectType(o_type) == ObjectType.JOINT: return Joint(handle) elif ObjectType(o_type) == ObjectType.SHAPE: return Shape(handle) else: return None
def __init__(self, name_or_handle: Union[str, int]): if isinstance(name_or_handle, int): self._handle = name_or_handle else: self._handle = sim.simGetObjectHandle(name_or_handle) assert_type = self._get_requested_type() actual = ObjectType(sim.simGetObjectType(self._handle)) if actual != assert_type: raise WrongObjectTypeError( 'You requested object of type %s, but the actual type was ' '%s' % (assert_type.name, actual.name))
def get_parent(self) -> Union['Object', None]: """Gets the parent of this object in the scene hierarchy. :return: The parent of this object, or None if it doesn't have a parent. """ try: handle = sim.simGetObjectParent(self._handle) except RuntimeError: # Most probably no parent. return None object_type = ObjectType(sim.simGetObjectType(handle)) cls = object_type_to_class.get(object_type, Object) return cls(handle)
def _get_requested_type(self) -> ObjectType: return ObjectType(sim.simGetObjectType(self.get_handle()))
def _get_requested_type(self) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(sim.simGetObjectType(self.get_handle()))
def get_type(self) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(sim.simGetObjectType(self._handle))
def get_object_type(name: str) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(sim.simGetObjectType(sim.simGetObjectHandle(name)))