module:Box(appInstance, name, category, gridWidth, gridHeight)

Parent class for gates and input and output boxes. Defines all the factors that the boxes have in common (svgObj structure, draggability and rotatability...)

new module:Box(appInstance, name, category, gridWidth, gridHeight)

Parameters:
Name Type Description
appInstance App

instance of App

name string

name of the element (input, output, and, or, xor...)

category string

type of the element (io, gate)

gridWidth number

width of the element in grid pixels

gridHeight number

height of the element in grid pixels

Extends

  • NetworkElement

Members

category :string

specifies the box category (io for input or output, gate for logic gates)

connectors :Array

array of connectors of this box

exportData

get data of this box as a JSON-ready object

gridHeight :number

height of this element in grid pixels

gridSize :number

size of the grid in SVG pixels

gridWidth :number

width of this element in grid pixels

height :number

height of this element in SVG pixels

inputConnectors

get all input connectors of this box

name :string

specifies the box type within the category (input/output in io, and/or/... in gate)

outputConnectors

get all output connectors of this box

svgObj :svgObj

svgObj containing all SVG data used to display this box

url :string

url of the image depicting this object

width :number

width of this element in SVG pixels

Methods

addConnector(left, top, isInputConnector)

add a connector to the element on the specified position

Parameters:
Name Type Description
left number

horizontal distance from the left edge of the element

top number

vertical distance from the top edge of the element

isInputConnector Boolean

whether or not should this connector an input connector (true for input connector, false for output connector)

addInputConnector(left, top)

add an input connector to the element on the specified position

Parameters:
Name Type Description
left number

horizontal distance from the left edge of the element

top number

vertical distance from the top edge of the element

addOutputConnector(left, top)

add an output connector to the element on the specified position

Parameters:
Name Type Description
left number

horizontal distance from the left edge of the element

top number

vertical distance from the top edge of the element

changeImage(suffixopt)

change image to another one that ends with a specified suffix

usage: changeImage("abc") changes image url to image-abc.svg, changeImage() changes image url to the default one (image.svg)

Parameters:
Name Type Attributes Description
suffix string <optional>

new suffix for the image

generateBlockNodes(marginTopopt, marginRightopt, marginBottomopt, marginLeftopt, …specialNodes) → {Set}

get set of nodes that are not suitable for wire routing

Parameters:
Name Type Attributes Default Description
marginTop Number <optional>
0

top margin of the element (distance from the element that should be also blocked)

marginRight Number <optional>
0

right margin of the element

marginBottom Number <optional>
0

bottom margin of the element

marginLeft Number <optional>
0

left margin of the element

specialNodes Number <repeatable>

additional nodes that should be added to the set

Returns:
Set -

set of not suitable nodes

get() → {jQuery.element}

get a jQuery element representing this box

Returns:
jQuery.element

getConnectorById(connectorId) → {Connector}

get the connector object based on its id

Parameters:
Name Type Description
connectorId string

ID of the Connector

Returns:
Connector -

instance of the Connector or undefined if not found

getGridPixelTransform() → {Transform}

get the instance of Transform representing the state of the transform attribute of this element with lenght units in grid pixels

Returns:
Transform -

Transform of the element

getTransform(gridPixelsopt) → {Transform}

get the instance of Transform representing the state of the transform attribute of this element

Parameters:
Name Type Attributes Default Description
gridPixels Boolean <optional>
false

if true, function will return the result in grid pixels instead of SVG pixels

Returns:
Transform -

Transform of the element

onClick()

empty function, will be redefined in InputBox

onClickMiddle()

custom callback function for middle click that rotates the box by 90 degrees to the right

onDrop(event)

called by onMouseUp when the mouse has been moved between onMouseDown and onMouseUp

applies grid snapping of the element on the end of the "drag and drop" action

Parameters:
Name Type Description
event jQuery.MouseEvent

onMouseDown(event)

function that is called on every mouse down on this element

moves the element to the front and calls onMouseDownLeft if applicable

Parameters:
Name Type Description
event jQuery.MouseEvent

onMouseDownLeft(event)

function that is called on every left mouse down on this element

prepares element for the "click" and "drag and drop" actions

Parameters:
Name Type Description
event jQuery.MouseEvent

onMouseMove(event)

function that is called on every left mouse move with this element applies the correct transform values to provide the "drag and drop" functionality

Parameters:
Name Type Description
event jQuery.MouseEvent

onMouseUp(event)

function that is called on every mouse up on this element provides the "click" functionality and calls the onDrop handler for the "drag and drop" functionality

Parameters:
Name Type Description
event jQuery.MouseEvent

refreshState()

empty function, redefined in inherited elements refreshState takes input connector values and sets output values accordingly

rotateBlockedNodes(right)

rotate the set of blocked nodes by 90 degrees to the right or to the left, depending on the parameter

used to rotate the nodes when the object itself is rotated

Parameters:
Name Type Description
right boolean

rotate clockwise if true, counterclockwise if false

rotateBlockedNodesLeft()

rotate the set of blocked nodes to the right

used to rotate the nodes when the object itself is rotated

rotateBlockedNodesRight()

rotate the set of blocked nodes to the right

used to rotate the nodes when the object itself is rotated

setTransform(transform)

set the transform attribute of this element

Parameters:
Name Type Description
transform Transform

Transform of the element (with lengths specified in SVG pixels)

updateWires(temporaryopt)

Updates all wires connected to this box. Iterates over all wires that are connected to this box and calls routeWire (or temporaryWire if the temporary parameter is set to true) to update the wire routing

Parameters:
Name Type Attributes Default Description
temporary Boolean <optional>
false

[description]