Skip to content

FIX: Insert row fix for tables #5931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/5931.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Insert row fix for tables
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ def _define_termination_impedance_dll_functions(self):
self._dll.getLumpedComplexCompOrder.argtypes = [POINTER(c_int), c_bool]
self._dll.getLumpedComplexCompOrder.restype = c_int

def _bytes_or_none(self, str_value):
if str_value:
return bytes(str_value, "ascii")
return None

def table_type_to_bool(self):
"""Set a flag to recognize source and load complex table.

Expand Down Expand Up @@ -216,7 +221,7 @@ def row(self, row_index):
imag_value_string = imag_value_buffer.value.decode("utf-8")
return frequency_value_string, real_value_string, imag_value_string

def update_row(self, row_index, frequency="", real="", imag=""):
def update_row(self, row_index, frequency=None, real=None, imag=None):
"""Update frequency and complex impedance at a specified index in the complex impedance table.

Parameters
Expand All @@ -230,65 +235,56 @@ def update_row(self, row_index, frequency="", real="", imag=""):
imag: str, optional
The imaginary part of the complex impedance to update. If not specified, it remains unchanged.
"""
frequency_bytes_value = bytes(frequency, "ascii")
real_bytes_value = bytes(real, "ascii")
imag_bytes_value = bytes(imag, "ascii")
status = self._dll.updateComplexTableRow(
row_index,
frequency_bytes_value,
real_bytes_value,
imag_bytes_value,
self._bytes_or_none(frequency),
self._bytes_or_none(real),
self._bytes_or_none(imag),
self.table_type_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def append_row(self, frequency, real, imag):
def append_row(self, frequency=None, real=None, imag=None):
"""Append frequency and complex impedance values to the last row of
both the source and load complex impedance table.


Parameters
----------
frequency: str
frequency: str, optional
The frequency value to append.
real: str
real: str, optional
The real part of the complex impedance to append.
imag: str
imag: str, optional
The imaginary part of the complex impedance to append.
"""
frequency_bytes_value = bytes(frequency, "ascii")
real_bytes_value = bytes(real, "ascii")
imag_bytes_value = bytes(imag, "ascii")
status = self._dll.appendComplexTableRow(
frequency_bytes_value,
real_bytes_value,
imag_bytes_value,
self._bytes_or_none(frequency),
self._bytes_or_none(real),
self._bytes_or_none(imag),
self.table_type_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def insert_row(self, row_index, frequency, real, imag):
def insert_row(self, row_index, frequency=None, real=None, imag=None):
"""Insert frequency and complex impedance values at a specified index in the complex impedance table.

Parameters
----------
row_index : int
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``99``.
frequency : str
frequency : str, optional
The frequency value to insert.
real : str
real : str, optional
The real part of the complex impedance to insert.
imag : str
imag : str, optional
The imaginary part of the complex impedance to insert.
"""
frequency_bytes_value = bytes(frequency, "ascii")
real_bytes_value = bytes(real, "ascii")
imag_bytes_value = bytes(imag, "ascii")
status = self._dll.insertComplexTableRow(
row_index,
frequency_bytes_value,
real_bytes_value,
imag_bytes_value,
self._bytes_or_none(frequency),
self._bytes_or_none(real),
self._bytes_or_none(imag),
self.table_type_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
Expand Down
42 changes: 26 additions & 16 deletions src/ansys/aedt/core/filtersolutions_core/multiple_bands_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def _define_multiple_bands_dll_functions(self):
self._dll.removeMultipleBandsTableRow.argtype = c_int
self._dll.removeMultipleBandsTableRow.restype = c_int

def _bytes_or_none(self, str_value):
if str_value:
return bytes(str_value, "ascii")
return None

@property
def row_count(self) -> int:
"""Total number of rows present in the multiple bands table.
Expand Down Expand Up @@ -105,7 +110,7 @@ def row(self, row_index):
upper_value_string = upper_value_buffer.value.decode("utf-8")
return lower_value_string, upper_value_string

def update_row(self, row_index, lower_frequency="", upper_frequency=""):
def update_row(self, row_index, lower_frequency=None, upper_frequency=None):
"""Update lower and upper frequency values for a row in the multiple bands table.

Parameters
Expand All @@ -119,41 +124,46 @@ def update_row(self, row_index, lower_frequency="", upper_frequency=""):
New upper frequency value to set for the row.
If this value is not provided, the row's upper frequency remains unchanged.
"""
lower_bytes_value = bytes(lower_frequency, "ascii")
upper_bytes_value = bytes(upper_frequency, "ascii")
status = self._dll.updateMultipleBandsTableRow(row_index, lower_bytes_value, upper_bytes_value)
status = self._dll.updateMultipleBandsTableRow(
row_index,
self._bytes_or_none(lower_frequency),
self._bytes_or_none(upper_frequency),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def append_row(self, lower_frequency, upper_frequency):
def append_row(self, lower_frequency=None, upper_frequency=None):
"""Append a new row with specified lower and upper frequency values to the end of the multiple bands table.

Parameters
----------
lower_frequency: str
lower_frequency: str, optional
Lower frequency value for the new row.
upper_frequency: str
upper_frequency: str, optional
Upper frequency value for the new row.
"""
lower_bytes_value = bytes(lower_frequency, "ascii")
upper_bytes_value = bytes(upper_frequency, "ascii")
status = self._dll.appendMultipleBandsTableRow(lower_bytes_value, upper_bytes_value)
status = self._dll.appendMultipleBandsTableRow(
self._bytes_or_none(lower_frequency),
self._bytes_or_none(upper_frequency),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def insert_row(self, row_index, lower_frequency, upper_frequency):
def insert_row(self, row_index, lower_frequency=None, upper_frequency=None):
"""Insert lower and upper frequencies in a given row.

Parameters
----------
row_index: int
Index of the row. Valid values range from ``0`` to ``6``, inclusive.
lower_frequency: str
lower_frequency: str, optional
Lower frequency value to insert.
upper_frequency: str
upper_frequency: str, optional
Upper frequency value to insert.
"""
lower_bytes_value = bytes(lower_frequency, "ascii")
upper_bytes_value = bytes(upper_frequency, "ascii")
status = self._dll.insertMultipleBandsTableRow(row_index, lower_bytes_value, upper_bytes_value)
status = self._dll.insertMultipleBandsTableRow(
row_index,
self._bytes_or_none(lower_frequency),
self._bytes_or_none(upper_frequency),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def remove_row(self, row_index):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,40 @@ def _define_optimization_goals_dll_functions(self):
self._dll.getOptimizationGoalDefinitionRow.argtype = [c_int, POINTER(c_char_p), c_int]
self._dll.getOptimizationGoalDefinitionRow.restype = c_int

self._dll.updateOptimizationGoalDefinitionRow.argtype = [c_int, c_int, c_char_p]
self._dll.updateOptimizationGoalDefinitionRow.argtype = [
c_int,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
]
self._dll.updateOptimizationGoalDefinitionRow.restype = c_int

self._dll.appendOptimizationGoalDefinitionRow.argtype = [c_int, c_char_p]
self._dll.appendOptimizationGoalDefinitionRow.argtype = [
c_int,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
]
self._dll.appendOptimizationGoalDefinitionRow.restype = c_int

self._dll.insertOptimizationGoalDefinitionRow.argtypes = [c_int, c_char_p, c_char_p]
self._dll.insertOptimizationGoalDefinitionRow.argtypes = [
c_int,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
c_char_p,
]
self._dll.insertOptimizationGoalDefinitionRow.restype = c_int

self._dll.removeOptimizationGoalDefinitionRow.argtype = c_int
Expand Down
37 changes: 19 additions & 18 deletions src/ansys/aedt/core/filtersolutions_core/transmission_zeros.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def table_format_to_bool(self):
else:
return True

def _bytes_or_none(self, str_value):
if str_value:
return bytes(str_value, "ascii")
return None

@property
def row_count(self) -> int:
"""Number of transmission zeros in the transmission zeros table.
Expand Down Expand Up @@ -167,7 +172,7 @@ def row(self, row_index):
position_value_string = position_value_buffer.value.decode("utf-8")
return zero_value_string, position_value_string

def update_row(self, row_index, zero="", position=""):
def update_row(self, row_index, zero=None, position=None):
"""Update the transmission zero ratio or bandwidth and its position for a row in the transmission zeros table.

Parameters
Expand All @@ -181,51 +186,47 @@ def update_row(self, row_index, zero="", position=""):
New position of the element causing the transmission zero in the circuit.
If no value is specified, the value remains unchanged.
"""
zero_bytes_value = bytes(zero, "ascii")
position_bytes_value = bytes(position, "ascii")
status = self._dll.updateTransmissionZerosTableRow(
row_index,
zero_bytes_value,
position_bytes_value,
self._bytes_or_none(zero),
self._bytes_or_none(position),
self.table_format_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def append_row(self, zero, position=""):
def append_row(self, zero=None, position=None):
"""Append a new row that includes the ratio or bandwidth and position.

Parameters
----------
zero: str
zero: str, optional
Transmission zero ratio or bandwidth value.
position: str
position: str, optional
Position of the element creating transmission zero in the associated circuit.
"""
zero_bytes_value = bytes(zero, "ascii")
position_bytes_value = bytes(position, "ascii")
status = self._dll.appendTransmissionZerosTableRow(
zero_bytes_value, position_bytes_value, self.table_format_to_bool()
self._bytes_or_none(zero),
self._bytes_or_none(position),
self.table_format_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

def insert_row(self, row_index, zero, position=""):
def insert_row(self, row_index, zero=None, position=None):
"""Insert a new row that includes the ratio or bandwidth and the position.

Parameters
----------
row_index: int
Index for the new row in the transmission zeros table. Valid values range from ``0`` to ``9``, inclusive.
zero: str
zero: str, optional
Transmission zero ratio or bandwidth value.
position: str
position: str, optional
Position of the element creating transmission zero in the associated circuit.
"""
zero_bytes_value = bytes(zero, "ascii")
position_bytes_value = bytes(position, "ascii")
status = self._dll.insertTransmissionZerosTableRow(
row_index,
zero_bytes_value,
position_bytes_value,
self._bytes_or_none(zero),
self._bytes_or_none(position),
self.table_format_to_bool(),
)
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,35 @@ def test_append_row(self, lumped_design):
assert lumped_design.multiple_bands_table.row(2) == ("100M", "500M")
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.append_row("", "500M")
assert info.value.args[0] == "It is not possible to append an empty value"
assert info.value.args[0] == "It is not possible to append an empty value into table"
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.append_row("100M", "")
assert info.value.args[0] == "It is not possible to append an empty value"
assert info.value.args[0] == "It is not possible to append an empty value into table"

def test_insert_row(self, lumped_design):
lumped_design.attributes.filter_multiple_bands_enabled = True
assert lumped_design.multiple_bands_table.row_count == 2
assert lumped_design.multiple_bands_table.row(0) == ("2G", "3G")
lumped_design.multiple_bands_table.insert_row(0, "200M", "5G")
assert lumped_design.multiple_bands_table.row_count == 3
assert lumped_design.multiple_bands_table.row(0) == ("200M", "5G")
assert lumped_design.multiple_bands_table.row(1) == ("2G", "3G")
lumped_design.multiple_bands_table.insert_row(0, lower_frequency="500M", upper_frequency="2G")
assert lumped_design.multiple_bands_table.row(0) == ("500M", "2G")
assert lumped_design.multiple_bands_table.row(1) == ("200M", "5G")
assert lumped_design.multiple_bands_table.row(2) == ("2G", "3G")
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.insert_row(22, lower_frequency="500M", upper_frequency="2G")
assert info.value.args[0] == "The rowIndex must be greater than zero and less than row count"
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.insert_row(0, lower_frequency="", upper_frequency="2G")
assert info.value.args[0] == "It is not possible to insert an empty value into table"
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.insert_row(0, lower_frequency="500M", upper_frequency="")
assert info.value.args[0] == "It is not possible to insert an empty value into table"
with pytest.raises(RuntimeError) as info:
lumped_design.multiple_bands_table.insert_row(0)
assert info.value.args[0] == "It is not possible to insert an empty value into table"

def test_remove_row(self, lumped_design):
lumped_design.attributes.filter_multiple_bands_enabled = True
Expand Down
Loading