Skip to content

Commit

Permalink
FIX: Points property fix (#757)
Browse files Browse the repository at this point in the history
* hfsspi SimsetupInfo bug fixed

* temp

* create port in pin exception handling

* bug fix

* REFACTOR: Compute arc point into utilities

---------

Co-authored-by: Sebastien Morais <[email protected]>
  • Loading branch information
svandenb-dev and SMoraisAnsys authored Aug 30, 2024
1 parent 10e9656 commit a2ece5b
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 176 deletions.
78 changes: 2 additions & 76 deletions src/pyedb/dotnet/edb_core/cell/primitive/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import math

from pyedb.dotnet.edb_core.cell.connectable import Connectable
from pyedb.dotnet.edb_core.general import convert_py_list_to_net_list
from pyedb.dotnet.edb_core.geometry.polygon_data import PolygonData
from pyedb.misc.utilities import compute_arc_points
from pyedb.modeler.geometry_operators import GeometryOperators


Expand Down Expand Up @@ -202,80 +202,6 @@ def is_negative(self):
def is_negative(self, value):
self._edb_object.SetIsNegative(value)

@staticmethod
def _eval_arc_points(p1, p2, h, n=6, tol=1e-12):
"""Get the points of the arc
Parameters
----------
p1 : list
Arc starting point.
p2 : list
Arc ending point.
h : float
Arc height.
n : int
Number of points to generate along the arc.
tol : float
Geometric tolerance.
Returns
-------
list, list
Points generated along the arc.
"""
# fmt: off
if abs(h) < tol:
return [], []
elif h > 0:
reverse = False
x1 = p1[0]
y1 = p1[1]
x2 = p2[0]
y2 = p2[1]
else:
reverse = True
x1 = p2[0]
y1 = p2[1]
x2 = p1[0]
y2 = p1[1]
h *= -1
xa = (x2 - x1) / 2
ya = (y2 - y1) / 2
xo = x1 + xa
yo = y1 + ya
a = math.sqrt(xa ** 2 + ya ** 2)
if a < tol:
return [], []
r = (a ** 2) / (2 * h) + h / 2
if abs(r - a) < tol:
b = 0
th = 2 * math.asin(1) # chord angle
else:
b = math.sqrt(r ** 2 - a ** 2)
th = 2 * math.asin(a / r) # chord angle

# center of the circle
xc = xo + b * ya / a
yc = yo - b * xa / a

alpha = math.atan2((y1 - yc), (x1 - xc))
xr = []
yr = []
for i in range(n):
i += 1
dth = (float(i) / (n + 1)) * th
xi = xc + r * math.cos(alpha - dth)
yi = yc + r * math.sin(alpha - dth)
xr.append(xi)
yr.append(yi)

if reverse:
xr.reverse()
yr.reverse()
# fmt: on
return xr, yr

def _get_points_for_plot(self, my_net_points, num):
"""
Get the points to be plotted.
Expand All @@ -295,7 +221,7 @@ def _get_points_for_plot(self, my_net_points, num):
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
else:
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h, num)
x_arc, y_arc = compute_arc_points(p1, p2, arc_h, num)
x.extend(x_arc)
y.extend(y_arc)
# i += 1
Expand Down
9 changes: 4 additions & 5 deletions src/pyedb/dotnet/edb_core/dotnet/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
# SOFTWARE.

"""Primitive."""

from pyedb.dotnet.edb_core.dotnet.database import NetDotNet
from pyedb.dotnet.edb_core.general import convert_py_list_to_net_list
from pyedb.misc.utilities import compute_arc_points
from pyedb.modeler.geometry_operators import GeometryOperators


Expand Down Expand Up @@ -256,11 +258,10 @@ def make_zone_primitive(self, zone_id):
"""
self.prim_obj.MakeZonePrimitive(zone_id)

def _get_points_for_plot(self, my_net_points, num):
def _get_points_for_plot(self, my_net_points, n=6, tol=1e-12):
"""
Get the points to be plot
"""
# fmt: off
x = []
y = []
for i, point in enumerate(my_net_points):
Expand All @@ -276,11 +277,9 @@ def _get_points_for_plot(self, my_net_points, num):
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
else:
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h, num)
x_arc, y_arc = compute_arc_points(p1, p2, arc_h, n, tol)
x.extend(x_arc)
y.extend(y_arc)
# i += 1
# fmt: on
return x, y

def points(self, arc_segments=6):
Expand Down
2 changes: 1 addition & 1 deletion src/pyedb/dotnet/edb_core/edb_data/primitives_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def points(self, arc_segments=6):
"""
try:
my_net_points = self.points_raw
xt, yt = self._app._get_points_for_plot(my_net_points, arc_segments)
xt, yt = self._app._active_cell.primitive._get_points_for_plot(my_net_points, arc_segments)
if not xt:
return []
x, y = GeometryOperators.orient_polygon(xt, yt, clockwise=True)
Expand Down
78 changes: 2 additions & 76 deletions src/pyedb/dotnet/edb_core/nets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

from __future__ import absolute_import # noreorder

import math
import os
import time
import warnings

from pyedb.dotnet.edb_core.edb_data.nets_data import EDBNetsData
from pyedb.generic.constants import CSS4_COLORS
from pyedb.generic.general_methods import generate_unique_name
from pyedb.misc.utilities import compute_arc_points
from pyedb.modeler.geometry_operators import GeometryOperators


Expand Down Expand Up @@ -354,80 +354,6 @@ def get_net_list(net_name, _net_list):

return _extended_nets

@staticmethod
def _eval_arc_points(p1, p2, h, n=6, tol=1e-12):
"""Get the points of the arc.
Parameters
----------
p1 : list
Arc starting point.
p2 : list
Arc ending point.
h : float
Arc height.
n : int
Number of points to generate along the arc.
tol : float
Geometric tolerance.
Returns
-------
list
points generated along the arc.
"""
# fmt: off
if abs(h) < tol:
return [], []
elif h > 0:
reverse = False
x1 = p1[0]
y1 = p1[1]
x2 = p2[0]
y2 = p2[1]
else:
reverse = True
x1 = p2[0]
y1 = p2[1]
x2 = p1[0]
y2 = p1[1]
h *= -1
xa = (x2 - x1) / 2
ya = (y2 - y1) / 2
xo = x1 + xa
yo = y1 + ya
a = math.sqrt(xa ** 2 + ya ** 2)
if a < tol:
return [], []
r = (a ** 2) / (2 * h) + h / 2
if abs(r - a) < tol:
b = 0
th = 2 * math.asin(1) # chord angle
else:
b = math.sqrt(r ** 2 - a ** 2)
th = 2 * math.asin(a / r) # chord angle

# center of the circle
xc = xo + b * ya / a
yc = yo - b * xa / a

alpha = math.atan2((y1 - yc), (x1 - xc))
xr = []
yr = []
for i in range(n):
i += 1
dth = (i / (n + 1)) * th
xi = xc + r * math.cos(alpha - dth)
yi = yc + r * math.sin(alpha - dth)
xr.append(xi)
yr.append(yi)

if reverse:
xr.reverse()
yr.reverse()
# fmt: on
return xr, yr

def _get_points_for_plot(self, my_net_points):
"""
Get the points to be plot
Expand All @@ -448,7 +374,7 @@ def _get_points_for_plot(self, my_net_points):
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
else:
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h)
x_arc, y_arc = compute_arc_points(p1, p2, arc_h)
x.extend(x_arc)
y.extend(y_arc)
# i += 1
Expand Down
109 changes: 91 additions & 18 deletions src/pyedb/misc/utilities.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,100 @@
from distutils.dir_util import copy_tree
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Module gathering utility functions for PyEDB modules."""

class file_tools:
def __init__(self):
pass

@staticmethod
def copy_folder(source_folder, destination_folder):
"""
import math

Parameters
----------
source_folder : str
source folder

destination_folder : str
destination folder.
def compute_arc_points(p1, p2, h, n=6, tol=1e-12):
"""Get the points of the arc.
Parameters
----------
p1 : list
Arc starting point.
p2 : list
Arc ending point.
h : float
Arc height.
n : int
Number of points to generate along the arc.
tol : float
Geometric tolerance.
Returns
-------
Returns
-------
list, list
Points generated along the arc.
"""
if abs(h) < tol:
return [], []
elif h > 0:
reverse = False
x1 = p1[0]
y1 = p1[1]
x2 = p2[0]
y2 = p2[1]
else:
reverse = True
x1 = p2[0]
y1 = p2[1]
x2 = p1[0]
y2 = p1[1]
h *= -1

"""
xa = (x2 - x1) / 2
ya = (y2 - y1) / 2
xo = x1 + xa
yo = y1 + ya
a = math.sqrt(xa**2 + ya**2)
if a < tol:
return [], []
r = (a**2) / (2 * h) + h / 2
if abs(r - a) < tol:
b = 0
th = 2 * math.asin(1) # chord angle
else:
b = math.sqrt(r**2 - a**2)
th = 2 * math.asin(a / r) # chord angle

copy_tree(source_folder, destination_folder)
return True
# Center of the circle
xc = xo + b * ya / a
yc = yo - b * xa / a

alpha = math.atan2((y1 - yc), (x1 - xc))
xr = []
yr = []
for i in range(n):
i += 1
dth = (float(i) / (n + 1)) * th
xi = xc + r * math.cos(alpha - dth)
yi = yc + r * math.sin(alpha - dth)
xr.append(xi)
yr.append(yi)

if reverse:
xr.reverse()
yr.reverse()

return xr, yr

0 comments on commit a2ece5b

Please sign in to comment.