コード例 #1
0
ファイル: lpycontrol.py プロジェクト: pradal/plantlab
def import_lpy_controls(filepath):
    if not path(filepath).isfile():
        return

    control = dict()

    f = open(filepath, 'r')
    script = f.read()
    f.close()

    if script is None: script = ""
    beginTag = LpyParsing.InitialisationBeginTag
    if not beginTag in script:
        return str(script), control
    else:
        txts = str(script).split(beginTag)
        new_script = txts[0]
        context_to_translate = txts[1]
        context = Lsystem().context()
        context.initialiseFrom(beginTag + context_to_translate)

    managers = get_managers()
    visualparameters = []
    scalars = []
    functions = []
    curves = []
    geoms = []

    lpy_code_version = 1.0
    if context.has_key('__lpy_code_version__'):
        lpy_code_version = context['__lpy_code_version__']
    if context.has_key('__scalars__'):
        scalars_ = context['__scalars__']
        scalars = [ProduceScalar(v) for v in scalars_]
    if context.has_key('__functions__') and lpy_code_version <= 1.0:
        functions = context['__functions__']
        for n, c in functions:
            c.name = n
        functions = [c for n, c in functions]
        funcmanager = managers['Function']
        geoms += [(funcmanager, func) for func in functions]
    if context.has_key('__curves__') and lpy_code_version <= 1.0:
        curves = context['__curves__']
        for n, c in curves:
            c.name = n
        curves = [c for n, c in curves]
        curvemanager = managers['Curve2D']
        geoms += [(curvemanager, curve) for curve in curves]
    if context.has_key('__parameterset__'):
        for panelinfo, objects in context['__parameterset__']:
            for typename, obj in objects:
                visualparameters.append((managers[typename], obj))

    for scalar in scalars:
        control[unicode(scalar.name)] = scalar.value
    for (manager, geom) in geoms:
        if geom != list():
            control[geom.getName()] = geom
    for (manager, geom) in visualparameters:
        if geom != list():
            control[geom.getName()] = geom

    new_controls = []
    for name, value in control.items():
        interfaces = guess_interface(value)
        if interfaces:
            new_controls.append(Control(name, interfaces[0], value))

    try:
        control["color map"] = to_color(context.turtle.getColorList())
    except AttributeError:
        pass
    else:
        new_controls.append(
            Control("color map", 'IColorList', control["color map"]))

    for control in new_controls:
        register_control(control)
コード例 #2
0
ファイル: lpycontrol.py プロジェクト: pradal/plantlab
def import_lpy_controls(filepath):
    if not path(filepath).isfile():
        return

    control = dict()

    f = open(filepath, "r")
    script = f.read()
    f.close()

    if script is None:
        script = ""
    beginTag = LpyParsing.InitialisationBeginTag
    if not beginTag in script:
        return str(script), control
    else:
        txts = str(script).split(beginTag)
        new_script = txts[0]
        context_to_translate = txts[1]
        context = Lsystem().context()
        context.initialiseFrom(beginTag + context_to_translate)

    managers = get_managers()
    visualparameters = []
    scalars = []
    functions = []
    curves = []
    geoms = []

    lpy_code_version = 1.0
    if context.has_key("__lpy_code_version__"):
        lpy_code_version = context["__lpy_code_version__"]
    if context.has_key("__scalars__"):
        scalars_ = context["__scalars__"]
        scalars = [ProduceScalar(v) for v in scalars_]
    if context.has_key("__functions__") and lpy_code_version <= 1.0:
        functions = context["__functions__"]
        for n, c in functions:
            c.name = n
        functions = [c for n, c in functions]
        funcmanager = managers["Function"]
        geoms += [(funcmanager, func) for func in functions]
    if context.has_key("__curves__") and lpy_code_version <= 1.0:
        curves = context["__curves__"]
        for n, c in curves:
            c.name = n
        curves = [c for n, c in curves]
        curvemanager = managers["Curve2D"]
        geoms += [(curvemanager, curve) for curve in curves]
    if context.has_key("__parameterset__"):
        for panelinfo, objects in context["__parameterset__"]:
            for typename, obj in objects:
                visualparameters.append((managers[typename], obj))

    for scalar in scalars:
        control[unicode(scalar.name)] = scalar.value
    for (manager, geom) in geoms:
        if geom != list():
            control[geom.getName()] = geom
    for (manager, geom) in visualparameters:
        if geom != list():
            control[geom.getName()] = geom

    new_controls = []
    for name, value in control.items():
        interfaces = guess_interface(value)
        if interfaces:
            new_controls.append(Control(name, interfaces[0], value))

    try:
        control["color map"] = to_color(context.turtle.getColorList())
    except AttributeError:
        pass
    else:
        new_controls.append(Control("color map", "IColorList", control["color map"]))

    for control in new_controls:
        register_control(control)
コード例 #3
0
ファイル: lpy.py プロジェクト: VirtualPlants/plantlab
def import_lpy_file(script):
    """
    Extract from an "old style" LPy file script part (str) and associated control (dict).
    Permit compatibility between LPy and OALab.

    :param: script to filter (str)
    :return: lpy script (str) without end begining with "###### INITIALISATION ######"
    and a dict which contain the control (dict)
    """
    control = dict()

    if script is None:
        script = ""
    beginTag = LpyParsing.InitialisationBeginTag
    if not beginTag in script:
        return str(script), control
    else:
        txts = str(script).split(beginTag)
        new_script = txts[0]
        context_to_translate = txts[1]
        context = Lsystem().context()
        context.initialiseFrom(beginTag + context_to_translate)

        managers = get_managers()
        visualparameters = []
        scalars = []
        functions = []
        curves = []
        geoms = []

        lpy_code_version = 1.0
        if context.has_key('__lpy_code_version__'):
            lpy_code_version = context['__lpy_code_version__']
        if context.has_key('__scalars__'):
            scalars_ = context['__scalars__']
            scalars = [ProduceScalar(v) for v in scalars_]
        if context.has_key('__functions__') and lpy_code_version <= 1.0:
            functions = context['__functions__']
            for n, c in functions:
                c.name = n
            functions = [c for n, c in functions]
            funcmanager = managers['Function']
            geoms += [(funcmanager, func) for func in functions]
        if context.has_key('__curves__') and lpy_code_version <= 1.0:
            curves = context['__curves__']
            for n, c in curves:
                c.name = n
            curves = [c for n, c in curves]
            curvemanager = managers['Curve2D']
            geoms += [(curvemanager, curve) for curve in curves]
        if context.has_key('__parameterset__'):
            for panelinfo, objects in context['__parameterset__']:
                for typename, obj in objects:
                    visualparameters.append((managers[typename], obj))

        control["color map"] = context.turtle.getColorList()
        for scalar in scalars:
            control[unicode(scalar.name)] = scalar
        for (manager, geom) in geoms:
            if geom != list():
                new_obj, new_name = geometry_2_piklable_geometry(manager, geom)
                control[new_name] = new_obj
        for (manager, geom) in visualparameters:
            if geom != list():
                new_obj, new_name = geometry_2_piklable_geometry(manager, geom)
                control[new_name] = new_obj

        return new_script, control