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 all 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 @@ -190,7 +195,7 @@ def row(self, row_index):
Parameters
----------
row_index: int
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``99``.
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``149``.

Returns
-------
Expand All @@ -216,33 +221,30 @@ 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
----------
row_index: int
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``99``.
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``149``.
frequency: str, optional
The frequency value to update. If not specified, it remains unchanged.
real: str, optional
The real part of the complex impedance to update. If not specified, it remains unchanged.
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.

Expand All @@ -256,39 +258,33 @@ def append_row(self, frequency, real, imag):
imag: str
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``.
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``149``.
frequency : str
The frequency value to insert.
real : str
The real part of the complex impedance to insert.
imag : str
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 All @@ -299,7 +295,7 @@ def remove_row(self, row_index):
Parameters
----------
row_index : int
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``99``.
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``149``.
"""
status = self._dll.removeComplexTableRow(row_index, self.table_type_to_bool())
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
Expand Down
34 changes: 22 additions & 12 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,12 +124,14 @@ 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
Expand All @@ -134,12 +141,13 @@ def append_row(self, lower_frequency, upper_frequency):
upper_frequency: str
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
Expand All @@ -151,9 +159,11 @@ def insert_row(self, row_index, lower_frequency, upper_frequency):
upper_frequency: str
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 @@ -83,16 +83,42 @@ def _define_optimization_goals_dll_functions(self):
self._dll.getOptimizationGoalDefinitionRowCount.argtype = POINTER(c_int)
self._dll.getOptimizationGoalDefinitionRowCount.restype = c_int

self._dll.getOptimizationGoalDefinitionRow.argtype = [c_int, POINTER(c_char_p), c_int]
self._dll.getOptimizationGoalDefinitionRow.argtypes = [c_int, 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.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.updateOptimizationGoalDefinitionRow.restype = c_int

self._dll.appendOptimizationGoalDefinitionRow.argtype = [c_int, c_char_p]
self._dll.appendOptimizationGoalDefinitionRow.argtypes = [
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 Expand Up @@ -138,7 +164,7 @@ def row(self, row_index) -> list:
"""
row_parameter_buffer = create_string_buffer(1024)
# Call the DLL function. Assuming it fills the buffer with comma-separated values.
status = self._dll.getOptimizationGoalDefinitionRow(row_index, byref(row_parameter_buffer), 1024)
status = self._dll.getOptimizationGoalDefinitionRow(row_index, row_parameter_buffer, 1024)
self._dll_interface.raise_error(status)
# Decode the buffer to a Python string and split by comma to get a list.
row_parameters = row_parameter_buffer.value.decode("utf-8").split("|")
Expand Down Expand Up @@ -210,19 +236,19 @@ def append_row(

Parameters
----------
lower_frequency: str, optional
lower_frequency: str
Lower frequency value to set.
upper_frequency: str, optional
upper_frequency: str
Upper frequency value to set.
goal_value: str, optional
goal_value: str
Goal value to set.
condition: str, optional
condition: str
Condition value to set.
parameter_name: str, optional
parameter_name: str
Parameter name value to set.
weight: str, optional
weight: str
Weight value to set.
enabled: str, optional
enabled: str
Enabled value to set.
"""
status = self._dll.appendOptimizationGoalDefinitionRow(
Expand Down Expand Up @@ -254,19 +280,19 @@ def insert_row(
----------
row_index: int
Index of the row. Valid values range from ``0`` to ``49``, inclusive.
lower_frequency: str, optional
lower_frequency: str
Lower frequency value.
upper_frequency: str, optional
upper_frequency: str
Upper frequency value.
goal_value: str, optional
goal_value: str
Goal value.
condition: str, optional
condition: str
Condition value.
parameter_name: str, optional
parameter_name: str
Parameter name.
weight: str, optional
weight: str
Weight value.
enabled: str, optional
enabled: str
Enabled value.
"""
status = self._dll.insertOptimizationGoalDefinitionRow(
Expand Down
29 changes: 15 additions & 14 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,17 +186,15 @@ 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
Expand All @@ -201,14 +204,14 @@ def append_row(self, zero, position=""):
position: str
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
Expand All @@ -220,12 +223,10 @@ def insert_row(self, row_index, zero, position=""):
position: str
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
Loading