Skip to content

Face coordinate system - Enhancement/723 #818

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 22 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,268 changes: 1,268 additions & 0 deletions _unittest/example_models/Coordinate_System.aedt

Large diffs are not rendered by default.

711 changes: 711 additions & 0 deletions _unittest/example_models/Coordinate_System1.aedt

Large diffs are not rendered by default.

1,011 changes: 1,011 additions & 0 deletions _unittest/example_models/Coordinate_System2.aedt

Large diffs are not rendered by default.

737 changes: 737 additions & 0 deletions _unittest/example_models/Coordinate_System3.aedt

Large diffs are not rendered by default.

125 changes: 121 additions & 4 deletions _unittest/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Setup paths for module imports
from _unittest.conftest import BasisTest, pyaedt_unittest_check_desktop_error
from pyaedt.modeler.Modeler import FaceCoordinateSystem

try:
import pytest # noqa: F401
Expand Down Expand Up @@ -271,7 +272,7 @@ def test_39_create_coaxial(self):
assert isinstance(coax[1].id, int)
assert isinstance(coax[2].id, int)

def test_40_create_coordinate(self):
def test_40_create_coordinate_system(self):
cs = self.aedtapp.modeler.create_coordinate_system()
assert cs
assert cs.update()
Expand All @@ -287,13 +288,83 @@ def test_40_create_coordinate(self):
assert cs.change_cs_mode(0)
assert cs.delete()

def test_40a_create_face_coordinate_system(self):
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[0], face.edges[1])
assert fcs
assert fcs.face_id == face.id
assert fcs.update()
assert fcs.delete()
fcs2 = self.aedtapp.modeler.create_face_coordinate_system(face, face, face.edges[1].vertices[0])
assert fcs2
assert fcs2.delete()
fcs2 = self.aedtapp.modeler.create_face_coordinate_system(
face, face.edges[0].vertices[0], face.edges[1].vertices[0]
)
assert fcs2
assert fcs2.delete()
fcs3 = self.aedtapp.modeler.create_face_coordinate_system(
face, face.edges[1].vertices[1], face.edges[1].vertices[0]
)
assert fcs3
assert fcs3.delete()
fcs4 = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[2], face.edges[3], name="test")
assert fcs4
assert fcs4.name == "test"
assert fcs4.delete()
fcs5 = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[2], face.edges[3], axis="Y")
assert fcs5
assert fcs5.props["WhichAxis"] == "Y"
assert fcs5.delete()
fcs6 = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[2], face.edges[3], rotation=14.3)
assert fcs6
assert fcs6.props["ZRotationAngle"] == "14.3deg"
assert fcs6.delete()
fcs7 = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[2], face.edges[3], offset=[0.2, 0.3])
assert fcs7
assert fcs7.props["XOffset"] == "0.2" + self.aedtapp.modeler.model_units
assert fcs7.props["YOffset"] == "0.3" + self.aedtapp.modeler.model_units
assert fcs7.delete()
fcs8 = self.aedtapp.modeler.create_face_coordinate_system(face.id, face.edges[0].id, face.edges[1].id)
assert fcs8
assert fcs8.delete()
fcs9 = self.aedtapp.modeler.create_face_coordinate_system(face.id, face.edges[0].vertices[0].id, face.id)
assert fcs9
assert fcs9.delete()
fcs10 = self.aedtapp.modeler.create_face_coordinate_system(
face, face.edges[2], face.edges[3], always_move_to_end=False
)
assert fcs10
assert fcs10.props["MoveToEnd"] is False
assert fcs10.delete()
fcs = FaceCoordinateSystem(self.aedtapp.modeler)
assert fcs._part_name is None
assert fcs._get_type_from_id(box.id) == "3dObject"
assert fcs._get_type_from_id(face.id) == "Face"
assert fcs._get_type_from_id(face.edges[0].id) == "Edge"
assert fcs._get_type_from_id(face.edges[0].vertices[0].id) == "Vertex"
assert fcs._get_type_from_object(box) == "3dObject"
assert fcs._get_type_from_object(face) == "Face"
assert fcs._get_type_from_object(face.edges[0]) == "Edge"
assert fcs._get_type_from_object(face.edges[0].vertices[0]) == "Vertex"

def test_41_rename_coordinate(self):
cs = self.aedtapp.modeler.create_coordinate_system(name="oldname")
assert cs.name == "oldname"
assert cs.rename("newname")
assert cs.name == "newname"
assert cs.delete()

def test_41a_rename_face_coordinate(self):
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[0], face.edges[1], name="oldname")
assert fcs.name == "oldname"
assert fcs.rename("newname")
assert fcs.name == "newname"
assert fcs.delete()

def test_42A_update_coordinate_system(self):
for cs in self.aedtapp.modeler.coordinate_systems:
cs.delete()
Expand All @@ -310,11 +381,36 @@ def test_42A_update_coordinate_system(self):
cs2.props["Theta"] = 30
assert cs2.update()
cs2.ref_cs = "Global"
cs2.update()
assert cs2.update()
assert tuple(self.aedtapp.modeler.oeditor.GetCoordinateSystems()) == ("Global", "CS1", "CS2")
assert len(self.aedtapp.modeler.coordinate_systems) == 2
assert cs2.delete()

def test_42A_update_face_coordinate_system(self):
for cs in self.aedtapp.modeler.coordinate_systems:
cs.delete()
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[0], face.edges[1], name="FCS1")
assert fcs
fcs.props["XOffset"] = "0.2mm"
fcs.props["YOffset"] = "0.3mm"
assert fcs.props["XOffset"] == "0.2mm"
assert fcs.props["YOffset"] == "0.3mm"
assert fcs.update()
fcs.props["ZRotationAngle"] = "14.3deg"
assert fcs.update()
assert fcs.props["ZRotationAngle"] == "14.3deg"
fcs.props["WhichAxis"] = "Y"
assert fcs.update()
assert fcs.props["WhichAxis"] == "Y"
fcs.props["MoveToEnd"] = False
assert fcs.update()
assert fcs.props["MoveToEnd"] is False
assert tuple(self.aedtapp.modeler.oeditor.GetCoordinateSystems()) == ("Global", "FCS1")
assert len(self.aedtapp.modeler.coordinate_systems) == 1
assert fcs.delete()

def test_42B_set_as_working_cs(self):
for cs in self.aedtapp.modeler.coordinate_systems:
cs.delete()
Expand All @@ -323,10 +419,31 @@ def test_42B_set_as_working_cs(self):
assert cs1.set_as_working_cs()
assert cs2.set_as_working_cs()

def test_42C_set_as_working_face_cs(self):
for cs in self.aedtapp.modeler.coordinate_systems:
cs.delete()
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs1 = self.aedtapp.modeler.create_face_coordinate_system(face, face.edges[0], face.edges[1])
fcs2 = self.aedtapp.modeler.create_face_coordinate_system(face, face, face.edges[1])
assert fcs1.set_as_working_cs()
assert fcs2.set_as_working_cs()

def test_43_set_working_coordinate_system(self):
cs1 = self.aedtapp.modeler.create_coordinate_system(name="new1")
self.aedtapp.modeler.set_working_coordinate_system("Global")
self.aedtapp.modeler.set_working_coordinate_system("new1")
assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.set_working_coordinate_system("new1")
assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.set_working_coordinate_system(cs1)

def test_43_set_working_face_coordinate_system(self):
box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face, face.edges[1], name="new2")
assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.set_working_coordinate_system("new2")
assert self.aedtapp.modeler.set_working_coordinate_system("Global")
assert self.aedtapp.modeler.set_working_coordinate_system(fcs)

def test_44_sweep_around_axis(self):
rect1 = self.aedtapp.modeler.primitives.create_rectangle(
Expand Down
42 changes: 41 additions & 1 deletion _unittest/test_13_LoadAEDTFile.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Setup paths for module imports
from _unittest.conftest import local_path, scratch_path
from _unittest.conftest import local_path, scratch_path, desktop_version

# Import required modules
from pyaedt.generic.filesystem import Scratch
from pyaedt.generic.LoadAEDTFile import load_entire_aedt_file
from pyaedt import Hfss
import base64
import filecmp
import os
import sys
import gc


def _write_jpg(design_info, scratch):
Expand Down Expand Up @@ -75,3 +77,41 @@ def test_02_check_design_names(self):
def test_03_check_first_design_jpg(self):
jpg_file = _write_jpg(self.design_info[0], self.local_scratch.path)
assert filecmp.cmp(jpg_file, os.path.join(local_path, "example_models", "Cassegrain_Hybrid.jpg"))


class TestProjectFileWithCoordinateSystems:
def setup_class(self):
with Scratch(scratch_path) as self.local_scratch:
aedt_file = os.path.join(local_path, "example_models", "Coordinate_System.aedt")
self.test_project = self.local_scratch.copyfile(aedt_file)
aedt_file = os.path.join(local_path, "example_models", "Coordinate_System1.aedt")
self.test_project1 = self.local_scratch.copyfile(aedt_file)
aedt_file = os.path.join(local_path, "example_models", "Coordinate_System2.aedt")
self.test_project2 = self.local_scratch.copyfile(aedt_file)
aedt_file = os.path.join(local_path, "example_models", "Coordinate_System3.aedt")
self.test_project3 = self.local_scratch.copyfile(aedt_file)
self.aedtapp = Hfss(specified_version=desktop_version)

def teardown_class(self):
self.aedtapp._desktop.ClearMessages("", "", 3)
self.local_scratch.remove()
gc.collect()

def test_01_check_can_load_aedt_file_with_multiple_coord_systems(self):
# implicitly this will test to make sure no exception is thrown by load_entire_aedt_file
assert load_entire_aedt_file(self.test_project)

def test_02_check_coordinate_system_retrival(self):
self.aedtapp.load_project(self.test_project, close_active_proj=True)
cs = self.aedtapp.modeler.coordinate_systems
assert cs
self.aedtapp.load_project(self.test_project1, close_active_proj=True)
cs = self.aedtapp.modeler.coordinate_systems
assert cs
self.aedtapp.load_project(self.test_project2, close_active_proj=True)
cs = self.aedtapp.modeler.coordinate_systems
assert cs
self.aedtapp.load_project(self.test_project3, close_active_proj=True)
cs = self.aedtapp.modeler.coordinate_systems
assert cs
self.aedtapp.close_project()
65 changes: 65 additions & 0 deletions examples/01-Modeling-Setup/HFSS_CoordinateSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,71 @@

cs5 = hfss.modeler.create_coordinate_system(name="CS5", mode="axisrotation", u=[1, 0, 0], theta=123)

###############################################################################
# Create a Face Coordinate System
# -------------------------------------------------------------------
# Face coordinate systems are bound to an object face.
# Here we create first a box and then a Face Coordinate System is defined on one of its faces.
# To create the face coordinate system a reference face, the axis starting and ending points must be specified.
box = hfss.modeler.create_box([0, 0, 0], [2, 2, 2])
face = box.faces[0]
fcs1 = hfss.modeler.create_face_coordinate_system(
face=face, origin=face.edges[0], axis_position=face.edges[1], name="FCS1"
)

###############################################################################
# Create a Face Coordinate System centered on the face
# -------------------------------------------------------------------
# Here we create a Face Coordinate System centered on the face and with the X axis pointing to the edge vertex.
fcs2 = hfss.modeler.create_face_coordinate_system(
face=face, origin=face, axis_position=face.edges[0].vertices[0], name="FCS2"
)

###############################################################################
# Swap the X and Y axis of a Face coordinate system
# -------------------------------------------------------------------
# As default the X axis is pointing `axis_position`. Optionally the Y axis can be selected.
fcs3 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0], axis="Y")

# The axis can also be changed after the coordinate system is created.
fcs3.props["WhichAxis"] = "X"
fcs3.update()

###############################################################################
# Apply a rotation around the Z axis.
# -------------------------------------------------------------------
# The Z axis of a Face Coordinate System is always orthogonal to the face.
# A rotation can be applied at definition. The rotation is expressed in degrees.
fcs4 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[1], rotation=10.3)

# The rotation can also be changed after the coordinate system is created.
fcs4.props["ZRotationAngle"] = "3deg"
fcs4.update()

###############################################################################
# Apply an offset to the X and Y axis of a Face coordinate system
# -------------------------------------------------------------------
# The offset is respect the Face Coordinate System itself.
fcs5 = hfss.modeler.create_face_coordinate_system(
face=face, origin=face, axis_position=face.edges[2], offset=[0.5, 0.3]
)

# The offset can also be changed after the coordinate system is created.
fcs5.props["XOffset"] = "0.2mm"
fcs5.props["YOffset"] = "0.1mm"
fcs5.update()

###############################################################################
# Create a coordinate system relative to a Face coordinate system
# -------------------------------------------------------------------
# Coordinate Systems and Face Coordinate Systems interact each other.
face = box.faces[1]
fcs6 = hfss.modeler.create_face_coordinate_system(face=face, origin=face, axis_position=face.edges[0])
cs_fcs = hfss.modeler.create_coordinate_system(
name="CS_FCS", origin=[0, 0, 0], reference_cs=fcs6.name, mode="view", view="iso"
)


###############################################################################
# Get All Coordinate Systems
# --------------------------
Expand Down
Loading