diff --git a/doc/changelog.d/1677.fixed.md b/doc/changelog.d/1677.fixed.md new file mode 100644 index 0000000000..d06502fa13 --- /dev/null +++ b/doc/changelog.d/1677.fixed.md @@ -0,0 +1 @@ +Issue 1621 fix diff --git a/src/pyedb/grpc/database/primitive/primitive.py b/src/pyedb/grpc/database/primitive/primitive.py index c4e128a50e..fc1edc8e05 100644 --- a/src/pyedb/grpc/database/primitive/primitive.py +++ b/src/pyedb/grpc/database/primitive/primitive.py @@ -20,6 +20,8 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import math + from ansys.edb.core.database import ProductIdType as GrpcProductIdType from ansys.edb.core.geometry.point_data import PointData as GrpcPointData from ansys.edb.core.primitive.circle import Circle as GrpcCircle @@ -354,6 +356,80 @@ def longest_arc(self) -> float: len = i.length return arc + def rotate(self, angle, center=None) -> bool: + """Rotate polygon around a center point by an angle. + + Parameters + ---------- + angle : float + Value of the rotation angle in degree. + center : List of float or str [x,y], optional + If None rotation is done from polygon center. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + """ + if angle and hasattr(self, "polygon_data"): + if center is None: + center = self.cast().polygon_data.bounding_circle()[0] + self.cast().polygon_data = self.polygon_data.rotate(angle * math.pi / 180, center) + return True + return False + + def move(self, vector) -> bool: + """Move polygon along a vector. + + Parameters + ---------- + vector : List of float or str [x,y]. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + + Examples + -------- + >>> edbapp = ansys.aedt.core.Edb("myproject.aedb") + >>> top_layer_polygon = [poly for poly in edbapp.modeler.polygons if poly.layer_name == "Top Layer"] + >>> for polygon in top_layer_polygon: + >>> polygon.move(vector=["2mm", "100um"]) + """ + if vector and isinstance(vector, list) and len(vector) == 2: + _vector = [Value(pt) for pt in vector] + self.cast().polygon_data = self.polygon_data.move(_vector) + return True + return False + + def scale(self, factor, center=None) -> bool: + """Scales the polygon relative to a center point by a factor. + + Parameters + ---------- + factor : float + Scaling factor. + center : List of float or str [x,y], optional + If None scaling is done from polygon center. + + Returns + ------- + bool + ``True`` when successful, ``False`` when failed. + """ + if not isinstance(factor, str) and hasattr(self, "polygon_data"): + factor = float(factor) + if not center: + center = self.cast().polygon_data.bounding_circle()[0] + elif isinstance(center, list) and len(center) == 2: + center = GrpcPointData([Value(center[0]), Value(center[1])]) + else: + self._pedb.logger.error(f"Failed to evaluate center on primitive {self.id}") + self.cast().polygon_data = self.polygon_data.scale(factor, center) + return True + return False + def subtract(self, primitives) -> list[any]: """Subtract active primitive with one or more primitives. diff --git a/src/pyedb/libraries/common.py b/src/pyedb/libraries/common.py index 4529b7a80b..12653f64c6 100644 --- a/src/pyedb/libraries/common.py +++ b/src/pyedb/libraries/common.py @@ -358,8 +358,10 @@ class MicroStripTechnologyStackup: >>> stack.substrate.material.permittivity = 9.8 """ - def __init__(self, pedb): + def __init__( + self, pedb, botton_layer_name="BOT_METAL", substrate_layer_name="Substrate", top_layer_name="TOP_METAL" + ): self._pedb = pedb - self.bottom_metal = MetalLayer(pedb, name="BOT_METAL", thickness=4e-6, material="Gold") - self.substrate = DielectricLayer(pedb, name="Substrate", thickness=100e-6, material="Silicon") - self.top_metal = MetalLayer(pedb, name="TOP_METAL", thickness=4e-6, material="Gold") + self.bottom_metal = MetalLayer(pedb, name=botton_layer_name, thickness=4e-6, material="Gold") + self.substrate = DielectricLayer(pedb, name=substrate_layer_name, thickness=100e-6, material="Silicon") + self.top_metal = MetalLayer(pedb, name=top_layer_name, thickness=4e-6, material="Gold") diff --git a/tests/system/test_rf_libraries.py b/tests/system/test_rf_libraries.py index 514159c20f..2f9d749520 100644 --- a/tests/system/test_rf_libraries.py +++ b/tests/system/test_rf_libraries.py @@ -99,10 +99,9 @@ def test_diff_tline(self, edb_examples): assert edb.modeler.paths[0].center_line == [[0.0, 0.0], [0.01, 0.0]] edb.close(terminate_rpc_session=False) - @pytest.mark.skipif(condition=config["use_grpc"], reason="Need to check variable with grpc") def test_hatch_grounded(self, edb_examples): edb = edb_examples.create_empty_edb() - MicroStripTechnologyStackup(edb) + MicroStripTechnologyStackup(edb, botton_layer_name="METAL_BOT") hatch = HatchGround( edb_cell=edb, width=100e-6,