Skip to content

Commit 94e7c1f

Browse files
FIX: Insert row fix for tables (#5931)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent cb6ad4c commit 94e7c1f

File tree

9 files changed

+309
-103
lines changed

9 files changed

+309
-103
lines changed

doc/changelog.d/5931.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Insert row fix for tables

src/ansys/aedt/core/filtersolutions_core/lumped_termination_impedance_table.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def _define_termination_impedance_dll_functions(self):
157157
self._dll.getLumpedComplexCompOrder.argtypes = [POINTER(c_int), c_bool]
158158
self._dll.getLumpedComplexCompOrder.restype = c_int
159159

160+
def _bytes_or_none(self, str_value):
161+
if str_value:
162+
return bytes(str_value, "ascii")
163+
return None
164+
160165
def table_type_to_bool(self):
161166
"""Set a flag to recognize source and load complex table.
162167
@@ -190,7 +195,7 @@ def row(self, row_index):
190195
Parameters
191196
----------
192197
row_index: int
193-
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``99``.
198+
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``149``.
194199
195200
Returns
196201
-------
@@ -216,33 +221,30 @@ def row(self, row_index):
216221
imag_value_string = imag_value_buffer.value.decode("utf-8")
217222
return frequency_value_string, real_value_string, imag_value_string
218223

219-
def update_row(self, row_index, frequency="", real="", imag=""):
224+
def update_row(self, row_index, frequency=None, real=None, imag=None):
220225
"""Update frequency and complex impedance at a specified index in the complex impedance table.
221226
222227
Parameters
223228
----------
224229
row_index: int
225-
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``99``.
230+
Row index on complex impedance table, starting at ``0`` and with a maximum value of ``149``.
226231
frequency: str, optional
227232
The frequency value to update. If not specified, it remains unchanged.
228233
real: str, optional
229234
The real part of the complex impedance to update. If not specified, it remains unchanged.
230235
imag: str, optional
231236
The imaginary part of the complex impedance to update. If not specified, it remains unchanged.
232237
"""
233-
frequency_bytes_value = bytes(frequency, "ascii")
234-
real_bytes_value = bytes(real, "ascii")
235-
imag_bytes_value = bytes(imag, "ascii")
236238
status = self._dll.updateComplexTableRow(
237239
row_index,
238-
frequency_bytes_value,
239-
real_bytes_value,
240-
imag_bytes_value,
240+
self._bytes_or_none(frequency),
241+
self._bytes_or_none(real),
242+
self._bytes_or_none(imag),
241243
self.table_type_to_bool(),
242244
)
243245
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
244246

245-
def append_row(self, frequency, real, imag):
247+
def append_row(self, frequency=None, real=None, imag=None):
246248
"""Append frequency and complex impedance values to the last row of
247249
both the source and load complex impedance table.
248250
@@ -256,39 +258,33 @@ def append_row(self, frequency, real, imag):
256258
imag: str
257259
The imaginary part of the complex impedance to append.
258260
"""
259-
frequency_bytes_value = bytes(frequency, "ascii")
260-
real_bytes_value = bytes(real, "ascii")
261-
imag_bytes_value = bytes(imag, "ascii")
262261
status = self._dll.appendComplexTableRow(
263-
frequency_bytes_value,
264-
real_bytes_value,
265-
imag_bytes_value,
262+
self._bytes_or_none(frequency),
263+
self._bytes_or_none(real),
264+
self._bytes_or_none(imag),
266265
self.table_type_to_bool(),
267266
)
268267
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
269268

270-
def insert_row(self, row_index, frequency, real, imag):
269+
def insert_row(self, row_index, frequency=None, real=None, imag=None):
271270
"""Insert frequency and complex impedance values at a specified index in the complex impedance table.
272271
273272
Parameters
274273
----------
275274
row_index : int
276-
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``99``.
275+
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``149``.
277276
frequency : str
278277
The frequency value to insert.
279278
real : str
280279
The real part of the complex impedance to insert.
281280
imag : str
282281
The imaginary part of the complex impedance to insert.
283282
"""
284-
frequency_bytes_value = bytes(frequency, "ascii")
285-
real_bytes_value = bytes(real, "ascii")
286-
imag_bytes_value = bytes(imag, "ascii")
287283
status = self._dll.insertComplexTableRow(
288284
row_index,
289-
frequency_bytes_value,
290-
real_bytes_value,
291-
imag_bytes_value,
285+
self._bytes_or_none(frequency),
286+
self._bytes_or_none(real),
287+
self._bytes_or_none(imag),
292288
self.table_type_to_bool(),
293289
)
294290
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
@@ -299,7 +295,7 @@ def remove_row(self, row_index):
299295
Parameters
300296
----------
301297
row_index : int
302-
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``99``.
298+
Row index in the complex impedance table, starting at ``0`` and with a maximum value of ``149``.
303299
"""
304300
status = self._dll.removeComplexTableRow(row_index, self.table_type_to_bool())
305301
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

src/ansys/aedt/core/filtersolutions_core/multiple_bands_table.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ def _define_multiple_bands_dll_functions(self):
6565
self._dll.removeMultipleBandsTableRow.argtype = c_int
6666
self._dll.removeMultipleBandsTableRow.restype = c_int
6767

68+
def _bytes_or_none(self, str_value):
69+
if str_value:
70+
return bytes(str_value, "ascii")
71+
return None
72+
6873
@property
6974
def row_count(self) -> int:
7075
"""Total number of rows present in the multiple bands table.
@@ -105,7 +110,7 @@ def row(self, row_index):
105110
upper_value_string = upper_value_buffer.value.decode("utf-8")
106111
return lower_value_string, upper_value_string
107112

108-
def update_row(self, row_index, lower_frequency="", upper_frequency=""):
113+
def update_row(self, row_index, lower_frequency=None, upper_frequency=None):
109114
"""Update lower and upper frequency values for a row in the multiple bands table.
110115
111116
Parameters
@@ -119,12 +124,14 @@ def update_row(self, row_index, lower_frequency="", upper_frequency=""):
119124
New upper frequency value to set for the row.
120125
If this value is not provided, the row's upper frequency remains unchanged.
121126
"""
122-
lower_bytes_value = bytes(lower_frequency, "ascii")
123-
upper_bytes_value = bytes(upper_frequency, "ascii")
124-
status = self._dll.updateMultipleBandsTableRow(row_index, lower_bytes_value, upper_bytes_value)
127+
status = self._dll.updateMultipleBandsTableRow(
128+
row_index,
129+
self._bytes_or_none(lower_frequency),
130+
self._bytes_or_none(upper_frequency),
131+
)
125132
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
126133

127-
def append_row(self, lower_frequency, upper_frequency):
134+
def append_row(self, lower_frequency=None, upper_frequency=None):
128135
"""Append a new row with specified lower and upper frequency values to the end of the multiple bands table.
129136
130137
Parameters
@@ -134,12 +141,13 @@ def append_row(self, lower_frequency, upper_frequency):
134141
upper_frequency: str
135142
Upper frequency value for the new row.
136143
"""
137-
lower_bytes_value = bytes(lower_frequency, "ascii")
138-
upper_bytes_value = bytes(upper_frequency, "ascii")
139-
status = self._dll.appendMultipleBandsTableRow(lower_bytes_value, upper_bytes_value)
144+
status = self._dll.appendMultipleBandsTableRow(
145+
self._bytes_or_none(lower_frequency),
146+
self._bytes_or_none(upper_frequency),
147+
)
140148
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
141149

142-
def insert_row(self, row_index, lower_frequency, upper_frequency):
150+
def insert_row(self, row_index, lower_frequency=None, upper_frequency=None):
143151
"""Insert lower and upper frequencies in a given row.
144152
145153
Parameters
@@ -151,9 +159,11 @@ def insert_row(self, row_index, lower_frequency, upper_frequency):
151159
upper_frequency: str
152160
Upper frequency value to insert.
153161
"""
154-
lower_bytes_value = bytes(lower_frequency, "ascii")
155-
upper_bytes_value = bytes(upper_frequency, "ascii")
156-
status = self._dll.insertMultipleBandsTableRow(row_index, lower_bytes_value, upper_bytes_value)
162+
status = self._dll.insertMultipleBandsTableRow(
163+
row_index,
164+
self._bytes_or_none(lower_frequency),
165+
self._bytes_or_none(upper_frequency),
166+
)
157167
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
158168

159169
def remove_row(self, row_index):

src/ansys/aedt/core/filtersolutions_core/optimization_goals_table.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,42 @@ def _define_optimization_goals_dll_functions(self):
8383
self._dll.getOptimizationGoalDefinitionRowCount.argtype = POINTER(c_int)
8484
self._dll.getOptimizationGoalDefinitionRowCount.restype = c_int
8585

86-
self._dll.getOptimizationGoalDefinitionRow.argtype = [c_int, POINTER(c_char_p), c_int]
86+
self._dll.getOptimizationGoalDefinitionRow.argtypes = [c_int, c_char_p, c_int]
8787
self._dll.getOptimizationGoalDefinitionRow.restype = c_int
8888

89-
self._dll.updateOptimizationGoalDefinitionRow.argtype = [c_int, c_int, c_char_p]
89+
self._dll.updateOptimizationGoalDefinitionRow.argtypes = [
90+
c_int,
91+
c_char_p,
92+
c_char_p,
93+
c_char_p,
94+
c_char_p,
95+
c_char_p,
96+
c_char_p,
97+
c_char_p,
98+
]
9099
self._dll.updateOptimizationGoalDefinitionRow.restype = c_int
91100

92-
self._dll.appendOptimizationGoalDefinitionRow.argtype = [c_int, c_char_p]
101+
self._dll.appendOptimizationGoalDefinitionRow.argtypes = [
102+
c_char_p,
103+
c_char_p,
104+
c_char_p,
105+
c_char_p,
106+
c_char_p,
107+
c_char_p,
108+
c_char_p,
109+
]
93110
self._dll.appendOptimizationGoalDefinitionRow.restype = c_int
94111

95-
self._dll.insertOptimizationGoalDefinitionRow.argtypes = [c_int, c_char_p, c_char_p]
112+
self._dll.insertOptimizationGoalDefinitionRow.argtypes = [
113+
c_int,
114+
c_char_p,
115+
c_char_p,
116+
c_char_p,
117+
c_char_p,
118+
c_char_p,
119+
c_char_p,
120+
c_char_p,
121+
]
96122
self._dll.insertOptimizationGoalDefinitionRow.restype = c_int
97123

98124
self._dll.removeOptimizationGoalDefinitionRow.argtype = c_int
@@ -138,7 +164,7 @@ def row(self, row_index) -> list:
138164
"""
139165
row_parameter_buffer = create_string_buffer(1024)
140166
# Call the DLL function. Assuming it fills the buffer with comma-separated values.
141-
status = self._dll.getOptimizationGoalDefinitionRow(row_index, byref(row_parameter_buffer), 1024)
167+
status = self._dll.getOptimizationGoalDefinitionRow(row_index, row_parameter_buffer, 1024)
142168
self._dll_interface.raise_error(status)
143169
# Decode the buffer to a Python string and split by comma to get a list.
144170
row_parameters = row_parameter_buffer.value.decode("utf-8").split("|")
@@ -210,19 +236,19 @@ def append_row(
210236
211237
Parameters
212238
----------
213-
lower_frequency: str, optional
239+
lower_frequency: str
214240
Lower frequency value to set.
215-
upper_frequency: str, optional
241+
upper_frequency: str
216242
Upper frequency value to set.
217-
goal_value: str, optional
243+
goal_value: str
218244
Goal value to set.
219-
condition: str, optional
245+
condition: str
220246
Condition value to set.
221-
parameter_name: str, optional
247+
parameter_name: str
222248
Parameter name value to set.
223-
weight: str, optional
249+
weight: str
224250
Weight value to set.
225-
enabled: str, optional
251+
enabled: str
226252
Enabled value to set.
227253
"""
228254
status = self._dll.appendOptimizationGoalDefinitionRow(
@@ -254,19 +280,19 @@ def insert_row(
254280
----------
255281
row_index: int
256282
Index of the row. Valid values range from ``0`` to ``49``, inclusive.
257-
lower_frequency: str, optional
283+
lower_frequency: str
258284
Lower frequency value.
259-
upper_frequency: str, optional
285+
upper_frequency: str
260286
Upper frequency value.
261-
goal_value: str, optional
287+
goal_value: str
262288
Goal value.
263-
condition: str, optional
289+
condition: str
264290
Condition value.
265-
parameter_name: str, optional
291+
parameter_name: str
266292
Parameter name.
267-
weight: str, optional
293+
weight: str
268294
Weight value.
269-
enabled: str, optional
295+
enabled: str
270296
Enabled value.
271297
"""
272298
status = self._dll.insertOptimizationGoalDefinitionRow(

src/ansys/aedt/core/filtersolutions_core/transmission_zeros.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def table_format_to_bool(self):
123123
else:
124124
return True
125125

126+
def _bytes_or_none(self, str_value):
127+
if str_value:
128+
return bytes(str_value, "ascii")
129+
return None
130+
126131
@property
127132
def row_count(self) -> int:
128133
"""Number of transmission zeros in the transmission zeros table.
@@ -167,7 +172,7 @@ def row(self, row_index):
167172
position_value_string = position_value_buffer.value.decode("utf-8")
168173
return zero_value_string, position_value_string
169174

170-
def update_row(self, row_index, zero="", position=""):
175+
def update_row(self, row_index, zero=None, position=None):
171176
"""Update the transmission zero ratio or bandwidth and its position for a row in the transmission zeros table.
172177
173178
Parameters
@@ -181,17 +186,15 @@ def update_row(self, row_index, zero="", position=""):
181186
New position of the element causing the transmission zero in the circuit.
182187
If no value is specified, the value remains unchanged.
183188
"""
184-
zero_bytes_value = bytes(zero, "ascii")
185-
position_bytes_value = bytes(position, "ascii")
186189
status = self._dll.updateTransmissionZerosTableRow(
187190
row_index,
188-
zero_bytes_value,
189-
position_bytes_value,
191+
self._bytes_or_none(zero),
192+
self._bytes_or_none(position),
190193
self.table_format_to_bool(),
191194
)
192195
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
193196

194-
def append_row(self, zero, position=""):
197+
def append_row(self, zero=None, position=None):
195198
"""Append a new row that includes the ratio or bandwidth and position.
196199
197200
Parameters
@@ -201,14 +204,14 @@ def append_row(self, zero, position=""):
201204
position: str
202205
Position of the element creating transmission zero in the associated circuit.
203206
"""
204-
zero_bytes_value = bytes(zero, "ascii")
205-
position_bytes_value = bytes(position, "ascii")
206207
status = self._dll.appendTransmissionZerosTableRow(
207-
zero_bytes_value, position_bytes_value, self.table_format_to_bool()
208+
self._bytes_or_none(zero),
209+
self._bytes_or_none(position),
210+
self.table_format_to_bool(),
208211
)
209212
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)
210213

211-
def insert_row(self, row_index, zero, position=""):
214+
def insert_row(self, row_index, zero=None, position=None):
212215
"""Insert a new row that includes the ratio or bandwidth and the position.
213216
214217
Parameters
@@ -220,12 +223,10 @@ def insert_row(self, row_index, zero, position=""):
220223
position: str
221224
Position of the element creating transmission zero in the associated circuit.
222225
"""
223-
zero_bytes_value = bytes(zero, "ascii")
224-
position_bytes_value = bytes(position, "ascii")
225226
status = self._dll.insertTransmissionZerosTableRow(
226227
row_index,
227-
zero_bytes_value,
228-
position_bytes_value,
228+
self._bytes_or_none(zero),
229+
self._bytes_or_none(position),
229230
self.table_format_to_bool(),
230231
)
231232
ansys.aedt.core.filtersolutions_core._dll_interface().raise_error(status)

0 commit comments

Comments
 (0)