JS API

Note

Schematik currently provides a limited set of Javascript API, but these can be easily extended. Submit any new API request at Issue Tracker


schematik

This class represents the top level handle for creating any schematics.

Attributes

schematicInstance

Handle to the underlying C++ instance, related C++ API can be accessed using this.

diagramBlock

Handle to the svg div where the diagram is created

Functions

class schematik(div)
Arguments:
  • div (string) – id of the svg block where the schematic is to be rendered

Constructor to the schematik class

processYosysJson(jsonData)
Arguments:
  • jsonData (JSON) – Input schematic information in json format

Automatically processes a data generated by YosysJS to form a complete design. Look at Yosys JSON for more details

getTerminalDirection(direction)
Arguments:
  • direction (string) – Possible values for direction are - “input”, “output”, “inout”
Returns:

A terminal direction enum

Note

This is only useful when using with topDesign.addSystemTerminal and module.addTerminal where you need to send a direction enum as a parameter

doPlacement()

Runs the placement algorithm on the topDesign instance

Note

This does not return anything, for retrieving the results of placement algorithm see schematik.getPlacedModulesJson

getPlacedModulesJson()
Returns:A JSON object containing placement data

Returns the results of the placement algorithm in the form of a JSON string.

Note

The string will need to be parsed to convert it into a Javascript object

doRouting()

Runs the routing algorithm on the topDesign instance

Note

This does not return anything, for retrieving the results of placement algorithm see schematik.getRoutedNetsJson

Warning

Calling this function without running the placement (or completely specifying placement yourself can upset people :P)

Error

It can sometimes throw error when a suitable routing is not found, in such cases you might need to use a different placement for a possible solution to be found. I am currently working on guaranteeing a possible routing

getRoutedNetsJson()
Returns:A JSON object containing routing data

Returns the results of the routing algorithm in the form of a JSON string.

Note

The string will need to be parsed to convert it into a Javascript object

drawPlacement([placementData])
Arguments:
  • placementData (JSON) – If provided uses this to render the placement else runs the placement algorithm to calculate placement and then renders it

Renders the placement result.

Note

All the rendering functions use snapsvg.js library

drawRouting([routingData])
Arguments:
  • routingData (JSON) – If provided uses this to render the routing else runs the routing algorithm to calculate routing and then renders it

Runs the routing algorithms and renders the result.

Note

All the rendering functions use snapsvg.js library


topDesign

Functions

class topDesign()

Constructor to the topDesign class. Provides direct access to the C++ classes

Note

Do not use this class directly especially if you are working with YosysJS, use schematik class instead. Though you might need this for finer control.

createJsonSchematicFromJson(jsonData)

Creates the placement schematic directly from Yosys JSON data

Warning

DEPRECATED!! do not use this, it will be removed in future releases

createDetailedJsonSchematicFromJson()

Creates the placement schematic directly from Yosys JSON data with debug mode on

Warning

DEPRECATED!! do not use this, it will be removed in future releases

addModule(moduleName)
Arguments:
  • moduleName (string) – A unique name for the new module
Returns:

A handle to the module object

Creates a new module with the given name and returns the handle to the module.

getModule(moduleName)
Arguments:
  • moduleName (string) – Name of the module
Returns:

A handle to the corresponding module object

Returns the module with the given name if it exists.

Warning

It might throw an error if the module does not exist, this will be changed to not throw an error in the future

addSystemTerminal(terminalName, terminalType, width)
Arguments:
  • terminalName (string) – A unique name for the terminal (unique among systemTerminals)
  • terminalType (enum) – A enum denoting the direction of the terminal. See schematik.getTerminalDirection for getting the enum.
  • width (integer) – Width of the terminal
Returns:

A handle to the new systemTerminal object

Adds a system level terminal to the topDesign.

getSystemTerminal(terminalName)
Arguments:
  • terminalName (string) – Name of the systemTerminal
Returns:

A handle to the corresponding systemTerminal object

doPlacement()

Perform placement on the topDesign schematic.

getPlacedModulesJson()
Returns:A JSON object containing placement data

Returns the results of the placement algorithm in the form of a JSON string.

Note

The string will need to be parsed to convert it into a Javascript object

doRouting()

Perform routing on the topDesign schematic.

Warning

Calling this function without running the placement (or completely specifying placement yourself can upset people :P)

Error

It can sometimes throw error when a suitable routing is not found, in such cases you might need to use a different placement for a possible solution to be found. I am currently working on guaranteeing a possible routing

getRoutedNetsJson()
Returns:A JSON object containing routing data

Returns the results of the routing algorithm in the form of a JSON string.

Note

The string will need to be parsed to convert it into a Javascript object


module

Functions

setSize(width, height)
Arguments:
  • width (integer) – width of the module
  • height (integer) –

    height of the module

    Sets the dimensions of the module

setPosition(x, y)
Arguments:
  • x (integer) – x position
  • y (integer) – y position

Sets the position of the module

Warning

The position will be modified if the placement algorithm is run. This is useful if we of need to modify position of a module or for completely specifying the placement.

getWidth()
Returns:Width of the module
getHeight()
Returns:Height of the module
getPositionX()
Returns:X-axis position of the module
getPositionY()
Returns:Y-axis position of the module
addTerminal(terminalName, type, width)
Arguments:
  • terminalName (string) – A unique name for the terminal (unique among terminals of the corresponding module)
  • terminalType (enum) – A enum denoting the direction of the terminal. See schematik.getTerminalDirection for getting the enum.
  • width (integer) – Width of the terminal
Returns:

A handle to the new terminal object

getTerminal(terminalName)
Arguments:
  • terminalName (string) – Name of the terminal
Returns:

A handle to the corresponding terminal object


terminal

Functions

partial(highIndex, lowIndex)
Arguments:
  • highIndex (integer) –
  • lowIndex (integer) –
Throw:

When highIndex < lowIndex, or highIndex > width - 1 of the terminal

Returns:

A spliced terminal with the given high and low indices

Splices the terminal into another terminal

connect(otherTerminal)
Arguments:
  • otherTerminal (terminal) – Other terminal to connect to
Throw:

If otherTerminal does not have the same width as this terminal

Connects the two terminals

Note

To connect two unequal width terminals first splice them using the terminal.partial function.

getWidth()
Returns:the width of the terminal.