/
PrimitivesCircuit.py
1335 lines (1168 loc) · 41.6 KB
/
PrimitivesCircuit.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
import math
import os
import random
from pyaedt.application.Variables import decompose_variable_value
from pyaedt.generic.LoadAEDTFile import load_keyword_in_aedt_file
from pyaedt.generic.constants import AEDT_UNITS
from pyaedt.generic.general_methods import filter_string
from pyaedt.generic.general_methods import generate_unique_name
from pyaedt.generic.general_methods import open_file
from pyaedt.generic.general_methods import pyaedt_function_handler
from pyaedt.generic.general_methods import recursive_glob
from pyaedt.modeler.circuits.object3dcircuit import CircuitComponent
from pyaedt.modeler.circuits.object3dcircuit import Wire
class CircuitComponents(object):
"""CircutComponents class.
Manages all circuit components for Nexxim and Twin Builder.
Examples
--------
>>> from pyaedt import Circuit
>>> aedtapp = Circuit()
>>> prim = aedtapp.modeler.schematic
"""
@pyaedt_function_handler()
def __getitem__(self, partname):
"""Retrieve a part.
Parameters
----------
partname : int or str
Part ID or part name.
Returns
-------
type
Part object details.
"""
if isinstance(partname, int):
return self.components[partname]
for el in self.components:
if self.components[el].name == partname or self.components[el].composed_name == partname or el == partname:
return self.components[el]
return None
def __init__(self, modeler):
self._app = modeler._app
self._modeler = modeler
self.logger = self._app.logger
self.o_model_manager = self._modeler.o_model_manager
self.oeditor = self._modeler.oeditor
self._currentId = 0
self.components = {}
self.wires = {}
self.refresh_all_ids()
self.current_position = [0, 0]
self.increment_mils = [1000, 1000]
self.limits_mils = 20000
@property
def o_definition_manager(self):
"""Aedt oDefinitionManager.
References
----------
>>> oDefinitionManager = oProject.GetDefinitionManager()
"""
return self._app.oproject.GetDefinitionManager()
@property
def o_component_manager(self):
"""Component manager object."""
return self._app.o_component_manager
@property
def o_symbol_manager(self):
"""Model manager object."""
return self._app.o_symbol_manager
@property
def version(self):
"""Version."""
return self._app._aedt_version
@property
def design_types(self):
"""Design types."""
return self._app._modeler
@property
def model_units(self):
"""Model units."""
return self._modeler.model_units
@property
def schematic_units(self):
"""Schematic units.
Options are ``"mm"``, ``"mil"``, ``"cm"`` and all other metric and imperial units.
The default is ``"meter"``.
"""
return self._modeler.schematic_units
@schematic_units.setter
def schematic_units(self, value):
self._modeler.schematic_units = value
@property
def design_type(self):
"""Design type."""
return self._app.design_type
@property
def nets(self):
"""List of all schematic nets."""
nets_comp = self.oeditor.GetAllNets()
nets = []
for net in nets_comp:
v = net.split(";")
if v[0].replace("Wire@", "") not in nets:
nets.append(v[0].replace("Wire@", ""))
return nets
@pyaedt_function_handler()
def _convert_point_to_meter(self, point):
"""Convert numbers automatically to mils.
It is rounded to the nearest 100 mil which is minimum schematic snap unit.
"""
xpos = point[0]
ypos = point[1]
if isinstance(point[0], (float, int)):
xpos = (
round(point[0] * AEDT_UNITS["Length"][self.schematic_units] / AEDT_UNITS["Length"]["mil"], -2)
* AEDT_UNITS["Length"]["mil"]
)
else:
decomposed = decompose_variable_value(point[0])
if decomposed[1] != "":
xpos = (
round(decomposed[0] * AEDT_UNITS["Length"][decomposed[1]] / AEDT_UNITS["Length"]["mil"], -2)
* AEDT_UNITS["Length"]["mil"]
)
if isinstance(point[1], (float, int)):
ypos = (
round(point[1] * AEDT_UNITS["Length"][self.schematic_units] / AEDT_UNITS["Length"]["mil"], -2)
* AEDT_UNITS["Length"]["mil"]
)
else:
decomposed = decompose_variable_value(point[1])
if decomposed[1] != "":
ypos = (
round(decomposed[0] * AEDT_UNITS["Length"][decomposed[1]] / AEDT_UNITS["Length"]["mil"], -2)
* AEDT_UNITS["Length"]["mil"]
)
return xpos, ypos
@pyaedt_function_handler()
def _convert_point_to_units(self, point):
"""Numbers are automatically converted and rounded to 100mil."""
return [i / AEDT_UNITS["Length"][self.schematic_units] for i in self._convert_point_to_meter(point)]
@pyaedt_function_handler()
def _get_location(self, location=None):
if not location:
xpos = self.current_position[0]
ypos = self.current_position[1]
else:
xpos, ypos = self._convert_point_to_meter(location)
if isinstance(xpos, (float, int)) and isinstance(ypos, (float, int)):
self.current_position = [xpos, ypos]
self.current_position[1] += AEDT_UNITS["Length"]["mil"] * self.increment_mils[1]
if self.current_position[1] / AEDT_UNITS["Length"]["mil"] > self.limits_mils:
self.current_position[1] = 0
self.current_position[0] += AEDT_UNITS["Length"]["mil"] * self.increment_mils[0]
return xpos, ypos
@pyaedt_function_handler()
def create_unique_id(self):
"""Create an unique ID.
Returns
-------
int
Unique ID in the range of ``[1, 65535]``.
"""
element_ids = []
for el in self.oeditor.GetAllElements():
try:
element_ids.append(int(el.split("@")[1].split(";")[1].split(":")[0]))
except (IndexError, ValueError):
pass
id = random.randint(1, 65535)
while id in element_ids:
id = random.randint(1, 65535)
return id
@pyaedt_function_handler()
def add_pin_iports(self, name, id_num):
"""Add ports on pins.
Parameters
----------
name : str
Name of the component.
id_num : int
ID of circuit component.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
References
----------
>>> oeditor.AddPinIPorts
"""
comp_id = "CompInst@" + name + ";" + str(id_num) + ";395"
arg1 = ["Name:Selections", "Selections:=", [comp_id]]
self.oeditor.AddPinIPorts(arg1)
self.refresh_all_ids()
return True
@pyaedt_function_handler()
def create_interface_port(self, name, location=None, angle=0):
"""Create an interface port.
Parameters
----------
name : str
Name of the port.
location : list, optional
Position on the X and Y axis. The default is ``None``.
angle : float, optional
Angle rotation in degrees. The default is ``0``.
Returns
-------
:class:`pyaedt.modules.Boundary.Excitation`
Circuit Excitation Object.
References
----------
>>> oEditor.CreateIPort
"""
if location is None:
location = []
if name in self._app.excitations:
self.logger.warning("Port name already assigned.")
return False
xpos, ypos = self._get_location(location)
id = self.create_unique_id()
arg1 = ["NAME:IPortProps", "Name:=", name, "Id:=", id]
arg2 = ["NAME:Attributes", "Page:=", 1, "X:=", xpos, "Y:=", ypos, "Angle:=", angle, "Flip:=", False]
id = self.oeditor.CreateIPort(arg1, arg2)
id = int(id.split(";")[1])
self.add_id_to_component(id)
# return id, self.components[id].composed_name
for el in self.components:
if ("IPort@" + name + ";" + str(id)) in self.components[el].composed_name:
return self._app.excitation_objects[name]
return False
@pyaedt_function_handler()
def create_page_port(self, name, location=[], angle=0):
"""Create a page port.
Parameters
----------
name : str
Name of the port.
location : list, optional
Position on the X and Y axis. The default is ``None``.
angle : optional
Angle rotation in degrees. The default is ``0``.
Returns
-------
:class:`pyaedt.modeler.cad.object3dcircuit.CircuitComponent`
Circuit Component Object.
References
----------
>>> oEditor.CreatePagePort
"""
xpos, ypos = self._get_location(location)
id = self.create_unique_id()
id = self.oeditor.CreatePagePort(
["NAME:PagePortProps", "Name:=", name, "Id:=", id],
["NAME:Attributes", "Page:=", 1, "X:=", xpos, "Y:=", ypos, "Angle:=", angle, "Flip:=", False],
)
id = int(id.split(";")[1])
# self.refresh_all_ids()
self.add_id_to_component(id)
return self.components[id]
@pyaedt_function_handler()
def create_gnd(self, location=None, angle=0):
"""Create a ground.
Parameters
----------
location : list, optional
Position on the X and Y axis. The default is ``None``.
angle : optional
Angle rotation in degrees. The default is ``0``.
Returns
-------
:class:`pyaedt.modeler.cad.object3dcircuit.CircuitComponent`
Circuit Component Object.
References
----------
>>> oEditor.CreateGround
"""
if location is None:
location = []
xpos, ypos = self._get_location(location)
id = self.create_unique_id()
name = self.oeditor.CreateGround(
["NAME:GroundProps", "Id:=", id],
["NAME:Attributes", "Page:=", 1, "X:=", xpos, "Y:=", ypos, "Angle:=", angle, "Flip:=", False],
)
id = int(name.split(";")[1])
self.add_id_to_component(id)
# return id, self.components[id].composed_name
for el in self.components:
if name in self.components[el].composed_name:
return self.components[el]
@pyaedt_function_handler(touchstone_full_path="input_file")
def create_model_from_touchstone(self, input_file, model_name=None, show_bitmap=True):
"""Create a model from a Touchstone file.
Parameters
----------
input_file : str
Full path to the Touchstone file.
model_name : str, optional
Name of the model. The default is ``None``.
show_bitmap : bool, optional
Show bitmap image of schematic component.
The default value is ``True``.
Returns
-------
str
Model name when successfully created. ``False`` if something went wrong.
References
----------
>>> oModelManager.Add
>>> oComponentManager.Add
"""
def _parse_ports_name(file, num_terminal):
"""Parse and interpret the option line in the touchstone file.
Parameters
----------
file : str
Path of the Touchstone file.
num_terminal : int
Number of terminals.
Returns
-------
List of str
Names of the ports in the touchstone file.
"""
portnames = []
line = file.readline()
while not line.startswith("! Port") and not line.startswith("! NPort") and line.find("S11") == -1:
line = file.readline()
if line.startswith("! Port"):
while line.startswith("! Port"):
portnames.append(line.split(" = ")[1].strip())
line = file.readline()
else: # pragma: no cover
portnames = ["Port" + str(n) for n in range(1, num_terminal + 1)]
return portnames
if not model_name:
model_name = os.path.splitext(os.path.basename(input_file))[0]
if "." in model_name:
model_name = model_name.replace(".", "_")
if model_name in list(self.o_model_manager.GetNames()):
model_name = generate_unique_name(model_name, n=2)
num_terminal = int(os.path.splitext(input_file)[1].lower().strip(".sp"))
# with open_file(touchstone_full_path, "r") as f:
# port_names = _parse_ports_name(f, num_terminal)
port_names = []
with open_file(input_file, "r") as f:
for line in f:
line = line.strip()
if line.startswith(("!", "#", "")):
if "Port" in line and "=" in line and "Impedance" not in line:
port_names.append(line.split("=")[-1].strip().replace(" ", "_").strip("[]"))
else:
break
image_subcircuit_path = ""
bmp_file_name = ""
if show_bitmap:
image_subcircuit_path = os.path.join(
self._modeler._app.desktop_install_dir, "syslib", "Bitmaps", "nport.bmp"
)
bmp_file_name = os.path.basename(image_subcircuit_path)
if not port_names:
port_names = ["Port" + str(i + 1) for i in range(num_terminal)]
arg = [
"NAME:" + model_name,
"Name:=",
model_name,
"ModTime:=",
0,
"Library:=",
"",
"LibLocation:=",
"Project",
"ModelType:=",
"nport",
"Description:=",
"",
"ImageFile:=",
image_subcircuit_path,
"SymbolPinConfiguration:=",
0,
["NAME:PortInfoBlk"],
["NAME:PortOrderBlk"],
"filename:=",
input_file,
"numberofports:=",
num_terminal,
"sssfilename:=",
"",
"sssmodel:=",
False,
"PortNames:=",
port_names,
"domain:=",
"frequency",
"datamode:=",
"Link",
"devicename:=",
"",
"SolutionName:=",
"",
"displayformat:=",
"MagnitudePhase",
"datatype:=",
"SMatrix",
[
"NAME:DesignerCustomization",
"DCOption:=",
0,
"InterpOption:=",
0,
"ExtrapOption:=",
1,
"Convolution:=",
0,
"Passivity:=",
0,
"Reciprocal:=",
False,
"ModelOption:=",
"",
"DataType:=",
1,
],
[
"NAME:NexximCustomization",
"DCOption:=",
3,
"InterpOption:=",
1,
"ExtrapOption:=",
3,
"Convolution:=",
0,
"Passivity:=",
0,
"Reciprocal:=",
False,
"ModelOption:=",
"",
"DataType:=",
2,
],
[
"NAME:HSpiceCustomization",
"DCOption:=",
1,
"InterpOption:=",
2,
"ExtrapOption:=",
3,
"Convolution:=",
0,
"Passivity:=",
0,
"Reciprocal:=",
False,
"ModelOption:=",
"",
"DataType:=",
3,
],
"NoiseModelOption:=",
"External",
]
self.o_model_manager.Add(arg)
arg = [
"NAME:" + model_name,
"Info:=",
[
"Type:=",
10,
"NumTerminals:=",
num_terminal,
"DataSource:=",
"",
"ModifiedOn:=",
1618569625,
"Manufacturer:=",
"",
"Symbol:=",
"",
"ModelNames:=",
"",
"Footprint:=",
"",
"Description:=",
"",
"InfoTopic:=",
"",
"InfoHelpFile:=",
"",
"IconFile:=",
bmp_file_name,
"Library:=",
"",
"OriginalLocation:=",
"Project",
"IEEE:=",
"",
"Author:=",
"",
"OriginalAuthor:=",
"",
"CreationDate:=",
1618569625,
"ExampleFile:=",
"",
"HiddenComponent:=",
0,
"CircuitEnv:=",
0,
"GroupID:=",
0,
],
"CircuitEnv:=",
0,
"Refbase:=",
"S",
"NumParts:=",
1,
"ModSinceLib:=",
False,
]
for i in range(num_terminal):
arg.append("Terminal:=")
arg.append([port_names[i], port_names[i], "A", False, i, 1, "", "Electrical", "0"])
arg.append("CompExtID:=")
arg.append(5)
arg.append(
[
"NAME:Parameters",
"MenuProp:=",
["CoSimulator", "SD", "", "Default", 0],
"ButtonProp:=",
["CosimDefinition", "SD", "", "Edit", "Edit", 40501, "ButtonPropClientData:=", []],
]
)
arg.append(
[
"NAME:CosimDefinitions",
[
"NAME:CosimDefinition",
"CosimulatorType:=",
102,
"CosimDefName:=",
"Default",
"IsDefinition:=",
True,
"Connect:=",
True,
"ModelDefinitionName:=",
model_name,
"ShowRefPin2:=",
2,
"LenPropName:=",
"",
],
"DefaultCosim:=",
"Default",
]
)
self.o_component_manager.Add(arg)
return model_name
@pyaedt_function_handler()
def create_touchstone_component(
self,
model_name,
location=None,
angle=0,
show_bitmap=True,
):
"""Create a component from a Touchstone model.
Parameters
----------
model_name : str
Name of the Touchstone model or full path to touchstone file.
If full touchstone is provided then, new model will be created.
location : list of float, optional
Position on the X and Y axis.
angle : float, optional
Angle rotation in degrees. The default is ``0``.
show_bitmap : bool, optional
Show bitmap image of schematic component.
The default value is ``True``.
Returns
-------
:class:`pyaedt.modeler.cad.object3dcircuit.CircuitComponent`
Circuit Component Object.
References
----------
>>> oModelManager.Add
>>> oComponentManager.Add
>>> oEditor.CreateComponent
Examples
--------
>>> from pyaedt import Circuit
>>> cir = Circuit()
>>> comps = cir.modeler.components
>>> s_parameter_path = os.path.join("your_path", "s_param_file_name.s4p")
>>> circuit_comp = comps.create_touchstone_component(s_parameter_path, location=[0.0, 0.0], show_bitmap=False)
"""
if location is None:
location = []
xpos, ypos = self._get_location(location)
id = self.create_unique_id()
if os.path.exists(model_name):
model_name = self.create_model_from_touchstone(model_name, show_bitmap=show_bitmap)
arg1 = ["NAME:ComponentProps", "Name:=", model_name, "Id:=", str(id)]
arg2 = ["NAME:Attributes", "Page:=", 1, "X:=", xpos, "Y:=", ypos, "Angle:=", angle, "Flip:=", False]
id = self.oeditor.CreateComponent(arg1, arg2)
id = int(id.split(";")[1])
self.add_id_to_component(id)
return self.components[id]
@pyaedt_function_handler(inst_name="name")
def create_component(
self,
name=None,
component_library="Resistors",
component_name="RES_",
location=None,
angle=0,
use_instance_id_netlist=False,
global_netlist_list=None,
):
"""Create a component from a library.
Parameters
----------
name : str, optional
Name of the instance. The default is ``None.``
component_library : str, optional
Name of the component library. The default is ``"Resistors"``.
component_name : str, optional
Name of component in the library. The default is ``"RES"``.
location : list of float, optional
Position on the X axis and Y axis.
The default is ``None``, in which case the component is placed in [0, 0].
angle : optional
Angle rotation in degrees. The default is ``0``.
use_instance_id_netlist : bool, optional
Whether to enable the instance ID in the net list.
The default is ``False``.
global_netlist_list : list, optional
The default is ``None``, in which case an empty list is passed.
Returns
-------
:class:`pyaedt.modeler.cad.object3dcircuit.CircuitComponent`
Circuit Component Object.
References
----------
>>> oEditor.CreateComponent
Examples
--------
>>> from pyaedt import TwinBuilder
>>> aedtapp = TwinBuilder()
>>> cmp = aedtapp.modeler.schematic.create_component(component_library="",component_name="ExcitationComponent")
>>> cmp.set_property("ShowPin",True)
>>> aedtapp.release_desktop(True, True)
"""
id = self.create_unique_id()
if component_library:
inst_name = self.design_libray + "\\" + component_library + ":" + component_name
else:
inst_name = component_name
arg1 = ["NAME:ComponentProps", "Name:=", inst_name, "Id:=", str(id)]
xpos, ypos = self._get_location(location)
angle = math.pi * angle / 180
arg2 = ["NAME:Attributes", "Page:=", 1, "X:=", xpos, "Y:=", ypos, "Angle:=", angle, "Flip:=", False]
id = self.oeditor.CreateComponent(arg1, arg2)
id = int(id.split(";")[1])
# self.refresh_all_ids()
self.add_id_to_component(id)
if name:
self.components[id].set_property("InstanceName", name)
if use_instance_id_netlist:
self.enable_use_instance_name(component_library, component_name)
elif global_netlist_list:
self.enable_global_netlist(component_name, global_netlist_list)
return self.components[id]
@pyaedt_function_handler(component_name="assignment")
def disable_data_netlist(self, assignment):
"""Disable the Nexxim global net list.
Parameters
----------
assignment : str
Name of the component.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
References
----------
>>> oComponentManager.GetData
>>> oComponentManager.Edit
"""
name = assignment
properties = self.o_component_manager.GetData(name)
if len(properties) > 0:
nexxim = list(properties[len(properties) - 1][1])
for el in nexxim:
if el == "Data:=":
nexxim_data = list(nexxim[nexxim.index(el) + 1])
nexxim_data[1] = ""
nexxim[nexxim.index(el) + 1] = nexxim_data
self.o_component_manager.Edit(
name, ["Name:" + assignment, ["NAME:CosimDefinitions", nexxim, "DefaultCosim:=", "DefaultNetlist"]]
)
return True
@pyaedt_function_handler(component_name="assignment")
def enable_global_netlist(self, assignment, global_netlist_list=None):
"""Enable Nexxim global net list.
Parameters
----------
assignment : str
Name of the component.
global_netlist_list : list
A list of lines to include. The default is ``None``.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
References
----------
>>> oComponentManager.GetData
>>> oComponentManager.Edit
"""
if global_netlist_list is None:
global_netlist_list = []
name = assignment
properties = self.o_component_manager.GetData(name)
if len(properties) > 0:
nexxim = list(properties[len(properties) - 1][1])
for el in nexxim:
if el == "GRef:=":
nexxim_data = list(nexxim[nexxim.index(el) + 1])
nexxim_data[1] = "\n".join(global_netlist_list).replace("\\", "/")
nexxim[nexxim.index(el) + 1] = nexxim_data
self.o_component_manager.Edit(
name,
["Name:" + assignment, ["NAME:CosimDefinitions", nexxim, "DefaultCosim:=", "DefaultNetlist"]],
)
return True
@pyaedt_function_handler(symbol_name="name", pin_lists="pins")
def create_symbol(self, name, pins):
"""Create a symbol.
Parameters
----------
name : str
Name of the symbol.
pins : list
List of the pins.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
References
----------
>>> oSymbolManager.Add
"""
numpins = len(pins)
h = int(numpins / 2)
x1 = 0
y2 = 0
x2 = 0.00508
y1 = 0.00254 * (h + 3)
xp = -0.00254
yp = 0.00254 * (h + 2)
angle = 0
arg = [
"NAME:" + name,
"ModTime:=",
1591858230,
"Library:=",
"",
"ModSinceLib:=",
False,
"LibLocation:=",
"Project",
"HighestLevel:=",
1,
"Normalize:=",
True,
"InitialLevels:=",
[0, 1],
["NAME:Graphics"],
]
self.o_symbol_manager.Add(arg)
id = 2
i = 1
id += 2
r = numpins - (h * 2)
for pin in pins:
arg.append(
[
"NAME:PinDef",
"Pin:=",
[pin, xp, yp, angle, "N", 0, 0.00254, False, 0, True, "", False, False, pin, True],
]
)
if i == (h + r):
yp = 0.00254 * (h + 2)
xp = 0.00762
angle = math.pi
else:
yp -= 0.00254
id += 2
i += 1
arg.append(
[
"NAME:Graphics",
["NAME:1", "Rect:=", [0, 0, 0, 0, (x1 + x2) / 2, (y1 + y2) / 2, x2 - x1, y1 - y2, 0, 0, 8192]],
]
)
self.o_symbol_manager.EditWithComps(name, arg, [])
return True
@pyaedt_function_handler()
def enable_use_instance_name(self, component_library="Resistors", component_name="RES_"):
"""Enable the use of the instance name.
Parameters
----------
component_library : str, optional
Name of the component library. The default is ``"Resistors"``.
component_name : str, optional
Name of the component. The default is ``"RES_"``.
Returns
-------
bool
``True`` when successful, ``False`` when failed.
References
----------
>>> oComponentManager.GetData
>>> oComponentManager.Edit
"""
if component_library:
name = self.design_libray + "\\" + component_library + ":" + component_name
else:
name = component_name
properties = self.o_component_manager.GetData(name)
if len(properties) > 0:
nexxim = list(properties[len(properties) - 1][1])
for el in nexxim:
if el == "Data:=":
nexxim_data = list(nexxim[nexxim.index(el) + 1])
netlist = nexxim_data[1]
if "@InstanceName" not in netlist[:15]:
newnetlist = "@InstanceName" + netlist[4:]
nexxim_data[1] = newnetlist
nexxim[nexxim.index(el) + 1] = nexxim_data
elif el == "GRef:=":
nexxim_data = list(nexxim[nexxim.index(el) + 1])
nexxim[nexxim.index(el) + 1] = nexxim_data
self.o_component_manager.Edit(
name,
["Name:" + component_name, ["NAME:CosimDefinitions", nexxim, "DefaultCosim:=", "DefaultNetlist"]],
)
return True
@pyaedt_function_handler()
def refresh_all_ids(self):
"""Refresh all IDs and return the number of components.
References
----------
>>> oEditor.GetAllElements()
"""
obj = self.oeditor.GetAllElements()
if not obj:
obj = []
obj = [i for i in obj if "Wire" not in i[:4]]
for el in obj:
if not self.get_obj_id(el):
name = el.split(";")
if len(name) > 1:
o = CircuitComponent(self, tabname=self.tab_name)
o.name = name[0]
if len(name) == 2:
o.schematic_id = name[1]
objID = int(o.schematic_id)
else:
o.id = int(name[1])
o.schematic_id = name[2]
objID = o.id
self.components[objID] = o
return len(self.components)
@pyaedt_function_handler()
def add_id_to_component(self, id):
"""Add an ID to a component.