/// <summary>
        /// Converts (restores) deserialized CircuitData object into a Circuit instance.
        /// Creation of graphical objects for GUI is determined by parameter.
        /// </summary>
        /// <param name="circuitData">deserialized CircuitData object</param>
        /// <param name="signals">the corresponding Signals for the circuit</param>
        /// <param name="createGraphics">states whether to create graphical objects</param>
        /// <returns>restored Circuit instance</returns>
        public Circuit ConvertToCircuit(CircuitData circuitData, SignalList signals, bool createGraphics)
        {
            Circuit circuit = new Circuit();

            CreateElements(circuit, circuitData, signals, createGraphics);
            return(circuit);
        }
        private void CreateElements(Circuit circuit, CircuitData circuitData, SignalList signals, bool createGraphics)
        {
            Dictionary <BaseElement, BaseElementData> elemDict = new Dictionary <BaseElement, BaseElementData>();

            foreach (BaseElementData elemData in circuitData.Elements)
            {
                InputOutputElement element = null;
                element = ConvertElementData(elemData, createGraphics, elemDict, signals);
                if (element != null)
                {
                    circuit.AddElement(element);
                }
            }
            foreach (ConnectionData connectionData in circuitData.Connections)
            {
                Connection connection = new Connection();
                connection.Name = connectionData.Name;
                ConnectTerminals(connection, circuit, elemDict);
                if (connection.Terminals.Count > 0)
                {
                    if (createGraphics)
                    {
                        GraphicConnection graphicConnection =
                            GraphicObjectFactory.CreateInstance(typeof(Connection), connection) as GraphicConnection;
                        CreateConnectionLines(circuit, graphicConnection, connectionData);
                    }
                    circuit.AddElement(connection);
                }
            }
        }
Ejemplo n.º 3
0
 public CircuitEditor()
 {
     InitializeComponent();
     //m_Elements = new List<GraphicBaseElement>();
     m_Circuit    = new Circuit();
     m_GridMode   = GridModes.Lines;
     m_SignalList = new SignalList();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts an array of SignalData to a SignalList
        /// </summary>
        /// <param name="signalDataArray">Array of SignalData to convert</param>
        /// <returns>converted SignalList</returns>
        public SignalList ConvertToSignalList(SignalData[] signalDataArray)
        {
            SignalList signalList = new SignalList();

            foreach (SignalData signalData in signalDataArray)
            {
                signalList.Add(ConvertSignalData(signalData));
            }
            return(signalList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Converts a SignalList to an array of SignalData
        /// </summary>
        /// <param name="signals">SignalList to convert</param>
        /// <returns>converted Array of SignalData</returns>
        public SignalData[] ConvertFromSignalList(SignalList signals)
        {
            List <SignalData> signalData = new List <SignalData>(signals.Count);

            foreach (Signal signal in signals)
            {
                signalData.Add(ConvertSignal(signal));
            }
            return(signalData.ToArray());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 解析信道列表
        /// </summary>
        private void ParseSignalList()
        {
            // 解析信道列表
            SignalList = EDFSignal.ParseList(StreamReader, Header.SignalCount);

            // 计算每秒采样数量
            SignalList.ForEach((s) =>
            {
                s.SamplesPerSecond = (int)(1 / Header.DataInterval * s.SamplesPerData);
            });

            // 计算每秒采样数量总和
            SamplesPerSecond = SignalList.Sum(s => s.SamplesPerSecond);

            #region TODO 判断文件类型

            if (SignalList[0].DigitalMaximum.Equals(8388607))
            {
                IsEDFX = true;

                BCO_Sample = 3;

                ParseSecondData = (buffer) =>
                {
                    // 声明返回值
                    var result = new double[SignalList.Count][];

                    for (var i = 0; i < result.Length; i++)
                    {
                        var a = result[i];
                    }

                    // 返回结果
                    return(result);
                };
            }
            else
            {
                IsEDFX = false;

                BCO_Sample = 2;

                ParseSecondData = (buffer) =>
                {
                    // 声明返回值
                    var result = new double[SignalList.Count][];

                    // 返回结果
                    return(result);
                };
            }

            #endregion TODO 判断文件类型
        }
Ejemplo n.º 7
0
        public void ConnectToByIndex(Bus bus, params int[] indexes)
        {
            ThrowIfBusWidthIsTooSmall(bus);

            SourceBus = bus;

            SignalList.Clear();
            foreach (var index in indexes)
            {
                SignalList.Add(SignalList[index]);
            }

            _prevValue = ValueFromSignals();
        }
Ejemplo n.º 8
0
        internal void readSignalsAndTime()
        {
            // Assume first line to be titles
            string titleLine = sr.ReadLine();
            var    titles    = titleLine.Split(new char[] { splitChar }, StringSplitOptions.RemoveEmptyEntries);

            this.signals = new SignalList();
            int col = 0;

            foreach (string title in titles)
            {
                signals.Add(new Signal()
                {
                    Name = title, UID = col
                });
                col++;
            }

            // Assume first column to be time
            List <DateTime> samples = new List <DateTime>();

            while (!sr.EndOfStream)
            {
                var line = sr.ReadLine();

                var values = line.Split(new char[] { splitChar }, StringSplitOptions.RemoveEmptyEntries);
                if (values.Length > timeColumn)
                {
                    var timeStr = values[timeColumn];
                    // Try to parse as double
                    double   doubleValue;
                    DateTime dt;
                    if (double.TryParse(timeStr, NumberStyles.Any, nfi, out doubleValue))
                    {
                        dt = new DateTime((long)(doubleValue * TimeSpan.TicksPerSecond));
                        samples.Add(dt);
                    }
                    else if (DateTime.TryParse(timeStr, out dt))
                    {
                        samples.Add(dt);
                    }
                }
            }

            timeVector = samples.ToArray();
        }
        public void TestMethod1()
        {
            //
            // TODO: Testlogik hier einfügen
            //
            Signal signal = new Signal();

            signal.Add(State.Low);
            signal.Add(State.High);
            SignalList sigList = new SignalList();

            sigList.Add(signal);

            SignalData[] sigData;
            sigData = SignalConverter.Instance.ConvertFromSignalList(sigList);
            SignalList compare = SignalConverter.Instance.ConvertToSignalList(sigData);

            Assert.AreEqual <SignalList>(sigList, compare);
            //Assert.IsTrue(sigList.Equals(compare));
        }
Ejemplo n.º 10
0
        public void ConnectTo(Bus bus, int offset = 0, int count = 0)
        {
            ThrowIfBusWidthIsTooSmall(bus);

            SourceBus = bus;

            if (count == 0)
            {
                count = BusWidth;
            }

            SignalList.Clear();
            var signals = bus.Signals.Skip(offset).Take(count);

            foreach (var signal in signals)
            {
                SignalList.Add(signal);
            }

            _prevValue = ValueFromSignals();
        }
Ejemplo n.º 11
0
        //private Connection ConvertConnectionData(ConnectionData connectionData) //directly done in CreateElements()
        //{
        //    Connection connection = new Connection();
        //    connection.Name = connectionData.Name;
        //    return connection;
        //}

        private InputOutputElement ConvertElementData(BaseElementData elemData, bool createGraphics,
                                                      Dictionary <BaseElement, BaseElementData> elemDict, SignalList signals)
        {
            InputOutputElement io = null;
            //determine type
            string desiredType = String.Empty;

            if (elemData is ClockData)
            {
                desiredType = typeof(Clock).Name;
            }
            if (elemData is ConstantInputData)
            {
                desiredType = typeof(ConstantInput).Name;
            }
            if (elemData is InputElementData)
            {
                desiredType = typeof(SignalInput).Name;
            }
            if (elemData is OutputElementData)
            {
                desiredType = typeof(SignalOutput).Name;
            }
            if (elemData is IOElementData)
            {
                desiredType = (elemData as IOElementData).Type;
            }
            if (elemData is MacroElementData)
            {
                desiredType = typeof(Macro).Name;
                MacroCache       cache            = MacroCache.Instance;
                MacroElementData macroElementData = elemData as MacroElementData;
                io = cache.GetMacro(macroElementData.Type);
                if (io == null)
                {
                    string loaded = cache.LoadMacro(macroElementData.Reference);
                    if (String.IsNullOrEmpty(loaded))
                    {
                        throw new MacroReferenceNotFoundException(String.Format("Macro not found: \"{0}\".", macroElementData.Type));
                    }
                    else if (loaded.CompareTo(macroElementData.Type) != 0)
                    {
                        throw new MacroReferenceTypeMismatchException(String.Format("Desired macro type \"{0}\" mismatches type \"{1}\" contained in file \"{2}\".", macroElementData.Type, loaded, macroElementData.Reference));
                    }
                    io = cache.GetMacro(macroElementData.Type);
                }
                if (createGraphics)
                {
                    GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(typeof(Macro), io);
                    graphic.Location = new PointF(elemData.X, elemData.Y);
                }
            }
            if (String.IsNullOrEmpty(desiredType))
            {
                throw new NotImplementedException(String.Format("Restoring of Type {0} not implemented", elemData.GetType().Name));
                //return null;
            }
            //create instance of io element type type (not macros)
            foreach (Type type in m_ElementTypes)
            {
                if (type.Name.Equals(desiredType))
                {
                    io = (InputOutputElement)Activator.CreateInstance(type);

                    if (elemData is InputElementData)
                    {
                        InputElementData inelemData = elemData as InputElementData;
                        if (signals != null)
                        {
                            foreach (Signal signal in signals)
                            {
                                if (signal.Name.Equals(inelemData.SignalName))
                                {
                                    (io as SignalInput).Signal = signal;
                                }
                            }
                        }
                    }

                    if (createGraphics)
                    {
                        GraphicBaseElement graphic = GraphicObjectFactory.CreateInstance(type, io);
                        graphic.Location = new PointF(elemData.X, elemData.Y);
                    }
                    break;
                }
            }
            if (io == null)
            {
                return(null);
            }
            //restore terminals
            if (elemData is ClockData)
            {
                ClockData clockData = elemData as ClockData;
                io.OutputCount = clockData.Outputs.Length;
                RestoreTerminals(clockData.Outputs, io.Outputs);
                Clock clock = io as Clock;
                clock.HighDuration = clockData.HighDuration;
                clock.LowDuration  = clockData.LowDuration;
            }
            if (elemData is ConstantInputData)
            {
                ConstantInputData  inelemData = elemData as ConstantInputData;
                StateTypeConverter stateconv  = new StateTypeConverter();
                (io as ConstantInput).State = (State)stateconv.ConvertFromString(inelemData.State.Trim());
                io.OutputCount = inelemData.Outputs.Length;
                RestoreTerminals(inelemData.Outputs, io.Outputs);
            }
            if (elemData is InputElementData)
            {
                InputElementData inelemData = elemData as InputElementData;
                io.OutputCount = inelemData.Outputs.Length;
                RestoreTerminals(inelemData.Outputs, io.Outputs);
                if (signals != null)
                {
                    foreach (Signal signal in signals)
                    {
                        if (signal.Name.Equals(inelemData.SignalName))
                        {
                            (io as SignalInput).Signal = signal;
                        }
                    }
                }
            }
            if (elemData is OutputElementData)
            {
                OutputElementData outelemData = elemData as OutputElementData;
                (io as SignalOutput).SignalName = outelemData.SignalName;
                io.InputCount = outelemData.Inputs.Length;
                RestoreTerminals(outelemData.Inputs, io.Inputs);
            }
            if (elemData is IOElementData || elemData is MacroElementData)
            {
                IOElementData ioelemData = elemData as IOElementData;
                io.InputCount  = ioelemData.Inputs.Length;
                io.OutputCount = ioelemData.Outputs.Length;
                RestoreTerminals(ioelemData.Inputs, io.Inputs);
                RestoreTerminals(ioelemData.Outputs, io.Outputs);
                io.UpdateIndex  = ioelemData.Index;
                io.UnitDelay    = ioelemData.UnitDelay;
                io.NegEdgeDelay = ioelemData.NegativeEdgeDelay;
                io.PosEdgeDelay = ioelemData.PositiveEdgeDelay;
            }
            io.Name = elemData.Name;
            elemDict.Add(io, elemData);
            return(io);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a disconnection specification.
 /// </summary>
 /// <param name="signals">a list of guarded signals</param>
 /// <param name="type">the type of the signals</param>
 /// <param name="after">the disconnection delay</param>
 public DisconnectionSpecification(SignalList signals, SubtypeIndication type, Expression after)
 {
     this.signals = signals;
     this.type    = type;
     this.after   = after;
 }
Ejemplo n.º 13
0
        private void UpdateListViewAfterTreeViewItemSelect()
        {
            lvSignals.Clear();
            lvSignals.Groups.Clear();

            var collectionIdentifier = tvSignals.SelectedNode.Tag as string;

            if (collectionIdentifier != null &&
                !collectionIdentifier.StartsWith("COLLECTION", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            if (collectionIdentifier != null)
            {
                collectionIdentifier = collectionIdentifier.Substring("COLLECTION:".Length);
                var categoryIdentifier = (tvSignals.SelectedNode.Parent.Tag as string)?.Substring("CATEGORY:".Length);
                var sourceIdentifier   =
                    (tvSignals.SelectedNode.Parent.Parent.Tag as string)?.Substring("SOURCE:".Length);

                lvSignals.Columns.Clear();
                lvSignals.Columns.Add(nameof(Signal));

                lvSignals.BeginUpdate();
                var signalsThisSource     = Signals.GetSignalsFromSource(sourceIdentifier);
                var signalsThisCategory   = signalsThisSource.GetSignalsByCategory(categoryIdentifier);
                var signalsThisCollection = signalsThisCategory.GetSignalsByCollection(collectionIdentifier);
                if (signalsThisCollection != null)
                {
                    var subCollections = signalsThisCollection.GetUniqueSubcollections(collectionIdentifier)
                                         .OrderBy(x => x)
                                         .ToList();


                    if (subCollections.Count > 0)
                    {
                        var signalsAlreadyAdded = new SignalList <Signal>();
                        foreach (var subcollectionName in subCollections)
                        {
                            var lvg = new ListViewGroup(subcollectionName, HorizontalAlignment.Left);
                            lvSignals.Groups.Add(lvg);
                            var signalsThisSubcollection =
                                signalsThisCollection
                                .GetSignalsBySubcollectionName(collectionIdentifier, subcollectionName)
                                .OrderBy(x => x.FriendlyName)
                                .ToList();
                            foreach (var signal in signalsThisSubcollection)
                            {
                                var lvi = CreateListViewItemFromSignal(signal);
                                lvg.Items.Add(lvi);
                                lvSignals.Items.Add(lvi);
                                signalsAlreadyAdded.Add(signal);
                            }
                        }
                        foreach (var signal in signalsThisCollection.Except(signalsAlreadyAdded))
                        {
                            var lvi = CreateListViewItemFromSignal(signal);
                            lvSignals.Items.Add(lvi);
                        }
                    }
                    else
                    {
                        foreach (var signal in signalsThisCollection)
                        {
                            var lvi = CreateListViewItemFromSignal(signal);
                            lvSignals.Items.Add(lvi);
                        }
                    }
                }
            }
            for (var i = 0; i < lvSignals.Columns.Count; i++)
            {
                lvSignals.Columns[i].TextAlign = HorizontalAlignment.Left;
                lvSignals.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            lvSignals.EndUpdate();
            lvSignals.Sort();
        }