-
Notifications
You must be signed in to change notification settings - Fork 0
/
edb.py
4499 lines (4024 loc) · 176 KB
/
edb.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 ``Edb`` class.
This module is implicitly loaded in HFSS 3D Layout when launched.
"""
from itertools import combinations
import os
from pathlib import Path
import re
import shutil
import sys
import tempfile
import time
import traceback
from typing import Union
import warnings
from pyedb.configuration.configuration import Configuration
from pyedb.dotnet.application.Variables import decompose_variable_value
from pyedb.dotnet.edb_core.components import Components
from pyedb.dotnet.edb_core.dotnet.database import Database
from pyedb.dotnet.edb_core.dotnet.layout import LayoutDotNet
from pyedb.dotnet.edb_core.edb_data.control_file import (
ControlFile,
convert_technology_file,
)
from pyedb.dotnet.edb_core.edb_data.design_options import EdbDesignOptions
from pyedb.dotnet.edb_core.edb_data.edbvalue import EdbValue
from pyedb.dotnet.edb_core.edb_data.hfss_pi_simulation_setup_data import (
HFSSPISimulationSetup,
)
from pyedb.dotnet.edb_core.edb_data.hfss_simulation_setup_data import (
HfssSimulationSetup,
)
from pyedb.dotnet.edb_core.edb_data.ports import (
BundleWavePort,
CircuitPort,
CoaxPort,
ExcitationSources,
GapPort,
WavePort,
)
from pyedb.dotnet.edb_core.edb_data.raptor_x_simulation_setup_data import (
RaptorXSimulationSetup,
)
from pyedb.dotnet.edb_core.edb_data.simulation_configuration import (
SimulationConfiguration,
)
from pyedb.dotnet.edb_core.edb_data.siwave_simulation_setup_data import (
SiwaveDCSimulationSetup,
SiwaveSYZSimulationSetup,
)
from pyedb.dotnet.edb_core.edb_data.sources import SourceType
from pyedb.dotnet.edb_core.edb_data.terminals import Terminal
from pyedb.dotnet.edb_core.edb_data.variables import Variable
from pyedb.dotnet.edb_core.general import (
LayoutObjType,
Primitives,
convert_py_list_to_net_list,
)
from pyedb.dotnet.edb_core.hfss import EdbHfss
from pyedb.dotnet.edb_core.layout import EdbLayout
from pyedb.dotnet.edb_core.layout_validation import LayoutValidation
from pyedb.dotnet.edb_core.materials import Materials
from pyedb.dotnet.edb_core.net_class import (
EdbDifferentialPairs,
EdbExtendedNets,
EdbNetClasses,
)
from pyedb.dotnet.edb_core.nets import EdbNets
from pyedb.dotnet.edb_core.padstack import EdbPadstacks
from pyedb.dotnet.edb_core.siwave import EdbSiwave
from pyedb.dotnet.edb_core.stackup import Stackup
from pyedb.generic.constants import AEDT_UNITS, SolverType
from pyedb.generic.general_methods import (
generate_unique_name,
get_string_version,
inside_desktop,
is_ironpython,
is_linux,
is_windows,
pyedb_function_handler,
)
from pyedb.generic.process import SiwaveSolve
from pyedb.generic.settings import settings
from pyedb.ipc2581.ipc2581 import Ipc2581
from pyedb.modeler.geometry_operators import GeometryOperators
if is_linux and is_ironpython:
import subprocessdotnet as subprocess
else:
import subprocess
import rtree
class Edb(Database):
"""Provides the EDB application interface.
This module inherits all objects that belong to EDB.
Parameters
----------
edbpath : str, optional
Full path to the ``aedb`` folder. The variable can also contain
the path to a layout to import. Allowed formats are BRD, MCM,
XML (IPC2581), GDS, and DXF. The default is ``None``.
For GDS import, the Ansys control file (also XML) should have the same
name as the GDS file. Only the file extension differs.
cellname : str, optional
Name of the cell to select. The default is ``None``.
isreadonly : bool, optional
Whether to open EBD in read-only mode when it is
owned by HFSS 3D Layout. The default is ``False``.
edbversion : str, int, float, optional
Version of EDB to use. The default is ``None``.
Examples of input values are ``232``, ``23.2``, ``2023.2``, ``"2023.2"``.
isaedtowned : bool, optional
Whether to launch EDB from HFSS 3D Layout. The
default is ``False``.
oproject : optional
Reference to the AEDT project object.
student_version : bool, optional
Whether to open the AEDT student version. The default is ``False.``
technology_file : str, optional
Full path to technology file to be converted to xml before importing or xml.
Supported by GDS format only.
Examples
--------
Create an ``Edb`` object and a new EDB cell.
>>> from pyedb.dotnet.edb import Edb
>>> app = Edb()
Add a new variable named "s1" to the ``Edb`` instance.
>>> app['s1'] = "0.25 mm"
>>> app['s1'].tofloat
>>> 0.00025
>>> app['s1'].tostring
>>> "0.25mm"
or add a new parameter with description:
>>> app['s2'] = ["20um", "Spacing between traces"]
>>> app['s2'].value
>>> 1.9999999999999998e-05
>>> app['s2'].description
>>> 'Spacing between traces'
Create an ``Edb`` object and open the specified project.
>>> app = Edb("myfile.aedb")
Create an ``Edb`` object from GDS and control files.
The XML control file resides in the same directory as the GDS file: (myfile.xml).
>>> app = Edb("/path/to/file/myfile.gds")
"""
def __init__(
self,
edbpath: Union[str, Path] = None,
cellname: str = None,
isreadonly: bool = False,
edbversion: str = None,
isaedtowned: bool = False,
oproject=None,
student_version: bool = False,
use_ppe: bool = False,
technology_file: str = None,
remove_existing_aedt: bool = False,
):
if isinstance(edbpath, Path):
edbpath = str(edbpath)
edbversion = get_string_version(edbversion)
self._clean_variables()
Database.__init__(self, edbversion=edbversion, student_version=student_version)
self.standalone = True
self.oproject = oproject
self._main = sys.modules["__main__"]
self.isaedtowned = isaedtowned
self.isreadonly = isreadonly
self.cellname = cellname
if not edbpath:
if is_windows:
edbpath = os.getenv("USERPROFILE")
if not edbpath:
edbpath = os.path.expanduser("~")
edbpath = os.path.join(edbpath, "Documents", generate_unique_name("layout") + ".aedb")
else:
edbpath = os.getenv("HOME")
if not edbpath:
edbpath = os.path.expanduser("~")
edbpath = os.path.join(edbpath, generate_unique_name("layout") + ".aedb")
self.logger.info("No EDB is provided. Creating a new EDB {}.".format(edbpath))
self.edbpath = edbpath
self.log_name = None
if edbpath:
self.log_name = os.path.join(
os.path.dirname(edbpath),
"pyedb_" + os.path.splitext(os.path.split(edbpath)[-1])[0] + ".log",
)
if not isreadonly:
self._check_remove_project_files(edbpath, remove_existing_aedt)
if isaedtowned and (inside_desktop or settings.remote_rpc_session):
self.open_edb_inside_aedt()
elif edbpath[-3:] in ["brd", "mcm", "sip", "gds", "xml", "dxf", "tgz", "anf"]:
self.edbpath = edbpath[:-4] + ".aedb"
working_dir = os.path.dirname(edbpath)
control_file = None
if technology_file:
if os.path.splitext(technology_file)[1] == ".xml":
control_file = technology_file
else:
control_file = convert_technology_file(technology_file, edbversion=edbversion)
self.import_layout_pcb(edbpath, working_dir, use_ppe=use_ppe, control_file=control_file)
if settings.enable_local_log_file and self.log_name:
self._logger.add_file_logger(self.log_name, "Edb")
self.logger.info("EDB %s was created correctly from %s file.", self.edbpath, edbpath[-2:])
elif edbpath.endswith("edb.def"):
self.edbpath = os.path.dirname(edbpath)
if settings.enable_local_log_file and self.log_name:
self._logger.add_file_logger(self.log_name, "Edb")
self.open_edb()
elif not os.path.exists(os.path.join(self.edbpath, "edb.def")):
self.create_edb()
if settings.enable_local_log_file and self.log_name:
self._logger.add_file_logger(self.log_name, "Edb")
self.logger.info("EDB %s created correctly.", self.edbpath)
elif ".aedb" in edbpath:
self.edbpath = edbpath
if settings.enable_local_log_file and self.log_name:
self._logger.add_file_logger(self.log_name, "Edb")
self.open_edb()
if self.active_cell:
self.logger.info("EDB initialized.")
else:
self.logger.info("Failed to initialize DLLs.")
def __enter__(self):
return self
def __exit__(self, ex_type, ex_value, ex_traceback):
if ex_type:
self.edb_exception(ex_value, ex_traceback)
@pyedb_function_handler()
def __getitem__(self, variable_name):
"""Get or Set a variable to the Edb project. The variable can be project using ``$`` prefix or
it can be a design variable, in which case the ``$`` is omitted.
Parameters
----------
variable_name : str
Returns
-------
variable object : :class:`pyedb.dotnet.edb_core.edb_data.variables.Variable`
"""
if self.variable_exists(variable_name)[0]:
return self.variables[variable_name]
return
@pyedb_function_handler()
def __setitem__(self, variable_name, variable_value):
type_error_message = "Allowed values are str, numeric or two-item list with variable description."
if type(variable_value) in [
list,
tuple,
]: # Two-item list or tuple. 2nd argument is a str description.
if len(variable_value) == 2:
if type(variable_value[1]) is str:
description = variable_value[1] if len(variable_value[1]) > 0 else None
else:
description = None
self.logger.warning("Invalid type for Edb variable desciprtion is ignored.")
val = variable_value[0]
else:
raise TypeError(type_error_message)
else:
description = None
val = variable_value
if self.variable_exists(variable_name)[0]:
self.change_design_variable_value(variable_name, val)
else:
self.add_design_variable(variable_name, val)
if description: # Add the variable description if a two-item list is passed for variable_value.
self.__getitem__(variable_name).description = description
def _check_remove_project_files(self, edbpath: str, remove_existing_aedt: bool) -> None:
aedt_file = os.path.splitext(edbpath)[0] + ".aedt"
files = [aedt_file, aedt_file + ".lock"]
for file in files:
if os.path.isfile(file):
if not remove_existing_aedt:
self.logger.warning(
f"AEDT project-related file {file} exists and may need to be deleted before opening the EDB in "
f"HFSS 3D Layout."
# noqa: E501
)
else:
try:
os.unlink(file)
self.logger.info(f"Deleted AEDT project-related file {file}.")
except:
self.logger.info(f"Failed to delete AEDT project-related file {file}.")
def _clean_variables(self):
"""Initialize internal variables and perform garbage collection."""
self._materials = None
self._components = None
self._core_primitives = None
self._stackup = None
self._stackup2 = None
self._padstack = None
self._siwave = None
self._hfss = None
self._nets = None
self._layout_instance = None
self._variables = None
self._active_cell = None
self._layout = None
self._configuration = None
@pyedb_function_handler()
def _init_objects(self):
self._components = Components(self)
self._stackup = Stackup(self, self.layout.layer_collection)
self._padstack = EdbPadstacks(self)
self._siwave = EdbSiwave(self)
self._hfss = EdbHfss(self)
self._nets = EdbNets(self)
self._core_primitives = EdbLayout(self)
self._stackup2 = self._stackup
self._materials = Materials(self)
@property
def cell_names(self):
"""Cell name container.
Returns
-------
list of cell names : List[str]
"""
names = []
for cell in self.circuit_cells:
names.append(cell.GetName())
return names
@property
def design_variables(self):
"""Get all edb design variables.
Returns
-------
variable dictionary : Dict[str, :class:`pyedb.dotnet.edb_core.edb_data.variables.Variable`]
"""
d_var = dict()
for i in self.active_cell.GetVariableServer().GetAllVariableNames():
d_var[i] = Variable(self, i)
return d_var
@property
def project_variables(self):
"""Get all project variables.
Returns
-------
variables dictionary : Dict[str, :class:`pyedb.dotnet.edb_core.edb_data.variables.Variable`]
"""
p_var = dict()
for i in self.active_db.GetVariableServer().GetAllVariableNames():
p_var[i] = Variable(self, i)
return p_var
@property
def layout_validation(self):
""":class:`pyedb.dotnet.edb_core.edb_data.layout_validation.LayoutValidation`.
Returns
-------
layout validation object : :class: 'pyedb.dotnet.edb_core.layout_validation.LayoutValidation'
"""
return LayoutValidation(self)
@property
def variables(self):
"""Get all Edb variables.
Returns
-------
variables dictionary : Dict[str, :class:`pyedb.dotnet.edb_core.edb_data.variables.Variable`]
"""
all_vars = dict()
for i, j in self.project_variables.items():
all_vars[i] = j
for i, j in self.design_variables.items():
all_vars[i] = j
return all_vars
@property
def terminals(self):
"""Get terminals belonging to active layout.
Returns
-------
Terminal dictionary : Dict[str, pyedb.dotnet.edb_core.edb_data.terminals.Terminal]
"""
temp = {}
terminal_mapping = Terminal(self)._terminal_mapping
for i in self.layout.terminals:
terminal_type = i.ToString().split(".")[-1]
ter = terminal_mapping[terminal_type](self, i)
temp[ter.name] = ter
return temp
@property
def excitations(self):
"""Get all layout excitations."""
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) == 0]
temp = {}
for ter in terms:
if "BundleTerminal" in ter.GetType().ToString():
temp[ter.GetName()] = BundleWavePort(self, ter)
else:
temp[ter.GetName()] = GapPort(self, ter)
return temp
@property
def ports(self):
"""Get all ports.
Returns
-------
port dictionary : Dict[str, [:class:`pyedb.dotnet.edb_core.edb_data.ports.GapPort`,
:class:`pyedb.dotnet.edb_core.edb_data.ports.WavePort`,]]
"""
temp = [term for term in self.layout.terminals if not term.IsReferenceTerminal()]
ports = {}
for t in temp:
t2 = Terminal(self, t)
if not t2.boundary_type == "PortBoundary":
continue
if t2.is_circuit_port:
port = CircuitPort(self, t)
ports[port.name] = port
elif t2.terminal_type == "BundleTerminal":
port = BundleWavePort(self, t)
ports[port.name] = port
elif t2.hfss_type == "Wave":
ports[t2.name] = WavePort(self, t)
elif t2.terminal_type == "PadstackInstanceTerminal":
ports[t2.name] = CoaxPort(self, t)
else:
ports[t2.name] = GapPort(self, t)
return ports
@property
def excitations_nets(self):
"""Get all excitations net names."""
names = list(set([i.GetNet().GetName() for i in self.layout.terminals]))
names = [i for i in names if i]
return names
@property
def sources(self):
"""Get all layout sources."""
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) in [3, 4, 7]]
return {ter.GetName(): ExcitationSources(self, ter) for ter in terms}
@property
def probes(self):
"""Get all layout probes."""
temp = {}
for name, val in self.terminals.items():
if val.boundary_type == "kVoltageProbe":
if not val.is_reference_terminal:
temp[name] = val
return temp
@pyedb_function_handler()
def open_edb(self):
"""Open EDB.
Returns
-------
``True`` when succeed ``False`` if failed : bool
"""
# self.logger.info("EDB Path is %s", self.edbpath)
# self.logger.info("EDB Version is %s", self.edbversion)
# if self.edbversion > "2023.1":
# self.standalone = False
self.run_as_standalone(self.standalone)
# self.logger.info("EDB Standalone %s", self.standalone)
try:
self.open(self.edbpath, self.isreadonly)
except Exception as e:
self.logger.error("Builder is not Initialized.")
if not self.active_db:
self.logger.warning("Error Opening db")
self._active_cell = None
return None
self.logger.info("Database {} Opened in {}".format(os.path.split(self.edbpath)[-1], self.edbversion))
self._active_cell = None
if self.cellname:
for cell in list(self.top_circuit_cells):
if cell.GetName() == self.cellname:
self._active_cell = cell
# if self._active_cell is still None, set it to default cell
if self._active_cell is None:
self._active_cell = list(self.top_circuit_cells)[0]
self.logger.info("Cell %s Opened", self._active_cell.GetName())
if self._active_cell:
self._init_objects()
self.logger.info("Builder was initialized.")
else:
self.logger.error("Builder was not initialized.")
return True
@pyedb_function_handler()
def open_edb_inside_aedt(self):
"""Open EDB inside AEDT.
Returns
-------
``True`` when succeed ``False`` if failed : bool
"""
self.logger.info("Opening EDB from HDL")
self.run_as_standalone(False)
if self.oproject.GetEDBHandle():
self.attach(self.oproject.GetEDBHandle())
if not self.active_db:
self.logger.warning("Error getting the database.")
self._active_cell = None
return None
self._active_cell = self.edb_api.cell.cell.FindByName(
self.active_db,
self.edb_api.cell._cell.CellType.CircuitCell,
self.cellname,
)
if self._active_cell is None:
self._active_cell = list(self.top_circuit_cells)[0]
if self._active_cell:
if not os.path.exists(self.edbpath):
os.makedirs(self.edbpath)
self._init_objects()
return True
else:
return None
else:
self._active_cell = None
return None
@pyedb_function_handler()
def create_edb(self):
"""Create EDB.
Returns
-------
``True`` when succeed ``False`` if failed : bool
"""
# if self.edbversion > "2023.1":
# self.standalone = False
self.run_as_standalone(self.standalone)
self.create(self.edbpath)
if not self.active_db:
self.logger.warning("Error creating the database.")
self._active_cell = None
return None
if not self.cellname:
self.cellname = generate_unique_name("Cell")
self._active_cell = self.edb_api.cell.create(
self.active_db, self.edb_api.cell.CellType.CircuitCell, self.cellname
)
if self._active_cell:
self._init_objects()
return True
return None
@pyedb_function_handler()
def import_layout_pcb(
self,
input_file,
working_dir,
anstranslator_full_path="",
use_ppe=False,
control_file=None,
):
"""Import a board file and generate an ``edb.def`` file in the working directory.
This function supports all AEDT formats, including DXF, GDS, SML (IPC2581), BRD, MCM and TGZ.
Parameters
----------
input_file : str
Full path to the board file.
working_dir : str
Directory in which to create the ``aedb`` folder. The name given to the AEDB file
is the same as the name of the board file.
anstranslator_full_path : str, optional
Full path to the Ansys translator. The default is ``""``.
use_ppe : bool
Whether to use the PPE License. The default is ``False``.
control_file : str, optional
Path to the XML file. The default is ``None``, in which case an attempt is made to find
the XML file in the same directory as the board file. To succeed, the XML file and board file
must have the same name. Only the extension differs.
Returns
-------
Full path to the AEDB file : str
"""
self._components = None
self._core_primitives = None
self._stackup = None
self._padstack = None
self._siwave = None
self._hfss = None
self._nets = None
aedb_name = os.path.splitext(os.path.basename(input_file))[0] + ".aedb"
if anstranslator_full_path and os.path.exists(anstranslator_full_path):
command = anstranslator_full_path
else:
command = os.path.join(self.base_path, "anstranslator")
if is_windows:
command += ".exe"
if not working_dir:
working_dir = os.path.dirname(input_file)
cmd_translator = [
command,
input_file,
os.path.join(working_dir, aedb_name),
"-l={}".format(os.path.join(working_dir, "Translator.log")),
]
if not use_ppe:
cmd_translator.append("-ppe=false")
if control_file and input_file[-3:] not in ["brd", "mcm", "sip"]:
if is_linux:
cmd_translator.append("-c={}".format(control_file))
else:
cmd_translator.append('-c="{}"'.format(control_file))
p = subprocess.Popen(cmd_translator)
p.wait()
if not os.path.exists(os.path.join(working_dir, aedb_name)):
self.logger.error("Translator failed to translate.")
return False
else:
self.logger.info("Translation correctly completed")
self.edbpath = os.path.join(working_dir, aedb_name)
return self.open_edb()
@pyedb_function_handler()
def export_to_ipc2581(self, ipc_path=None, units="MILLIMETER"):
"""Create an XML IPC2581 file from the active EDB.
.. note::
The method works only in CPython because of some limitations on Ironpython in XML parsing and
because it's time-consuming.
This method is still being tested and may need further debugging.
Any feedback is welcome. Back drills and custom pads are not supported yet.
Parameters
----------
ipc_path : str, optional
Path to the XML IPC2581 file. The default is ``None``, in which case
an attempt is made to find the XML IPC2581 file in the same directory
as the active EDB. To succeed, the XML IPC2581 file and the active
EDT must have the same name. Only the extension differs.
units : str, optional
Units of the XML IPC2581 file. Options are ``"millimeter"``,
``"inch"``, and ``"micron"``. The default is ``"millimeter"``.
Returns
-------
``True`` if successful, ``False`` if failed : bool
"""
if units.lower() not in ["millimeter", "inch", "micron"]: # pragma no cover
self.logger.warning("The wrong unit is entered. Setting to the default, millimeter.")
units = "millimeter"
if not ipc_path:
ipc_path = self.edbpath[:-4] + "xml"
self.logger.info("Export IPC 2581 is starting. This operation can take a while.")
start = time.time()
ipc = Ipc2581(self, units)
ipc.load_ipc_model()
ipc.file_path = ipc_path
result = ipc.write_xml()
if result: # pragma no cover
self.logger.info_timer("Export IPC 2581 completed.", start)
self.logger.info("File saved as %s", ipc_path)
return ipc_path
self.logger.info("Error exporting IPC 2581.")
return False
@property
def configuration(self):
"""Edb project configuration from file."""
if not self._configuration:
self._configuration = Configuration(self)
return self._configuration
def edb_exception(self, ex_value, tb_data):
"""Write the trace stack to AEDT when a Python error occurs.
Parameters
----------
ex_value :
tb_data :
Returns
-------
None
"""
tb_trace = traceback.format_tb(tb_data)
tblist = tb_trace[0].split("\n")
self.logger.error(str(ex_value))
for el in tblist:
self.logger.error(el)
@property
def active_db(self):
"""Database object."""
return self.db
@property
def active_cell(self):
"""Active cell."""
return self._active_cell
@property
def core_components(self): # pragma: no cover
"""Edb Components methods and properties.
.. deprecated:: 0.6.62
Use new property :func:`components` instead.
Returns
-------
Instance of :class:`pyedb.dotnet.edb_core.Components.Components`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> comp = edbapp.components.get_component_by_name("J1")
"""
warnings.warn("Use new property :func:`components` instead.", DeprecationWarning)
return self.components
@property
def components(self):
"""Edb Components methods and properties.
Returns
-------
Instance of :class:`pyedb.dotnet.edb_core.components.Components`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> comp = edbapp.components.get_component_by_name("J1")
"""
if not self._components and self.active_db:
self._components = Components(self)
return self._components
@property
def core_stackup(self):
"""Core stackup.
.. deprecated:: 0.6.5
There is no need to use the ``core_stackup`` property anymore.
You can instantiate a new ``stackup`` class directly from the ``Edb`` class.
"""
mess = "`core_stackup` is deprecated.\n"
mess += " Use `app.stackup` directly to instantiate new stackup methods."
warnings.warn(mess, DeprecationWarning)
if not self._stackup and self.active_db:
self._stackup = Stackup(self)
return self._stackup
@property
def design_options(self):
"""Edb Design Settings and Options.
Returns
-------
Instance of :class:`pyedb.dotnet.edb_core.edb_data.design_options.EdbDesignOptions`
"""
return EdbDesignOptions(self.active_cell)
@property
def stackup(self):
"""Stackup manager.
Returns
-------
Instance of :class: 'pyedb.dotnet.edb_core.Stackup`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> edbapp.stackup.layers["TOP"].thickness = 4e-5
>>> edbapp.stackup.layers["TOP"].thickness == 4e-05
>>> edbapp.stackup.add_layer("Diel", "GND", layer_type="dielectric", thickness="0.1mm", material="FR4_epoxy")
"""
return Stackup(self, self.layout.layer_collection)
@property
def materials(self):
"""Material Database.
Returns
-------
Instance of :class: `pyedb.dotnet.edb_core.Materials`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb()
>>> edbapp.materials.add_material("air", permittivity=1.0)
>>> edbapp.materials.add_debye_material("debye_mat", 5, 3, 0.02, 0.05, 1e5, 1e9)
>>> edbapp.materials.add_djordjevicsarkar_material("djord_mat", 3.3, 0.02, 3.3)
"""
if not self._materials and self.active_db:
self._materials = Materials(self)
return self._materials
@property
def core_padstack(self): # pragma: no cover
"""Core padstack.
.. deprecated:: 0.6.62
Use new property :func:`padstacks` instead.
Returns
-------
Instance of :class: `pyedb.dotnet.edb_core.padstack.EdbPadstack`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> p = edbapp.padstacks.create(padstackname="myVia_bullet", antipad_shape="Bullet")
>>> edbapp.padstacks.get_pad_parameters(
>>> ... p, "TOP", edbapp.padstacks.pad_type.RegularPad
>>> ... )
"""
warnings.warn("Use new property :func:`padstacks` instead.", DeprecationWarning)
return self.padstacks
@property
def padstacks(self):
"""Core padstack.
Returns
-------
Instance of :class: `legacy.edb_core.padstack.EdbPadstack`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> p = edbapp.padstacks.create(padstackname="myVia_bullet", antipad_shape="Bullet")
>>> edbapp.padstacks.get_pad_parameters(
>>> ... p, "TOP", edbapp.padstacks.pad_type.RegularPad
>>> ... )
"""
if not self._padstack and self.active_db:
self._padstack = EdbPadstacks(self)
return self._padstack
@property
def core_siwave(self): # pragma: no cover
"""Core SIWave methods and properties.
.. deprecated:: 0.6.62
Use new property :func:`siwave` instead.
Returns
-------
Instance of :class: `pyedb.dotnet.edb_core.siwave.EdbSiwave`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> p2 = edbapp.siwave.create_circuit_port_on_net("U2A5", "V3P3_S0", "U2A5", "GND", 50, "test")
"""
warnings.warn("Use new property :func:`siwave` instead.", DeprecationWarning)
return self.siwave
@property
def siwave(self):
"""Core SIWave methods and properties.
Returns
-------
Instance of :class: `pyedb.dotnet.edb_core.siwave.EdbSiwave`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> p2 = edbapp.siwave.create_circuit_port_on_net("U2A5", "V3P3_S0", "U2A5", "GND", 50, "test")
"""
if not self._siwave and self.active_db:
self._siwave = EdbSiwave(self)
return self._siwave
@property
def core_hfss(self): # pragma: no cover
"""Core HFSS methods and properties.
.. deprecated:: 0.6.62
Use new property :func:`hfss` instead.
Returns
-------
Instance of :class:`legacy.edb_core.hfss.EdbHfss`
Examples
--------
>>> from pyedb.dotnet.edb import Edb
>>> edbapp = Edb("myproject.aedb")
>>> edbapp.hfss.configure_hfss_analysis_setup(sim_config)
"""
warnings.warn("Use new property :func:`hfss` instead.", DeprecationWarning)
return self.hfss
@property
def hfss(self):
"""Core HFSS methods and properties.
Returns
-------
:class:`pyedb.dotnet.edb_core.hfss.EdbHfss`
See Also
--------
:class:`legacy.edb_core.edb_data.simulation_configuration.SimulationConfiguration`
Examples
--------
>>> from pyedb.dotnet.edb import Edb