Skip to content

Commit

Permalink
Improved the way the information are plotted from the __str__ methods (
Browse files Browse the repository at this point in the history
…#3845)

* Improved the way the information are plotted from the __str__ methods

* Update pyaedt/application/Design.py

Co-authored-by: Kathy Pippert <[email protected]>

* Update Design.py

* Improved the way the information are plotted from the __str__ methods

---------

Co-authored-by: maxcapodi78 <Shark78>
Co-authored-by: Samuel Lopez <[email protected]>
Co-authored-by: Kathy Pippert <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent c6118db commit 263ee72
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 34 deletions.
2 changes: 2 additions & 0 deletions _unittest/test_01_Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def test_08_objects(self):
print(self.aedtapp.logger)
print(self.aedtapp.variable_manager)
print(self.aedtapp.materials)
print(self.aedtapp)
assert self.aedtapp.info

def test_09_set_objects_deformation(self):
assert self.aedtapp.modeler.set_objects_deformation(["inner"])
Expand Down
12 changes: 6 additions & 6 deletions _unittest/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ def test_print_object(self):
o = self.create_copper_box()
assert o.name in o.__str__()
test_face = o.faces[0]
assert "FaceId" in test_face.__repr__()
assert "FaceId" in test_face.__str__()
assert isinstance(int(test_face.__str__()), int)
assert isinstance(int(test_face.__repr__()), int)
test_edge = test_face.edges[0]
assert "EdgeId" in test_edge.__repr__()
assert "EdgeId" in test_edge.__str__()
assert isinstance(int(test_edge.__str__()), int)
assert isinstance(int(test_edge.__repr__()), int)
test_vertex = test_face.vertices[0]
assert "Vertex" in test_vertex.__repr__()
assert "Vertex" in test_vertex.__str__()
assert isinstance(int(test_vertex.__str__()), int)
assert isinstance(int(test_vertex.__repr__()), int)

def test_13_delete_self(self):
o = self.create_copper_box()
Expand Down
47 changes: 39 additions & 8 deletions pyaedt/application/Design.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,36 @@ class Design(AedtObjects):
"""

def __str__(self):
pyaedt_details = " pyaedt API\n"
pyaedt_details += "pyaedt running AEDT Version {} \n".format(settings.aedt_version)
pyaedt_details += "Running {} tool in AEDT\n".format(self.design_type)
pyaedt_details += "Solution Type: {} \n".format(self.solution_type)
pyaedt_details += "Project Name: {} Design Name {} \n".format(self.project_name, self.design_name)
@property
def _pyaedt_details(self):
import platform

from pyaedt import __version__ as pyaedt_version

_p_dets = {
"PyAEDT Version": pyaedt_version,
"Product": "Ansys Electronics Desktop {}".format(settings.aedt_version),
"Design Type": self.design_type,
"Solution Type": self.solution_type,
"Project Name": self.project_name,
"Design Name": self.design_name,
"Project Path": "",
}
if self._oproject:
pyaedt_details += 'Project Path: "{}" \n'.format(self.project_path)
return pyaedt_details
_p_dets["Project Path"] = self.project_file
_p_dets["Platform"] = platform.platform()
_p_dets["Python Version"] = platform.python_version()
_p_dets["AEDT Process ID"] = self.desktop_class.aedt_process_id
_p_dets["AEDT GRPC Port"] = self.desktop_class.port
return _p_dets

def __str__(self):
return "\n".join(
[
"{}:".format(each_name).ljust(25) + "{}".format(each_attr).ljust(25)
for each_name, each_attr in self._pyaedt_details.items()
]
)

def __exit__(self, ex_type, ex_value, ex_traceback):
if ex_type:
Expand All @@ -133,6 +154,16 @@ def __setitem__(self, variable_name, variable_value):
self.variable_manager[variable_name] = variable_value
return True

@property
def info(self):
"""Dictionary of the PyAEDT session information.
Returns
-------
dict
"""
return self._pyaedt_details

def _init_design(self, project_name, design_name, solution_type=None):
# calls the method from the application class
self._init_from_design(
Expand Down
3 changes: 2 additions & 1 deletion pyaedt/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,8 @@ def __init__(
sys.path.append(
os.path.join(self._main.sDesktopinstallDirectory, "common", "commonfiles", "IronPython", "DLLs")
)

if "GetGrpcServerPort" in dir(self.odesktop):
self.port = self.odesktop.GetGrpcServerPort()
# save the current desktop session in the database
_desktop_sessions[self.aedt_process_id] = self

Expand Down
24 changes: 12 additions & 12 deletions pyaedt/modeler/cad/elements3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ def position(self):
except Exception as e:
return None

def __repr__(self):
return "Vertex " + str(self.id)

def __str__(self):
return "Vertex " + str(self.id)
return str(self.id)

def __repr__(self):
return str(self.id)


class EdgePrimitive(EdgeTypePrimitive, object):
Expand Down Expand Up @@ -366,11 +366,11 @@ def length(self):
except:
return False

def __repr__(self):
return "EdgeId " + str(self.id)

def __str__(self):
return "EdgeId " + str(self.id)
return str(self.id)

def __repr__(self):
return str(self.id)

@pyaedt_function_handler()
def create_object(self, non_model=False):
Expand Down Expand Up @@ -420,11 +420,11 @@ def move_along_normal(self, offset=1.0):
class FacePrimitive(object):
"""Contains the face object within the AEDT Desktop Modeler."""

def __repr__(self):
return "FaceId " + str(self.id)

def __str__(self):
return "FaceId " + str(self.id)
return str(self.id)

def __repr__(self):
return str(self.id)

def __init__(self, object3d, obj_id):
"""
Expand Down
8 changes: 1 addition & 7 deletions pyaedt/modeler/cad/object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,10 +1887,4 @@ def _change_property(self, vPropChange):
return self._primitives._change_geometry_property(vPropChange, self._m_name)

def __str__(self):
return """
name: {} id: {} object_type: {}
""".format(
self.name,
self.id,
self._object_type,
)
return self.name

0 comments on commit 263ee72

Please sign in to comment.