Document Model Architecture¶
The document model is the backbone of the application, representing the entire user project as a hierarchical tree of objects. It is designed to be reactive, serializable, and easily traversable.
Overview¶
The architecture is built on the Composite design pattern. A single
abstract base class, DocItem, defines the common interface for all
objects that can exist in the document tree (e.g., layers, workpieces,
groups). This allows complex, nested structures to be treated uniformly.
Key principles of the model include:
- Tree Structure: The
Docobject serves as the root of the tree. Each item (except the root) has a singleparentand can have multiplechildren. - Reactivity: The model uses a signal/slot system (
blinker). When an item is changed, it emits a signal. Parent items listen to their children's signals and "bubble them up" the tree. This allows high-level components like thePipelineto listen for any change in the document by connecting to a single signal on the rootDocobject. The system tracks both content changes and transform changes separately for efficient updates. - Transformation Hierarchy: Every
DocItemhas a local transformationMatrix. An item's final position, scale, and rotation in the "world" (the main canvas) is the product of its own local matrix and the world matrices of all its ancestors. - Data Decoupling: The visual or raw data for a
WorkPieceis not stored directly within it. Instead, theWorkPieceholds a UID that references anImportSourceobject in a central registry on theDoc. This decouples the document structure from the data management, making the model more lightweight and flexible.
Class Inheritance¶
This diagram shows the class hierarchy. Every object that is part of the
document's spatial tree inherits from the abstract base class DocItem,
gaining core functionalities like parenting, transformations, and signal
bubbling.
classDiagram
direction TD
class DocItem {
<<abstract>>
+uid: str
+parent: DocItem
+children: List~DocItem~
+matrix: Matrix
+updated Signal
+transform_changed Signal
+get_world_transform() Matrix
}
DocItem <|-- Doc
DocItem <|-- Layer
DocItem <|-- Group
DocItem <|-- WorkPiece
DocItem <|-- Workflow
DocItem <|-- Step
DocItem <|-- StockItem
class Doc
class Layer
class Group
class WorkPiece
class Workflow
class Step
class StockItem
DocItem: The abstract foundation providing the composite pattern implementation.- All other classes are concrete implementations of
DocItem, each with a specialized role in the document structure.
Object Composition¶
This diagram illustrates how instances of the classes are assembled to form a complete document. It shows the parent-child relationships and references between objects.
graph TD
D(Doc)
ST(StockItem)
L(Layer) -- "owns one" --> WF(Workflow)
WF -- "contains" --> S(Step)
L -- "contains" --> G(Group)
L -- "contains" --> WP(WorkPiece)
D -- "contains" --> L
D -- "contains" --> ST
G -- "contains (recursive)" --> G
G -- "contains" --> WP
- A
Docis the top-level object. It contains one or moreLayers andStockItems. It also manages a registry of allImportSources in the project. - Each
Layercontains the user's content:WorkPieces andGroups. Crucially, aLayeralso owns oneWorkflow. - A
Workflowcontains an ordered list ofSteps, which define the manufacturing process for that layer. - A
Groupis a container that can holdWorkPieces and otherGroups, allowing for nested transformations. - A
WorkPieceis a fundamental design element. It does not store its raw data directly. Instead, it references anImportSourcevia a UID. It also has its ownGeometry(vector data) and can have a list ofTabs.
DocItem Descriptions¶
-
DocItem(Abstract) -
Role: The abstract base for all tree nodes.
-
Key Properties:
uid,parent,children,matrix,updatedsignal,transform_changedsignal. Provides the core composite pattern logic. -
Doc -
Role: The root of the document tree.
-
Key Properties:
children(Layers, StockItems),import_sources(a dictionary mapping UIDs toImportSourceobjects),active_layer. -
Layer -
Role: The primary organizational unit for content. A layer associates a group of workpieces with a single manufacturing workflow.
-
Key Properties:
children(WorkPieces, Groups, one Workflow),visible,stock_item_uid. -
Group -
Role: A container for other
DocItems (WorkPiece,Group). Allows a collection of items to be transformed as a single unit. -
WorkPiece -
Role: Represents a single, tangible design element on the canvas (e.g., an imported SVG).
-
Key Properties:
vectors(aGeometryobject),import_source_uid,tabs,tabs_enabled. Itsvectorsare normalized to a 1x1 box, with all scaling and positioning handled by its transformationmatrix. -
Workflow -
Role: An ordered sequence of processing instructions. Owned by a
Layer. -
Key Properties:
children(an ordered list ofSteps). -
Step -
Role: A single processing instruction within a
Workflow(e.g., "Contour Cut" or "Raster Engrave"). It is a configuration object holding dictionaries that define the producer, modifiers, and transformers to be used. -
StockItem - Role: Represents a piece of physical material in the document,
defined by its own vector
geometry.Layers can be assigned to a specific stock item.