1
1
"""Database."""
2
+ from __future__ import annotations
3
+
4
+ from typing import TYPE_CHECKING , List , Tuple , Union
5
+
6
+ if TYPE_CHECKING :
7
+ from ansys .edb .core .inner .messages import EDBObjMessage
2
8
3
9
from enum import Enum
4
10
34
40
35
41
36
42
class ProductIdType (Enum ):
37
- """Provides an enum representing IDs of Ansys products that support EDB usage."""
43
+ """Enum representing IDs of Ansys products that support EDB usage."""
38
44
39
45
HFSS_3D_LAYOUT = DESIGNER = edb_defs_pb2 .DESIGNER
40
46
SIWAVE = edb_defs_pb2 .SI_WAVE
@@ -48,18 +54,18 @@ class Database(ObjBase, variable_server.VariableServer):
48
54
49
55
__stub : DatabaseServiceStub = StubAccessor (StubType .database )
50
56
51
- def __init__ (self , msg ):
57
+ def __init__ (self , msg : EDBObjMessage ):
52
58
"""Initialize a new database.
53
59
54
60
Parameters
55
61
----------
56
- msg : EDBObjMessage
62
+ msg : . EDBObjMessage
57
63
"""
58
64
ObjBase .__init__ (self , msg )
59
65
variable_server .VariableServer .__init__ (self , self )
60
66
61
67
@classmethod
62
- def create (cls , db_path ) :
68
+ def create (cls , db_path : str ) -> Database :
63
69
"""Create a database in a given location.
64
70
65
71
Parameters
@@ -69,13 +75,13 @@ def create(cls, db_path):
69
75
70
76
Returns
71
77
-------
72
- Database
78
+ . Database
73
79
"""
74
80
msg = cls .__stub .Create (proto_wrappers .StringValue (value = db_path ))
75
81
return Database (msg )
76
82
77
83
@classmethod
78
- def open (cls , db_path , read_only ) :
84
+ def open (cls , db_path : str , read_only : bool ) -> Database :
79
85
"""Open a database in a given location.
80
86
81
87
Parameters
@@ -87,8 +93,7 @@ def open(cls, db_path, read_only):
87
93
88
94
Returns
89
95
-------
90
- Database object or None
91
- Database object opened or ``None`` if no database object is found.
96
+ .Database
92
97
"""
93
98
return Database (
94
99
cls .__stub .Open (
@@ -100,7 +105,7 @@ def open(cls, db_path, read_only):
100
105
)
101
106
102
107
@classmethod
103
- def delete (cls , db_path ):
108
+ def delete (cls , db_path : str ):
104
109
"""Delete a database in a given specified location.
105
110
106
111
Parameters
@@ -124,37 +129,37 @@ def close(self):
124
129
self .msg = None
125
130
126
131
@staticmethod
127
- def _map_cell_edb_obj_collection (cells_msg ) :
128
- """Get a list of cell objects from the `` EDBObjCollection` ` message."""
132
+ def _map_cell_edb_obj_collection (cells_msg : EDBObjMessage ) -> List [ Cell ] :
133
+ """Get a list of cell objects from the :class:`. EDBObjCollection` message."""
129
134
return map_list (cells_msg .items , Cell )
130
135
131
136
@property
132
- def top_circuit_cells (self ):
137
+ def top_circuit_cells (self ) -> List [ Cell ] :
133
138
""":obj:`list` of :class:`.Cell`: Top circuit cells in the database."""
134
139
return Database ._map_cell_edb_obj_collection (self .__stub .GetTopCircuits (self .msg ))
135
140
136
141
@property
137
- def circuit_cells (self ):
142
+ def circuit_cells (self ) -> List [ Cell ] :
138
143
""":obj:`list` of :class:`.Cell`: All circuit cells in the database."""
139
144
return Database ._map_cell_edb_obj_collection (self .__stub .GetCircuits (self .msg ))
140
145
141
146
@property
142
- def footprint_cells (self ):
147
+ def footprint_cells (self ) -> List [ Cell ] :
143
148
""":obj:`list` of :class:`.Cell`: All footprint cells in the database."""
144
149
return Database ._map_cell_edb_obj_collection (self .__stub .GetFootprints (self .msg ))
145
150
146
151
@property
147
- def edb_uid (self ):
152
+ def edb_uid (self ) -> int :
148
153
""":obj:`int`: Unique EDB ID of the database."""
149
154
return self .__stub .GetId (self .msg ).value
150
155
151
156
@property
152
- def is_read_only (self ):
157
+ def is_read_only (self ) -> bool :
153
158
""":obj:`bool`: Flag indicating if the database is open in read-only mode."""
154
159
return self .__stub .IsReadOnly (self .msg ).value
155
160
156
161
@classmethod
157
- def find_by_id (cls , db_id ) :
162
+ def find_by_id (cls , db_id : int ) -> Database :
158
163
"""Find a database by ID.
159
164
160
165
Parameters
@@ -164,12 +169,11 @@ def find_by_id(cls, db_id):
164
169
165
170
Returns
166
171
-------
167
- Database
168
- Database when successful, Null when failed.
172
+ .Database
169
173
"""
170
174
return Database (cls .__stub .FindById (proto_wrappers .Int64Value (value = db_id )))
171
175
172
- def save_as (self , path , version = "" ):
176
+ def save_as (self , path : str , version : str = "" ):
173
177
"""Save the database to a new location and older EDB version.
174
178
175
179
Parameters
@@ -185,7 +189,7 @@ def save_as(self, path, version=""):
185
189
)
186
190
187
191
@classmethod
188
- def get_version_by_release (cls , release ) :
192
+ def get_version_by_release (cls , release : str ) -> str :
189
193
"""Get the EDB version for a given release name.
190
194
191
195
Parameters
@@ -201,16 +205,16 @@ def get_version_by_release(cls, release):
201
205
return cls .__stub .GetVersionByRelease (str_message (release )).value
202
206
203
207
@property
204
- def directory (self ):
208
+ def directory (self ) -> str :
205
209
""":obj:`str`: Directory where the database is located."""
206
210
return self .__stub .GetDirectory (self .msg ).value
207
211
208
- def get_product_property (self , prod_id , attr_it ) :
212
+ def get_product_property (self , prod_id : ProductIdType , attr_it : int ) -> str :
209
213
"""Get a product-specific property value.
210
214
211
215
Parameters
212
216
----------
213
- prod_id : ProductIdType
217
+ prod_id : . ProductIdType
214
218
Product ID.
215
219
attr_it : int
216
220
Attribute ID.
@@ -224,12 +228,12 @@ def get_product_property(self, prod_id, attr_it):
224
228
get_product_property_message (self , prod_id , attr_it )
225
229
).value
226
230
227
- def set_product_property (self , prod_id , attr_it , prop_value ):
231
+ def set_product_property (self , prod_id : ProductIdType , attr_it : int , prop_value : str ):
228
232
"""Set the product property associated with the given product ID and attribute ID.
229
233
230
234
Parameters
231
235
----------
232
- prod_id : ProductIdType
236
+ prod_id : . ProductIdType
233
237
Product ID.
234
238
attr_it : int
235
239
Attribute ID.
@@ -240,12 +244,12 @@ def set_product_property(self, prod_id, attr_it, prop_value):
240
244
set_product_property_message (self , prod_id , attr_it , prop_value )
241
245
)
242
246
243
- def get_product_property_ids (self , prod_id ) :
247
+ def get_product_property_ids (self , prod_id : ProductIdType ) -> List [ int ] :
244
248
"""Get a list of attribute IDs for a given product property ID.
245
249
246
250
Parameters
247
251
----------
248
- prod_id : ProductIdType
252
+ prod_id : . ProductIdType
249
253
Product ID.
250
254
251
255
Returns
@@ -258,14 +262,16 @@ def get_product_property_ids(self, prod_id):
258
262
).ids
259
263
return [attr_id for attr_id in attr_ids ]
260
264
261
- def import_material_from_control_file (self , control_file , schema_dir = None , append = True ):
265
+ def import_material_from_control_file (
266
+ self , control_file : str , schema_dir : Union [str , None ] = None , append : bool = True
267
+ ):
262
268
"""Import materials from a control file.
263
269
264
270
Parameters
265
271
----------
266
272
control_file : str
267
273
Full path to the control file.
268
- schema_dir : str
274
+ schema_dir : Union[ str, None]
269
275
Path to the schema directory.
270
276
append : bool, default: True
271
277
Whether to keep existing materials in the database. If ``False``, the
@@ -281,12 +287,12 @@ def import_material_from_control_file(self, control_file, schema_dir=None, appen
281
287
)
282
288
283
289
@property
284
- def version (self ):
290
+ def version (self ) -> Tuple [ int , int ] :
285
291
""":obj:`tuple` of (:obj:`int`, :obj:`int`): Version [major, minor] of the database."""
286
292
version_msg = self .__stub .GetVersion (self .msg )
287
293
return version_msg .major .id , version_msg .minor .id
288
294
289
- def scale (self , scale_factor ):
295
+ def scale (self , scale_factor : float ):
290
296
"""Scale all geometries and their locations uniformly by a positive factor.
291
297
292
298
Parameters
@@ -297,34 +303,34 @@ def scale(self, scale_factor):
297
303
self .__stub .Scale (double_property_message (self , scale_factor ))
298
304
299
305
@property
300
- def source (self ):
306
+ def source (self ) -> str :
301
307
""":obj:`str`: Name of the source database."""
302
308
return self .__stub .GetSource (self .msg ).value
303
309
304
310
@source .setter
305
- def source (self , source ):
311
+ def source (self , source : str ):
306
312
self .__stub .SetSource (edb_obj_name_message (self , source ))
307
313
308
314
@property
309
- def source_version (self ):
315
+ def source_version (self ) -> str :
310
316
""":obj:`str`: Source version for the database."""
311
317
return self .__stub .GetSourceVersion (self .msg ).value
312
318
313
319
@source_version .setter
314
- def source_version (self , source_version ):
320
+ def source_version (self , source_version : str ):
315
321
self .__stub .SetSourceVersion (edb_obj_name_message (self , source_version ))
316
322
317
- def copy_cells (self , cells_to_copy ) :
323
+ def copy_cells (self , cells_to_copy : List [ Cell ]) -> List [ Cell ] :
318
324
"""Copy cells from other databases or this database into this database.
319
325
320
326
Parameters
321
327
----------
322
- cells_to_copy : list[:class:` .Cell`]
328
+ cells_to_copy : list of .Cell
323
329
Cells to copy.
324
330
325
331
Returns
326
332
-------
327
- list[:class:` .Cell`]
333
+ list of .Cell
328
334
New cells created in this database.
329
335
"""
330
336
return Database ._map_cell_edb_obj_collection (
@@ -353,45 +359,45 @@ def _get_bondwire_definition_objs(self, def_class, bw_def_type_enum):
353
359
)
354
360
355
361
@property
356
- def apd_bondwire_defs (self ):
362
+ def apd_bondwire_defs (self ) -> List [ ApdBondwireDef ] :
357
363
""":obj:`list` of :class:`.ApdBondwireDef`: All APD bondwire definitions in the database."""
358
364
return self ._get_bondwire_definition_objs (ApdBondwireDef , BondwireDefType .APD_BONDWIRE_DEF )
359
365
360
366
@property
361
- def jedec4_bondwire_defs (self ):
367
+ def jedec4_bondwire_defs (self ) -> List [ Jedec4BondwireDef ] :
362
368
""":obj:`list` of :class:`.Jedec4BondwireDef`: All JEDEC4 bondwire definitions in the database."""
363
369
return self ._get_bondwire_definition_objs (
364
370
Jedec4BondwireDef , BondwireDefType .JEDEC4_BONDWIRE_DEF
365
371
)
366
372
367
373
@property
368
- def jedec5_bondwire_defs (self ):
374
+ def jedec5_bondwire_defs (self ) -> List [ Jedec5BondwireDef ] :
369
375
""":obj:`list` of:class:`.Jedec5BondwireDef`: All JEDEC5 bondwire definitions in the database."""
370
376
return self ._get_bondwire_definition_objs (
371
377
Jedec5BondwireDef , BondwireDefType .JEDEC5_BONDWIRE_DEF
372
378
)
373
379
374
380
@property
375
- def padstack_defs (self ):
381
+ def padstack_defs (self ) -> List [ PadstackDef ] :
376
382
""":obj:`list` of :class:`.PadstackDef`: All padstack definitions in the database."""
377
383
return self ._get_definition_objs (PadstackDef , DefinitionObjType .PADSTACK_DEF )
378
384
379
385
@property
380
- def package_defs (self ):
386
+ def package_defs (self ) -> List [ PackageDef ] :
381
387
""":obj:`list` of :class:`.PackageDef`: All package definitions in the database."""
382
388
return self ._get_definition_objs (PackageDef , DefinitionObjType .PACKAGE_DEF )
383
389
384
390
@property
385
- def component_defs (self ):
391
+ def component_defs (self ) -> List [ ComponentDef ] :
386
392
""":obj:`list` of :class:`.ComponentDef`: All component definitions in the database."""
387
393
return self ._get_definition_objs (ComponentDef , DefinitionObjType .COMPONENT_DEF )
388
394
389
395
@property
390
- def material_defs (self ):
396
+ def material_defs (self ) -> List [ MaterialDef ] :
391
397
""":obj:`list` of :class:`.MaterialDef`: All material definitions in the database."""
392
398
return self ._get_definition_objs (MaterialDef , DefinitionObjType .MATERIAL_DEF )
393
399
394
400
@property
395
- def dataset_defs (self ):
401
+ def dataset_defs (self ) -> List [ DatasetDef ] :
396
402
""":obj:`list` of :class:`.DatasetDef`: All dataset definitions in the database."""
397
403
return self ._get_definition_objs (DatasetDef , DefinitionObjType .DATASET_DEF )
0 commit comments