protected override void UpdateInnerSystem(ref DeMIMOI_InputOutput[] new_outputs) { if (Inputs[0][0].Value != null) { new_outputs[0].Value = (int)Inputs[0][0].Value * 2; new_outputs[1].Value = (int)Inputs[0][1].Value * 4; } }
public DeMIMOI_ConnectionEventArgs(DeMIMOI_InputOutput from, DeMIMOI_InputOutput to) { From = from; To = to; }
/// <summary> /// Search the inputs or outputs of the parent model of the input given to return the input indexes in the Input array it is contained /// </summary> /// <param name="input">Input to find the indexes</param> /// <param name="arrayToSearchIn">Array of the DeMIMOI to search in (Inputs or Outputs array)</param> /// <returns>The indexes found (both to -1 if it does not succeed)</returns> private static int[] GetInputOutputIndexes(DeMIMOI_InputOutput input, DeMIMOI_InputOutputType arrayToSearchIn) { // Initialize the indexes found to -1 (default if not found) int[] indexesFound = new int[2]; indexesFound[0] = -1; indexesFound[1] = -1; // Create a reference that points the array we should search in List<List<DeMIMOI_InputOutput>> demimoi_io_array; if (arrayToSearchIn == DeMIMOI_InputOutputType.INPUT) { demimoi_io_array = input.Parent.Inputs; } else { demimoi_io_array = input.Parent.Outputs; } // Search the selected array to find the input_output in for (int i = 0; i < demimoi_io_array.Count; i++) { for (int j = 0; j < demimoi_io_array[i].Count; j++) { // If we find it if (demimoi_io_array[i][j] == input) { // Get the index and leave the whole loop indexesFound[0] = i; indexesFound[1] = j; break; } } // If we found the indexes, leave the loop if (indexesFound[0] != -1) { break; } } return indexesFound; }
/// <summary> /// Connects two DeMIMOI_InputOutput to each other /// <remarks>It has to be one input and one output.</remarks> /// </summary> /// <param name="input_output">If the current object is an input, this argument must be an output, if the current object is an output, this argument must be an input</param> public void ConnectTo(DeMIMOI_InputOutput input_output) { // If the input we want to connect is defined... if (input_output != null) { // If it's an output and the argument is an input... if (Type == DeMIMOI_InputOutputType.OUTPUT && input_output.Type == DeMIMOI_InputOutputType.INPUT) { // Ok, connect the input to this output input_output.ConnectedTo = this; // If event signalling is required if (Connected != null) { Connected(this, new DeMIMOI_ConnectionEventArgs(this, input_output)); } // If event signalling for the input is required if (input_output.Connected != null) { input_output.Connected(this, new DeMIMOI_ConnectionEventArgs(this, input_output)); } } else { // If it's an input and the argument is an output... if (Type == DeMIMOI_InputOutputType.INPUT && input_output.Type == DeMIMOI_InputOutputType.OUTPUT) { // Ok, connect this to the given output ConnectedTo = input_output; // If event signalling is required if (Connected != null) { Connected(this, new DeMIMOI_ConnectionEventArgs(input_output, this)); } // If event signalling for the output is required if (input_output.Connected != null) { input_output.Connected(this, new DeMIMOI_ConnectionEventArgs(input_output, this)); } } else { // NOK, this makes non sense ! Trying to connect two outputs or two inputs... throw new Exception("Can't connect two inputs or two outputs together ! Connect one output to an input !"); } } } else { // The input (or output) is not defined, so we unplug Unplug(this); } }
/// <summary> /// Disconnects an input from the output it's connected to /// </summary> /// <param name="input">An input typed DeMIMOI_InputOutput object to disconnect</param> public static void Unplug(DeMIMOI_InputOutput input) { // If it's an input if (input.Type == DeMIMOI_InputOutputType.INPUT) { // If the input is connected to something if (input.ConnectedTo != null) { DeMIMOI_ConnectionEventArgs eventArg = null; // Before disconnecting, pick up the current value and set it to the input (i.e. once it has been disconnected, the input keeps the last value it had before disconnection) input.input_output_value = input.ConnectedTo.Value; // If event signalling is required if (input.Disconnected != null) { // Prepare the event args eventArg = new DeMIMOI_ConnectionEventArgs(input.ConnectedTo, input); } // Disconnect it input.ConnectedTo = null; // Reset the IgnoreConnection so that it will be taken into account for the new connection it may have in the future input.IgnoreConnection = false; // If event signalling is required if (input.Disconnected != null) { input.Disconnected(input, eventArg); } } } else { throw new Exception("Can't unplug an output !"); } }
/// <summary> /// Search the inputs or outputs of the parent model of the input given to return the input indexes in the Input array it is contained /// </summary> /// <param name="input_output">Input to find the indexes</param> /// <returns>The indexes found (both to -1 if it does not succeed)</returns> public static int[] GetInputOutputIndexes(DeMIMOI_InputOutput input_output) { // First search in the same array than the input_output.Type indicates int[] indexesFound = GetInputOutputIndexes(input_output, input_output.Type); // If we didn't find anything, try on the other array (i.e. Output array if input_output is an input and vice versa) if (indexesFound[0] == -1) { if (input_output.Type == DeMIMOI_InputOutputType.INPUT) { indexesFound = GetInputOutputIndexes(input_output, DeMIMOI_InputOutputType.OUTPUT); } else { indexesFound = GetInputOutputIndexes(input_output, DeMIMOI_InputOutputType.INPUT); } } return indexesFound; }
/// <summary> /// Creates a DeMIMOI_Constant and connect it to the desired input to set constant /// </summary> /// <param name="inputToSetTo">Input to set to the constant</param> /// <param name="value">Value of the constant to set</param> public DeMIMOI_Constant(DeMIMOI_InputOutput inputToSetTo, object value) : base(null, new DeMIMOI_Port(1)) { Initialize(inputToSetTo, value); }
void Initialize(DeMIMOI_InputOutput inputToSetTo, object value) { ID = AllocNewId(); Name = GetType().Name + "_" + ID; ConstOutput.Value = value; ConstOutput.Connected += new DeMIMOI_ConnectionEventHandler(ConstOutput_Connected); if (inputToSetTo != null) { ConstOutput.ConnectTo(inputToSetTo); } UpdateName(); }
/// <summary> /// Initializes outputs arrays /// </summary> /// <param name="output_count">Number of outputs of the system</param> /// <param name="output_delays_count">Number of delayed output steps</param> protected void InitializeOutputs(DeMIMOI_Port output_port) { if (output_port != null) { // Create the outputs image for time t CurrentOutputs = new List<DeMIMOI_InputOutput>(); for (int j = 0; j < output_port.IODelayCount.Length; j++) { CurrentOutputs.Add(new DeMIMOI_InputOutput(this, DeMIMOI_InputOutputType.OUTPUT)); } // Create all the outputs including delayed outputs Outputs = new List<List<DeMIMOI_InputOutput>>(); for (int i = 0; i < output_port.IODelayCount.Length; i++) { // Create the delayed outputs for the current output List<DeMIMOI_InputOutput> outputs_i_n = new List<DeMIMOI_InputOutput>(); for (int j = 0; j < output_port.IODelayCount[i]; j++) { DeMIMOI_InputOutput io = new DeMIMOI_InputOutput(this, DeMIMOI_InputOutputType.OUTPUT); io.Connected += new DeMIMOI_ConnectionEventHandler(DeMIMOI_Connected); io.Disconnected += new DeMIMOI_ConnectionEventHandler(DeMIMOI_Disconnected); outputs_i_n.Add(io); } Outputs.Add(outputs_i_n); } } }