Beispiel #1
0
    def test_set_source(self):
        from libcellml import Component, ImportSource

        x = Component()
        i = ImportSource()
        i.setUrl('bonjour')
        x.setSourceComponent(i, 'camembert')
        self.assertEqual(x.importSource().url(), 'bonjour')
        self.assertEqual(x.importReference(), 'camembert')
    #  10.d
    #       Iterate through the items in the library (Importer.libraryCount() will give you
    #       the total), and print its keys to the terminal.  The keys can be retrieved as a 
    #       string from the Importer.key(index) function.  At this stage we expect only one model in the library.
    print('The importer has {} models in the library.'.format(importer.libraryCount()))
    for i in range(0, importer.libraryCount()):
        print(' library({}) = {}'.format(i, importer.key(i)))
    print()

    #  10.e
    #      We can simply use a clone of the imported components to define dummy variables in the 
    #      destination component.
    #      Create dummy components from the resolved imported components. You can get these from the 
    #      library or from the import source's model (or one of each, to prove to yourself that it works
    #      either way!).
    dummy_gate = imported_gate.importSource().model().component(imported_gate.importReference()).clone()
    dummy_controller = importer.library('PotassiumChannelController.cellml').component(controller.importReference()).clone()
    
    #      GOTCHA: Note that when an item is added to a new parent, it is automatically removed from 
    #         its original parent.  Iterating through a set of children is best done in descending
    #         index order or using a while loop so that child items are not skipped as the indices change.
    #  10.f
    #      Iterate through the variables in each dummy component, and add a clone of each variable 
    #      to the destination component. 
    while(dummy_gate.variableCount()):
        imported_gate.addVariable(dummy_gate.variable(0))
    
    while(dummy_controller.variableCount()):
        controller.addVariable(dummy_controller.variable(0))

    #      More connections are needed.  These should include:
    #       the total), and print its keys to the terminal.  The keys can be retrieved as a
    #       string from the Importer.key(index) function.  At this stage we expect only one model in the library.
    print('The importer has {} models in the library.'.format(
        importer.libraryCount()))
    for i in range(0, importer.libraryCount()):
        print(' library({}) = {}'.format(i, importer.key(i)))
    print()

    #  10.e
    #      We can simply use a clone of the imported components to define dummy variables in the
    #      destination component.
    #      Create dummy components from the resolved imported components. You can get these from the
    #      library or from the import source's model (or one of each, to prove to yourself that it works
    #      either way!).
    dummy_gate = imported_gate.importSource().model().component(
        imported_gate.importReference()).clone()
    dummy_controller = importer.library(
        os.path.join(import_path,
                     'PotassiumChannelController.cellml')).component(
                         controller.importReference()).clone()

    #      GOTCHA: Note that when an item is added to a new parent, it is automatically removed from
    #         its original parent.  Iterating through a set of children is best done in descending
    #         index order or using a while loop so that child items are not skipped as the indices change.
    #  10.f
    #      Iterate through the variables in each dummy component, and add a clone of each variable
    #      to the destination component.
    while (dummy_gate.variableCount()):
        imported_gate.addVariable(dummy_gate.variable(0))

    while (dummy_controller.variableCount()):