"""
==========================================
Genrating feedthrough from single instance
==========================================

This example demostrates how to generate a feedthrough wire connection for
a given scalar or vector wires.

**Initial Design**

.. hdl-diagram:: ../../../examples/basic/_initial_design.v
   :type: netlistsvg
   :align: center
   :module: top


**Output1** ``wire0`` feedthough from ``inst_2_1``

.. hdl-diagram:: ../../../examples/basic/_output_wire.v
   :type: netlistsvg
   :align: center
   :module: top

**Output2** ``bus_in`` feedthrough from ``inst_1_0``

.. hdl-diagram:: ../../../examples/basic/_output_bus.v
   :type: netlistsvg
   :align: center
   :module: top

"""

from os import path
import spydrnet as sdn
import spydrnet_physical as sdnphy

netlist = sdnphy.load_netlist_by_name('basic_hierarchy')

top = netlist.top_instance.reference
cable0 = next(top.get_cables("wire0"))
inst2 = next(top.get_instances("inst_2_0"))

sdn.compose(netlist, '_initial_design.v', skip_constraints=True)


top.create_feedthrough(inst2, cable0)
top.create_unconn_wires()
sdn.compose(netlist, '_output_wire.v', skip_constraints=True)


netlist = sdnphy.load_netlist_by_name('basic_hierarchy')

top = netlist.top_instance.reference
bus_in = next(top.get_cables("bus_in"))
inst1 = next(top.get_instances("inst_1_0"))

cables = top.create_feedthrough(inst1, bus_in)
top.create_unconn_wires()
sdn.compose(netlist, '_output_bus.v', skip_constraints=True)

[((37, 10, 37, 56), 'spydrnet_physical.load_netlist_by_name', 'sdnphy.load_netlist_by_name', ({(37, 38, 37, 55): '"""basic_hierarchy"""'}, {}), "('basic_hierarchy')", True, 'import spydrnet_physical as sdnphy\n'), ((43, 0, 43, 64), 'spydrnet.compose', 'sdn.compose', (), '', True, 'import spydrnet as sdn\n'), ((48, 0, 48, 61), 'spydrnet.compose', 'sdn.compose', (), '', True, 'import spydrnet as sdn\n'), ((51, 10, 51, 56), 'spydrnet_physical.load_netlist_by_name', 'sdnphy.load_netlist_by_name', ({(51, 38, 51, 55): '"""basic_hierarchy"""'}, {}), "('basic_hierarchy')", True, 'import spydrnet_physical as sdnphy\n'), ((59, 0, 59, 60), 'spydrnet.compose', 'sdn.compose', (), '', True, 'import spydrnet as sdn\n')]