Skip to content

Commit 3b22d74

Browse files
maxcapodi78pyansys-ci-botgkorompiSamuelopez-ansys
authored
FEAT: Added offset to page port creation during connect_to_component. (#6599)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: gkorompi <[email protected]> Co-authored-by: Samuel Lopez <[email protected]>
1 parent 054975c commit 3b22d74

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

doc/changelog.d/6599.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added offset to page port creation during connect_to_component.

src/ansys/aedt/core/generic/configurations.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
# SOFTWARE.
24-
2524
from collections import defaultdict
2625
import copy
2726
from datetime import datetime
2827
import json
28+
import math
2929
import os
3030
from pathlib import Path
3131
import tempfile
@@ -2386,7 +2386,10 @@ def import_config(self, config_file, *args):
23862386
self.results._reset_results()
23872387

23882388
data = read_configuration_file(config_file)
2389-
2389+
try:
2390+
offset = data["general"]["port_offset"]
2391+
except KeyError:
2392+
offset = 0
23902393
if self.options.import_variables:
23912394
try:
23922395
for k, v in data["general"]["variables"].items():
@@ -2488,15 +2491,29 @@ def import_config(self, config_file, *args):
24882491
location = [x - y for x, y in zip(gnd_pin.location, [0, 0.00254])]
24892492
self._app.modeler.schematic.create_gnd(location, page=i)
24902493
elif len(pins) > 1:
2491-
pins[0].connect_to_component(pins[1:], page_name=i)
2494+
pins[0].connect_to_component(pins[1:], page_name=i, offset=offset)
24922495

24932496
for i, j in data["ports"].items():
2497+
created = False
24942498
for key, value in j.items():
24952499
for comp in comp_list:
24962500
if comp.parameters["InstanceName"] == key:
24972501
for pin in comp.pins:
24982502
if pin.name in value:
2499-
self._app.modeler.schematic.create_interface_port(name=i, location=pin.location)
2503+
location = [
2504+
pin.location[0] - offset * math.cos(pin.total_angle * math.pi / 180),
2505+
pin.location[1] - offset * math.sin(pin.total_angle * math.pi / 180),
2506+
]
2507+
2508+
if not created:
2509+
self._app.modeler.schematic.create_interface_port(name=i, location=location)
2510+
created = True
2511+
else:
2512+
self._app.modeler.schematic.create_page_port(
2513+
name=i, location=location, angle=pin.total_angle
2514+
)
2515+
if offset != 0:
2516+
self._app.modeler.schematic.create_wire([location, pin.location])
25002517

25012518
if self.options.import_setups and data.get("setups", None):
25022519
self.results.import_setup = True

src/ansys/aedt/core/modeler/circuits/object_3d_circuit.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ansys.aedt.core.generic.general_methods import pyaedt_function_handler
3232
from ansys.aedt.core.generic.numbers_utils import decompose_variable_value
3333
from ansys.aedt.core.generic.settings import settings
34+
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators
3435
from ansys.aedt.core.modeler.geometry_operators import GeometryOperators as go
3536

3637

@@ -48,6 +49,11 @@ def units(self):
4849
"""Length units."""
4950
return self._circuit_comp.units
5051

52+
@property
53+
def total_angle(self):
54+
"""Return the pin orientation in the schematic."""
55+
return int(self.angle + self._circuit_comp.angle)
56+
5157
@property
5258
def location(self):
5359
"""Pin Position in [x,y] format.
@@ -152,7 +158,14 @@ def _get_deltas(self, point, move_x=True, move_y=True, positive=True, units=1):
152158

153159
@pyaedt_function_handler(component_pin="assignment")
154160
def connect_to_component(
155-
self, assignment, page_name=None, use_wire=False, wire_name="", clearance_units=1, page_port_angle=None
161+
self,
162+
assignment,
163+
page_name=None,
164+
use_wire=False,
165+
wire_name="",
166+
clearance_units=1,
167+
page_port_angle=None,
168+
offset=0,
156169
):
157170
"""Connect schematic components.
158171
@@ -174,6 +187,8 @@ def connect_to_component(
174187
page_port_angle : int, optional
175188
Page port angle on the source pin. The default is ``None``, in which case
176189
the angle is automatically computed.
190+
offset : float, optional
191+
Page port offset in the direction of the pin. The default is ``0``.
177192
178193
Returns
179194
-------
@@ -274,11 +289,7 @@ def connect_to_component(
274289
if page_name is None:
275290
page_name = f"{self._circuit_comp.composed_name.replace('CompInst@', '').replace(';', '_')}_{self.name}"
276291

277-
if (
278-
len(assignment) == 1
279-
and (abs(self.location[1] - assignment[0].location[1]) + abs(self.location[0] - assignment[0].location[0]))
280-
< 0.01524
281-
):
292+
if len(assignment) == 1 and GeometryOperators.points_distance(self.location, assignment[0].location) < 0.01524:
282293
self._circuit_comp._circuit_components.create_wire([self.location, assignment[0].location], name=page_name)
283294
return True
284295
if "Port" in self._circuit_comp.composed_name:
@@ -296,19 +307,25 @@ def connect_to_component(
296307
self._component._circuit_components.logger.debug(
297308
"Cannot parse page name from circuit component name"
298309
)
299-
if self.location[0] > self._circuit_comp.location[0]:
300-
angle = 180
301-
else:
302-
angle = 0
303-
ret1 = self._circuit_comp._circuit_components.create_page_port(page_name, self.location, angle=angle)
310+
angle = page_port_angle if page_port_angle else self.total_angle
311+
location = [
312+
self.location[0] - offset * math.cos(self.total_angle * math.pi / 180),
313+
self.location[1] - offset * math.sin(self.total_angle * math.pi / 180),
314+
]
315+
ret1 = self._circuit_comp._circuit_components.create_page_port(page_name, location, angle=angle)
316+
if offset != 0:
317+
self._circuit_comp._circuit_components.create_wire([self.location, location])
304318
for cmp in assignment:
305-
if cmp.location[0] > cmp._circuit_comp.location[0]:
306-
angle = 180
307-
else:
308-
angle = 0
319+
location = [
320+
cmp.location[0] - offset * math.cos(cmp.total_angle * math.pi / 180),
321+
cmp.location[1] - offset * math.sin(cmp.total_angle * math.pi / 180),
322+
]
323+
309324
ret2 = self._circuit_comp._circuit_components.create_page_port(
310-
page_name, location=cmp.location, angle=angle
325+
page_name, location=location, angle=cmp.total_angle
311326
)
327+
if offset != 0:
328+
self._circuit_comp._circuit_components.create_wire([cmp.location, location])
312329
if ret1 and ret2:
313330
return True, ret1, ret2
314331
else:

tests/system/general/test_21_Circuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def test_44_auto_wire(self, aedtapp):
823823
l2 = aedtapp.modeler.schematic.create_inductor(value=1e-9, location=[1400, 4000], angle=0)
824824
aedtapp.modeler.schematic.create_resistor(value=50, location=[3100, 3200])
825825

826-
assert p1.pins[0].connect_to_component(r1.pins[1], use_wire=True)
826+
assert p1.pins[0].connect_to_component(r1.pins[1], use_wire=True, offset=0.0512)
827827
assert l1.pins[0].connect_to_component(l2.pins[0], use_wire=True)
828828
assert l3.pins[0].connect_to_component(l2.pins[1], use_wire=True, clearance_units=2)
829829
assert l4.pins[1].connect_to_component(l3.pins[0], use_wire=True, clearance_units=2)

0 commit comments

Comments
 (0)