示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // read definitions and create province lists
            lblStatus.Text = "Load Source Definitions";
            Application.DoEvents();
            string sourceDefPath = Path.Combine(tbSourceMapFolder.Text, "Definition.csv");

            Program.sourceDef = new DefinitionReader(sourceDefPath, PushStatusUpdate);

            lblStatus.Text = "Load Target Definitions";
            Application.DoEvents();
            string targetDefPath = Path.Combine(tbDestMapFolder.Text, "Definition.csv");

            Program.targetDef = new DefinitionReader(targetDefPath, PushStatusUpdate);

            // pre-scale maps
            lblStatus.Text = "Scale Maps";
            PushStatusUpdate(0.0);
            Application.DoEvents();
            string sourceMapPath = Path.Combine(tbSourceMapFolder.Text, "Provinces.bmp");
            Bitmap srcMap        = (Bitmap)Bitmap.FromFile(sourceMapPath);

            PushStatusUpdate(33.0);
            string targetMapPath = Path.Combine(tbDestMapFolder.Text, "Provinces.bmp");
            Bitmap targetMap     = (Bitmap)Bitmap.FromFile(targetMapPath);

            PushStatusUpdate(67.0);
            if (cbScale.Checked)
            {
                int h = Math.Max(srcMap.Height, targetMap.Height);
                int w = Math.Max(srcMap.Width, targetMap.Width);
                if (srcMap.Height < h || srcMap.Width < w)
                {
                    srcMap = Program.CleanResizeBitmap(srcMap, w, h);
                }
                if (targetMap.Height < h || targetMap.Width < w)
                {
                    targetMap = Program.CleanResizeBitmap(targetMap, w, h);
                }
            }
            PushStatusUpdate(100.0);
            srcMap.Tag    = sourceMapPath;
            targetMap.Tag = targetMapPath;

            // add geo data to province lists
            lblStatus.Text = "Load Source Map";
            Application.DoEvents();
            Program.sourceMap = new MapReader(srcMap, Program.sourceDef.provinces, ckInvertSource.Checked, PushStatusUpdate);

            lblStatus.Text = "Load Target Map";
            Application.DoEvents();
            Program.targetMap = new MapReader(targetMap, Program.targetDef.provinces, ckInvertDest.Checked, PushStatusUpdate);

            // load localizations, if desired
            if (cbNamesFrom.SelectedItem.ToString() == "Localization")
            {
                lblStatus.Text = "Load Source Localization";
                Application.DoEvents();
                LocalizationReader lr = new LocalizationReader(tbSourceMapFolder.Text, Program.sourceDef.provinces, PushStatusUpdate);

                lblStatus.Text = "Load Target Localization";
                Application.DoEvents();
                lr = new LocalizationReader(tbDestMapFolder.Text, Program.targetDef.provinces, PushStatusUpdate);
            }

            // read existing mappings (if any)
            string mappingFile = tbMappingsFile.Text.Trim();

            if (mappingFile != String.Empty && File.Exists(mappingFile))
            {
                lblStatus.Text = "Parse Existing Mappings";
                Application.DoEvents();
                Program.mappings = new MappingReader(mappingFile, tbSourceTag.Text,
                                                     tbDestTag.Text, Program.sourceDef.provinces, Program.targetDef.provinces, PushStatusUpdate);
            }
            else
            {
                Program.mappings = new MappingReader(mappingFile, tbSourceTag.Text, tbDestTag.Text);
            }

            // save settings
            Properties.Settings.Default.srcMapFolder  = tbSourceMapFolder.Text;
            Properties.Settings.Default.destMapFolder = tbDestMapFolder.Text;
            Properties.Settings.Default.srcTag        = tbSourceTag.Text;
            Properties.Settings.Default.destTag       = tbDestTag.Text;
            Properties.Settings.Default.mappingFile   = tbMappingsFile.Text;
            Properties.Settings.Default.fitMaps       = cbScale.Checked;
            Properties.Settings.Default.namesFrom     = cbNamesFrom.SelectedItem.ToString();
            Properties.Settings.Default.invertSource  = ckInvertSource.Checked;
            Properties.Settings.Default.invertDest    = ckInvertDest.Checked;
            Properties.Settings.Default.Save();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // read definitions and create province lists
            lblStatus.Text = "Load Source Definitions";
            Application.DoEvents();
            string sourceDefPath = Path.Combine(tbSourceMapFolder.Text, "Definition.csv");
            Program.sourceDef = new DefinitionReader(sourceDefPath, PushStatusUpdate);

            lblStatus.Text = "Load Target Definitions";
            Application.DoEvents();
            string targetDefPath = Path.Combine(tbDestMapFolder.Text, "Definition.csv");
            Program.targetDef = new DefinitionReader(targetDefPath, PushStatusUpdate);

            // pre-scale maps
            lblStatus.Text = "Scale Maps";
            PushStatusUpdate(0.0);
            Application.DoEvents();
            string sourceMapPath = Path.Combine(tbSourceMapFolder.Text, "Provinces.bmp");
            Bitmap srcMap = (Bitmap)Bitmap.FromFile(sourceMapPath);
            PushStatusUpdate(33.0);
            string targetMapPath = Path.Combine(tbDestMapFolder.Text, "Provinces.bmp");
            Bitmap targetMap = (Bitmap)Bitmap.FromFile(targetMapPath);
            PushStatusUpdate(67.0);
            if (cbScale.Checked)
            {
                int h = Math.Max(srcMap.Height, targetMap.Height);
                int w = Math.Max(srcMap.Width, targetMap.Width);
                if (srcMap.Height < h || srcMap.Width < w)
                {
                    srcMap = Program.CleanResizeBitmap(srcMap, w, h);
                }
                if (targetMap.Height < h || targetMap.Width < w)
                {
                    targetMap = Program.CleanResizeBitmap(targetMap, w, h);
                }
            }
            PushStatusUpdate(100.0);
            srcMap.Tag = sourceMapPath;
            targetMap.Tag = targetMapPath;

            // add geo data to province lists
            lblStatus.Text = "Load Source Map";
            Application.DoEvents();
            Program.sourceMap = new MapReader(srcMap, Program.sourceDef.provinces, ckInvertSource.Checked, PushStatusUpdate);

            lblStatus.Text = "Load Target Map";
            Application.DoEvents();
            Program.targetMap = new MapReader(targetMap, Program.targetDef.provinces, ckInvertDest.Checked, PushStatusUpdate);

            // load localizations, if desired
            if (cbNamesFrom.SelectedItem.ToString() == "Localization")
            {
                lblStatus.Text = "Load Source Localization";
                Application.DoEvents();
                LocalizationReader lr = new LocalizationReader(tbSourceMapFolder.Text, Program.sourceDef.provinces, PushStatusUpdate);

                lblStatus.Text = "Load Target Localization";
                Application.DoEvents();
                lr = new LocalizationReader(tbDestMapFolder.Text, Program.targetDef.provinces, PushStatusUpdate);
            }

            // read existing mappings (if any)
            string mappingFile = tbMappingsFile.Text.Trim();
            if (mappingFile != String.Empty && File.Exists(mappingFile))
            {
                lblStatus.Text = "Parse Existing Mappings";
                Application.DoEvents();
                Program.mappings = new MappingReader(mappingFile, tbSourceTag.Text,
                    tbDestTag.Text, Program.sourceDef.provinces, Program.targetDef.provinces, PushStatusUpdate);
            }
            else
            {
                Program.mappings = new MappingReader(mappingFile, tbSourceTag.Text, tbDestTag.Text);
            }

            // save settings
            Properties.Settings.Default.srcMapFolder = tbSourceMapFolder.Text;
            Properties.Settings.Default.destMapFolder = tbDestMapFolder.Text;
            Properties.Settings.Default.srcTag = tbSourceTag.Text;
            Properties.Settings.Default.destTag = tbDestTag.Text;
            Properties.Settings.Default.mappingFile = tbMappingsFile.Text;
            Properties.Settings.Default.fitMaps = cbScale.Checked;
            Properties.Settings.Default.namesFrom = cbNamesFrom.SelectedItem.ToString();
            Properties.Settings.Default.invertSource = ckInvertSource.Checked;
            Properties.Settings.Default.invertDest = ckInvertDest.Checked;
            Properties.Settings.Default.Save();
        }