def check_object(scene: CachedScene, obj: SceneObject, new_one: bool = False) -> None: """Checks if object can be added into the scene.""" assert not obj.children if obj.type not in glob.OBJECT_TYPES: raise Arcor2Exception("Unknown object type.") obj_type = glob.OBJECT_TYPES[obj.type] if obj_type.meta.disabled: raise Arcor2Exception("Object type disabled.") check_object_parameters(obj_type, obj.parameters) # TODO check whether object needs parent and if so, if the parent is in scene and parent_id is set if obj_type.meta.needs_parent_type: pass if obj_type.meta.has_pose and obj.pose is None: raise Arcor2Exception("Object requires pose.") if not obj_type.meta.has_pose and obj.pose is not None: raise Arcor2Exception("Object do not have pose.") if obj_type.meta.abstract: raise Arcor2Exception("Cannot instantiate abstract type.") if new_one: if obj.id in scene.object_ids: raise Arcor2Exception( "Object/service with that id already exists.") if obj.name in scene.object_names(): raise Arcor2Exception("Name is already used.") hlp.is_valid_identifier(obj.name)
def check_object(obj_types: ObjectTypeDict, scene: CachedScene, obj: SceneObject, new_one: bool = False) -> None: """Checks if object can be added into the scene.""" assert not obj.children if obj.type not in obj_types: raise Arcor2Exception(f"Unknown ObjectType {obj.type}.") obj_type = obj_types[obj.type] if obj_type.meta.disabled: raise Arcor2Exception(f"ObjectType {obj.type} is disabled. {obj_type.meta.problem}") check_object_parameters(obj_type, obj.parameters) # TODO check whether object needs parent and if so, if the parent is in scene and parent_id is set if obj_type.meta.needs_parent_type: pass if obj_type.meta.has_pose and obj.pose is None: raise Arcor2Exception(f"Object {obj.name} requires pose.") if not obj_type.meta.has_pose and obj.pose is not None: raise Arcor2Exception(f"Object {obj.name} should not have pose.") if obj_type.meta.abstract: raise Arcor2Exception(f"ObjectType {obj.type} is abstract.") if new_one: if obj.id in scene.object_ids: raise Arcor2Exception(f"Object {obj.name} has duplicate id.") if obj.name in scene.object_names(): raise Arcor2Exception(f"Object name {obj.name} is duplicate.") hlp.is_valid_identifier(obj.name)