Skip to content

Commit db7d43e

Browse files
ramin4667pyansys-ci-botjsalant22
authored
FEAT: Add function to emit to list all component types (#6210)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Josh Salant <101826634+jsalant22@users.noreply.github.com>
1 parent dba8945 commit db7d43e

4 files changed

Lines changed: 61 additions & 8 deletions

File tree

doc/changelog.d/6210.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add function to emit to list all component types

src/ansys/aedt/core/modeler/circuits/primitives_circuit.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,15 +1676,21 @@ def __getitem__(self, compname):
16761676
Circuit Component Info.
16771677
16781678
"""
1679-
items = self.find_components("*" + compname)
1680-
if items and len(items) == 1:
1681-
return self.components[items[0]]
1682-
elif len(items) > 1:
1683-
self._component_manager._logger.warning("Multiple components found.")
1684-
return None
1679+
if self._component_manager.design_type == "EMIT":
1680+
items = self.find_components("*" + compname + "*")
1681+
# Return a list of components
1682+
return [self.components[item] for item in items] if items else []
16851683
else:
1686-
self._component_manager._logger.warning("Component not found.")
1687-
return None
1684+
items = self.find_components("*" + compname)
1685+
# Return a single component or None
1686+
if items and len(items) == 1:
1687+
return self.components[items[0]]
1688+
elif len(items) > 1:
1689+
self._component_manager._logger.warning("Multiple components found.")
1690+
return None
1691+
else:
1692+
self._component_manager._logger.warning("Component not found.")
1693+
return None
16881694

16891695
def __init__(self, component_manager):
16901696
self._component_manager = component_manager

src/ansys/aedt/core/modeler/circuits/primitives_emit.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from ansys.aedt.core.emit_core import emit_constants as emit_consts
2929
import ansys.aedt.core.generic.constants as consts
3030
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
31+
from ansys.aedt.core.modeler.circuits.primitives_circuit import ComponentCatalog
3132

3233

3334
class EmitComponents(object):
@@ -170,6 +171,10 @@ def __getitem__(self, compname):
170171

171172
return None
172173

174+
@property
175+
def _logger(self):
176+
return self._app.logger
177+
173178
def __len__(self):
174179
return len(self.components)
175180

@@ -181,7 +186,40 @@ def __init__(self, parent, modeler):
181186
self.modeler = modeler
182187
self._currentId = 0
183188
self.components = defaultdict(EmitComponent)
189+
self.include_personal_lib = False
184190
self.refresh_all_ids()
191+
self._components_catalog = None
192+
self._app = modeler._app
193+
194+
@property
195+
def include_personal_library(self, value=None):
196+
"""Include personal library."""
197+
if value is not None:
198+
self.include_personal_lib = value
199+
return self.include_personal_lib
200+
201+
@include_personal_library.setter
202+
def include_personal_library(self, value):
203+
self.include_personal_lib = value
204+
205+
@property
206+
def design_libray(self):
207+
"""Design library."""
208+
if self.include_personal_lib:
209+
return "PersonalLib"
210+
return "EMIT Elements"
211+
212+
@property
213+
def components_catalog(self):
214+
"""System library component catalog with all information.
215+
216+
Returns
217+
-------
218+
:class:`ansys.aedt.core.modeler.cad.primitivesCircuit.ComponentCatalog`
219+
"""
220+
if not self._components_catalog:
221+
self._components_catalog = ComponentCatalog(self)
222+
return self._components_catalog
185223

186224
@pyaedt_function_handler()
187225
def create_component(self, component_type, name=None, library=None):

tests/system/solvers/test_26_emit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,3 +1292,11 @@ def count_license_actions(license_file_path):
12921292
expected_checkins = checkins_per_run * (number_of_runs + 1)
12931293

12941294
assert checkouts == expected_checkouts and checkins == expected_checkins
1295+
1296+
@pytest.mark.skipif(config["desktopVersion"] < "2025.1", reason="Skipped on versions earlier than 2024 R2.")
1297+
def test_25_components_catalog(self, add_app):
1298+
self.aedtapp = add_app(project_name="catalog-list", application=Emit)
1299+
comp_list = self.aedtapp.modeler.components.components_catalog["LTE"]
1300+
assert len(comp_list) == 14
1301+
assert comp_list[12].name == "LTE BTS"
1302+
assert comp_list[13].name == "LTE Mobile Station"

0 commit comments

Comments
 (0)