/** * Reorders input signal assignments to match Simulink MDL order (utilty method only needed for * Simulink model generation) * * <p>Put in this class due to need to access lots of internals. */ public void reorderInputsForMDL() { // If only one or two inputs, no need to change anything if (this.numInputs() > 2) { // move 1, 2, 3, ... n-2, n-1, n to // n, n-1, n-2, ... 3, 1, 2 // note first two are in reverse order // This is due to Matlab order requirements // loop through inputs Iterator<Signal> theInputsIterator = this.getInputIterator(); while (theInputsIterator.hasNext()) { Signal theInput = theInputsIterator.next(); // find our index into the signal's destination // ports BlockArrayList destBlocks = theInput.getDests(); ArrayList<Integer> destPorts = theInput.getDestPortNumbers(); // Look for ourself in the destBlocks & record // corresponding port index Iterator<Block> destBlockIterator = destBlocks.iterator(); Iterator<Integer> destPortIterator = destPorts.iterator(); int thePortIndex = 0; while (destBlockIterator.hasNext()) { Block destBlock = destBlockIterator.next(); Integer destPort = destPortIterator.next(); if (destBlock == this) { // set value for new index int oldPortNumber = destPort.intValue(); int newPortNumber = (this.numInputs() + 1) - oldPortNumber; if (oldPortNumber == (this.numInputs() - 1)) newPortNumber = 1; if (oldPortNumber == (this.numInputs())) newPortNumber = 2; theInput.setPortNumber(thePortIndex, newPortNumber); } thePortIndex++; } } } }