public void UpdateInputTerminals(int inputTerminalCount) { AutoBorrowNodeFacade nodeFacade = AutoBorrowNodeFacade.GetNodeFacade(this); var immutableReferenceType = NITypes.Void.CreateImmutableReference(); int currentInputTerminalCount = InputTerminals.Count(); if (currentInputTerminalCount < inputTerminalCount) { for (; currentInputTerminalCount < inputTerminalCount; ++currentInputTerminalCount) { var terminal = CreateTerminal(Direction.Input, immutableReferenceType, "inner lifetime"); nodeFacade[terminal] = new SimpleTerminalFacade(terminal, terminal.GetTypeVariableSet().CreateReferenceToNewTypeVariable()); MoveTerminalToIndex(terminal, currentInputTerminalCount); } } else if (currentInputTerminalCount > inputTerminalCount) { int i = currentInputTerminalCount - 1; while (i >= 0 && currentInputTerminalCount > inputTerminalCount) { Terminal inputTerminal = InputTerminals.ElementAt(i); if (!inputTerminal.IsConnected) { RemoveTerminalAtIndex(inputTerminal.Index); --currentInputTerminalCount; } --i; } } }
public void UpdateTerminals(int inputTerminalCount, int outputTerminalCount) { var immutableReferenceType = NITypes.Void.CreateImmutableReference(); int currentInputTerminalCount = InputTerminals.Count(); if (currentInputTerminalCount < inputTerminalCount) { for (; currentInputTerminalCount < inputTerminalCount; ++currentInputTerminalCount) { var inputTerminal = new NodeTerminal(Direction.Input, immutableReferenceType, "nested scope"); InsertComponent(currentInputTerminalCount, inputTerminal); } } else if (currentInputTerminalCount > inputTerminalCount) { int i = currentInputTerminalCount - 1; while (i >= 0 && currentInputTerminalCount > inputTerminalCount) { Terminal inputTerminal = InputTerminals.ElementAt(i); if (!inputTerminal.Connected) { RemoveComponent(inputTerminal); --currentInputTerminalCount; } --i; } } int currentOutputTerminalCount = OutputTerminals.Count(); if (currentOutputTerminalCount < outputTerminalCount) { for (; currentOutputTerminalCount < outputTerminalCount; ++currentOutputTerminalCount) { var outputTerminal = new NodeTerminal(Direction.Output, immutableReferenceType, "outer scope"); InsertComponent(currentInputTerminalCount + currentOutputTerminalCount, outputTerminal); } } else if (currentOutputTerminalCount > outputTerminalCount) { int i = currentOutputTerminalCount - 1; while (i >= 0 && currentOutputTerminalCount > outputTerminalCount) { Terminal outputTerminal = OutputTerminals.ElementAt(i); if (!outputTerminal.Connected) { RemoveComponent(outputTerminal); --currentOutputTerminalCount; } --i; } } SetIconViewGeometry(); }
protected override void SetIconViewGeometry() { int maxSideTerminals = Math.Max(InputTerminals.Count(), OutputTerminals.Count()); Bounds = new SMRect(Left, Top, StockDiagramGeometries.GridSize * 4, StockDiagramGeometries.GridSize * Math.Max(maxSideTerminals, 2) * 2); int i = 0; foreach (var inputTerminal in InputTerminals) { inputTerminal.Hotspot = new SMPoint(0, StockDiagramGeometries.GridSize * (i * 2 + 1)); ++i; } i = 0; foreach (var outputTerminal in OutputTerminals) { outputTerminal.Hotspot = new SMPoint(StockDiagramGeometries.GridSize * 4, StockDiagramGeometries.GridSize * (i * 2 + 1)); ++i; } }
private void UpdateTerminalsFromDataType(NIType type) { bool isStruct = type.IsValueClass(); bool isUnion = type.IsUnion(); if (isStruct || isUnion) { NIType[] fields = type.GetFields().ToArray(); int inputTerminalCount = isStruct ? fields.Length : 1; if (!InputTerminals.HasExactly(inputTerminalCount)) { while (inputTerminalCount < InputTerminals.Count()) { FixedTerminals.Remove(FixedTerminals.Last()); } while (inputTerminalCount > InputTerminals.Count()) { int index = InputTerminals.Count(); FixedTerminals.Add(new ConstructorTerminal(NITypes.Void, $"element{index}")); } if (isStruct) { foreach (var pair in FixedTerminals.Skip(1).Cast <ConstructorTerminal>().Zip(fields)) { pair.Key.FieldName = pair.Value.GetName(); } } else { // TODO: attempt to recover the same variant element index ((ConstructorTerminal)FixedTerminals[1]).FieldName = fields[0].GetName(); } } SetGeometry(); } }