Beispiel #1
0
def create_sample_tree():
    # view from img/treeview.png

    # This is : small.sample.itis.swiss
    #   Model (root) 7865b1fa-e680-11e9-ba43-ac9e17b76a71
    #   ├── Block 1  d29dced4-4399-4bdc-951d-d474a48db477
    #   ├── Grid   5e92f325-2085-45ab-9c21-8a9019a2290d
    #   └── Group 1  17895910-9d97-45d0-aeeb-0faaff44080e
    #   ├── Cylinder 1  e7c5e7f0-a1e3-4d2a-b958-494c33923fa0
    #   └── Sphere 1  d3e0da1c-e7a4-4adb-960c-00b477cb1df5

    tree = Tree()
    tree.name = "sample-tree"
    root = tree.create_node("model",
                            identifier="7865b1fa-e680-11e9-ba43-ac9e17b76a71",
                            data=Attributes())  # Root

    tree.create_node("Grid", parent=root.identifier, data=Attributes())
    tree.create_node("Block 1", parent=root.identifier, data=Attributes())

    group1 = tree.create_node("Group 1",
                              parent=root.identifier,
                              data=Attributes())
    tree.create_node("Sphere 1", parent=group1.identifier, data=Attributes())
    tree.create_node("Cylinder 1", parent=group1.identifier, data=Attributes())
    return tree
Beispiel #2
0
def create_tree_from_model(app: web.Application, smash_file: Path) -> Tree:
    from pysmash.application import get_app_safe
    from XCoreModeling import GetActiveModel, IsEntityGroup

    kernel = app[APP_KERNEL_KEY]
    assert kernel == get_app_safe()
    kernel.OpenFiles([
        str(smash_file),
    ])

    tree = Tree()
    tree.name = os.path.basename(smash_file)

    def _build_tree(entity, parent_id=None):
        node = tree.create_node(entity.Name,
                                identifier=str(entity.Id),
                                parent=parent_id)
        node.entity = entity  # TODO:  check python weakptr

        if IsEntityGroup(entity):
            for child in entity.Entities:
                _build_tree(child, parent_id=node.identifier)

    model = GetActiveModel()
    _build_tree(model.RootGroup)

    log.debug(tree)

    return tree
Beispiel #3
0
def create_large_tree(*, max_depth: int = 5, max_children: int = 20):
    tree = Tree()
    tree.name = "large-tree"

    def create_children(parent, depth):
        if depth + 1 <= max_depth:
            N = random.randrange(max_children)
            # n random names # pylint: disable=no-member
            names = [f"{fake.name()}" for n in range(N)]
            children = [
                tree.create_node(name, parent=parent.identifier)
                for name in names
            ]

            # TODO: add attributes
            for child in children:
                create_children(child, depth + 1)

    root = tree.create_node("root",
                            identifier="d2746468-12dc-4fc7-8a03-2ada76b53a1e")
    create_children(root, depth=0)

    return tree