Skip to content

Commit

Permalink
Deprecate checkifmaterialexists
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuelopez-ansys committed Nov 11, 2024
1 parent 1dbffaf commit 8335d39
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def assignmaterial_from_sherlock_files(self, component_file, material_file):
list_mat_obj += [rd for rd, md in zip(component_data["Ref Des"], component_data["Material"]) if md == mat]
list_mat_obj = [mo for mo in list_mat_obj if mo in all_objs]
if list_mat_obj:
newmat = self.materials.checkifmaterialexists(mat)
newmat = self.materials.exists_material(mat)

Check warning on line 955 in src/ansys/aedt/core/application/analysis_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/application/analysis_3d.py#L955

Added line #L955 was not covered by tests
if not newmat:
newmat = self.materials.add_material(mat.lower())
if "Material Density" in material_data:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/generic/configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ def import_config(self, config_file, *args):
if self.options.import_materials and dict_in.get("materials", None):
self.results.import_materials = True
for el, val in dict_in["materials"].items():
if self._app.materials.checkifmaterialexists(el):
if self._app.materials.exists_material(el):
newname = generate_unique_name(el)
self._app.logger.warning("Material %s already exists. Renaming to %s", el, newname)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modeler/advanced_cad/stackup_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, application, material_name, cloned_material_name, list_of_pro
self._magnetic_loss_tangent = None
self._material = None
self._material_name = None
if application.materials.checkifmaterialexists(material_name):
if application.materials.exists_material(material_name):

Check warning on line 247 in src/ansys/aedt/core/modeler/advanced_cad/stackup_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/advanced_cad/stackup_3d.py#L247

Added line #L247 was not covered by tests
if not list_of_properties:
cloned_material = application.materials.duplicate_material(material_name, cloned_material_name)
permittivity = cloned_material.permittivity.value
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modeler/cad/object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ def material_name(self):

@material_name.setter
def material_name(self, mat):
matobj = self._primitives._materials.checkifmaterialexists(mat)
matobj = self._primitives._materials.exists_material(mat)
mat_value = None
if matobj:
mat_value = chr(34) + matobj.name + chr(34)
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -6326,7 +6326,7 @@ def update_geometry_property(self, assignment, name=None, value=None):

# Handle special cases for material
if property_key == "material_name" and isinstance(value, str):
matobj = self._materials.checkifmaterialexists(value)
matobj = self._materials.exists_material(value)
if matobj:
value = f'"{matobj.name}"'
elif "[" in value or "(" in value: # pragma: no cover
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/modeler/cad/primitives_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3086,7 +3086,7 @@ def check_choke_values(self, input_dir, create_another_file=True):
try:
core_material = str(values["Core"]["Material"])
if len(core_material) > 0:
if self.materials.checkifmaterialexists(core_material):
if self.materials.exists_material(core_material):
values["Core"]["Material"] = self.materials._get_aedt_case_name(core_material)
else:
self.logger.error(
Expand All @@ -3109,7 +3109,7 @@ def check_choke_values(self, input_dir, create_another_file=True):
try:
winding_material = str(values["Outer Winding"]["Material"])
if len(winding_material) > 0:
if self.materials.checkifmaterialexists(winding_material):
if self.materials.exists_material(winding_material):
values["Outer Winding"]["Material"] = self.materials._get_aedt_case_name(winding_material)
else:
self.logger.error(
Expand Down
35 changes: 32 additions & 3 deletions src/ansys/aedt/core/modules/material_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __iter__(self):
return iter(self.material_keys.values()) if sys.version_info.major > 2 else self.material_keys.itervalues()

def __getitem__(self, item):
matobj = self.checkifmaterialexists(item)
matobj = self.exists_material(item)
if matobj:
return matobj
elif item in list(self.surface_material_keys.keys()):
Expand Down Expand Up @@ -243,6 +243,35 @@ def _get_surface_materials(self):
def checkifmaterialexists(self, material):
"""Check if a material exists in AEDT or PyAEDT Definitions.
.. deprecated:: 0.11.4
Use :func:`exists_material` method instead.
Parameters
----------
material : str
Name of the material. If the material exists and is not in the materials database,
it is added to this database.
Returns
-------
:class:`ansys.aedt.core.modules.material.Material`
Material object if present, ``False`` when failed.
References
----------
>>> oDefinitionManager.GetProjectMaterialNames
>>> oMaterialManager.GetData
"""
warnings.warn(

Check warning on line 266 in src/ansys/aedt/core/modules/material_lib.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modules/material_lib.py#L266

Added line #L266 was not covered by tests
"`checkifmaterialexists` is deprecated. Use `exists_material` method instead.", DeprecationWarning
)
return self.exists_material(material=material)

Check warning on line 269 in src/ansys/aedt/core/modules/material_lib.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modules/material_lib.py#L269

Added line #L269 was not covered by tests

@pyaedt_function_handler()
def exists_material(self, material):
"""Check if a material exists in AEDT or PyAEDT Definitions.
Parameters
----------
material : str
Expand Down Expand Up @@ -293,7 +322,7 @@ def check_thermal_modifier(self, material):
``True`` when successful, ``False`` when failed.
"""
omat = self.checkifmaterialexists(material)
omat = self.exists_material(material)
if omat:
for el in MatProperties.aedtname:
if omat.__dict__["_" + el].thermalmodifier:
Expand Down Expand Up @@ -451,7 +480,7 @@ def add_material_sweep(self, assignment, name):
"""
matsweep = []
for mat in assignment:
matobj = self.checkifmaterialexists(mat)
matobj = self.exists_material(mat)
if matobj:
matsweep.append(matobj)

Expand Down

0 comments on commit 8335d39

Please sign in to comment.