def getDefaultSymbol(size):
    symbol = QgsMarkerSymbol()
    for i in range(symbol.symbolLayerCount()):
        symbol.takeSymbolLayer(0)
    symbolLayer = QgsSvgMarkerSymbolLayer(
        os.path.join(os.path.dirname(__file__), 'svg', 'question.svg'))
    symbolLayer.setSizeUnit(3)
    symbolLayer.setSize(size)
    symbol.insertSymbolLayer(0, symbolLayer)
    return symbol
def symbolForCode(code, size):
    # noinspection PyBroadException,PyUnusedLocal
    try:
        symbol = QgsMarkerSymbol()
        for i in range(symbol.symbolLayerCount()):
            symbol.takeSymbolLayer(0)

        echelonCode = code[3] + code[8:10]
        echelonLayer = getSymbolLayer('Echelon', echelonCode, size)
        if echelonLayer is not None:
            symbol.insertSymbolLayer(0, echelonLayer)
        # log.debug('echelon: %s %s' % (echelonCode,
        #                               str(echelonLayer is not None)))

        amplifierCode = code[3] + code[8:10]
        amplifierLayer = getSymbolLayer('Amplifier', amplifierCode, size)
        if amplifierLayer is not None:
            symbol.insertSymbolLayer(0, amplifierLayer)
        # log.debug('amplifier: %s %s' % (
        #     amplifierCode, str(amplifierLayer is not None)))

        hqtffdCode = code[3:6] + code[7]
        hqtffdLayer = getSymbolLayer('HQTFFD', hqtffdCode, size)
        if hqtffdLayer is not None:
            symbol.insertSymbolLayer(0, hqtffdLayer)
        # log.debug('hqtffd: %s %s' %
        #           (hqtffdCode, str(hqtffdLayer is not None)))

        ocaCode = code[2:7] + '2'
        ocaLayer = getSymbolLayer('OCA', ocaCode, size)
        if ocaLayer is not None:
            symbol.insertSymbolLayer(0, ocaLayer)
        # log.debug('oca: %s %s' % (ocaCode, str(ocaLayer is not None)))

        mainCode = code[4:6] + code[10:16]
        mainLayer = getSymbolLayer('Appendices', mainCode, size)
        if mainLayer is not None:
            symbol.insertSymbolLayer(0, mainLayer)
        # log.debug('main: %s %s' % (mainCode, str(mainLayer is not None)))

        modifier1Code = code[4:6] + code[16:18] + '1'
        modifier1Layer = getSymbolLayer('Appendices', modifier1Code, size)
        if modifier1Layer is not None:
            symbol.insertSymbolLayer(0, modifier1Layer)

        modifier2Code = code[4:6] + code[18:20] + '2'
        modifier2Layer = getSymbolLayer('Appendices', modifier2Code, size)
        if modifier2Layer is not None:
            symbol.insertSymbolLayer(0, modifier2Layer)

        frameCode = '%s_%s_%s' % (code[2], code[3:6], code[0])
        frameLayer = getSymbolLayer('Frames', frameCode, size)
        if frameLayer is not None:
            symbol.insertSymbolLayer(0, frameLayer)
        # log.debug('frame: %s %s' % (frameCode, str(frameLayer is not None)))

        if symbol.symbolLayerCount() == 0:
            symbol = None
    except Exception as e:
        symbol = None

    return symbol