Ejemplo n.º 1
0
        public void CreateConfigFile(Config config)
        {
            XDocument xdoc = new XDocument();
            xdoc.Declaration = new XDeclaration("1.0", "utf-8", "no");

            XElement root = new XElement("Config");

            XElement element = new XElement("Map");
            element.SetAttributeValue("ShowGrid", config.ShowMapGrid ?? "On");
            element.SetAttributeValue("BottomAxes", config.BottomAxes ?? "CD");
            element.SetAttributeValue("MDInverse", config.MDInverse);
            element.SetAttributeValue("CDInverse", config.CDInverse);
            element.SetAttributeValue("BackgroundColor", config.BackgroundColor ?? "#FFFFFF");
            element.SetAttributeValue("GridColor", config.GridColor ?? "#AFAFAF");
            element.SetAttributeValue("XPrecision", config.XPrecision);
            element.SetAttributeValue("YPrecision", config.YPrecision);
            element.SetAttributeValue("ScrollingRange", config.ScrollingRange ?? "");
            root.Add(element);

            foreach (var item in config.Legends)
            {
                XElement el = new XElement("Legend");
                el.SetAttributeValue("ClassID", item.ClassID);
                el.SetAttributeValue("Name", item.Name);
                el.SetAttributeValue("Color", item.Color);
                el.SetAttributeValue("Shape", item.Shape);
                root.Add(el);
            }
            xdoc.Add(root);
            if (!Directory.Exists(_xmlDirectory))
            {
                Directory.CreateDirectory(_xmlDirectory);
            }
            xdoc.Save(_xmlPath);
        }
Ejemplo n.º 2
0
        public Config GetConfigFile()
        {
            // Check config exist
            if (!Directory.Exists(_xmlDirectory) || !File.Exists(_xmlPath))
            {
                return new Config() {
                    BackgroundColor = "#FFFFFF",
                    GridColor = "#AFAFAF",
                    XPrecision = "0",
                    YPrecision = "0",
                    Legends = new List<Legend>()
                };
            }

            Config config = new Config() { Legends = new List<Legend>() };

            XDocument xdoc = XDocument.Load(_xmlPath);

            // Get map setting
            XElement xmlMap = xdoc.Root.Elements("Map").FirstOrDefault();
            config.ShowMapGrid = xmlMap.Attribute("ShowGrid").Value;
            config.BottomAxes = xmlMap.Attribute("BottomAxes").Value;
            config.MDInverse = Convert.ToBoolean(xmlMap.Attribute("MDInverse").Value);
            config.CDInverse = Convert.ToBoolean(xmlMap.Attribute("CDInverse").Value);
            config.BackgroundColor = xmlMap.Attribute("BackgroundColor") == null ? "#FFFFFF" : xmlMap.Attribute("BackgroundColor").Value;
            config.GridColor = xmlMap.Attribute("GridColor") == null ? "#AFAFAF" : xmlMap.Attribute("GridColor").Value;
            config.XPrecision = xmlMap.Attribute("XPrecision") == null ? "0" : xmlMap.Attribute("XPrecision").Value;
            config.YPrecision = xmlMap.Attribute("YPrecision") == null ? "0" : xmlMap.Attribute("YPrecision").Value;
            config.ScrollingRange = xmlMap.Attribute("ScrollingRange") == null ? "" : xmlMap.Attribute("ScrollingRange").Value;

            // Get legend setting
            foreach (var legend in xdoc.Root.Elements("Legend"))
            {
                config.Legends.Add(new Legend()
                {
                    ClassID = legend.Attribute("ClassID").Value,
                    Name = legend.Attribute("Name").Value,
                    Color = legend.Attribute("Color").Value,
                    Shape = legend.Attribute("Shape").Value
                });
            }
            return config;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 建構子
        /// </summary>
        /// <param name="legends"></param>
        public Settings(Config config)
        {
            InitializeComponent();

            cmbShowMapGrid.SelectedItem = config.ShowMapGrid;
            cmbBottomAxes.SelectedItem = config.BottomAxes;
            chkMDInverse.Checked = config.MDInverse;
            chkCDInverse.Checked = config.CDInverse;
            lblBackgroundColor.BackColor = System.Drawing.ColorTranslator.FromHtml(config.BackgroundColor);
            lblGridColor.BackColor = System.Drawing.ColorTranslator.FromHtml(config.GridColor);
            txtXPrecision.Text = config.XPrecision;
            txtYPrecision.Text = config.YPrecision;
            txtScrollingRange.Text = config.ScrollingRange;

            // Initialize DataGridView
            List<Column> columns = new List<Column>();
            Column classId = new Column(0, "ClassID", 60);
            Column name = new Column(1, "Name", 120);
            Column color = new Column(2, "Color", 80);
            Column shape = new Column(3, "Shape", 80);
            columns.Add(classId);
            columns.Add(name);
            columns.Add(color);
            columns.Add(shape);
            foreach (Column c in columns)
            {
                if (c.Name == "Shape")
                {
                    DataGridViewComboBoxColumn cmbShape = new DataGridViewComboBoxColumn();
                    cmbShape.HeaderText = c.Name;
                    cmbShape.DisplayIndex = c.Index;
                    cmbShape.DataPropertyName = c.Name;
                    cmbShape.Width = c.Width;
                    cmbShape.DataSource = new BindingSource(shapes, null);
                    cmbShape.DisplayMember = "Value";
                    cmbShape.ValueMember = "Key";
                    dgvFlawLegends.Columns.Add(cmbShape);
                }
                else
                {
                    DataGridViewCell cell = new DataGridViewTextBoxCell();
                    DataGridViewColumn column = new DataGridViewColumn();
                    column.CellTemplate = cell;
                    column.Name = c.Name;
                    column.HeaderText = c.Name;
                    column.Width = c.Width;
                    column.DataPropertyName = c.Name;
                    column.SortMode = DataGridViewColumnSortMode.Automatic;
                    if (c.Name == "ClassID" || c.Name == "Name" || c.Name == "Color")
                    {
                        column.ReadOnly = true;
                    }
                    dgvFlawLegends.Columns.Add(column);
                }
            }
            dgvFlawLegends.MultiSelect = false;
            dgvFlawLegends.AutoGenerateColumns = false;

            // Load legends
            _legends = config.Legends;
            dgvFlawLegends.DataSource = _legends;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 開啟設定視窗 設定 Map 相關參數
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSetting_Click(object sender, EventArgs e)
        {
            // Read XML
            ConfigHelper ch = new ConfigHelper();
            _config = ch.GetConfigFile();

            Settings setting = new Settings(_config);
            setting.ShowDialog();

            if (chartControl.Series.Count > 0)
            {
                chartControl.Series.Clear();
                // Add each legend to chart
                foreach (var legend in _config.Legends)
                {
                    Series series = new Series(legend.Name, ViewType.Point);
                    series.ArgumentScaleType = ScaleType.Numerical;
                    series.ArgumentDataMember = "CD";
                    series.ValueScaleType = ScaleType.Numerical;
                    series.ValueDataMembers.AddRange(new string[] { "MD" });
                    series.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False;

                    PointSeriesView seriesView = (PointSeriesView)series.View;
                    seriesView.PointMarkerOptions.Size = 15;
                    seriesView.PointMarkerOptions.Kind = _dicSeriesShape[legend.Shape];
                    seriesView.Color = System.Drawing.ColorTranslator.FromHtml(legend.Color);

                    chartControl.Series.Add(series);
                }

                foreach (Series series in chartControl.Series)
                {
                    series.DataSource = QueryDataTable(_flawData, "FlawClass = '" + series.Name + "'", ""); ;
                }

                SetScrollingRange();
            }
        }
Ejemplo n.º 5
0
        public void OnSetFlawLegend(List<FlawLegend> legend)
        {
            ConfigHelper ch = new ConfigHelper();
            Config configFile = ch.GetConfigFile();
            Config newConfig = new Config() { Legends = new List<NMap.Model.Legend>() };

            List<NMap.Model.Legend> mcsLegends = new List<NMap.Model.Legend>();
            foreach (var item in legend)
            {
                NMap.Model.Legend l = new NMap.Model.Legend();
                l.ClassID = item.ClassID.ToString();
                l.Color = String.Format("#{0:X2}{1:X2}{2:X2}",
                              ColorTranslator.FromWin32((int)item.Color).R,
                              ColorTranslator.FromWin32((int)item.Color).G,
                              ColorTranslator.FromWin32((int)item.Color).B);
                l.Shape = "Circle";
                l.Name = item.Name;
                l.OriginLegend = item;
                mcsLegends.Add(l);
            }

            // Compare legends in config file and mcs file
            if (configFile.Legends.Count() != 0)
            {
                if (configFile.Legends.Count() == mcsLegends.Count())
                {
                    int i = 0;
                    foreach (var item in mcsLegends)
                    {
                        configFile.Legends[i].ClassID = item.ClassID;
                        configFile.Legends[i].Name = item.Name;
                        i++;
                    }
                }
                else if (configFile.Legends.Count() > mcsLegends.Count())
                {
                    int i = 0;
                    foreach (var item in mcsLegends)
                    {
                        configFile.Legends[i].ClassID = item.ClassID;
                        configFile.Legends[i].Name = item.Name;
                        i++;
                    }
                    configFile.Legends.RemoveRange(i, configFile.Legends.Count() - i);
                }
                else
                {
                    int i = 0;
                    int legendQuantity = configFile.Legends.Count();
                    foreach (var item in mcsLegends)
                    {
                        if (legendQuantity > i)
                        {
                            configFile.Legends[i].ClassID = item.ClassID;
                            configFile.Legends[i].Name = item.Name;
                        }
                        else
                        {
                            configFile.Legends.Add(item);
                        }
                        i++;
                    }
                }
            }
            else
            {
                configFile.Legends = mcsLegends;
            }

            // Reset config
            ch.CreateConfigFile(configFile);
        }
Ejemplo n.º 6
0
        public void OnJobStarted(int jobKey)
        {
            //btnSetting.Enabled = false;
            JobHelper.JobKey = jobKey;

            // Get config from xml file
            ConfigHelper ch = new ConfigHelper();
            _config = ch.GetConfigFile();
            InitialChart();

            // Add each legend to chart
            foreach (var legend in _config.Legends)
            {
                Series series = new Series(legend.Name, ViewType.Point);
                series.ArgumentScaleType = ScaleType.Numerical;
                series.ArgumentDataMember = "CD";
                series.ValueScaleType = ScaleType.Numerical;
                series.ValueDataMembers.AddRange(new string[] { "MD" });
                series.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False;

                PointSeriesView seriesView = (PointSeriesView)series.View;
                seriesView.PointMarkerOptions.Size = 15;
                seriesView.PointMarkerOptions.Kind = _dicSeriesShape[legend.Shape];
                seriesView.Color = System.Drawing.ColorTranslator.FromHtml(legend.Color);

                chartControl.Series.Add(series);
            }
        }