コード例 #1
0
        /// <summary>
        /// Helper method that creates all the wires on the VI.
        /// Since the other nodes have all been created, this method can look at all the connections on the wire.
        /// </summary>
        private void ConnectWires()
        {
            foreach (Wire wire in _modelWires)
            {
                var connectedDfirTerminals = new List <NationalInstruments.Dfir.Terminal>();
                var looseEnds = new List <Terminal>();
                foreach (Terminal terminal in wire.Terminals)
                {
                    if (terminal.ConnectedTerminal != null)
                    {
                        connectedDfirTerminals.Add(_map.GetDfirForTerminal(terminal.ConnectedTerminal));
                    }
                    else
                    {
                        looseEnds.Add(terminal);
                    }
                }

                var parentDiagram = (NationalInstruments.Dfir.Diagram)_map.GetDfirForModel(wire.Owner);
                NationalInstruments.Dfir.Wire dfirWire = NationalInstruments.Dfir.Wire.Create(parentDiagram, connectedDfirTerminals);
                _map.AddMapping(wire, dfirWire);
                dfirWire.SetWireBeginsMutableVariable(wire.GetWireBeginsMutableVariable());
                int i = 0;
                // Map connected model wire terminals
                foreach (Terminal terminal in wire.Terminals.Where(t => t.ConnectedTerminal != null))
                {
                    MapTerminalAndType(terminal, dfirWire.Terminals[i]);
                    i++;
                }
                // Map unconnected model wire terminals
                foreach (Terminal terminal in looseEnds)
                {
                    NationalInstruments.Dfir.Terminal dfirTerminal = dfirWire.CreateBranch();
                    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)
                {
                    NationalInstruments.Dfir.Terminal dfirTerminal = dfirWire.CreateBranch();
                    dfirTerminal.DataType = PFTypes.Void;
                }

                // Now split the wire up into multiple wires if there are multiple sinks
                if (dfirWire.SinkTerminals.Count > 1)
                {
                }
            }

            // done with stored wires, set to null to avoid memory leaks
            _modelWires = null;
        }
コード例 #2
0
        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;
                }
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        private void VisitConnectable(Connectable connectable)
        {
            // Update terminals on a TerminateLifetime before reflecting types
            var terminateLifetime = connectable as TerminateLifetime;

            if (terminateLifetime != null)
            {
                VisitTerminateLifetime(terminateLifetime);
            }

            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;
                }
            }
        }