Skip to content

Commit 67d9e0c

Browse files
SMoraisAnsyspyansys-ci-botSamuelopez-ansys
authored
REFACTOR: Enforce design check in extensions (#6433)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Samuelopez-ansys <[email protected]>
1 parent 0ae7248 commit 67d9e0c

22 files changed

+316
-255
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enforce design check in extensions

src/ansys/aedt/core/extensions/hfss/move_it.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import ansys.aedt.core.extensions
3636
from ansys.aedt.core.extensions.misc import ExtensionCommon
3737
from ansys.aedt.core.extensions.misc import ExtensionCommonData
38+
from ansys.aedt.core.extensions.misc import ExtensionHFSSCommon
3839
from ansys.aedt.core.extensions.misc import get_aedt_version
3940
from ansys.aedt.core.extensions.misc import get_arguments
4041
from ansys.aedt.core.extensions.misc import get_port
@@ -62,7 +63,7 @@ class MoveItExtensionData(ExtensionCommonData):
6263
delay: float = EXTENSION_DEFAULT_ARGUMENTS["delay"]
6364

6465

65-
class MoveItExtension(ExtensionCommon):
66+
class MoveItExtension(ExtensionHFSSCommon):
6667
"""Extension for move it in AEDT."""
6768

6869
def __init__(self, withdraw: bool = False):
@@ -77,9 +78,6 @@ def __init__(self, withdraw: bool = False):
7778
)
7879
# Add private attributes and initialize them through __load_aedt_info
7980
self.__assignments = None
80-
self.__velocity = None
81-
self.__acceleration = None
82-
self.__delay = None
8381
self.__load_aedt_info()
8482

8583
# Tkinter widgets

src/ansys/aedt/core/extensions/hfss3dlayout/cutout.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import ansys.aedt.core.extensions.hfss3dlayout
3838
from ansys.aedt.core.extensions.misc import DEFAULT_PADDING
3939
from ansys.aedt.core.extensions.misc import SUN
40-
from ansys.aedt.core.extensions.misc import ExtensionCommon
4140
from ansys.aedt.core.extensions.misc import ExtensionCommonData
41+
from ansys.aedt.core.extensions.misc import ExtensionHFSS3DLayoutCommon
4242
from ansys.aedt.core.extensions.misc import get_aedt_version
4343
from ansys.aedt.core.extensions.misc import get_arguments
4444
from ansys.aedt.core.extensions.misc import get_port
@@ -77,7 +77,7 @@ class CutoutData(ExtensionCommonData):
7777
fix_disjoints: bool = EXTENSION_DEFAULT_ARGUMENTS["fix_disjoints"]
7878

7979

80-
class CutoutExtension(ExtensionCommon):
80+
class CutoutExtension(ExtensionHFSS3DLayoutCommon):
8181
"""Class to create a cutout in an HFSS 3D Layout design."""
8282

8383
def __init__(self, withdraw: bool = False):
@@ -94,7 +94,6 @@ def __init__(self, withdraw: bool = False):
9494
self.__objects_net = self.__load_objects_net()
9595
self.__widgets = {}
9696
self.__execute_cutout = False
97-
self.__check_design_type()
9897
self.add_extension_content()
9998

10099
def add_extension_content(self):
@@ -208,12 +207,6 @@ def execute_cutout(self):
208207
"""Get whether the cutout should be executed."""
209208
return self.__execute_cutout
210209

211-
def __check_design_type(self):
212-
"""Check if the active design is an HFSS 3D Layout design."""
213-
active_design = self.desktop.active_design()
214-
if active_design is None or active_design.GetDesignType() != "HFSS 3D Layout Design":
215-
raise AEDTRuntimeError("An HFSS 3D Layout design is needed for this extension.")
216-
217210
def __load_objects_net(self):
218211
"""Load objects by net from the EDB modeler."""
219212
res = defaultdict(list)

src/ansys/aedt/core/extensions/icepak/power_map_from_csv.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
from ansys.aedt.core import Icepak
3737
import ansys.aedt.core.extensions
3838
from ansys.aedt.core.extensions.misc import DEFAULT_PADDING
39-
from ansys.aedt.core.extensions.misc import ExtensionCommon
4039
from ansys.aedt.core.extensions.misc import ExtensionCommonData
40+
from ansys.aedt.core.extensions.misc import ExtensionIcepakCommon
4141
from ansys.aedt.core.extensions.misc import get_aedt_version
4242
from ansys.aedt.core.extensions.misc import get_arguments
4343
from ansys.aedt.core.extensions.misc import get_port
@@ -77,7 +77,7 @@ class PowerMapFromCSVExtensionData(ExtensionCommonData):
7777
source_unit_info: dict = field(default_factory=dict)
7878

7979

80-
class PowerMapFromCSVExtension(ExtensionCommon):
80+
class PowerMapFromCSVExtension(ExtensionIcepakCommon):
8181
"""Class to create a cutout in an HFSS 3D Layout design."""
8282

8383
def __init__(self, withdraw: bool = False):
@@ -89,7 +89,6 @@ def __init__(self, withdraw: bool = False):
8989
add_custom_content=False,
9090
)
9191
self.data: PowerMapFromCSVExtensionData = PowerMapFromCSVExtensionData()
92-
self.__check_design_type()
9392
self.add_extension_content()
9493

9594
def browse_file(self):
@@ -145,12 +144,6 @@ def __parse_data(self):
145144
self.data.source_unit_info = source_unit_info
146145
self.root.destroy()
147146

148-
def __check_design_type(self):
149-
"""Check if the active design is an Icepak design."""
150-
active_design = self.desktop.active_design()
151-
if active_design is None or active_design.GetDesignType() != "Icepak":
152-
raise AEDTRuntimeError(DESIGN_TYPE_ERROR_MSG)
153-
154147

155148
def create_powermaps_from_csv(ipk, csv_path: Path):
156149
"""Create powermap from an Icepak classic CSV file.

src/ansys/aedt/core/extensions/maxwell3d/create_coil.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import ansys.aedt.core.extensions
3333
from ansys.aedt.core.extensions.misc import ExtensionCommon
3434
from ansys.aedt.core.extensions.misc import ExtensionCommonData
35+
from ansys.aedt.core.extensions.misc import ExtensionMaxwell3DCommon
3536
from ansys.aedt.core.extensions.misc import get_aedt_version
3637
from ansys.aedt.core.extensions.misc import get_arguments
3738
from ansys.aedt.core.extensions.misc import get_port
@@ -90,7 +91,7 @@ class CoilExtensionData(ExtensionCommonData):
9091
looping_position: str = EXTENSION_DEFAULT_ARGUMENTS["looping_position"]
9192

9293

93-
class CoilExtension(ExtensionCommon):
94+
class CoilExtension(ExtensionMaxwell3DCommon):
9495
"""Extension to create coils in AEDT."""
9596

9697
def __init__(self, withdraw: bool = False):

src/ansys/aedt/core/extensions/misc.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def __init__(
122122
raise ValueError(f"Invalid theme color: {theme_color}. Use 'light' or 'dark'.")
123123

124124
self.root = self.__init_root(title, withdraw)
125+
self.root.protocol("WM_DELETE_WINDOW", self.__on_close)
125126
self.style: ttk.Style = ttk.Style()
126127
self.theme: ExtensionTheme = ExtensionTheme()
127128
self._widgets = {}
@@ -135,7 +136,7 @@ def __init__(
135136
if add_custom_content:
136137
self.add_extension_content()
137138

138-
self.root.protocol("WM_DELETE_WINDOW", self.__on_close)
139+
self.check_design_type()
139140

140141
def add_toggle_theme_button(self, parent, toggle_row, toggle_column):
141142
"""Create a button to toggle between light and dark themes."""
@@ -334,6 +335,70 @@ def add_extension_content(self):
334335
"""
335336
raise NotImplementedError("Subclasses must implement this method.")
336337

338+
@abstractmethod
339+
def check_design_type(self):
340+
"""Check the design type.
341+
342+
This method should be implemented by subclasses to add specific content
343+
to the extension UI.
344+
"""
345+
raise NotImplementedError("Subclasses must implement this method.")
346+
347+
348+
class ExtensionIcepakCommon(ExtensionCommon):
349+
"""Common methods for Icepak extensions."""
350+
351+
def check_design_type(self):
352+
"""Check if the active design is an Icepak design."""
353+
if self.aedt_application.design_type != "Icepak":
354+
raise AEDTRuntimeError("This extension can only be used with Icepak designs.")
355+
356+
357+
class ExtensionHFSSCommon(ExtensionCommon):
358+
"""Common methods for HFSS extensions."""
359+
360+
def check_design_type(self):
361+
"""Check if the active design is an HFSS design."""
362+
if self.aedt_application.design_type != "HFSS":
363+
raise AEDTRuntimeError("This extension can only be used with HFSS designs.")
364+
365+
366+
class ExtensionHFSS3DLayoutCommon(ExtensionCommon):
367+
"""Common methods for HFSS 3D Layout extensions."""
368+
369+
def check_design_type(self):
370+
"""Check if the active design is an HFSS 3D Layout design."""
371+
if self.aedt_application.design_type != "HFSS 3D Layout Design":
372+
raise AEDTRuntimeError("This extension can only be used with HFSS 3D Layout designs.")
373+
374+
375+
class ExtensionMaxwell2DCommon(ExtensionCommon):
376+
"""Common methods for Maxwell 2D extensions."""
377+
378+
def check_design_type(self):
379+
"""Check if the active design is a Maxwell 2D design."""
380+
if self.aedt_application.design_type != "Maxwell 2D":
381+
raise AEDTRuntimeError("This extension can only be used with Maxwell 2D designs.")
382+
383+
384+
class ExtensionMaxwell3DCommon(ExtensionCommon):
385+
"""Common methods for Maxwell 3D extensions."""
386+
387+
def check_design_type(self):
388+
"""Check if the active design is a Maxwell 3D design."""
389+
if self.aedt_application.design_type != "Maxwell 3D":
390+
raise AEDTRuntimeError("This extension can only be used with Maxwell 3D designs.")
391+
392+
393+
class ExtensionProjectCommon(ExtensionCommon):
394+
"""Common methods for project-level extensions."""
395+
396+
def check_design_type(self):
397+
"""Check the active design type.
398+
399+
Not required for extension at project level."""
400+
pass
401+
337402

338403
def create_default_ui(title, withdraw=False):
339404
import tkinter

src/ansys/aedt/core/extensions/project/advanced_fields_calculator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import ansys.aedt.core.extensions
3535
from ansys.aedt.core.extensions.misc import ExtensionCommon
3636
from ansys.aedt.core.extensions.misc import ExtensionCommonData
37+
from ansys.aedt.core.extensions.misc import ExtensionProjectCommon
3738
from ansys.aedt.core.extensions.misc import get_aedt_version
3839
from ansys.aedt.core.extensions.misc import get_arguments
3940
from ansys.aedt.core.extensions.misc import get_port
@@ -61,7 +62,7 @@ class AdvancedFieldsCalculatorExtensionData(ExtensionCommonData):
6162
assignments: list = field(default_factory=lambda: [])
6263

6364

64-
class AdvancedFieldsCalculatorExtension(ExtensionCommon):
65+
class AdvancedFieldsCalculatorExtension(ExtensionProjectCommon):
6566
"""Extension for advanced fields calculator in AEDT."""
6667

6768
def __init__(self, withdraw: bool = False):

src/ansys/aedt/core/extensions/project/configure_layout.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import ansys.aedt.core
4040
from ansys.aedt.core.examples.downloads import download_file
4141
from ansys.aedt.core.extensions.misc import ExtensionCommon
42+
from ansys.aedt.core.extensions.misc import ExtensionProjectCommon
4243
from ansys.aedt.core.extensions.misc import get_aedt_version
4344
from ansys.aedt.core.extensions.misc import get_arguments
4445
from ansys.aedt.core.extensions.misc import get_port
@@ -368,7 +369,7 @@ def export_config_from_design(self):
368369
messagebox.showinfo("Message", "Failed")
369370

370371

371-
class ConfigureLayoutExtension(ExtensionCommon):
372+
class ConfigureLayoutExtension(ExtensionProjectCommon):
372373
def __init__(self, withdraw: bool = False):
373374
self.tabs = {}
374375
super().__init__(

src/ansys/aedt/core/extensions/project/points_cloud.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from ansys.aedt.core import get_pyaedt_app
3535
from ansys.aedt.core.extensions.misc import ExtensionCommon
3636
from ansys.aedt.core.extensions.misc import ExtensionCommonData
37+
from ansys.aedt.core.extensions.misc import ExtensionProjectCommon
3738
from ansys.aedt.core.extensions.misc import get_aedt_version
3839
from ansys.aedt.core.extensions.misc import get_arguments
3940
from ansys.aedt.core.extensions.misc import get_port
@@ -62,7 +63,7 @@ class PointsCloudExtensionData(ExtensionCommonData):
6263
output_file: str = EXTENSION_DEFAULT_ARGUMENTS["output_file"]
6364

6465

65-
class PointsCloudExtension(ExtensionCommon):
66+
class PointsCloudExtension(ExtensionProjectCommon):
6667
"""Extension for point cloud generator in AEDT."""
6768

6869
def __init__(self, withdraw: bool = False):

src/ansys/aedt/core/extensions/project/via_design.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from ansys.aedt.core.extensions.misc import DEFAULT_PADDING
4242
from ansys.aedt.core.extensions.misc import SUN
43-
from ansys.aedt.core.extensions.misc import ExtensionCommon
43+
from ansys.aedt.core.extensions.misc import ExtensionProjectCommon
4444
from ansys.aedt.core.extensions.misc import get_aedt_version
4545
from ansys.aedt.core.extensions.misc import get_arguments
4646
from ansys.aedt.core.extensions.misc import get_port
@@ -77,7 +77,7 @@ class ExportExampleData:
7777
]
7878

7979

80-
class ViaDesignExtension(ExtensionCommon):
80+
class ViaDesignExtension(ExtensionProjectCommon):
8181
"""Extension for advanced fields calculator in AEDT."""
8282

8383
def __init__(self, withdraw: bool = False):

0 commit comments

Comments
 (0)