modules

geometor.model

provides the core data structures and logic for constructing geometric models in 2D space.

everything centers around Model

Submodules

Attributes

GeometryObject

Classes

Model

The central class representing a collection of geometric elements.

Functions

load_model(→ geometor.model.Model)

Load a model from a JSON file and return a new Model instance.

Package Contents

geometor.model.load_model(file_path: str, logger: logging.Logger | None = None) geometor.model.Model

Load a model from a JSON file and return a new Model instance.

This function reads a JSON file containing serialized model data and reconstructs a geometor.model.Model object. It performs a two-pass process: first parsing all symbolic expressions to recreate the geometry objects, and then linking them with their parents and metadata to restore the full dependency graph.

Parameters:
  • file_path – The path to the JSON file to load.

  • logger – An optional logger instance to attach to the new model.

Returns:

A new geometor.model.Model instance populated with the loaded data.

geometor.model.GeometryObject
class geometor.model.Model(name: str = '', logger: logging.Logger | None = None, use_point_subscript: bool = False)

Bases: dict, geometor.model.points.PointsMixin, geometor.model.lines.LinesMixin, geometor.model.circles.CirclesMixin, geometor.model.polygons.PolygonsMixin, geometor.model.segments.SegmentsMixin, geometor.model.polynomials.PolynomialsMixin, geometor.model.serialize.SerializeMixin, geometor.model.reports.ReportMixin, geometor.model.delete.DeleteMixin, geometor.model.sections.SectionsMixin, geometor.model.wedges.WedgesMixin, geometor.model.ancestors.AncestorsMixin

The central class representing a collection of geometric elements.

The Model class is a comprehensive container that inherits from dict to store geometric elements mapped to their symbolic representations. It composes multiple mixins to provide a rich feature set, including point plotting, circle/line construction, serialization, reporting, and more.

use_point_subscript = False
ID_gen
last_point_id = ''
log(message: object) None

Log a message to the model’s logger or print if it’s a rich object.

set_analysis_hook(hook_function: Callable) None

Set a hook function to be called during analysis/point addition.

property new_points: list[sympy.geometry.Point]

The new_points of the model.

clear_new_points() None

Clear the list of newly added points.

property name: str

The name of the model.

__setitem__(key: GeometryObject, value: geometor.model.element.Element) None

Set an item in the model, enforcing type checks.

This override of the dictionary setter ensures type safety for the model. It validates that keys are recognized GeometryObjects and values are Element wrappers, maintaining the integrity of the model’s storage.

Parameters:
  • key – The geometric object (GeometryObject).

  • value – The element wrapper (Element).

Raises:

TypeError – If key or value are not of the expected types.

remove_by_ID(ID: str) None

Remove a geometric element from the model by its ID.

property points: list[sympy.geometry.Point]

Returns point elements from model as list.

property structs: list[geometor.model.element.Struct]

Returns struct elements (line or circle) from model as list.

property lines: list[sympy.geometry.Line]

Returns line elements from model as list.

property circles: list[sympy.geometry.Circle]

Returns circle elements from model as list.

limits() tuple[tuple[float, float], tuple[float, float]]

Find x, y limits from points and circles of the model.

This method calculates the bounding box of all geometric elements currently in the model. It iterates through points and circles (accounting for radii) to determine the minimum and maximum coordinates.

Returns:

A tuple containing ((min_x, max_x), (min_y, max_y)).

Return type:

tuple

Raises:

ValueError – If the model contains no geometric elements.

get_element_by_ID
parse_command(command: str) None

Parse and execute a single command string.