private void VisitWire(NationalInstruments.SourceModel.Wire wire) { var dfirWire = (NationalInstruments.Dfir.Wire)_map.GetDfirForModel(wire); bool isFirstVariableWire = dfirWire.GetIsFirstVariableWire(); wire.SetIsFirstVariableWire(isFirstVariableWire); NationalInstruments.Dfir.Terminal dfirSourceTerminal; if (dfirWire.TryGetSourceTerminal(out dfirSourceTerminal)) { wire.SetWireVariable(dfirSourceTerminal.GetFacadeVariable()); } if (!isFirstVariableWire) { wire.SetWireBeginsMutableVariable(false); } }
private void VisitConnectable(Connectable connectable) { // Update terminals on a TerminateLifetime before reflecting types var terminateLifetime = connectable as TerminateLifetime; var typePassthrough = connectable as TypePassthrough; var structFieldAccessor = connectable as StructFieldAccessor; var variantMatchStructure = connectable as SourceModel.VariantMatchStructure; if (terminateLifetime != null) { VisitTerminateLifetime(terminateLifetime); } if (typePassthrough != null) { NIType type = _map.GetDfirForTerminal(typePassthrough.InputTerminals.ElementAt(0)).GetTrueVariable().Type.GetReferentType(); typePassthrough.Type = type; } if (structFieldAccessor != null) { var structFieldAccessorDfir = (StructFieldAccessorNode)_map.GetDfirForModel(structFieldAccessor); structFieldAccessor.UpdateDependencies(structFieldAccessorDfir.StructType); } if (variantMatchStructure != null) { var variantMatchStructureSelectorDfir = ((Nodes.VariantMatchStructure)_map.GetDfirForModel(variantMatchStructure)).Selector; NIType variantType = variantMatchStructureSelectorDfir.InputTerminals[0].GetTrueVariable().Type; variantMatchStructure.UpdateDependencies(variantType); } foreach (var nodeTerminal in connectable.Terminals) { NationalInstruments.Dfir.Terminal dfirTerminal = _map.GetDfirForTerminal(nodeTerminal); NIType typeToReflect = dfirTerminal.DataType; if (!nodeTerminal.DataType.Equals(typeToReflect)) { nodeTerminal.DataType = typeToReflect; } } }
public static DfirWire TranslateModelWire(this DfirModelMap dfirModelMap, SMWire wire) { var connectedDfirTerminals = new List <DfirTerminal>(); var looseEnds = new List <SMTerminal>(); foreach (SMTerminal terminal in wire.Terminals) { if (terminal.ConnectedTerminal != null) { connectedDfirTerminals.Add(dfirModelMap.GetDfirForTerminal(terminal.ConnectedTerminal)); } else { looseEnds.Add(terminal); } } var parentDiagram = (DfirDiagram)dfirModelMap.GetDfirForModel(wire.Owner); DfirWire dfirWire = DfirWire.Create(parentDiagram, connectedDfirTerminals); dfirModelMap.AddMapping(wire, dfirWire); int i = 0; // Map connected model wire terminals foreach (SMTerminal terminal in wire.Terminals.Where(t => t.ConnectedTerminal != null)) { dfirModelMap.MapTerminalAndType(terminal, dfirWire.Terminals[i]); i++; } // Map unconnected model wire terminals foreach (SMTerminal terminal in looseEnds) { DfirTerminal dfirTerminal = dfirWire.CreateBranch(); dfirModelMap.MapTerminalAndType(terminal, dfirTerminal); } // "Map" loose ends with no terminals in the model int numberOfLooseEndsInModel = wire.Joints.Count(j => j.Dangling); for (int looseEndsIndex = 0; looseEndsIndex < numberOfLooseEndsInModel; ++looseEndsIndex) { DfirTerminal dfirTerminal = dfirWire.CreateBranch(); dfirTerminal.DataType = NITypes.Void; } return(dfirWire); }
private NationalInstruments.Dfir.BorderNode TranslateBorderNode(BorderNode sourceModelBorderNode, NationalInstruments.Dfir.Structure dfirParentStructure) { var flatSequenceSimpleTunnel = sourceModelBorderNode as FlatSequenceSimpleTunnel; var loopTunnel = sourceModelBorderNode as LoopTunnel; var borrowTunnel = sourceModelBorderNode as SourceModel.BorrowTunnel; var loopBorrowTunnel = sourceModelBorderNode as LoopBorrowTunnel; var lockTunnel = sourceModelBorderNode as SourceModel.LockTunnel; var loopConditionTunnel = sourceModelBorderNode as SourceModel.LoopConditionTunnel; var loopIterateTunnel = sourceModelBorderNode as SourceModel.LoopIterateTunnel; var flatSequenceTerminateLifetimeTunnel = sourceModelBorderNode as FlatSequenceTerminateLifetimeTunnel; var loopTerminateLifetimeTunnel = sourceModelBorderNode as LoopTerminateLifetimeTunnel; var unwrapOptionTunnel = sourceModelBorderNode as SourceModel.UnwrapOptionTunnel; if (borrowTunnel != null) { var borrowDfir = new Nodes.BorrowTunnel(dfirParentStructure, borrowTunnel.BorrowMode); CreateTerminateLifetimeTunnel(borrowDfir, dfirParentStructure); return(borrowDfir); } else if (loopBorrowTunnel != null) { var borrowDfir = new Nodes.BorrowTunnel(dfirParentStructure, loopBorrowTunnel.BorrowMode); CreateTerminateLifetimeTunnel(borrowDfir, dfirParentStructure); return(borrowDfir); } else if (lockTunnel != null) { var lockDfir = new Nodes.LockTunnel(dfirParentStructure); CreateTerminateLifetimeTunnel(lockDfir, dfirParentStructure); return(lockDfir); } else if (loopConditionTunnel != null) { var loopConditionDfir = new Nodes.LoopConditionTunnel((Nodes.Loop)dfirParentStructure); CreateTerminateLifetimeTunnel(loopConditionDfir, dfirParentStructure); return(loopConditionDfir); } else if (loopIterateTunnel != null) { var loopIterateDfir = new IterateTunnel(dfirParentStructure); CreateTerminateLifetimeTunnel(loopIterateDfir, dfirParentStructure); return(loopIterateDfir); } else if (flatSequenceTerminateLifetimeTunnel != null) { var beginLifetimeDfir = (Nodes.IBeginLifetimeTunnel)_map.GetDfirForModel((Element)flatSequenceTerminateLifetimeTunnel.BeginLifetimeTunnel); return(beginLifetimeDfir.TerminateLifetimeTunnel); } else if (loopTerminateLifetimeTunnel != null) { var beginLifetimeDfir = (Nodes.IBeginLifetimeTunnel)_map.GetDfirForModel((Element)loopTerminateLifetimeTunnel.BeginLifetimeTunnel); return(beginLifetimeDfir.TerminateLifetimeTunnel); } else if (flatSequenceSimpleTunnel != null || loopTunnel != null) { return(dfirParentStructure.CreateTunnel( VIDfirBuilder.TranslateDirection(sourceModelBorderNode.PrimaryOuterTerminal.Direction), NationalInstruments.Dfir.TunnelMode.LastValue, sourceModelBorderNode.PrimaryOuterTerminal.DataType, sourceModelBorderNode.PrimaryInnerTerminals.First().DataType)); } else if (unwrapOptionTunnel != null) { return(new Nodes.UnwrapOptionTunnel(dfirParentStructure)); } throw new NotImplementedException("Unknown BorderNode type: " + sourceModelBorderNode.GetType().Name); }