/// <summary>
        /// 選択状態のRセンサ描画
        /// </summary>
        /// <param name="sensorCvs"></param>
        /// <returns></returns>
        private CanvasSensor activeSensorR(CanvasSensor sensorCvs)
        {
            this.activeSensorCanvas = sensorCvs;
            //this.locationSetting.setSelectSetting(sensorCvs.chIndex);

            for (int i = 0; i < this.sensorList.Count; i++)
            {
                if (this.sensorList[i] != null && this.sensorList[i].chIndex != sensorCvs.chIndex)
                {
                    if (this.sensorList[i].sensorType == SENSOR_TYPE_R)
                    {
                        this.drawNormalSensorR(this.sensorList[i]);
                    }
                    else if (this.sensorList[i].sensorType == SENSOR_TYPE_B)
                    {
                        this.drawNormalSensorB(this.sensorList[i]);
                    }
                }
            }
            switch (sensorCvs.direction)
            {
                case (SENSOR_DIRECTION_BOTTOM):
                    Canvas.SetTop(sensorCvs.Children[1], 2);
                    Canvas.SetLeft(sensorCvs.Children[1], 2);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_active_bottom"];
                    break;
                case (SENSOR_DIRECTION_LEFT):
                    Canvas.SetTop(sensorCvs.Children[1], 2);
                    Canvas.SetLeft(sensorCvs.Children[1], 18);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_active_left"];
                    break;
                case (SENSOR_DIRECTION_RIGHT):
                    Canvas.SetTop(sensorCvs.Children[1], 18);
                    Canvas.SetLeft(sensorCvs.Children[1], 2);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_active_right"];
                    break;
                case (SENSOR_DIRECTION_TOP):
                    Canvas.SetTop(sensorCvs.Children[1], 18);
                    Canvas.SetLeft(sensorCvs.Children[1], 18);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_active_top"];
                    break;
            }
            this.locationSetting.setSensorMeasureDirection(sensorCvs.chIndex, sensorCvs.direction);

            #region Old Code Program Rendering
            //SolidColorBrush lineBrush = new SolidColorBrush();
            //lineBrush.Color = this.activeSensorColor;

            //sensorCvs.Children.Clear();

            //Rectangle rect = new Rectangle();
            //rect.Fill = Brushes.Transparent;
            //rect.Width = 31;
            //rect.Height = 31;
            //sensorCvs.Children.Add(rect);

            //Line ln1 = new Line();
            //Line ln2 = new Line();
            //Line ln3 = new Line();
            //Line ln4 = new Line();
            //ln1.Stroke = lineBrush;
            //ln1.StrokeThickness = 3;
            //ln2.Stroke = lineBrush;
            //ln2.StrokeThickness = 3;
            //ln3.Stroke = lineBrush;
            //ln3.StrokeThickness = 3;
            //ln4.Stroke = lineBrush;
            //ln4.StrokeThickness = 3;

            //switch (sensorCvs.direction)
            //{
            //    case (SENSOR_DIRECTION_TOP):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 0;

            //        ln2.X1 = 16;
            //        ln2.Y1 = 0;
            //        ln2.X2 = 16;
            //        ln2.Y2 = 31;

            //        ln3.X1 = 27;
            //        ln3.Y1 = 13;
            //        ln3.X2 = 16;
            //        ln3.Y2 = 0;

            //        ln4.X1 = 4;
            //        ln4.Y1 = 16;
            //        ln4.X2 = 16;
            //        ln4.Y2 = 0;

            //        break;
            //    case (SENSOR_DIRECTION_BOTTOM):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 31;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 16;
            //        ln2.Y1 = 0;
            //        ln2.X2 = 16;
            //        ln2.Y2 = 31;

            //        ln3.X1 = 4;
            //        ln3.Y1 = 16;
            //        ln3.X2 = 16;
            //        ln3.Y2 = 31;

            //        ln4.X1 = 27;
            //        ln4.Y1 = 13;
            //        ln4.X2 = 16;
            //        ln4.Y2 = 31;

            //        break;
            //    case (SENSOR_DIRECTION_LEFT):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 0;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 0;
            //        ln2.Y1 = 16;
            //        ln2.X2 = 31;
            //        ln2.Y2 = 16;

            //        ln3.X1 = 16;
            //        ln3.Y1 = 4;
            //        ln3.X2 = 0;
            //        ln3.Y2 = 16;

            //        ln4.X1 = 19;
            //        ln4.Y1 = 27;
            //        ln4.X2 = 0;
            //        ln4.Y2 = 16;

            //        break;
            //    case (SENSOR_DIRECTION_RIGHT):
            //        ln1.X1 = 31;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 0;
            //        ln2.Y1 = 16;
            //        ln2.X2 = 31;
            //        ln2.Y2 = 16;

            //        ln3.X1 = 16;
            //        ln3.Y1 = 27;
            //        ln3.X2 = 31;
            //        ln3.Y2 = 16;

            //        ln4.X1 = 13;
            //        ln4.Y1 = 4;
            //        ln4.X2 = 31;
            //        ln4.Y2 = 16;

            //        break;
            //}
            //sensorCvs.Children.Add(ln1);
            //sensorCvs.Children.Add(ln2);
            //sensorCvs.Children.Add(ln3);
            //sensorCvs.Children.Add(ln4);
            #endregion

            return sensorCvs;
        }
        /// <summary>
        /// 新Rセンサの描画
        /// </summary>
        /// <param name="chIndex"></param>
        /// <returns></returns>
        private CanvasSensor newSensorR(int chIndex)
        {
            CanvasSensor cvs = new CanvasSensor();
            cvs.Width = 31;
            cvs.Height = 31;
            cvs.chIndex = chIndex;
            cvs.sensorType = SENSOR_TYPE_R;
            cvs.direction = SENSOR_DIRECTION_BOTTOM;
            cvs.target = SENSOR_TARGET_UNDER_KANAGATA;

            Image img = new Image();
            img.Source = (BitmapImage)this.Resources["image_sensor_r_normal_bottom"];
            img.Height = 31;
            img.Width = 31;

            cvs.sensorImage = img;
            cvs.Children.Add(img);

            TextBlock txt = new TextBlock();
            txt.Text = this.sensorNumberLabelItems[cvs.chIndex];
            txt.FontSize = FONT_SIZE;
            txt.Background = Brushes.White;
            Canvas.SetTop(txt, 2);
            Canvas.SetLeft(txt, 2);

            cvs.Children.Add(txt);

            this.sensorList[chIndex] = cvs;

            //this.drawNormalSensorR(cvs);

            cvs.MouseLeftButtonDown += new MouseButtonEventHandler(sensor_MouseLeftButtonDown);
            cvs.MouseLeftButtonUp += new MouseButtonEventHandler(sensor_MouseLeftButtonUp);

            return cvs;
        }
        /// <summary>
        /// 通常状態のRセンサ描画
        /// </summary>
        /// <param name="sensorCvs"></param>
        /// <returns></returns>
        private CanvasSensor drawNormalSensorR(CanvasSensor sensorCvs)
        {
            switch (sensorCvs.direction)
            {
                case (SENSOR_DIRECTION_BOTTOM):
                    Canvas.SetTop(sensorCvs.Children[1], 2);
                    Canvas.SetLeft(sensorCvs.Children[1], 2);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_normal_bottom"];
                    break;
                case (SENSOR_DIRECTION_LEFT):
                    Canvas.SetTop(sensorCvs.Children[1], 2);
                    Canvas.SetLeft(sensorCvs.Children[1], 18);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_normal_left"];
                    break;
                case (SENSOR_DIRECTION_RIGHT):
                    Canvas.SetTop(sensorCvs.Children[1], 18);
                    Canvas.SetLeft(sensorCvs.Children[1], 2);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_normal_right"];
                    break;
                case (SENSOR_DIRECTION_TOP):
                    Canvas.SetTop(sensorCvs.Children[1], 18);
                    Canvas.SetLeft(sensorCvs.Children[1], 18);
                    sensorCvs.sensorImage.Source = (BitmapImage)this.Resources["image_sensor_r_normal_top"];
                    break;
            }

            #region Old Code Program Rendering
            //sensorCvs.Children.Clear();
            //Rectangle rect = new Rectangle();
            //rect.Fill = Brushes.Transparent;
            //rect.Width = 31;
            //rect.Height = 31;
            //sensorCvs.Children.Add(rect);

            //Line ln1 = new Line();
            //Line ln2 = new Line();
            //Line ln3 = new Line();
            //Line ln4 = new Line();
            //ln1.Stroke = Brushes.Black;
            //ln1.StrokeThickness = 3;
            //ln2.Stroke = Brushes.Black;
            //ln2.StrokeThickness = 3;
            //ln3.Stroke = Brushes.Black;
            //ln3.StrokeThickness = 3;
            //ln4.Stroke = Brushes.Black;
            //ln4.StrokeThickness = 3;

            //switch (sensorCvs.direction)
            //{
            //    case (SENSOR_DIRECTION_TOP):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 0;

            //        ln2.X1 = 16;
            //        ln2.Y1 = 0;
            //        ln2.X2 = 16;
            //        ln2.Y2 = 31;

            //        ln3.X1 = 27;
            //        ln3.Y1 = 13;
            //        ln3.X2 = 16;
            //        ln3.Y2 = 0;

            //        ln4.X1 = 4;
            //        ln4.Y1 = 16;
            //        ln4.X2 = 16;
            //        ln4.Y2 = 0;

            //        break;
            //    case (SENSOR_DIRECTION_BOTTOM):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 31;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 16;
            //        ln2.Y1 = 0;
            //        ln2.X2 = 16;
            //        ln2.Y2 = 31;

            //        ln3.X1 = 4;
            //        ln3.Y1 = 16;
            //        ln3.X2 = 16;
            //        ln3.Y2 = 31;

            //        ln4.X1 = 27;
            //        ln4.Y1 = 13;
            //        ln4.X2 = 16;
            //        ln4.Y2 = 31;

            //        break;
            //    case (SENSOR_DIRECTION_LEFT):
            //        ln1.X1 = 0;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 0;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 0;
            //        ln2.Y1 = 16;
            //        ln2.X2 = 31;
            //        ln2.Y2 = 16;

            //        ln3.X1 = 16;
            //        ln3.Y1 = 4;
            //        ln3.X2 = 0;
            //        ln3.Y2 = 16;

            //        ln4.X1 = 19;
            //        ln4.Y1 = 27;
            //        ln4.X2 = 0;
            //        ln4.Y2 = 16;

            //        break;
            //    case (SENSOR_DIRECTION_RIGHT):
            //        ln1.X1 = 31;
            //        ln1.Y1 = 0;
            //        ln1.X2 = 31;
            //        ln1.Y2 = 31;

            //        ln2.X1 = 0;
            //        ln2.Y1 = 16;
            //        ln2.X2 = 31;
            //        ln2.Y2 = 16;

            //        ln3.X1 = 16;
            //        ln3.Y1 = 27;
            //        ln3.X2 = 31;
            //        ln3.Y2 = 16;

            //        ln4.X1 = 13;
            //        ln4.Y1 = 4;
            //        ln4.X2 = 31;
            //        ln4.Y2 = 16;

            //        break;
            //}
            //sensorCvs.Children.Add(ln1);
            //sensorCvs.Children.Add(ln2);
            //sensorCvs.Children.Add(ln3);
            //sensorCvs.Children.Add(ln4);

            #endregion

            return sensorCvs;
        }
        /// <summary>
        /// 選択状態Bセンサの描画
        /// </summary>
        /// <param name="sensorCvs"></param>
        /// <returns></returns>
        private CanvasSensor activeSensorB(CanvasSensor sensorCvs)
        {
            this.activeSensorCanvas = sensorCvs;
            //this.locationSetting.setSelectSetting(sensorCvs.chIndex);

            for (int i = 0; i < this.sensorList.Count; i++)
            {
                if (this.sensorList[i] != null && this.sensorList[i].chIndex != sensorCvs.chIndex)
                {
                    if (this.sensorList[i].sensorType == SENSOR_TYPE_R)
                    {
                        this.drawNormalSensorR(this.sensorList[i]);
                    }
                    else if (this.sensorList[i].sensorType == SENSOR_TYPE_B)
                    {
                        this.drawNormalSensorB(this.sensorList[i]);
                    }
                }
            }
            SolidColorBrush fillBrush = new SolidColorBrush();
            fillBrush.Color = this.activeSensorColor;

            sensorCvs.Children.Clear();
            Ellipse ellipse = new Ellipse();
            ellipse.Fill = fillBrush;
            ellipse.Width = 31;
            ellipse.Height = 31;
            sensorCvs.Children.Add(ellipse);

            Line ln1 = new Line();
            ln1.Stroke = Brushes.White;
            ln1.X1 = 16;
            ln1.Y1 = 0;

            ln1.X2 = 16;
            ln1.Y2 = 31;
            sensorCvs.Children.Add(ln1);

            Line ln2 = new Line();
            ln2.Stroke = Brushes.White;
            ln2.X1 = 0;
            ln2.Y1 = 16;

            ln2.X2 = 31;
            ln2.Y2 = 16;
            sensorCvs.Children.Add(ln2);

            TextBlock txt = new TextBlock();
            txt.Text = this.sensorNumberLabelItems[sensorCvs.chIndex];
            txt.FontSize = FONT_SIZE;
            txt.Background = Brushes.White;
            Canvas.SetLeft(txt, 2);

            sensorCvs.Children.Add(txt);

            return sensorCvs;
        }
        /// <summary>
        /// 通常状態Bセンサの描画
        /// </summary>
        /// <param name="sensorCvs"></param>
        /// <returns></returns>
        private CanvasSensor drawNormalSensorB(CanvasSensor sensorCvs)
        {
            Ellipse ellipse = new Ellipse();
            ellipse.Fill = Brushes.Black;
            ellipse.Width = 31;
            ellipse.Height = 31;
            sensorCvs.Children.Add(ellipse);

            Line ln1 = new Line();
            ln1.Stroke = Brushes.White;
            ln1.X1 = 16;
            ln1.Y1 = 0;

            ln1.X2 = 16;
            ln1.Y2 = 31;
            sensorCvs.Children.Add(ln1);

            Line ln2 = new Line();
            ln2.Stroke = Brushes.White;
            ln2.X1 = 0;
            ln2.Y1 = 16;

            ln2.X2 = 31;
            ln2.Y2 = 16;
            sensorCvs.Children.Add(ln2);

            TextBlock txt = new TextBlock();
            txt.Text = this.sensorNumberLabelItems[sensorCvs.chIndex];
            txt.FontSize = FONT_SIZE;
            txt.Background = Brushes.White;
            Canvas.SetLeft(txt, 2);

            sensorCvs.Children.Add(txt);

            return sensorCvs;
        }
        /// <summary>
        /// 新規Bセンサ描画
        /// </summary>
        /// <param name="chIndex"></param>
        /// <returns></returns>
        private CanvasSensor newSensorB(int chIndex)
        {
            CanvasSensor cvs = new CanvasSensor();
            cvs.Width = 31;
            cvs.Height = 31;
            cvs.chIndex = chIndex;
            cvs.sensorType = SENSOR_TYPE_B;

            this.sensorList[chIndex] = cvs;

            this.drawNormalSensorB(cvs);

            cvs.MouseLeftButtonDown += new MouseButtonEventHandler(sensor_MouseLeftButtonDown);
            cvs.MouseLeftButtonUp += new MouseButtonEventHandler(sensor_MouseLeftButtonUp);

            return cvs;
        }
        /// <summary>
        /// センサ左マウスダウンイベント
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void sensor_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Console.WriteLine("Sensor Mouse Down!!");

            if (this.locationSetting.IsCurrentCellInEditMode)
            {
                this.locationSetting.BringToFront();
                return;
            }

            this.isDragging = true;
            CanvasSensor clickedCanvasSensor = (CanvasSensor)sender;
            this.activeSensorCanvas = (CanvasSensor)sender;

            this.locationSetting.setSelectSetting(clickedCanvasSensor.chIndex);

            if (clickedCanvasSensor.sensorType == SENSOR_TYPE_B)
            {
                this.activeSensorB(clickedCanvasSensor);
            }
            else if (clickedCanvasSensor.sensorType == SENSOR_TYPE_R)
            {
                this.activeSensorR(clickedCanvasSensor);
            }

            this.currentMousePoint = e.GetPosition(this.cvsBase);
            //this.dragSensorPaddingPointX = e.GetPosition(this.activeSensorCanvas).X;
            //this.dragSensorPaddingPointY = e.GetPosition(this.activeSensorCanvas).Y;

            this.locationSetting.setSensorNumber(clickedCanvasSensor.chIndex);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sensor"></param>
        private void setSensorContextMenu(CanvasSensor sensor)
        {
            ContextMenu menu = new ContextMenu();
            CustomMenuItem item = new CustomMenuItem();
            item.Name = "";
            item.Header = "測定対象設定";
            item.sensor = sensor;
            item.PreviewMouseDown += new MouseButtonEventHandler(sensorContextMenuItem_MouseDown);

            menu.Items.Add(item);


            sensor.ContextMenu = menu;
        }