def __init__(self, name_or_handle: Union[str, int]): if isinstance(name_or_handle, int): self._handle = name_or_handle else: self._handle = vrep.simGetObjectHandle(name_or_handle) assert_type = self._get_requested_type() actual = ObjectType(vrep.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 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 = vrep.simGetObjectType(handle) if t == vrep.sim_object_shape_type: return Shape(handle) elif t == vrep.sim_object_dummy_type: return Dummy(handle) elif t == vrep.sim_object_path_type: return CartesianPath(handle) elif t == vrep.sim_object_joint_type: return Joint(handle) elif t == vrep.sim_object_visionsensor_type: return VisionSensor(handle) elif t == vrep.sim_object_forcesensor_type: return ForceSensor(handle) elif t == vrep.sim_object_proximitysensor_type: return ProximitySensor(handle)
def _get_requested_type(self) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(vrep.simGetObjectType(self.get_handle()))
def get_type(self) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(vrep.simGetObjectType(self._handle))
def get_object_type(name: str) -> ObjectType: """Gets the type of the object. :return: Type of the object. """ return ObjectType(vrep.simGetObjectType(vrep.simGetObjectHandle(name)))