Пример #1
0
def page(diagram, event_manager, element_factory, properties):
    page = DiagramPage(diagram, event_manager, element_factory, properties,
                       UMLModelingLanguage())
    page.construct()
    assert page.diagram == diagram
    assert page.view.canvas == diagram.canvas
    yield page
    page.close()
Пример #2
0
def element_factory():
    event_manager = EventManager()
    element_dispatcher = ElementDispatcher(event_manager, UMLModelingLanguage())
    element_factory = ElementFactory(event_manager, element_dispatcher)
    yield element_factory
    element_factory.shutdown()
    element_dispatcher.shutdown()
    event_manager.shutdown()
Пример #3
0
def diagrams(event_manager, element_factory, properties):
    window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    diagrams = Diagrams(event_manager, element_factory, properties,
                        UMLModelingLanguage())
    window.add(diagrams.open())
    window.show()
    yield diagrams
    diagrams.close()
Пример #4
0
def tab(event_manager, element_factory, properties):
    diagram = element_factory.create(UML.Diagram)
    tab = DiagramPage(diagram, event_manager, element_factory, properties,
                      UMLModelingLanguage())

    window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
    window.add(tab.construct())
    window.show()
    yield tab
    window.destroy()
Пример #5
0
def generate(
    filename: PathLike,
    outfile: PathLike,
    overridesfile: Optional[PathLike] = None,
) -> None:
    """Generates the Python data model.

    Opens the Gaphor model, generates the list of classes using the
    element factory, and then creates a new Python data model using a
    relationship search tree.
    """
    element_factory = ElementFactory()
    modeling_language = UMLModelingLanguage()
    with open(filename):
        storage.load(
            filename,
            element_factory,
            modeling_language,
        )

    classes: List = element_factory.lselect(UML.Class)
    classes, enumerations = find_enumerations(classes)
    classes = filter_out_gaphor_profile(classes)

    # Lambda key sort issue in mypy: https://github.com/python/mypy/issues/9656
    classes = sorted(
        (cls for cls in classes if cls.name[0] != "~"), key=lambda c: c.name  # type: ignore
    )

    hierarchy = create_class_hierarchy(classes)

    uml_classes = filter_uml_classes(classes, modeling_language)

    with open(outfile, "w") as f:
        f.write(header)
        for cls in uml_classes:
            f.write(f"from gaphor.UML import {cls.name}\n")

        cls_written: Set[Element] = set(uml_classes)
        for cls in hierarchy.keys():
            cls.attribute.sort(key=lambda a: a.name or "")  # type: ignore[attr-defined]
            write_class_def(cls, hierarchy, f, cls_written)

        f.write("\n\n")

        for cls in hierarchy.keys():
            write_properties(cls, f, enumerations)

        for cls in hierarchy.keys():
            write_subsets(cls, f)

    element_factory.shutdown()
Пример #6
0
def test_filter_uml_classes(classes):
    """Test filtering of classes between UML and others."""
    classes[0].name = "~Class"
    classes[1].name = "Class"
    classes[2].name = "Behavior"
    classes[3].name = "Transportation"
    classes[4].name = "Car"
    classes[5].name = "Truck"
    classes[6].name = "Van"
    assert len(classes) == 7

    uml_classes = filter_uml_classes(classes, UMLModelingLanguage())

    assert len(uml_classes) == 2
Пример #7
0
def generate(
    filename: PathLike,
    outfile: PathLike,
    overridesfile: Optional[PathLike] = None,
) -> None:
    """Generates the Python data model.

    Opens the Gaphor model, generates the list of classes using the element
    factory, and then creates a new Python data model using a relationship
    search tree.

    """
    element_factory = ElementFactory()
    modeling_language = UMLModelingLanguage()
    with open(filename):
        storage.load(
            filename,
            element_factory,
            modeling_language,
        )
    with open(outfile, "w") as f:
        f.write(header)
        classes: List = element_factory.lselect(
            lambda e: e.isKindOf(UML.Class))
        classes, enumerations = find_enumerations(classes)

        classes = sorted((cls for cls in classes if cls.name[0] != "~"),
                         key=lambda c: c.name)

        trees = create_class_trees(classes)
        create_referenced(classes)

        uml_classes = filter_uml_classes(classes, modeling_language)
        for cls in uml_classes:
            f.write(f"from gaphor.UML import {cls.name}\n")

        cls_written: Set[Element] = set(uml_classes)
        for cls in trees.keys():
            cls.attribute.sort(
                key=lambda a: a.name or "")  # type: ignore[attr-defined]
            write_class_def(cls, trees, f, cls_written)

        f.write("\n\n")

        for cls in trees.keys():
            write_properties(cls, f, enumerations)

    element_factory.shutdown()
def view(diagram, event_manager, element_factory):
    page = DiagramPage(diagram, event_manager, element_factory, {},
                       UMLModelingLanguage())
    page.construct()
    return page.view
Пример #9
0
 def __init__(self):
     self._modeling_languages = [
         UMLModelingLanguage(),
         SysMLModelingLanguage()
     ]
Пример #10
0
def modeling_language():
    return UMLModelingLanguage()
Пример #11
0
def element_factory(event_manager):
    return ElementFactory(
        event_manager, ElementDispatcher(event_manager, UMLModelingLanguage()))
Пример #12
0
def element_factory(event_manager):
    element_factory = ElementFactory(
        event_manager, ElementDispatcher(event_manager, UMLModelingLanguage()))
    yield element_factory
    element_factory.shutdown()