Skip to content

Commit a2ece5b

Browse files
FIX: Points property fix (#757)
* 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]>
1 parent 10e9656 commit a2ece5b

File tree

5 files changed

+100
-176
lines changed

5 files changed

+100
-176
lines changed

Diff for: src/pyedb/dotnet/edb_core/cell/primitive/primitive.py

+2-76
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
import math
2322

2423
from pyedb.dotnet.edb_core.cell.connectable import Connectable
2524
from pyedb.dotnet.edb_core.general import convert_py_list_to_net_list
2625
from pyedb.dotnet.edb_core.geometry.polygon_data import PolygonData
26+
from pyedb.misc.utilities import compute_arc_points
2727
from pyedb.modeler.geometry_operators import GeometryOperators
2828

2929

@@ -202,80 +202,6 @@ def is_negative(self):
202202
def is_negative(self, value):
203203
self._edb_object.SetIsNegative(value)
204204

205-
@staticmethod
206-
def _eval_arc_points(p1, p2, h, n=6, tol=1e-12):
207-
"""Get the points of the arc
208-
209-
Parameters
210-
----------
211-
p1 : list
212-
Arc starting point.
213-
p2 : list
214-
Arc ending point.
215-
h : float
216-
Arc height.
217-
n : int
218-
Number of points to generate along the arc.
219-
tol : float
220-
Geometric tolerance.
221-
222-
Returns
223-
-------
224-
list, list
225-
Points generated along the arc.
226-
"""
227-
# fmt: off
228-
if abs(h) < tol:
229-
return [], []
230-
elif h > 0:
231-
reverse = False
232-
x1 = p1[0]
233-
y1 = p1[1]
234-
x2 = p2[0]
235-
y2 = p2[1]
236-
else:
237-
reverse = True
238-
x1 = p2[0]
239-
y1 = p2[1]
240-
x2 = p1[0]
241-
y2 = p1[1]
242-
h *= -1
243-
xa = (x2 - x1) / 2
244-
ya = (y2 - y1) / 2
245-
xo = x1 + xa
246-
yo = y1 + ya
247-
a = math.sqrt(xa ** 2 + ya ** 2)
248-
if a < tol:
249-
return [], []
250-
r = (a ** 2) / (2 * h) + h / 2
251-
if abs(r - a) < tol:
252-
b = 0
253-
th = 2 * math.asin(1) # chord angle
254-
else:
255-
b = math.sqrt(r ** 2 - a ** 2)
256-
th = 2 * math.asin(a / r) # chord angle
257-
258-
# center of the circle
259-
xc = xo + b * ya / a
260-
yc = yo - b * xa / a
261-
262-
alpha = math.atan2((y1 - yc), (x1 - xc))
263-
xr = []
264-
yr = []
265-
for i in range(n):
266-
i += 1
267-
dth = (float(i) / (n + 1)) * th
268-
xi = xc + r * math.cos(alpha - dth)
269-
yi = yc + r * math.sin(alpha - dth)
270-
xr.append(xi)
271-
yr.append(yi)
272-
273-
if reverse:
274-
xr.reverse()
275-
yr.reverse()
276-
# fmt: on
277-
return xr, yr
278-
279205
def _get_points_for_plot(self, my_net_points, num):
280206
"""
281207
Get the points to be plotted.
@@ -295,7 +221,7 @@ def _get_points_for_plot(self, my_net_points, num):
295221
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
296222
else:
297223
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
298-
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h, num)
224+
x_arc, y_arc = compute_arc_points(p1, p2, arc_h, num)
299225
x.extend(x_arc)
300226
y.extend(y_arc)
301227
# i += 1

Diff for: src/pyedb/dotnet/edb_core/dotnet/primitive.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
# SOFTWARE.
2222

2323
"""Primitive."""
24+
2425
from pyedb.dotnet.edb_core.dotnet.database import NetDotNet
2526
from pyedb.dotnet.edb_core.general import convert_py_list_to_net_list
27+
from pyedb.misc.utilities import compute_arc_points
2628
from pyedb.modeler.geometry_operators import GeometryOperators
2729

2830

@@ -256,11 +258,10 @@ def make_zone_primitive(self, zone_id):
256258
"""
257259
self.prim_obj.MakeZonePrimitive(zone_id)
258260

259-
def _get_points_for_plot(self, my_net_points, num):
261+
def _get_points_for_plot(self, my_net_points, n=6, tol=1e-12):
260262
"""
261263
Get the points to be plot
262264
"""
263-
# fmt: off
264265
x = []
265266
y = []
266267
for i, point in enumerate(my_net_points):
@@ -276,11 +277,9 @@ def _get_points_for_plot(self, my_net_points, num):
276277
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
277278
else:
278279
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
279-
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h, num)
280+
x_arc, y_arc = compute_arc_points(p1, p2, arc_h, n, tol)
280281
x.extend(x_arc)
281282
y.extend(y_arc)
282-
# i += 1
283-
# fmt: on
284283
return x, y
285284

286285
def points(self, arc_segments=6):

Diff for: src/pyedb/dotnet/edb_core/edb_data/primitives_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def points(self, arc_segments=6):
488488
"""
489489
try:
490490
my_net_points = self.points_raw
491-
xt, yt = self._app._get_points_for_plot(my_net_points, arc_segments)
491+
xt, yt = self._app._active_cell.primitive._get_points_for_plot(my_net_points, arc_segments)
492492
if not xt:
493493
return []
494494
x, y = GeometryOperators.orient_polygon(xt, yt, clockwise=True)

Diff for: src/pyedb/dotnet/edb_core/nets.py

+2-76
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
from __future__ import absolute_import # noreorder
2424

25-
import math
2625
import os
2726
import time
2827
import warnings
2928

3029
from pyedb.dotnet.edb_core.edb_data.nets_data import EDBNetsData
3130
from pyedb.generic.constants import CSS4_COLORS
3231
from pyedb.generic.general_methods import generate_unique_name
32+
from pyedb.misc.utilities import compute_arc_points
3333
from pyedb.modeler.geometry_operators import GeometryOperators
3434

3535

@@ -354,80 +354,6 @@ def get_net_list(net_name, _net_list):
354354

355355
return _extended_nets
356356

357-
@staticmethod
358-
def _eval_arc_points(p1, p2, h, n=6, tol=1e-12):
359-
"""Get the points of the arc.
360-
361-
Parameters
362-
----------
363-
p1 : list
364-
Arc starting point.
365-
p2 : list
366-
Arc ending point.
367-
h : float
368-
Arc height.
369-
n : int
370-
Number of points to generate along the arc.
371-
tol : float
372-
Geometric tolerance.
373-
374-
Returns
375-
-------
376-
list
377-
points generated along the arc.
378-
"""
379-
# fmt: off
380-
if abs(h) < tol:
381-
return [], []
382-
elif h > 0:
383-
reverse = False
384-
x1 = p1[0]
385-
y1 = p1[1]
386-
x2 = p2[0]
387-
y2 = p2[1]
388-
else:
389-
reverse = True
390-
x1 = p2[0]
391-
y1 = p2[1]
392-
x2 = p1[0]
393-
y2 = p1[1]
394-
h *= -1
395-
xa = (x2 - x1) / 2
396-
ya = (y2 - y1) / 2
397-
xo = x1 + xa
398-
yo = y1 + ya
399-
a = math.sqrt(xa ** 2 + ya ** 2)
400-
if a < tol:
401-
return [], []
402-
r = (a ** 2) / (2 * h) + h / 2
403-
if abs(r - a) < tol:
404-
b = 0
405-
th = 2 * math.asin(1) # chord angle
406-
else:
407-
b = math.sqrt(r ** 2 - a ** 2)
408-
th = 2 * math.asin(a / r) # chord angle
409-
410-
# center of the circle
411-
xc = xo + b * ya / a
412-
yc = yo - b * xa / a
413-
414-
alpha = math.atan2((y1 - yc), (x1 - xc))
415-
xr = []
416-
yr = []
417-
for i in range(n):
418-
i += 1
419-
dth = (i / (n + 1)) * th
420-
xi = xc + r * math.cos(alpha - dth)
421-
yi = yc + r * math.sin(alpha - dth)
422-
xr.append(xi)
423-
yr.append(yi)
424-
425-
if reverse:
426-
xr.reverse()
427-
yr.reverse()
428-
# fmt: on
429-
return xr, yr
430-
431357
def _get_points_for_plot(self, my_net_points):
432358
"""
433359
Get the points to be plot
@@ -448,7 +374,7 @@ def _get_points_for_plot(self, my_net_points):
448374
p2 = [my_net_points[i + 1].X.ToDouble(), my_net_points[i + 1].Y.ToDouble()]
449375
else:
450376
p2 = [my_net_points[0].X.ToDouble(), my_net_points[0].Y.ToDouble()]
451-
x_arc, y_arc = self._eval_arc_points(p1, p2, arc_h)
377+
x_arc, y_arc = compute_arc_points(p1, p2, arc_h)
452378
x.extend(x_arc)
453379
y.extend(y_arc)
454380
# i += 1

Diff for: src/pyedb/misc/utilities.py

+91-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,100 @@
1-
from distutils.dir_util import copy_tree
1+
# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
222

23+
"""Module gathering utility functions for PyEDB modules."""
324

4-
class file_tools:
5-
def __init__(self):
6-
pass
725

8-
@staticmethod
9-
def copy_folder(source_folder, destination_folder):
10-
"""
26+
import math
1127

12-
Parameters
13-
----------
14-
source_folder : str
15-
source folder
1628

17-
destination_folder : str
18-
destination folder.
29+
def compute_arc_points(p1, p2, h, n=6, tol=1e-12):
30+
"""Get the points of the arc.
1931
32+
Parameters
33+
----------
34+
p1 : list
35+
Arc starting point.
36+
p2 : list
37+
Arc ending point.
38+
h : float
39+
Arc height.
40+
n : int
41+
Number of points to generate along the arc.
42+
tol : float
43+
Geometric tolerance.
2044
21-
Returns
22-
-------
45+
Returns
46+
-------
47+
list, list
48+
Points generated along the arc.
49+
"""
50+
if abs(h) < tol:
51+
return [], []
52+
elif h > 0:
53+
reverse = False
54+
x1 = p1[0]
55+
y1 = p1[1]
56+
x2 = p2[0]
57+
y2 = p2[1]
58+
else:
59+
reverse = True
60+
x1 = p2[0]
61+
y1 = p2[1]
62+
x2 = p1[0]
63+
y2 = p1[1]
64+
h *= -1
2365

24-
"""
66+
xa = (x2 - x1) / 2
67+
ya = (y2 - y1) / 2
68+
xo = x1 + xa
69+
yo = y1 + ya
70+
a = math.sqrt(xa**2 + ya**2)
71+
if a < tol:
72+
return [], []
73+
r = (a**2) / (2 * h) + h / 2
74+
if abs(r - a) < tol:
75+
b = 0
76+
th = 2 * math.asin(1) # chord angle
77+
else:
78+
b = math.sqrt(r**2 - a**2)
79+
th = 2 * math.asin(a / r) # chord angle
2580

26-
copy_tree(source_folder, destination_folder)
27-
return True
81+
# Center of the circle
82+
xc = xo + b * ya / a
83+
yc = yo - b * xa / a
84+
85+
alpha = math.atan2((y1 - yc), (x1 - xc))
86+
xr = []
87+
yr = []
88+
for i in range(n):
89+
i += 1
90+
dth = (float(i) / (n + 1)) * th
91+
xi = xc + r * math.cos(alpha - dth)
92+
yi = yc + r * math.sin(alpha - dth)
93+
xr.append(xi)
94+
yr.append(yi)
95+
96+
if reverse:
97+
xr.reverse()
98+
yr.reverse()
99+
100+
return xr, yr

0 commit comments

Comments
 (0)