Skip to content

Commit

Permalink
FEAT: variable description (#896)
Browse files Browse the repository at this point in the history
* FEATURE: variable description

* MISC: Auto fixes from pre-commit.com hooks

For more information, see https://pre-commit.ci

* Update tests/legacy/system/test_edb.py

Co-authored-by: Sébastien Morais <[email protected]>

* fix minor

---------

Co-authored-by: ring630 <@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sébastien Morais <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent 5b3d28f commit 056fb81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/pyedb/dotnet/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3180,7 +3180,7 @@ def get_variable(self, variable_name):
self.logger.info("Variable %s doesn't exists.", variable_name)
return None

def add_project_variable(self, variable_name, variable_value):
def add_project_variable(self, variable_name, variable_value, description=""):
"""Add a variable to edb database (project). The variable will have the prefix `$`.
..note::
Expand All @@ -3192,6 +3192,8 @@ def add_project_variable(self, variable_name, variable_value):
Name of the variable. Name can be provided without ``$`` prefix.
variable_value : str, float
Value of the variable with units.
description : str, optional
Description of the variable.
Returns
-------
Expand All @@ -3210,9 +3212,11 @@ def add_project_variable(self, variable_name, variable_value):
"""
if not variable_name.startswith("$"):
variable_name = "${}".format(variable_name)
return self.add_design_variable(variable_name=variable_name, variable_value=variable_value)
return self.add_design_variable(
variable_name=variable_name, variable_value=variable_value, description=description
)

def add_design_variable(self, variable_name, variable_value, is_parameter=False):
def add_design_variable(self, variable_name, variable_value, is_parameter=False, description=""):
"""Add a variable to edb. The variable can be a design one or a project variable (using ``$`` prefix).
..note::
Expand All @@ -3228,7 +3232,8 @@ def add_design_variable(self, variable_name, variable_value, is_parameter=False)
is_parameter : bool, optional
Whether to add the variable as a local variable. The default is ``False``.
When ``True``, the variable is added as a parameter default.
description : str, optional
Description of the variable.
Returns
-------
tuple
Expand All @@ -3250,6 +3255,8 @@ def add_design_variable(self, variable_name, variable_value, is_parameter=False)
var_server = self.variable_exists(variable_name)
if not var_server[0]:
var_server[1].AddVariable(variable_name, self.edb_value(variable_value), is_parameter)
if description:
var_server[1].SetVariableDescription(variable_name, description)
return True, var_server[1]
self.logger.error("Variable %s already exists.", variable_name)
return False, var_server[1]
Expand Down
10 changes: 8 additions & 2 deletions tests/legacy/system/test_edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ def test_hfss_mesh_operations(self):

def test_add_variables(self):
"""Add design and project variables."""
result, var_server = self.edbapp.add_design_variable("my_variable", "1mm")
result, var_server = self.edbapp.add_design_variable("variable_no_description", "1mm")
assert result
assert var_server
assert self.edbapp.variables["variable_no_description"].description == ""
result, var_server = self.edbapp.add_design_variable("my_variable", "1mm", description="var_1")
assert result
assert var_server
assert self.edbapp.variables["my_variable"].description == "var_1"
result, var_server = self.edbapp.add_design_variable("my_variable", "1mm")
assert not result
assert self.edbapp.modeler.parametrize_trace_width("A0_N")
Expand All @@ -185,7 +190,8 @@ def test_add_variables(self):
assert var_server.IsVariableParameter("my_parameter")
result, var_server = self.edbapp.add_design_variable("my_parameter", "2mm", True)
assert not result
result, var_server = self.edbapp.add_project_variable("$my_project_variable", "3mm")
result, var_server = self.edbapp.add_project_variable("$my_project_variable", "3mm", description="var_2")
assert self.edbapp.variables["$my_project_variable"].description == "var_2"
assert result
assert var_server
result, var_server = self.edbapp.add_project_variable("$my_project_variable", "3mm")
Expand Down

0 comments on commit 056fb81

Please sign in to comment.