Document
- class Document(line_collection=None, page_size=None)
This class is the core data model of vpype and represent the data that is passed from one command to the other. At its core, a Document is a collection of layers identified by non-zero positive integers and each represented by a
LineCollection
.In addition, the Document class maintains a
page_size
attribute which describe the physical size of the document. This attribute is not strictly linked to the actual Document’s content, but can be set based on it.Methods
Create a Document, optionally providing a
LayerCollection
for layer 1.Add a the content of a
LineCollection
to a given layer.Compute bounds of the document.
Returns the total number of layers.
Crop all layers to a rectangular area.
Create an empty copy of this document with the same page size.
Test existence of a layer.
Extend a Document with the content of another Document.
Adjust the page sized according to the following logic:
Set
page_size
to the current geometries' width and height and move the geometries so that their bounds align to (0, 0).Returns the lowest unused layer id.
Returns the list of layer IDs
Returns True if all layers are empty.
Returns an iterator that yield layers corresponding to the provided IDs, provided they exist.
Return the total length of the paths.
Returns the total pen-up distance corresponding to the path.
Removes a layer from the Document.
Rotate the Document's content..
Scale the geometry.
Returns the total number of segment across all lines.
Translates all line by a given offset.
Attributes
Returns a reference to the layer dictionary.
Returns the page size or None if it hasn't been set.
Methods
- Document.__getitem__(layer_id)
- Document.__init__(line_collection=None, page_size=None)
Create a Document, optionally providing a
LayerCollection
for layer 1.- Parameters
line_collection (
Optional
[LineCollection
]) -- if provided, used as layer 1
- Document.__setitem__(layer_id, value)
- Document.add(lc, layer_id=None)
Add a the content of a
LineCollection
to a given layer.If the given layer is None, the input LineCollection is used to create a new layer using the lowest available layer ID.
- Return type
- Document.bounds(layer_ids=None)
Compute bounds of the document.
If layer_ids is provided, bounds are computed only for the corresponding IDs.
Note: the bounds are computed based on the actual geometries contained in this
Document
instance. The document’s page size, if any, is not taken into account by this calculation.
- Document.crop(x1, y1, x2, y2)
Crop all layers to a rectangular area.
- Document.empty_copy()
Create an empty copy of this document with the same page size.
- Return type
- Document.exists(layer_id)
Test existence of a layer.
Note that existence of a layer does not necessarily imply that it isn’t empty.
- Document.extend(doc)
Extend a Document with the content of another Document.
The layer structure of the source Document is maintained and geometries are either appended to the destination’s corresponding layer or new layers are created, depending on if the layer existed or not in the destination Document.
The
page_size
attribute is adjusted usingextend_page_size()
.
- Document.extend_page_size(page_size)
Adjust the page sized according to the following logic:
if
page_size
is None, the the page size is unchangedif
self.page_size
is None, it is set topage_size
if both page sizes are not None, the page size is set to the largest value in both direction
- Document.fit_page_size_to_content()
Set
page_size
to the current geometries’ width and height and move the geometries so that their bounds align to (0, 0).- Return type
- Document.is_empty()
Returns True if all layers are empty.
- Return type
- Returns
True if all layers are empty
- Document.layers_from_ids(layer_ids)
Returns an iterator that yield layers corresponding to the provided IDs, provided they exist. This is typically used to process a command’s layer list option, in combination with
multiple_to_layer_ids()
.Non-existent layer IDs in the input are ignored.
- Parameters
- Return type
- Returns
layer iterator
- Document.pen_up_length()
Returns the total pen-up distance corresponding to the path.
This function does not account for the pen-up distance between layers.
- Return type
- Returns
total pen-up distances
- Document.pop(layer_id)
Removes a layer from the Document.
- Parameters
layer_id (
int
) -- ID of the layer to be removed- Return type
- Returns
the
LineCollection
corresponding to the removed layer
- Document.rotate(angle)
Rotate the Document’s content..
The rotation is performed about the coordinates origin (0, 0). To rotate around a specific location, appropriate translations must be performed before and after the scaling (see
LineCollection.rotate()
).
- Document.scale(sx, sy=None)
Scale the geometry.
The scaling is performed about the coordinates origin (0, 0). To scale around a specific location, appropriate translations must be performed before and after the scaling (see
LineCollection.scale()
).
- Document.segment_count()
Returns the total number of segment across all lines.
- Return type
- Returns
the total number of segments in the geometries
Attributes
- Document.layers
Returns a reference to the layer dictionary. :rtype:
Dict
[int
,LineCollection
] :returns: the internal layer dictionary