<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def add_object(self, obj):
        '''add an object to a layer'''
        state = self.state
        if not obj.layer in state.layers:
            # its a new layer
            state.layers[obj.layer] = {}
        state.layers[obj.layer][obj.key] = obj
        state.need_redraw = True
        if (not self.legend_checkbox_menuitem_added and
            isinstance(obj, SlipFlightModeLegend)):
            self.add_legend_checkbox_menuitem()
            self.legend_checkbox_menuitem_added = True
            self.SetMenuBar(self.menu.wx_menu())