Datatypes Classes
Attention
Datatype classes are internally used in record or component classes. This page is only for documentation purposes.
Common Datatypes
Mapping Base Class
- class pyaltiumlib.datatypes.mapping.MappingBase(value: int)
Base class for mapping integer values to corresponding string representations. This class provides a common structure for handling mapped values.
- Parameters:
value (int) – The integer value to be mapped.
- Raises:
ValueError – If the provided value is not found in the _map dictionary.
- __repr__()
Returns the string representation of the mapped value.
- Returns:
The name corresponding to the integer value.
- Return type:
str
- to_int()
Returns the integer value of the mapped object.
- Returns:
The integer representation.
- Return type:
int
Coordinate
- class pyaltiumlib.datatypes.coordinate.Coordinate(value)
Represents a single coordinate value.
This class provides parsing functions for extracting coordinates from different data formats, as well as mathematical operations.
- Parameters:
value (int or float) – The numerical value of the coordinate.
Operations:
Supports addition, subtraction, multiplication, and division with both integers, floats, and other Coordinate instances. Can be compared using <, >, <=, >= with both Coordinate instances and numerical values.
- __repr__()
Returns a string representation of the coordinate.
- classmethod parse_bin(x_bytes, scale=1.0)
Parses a coordinate from binary data (pcb file).
- Parameters:
x_bytes (bytes) – Binary representation of the coordinate.
scale (float, optional) – Scaling factor for the parsed coordinate.
- Returns:
A Coordinate instance with the parsed value.
- Return type:
Coordinate
- classmethod parse_dpx(key, data, scale=1.0)
Parses a coordinate from a parameter collection data dictionary (schematic file).
- Parameters:
key (str) – The key corresponding to the coordinate.
data (dict) – The dictionary containing coordinate data.
scale (float, optional) – Scaling factor for the parsed coordinate.
- Returns:
A Coordinate instance with the parsed value.
- Return type:
Coordinate
Coordinate Point
- class pyaltiumlib.datatypes.coordinate.CoordinatePoint(x, y)
This class encapsulates two Coordinate instances for the X and Y axes.
- Parameters:
x (int, float, or Coordinate) – The X-coordinate value.
y (int, float, or Coordinate) – The Y-coordinate value.
Mathematical Operations:
Supports addition, subtraction, multiplication, and division with CoordinatePoint instances or numerical values.
- __repr__()
Returns a string representation of the coordinate point.
- copy()
Returns a copy of the CoordinatePoint.
- expand(size)
Expands the coordinate point by a given size.
- Parameters:
size (int, float, or Coordinate) – The amount to expand by.
- Returns:
A new expanded CoordinatePoint.
- Return type:
CoordinatePoint
- offset(offset_x, offset_y)
Offsets the coordinate point by given values.
- Parameters:
offset_x (int or float) – Offset for the X coordinate.
offset_y (int or float) – Offset for the Y coordinate.
- Returns:
The offset CoordinatePoint.
- Return type:
CoordinatePoint
- rotate(center, angle)
Rotates the coordinate point around a given center by an angle.
- Parameters:
center (CoordinatePoint) – The center point for rotation.
angle (float) – The rotation angle in degrees.
- Returns:
The rotated CoordinatePoint.
- Return type:
CoordinatePoint
- to_int()
Converts the coordinate point to integer values.
- to_int_tuple()
Returns the coordinate point as a tuple of integers.
Binary Reader
- class pyaltiumlib.datatypes.binaryreader.BinaryReader(data)
A utility class for reading binary data with structured methods.
- Parameters:
data (bytes) – The binary data to be read.
- classmethod from_stream(stream, size_length=4)
Reads a binary block from a stream and initializes a BinaryReader.
- Parameters:
stream (file-like object) – The binary stream to read from.
size_length (int optional) – Number of bytes indicating the block size.
- Returns:
An instance of BinaryReader.
- Return type:
BinaryReader
- has_content()
Checks if there is remaining data to read.
- Returns:
True if data exists, False otherwise.
- Return type:
bool
- length()
Returns the length of the binary data.
- Returns:
The length of the data.
- Return type:
int
- read(length)
Reads a specified number of bytes from the binary data.
- Parameters:
length (int) – The number of bytes to read.
- Returns:
The read bytes.
- Return type:
bytes
- read_bin_coord(scaley=-1.0, double=False, double_scaling=0.0001)
Reads a binary coordinate pair and returns a CoordinatePoint.
- Parameters:
scaley (float) – Scaling factor for the Y coordinate.
double (bool optional) – Read coordinates as double
float (float optional) – Scaling of double values
- Returns:
A CoordinatePoint object.
- Return type:
CoordinatePoint
- read_byte()
Reads a single byte from the binary data.
- Returns:
The read byte.
- Return type:
bytes
- read_double()
Reads an IEEE 754 double-precision floating point value.
- Returns:
The double value.
- Return type:
float
- read_int16(signed=False)
Reads a 16-bit integer.
- Parameters:
signed (bool optional) – Whether to interpret the value as signed.
- Returns:
The integer value.
- Return type:
int
- read_int32(signed=False)
Reads a 32-bit integer.
- Parameters:
signed (bool optional) – Whether to interpret the value as signed.
- Returns:
The integer value.
- Return type:
int
- read_int8(signed=False)
Reads an 8-bit integer.
- Parameters:
signed (bool optional) – Whether to interpret the value as signed.
- Returns:
The integer value.
- Return type:
int
- read_string_block(size_string=1)
Reads a length-prefixed string.
- Parameters:
size_string (int optional) – Number of bytes specifying the string length.
- Returns:
The decoded string.
- Return type:
str
- read_unicode_text(length=32, encoding='utf-16-le')
Reads a Unicode string of fixed length.
- Parameters:
length (int optional) – Maximum length of the string in bytes.
encoding (str optional) – The encoding format.
- Returns:
The decoded Unicode string.
- Return type:
str
ParameterCollection
- class pyaltiumlib.datatypes.parametercollection.ParameterCollection(data=None)
A class representing a collection of parameters parsed from a string. The collection is shown as dictionary or list of dictionaries if multiple records are included.
- Parameters:
data (bytes, optional) – Binary data containing parameters, defaults to None leads an empty class.
- classmethod from_block(olestream, sizelength=4)
Alternate constructor to create a ParameterCollection from a block. Parses an OLE stream block containing a parameter collection.
- Parameters:
olestream (olestream) – The input binary stream.
sizelength (int, optional) – Number of bytes indicating the block size, defaults to 4.
- Raises:
ValueError – If stream length does not match expected block length.
- Returns:
An instance of ParameterCollection.
- Return type:
ParameterCollection
- get(keys, default=None)
Retrieves values corresponding to the given keys.
- Parameters:
keys (str or list) – A key or list of keys to search in the collection.
default (any, optional) – The value to return if the key is not found, defaults to None.
- Returns:
The requested values, either as a dict, list, or string.
- Return type:
dict | list | str
- get_bool(key, default=False)
Retrieves the value corresponding to the given key as a boolean.
- Parameters:
key (str) – The key to search for in the collection.
- Returns:
The corresponding boolean value.
- Return type:
bool
- get_int(key, default=0)
Retrieves the value corresponding to the given key as a int.
- Parameters:
key (str) – The key to search for in the collection.
- Returns:
The corresponding boolean value.
- Return type:
bool
- get_record()
Retrieves the record ID stored in the collection.
- Returns:
The record ID, or None if not found.
- Return type:
int or None
- parse(data)
Parses a block containing parameters separated by ‘|’, where each entry is terminated with 0x00. The encoding used is primarily Windows-1252 / ANSI.
- Parameters:
data (bytes) – The binary data containing parameters.
- Raises:
ValueError – If decoding fails, if the data does not end with 0x00, or if duplicate keys are found in a record.
Schematic Datatypes
SchematicPin
- class pyaltiumlib.datatypes.parametercollection.SchematicPin(data=None)
Bases:
ParameterCollectionA class representing a collection of parameters parsed from binary data. This class is a derivate of the original parameter collection to cover schematic pins
- Parameters:
data (bytes, optional) – Binary data containing parameters, defaults to None leads an empty class.
- parse(binary_data)
Parses a binary data using a binaryReader
- Parameters:
data (bytes) – The binary data containing parameters.
- Raises:
ValueError – If decoding fails, if the data does not end with 0x00, or if duplicate keys are found in a record.