Core Services

here you can find the API for services that are related to model creation and model manipulation.

Element Repository (/Factory)

class gaphor.core.modeling.ElementFactory(event_manager: EventManager | None = None, element_dispatcher: ElementDispatcher | None = None)[source]

The ElementFactory is used as a central repository for a model.

New model elements should be created by create.

Methods like select can be used to find elements in the model.

select(expression: Callable[[Base], bool]) Iterator[Base][source]
select(expression: type[T]) Iterator[T]
select(expression: None) Iterator[Base]

Iterate elements that comply with expression.

Expressions can be:

  • None: return all elements.

  • A type: return all elements of that type, or subtypes.

  • An expression.

lselect(expression: Callable[[Base], bool] | type[T] | None = None) list[Base][source]

Like select, but return a list, instead of an iterator.

lookup(id: str) Base | None[source]

Find element with a specific id.

keys() Iterator[str][source]

Iterate all id’s in the factory.

values() Iterator[Base][source]

Iterate all elements in the factory.

size() int[source]

Return the amount of elements currently in the factory.

is_empty() bool[source]

Returns True if the factory holds no elements.

create(type: type[T]) T[source]

Create a new model element of type type.

This method will only create model elements, not Presentation elements: those are created by Diagram.

flush() None[source]

Flush all elements (remove them from the factory).

Diagram elements are flushed first. The remaining elements are flushed next.

Modeling Language

Information on how modeling languages are managed can be found Modeling Languages.

Event Manager

The Event System takes care of dispatches events throughout Gaphor.