From abbbb203d14699d79a694705d6896555eebc8e91 Mon Sep 17 00:00:00 2001 From: Joshua Date: Fri, 20 Nov 2026 10:11:53 -0600 Subject: [PATCH] Add option to exclude data types from alignment rules. --- src/AuDaGe/formats/controlexpert/xsy.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/AuDaGe/formats/controlexpert/xsy.py b/src/AuDaGe/formats/controlexpert/xsy.py index c514566..8169b17 100644 --- a/src/AuDaGe/formats/controlexpert/xsy.py +++ b/src/AuDaGe/formats/controlexpert/xsy.py @@ -10,7 +10,7 @@ desc: AuDaGe module for handling Schneider Electric ControlExpert XSY files. import os import warnings -from collections.abc import Collection, Iterable +from collections.abc import Collection from dataclasses import dataclass from enum import IntEnum, StrEnum, auto from importlib import resources @@ -129,7 +129,7 @@ class Definitions(XSYBlock): path: Path, stylesheet_path: Path | None = None, name_ext: str = "Definitions", - definition_paths: Iterable[Path] | None = None, + definition_paths: Collection[Path] | None = None, include_builtins: bool = True, ) -> Definitions: """Read the DDTSource nodes of an XSY file into a DataFrame.""" @@ -201,10 +201,18 @@ class Definitions(XSYBlock): cls, address: float, length: float, + data_type: str, max_alignment: int = iec.DataUnit.DWORD, + excluded_data_types: Collection[str] = ("STRING",), ) -> float: # Return early if missing information. - if pd.isna(address) or pd.isna(length) or length <= 0: + if ( + pd.isna(address) + or pd.isna(length) + or pd.isna(data_type) + or length <= 0 + or data_type in excluded_data_types + ): return address alignment = min(length, max_alignment) rem = address % alignment @@ -260,6 +268,7 @@ class Definitions(XSYBlock): row[XC.ADDRESS] = cls._calculate_padding( prev_row[XC.ADDRESS] + prev_row[XC.LENGTH], row[XC.LENGTH], + row[XC.DATATYPE], ) group_dict_calc.append(row) group_calc = frame.AuDaGeFrame(group_dict_calc) @@ -564,7 +573,7 @@ class XSYReader: def __init__( self, - definition_paths: Iterable[Path] | None = None, + definition_paths: Collection[Path] | None = None, datablock_ss_path: Path | None = None, definitions_ss_path: Path | None = None, even_addresses: bool = True, @@ -574,7 +583,7 @@ class XSYReader: Parameters ---------- - definition_paths : iterable of pathlike (optional) + definition_paths : collection of Path (optional) List of additional XSY files to read UDT (DDT) definitions from. datablock_ss_path: pathlike (optional) Path to XSLT stylesheet to flatten the XSY file and extract the