private void ProcessTileList(string savePath, string tileListId) { try { // read the tile settings string tileSettingsFile = savePath + "\\TilingSettings"; FileStream fsreader = new FileStream(tileSettingsFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryFormatter formatter = new BinaryFormatter(); TileSettings tileSettings = (TileSettings)formatter.Deserialize(fsreader); fsreader.Close(); // read tile list for generation from file string tileDataFile = savePath + "\\TilingList" + tileListId; BinaryReader bsreader = new BinaryReader(File.Open(tileDataFile, FileMode.Open)); try { while (true) { GenerateTile(tileSettings.startX, tileSettings.startY, tileSettings.initTileGap, tileSettings.imageSize, tileSettings.imageBuffer, tileSettings.savePath, bsreader.ReadInt32(), bsreader.ReadInt32(), bsreader.ReadInt32(), tileSettings.imageFormat); } } catch (Exception) // need to find nicer way to do this { bsreader.Close(); } // when process is complete delete the list input File.Delete(tileDataFile); } catch (Exception ex) { ExceptionDump(ex); } }
/// <summary> /// Removes a specified tileSettings object from list /// </summary> /// <param name="fileName">The TileSettings.settingsName string to remove</param> public void RemoveTilePreset(string name) { TileSettings toDeleteRef = null; foreach (TileSettings tileSettings in tileSettingsArray) { if (tileSettings.settingsName == name) { toDeleteRef = tileSettings; } } tileSettingsArray.Remove(toDeleteRef); }
/// <summary> /// Add the specified tileSettings object to list /// </summary> /// <param name="fileName">The TileSettings object to add</param> public void AddToTilePreset(TileSettings tileSettings) { tileSettingsArray.Add(tileSettings); }
// saves the currently loaded tile settings and updates loadedSettings private void SaveTileSettings(string name, bool newConfig) { foreach (TileSettings tileSettings in mainForm.settings.tileSettingsArray) { if (tileSettings.settingsName == name) { // form input variables int processes; int depth; int imageSize; int imageBuffer; string imageFormat; string savePath; bool overwrite; bool snapWorld; numTiles = 0; numTestTiles = 0; processes = Convert.ToInt32(cmbProcesses.Text); // number of parallel processes depth = Convert.ToInt32(cmbLevels.Text); // number of tile levels imageSize = Convert.ToInt32(cmbImageSize.Text); // pixels if (cmbImageBuffer.Text == "Off") { imageBuffer = 0; // pixels } else { imageBuffer = Convert.ToInt32(cmbImageBuffer.Text); // pixels } imageFormat = cmbImageFormat.Text; // image save format savePath = txtSavePath.Text; // location to save generated tiles if (cmbOverwrite.SelectedIndex == 0) { overwrite = true; } else { overwrite = false; } if (cmbSnapWorld.SelectedIndex == 0) { snapWorld = true; } else { snapWorld = false; } // 0/0/0 tile variables double startPointX; double startPointY; if (snapWorld) { startPointX = worldSnapMinX; startPointY = worldSnapMinY; } else { startPointX = map.extent.minx; startPointY = map.extent.miny; } // inital distance between tiles, for level 0 is max meters - min meters double initGap; if (snapWorld) { initGap = Math.Abs(worldSnapMinX - worldSnapMaxX); } else { if ((map.extent.maxx - map.extent.minx) > (map.extent.maxy - map.extent.miny)) { initGap = map.extent.maxx - map.extent.minx; } else { initGap = map.extent.maxy - map.extent.miny; } } // meta-buffer to fix labeling as a multiplier double buffer = 1 + ((double)imageBuffer / (double)imageSize); tileSettings.depth = depth; tileSettings.imageBuffer = imageBuffer; tileSettings.imageFormat = imageFormat; tileSettings.imageSize = imageSize; tileSettings.overwrite = overwrite; tileSettings.processes = processes; tileSettings.savePath = savePath; tileSettings.snapWorld = snapWorld; if (newConfig) { tileSettings.startX = startPointX; tileSettings.startY = startPointY; tileSettings.initTileGap = initGap; } loadedSettings = tileSettings; } } }
private void cmbPreConfig_SelectedIndexChanged(object sender, EventArgs e) { if (cmbPreConfig.Text == "< unsaved settings >") { loadedSettings = null; btnDeleteConfig.Enabled = false; btnGenerateTiles.Enabled = false; btnBaseLayerText.Enabled = false; cmbSnapWorld.Enabled = true; txtPreMinX.Text = ""; txtPreMinY.Text = ""; txtPreMaxX.Text = ""; txtPreMaxY.Text = ""; } else { btnDeleteConfig.Enabled = true; btnGenerateTiles.Enabled = true; btnBaseLayerText.Enabled = true; cmbSnapWorld.Enabled = false; foreach (TileSettings tileSettings in mainForm.settings.tileSettingsArray) { if (tileSettings.settingsName == cmbPreConfig.Text) { txtPreMinX.Text = tileSettings.startX.ToString(); txtPreMinY.Text = tileSettings.startY.ToString(); txtPreMaxX.Text = (Convert.ToDouble(txtPreMinX.Text) + tileSettings.initTileGap).ToString(); txtPreMaxY.Text = (Convert.ToDouble(txtPreMinY.Text) + tileSettings.initTileGap).ToString(); cmbProcesses.SelectedIndex = tileSettings.processes - 1; cmbLevels.SelectedIndex = tileSettings.depth - 1; if (tileSettings.overwrite) { cmbOverwrite.SelectedIndex = 0; } else { cmbOverwrite.SelectedIndex = 1; } if (tileSettings.snapWorld) { cmbSnapWorld.SelectedIndex = 0; } else { cmbSnapWorld.SelectedIndex = 1; } if (tileSettings.imageBuffer == 0) cmbImageBuffer.SelectedIndex = 0; if (tileSettings.imageBuffer == 25) cmbImageBuffer.SelectedIndex = 1; if (tileSettings.imageBuffer == 50) cmbImageBuffer.SelectedIndex = 2; if (tileSettings.imageBuffer == 100) cmbImageBuffer.SelectedIndex = 3; if (tileSettings.imageFormat == "png") cmbImageFormat.SelectedIndex = 0; if (tileSettings.imageFormat == "jpg") cmbImageFormat.SelectedIndex = 1; if (tileSettings.imageSize == 256) cmbImageSize.SelectedIndex = 0; txtSavePath.Text = tileSettings.savePath; loadedSettings = tileSettings; } } } if (loaded) UpdatePreview(); if (loaded) UpdateTable(); }