-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from andlaus/refactor_compumethods
Refactor the compu methods
- Loading branch information
Showing
30 changed files
with
1,648 additions
and
973 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
from xml.etree import ElementTree | ||
|
||
from ..odxtypes import AtomicOdxType, DataType | ||
|
||
|
||
@dataclass | ||
class CompuConst: | ||
v: Optional[str] | ||
vt: Optional[str] | ||
|
||
data_type: DataType | ||
|
||
@staticmethod | ||
def compuvalue_from_et(et_element: ElementTree.Element, *, data_type: DataType) -> "CompuConst": | ||
|
||
v = et_element.findtext("V") | ||
vt = et_element.findtext("VT") | ||
|
||
return CompuConst(v=v, vt=vt, data_type=data_type) | ||
|
||
def __post_init__(self) -> None: | ||
self._value: Optional[AtomicOdxType] = self.vt | ||
if self.v is not None: | ||
self._value = self.data_type.from_string(self.v) | ||
|
||
@property | ||
def value(self) -> Optional[AtomicOdxType]: | ||
return self._value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
from xml.etree import ElementTree | ||
|
||
from ..odxtypes import DataType | ||
from ..utils import dataclass_fields_asdict | ||
from .compuconst import CompuConst | ||
from .compuinversevalue import CompuInverseValue | ||
|
||
|
||
@dataclass | ||
class CompuDefaultValue(CompuConst): | ||
compu_inverse_value: Optional[CompuInverseValue] | ||
|
||
@staticmethod | ||
def compuvalue_from_et(et_element: ElementTree.Element, *, | ||
data_type: DataType) -> "CompuDefaultValue": | ||
kwargs = dataclass_fields_asdict( | ||
CompuConst.compuvalue_from_et(et_element, data_type=data_type)) | ||
|
||
compu_inverse_value = None | ||
if (civ_elem := et_element.find("COMPU-INVERSE-VALUE")) is not None: | ||
compu_inverse_value = CompuInverseValue.compuvalue_from_et( | ||
civ_elem, data_type=data_type) | ||
|
||
return CompuDefaultValue(**kwargs, compu_inverse_value=compu_inverse_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
from xml.etree import ElementTree | ||
|
||
from ..odxlink import OdxDocFragment | ||
from ..odxtypes import DataType | ||
from ..progcode import ProgCode | ||
from .compudefaultvalue import CompuDefaultValue | ||
from .compuscale import CompuScale | ||
|
||
|
||
@dataclass | ||
class CompuInternalToPhys: | ||
compu_scales: List[CompuScale] | ||
prog_code: Optional[ProgCode] | ||
compu_default_value: Optional[CompuDefaultValue] | ||
|
||
@staticmethod | ||
def compu_internal_to_phys_from_et(et_element: ElementTree.Element, | ||
doc_frags: List[OdxDocFragment], *, internal_type: DataType, | ||
physical_type: DataType) -> "CompuInternalToPhys": | ||
compu_scales = [ | ||
CompuScale.compuscale_from_et( | ||
cse, doc_frags, internal_type=internal_type, physical_type=physical_type) | ||
for cse in et_element.iterfind("COMPU-SCALES/COMPU-SCALE") | ||
] | ||
|
||
prog_code = None | ||
if (pce := et_element.find("PROG-CODE")) is not None: | ||
prog_code = ProgCode.from_et(pce, doc_frags) | ||
|
||
compu_default_value = None | ||
if (cdve := et_element.find("COMPU-DEFAULT-VALUE")) is not None: | ||
compu_default_value = CompuDefaultValue.compuvalue_from_et( | ||
cdve, data_type=physical_type) | ||
|
||
return CompuInternalToPhys( | ||
compu_scales=compu_scales, prog_code=prog_code, compu_default_value=compu_default_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
from .compuconst import CompuConst | ||
|
||
# make CompuInverseValue an alias for CompuConst. The XSD defines two | ||
# separate but identical groups for this (why?)... | ||
CompuInverseValue = CompuConst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: MIT | ||
from dataclasses import dataclass | ||
from typing import List, Optional | ||
from xml.etree import ElementTree | ||
|
||
from ..odxlink import OdxDocFragment | ||
from ..odxtypes import DataType | ||
from ..progcode import ProgCode | ||
from .compudefaultvalue import CompuDefaultValue | ||
from .compuscale import CompuScale | ||
|
||
|
||
@dataclass | ||
class CompuPhysToInternal: | ||
compu_scales: List[CompuScale] | ||
prog_code: Optional[ProgCode] | ||
compu_default_value: Optional[CompuDefaultValue] | ||
|
||
@staticmethod | ||
def compu_phys_to_internal_from_et(et_element: ElementTree.Element, | ||
doc_frags: List[OdxDocFragment], *, internal_type: DataType, | ||
physical_type: DataType) -> "CompuPhysToInternal": | ||
compu_scales = [ | ||
CompuScale.compuscale_from_et( | ||
cse, doc_frags, internal_type=internal_type, physical_type=physical_type) | ||
for cse in et_element.iterfind("COMPU-SCALES/COMPU-SCALE") | ||
] | ||
|
||
prog_code = None | ||
if (pce := et_element.find("PROG-CODE")) is not None: | ||
prog_code = ProgCode.from_et(pce, doc_frags) | ||
|
||
compu_default_value = None | ||
if (cdve := et_element.find("COMPU-DEFAULT-VALUE")) is not None: | ||
compu_default_value = CompuDefaultValue.compuvalue_from_et( | ||
cdve, data_type=internal_type) | ||
|
||
return CompuPhysToInternal( | ||
compu_scales=compu_scales, prog_code=prog_code, compu_default_value=compu_default_value) |
Oops, something went wrong.