예제 #1
0
파일: PinGroup.cs 프로젝트: brekooname/HLab
        public T GetOrAddPin <T>(Action <T> factory, string id, GraphValueType type = null) where T : IPin, new()
        {
            if (string.IsNullOrEmpty(id))
            {
                var pins = Pins.Where(p => p.Id.StartsWith("#")).ToList();
                id = "#" + (pins.Count == 0?0:pins.Max(p => int.Parse(p.Id.TrimStart('#'))) + 1);
            }
            else
            {
                var pin = Pins.FirstOrDefault(p => p.Id == id);
                if (pin is T tp)
                {
                    return(tp);
                }
            }

            var newPin = new T
            {
                Id    = id,
                Group = this,
            };

            if (type != null)
            {
                newPin.ValueType = type;
            }

            factory?.Invoke(newPin);

            Pins.Add(newPin);
            return(newPin);
        }
예제 #2
0
        /// <summary>
        /// Removes the pin.
        /// </summary>
        /// <param name="name">Name.</param>
        public void RemovePin(string name)
        {
            var result = Pins.Where(o => o.Name == name).ToList <IPin> ();

            if (result.Count > 0)
            {
                var pin = result.First();
                if (pin is DPin)
                {
                    var tmp = GetCorespondingSequence(pin as DPin);
                    if (tmp != null)
                    {
                        RemoveSequence(tmp.Name);
                    }
                }
                else if (pin is APin)
                {
                    var tmp = GetCorespondingCombination(pin as APin);
                    if (tmp != null)
                    {
                        RemoveMeasurementCombination(tmp);
                    }
                }
                Pins.Remove(result.First());
                if (OnPinsUpdated != null)
                {
                    OnPinsUpdated.Invoke(this, new ControllerPinUpdateArgs(result [0], UpdateOperation.Remove));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the digital pins without sequence.
        /// </summary>
        /// <returns>The digital pins without sequence.</returns>
        public DPin[] GetPinsWithoutSequence()
        {
            var pins = Pins.Where(o => (o as DPin) != null).Cast <DPin> ().ToList();

            pins.RemoveAll(o => Sequences.Select(seq => seq.Pin == o).Any(b => b == true));

            return(pins.ToArray());
        }
예제 #4
0
        /// <summary>
        /// Gets the pins without measurement combinations.
        /// </summary>
        /// <returns>The pins without measurement combinations.</returns>
        public APin[] GetPinsWithoutCombinations()
        {
            var pins = Pins.Where(o => o.Type == PinType.ANALOG).Cast <APin> ().ToList();

            pins.RemoveAll(o => MeasurementCombinations.Select(mc => mc.Pins.Contains(o)).Any(b => b == true));

            return(pins.ToArray());
        }
예제 #5
0
        public void UpdatePinsVisible(int?changedCategoryId = null, bool?isSelected = null,
                                      bool?isRootCategory   = null)
        {
            var selectedRootcategories = SelectedRootCategories;
            var selectedSubcategories  = SelectedSubCategories;


            if (!selectedRootcategories.Any())
            {
                foreach (var pin in Pins)
                {
                    pin.IsVisible = CheckVisiblePinByTags(pin);
                }
            }
            else
            {
                foreach (var pin in Pins.Where(pin => selectedRootcategories.Contains(pin.RootCategory)))
                {
                    if (!CheckVisiblePinByTags(pin))
                    {
                        pin.IsVisible = false;
                        continue;
                    }

                    if (!pin.SubCategories.Any()) //Если нет вложенных категорий, или ни одна из подкатегорий не выбрана
                    {
                        pin.IsVisible = true;
                    }
                    else
                    {
                        var subcategories =
                            PinSubCategories.Where(item => item.ParentId == pin.RootCategory).Select(item => item.Id);
                        // Если не отмечены никакие подкатегории в категории
                        var selectedByNoSelectedSubcategoriesIncategory =
                            !selectedSubcategories.Intersect(subcategories).Any();
                        var visibleBySelectedSubCategory =
                            pin.SubCategories.Any(item => selectedSubcategories.Contains(item));
                        //Если выбрана подкатегория с пином
                        pin.IsVisible = (visibleBySelectedSubCategory || selectedByNoSelectedSubcategoriesIncategory);
                    }
                }
                foreach (var pin in Pins.Where(pin => !selectedRootcategories.Contains(pin.RootCategory)))
                {
                    pin.IsVisible = false;
                }
            }
            OnPropertyChanged(nameof(SelectedPinsCnt));
        }
예제 #6
0
        public SimulationResult(IReadOnlyList <SchemeState> states)
        {
            Pins = states[0]
                   .InputPins
                   .Concat(states[0].OutputPins)
                   .Where(x => x.IsSignificant)
                   .Select(x => ExtractPinValuesFromStateList(x, states))
                   .ToArray();

            foreach (var pin in Pins.Where(x => x.IsOutputPin))
            {
                Score += pin.ActualValues.Zip(pin.CorrectValues, (a, c) => a == c ? 1.0 : 0).Sum();
            }

            Score /= states.Count;
            Score /= Pins.Count(x => x.IsOutputPin);
        }