Пример #1
0
 public static void MapTerminalsInOrder(this DfirModelMap dfirModelMap, SMNode sourceModelNode, DfirNode dfirNode)
 {
     foreach (var pair in sourceModelNode.Terminals.Zip(dfirNode.Terminals))
     {
         dfirModelMap.MapTerminalAndType(pair.Key, pair.Value);
     }
 }
Пример #2
0
        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);
        }
Пример #3
0
 private void MapBorderNode(BorderNode sourceModelBorderNode, NationalInstruments.Dfir.BorderNode dfirBorderNode)
 {
     if (dfirBorderNode != null)
     {
         _map.AddMapping(sourceModelBorderNode, dfirBorderNode);
         int i = 0;
         foreach (var terminal in sourceModelBorderNode.OuterTerminals)
         {
             _map.MapTerminalAndType(terminal, dfirBorderNode.GetOuterTerminal(i));
             ++i;
         }
         i = 0;
         foreach (var terminal in sourceModelBorderNode.InnerTerminals)
         {
             // TODO: won't work for border nodes with multiple inner terminals per diagram
             // also assumes that the border node has the same terminals on each diagram, which
             // won't be true for the pattern selector
             // Fortunately, for now, the only inner terminal on OptionPatternStructureSelector is on the first diagram
             _map.MapTerminalAndType(terminal, dfirBorderNode.GetInnerTerminal(i, 0));
             ++i;
         }
     }
 }
Пример #4
0
        private void VisitTerminateLifetime(TerminateLifetime terminateLifetime)
        {
            var terminateLifetimeDfir = (TerminateLifetimeNode)_map.GetDfirForModel(terminateLifetime);

            if (terminateLifetimeDfir.RequiredInputCount != null && terminateLifetimeDfir.RequiredOutputCount != null)
            {
                terminateLifetime.UpdateTerminals(terminateLifetimeDfir.RequiredInputCount.Value, terminateLifetimeDfir.RequiredOutputCount.Value);
            }
            foreach (var pair in terminateLifetime.Terminals.Zip(terminateLifetimeDfir.Terminals))
            {
                if (!_map.ContainsTerminal(pair.Key))
                {
                    _map.MapTerminalAndType(pair.Key, pair.Value);
                }
            }
        }