/// <summary>
        /// CSVからオブジェクト生成
        /// </summary>
        /// <param name="csv"></param>
        /// <returns></returns>
        public static ItemBean CreateFromCsv(string csv)
        {
            ItemBean item = null;
            AxisBean axis = null;

            string[] fields = CsvUtil.Split(csv);

            if (fields.Count() == dataNum)
            {
                item = new ItemBean();
                axis = new AxisBean();

                item.Id        = int.Parse(fields[0]);
                item.Name      = fields[1];
                item.YAxisMax  = double.Parse(fields[2]);
                item.YAxisMin  = double.Parse(fields[3]);
                item.LineColor = ColorUtil.NameToColor(fields[4]);
                item.LineWidth = double.Parse(fields[5]);
                item.Visible   = bool.Parse(fields[6]);

                axis.Id              = int.Parse(fields[7]);
                axis.Name            = fields[8];
                axis.UnitName        = fields[9];
                axis.AxisMax         = item.YAxisMax;
                axis.AxisMin         = item.YAxisMin;
                axis.GridLineVisible = bool.Parse(fields[10]);
                axis.GridResolution  = double.Parse(fields[11]);
                axis.AxisColor       = ColorUtil.NameToColor(fields[12]);
                axis.DispOrder       = int.Parse(fields[13]);

                item.Axis = axis;
            }

            return(item);
        }
        /// <summary>
        /// CSVからオブジェクト生成
        /// </summary>
        /// <param name="csv"></param>
        /// <returns></returns>
        public static AxisBean CreateFromCsv(string csv)
        {
            AxisBean ret = null;

            string[] fields = CsvUtil.Split(csv);

            if (fields.Count() == fieldNum)
            {
                ret = new AxisBean();

                ret.Id              = int.Parse(fields[0]);
                ret.Name            = fields[1];
                ret.UnitName        = fields[2];
                ret.AdRangeMax      = double.Parse(fields[3]);
                ret.AdRangeMin      = double.Parse(fields[4]);
                ret.AxisMax         = double.Parse(fields[5]);
                ret.AxisMin         = double.Parse(fields[6]);
                ret.GridLineVisible = bool.Parse(fields[7]);
                ret.GridResolution  = double.Parse(fields[8]);
                ret.AxisColor       = ColorUtil.NameToColor(fields[9]);
                ret.DispOrder       = int.Parse(fields[10]);
                ret.IsY2Axis        = bool.Parse(fields[11]);
            }

            return(ret);
        }
        /// <summary>
        /// ファイルからロードしてリスト生成
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static void Load()
        {
            string filePath = FilePath;

            AxisList = new List <AxisBean>();
            FileStream   fs = null;
            StreamReader sr = null;

            try
            {
                if (!File.Exists(filePath))
                {
                    GenerateDefaultList();

                    AccelerationAxis       = AxisList.Find(a => a.Id == (int)AxisIds.Accelerometer);
                    AngularVelocityAxis    = AxisList.Find(a => a.Id == (int)AxisIds.AngularVelocity);
                    ElectrooculographyAxis = AxisList.Find(a => a.Id == (int)AxisIds.Electrooculography);
                    QuaternionAxis         = AxisList.Find(a => a.Id == (int)AxisIds.Quaternion);

                    return;
                }

                // ファイルオープン
                fs = File.OpenRead(filePath);
                sr = new StreamReader(fs);

                while (!sr.EndOfStream)
                {
                    // 読む
                    string rec = sr.ReadLine();

                    // オブジェクトリストに格納
                    AxisBean axis = AxisBean.CreateFromCsv(rec);
                    if (axis != null)
                    {
                        AxisList.Add(axis);
                    }
                }

                AccelerationAxis       = AxisList.Find(a => a.Id == (int)AxisIds.Accelerometer);
                AngularVelocityAxis    = AxisList.Find(a => a.Id == (int)AxisIds.AngularVelocity);
                ElectrooculographyAxis = AxisList.Find(a => a.Id == (int)AxisIds.Electrooculography);
                QuaternionAxis         = AxisList.Find(a => a.Id == (int)AxisIds.Quaternion);
            }
            finally
            {
                // 後始末
                if (sr != null)
                {
                    sr.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
        /// <summary>
        /// 表示フォーマット処理
        /// Colorの背景色変更
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvAxis_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (dgvAxis.Columns[e.ColumnIndex].Name == "color")
            {
                AxisBean axis = (AxisBean)dgvAxis.Rows[e.RowIndex].DataBoundItem;

                e.CellStyle.BackColor          = axis.AxisColor;
                e.CellStyle.SelectionBackColor = axis.AxisColor;
            }
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public ItemMasterBean()
        {
            XAxis = new AxisBean();
            // X軸情報初期化
            XAxis.GridLineVisible = true;
            XAxis.GridResolution  = 60 * 1000;
            XAxis.AxisMin         = 0;
            XAxis.AxisMax         = 900 * 1000;

            ItemList = new List <ItemBean>();
        }
        /// <summary>
        /// itemList中に指定軸を使用中で表示中の項目があればtrue
        /// なければfalse
        /// </summary>
        /// <param name="itemList"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        public static bool IsAxisVisible(List <ItemBean> itemList, AxisBean axis)
        {
            bool isVisible = false;

            for (int i = 0; i < itemList.Count; i++)
            {
                // 軸の取得
                AxisBean a = itemList[i].Axis;

                if (a.Id == axis.Id && itemList[i].Visible)
                {
                    isVisible = true;
                    break;
                }
            }
            return(isVisible);
        }
        /// <summary>
        /// Clone
        /// </summary>
        /// <returns></returns>
        public AxisBean Clone()
        {
            AxisBean ret = new AxisBean();

            ret.Id              = this.Id;
            ret.Name            = this.Name;
            ret.UnitName        = this.UnitName;
            ret.AdRangeMax      = this.AdRangeMax;
            ret.AdRangeMin      = this.AdRangeMin;
            ret.AxisMax         = this.AxisMax;
            ret.AxisMin         = this.AxisMin;
            ret.GridLineVisible = this.GridLineVisible;
            ret.GridResolution  = this.GridResolution;
            ret.AxisColor       = this.AxisColor;
            ret.DispOrder       = this.DispOrder;

            return(ret);
        }
        /// <summary>
        /// 項目リストから軸リストを抽出する
        /// 軸IDと項目のYMax,YMinが異なる軸を抽出する
        /// </summary>
        /// <param name="itemList"></param>
        /// <returns></returns>
        public static List <AxisBean> SelectAxisList(List <ItemBean> itemList)
        {
            List <AxisBean> axisList = new List <AxisBean>();

            foreach (ItemBean item in itemList)
            {
                // 同じデータ種類がなければLISTに追加
                AxisBean axis = axisList.Find(a => a.Id == item.Axis.Id && a.AxisMax == item.YAxisMax && a.AxisMin == item.YAxisMin);
                if (axis == null)
                {
                    AxisBean a = item.Axis;
                    a.AxisMax = item.YAxisMax;
                    a.AxisMin = item.YAxisMin;
                    axisList.Add(a);
                }
            }

            return(axisList);
        }
        /// <summary>
        /// CellClickハンドラ
        /// カラーダイアログを表示し、色設定する
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvAxis_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0)
            {
                return;
            }

            //"Color"列がクリックされた
            if (dgvAxis.Columns[e.ColumnIndex].Name == "color")
            {
                if (colorDialog.ShowDialog(this) == DialogResult.OK)
                {
                    AxisBean axis = (AxisBean)dgvAxis.Rows[e.RowIndex].DataBoundItem;
                    axis.AxisColor = colorDialog.Color;
                    dgvAxis.CommitEdit(DataGridViewDataErrorContexts.Commit);

                    // 編集フラグON
                    HasEdited = true;
                }
            }
        }
        /// <summary>
        /// 下へ移動ボタンクリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void downButton_Click(object sender, EventArgs e)
        {
            if (dgvAxis.SelectedCells.Count <= 0)
            {
                return;
            }

            int rowIndex = dgvAxis.SelectedCells[0].RowIndex;

            if (rowIndex >= dgvAxis.Rows.Count - 1)
            {
                return;
            }

            // Selected Row Data
            DataGridViewRow row  = dgvAxis.Rows[rowIndex];
            AxisBean        axis = row.DataBoundItem as AxisBean;

            // Selected Row - 1 Data
            DataGridViewRow row1  = dgvAxis.Rows[rowIndex + 1];
            AxisBean        axis1 = row1.DataBoundItem as AxisBean;

            if (axis != null && axis1 != null)
            {
                // 表示順をスワップ
                int order  = axis.DispOrder;
                int order1 = axis1.DispOrder;

                axis.DispOrder  = order1;
                axis1.DispOrder = order;
            }

            // ReDisplay
            axisBindingSource  = new BindingSource(AxisMaster.AxisList.OrderBy(d => d.DispOrder), string.Empty);
            dgvAxis.DataSource = axisBindingSource;
            dgvAxis.Rows[rowIndex + 1].Selected = true;

            // 編集フラグON
            HasEdited = true;
        }
        /// <summary>
        /// 軸マスター編集クリック
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void axisMasterMenu_Click(object sender, EventArgs e)
        {
            Tracer.WriteInformation("軸マスター設定メニュークリック");

            try
            {
                AxisMasterForm axisMasterForm = new AxisMasterForm();
                DialogResult   result         = axisMasterForm.ShowDialog();

                //if (axisMasterForm.HasEdited)
                if (result == DialogResult.OK)
                {
                    AxisBean[] axisBeans = new AxisBean[] { chart1Axis, chart2Axis, chart3Axis };

                    for (int i = 0; i < graphViews.Length; i++)
                    {
                        GraphView graphView = graphViews[i];
                        AxisBean  axis      = axisBeans[i];

                        if (graphView != null && axis != null)
                        {
                            graphView.YAxisColorChanged(axis);
                            graphView.YAxisGridChanged(axis);
                            graphView.YAxisNameChanged(axis);
                            graphView.YAxisRangeChanged(axis);
                            graphView.Title = string.Format("Chart{0} : {1} {2}", i + 1, axis.Name, axis.UnitName.Equals("") ? "" : "(" + axis.UnitName + ")");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.WriteException(ex);
                MessageBox.Show(ex.Message, "Graph Control", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 出荷時LIST生成
        /// </summary>
        public static void GenerateDefaultList()
        {
            AxisList = new List <AxisBean>();

            // TODO : 加速度グラフのデフォルト値
            AxisBean axis;

            axis      = new AxisBean();
            axis.Id   = (int)AxisIds.Accelerometer;
            axis.Name = "Accelerometer";

            //axis.UnitName = "m/s^2";
            //axis.AdRangeMax = 10.0;
            //axis.AdRangeMin = -10.0;
            //axis.AxisMax = 10.0;
            //axis.AxisMin = -10.0;
            //axis.GridLineVisible = true;
            //axis.GridResolution = 2;
            //axis.DispOrder = axis.Id;
            //axis.AxisColor = Color.Olive;

            axis.UnitName   = "LSB";
            axis.AdRangeMax = 10.0;
            axis.AdRangeMin = -10.0;
            //axis.AxisMax = 35000.0;
            //axis.AxisMin = -35000.0;
            axis.AxisMax         = 36000.0;
            axis.AxisMin         = -36000.0;
            axis.GridLineVisible = true;
            //axis.GridResolution = 10000;
            axis.GridResolution = 12000;
            axis.DispOrder      = axis.Id;
            //axis.AxisColor = Color.Olive;
            axis.AxisColor = Color.Silver;

            AxisList.Add(axis);

            // TODO : 角速度グラフのデフォルト値
            axis      = new AxisBean();
            axis.Id   = (int)AxisIds.AngularVelocity;
            axis.Name = "Gyroscope";

            //axis.UnitName = "rad/s";
            //axis.AdRangeMax = 10.0;
            //axis.AdRangeMin = -10.0;
            //axis.AxisMax = 10.0;
            //axis.AxisMin = -10.0;
            //axis.GridLineVisible = true;
            //axis.GridResolution = 2;
            //axis.DispOrder = axis.Id;
            //axis.AxisColor = Color.Olive;

            axis.UnitName   = "LSB";
            axis.AdRangeMax = 10.0;
            axis.AdRangeMin = -10.0;
            //axis.AxisMax = 35000.0;
            //axis.AxisMin = -35000.0;
            axis.AxisMax         = 36000.0;
            axis.AxisMin         = -36000.0;
            axis.GridLineVisible = true;
            //axis.GridResolution = 10000;
            axis.GridResolution = 12000;
            axis.DispOrder      = axis.Id;
            //axis.AxisColor = Color.Olive;
            axis.AxisColor = Color.Silver;

            AxisList.Add(axis);

            // TODO : 眼電位グラフのデフォルト値
            axis      = new AxisBean();
            axis.Id   = (int)AxisIds.Electrooculography;
            axis.Name = "Electrooculography";

            //axis.UnitName = "mV";
            //axis.AdRangeMax = 10.0;
            //axis.AdRangeMin = -10.0;
            //axis.AxisMax = 10.0;
            //axis.AxisMin = -10.0;
            //axis.GridLineVisible = true;
            //axis.GridResolution = 2;
            //axis.DispOrder = axis.Id;
            //axis.AxisColor = Color.Olive;

            axis.UnitName   = "LSB";
            axis.AdRangeMax = 10.0;
            axis.AdRangeMin = -10.0;
            //axis.AxisMax = 1000.0;
            //axis.AxisMin = -1000.0;
            axis.AxisMax         = 1200.0;
            axis.AxisMin         = -1200.0;
            axis.GridLineVisible = true;
            //axis.GridResolution = 500;
            axis.GridResolution = 400;
            axis.DispOrder      = axis.Id;
            //axis.AxisColor = Color.Olive;
            axis.AxisColor = Color.Silver;

            AxisList.Add(axis);

            // TODO : クォータニオングラフのデフォルト値
            // TODO : クォータニオンを無効化
            //axis = new AxisBean();
            //axis.Id = (int)AxisIds.Quaternion;
            //axis.Name = "Quaternion";

            ////axis.UnitName = "";
            ////axis.AdRangeMax = 10.0;
            ////axis.AdRangeMin = -10.0;
            ////axis.AxisMax = 10.0;
            ////axis.AxisMin = -10.0;
            ////axis.GridLineVisible = true;
            ////axis.GridResolution = 2;
            ////axis.DispOrder = axis.Id;
            ////axis.AxisColor = Color.Olive;

            //axis.UnitName = "";
            //axis.AdRangeMax = 10.0;
            //axis.AdRangeMin = -10.0;
            //axis.AxisMax = 5000.0;
            //axis.AxisMin = -5000.0;
            //axis.GridLineVisible = true;
            //axis.GridResolution = 2000;
            //axis.DispOrder = axis.Id;
            //axis.AxisColor = Color.Olive;

            //AxisList.Add(axis);
        }
Beispiel #13
0
        /// <summary>
        /// ファイルからロードしてリスト生成
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static void Load()
        {
            string filePath = FilePath;

            ItemPatternList = new List <ItemMasterBean>();
            FileStream   fs = null;
            StreamReader sr = null;

            string[]       fields;
            ItemMasterBean pattern = null;

            try
            {
                AxisMaster.Load();

                if (!File.Exists(filePath))
                {
                    GenerateDefaultList();
                    return;
                }


                // ファイルオープン
                fs = File.OpenRead(filePath);
                sr = new StreamReader(fs);

                string version = string.Empty;

                while (!sr.EndOfStream)
                {
                    // 読む
                    string rec = sr.ReadLine();

                    // アプリケーションバージョン
                    if (rec.Contains("$ApplicationVersion"))
                    {
                        version = rec.Split(new char[] { '=' })[1];
                    }

                    // 項目パターン名称
                    else if (rec.Contains("$ItemPattern"))
                    {
                        // いままでの項目パターンを保存
                        if (pattern != null)
                        {
                            ItemPatternList.Add(pattern);
                        }

                        // 新しい項目パターン生成
                        pattern = new ItemMasterBean();

                        // '='で分割してItemPatternの名称を取り出す
                        fields = rec.Split(new char[] { '=' });

                        pattern.Name = fields[1].Trim();
                    }

                    // X軸情報
                    else if (rec.Contains("$XAxis"))
                    {
                        // '='で分割してITEMのCSVを取り出す
                        fields        = rec.Split(new char[] { '=' });
                        pattern.XAxis = AxisBean.CreateFromCsv(fields[1]);
                    }

                    else
                    {
                        // オブジェクトリストに格納
                        ItemBean item = ItemBean.CreateFromCsv(rec);
                        if (item != null)
                        {
                            // 軸マスター更新されていた時のため、軸をマスターから取り直す
                            AxisBean axis = AxisMaster.AxisList.Find(d => d.Id == item.Axis.Id);
                            item.Axis = axis;

                            pattern.ItemList.Add(item);
                        }
                    }
                }

                if (version.Equals(System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion) == false)
                {
                    // バージョン不一致の為、ファイルを破棄
                    if (File.Exists(filePath))
                    {
                        sr.Close();
                        sr = null;
                        fs.Close();
                        fs = null;
                        File.Delete(filePath);
                    }
                    GenerateDefaultList();
                    return;
                }

                // 最後の項目パターンを保存
                if (pattern != null)
                {
                    ItemPatternList.Add(pattern);
                }

                AccelerationItems       = new List <ItemMasterBean>();
                AngularVelocityItems    = new List <ItemMasterBean>();
                ElectrooculographyItems = new List <ItemMasterBean>();
                // TODO : クォータニオンを無効化
                //QuaternionItems = new List<ItemMasterBean>();
                for (int i = 0; i < 3; i++)
                {
                    AccelerationItems.Add(ItemPatternList.Find(p => p.Name == string.Format("Accelerometer{0}", i)));
                    AngularVelocityItems.Add(ItemPatternList.Find(p => p.Name == string.Format("AngularVelocity{0}", i)));
                    ElectrooculographyItems.Add(ItemPatternList.Find(p => p.Name == string.Format("Electrooculography{0}", i)));
                    // TODO : クォータニオンを無効化
                    //QuaternionItems.Add(ItemPatternList.Find(p => p.Name == string.Format("Quaternion[0]", i)));
                }
            }
            finally
            {
                // 後始末
                if (sr != null)
                {
                    sr.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }