예제 #1
0
        /// <summary>
        /// 检验region的合法性
        /// </summary>
        /// <param name="start">开始位置</param>
        /// <param name="end">结束位置</param>
        /// <returns>是否合法</returns>
        private bool VerifyRegion(int start, int end, HighLevelRegion updateRegion)
        {
            bool legal = true;

            foreach (var region in this.HighLevelRegions)
            {
                if (region == updateRegion)
                {
                    continue;
                }

                if (start >= region.StartPosition - 1 && start <= region.EndPosition + 1)
                {
                    legal = false;
                    break;
                }

                if (end >= region.StartPosition - 1 && end <= region.EndPosition + 1)
                {
                    legal = false;
                    break;
                }
            }

            return(legal);
        }
예제 #2
0
        /// <summary>
        /// List Box 选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HighRegionsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox         listBox = sender as ListBox;
            HighLevelRegion region  = listBox?.SelectedValue as HighLevelRegion;

            if (region == null)
            {
                return;
            }
            this._selectHighLevelRegion = region;
        }
예제 #3
0
        /// <summary>
        /// 添加高电平区域事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddRegionButton_OnClick(object sender, RoutedEventArgs e)
        {
            int start = Convert.ToInt32(this.RegionStartTextBox.Text);
            int end   = Convert.ToInt32(this.RegionEndTextBox.Text);

            if (!this.VerifyRegion(start, end, null))
            {
                MessageBox.Show("高电平起始结束位置冲突", "设置错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            HighLevelRegion newRegion = new HighLevelRegion(start, end);

            this.HighLevelRegions.Insert(this.FindRightPosition4NewRegion(start), newRegion);
        }
예제 #4
0
        /// <summary>
        /// TTL字符串改变事件
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void TtlStringPropertyCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TtlSettingWindow settingWindow = d as TtlSettingWindow;

            if (settingWindow == null)
            {
                return;
            }
            char[] chars = settingWindow.TtlString.ToCharArray();
            settingWindow.TtlLengthTextBox.Text = chars.Length.ToString();
            HighLevelRegion region = null;

            for (int i = 0; i < chars.Length; i++)
            {
                char c = chars[i];
                if (c == '1')
                {
                    if (region == null)
                    {
                        region = new HighLevelRegion(i, i);
                    }
                    else
                    {
                        region.EndPosition = i;
                    }

                    if (i != chars.Length - 1)
                    {
                        continue;
                    }
                    settingWindow.HighLevelRegions.Add(region);
                    region = null;
                }
                else
                {
                    if (region == null)
                    {
                        continue;
                    }
                    settingWindow.HighLevelRegions.Add(region);
                    region = null;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// 更新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UpdateRegionButton_OnClick(object sender, RoutedEventArgs e)
        {
            int start = Convert.ToInt32(this.RegionStartTextBox.Text);
            int end   = Convert.ToInt32(this.RegionEndTextBox.Text);
            //            HighLevelRegion selectedRegion = this.HighRegionsListBox.SelectedItem as HighLevelRegion;
            HighLevelRegion selectedRegion = this.HighLevelRegions[this.HighRegionsListBox.SelectedIndex];

            if (selectedRegion == null)
            {
                return;
            }
            if (!this.VerifyRegion(start, end, selectedRegion))
            {
                MessageBox.Show("高电平起始结束位置冲突", "设置错误", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            selectedRegion.StartPosition = start;
            selectedRegion.EndPosition   = end;
            this.HighRegionsListBox.Items.Refresh();
        }