def test():
    esh = EnergySystemHandler()
    #left = esh.load_file('Right1_with_ESI.esdl')
    left = esh.load_file('Left.esdl')

    #right = esh.import_file('Right1_with_ESI.esdl')
    right = esh.import_file('Right1_with_ESI_and_connectedTo_and_carrier.esdl')
    #right = esh.import_file('Left.esdl')

    merge = ESDLMerge()
    merge.config(forceCombineMainArea=True)

    es = merge.merge(left, right)
    print(esh.to_string())
def test():
    stack = UndoRedoCommandStack(
    )  # keep track of all undo-redo stuff using notifications

    #monitor_esdl_changes(stack)

    esh = EnergySystemHandler()
    esdl.EnergySystem.__repr__ = lambda x: '{}(name={})'.format(
        x.eClass.name, x.name)
    es, _ = esh.load_file('esdl\Left.esdl')
    es: esdl.EnergySystem = es
    es2, _ = esh.import_file('esdl\Right1.esdl')
    print(esh.rset.resources)
    resource = esh.get_resource(es.id)
    print(resource.uri.plain)
    from esdl.undo import ResourceObserver
    ro = ResourceObserver(command_stack=stack)

    ro.observe(resource)

    stack.start_recording(combineCommands=True)
    #changeESName = Set(owner=es, feature='name', value="Please undo me!")
    #stack.execute(changeESName)
    print('Initial value:', es.name, es.description)
    #stack.undo()
    es.name = "Please undo me!"
    print('Updated value:', es.name, es.description)
    stack.add_undo_step()
    es.description = "cool"
    stack.stop_recording()
    print('Updated value2:', es.name, es.description)
    stack.undo()
    print('Undone:', es.name, es.description)

    stack.redo()
    print('Redo:', es.name, es.description)
    print(stack.stack)

    stack.undo()
    print('Undo again:', es.name, es.description)
    print(stack.stack)

    stack.undo()
    print('Undo again:', es.name, es.description)
    print(stack.stack)

    print("---- next test ----")

    stack.start_recording(combineCommands=True)
    area: esdl.Area = es.instance[0].area
    #observer.observe(area)
    #addAsset = Add(owner=area, feature='asset', value=chp)
    #stack.execute(addAsset)
    print('Area name:' + area.name)
    area.name = 'test area'
    print('Area name after change:' + area.name)
    #stack.undo()
    #print('Area name after undo:' + area.name)
    #print('Area assets', area.asset)
    chp = esdl.CHP(id="CHP",
                   name="CHP",
                   fuelType=esdl.PowerPlantFuelEnum.NATURAL_GAS)
    area.asset.append(chp)
    print('Area assets after adding CHP', area.asset)
    stack.stop_recording()
    stack.undo()
    print('Area assets after undo', area.asset)
    print('Area name after undo:' + area.name)

    r2Stack = UndoRedoCommandStack()
    ResourceObserver(r2Stack).observe(esh.get_resource(es_id=es2.id))
    r2Stack.start_recording()
    stack.start_recording(combineCommands=True)
    es2.name = 'test'
    stack.stop_recording()
    r2Stack.stop_recording()
    r2Stack.undo()
    print(es2.name)