Tutorial 3: Customized view; labeled pins

A Plug-in Tutorial
...     Tutorial 3: Customized view; labeled pins

The default view may not be adequate for some applications. In this example we make a minimal shift to a customized view. Later examples will demonstrate features that can be added to a enrich the view, such as a customized component footprint, pin positioning and on-board controls. This example also shows how to label the pins.

By convention, we form the customized view's class name by appending "View" to the end of the plug-in's class name. The two class definitions that follow define the plug-in, Plugin02, and its customized view, Plugin02View. The connection between Plugin02 and Plugin02View is made in dlsim.props.

Document Class

package plugins.tutorial;

import dlsim.document.DLPlugIn;

/**
 * Plugin02: sample plugin using customized view and labeled pins
 * Same as Plugin01
 * 5 inputs, 5 outputs
 * copies input to corresponding output
 * bundles pins and uses leds
 * 
 * @author rms
 *
 */
public class Plugin02 extends DLPlugIn {
    public static PluginInfo info = 
       new PluginInfo("My Third PlugIn",
         "Same as Plugin01 with customized view and labeled pins");
    /**
     * Constructor must specify input and output size (default is 0)
     * Constructor may specify pin bundling with inMap and outMap
     */
    public Plugin02() {
	setInputSize(5);
	setOutputSize(5);
	setInMap(2,1,2);
	setOutMap(1,2,2);
	setLedSize(5);
	setLabels("in(0-1)", "in(2)", "in(3-4)",
                  "out(0)", "out(1-2)", "out(3-4)");
    }
    /**
     * evalState is called when an input state changes
     * Parameters:
     *   source - pin number of input source that changed
     *   val - new state value (0 or 1)
     *   
     * Output changes are propagated using putState(dest, val), 
     * where dest is the output pinnumber and val is the new state.
     * 
     * Leds show current pin state
     */
     public void evalState(int source, int val) {
	putState(source+getInputSize(), val);
	setLed(source, val);
    }

}

Pin labels
Pin labels are specified using void setLabels(String... labels). The number of labels should correspond to the number of (actual) input and output pins.

View Class

package plugins.tutorial;

import dlsim.document.DLPlugIn;
import dlsim.view.util.UserPluginView;

public class Plugin02View extends UserPluginView {
    /**
     * View class for Plugin02
     * author: rms
     */
    public Plugin02View() {
	super();
    }
	
    public Plugin02View(DLPlugIn plugin) {
	super(plugin);
    }

    public void setup() {
	setWD(100);
	setHT(80);
	setNoName(true);
    }
}

View classes must extend UserPluginView and have the following requirements:

Constructors
Two are required, with signatures as shown. Generally, these constructors will simply call super.

Setup
The user must implement setup(), minimally to set width and height of the component. (Size values will be ignored if they are too small to accomodate

The call to void setNoName() inhibits printing of the plug-in's classname.

Note that LED setup is automatic, as in the case of the default view.

Run DLSim 3 (using "ant run") and build the circuit shown below using Plugin02.

The circuit shows the pin labeling specified by setLabels.

Exercise

  1. Change the pin labels. Add pins and LEDs. Remove setNoName.