-
Notifications
You must be signed in to change notification settings - Fork 0
/
components.py
2748 lines (2418 loc) · 103 KB
/
components.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# 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.
"""This module contains the `Components` class.
"""
import codecs
import json
import math
import re
import warnings
from pyedb.dotnet.clr_module import String
from pyedb.dotnet.edb_core.definition.component_def import EDBComponentDef
from pyedb.dotnet.edb_core.edb_data.components_data import EDBComponent
from pyedb.dotnet.edb_core.edb_data.padstacks_data import EDBPadstackInstance
from pyedb.dotnet.edb_core.edb_data.sources import Source, SourceType
from pyedb.dotnet.edb_core.general import convert_py_list_to_net_list
from pyedb.dotnet.edb_core.padstack import EdbPadstacks
from pyedb.generic.general_methods import (
_retry_ntimes,
generate_unique_name,
get_filename_without_extension,
pyedb_function_handler,
)
from pyedb.modeler.geometry_operators import GeometryOperators
def resistor_value_parser(RValue):
"""Convert a resistor value.
Parameters
----------
RValue : float
Resistor value.
Returns
-------
float
Resistor value.
"""
if isinstance(RValue, str):
RValue = RValue.replace(" ", "")
RValue = RValue.replace("meg", "m")
RValue = RValue.replace("Ohm", "")
RValue = RValue.replace("ohm", "")
RValue = RValue.replace("k", "e3")
RValue = RValue.replace("m", "e-3")
RValue = RValue.replace("M", "e6")
RValue = float(RValue)
return RValue
class Components(object):
"""Manages EDB components and related method accessible from `Edb.components` property.
Parameters
----------
edb_class : :class:`pyedb.dotnet.edb.Edb`
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components
"""
@pyedb_function_handler()
def __getitem__(self, name):
"""Get a component or component definition from the Edb project.
Parameters
----------
name : str
Returns
-------
:class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`
"""
if name in self.instances:
return self.instances[name]
elif name in self.definitions:
return self.definitions[name]
self._pedb.logger.error("Component or definition not found.")
return
def __init__(self, p_edb):
self._pedb = p_edb
self._cmp = {}
self._res = {}
self._cap = {}
self._ind = {}
self._ios = {}
self._ics = {}
self._others = {}
self._pins = {}
self._comps_by_part = {}
self._init_parts()
self._padstack = EdbPadstacks(self._pedb)
@property
def _logger(self):
"""Logger."""
return self._pedb.logger
@property
def _edb(self):
return self._pedb.edb_api
@pyedb_function_handler()
def _init_parts(self):
a = self.components
a = self.resistors
a = self.ICs
a = self.Others
a = self.inductors
a = self.IOs
a = self.components_by_partname
return True
def _get_edb_value(self, value):
return self._pedb.edb_value(value)
@property
def _edbutils(self):
return self._pedb.edbutils
@property
def _active_layout(self):
return self._pedb.active_layout
@property
def _layout(self):
return self._pedb.layout
@property
def _cell(self):
return self._pedb.cell
@property
def _db(self):
return self._pedb.active_db
@property
def components(self):
"""Component setup information.
.. deprecated:: 0.6.62
Use new property :func:`instances` instead.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Default dictionary for the EDB component.
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.components
"""
warnings.warn("Use new property :func:`instances` instead.", DeprecationWarning)
return self.instances
@property
def instances(self):
"""All Cell components objects.
Returns
-------
Dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Default dictionary for the EDB component.
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.components
"""
if not self._cmp:
self.refresh_components()
return self._cmp
@property
def definitions(self):
"""Retrieve component definition list.
Returns
-------
dict of :class:`EDBComponentDef`"""
return {l.GetName(): EDBComponentDef(self._pedb, l) for l in list(self._pedb.component_defs)}
@property
def nport_comp_definition(self):
"""Retrieve Nport component definition list."""
m = "Ansys.Ansoft.Edb.Definition.NPortComponentModel"
return {name: l for name, l in self.definitions.items() if m in [i.ToString() for i in l._comp_model]}
@pyedb_function_handler()
def import_definition(self, file_path):
"""Import component definition from json file.
Parameters
----------
file_path : str
File path of json file.
"""
with codecs.open(file_path, "r", encoding="utf-8") as f:
data = json.load(f)
for part_name, p in data["Definitions"].items():
model_type = p["Model_type"]
if part_name not in self.definitions:
continue
comp_definition = self.definitions[part_name]
comp_definition.type = p["Component_type"]
if model_type == "RLC":
comp_definition.assign_rlc_model(p["Res"], p["Ind"], p["Cap"], p["Is_parallel"])
else:
model_name = p["Model_name"]
file_path = data[model_type][model_name]
if model_type == "SParameterModel":
if "Reference_net" in p:
reference_net = p["Reference_net"]
else:
reference_net = None
comp_definition.assign_s_param_model(file_path, model_name, reference_net)
elif model_type == "SPICEModel":
comp_definition.assign_spice_model(file_path, model_name)
else:
pass
return True
@pyedb_function_handler()
def export_definition(self, file_path):
"""Export component definitions to json file.
Parameters
----------
file_path : str
File path of json file.
Returns
-------
"""
data = {
"SParameterModel": {},
"SPICEModel": {},
"Definitions": {},
}
for part_name, props in self.definitions.items():
comp_list = list(props.components.values())
if comp_list:
data["Definitions"][part_name] = {}
data["Definitions"][part_name]["Component_type"] = props.type
comp = comp_list[0]
data["Definitions"][part_name]["Model_type"] = comp.model_type
if comp.model_type == "RLC":
rlc_values = [i if i else 0 for i in comp.rlc_values]
data["Definitions"][part_name]["Res"] = rlc_values[0]
data["Definitions"][part_name]["Ind"] = rlc_values[1]
data["Definitions"][part_name]["Cap"] = rlc_values[2]
data["Definitions"][part_name]["Is_parallel"] = True if comp.is_parallel_rlc else False
else:
if comp.model_type == "SParameterModel":
model = comp.s_param_model
data["Definitions"][part_name]["Model_name"] = model.name
data["Definitions"][part_name]["Reference_net"] = model.reference_net
if not model.name in data["SParameterModel"]:
data["SParameterModel"][model.name] = model.file_path
elif comp.model_type == "SPICEModel":
model = comp.spice_model
data["Definitions"][part_name]["Model_name"] = model.name
if not model.name in data["SPICEModel"]:
data["SPICEModel"][model.name] = model.file_path
else:
model = comp.netlist_model
data["Definitions"][part_name]["Model_name"] = model.netlist
with codecs.open(file_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)
return file_path
@pyedb_function_handler()
def refresh_components(self):
"""Refresh the component dictionary."""
# self._logger.info("Refreshing the Components dictionary.")
self._cmp = {
l.GetName(): EDBComponent(self._pedb, l)
for l in self._layout.groups
if l.ToString() == "Ansys.Ansoft.Edb.Cell.Hierarchy.Component"
}
return True
@property
def resistors(self):
"""Resistors.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of resistors.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.resistors
"""
self._res = {}
for el, val in self.instances.items():
if val.type == "Resistor":
self._res[el] = val
return self._res
@property
def capacitors(self):
"""Capacitors.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of capacitors.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.capacitors
"""
self._cap = {}
for el, val in self.instances.items():
if val.type == "Capacitor":
self._cap[el] = val
return self._cap
@property
def inductors(self):
"""Inductors.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of inductors.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.inductors
"""
self._ind = {}
for el, val in self.instances.items():
if val.type == "Inductor":
self._ind[el] = val
return self._ind
@property
def ICs(self):
"""Integrated circuits.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of integrated circuits.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.ICs
"""
self._ics = {}
for el, val in self.instances.items():
if val.type == "IC":
self._ics[el] = val
return self._ics
@property
def IOs(self):
"""Circuit inupts and outputs.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of circuit inputs and outputs.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.IOs
"""
self._ios = {}
for el, val in self.instances.items():
if val.type == "IO":
self._ios[el] = val
return self._ios
@property
def Others(self):
"""Other core components.
Returns
-------
dict[str, :class:`pyedb.dotnet.edb_core.edb_data.components_data.EDBComponent`]
Dictionary of other core components.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.others
"""
self._others = {}
for el, val in self.instances.items():
if val.type == "Other":
self._others[el] = val
return self._others
@property
def components_by_partname(self):
"""Components by part name.
Returns
-------
dict
Dictionary of components by part name.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> edbapp.components.components_by_partname
"""
self._comps_by_part = {}
for el, val in self.instances.items():
if val.partname in self._comps_by_part.keys():
self._comps_by_part[val.partname].append(val)
else:
self._comps_by_part[val.partname] = [val]
return self._comps_by_part
@pyedb_function_handler()
def get_component_by_name(self, name):
"""Retrieve a component by name.
Parameters
----------
name : str
Name of the component.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
edbcmp = self._pedb.edb_api.cell.hierarchy.component.FindByName(self._active_layout, name)
if edbcmp is not None:
return edbcmp
else:
pass
@pyedb_function_handler()
def get_components_from_nets(self, netlist=None):
"""Retrieve components from a net list.
Parameters
----------
netlist : str, optional
Name of the net list. The default is ``None``.
Returns
-------
list
List of components that belong to the signal nets.
"""
cmp_list = []
if isinstance(netlist, str):
netlist = [netlist]
components = list(self.instances.keys())
for refdes in components:
cmpnets = self._cmp[refdes].nets
if set(cmpnets).intersection(set(netlist)):
cmp_list.append(refdes)
return cmp_list
@pyedb_function_handler()
def _get_edb_pin_from_pin_name(self, cmp, pin):
if not isinstance(cmp, self._pedb.edb_api.cell.hierarchy.component):
return False
if not isinstance(pin, str):
pin = pin.GetName()
pins = self.get_pin_from_component(component=cmp, pinName=pin)
if pins:
return pins[0]
return False
@pyedb_function_handler()
def get_component_placement_vector(
self,
mounted_component,
hosting_component,
mounted_component_pin1,
mounted_component_pin2,
hosting_component_pin1,
hosting_component_pin2,
flipped=False,
):
"""Get the placement vector between 2 components.
Parameters
----------
mounted_component : `edb.cell.hierarchy._hierarchy.Component`
Mounted component name.
hosting_component : `edb.cell.hierarchy._hierarchy.Component`
Hosting component name.
mounted_component_pin1 : str
Mounted component Pin 1 name.
mounted_component_pin2 : str
Mounted component Pin 2 name.
hosting_component_pin1 : str
Hosted component Pin 1 name.
hosting_component_pin2 : str
Hosted component Pin 2 name.
flipped : bool, optional
Either if the mounted component will be flipped or not.
Returns
-------
tuple
Tuple of Vector offset, rotation and solder height.
Examples
--------
>>> edb1 = Edb(edbpath=targetfile1, edbversion="2021.2")
>>> hosting_cmp = edb1.components.get_component_by_name("U100")
>>> mounted_cmp = edb2.components.get_component_by_name("BGA")
>>> vector, rotation, solder_ball_height = edb1.components.get_component_placement_vector(
... mounted_component=mounted_cmp,
... hosting_component=hosting_cmp,
... mounted_component_pin1="A12",
... mounted_component_pin2="A14",
... hosting_component_pin1="A12",
... hosting_component_pin2="A14")
"""
m_pin1_pos = [0.0, 0.0]
m_pin2_pos = [0.0, 0.0]
h_pin1_pos = [0.0, 0.0]
h_pin2_pos = [0.0, 0.0]
if not isinstance(mounted_component, self._pedb.edb_api.cell.hierarchy.component):
return False
if not isinstance(hosting_component, self._pedb.edb_api.cell.hierarchy.component):
return False
if mounted_component_pin1:
m_pin1 = self._get_edb_pin_from_pin_name(mounted_component, mounted_component_pin1)
m_pin1_pos = self.get_pin_position(m_pin1)
if mounted_component_pin2:
m_pin2 = self._get_edb_pin_from_pin_name(mounted_component, mounted_component_pin2)
m_pin2_pos = self.get_pin_position(m_pin2)
if hosting_component_pin1:
h_pin1 = self._get_edb_pin_from_pin_name(hosting_component, hosting_component_pin1)
h_pin1_pos = self.get_pin_position(h_pin1)
if hosting_component_pin2:
h_pin2 = self._get_edb_pin_from_pin_name(hosting_component, hosting_component_pin2)
h_pin2_pos = self.get_pin_position(h_pin2)
#
vector = [h_pin1_pos[0] - m_pin1_pos[0], h_pin1_pos[1] - m_pin1_pos[1]]
vector1 = GeometryOperators.v_points(m_pin1_pos, m_pin2_pos)
vector2 = GeometryOperators.v_points(h_pin1_pos, h_pin2_pos)
multiplier = 1
if flipped:
multiplier = -1
vector1[1] = multiplier * vector1[1]
rotation = GeometryOperators.v_angle_sign_2D(vector1, vector2, False)
if rotation != 0.0:
layinst = mounted_component.GetLayout().GetLayoutInstance()
cmpinst = layinst.GetLayoutObjInstance(mounted_component, None)
center = cmpinst.GetCenter()
center_double = [center.X.ToDouble(), center.Y.ToDouble()]
vector_center = GeometryOperators.v_points(center_double, m_pin1_pos)
x_v2 = vector_center[0] * math.cos(rotation) + multiplier * vector_center[1] * math.sin(rotation)
y_v2 = -1 * vector_center[0] * math.sin(rotation) + multiplier * vector_center[1] * math.cos(rotation)
new_vector = [x_v2 + center_double[0], y_v2 + center_double[1]]
vector = [h_pin1_pos[0] - new_vector[0], h_pin1_pos[1] - new_vector[1]]
if vector:
solder_ball_height = self.get_solder_ball_height(mounted_component)
return True, vector, rotation, solder_ball_height
self._logger.warning("Failed to compute vector.")
return False, [0, 0], 0, 0
@pyedb_function_handler()
def get_solder_ball_height(self, cmp):
"""Get component solder ball height.
Parameters
----------
cmp : str or self._pedb.component
EDB component or str component name.
Returns
-------
double, bool
Salder ball height vale, ``False`` when failed.
"""
if cmp is not None:
if not (isinstance(cmp, self._pedb.edb_api.cell.hierarchy.component)):
cmp = self.get_component_by_name(cmp)
cmp_prop = cmp.GetComponentProperty().Clone()
return cmp_prop.GetSolderBallProperty().GetHeight()
return False
@pyedb_function_handler()
def create_source_on_component(self, sources=None):
"""Create voltage, current source, or resistor on component.
Parameters
----------
sources : list[Source]
List of ``edb_data.sources.Source`` objects.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
"""
if not sources: # pragma: no cover
return False
if isinstance(sources, Source): # pragma: no cover
sources = [sources]
if isinstance(sources, list): # pragma: no cover
for src in sources:
if not isinstance(src, Source): # pragma: no cover
self._logger.error("List of source objects must be passed as an argument.")
return False
for source in sources:
positive_pins = self.get_pin_from_component(source.positive_node.component, source.positive_node.net)
negative_pins = self.get_pin_from_component(source.negative_node.component, source.negative_node.net)
positive_pin_group = self.create_pingroup_from_pins(positive_pins)
if not positive_pin_group: # pragma: no cover
return False
negative_pin_group = self.create_pingroup_from_pins(negative_pins)
if not negative_pin_group: # pragma: no cover
return False
if source.source_type == SourceType.Vsource: # pragma: no cover
positive_pin_group_term = self._create_pin_group_terminal(
positive_pin_group,
)
negative_pin_group_term = self._create_pin_group_terminal(negative_pin_group, isref=True)
positive_pin_group_term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.kVoltageSource)
negative_pin_group_term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.kVoltageSource)
term_name = source.name
positive_pin_group_term.SetName(term_name)
negative_pin_group_term.SetName("{}_ref".format(term_name))
positive_pin_group_term.SetSourceAmplitude(self._get_edb_value(source.amplitude))
negative_pin_group_term.SetSourceAmplitude(self._get_edb_value(source.amplitude))
positive_pin_group_term.SetSourcePhase(self._get_edb_value(source.phase))
negative_pin_group_term.SetSourcePhase(self._get_edb_value(source.phase))
positive_pin_group_term.SetImpedance(self._get_edb_value(source.impedance))
negative_pin_group_term.SetImpedance(self._get_edb_value(source.impedance))
positive_pin_group_term.SetReferenceTerminal(negative_pin_group_term)
elif source.source_type == SourceType.Isource: # pragma: no cover
positive_pin_group_term = self._create_pin_group_terminal(
positive_pin_group,
)
negative_pin_group_term = self._create_pin_group_terminal(negative_pin_group, isref=True)
positive_pin_group_term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.kCurrentSource)
negative_pin_group_term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.kCurrentSource)
term_name = source.name
positive_pin_group_term.SetName(term_name)
negative_pin_group_term.SetName("{}_ref".format(term_name))
positive_pin_group_term.SetSourceAmplitude(self._get_edb_value(source.amplitude))
negative_pin_group_term.SetSourceAmplitude(self._get_edb_value(source.amplitude))
positive_pin_group_term.SetSourcePhase(self._get_edb_value(source.phase))
negative_pin_group_term.SetSourcePhase(self._get_edb_value(source.phase))
positive_pin_group_term.SetImpedance(self._get_edb_value(source.impedance))
negative_pin_group_term.SetImpedance(self._get_edb_value(source.impedance))
positive_pin_group_term.SetReferenceTerminal(negative_pin_group_term)
elif source.source_type == SourceType.Rlc: # pragma: no cover
self.create(
pins=[positive_pins[0], negative_pins[0]],
component_name=source.name,
is_rlc=True,
r_value=source.r_value,
l_value=source.l_value,
c_value=source.c_value,
)
return True
@pyedb_function_handler()
def create_port_on_pins(self, refdes, pins, reference_pins, impedance=50.0, port_name=None, pec_boundary=False):
"""Create circuit port between pins and reference ones.
Parameters
----------
refdes : Component reference designator
str or EDBComponent object.
pins : pin name where the terminal has to be created. Single pin or several ones can be provided.If several
pins are provided a pin group will is created. Pin names can be the EDB name or the EDBPadstackInstance one.
For instance the pin called ``Pin1`` located on component ``U1``, ``U1-Pin1`` or ``Pin1`` can be provided and
will be handled.
str, [str], EDBPadstackInstance, [EDBPadstackInstance]
reference_pins : reference pin name used for terminal reference. Single pin or several ones can be provided.
If several pins are provided a pin group will is created. Pin names can be the EDB name or the
EDBPadstackInstance one. For instance the pin called ``Pin1`` located on component ``U1``, ``U1-Pin1``
or ``Pin1`` can be provided and will be handled.
str, [str], EDBPadstackInstance, [EDBPadstackInstance]
impedance : Port impedance
str, float
port_name : str, optional
Port name. The default is ``None``, in which case a name is automatically assigned.
pec_boundary : bool, optional
Whether to define the PEC boundary, The default is ``False``. If set to ``True``,
a perfect short is created between the pin and impedance is ignored. This
parameter is only supported on a port created between two pins, such as
when there is no pin group.
Returns
-------
EDB terminal created, or False if failed to create.
Example:
>>> from pyedb import Edb
>>> edb = Edb(path_to_edb_file)
>>> pin = "AJ6"
>>> ref_pins = ["AM7", "AM4"]
Or to take all reference pins
>>> ref_pins = [pin for pin in list(edb.components["U2A5"].pins.values()) if pin.net_name == "GND"]
>>> edb.components.create_port_on_pins(refdes="U2A5", pins=pin, reference_pins=ref_pins)
>>> edb.save_edb()
>>> edb.close_edb()
"""
if isinstance(pins, str) or isinstance(pins, EDBPadstackInstance):
pins = [pins]
if isinstance(reference_pins, str):
reference_pins = [reference_pins]
if isinstance(refdes, str) or isinstance(refdes, EDBComponent):
refdes = self.instances[refdes]
if any(refdes.rlc_values):
return self.deactivate_rlc_component(component=refdes, create_circuit_port=True)
if len([pin for pin in pins if isinstance(pin, str)]) == len(pins):
cmp_pins = []
for pin_name in pins:
cmp_pin = [pin for pin in list(refdes.pins.values()) if pin_name == pin.name]
if not cmp_pin:
cmp_pin = [pin for pin in list(refdes.pins.values()) if pin_name == pin.name.split("-")[1]]
if cmp_pin:
cmp_pins.append(cmp_pin[0])
if not cmp_pins:
return
pins = cmp_pins
if not len([pin for pin in pins if isinstance(pin, EDBPadstackInstance)]) == len(pins):
self._logger.error("Pin list must contain only pins instances")
return
if not port_name:
port_name = "Port_{}_{}".format(pins[0].net_name, pins[0].name)
if len([pin for pin in reference_pins if isinstance(pin, str)]) == len(reference_pins):
ref_cmp_pins = []
for ref_pin_name in reference_pins:
cmp_ref_pin = [pin for pin in list(refdes.pins.values()) if ref_pin_name == pin.name]
if not cmp_ref_pin:
cmp_ref_pin = [pin for pin in list(refdes.pins.values()) if ref_pin_name == pin.name.split("-")[1]]
if cmp_ref_pin:
ref_cmp_pins.append(cmp_ref_pin[0])
if not ref_cmp_pins:
return
reference_pins = ref_cmp_pins
if not len([pin for pin in reference_pins if isinstance(pin, EDBPadstackInstance)]) == len(reference_pins):
return
if len(pins) > 1:
pec_boundary = False
self._logger.info(
"Disabling PEC boundary creation, this feature is supported on single pin "
"ports only, {} pins found".format(len(pins))
)
group_name = "group_{}".format(port_name)
pin_group = self.create_pingroup_from_pins(pins, group_name)
term = self._create_pin_group_terminal(pingroup=pin_group, term_name=port_name)
else:
term = self._create_terminal(pins[0].primitive_object, term_name=port_name)
term.SetIsCircuitPort(True)
if len(reference_pins) > 1:
pec_boundary = False
self._logger.info(
"Disabling PEC boundary creation. This feature is supported on single pin"
"ports only {} reference pins found.".format(len(reference_pins))
)
ref_group_name = "group_{}_ref".format(port_name)
ref_pin_group = self.create_pingroup_from_pins(reference_pins, ref_group_name)
ref_term = self._create_pin_group_terminal(pingroup=ref_pin_group, term_name=port_name + "_ref")
else:
ref_term = self._create_terminal(reference_pins[0].primitive_object, term_name=port_name + "_ref")
ref_term.SetIsCircuitPort(True)
term.SetImpedance(self._edb.utility.value(impedance))
term.SetReferenceTerminal(ref_term)
if pec_boundary:
term.SetIsCircuitPort(False)
ref_term.SetIsCircuitPort(False)
term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.PecBoundary)
ref_term.SetBoundaryType(self._edb.cell.terminal.BoundaryType.PecBoundary)
self._logger.info(
"PEC boundary created between pin {} and reference pin {}".format(pins[0].name, reference_pins[0].name)
)
if term:
return term
return False
@pyedb_function_handler()
def create_port_on_component(
self,
component,
net_list,
port_type=SourceType.CoaxPort,
do_pingroup=True,
reference_net="gnd",
port_name=None,
solder_balls_height=None,
solder_balls_size=None,
solder_balls_mid_size=None,
):
"""Create ports on a component.
Parameters
----------
component : str or self._pedb.component
EDB component or str component name.
net_list : str or list of string.
List of nets where ports must be created on the component.
If the net is not part of the component, this parameter is skipped.
port_type : SourceType enumerator, CoaxPort or CircuitPort
Type of port to create. ``CoaxPort`` generates solder balls.
``CircuitPort`` generates circuit ports on pins belonging to the net list.
do_pingroup : bool
True activate pingroup during port creation (only used with combination of CircPort),
False will take the closest reference pin and generate one port per signal pin.
refnet : string or list of string.
list of the reference net.
port_name : str
Port name for overwriting the default port-naming convention,
which is ``[component][net][pin]``. The port name must be unique.
If a port with the specified name already exists, the
default naming convention is used so that port creation does
not fail.
solder_balls_height : float, optional
Solder balls height used for the component. When provided default value is overwritten and must be
provided in meter.
solder_balls_size : float, optional
Solder balls diameter. When provided auto evaluation based on padstack size will be disabled.
solder_balls_mid_size : float, optional
Solder balls mid diameter. When provided if value is different than solder balls size, spheroid shape will
be switched.
Returns
-------
double, bool
Salder ball height vale, ``False`` when failed.
Examples
--------
>>> from pyedb import Edb
>>> edbapp = Edb("myaedbfolder")
>>> net_list = ["M_DQ<1>", "M_DQ<2>", "M_DQ<3>", "M_DQ<4>", "M_DQ<5>"]
>>> edbapp.components.create_port_on_component(cmp="U2A5", net_list=net_list,
>>> port_type=SourceType.CoaxPort, do_pingroup=False, refnet="GND")
"""
if isinstance(component, str):
component = self.instances[component].edbcomponent
if not solder_balls_height:
solder_balls_height = self.components[component.GetName()].solder_ball_height
if not solder_balls_size:
solder_balls_size = self.components[component.GetName()].solder_ball_diameter[0]
if not solder_balls_mid_size:
solder_balls_mid_size = self.components[component.GetName()].solder_ball_diameter[1]
if not isinstance(net_list, list):
net_list = [net_list]
for net in net_list:
if not isinstance(net, str):
try:
net_name = net.name
if net_name != "":
net_list.append(net_name)
except:
pass
if reference_net in net_list:
net_list.remove(reference_net)
cmp_pins = [
p for p in list(component.LayoutObjs) if int(p.GetObjType()) == 1 and p.GetNet().GetName() in net_list
]
for p in cmp_pins: # pragma no cover
if not p.IsLayoutPin():
p.SetIsLayoutPin(True)
if len(cmp_pins) == 0:
self._logger.info(
"No pins found on component {}, searching padstack instances instead".format(component.GetName())
)
return False
pin_layers = cmp_pins[0].GetPadstackDef().GetData().GetLayerNames()
if port_type == SourceType.CoaxPort:
pad_params = self._padstack.get_pad_parameters(pin=cmp_pins[0], layername=pin_layers[0], pad_type=0)
if not pad_params[0] == 7:
if not solder_balls_size: # pragma no cover
sball_diam = min([self._pedb.edb_value(val).ToDouble() for val in pad_params[1]])
sball_mid_diam = sball_diam
else: # pragma no cover
sball_diam = solder_balls_size
if solder_balls_mid_size:
sball_mid_diam = solder_balls_mid_size
else:
sball_mid_diam = solder_balls_size
if not solder_balls_height: # pragma no cover
solder_balls_height = 2 * sball_diam / 3
else: # pragma no cover
if not solder_balls_size:
bbox = pad_params[1]
sball_diam = min([abs(bbox[2] - bbox[0]), abs(bbox[3] - bbox[1])]) * 0.8
else:
sball_diam = solder_balls_size
if not solder_balls_height:
solder_balls_height = 2 * sball_diam / 3
if solder_balls_mid_size:
sball_mid_diam = solder_balls_mid_size
else:
sball_mid_diam = sball_diam
sball_shape = "Cylinder"
if not sball_diam == sball_mid_diam:
sball_shape = "Spheroid"
self.set_solder_ball(
component=component,
sball_height=solder_balls_height,
sball_diam=sball_diam,
sball_mid_diam=sball_mid_diam,
shape=sball_shape,
)
for pin in cmp_pins:
self._padstack.create_coax_port(padstackinstance=pin, name=port_name)
elif port_type == SourceType.CircPort: # pragma no cover
ref_pins = [
p
for p in list(component.LayoutObjs)
if int(p.GetObjType()) == 1 and p.GetNet().GetName() in reference_net
]
for p in ref_pins:
if not p.IsLayoutPin():
p.SetIsLayoutPin(True)
if len(ref_pins) == 0:
self._logger.info("No reference pin found on component {}.".format(component.GetName()))
if do_pingroup: