Skip to content

Commit

Permalink
Improved plot with view (#1833)
Browse files Browse the repository at this point in the history
Co-authored-by: maxcapodi78 <Shark78>
  • Loading branch information
maxcapodi78 committed Oct 14, 2022
1 parent 2c52a75 commit f219dd5
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
6 changes: 6 additions & 0 deletions _unittest/test_02_2D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Setup paths for module imports

try:
import filecmp

import pytest # noqa: F401
except ImportError:
import _unittest_ironpython.conf_unittest as pytest # noqa: F401
Expand Down Expand Up @@ -136,6 +138,10 @@ def test_09_plot(self):
)
obj = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"))
assert os.path.exists(obj.image_file)
obj2 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy")
assert os.path.exists(obj2.image_file)
obj3 = self.aedtapp.plot(show=False, export_path=os.path.join(self.local_scratch.path, "image.jpg"), view="xy1")
assert filecmp.cmp(obj.image_file, obj3.image_file)

def test_10_edit_menu_commands(self):
rect1 = self.aedtapp.modeler.create_rectangle([1, 0, -2], [8, 3])
Expand Down
5 changes: 5 additions & 0 deletions pyaedt/application/Analysis3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def plot(
plot_air_objects=True,
force_opacity_value=None,
clean_files=False,
view="isometric",
):
"""Plot the model or a subset of objects.
Expand All @@ -206,6 +207,9 @@ def plot(
clean_files : bool, optional
Whether to clean created files after plot generation. The default is ``False``,
which means that the cache is maintained in the model object that is returned.
view : str, optional
View to export. Options are ``"isometric"``, ``"xy"``, ``"xz"``, ``"yz"``.
The default is ``"isometric"``.
Returns
-------
Expand All @@ -225,6 +229,7 @@ def plot(
plot_air_objects=plot_air_objects,
force_opacity_value=force_opacity_value,
clean_files=clean_files,
view=view,
)

@pyaedt_function_handler()
Expand Down
5 changes: 4 additions & 1 deletion pyaedt/generic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ def __init__(self):
self.gif_file = None
self._background_color = (255, 255, 255)
self.off_screen = False
self.windows_size = [1024, 768]
if self.is_notebook:
self.windows_size = [600, 600]
else:
self.windows_size = [1024, 768]
self.pv = None
self._orientation = ["xy", 0, 0, 0]
self.units = "meter"
Expand Down
5 changes: 3 additions & 2 deletions pyaedt/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -3918,12 +3918,13 @@ def thicken_port_sheets(self, inputlist, value, internalExtr=True, internalvalue
tol = 1e-6
ports_ID = {}
aedt_bounding_box = self.modeler.get_model_bounding_box()
aedt_bounding_dim = self.modeler.get_bounding_dimension()
directions = {}
for el in inputlist:
objID = self.modeler.oeditor.GetFaceIDs(el)
faceCenter = self.modeler.oeditor.GetFaceCenter(int(objID[0]))
directionfound = False
l = 10
l = min(aedt_bounding_dim) / 2
while not directionfound:
self.modeler.oeditor.ThickenSheet(
["NAME:Selections", "Selections:=", el, "NewPartsModelFlag:=", "Model"],
Expand All @@ -3948,7 +3949,7 @@ def thicken_port_sheets(self, inputlist, value, internalExtr=True, internalvalue
directions[el] = "Internal"
directionfound = True
else:
l = l + 10
l = l + min(aedt_bounding_dim) / 2
for el in inputlist:
objID = self.modeler.oeditor.GetFaceIDs(el)
maxarea = 0
Expand Down
16 changes: 13 additions & 3 deletions pyaedt/modules/AdvancedPostProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def plot_model_obj(
force_opacity_value=None,
clean_files=False,
array_coordinates=None,
view="isometric",
):
"""Plot the model or a substet of objects.
Expand All @@ -248,6 +249,9 @@ def plot_model_obj(
array_coordinates : list of list
List of array element centers. The modeler objects will be duplicated and translated.
List of [[x1,y1,z1], [x2,y2,z2]...].
view : str, optional
View to export. Options are ``"isometric"``, ``"xy"``, ``"xz"``, ``"yz"``.
The default is ``"isometric"``.
Returns
-------
Expand All @@ -264,6 +268,10 @@ def plot_model_obj(
)

model.off_screen = not show
if view != "isometric" and view in ["xy", "xz", "yz"]:
model.camera_position = view
else:
self.logger.warning("Wrong view setup. It has to be one of xy, xz, yz, isometric.")
if export_path:
model.plot(export_path)
elif show:
Expand Down Expand Up @@ -305,8 +313,7 @@ def plot_field_from_fieldplot(
``"png"``, ``"svg"``, and ``"webp"``. The default is
``"jpg"``.
view : str, optional
View to export. Options are ``isometric``, ``top``, ``front``,
``left``, ``all``.. The default is ``"iso"``. If ``"all"``, all views are exported.
View to export. Options are ``"isometric"``, ``"xy"``, ``"xz"``, ``"yz"``.
plot_label : str, optional
Type of the plot. The default is ``"Temperature"``.
plot_folder : str, optional
Expand Down Expand Up @@ -341,7 +348,10 @@ def plot_field_from_fieldplot(
if plot_label:
model.fields[0].label = plot_label

model.view = view
if view != "isometric" and view in ["xy", "xz", "yz"]:
model.camera_position = view
else:
self.logger.warning("Wrong view setup. It has to be one of xy, xz, yz, isometric.")

if scale_min and scale_max:
model.range_min = scale_min
Expand Down
3 changes: 1 addition & 2 deletions pyaedt/modules/PostProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2880,8 +2880,7 @@ def export_field_image_with_view(self, plotName, foldername, exportFilePath, vie
exportFilePath :
Path for exporting the image file.
view : str, optional
View to export. Options are ``"isometric"``, ``"top"``, ``"bottom"``, ``"right"``, ``"left"`` and any
custom orientation.
View to export. Options are ``"isometric"``, ``"xy"``, ``"xz"``, ``"yz"``.
The default is ``"isometric"``.
wireframe : bool, optional
Whether to put the objects in the wireframe mode. The default is ``True``.
Expand Down
3 changes: 1 addition & 2 deletions pyaedt/modules/solutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2835,8 +2835,7 @@ def export_image_from_aedtplt(
Path where image will be saved.
The default is ``None`` which export file in working_directory.
view : str, optional
View of the exported plot. Options are ``isometric``,
``top``, ``front``, ``left``, and ``all``.
View to export. Options are ``"isometric"``, ``"xy"``, ``"xz"``, ``"yz"``.
plot_mesh : bool, optional
Plot mesh.
scale_min : float, optional
Expand Down

0 comments on commit f219dd5

Please sign in to comment.