/* * Example of a simple node performing a mathematical operation * Created by Richard Radlherr */ using System; // It is important to import the TagTool core classes which defines // the BaseNode class using TagTool.Core; namespace TestNodeCollection.MyNodes { /** * The information attribute lets you set the name * and a description of the node you are intending to program. * * All nodes must be derived from the BaseNode class. */ [Information("Modulo", ToolTipText = "Calculates the modulus.")] public class MyClass : BaseNode { // declare neccessary input slots InputSlot number; InputSlot modulus; // declare neccessary output slots OutputSlot result; /** * Each node must have a standard constructor. */ public MyClass() { // this is the name of this instance of the modulo node. Name = "Modulo"; // Create the slot for the argument from which we calculate // the modulus. // The default value is zero // to be compatible to the most nodes from the Nodekit we use // the double datatype instead of an integer. // For the modulo calulation we use only the fixed part of the // number. number = new InputSlot(this, "Number", 0.0); // Let the slot update the node if its value changes. number.Active = true; // set a callback for parsing values - this enables a text // field for entering the value. number.ParseCallback = ParseDouble; // Similarly to the number input slot we set up the // modulus input slot. // Note that zero is not allowed in a modulo operation. modulus = new InputSlot(this, "Modulus", 1.0); modulus.Active = true; modulus.ParseCallback = ParseDouble; // create the slot containing the result of the calculation. result = new OutputSlot(this, "Result", typeof(double)); // set an initial value for the output. result.Value = 0.0; } /** * Parse callback for the numbers. */ private static Object ParseDouble(String description) { return Convert.ToDouble(description); } /** * The update method is where the work is done. */ public override void Update(Object sender) { // prevent from division by zero if((int)(double)modulus.Value > 0) { result.Value = (double) ((int)(double)number.Value % (int)(double)modulus.Value); } } /** * On initializatoin (called after loading the node) we have nothing * to do. */ public override void Initialize() { } /** * Expose each slot as property member of the class. *´The node attribute is necessary for creating the GUI * automatically * by traversing over the properties. */ [NodeAttribute(SlotType.Input, Show = true)] public InputSlot Number { get { return number; } } [NodeAttribute(SlotType.Input, Show = true)] public InputSlot Modulus { get { return modulus; } } [NodeAttribute(SlotType.Output, Show = true)] public OutputSlot Result { get { return result; } } } }