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)[源代码]

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][源代码]
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][源代码]

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

lookup(id: str) Base | None[源代码]

Find element with a specific id.

keys() Iterator[str][源代码]

Iterate all id's in the factory.

values() Iterator[Base][源代码]

Iterate all elements in the factory.

size() int[源代码]

Return the amount of elements currently in the factory.

is_empty() bool[源代码]

Returns True if the factory holds no elements.

create(type: type[T]) T[源代码]

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[源代码]

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 建模语言.

Event Manager

The 事件系统 takes care of dispatches events throughout Gaphor.