Skip to content

FIX: fix extension manager + add missing icon fields distribution #6066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 24, 2025
1 change: 1 addition & 0 deletions doc/changelog.d/6066.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix extension manager + add missing icon fields distribution
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[FieldsDistribution]
name = "Fields distribution"
script = "../maxwell3d/fields_distribution.py"
icon = "../maxwell3d/images/large/fields_distribution.png"
template = "run_pyaedt_toolkit_script"
pip = ""
63 changes: 36 additions & 27 deletions src/ansys/aedt/core/workflows/maxwell3d/fields_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from pathlib import Path
import tkinter as tk
from tkinter.font import Font

import ansys.aedt.core
from ansys.aedt.core.generic.design_types import get_pyaedt_app
Expand Down Expand Up @@ -52,24 +51,17 @@
extension_description = "Fields distribution"


def _text_size(path, entry): # pragma: no cover
def _text_size(theme, path, entry): # pragma: no cover
# Calculate the length of the text
text_length = len(path)

height = 1
# Adjust font size based on text length
if text_length < 20:
font_size = 20
elif text_length < 50:
font_size = 15
else:
font_size = 10

# Set the font size
text_font = Font(size=font_size)
entry.configure(font=text_font)
if text_length > 50:
height += 1

# Adjust the width of the Text widget based on text length
entry.configure(width=max(20, text_length // 2))
# Adjust the width and the height of the Text widget based on text length
entry.configure(height=height, width=max(40, text_length // 2), font=theme.default_font)

entry.insert(tk.END, path)

Expand Down Expand Up @@ -120,8 +112,13 @@ def frontend(): # pragma: no cover
)
point.delete()

project_name = maxwell.project_name
design_name = maxwell.design_name

# Create UI
master = tk.Tk()
master.project_name = project_name
master.design_name = design_name

# Configure the grid to expand with the window
master.grid_rowconfigure(0, weight=1)
Expand Down Expand Up @@ -216,6 +213,8 @@ def frontend(): # pragma: no cover
export_file_entry = tk.Text(export_file_frame, width=40, height=1, wrap=tk.WORD)
export_file_entry.pack(expand=True, fill=tk.BOTH, side=tk.LEFT)

maxwell.release_desktop(False, False)

def toggle_theme():
if master.theme == "light":
set_dark_theme()
Expand Down Expand Up @@ -308,13 +307,17 @@ def callback(button_id):
master.flag = True
master.destroy()
elif button_id == 2:
master.flag = False
setup_name = master.solution_option.split(":")[0].strip()
if maxwell.get_setup(setup_name) and not maxwell.get_setup(setup_name).is_solved:
messagebox.showerror("Error", "Selected setup is not solved.")
return None
ansys.aedt.core.Desktop(
new_desktop=False,
specified_version=version,
port=port,
aedt_process_id=aedt_process_id,
student_version=is_student,
)

maxwell.post.plot_field(
master.flag = False
maxwell_app = get_pyaedt_app(project_name, design_name)
plot = maxwell_app.post.plot_field(
quantity=master.export_option,
assignment=master.objects_list,
plot_type="Surface",
Expand All @@ -323,6 +326,11 @@ def callback(button_id):
keep_plot_after_generation=False,
show_grid=False,
)
maxwell_app.release_desktop(False, False)
if not plot.fields:
setup_name = master.solution_option.split(":")[0].strip()
messagebox.showerror("Error", f"{setup_name} is not solved.")
return None

def browse_files():
filename = filedialog.askopenfilename(
Expand Down Expand Up @@ -356,8 +364,7 @@ def submit():
master.objects_list = [objects_list_lb.get(i) for i in selected_objects]
points = points_entry.get("1.0", tk.END).strip()
pts_path = points_main({"is_test": False, "choice": master.objects_list, "points": int(points)})

_text_size(pts_path, sample_points_entry)
_text_size(theme, pts_path, sample_points_entry)
else:
browse_files()
popup.destroy()
Expand All @@ -381,7 +388,7 @@ def save_as_files():
("Numpy array", "*.npy"),
],
)
_text_size(filename, export_file_entry)
_text_size(theme, filename, export_file_entry)
master.file_path = export_file_entry.get("1.0", tk.END).strip()
# master.destroy()

Expand Down Expand Up @@ -416,8 +423,6 @@ def save_as_files():
objects_list = getattr(master, "objects_list", extension_arguments["objects_list"])
solution_option = getattr(master, "solution_option", extension_arguments["solution_option"])

maxwell.release_desktop(False, False)

if master.flag:
output_dict = {
"points_file": points_file,
Expand Down Expand Up @@ -452,7 +457,10 @@ def main(extension_args):
objects_list = extension_args.get("objects_list", extension_arguments["objects_list"])
solution_option = extension_args.get("solution_option", extension_arguments["solution_option"])

# Your workflow
if not export_file: # pragma: no cover
aedtapp.logger.error("Not export file specified.")
aedtapp.release_desktop(False, False)
return False
if not points_file:
points_file = None
if not objects_list:
Expand All @@ -470,8 +478,9 @@ def main(extension_args):

setup_name = solution_option.split(":")[0].strip()
is_solved = [s.is_solved for s in aedtapp.setups if s.name == setup_name][0]
if not is_solved:
if not is_solved: # pragma: no cover
aedtapp.logger.error("The setup is not solved. Please solve the setup before exporting the field data.")
aedtapp.release_desktop(False, False)
return False
field_path = str(Path(export_file).with_suffix(".fld"))

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ template = "run_pyaedt_toolkit_script"
pip = "ansys-magnet-segmentation-toolkit"
package = "ansys-magnet-segmentation-toolkit"

[LossDistribution]
name = "Export of loss distribution"
script = "transfomer_loss_distribution.py"
icon = ""
[FieldsDistribution]
name = "Fields distribution"
script = "fields_distribution.py"
icon = "images/large/fields_distribution.png"
template = "run_pyaedt_toolkit_script"
pip = ""
16 changes: 0 additions & 16 deletions tests/system/visualization/test_45_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,22 +684,6 @@ def test_fields_distribution(self, add_app, local_scratch):

file_path = os.path.join(local_scratch.path, "loss_distribution.csv")

aedtapp = add_app(application=ansys.aedt.core.Maxwell2d)

rectangle = aedtapp.modeler.create_rectangle(origin=[0, 0, 0], sizes=[10, 20])
aedtapp.create_setup("Setup1")

assert not main(
{
"is_test": True,
"points_file": "",
"export_file": file_path,
"export_option": "Ohmic_loss",
"objects_list": [rectangle.name],
"solution_option": "Setup1 : LastAdaptive",
}
)

aedtapp = add_app(
application=ansys.aedt.core.Maxwell2d, subfolder=test_subfolder, project_name=fields_distribution
)
Expand Down