21
21
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
22
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
# SOFTWARE.
24
-
25
24
from collections import defaultdict
26
25
import copy
27
26
from datetime import datetime
28
27
import json
28
+ import math
29
29
import os
30
30
from pathlib import Path
31
31
import tempfile
@@ -2216,7 +2216,7 @@ def export_config(self, config_file=None, overwrite=False):
2216
2216
getattr (self , key )(dict_out ) # Call private export method to update dict_out.
2217
2217
2218
2218
pin_mapping = defaultdict (list )
2219
- data_refdes = {}
2219
+ data_instance = {}
2220
2220
data_models = {}
2221
2221
pin_nets = {}
2222
2222
skip_list = [
@@ -2242,21 +2242,22 @@ def export_config(self, config_file=None, overwrite=False):
2242
2242
"IBIS_Model_Text" ,
2243
2243
"aminetlist_example_model_rx" ,
2244
2244
"CoSimulator" ,
2245
+ "source_name" ,
2245
2246
]
2246
2247
for comp in list (self ._app .modeler .schematic .components .values ()):
2248
+ if not comp .component_info :
2249
+ continue
2250
+ else :
2251
+ component = comp .component_info ["Component" ]
2247
2252
properties = {}
2248
2253
num_terminals = None
2249
- refdes = comp .refdes
2254
+ instance = comp .parameters [ "InstanceName" ]
2250
2255
position = comp .location
2251
2256
angle = comp .angle
2252
2257
mirror = comp .mirror
2253
2258
parameters = comp .parameters
2254
- if not comp .component_info :
2255
- continue
2256
- else :
2257
- component = comp .component_info ["Component" ]
2258
2259
path = comp .component_path
2259
- port_names = None
2260
+ port_names = []
2260
2261
if not path :
2261
2262
component_type = "Nexxim Component"
2262
2263
path = ""
@@ -2283,9 +2284,9 @@ def export_config(self, config_file=None, overwrite=False):
2283
2284
elif path [- 4 :] == ".sss" :
2284
2285
component_type = "nexxim state space"
2285
2286
num_terminals = comp .model_data .props ["numberofports" ]
2286
- port_names = comp .model_data .props ["PortNames" ]
2287
2287
2288
2288
for pin in comp .pins :
2289
+ port_names .append (pin .name )
2289
2290
if pin .net == "0" :
2290
2291
net = "gnd"
2291
2292
else :
@@ -2294,15 +2295,15 @@ def export_config(self, config_file=None, overwrite=False):
2294
2295
pin_nets .update (temp_dict )
2295
2296
2296
2297
temp_dict2 = {
2297
- refdes : {
2298
+ instance : {
2298
2299
"component" : component ,
2299
2300
"properties" : properties ,
2300
2301
"position" : position ,
2301
2302
"angle" : angle ,
2302
2303
"mirror" : mirror ,
2303
2304
}
2304
2305
}
2305
- data_refdes .update (temp_dict2 )
2306
+ data_instance .update (temp_dict2 )
2306
2307
if "$PROJECTDIR" in path :
2307
2308
path = path .replace ("$PROJECTDIR" , self ._app .project_path )
2308
2309
elif "<Project>" in path :
@@ -2322,10 +2323,10 @@ def export_config(self, config_file=None, overwrite=False):
2322
2323
for key , values in pin_mapping .items ():
2323
2324
temp_dict3 = {}
2324
2325
for value in values :
2325
- if value ._circuit_comp .refdes in temp_dict3 :
2326
- temp_dict3 [value ._circuit_comp .refdes ].append (value .name )
2326
+ if value ._circuit_comp .parameters [ "InstanceName" ] in temp_dict3 :
2327
+ temp_dict3 [value ._circuit_comp .parameters [ "InstanceName" ] ].append (value .name )
2327
2328
else :
2328
- temp_dict3 .update ({value ._circuit_comp .refdes : [value .name ]})
2329
+ temp_dict3 .update ({value ._circuit_comp .parameters [ "InstanceName" ] : [value .name ]})
2329
2330
pin_mapping [key ] = temp_dict3
2330
2331
2331
2332
port_dict = {}
@@ -2339,7 +2340,7 @@ def export_config(self, config_file=None, overwrite=False):
2339
2340
del pin_mapping [key ]
2340
2341
2341
2342
dict_out .update (
2342
- {"models" : data_models , "refdes " : data_refdes , "pin_mapping" : pin_mapping , "ports" : port_dict }
2343
+ {"models" : data_models , "instance " : data_instance , "pin_mapping" : pin_mapping , "ports" : port_dict }
2343
2344
) # Call private export method to update dict_out.
2344
2345
2345
2346
# update the json if it exists already
@@ -2385,7 +2386,10 @@ def import_config(self, config_file, *args):
2385
2386
self .results ._reset_results ()
2386
2387
2387
2388
data = read_configuration_file (config_file )
2388
-
2389
+ try :
2390
+ offset = data ["general" ]["port_offset" ]
2391
+ except KeyError :
2392
+ offset = 0
2389
2393
if self .options .import_variables :
2390
2394
try :
2391
2395
for k , v in data ["general" ]["variables" ].items ():
@@ -2402,7 +2406,7 @@ def import_config(self, config_file, *args):
2402
2406
else :
2403
2407
self .results .import_postprocessing_variables = True
2404
2408
2405
- for i , j in data ["refdes " ].items ():
2409
+ for i , j in data ["instance " ].items ():
2406
2410
for key , value in data ["models" ].items ():
2407
2411
if key == j ["component" ]:
2408
2412
component_type = value ["component_type" ]
@@ -2441,6 +2445,8 @@ def import_config(self, config_file, *args):
2441
2445
new_comp = self ._app .modeler .schematic .create_touchstone_component (
2442
2446
value ["file_path" ], location = j ["position" ], angle = j ["angle" ]
2443
2447
)
2448
+ for pin in new_comp .pins :
2449
+ pin .name = value ["port_names" ][pin .pin_number - 1 ]
2444
2450
elif component_type == "spice" :
2445
2451
new_comp = self ._app .modeler .schematic .create_component_from_spicemodel (
2446
2452
input_file = value ["file_path" ], location = j ["position" ]
@@ -2455,6 +2461,8 @@ def import_config(self, config_file, *args):
2455
2461
)
2456
2462
if not new_comp : # pragma: no cover
2457
2463
continue
2464
+ else :
2465
+ new_comp .parameters ["InstanceName" ] = i
2458
2466
# reorder pin positions for spice or nexxim state space components or touchstone components
2459
2467
if (
2460
2468
value .get ("pin_locations" , {})
@@ -2474,7 +2482,7 @@ def import_config(self, config_file, *args):
2474
2482
pins = []
2475
2483
for key , value in j .items ():
2476
2484
for comp in comp_list :
2477
- if comp .refdes == key :
2485
+ if comp .parameters [ "InstanceName" ] == key :
2478
2486
for pin in comp .pins :
2479
2487
if pin .name in value :
2480
2488
pins .append (pin )
@@ -2483,15 +2491,29 @@ def import_config(self, config_file, *args):
2483
2491
location = [x - y for x , y in zip (gnd_pin .location , [0 , 0.00254 ])]
2484
2492
self ._app .modeler .schematic .create_gnd (location , page = i )
2485
2493
elif len (pins ) > 1 :
2486
- pins [0 ].connect_to_component (pins [1 :], page_name = i )
2494
+ pins [0 ].connect_to_component (pins [1 :], page_name = i , offset = offset )
2487
2495
2488
2496
for i , j in data ["ports" ].items ():
2497
+ created = False
2489
2498
for key , value in j .items ():
2490
2499
for comp in comp_list :
2491
- if comp .refdes == key :
2500
+ if comp .parameters [ "InstanceName" ] == key :
2492
2501
for pin in comp .pins :
2493
2502
if pin .name in value :
2494
- self ._app .modeler .schematic .create_interface_port (name = i , location = pin .location )
2503
+ location = [
2504
+ pin .location [0 ] - offset * math .cos (pin .total_angle * math .pi / 180 ),
2505
+ pin .location [1 ] - offset * math .sin (pin .total_angle * math .pi / 180 ),
2506
+ ]
2507
+
2508
+ if not created :
2509
+ self ._app .modeler .schematic .create_interface_port (name = i , location = location )
2510
+ created = True
2511
+ else :
2512
+ self ._app .modeler .schematic .create_page_port (
2513
+ name = i , location = location , angle = pin .total_angle
2514
+ )
2515
+ if offset != 0 :
2516
+ self ._app .modeler .schematic .create_wire ([location , pin .location ])
2495
2517
2496
2518
if self .options .import_setups and data .get ("setups" , None ):
2497
2519
self .results .import_setup = True
0 commit comments