private void button_Click(object sender, EventArgs e) { //Preiminary Checks //Have we set textures? if (string.IsNullOrEmpty(ballast_file)) { ballast_file = ("Ballast"); ballast_texture = (launchpath + "\\Textures\\ballast.png"); } if (string.IsNullOrEmpty(sleeper_file)) { sleeper_file = ("Sleeper"); sleeper_texture = (launchpath + "\\Textures\\sleeper.png"); } if (string.IsNullOrEmpty(embankment_file)) { embankment_file = ("GrassSeit"); embankment_texture = (launchpath + "\\Textures\\GrassSeit.png"); } if (string.IsNullOrEmpty(railside_file)) { railside_file = ("railSide"); railside_texture = (launchpath + "\\Textures\\railSide.png"); } if (string.IsNullOrEmpty(railtop_file)) { railtop_file = ("railTop"); railtop_texture = (launchpath + "\\Textures\\railTop.png"); } if (string.IsNullOrEmpty(platform_file)) { platform_file = ("platformsurface"); platform_texture = (launchpath + "\\Textures\\platformsurface.png"); } if (string.IsNullOrEmpty(fence_file)) { fence_file = ("fence_18"); fence_texture = (launchpath + "\\Textures\\fence_18.png"); } if (string.IsNullOrEmpty(arch_file)) { arch_file = ("viaduct1"); arch_texture = (launchpath + "\\Textures\\viaduct1.png"); } if (string.IsNullOrEmpty(topwall_file)) { topwall_file = ("viaduct2"); topwall_texture = (launchpath + "\\Textures\\viaduct2.png"); } if (string.IsNullOrEmpty(footwalk_file)) { footwalk_file = ("viaduct3"); footwalk_texture = (launchpath + "\\Textures\\viaduct3.png"); } if (string.IsNullOrEmpty(archis_file)) { archis_file = ("viaduct4"); archis_texture = (launchpath + "\\Textures\\viaduct4.png"); } if (string.IsNullOrEmpty(viaductfence_file)) { viaductfence_file = ("viaduct8"); viaductfence_texture = (launchpath + "\\Textures\\viaduct8.png"); } if (string.IsNullOrEmpty(steel_file)) { steel_file = ("viaduct7"); steel_texture = (launchpath + "\\Textures\\viaduct7.png"); } if (string.IsNullOrEmpty(black_file)) { black_file = ("black"); black_texture = (launchpath + "\\Textures\\black.png"); } spez_file = "SchieneSpez"; spez_texture = (launchpath + "\\Textures\\SchieneSpez.png"); spezanf_file = "SchieneSpezAnf"; spezanf_texture = (launchpath + "\\Textures\\SchieneSpezAnf.png"); motor_file = "WeichAntrieb"; motor_texture = (launchpath + "\\Textures\\WeichAntrieb.png"); EingabeOK = double.TryParse(trackgauge_inp.Text, out trackgauge); if (EingabeOK == false) { MessageBox.Show("Invalid Track Gauge!"); return; } else { //Is the track gauge standard? if (trackgauge != 1.44) { gaugeoffset = ((trackgauge - 1.44) / 2); } else { gaugeoffset = 0; } } if (richTextBox1.TextLength == 0) { MessageBox.Show("Please select a valid path!"); return; } else { path = richTextBox1.Text; if (!System.IO.Directory.Exists(path)) { MessageBox.Show("Please select a valid path!"); } } //Set texture format if (!pngtextures1.Checked) { texture_format = ("bmp"); } else { texture_format = ("png"); } //Check if the entered path exists var pathExists = System.IO.Directory.Exists(richTextBox1.Text); if (!pathExists) { MessageBox.Show("Path does not exist."); return; } if ((MainTabs.SelectedTab.TabIndex == 0 && noembankment1.Checked) || (MainTabs.SelectedTab.TabIndex == 1 && noembankment2.Checked)) { noembankment = true; } else { noembankment = false; } if ((MainTabs.SelectedTab.TabIndex == 0 && invertexture.Checked) || (MainTabs.SelectedTab.TabIndex == 1 && invertextures1.Checked)) { inverttextures = true; } else { inverttextures = false; } if ((MainTabs.SelectedTab.TabIndex == 0 && notexturerails.Checked) || (MainTabs.SelectedTab.TabIndex == 1 && notexturerails1.Checked)) { norailtexture = true; } else { norailtexture = false; } try { //Create Switch if (MainTabs.SelectedTab.TabIndex == 0) { EingabeOK = double.TryParse(textBox_radius.Text, out radius); if (EingabeOK == false) { MessageBox.Show(Resources.invalidradius); return; } EingabeOK = Int32.TryParse(textBox_segmente.Text, out segmente); if (EingabeOK == false) { MessageBox.Show(Resources.invalidsegements); return; } if (addpointmotor.Checked) { pointmotor = true; } else { pointmotor = false; } //Check secondary deviation is a valid number EingabeOK = double.TryParse(textBox_tot.Text, out Abw_tot); if (EingabeOK == false) { MessageBox.Show(Resources.invaliddeviation); return; } //Check length is a valid number //TODO: Check length is no more than 200m EingabeOK = int.TryParse(textBox_laenge.Text, out laenge); if (EingabeOK == false) { MessageBox.Show(Resources.invalidlength); return; } //Check Z-Movement is valid EingabeOK = int.TryParse(textBox_z.Text, out zmovement); if (EingabeOK == false) { MessageBox.Show(Resources.invalidzmovement); return; } Switch.BuildSwitch(); } //Create Curve if (MainTabs.SelectedTab.TabIndex == 1) { EingabeOK = double.TryParse(textBox_radius_curve.Text, out radius); if (EingabeOK == false) { MessageBox.Show(Resources.invalidradius); return; } if (radius != 0) { EingabeOK = Int32.TryParse(textBox_segmente_curve.Text, out segmente); if (EingabeOK == false) { MessageBox.Show(Resources.invalidsegements); return; } //Check radius if ((radius <= 49) && (radius >= -49)) { MessageBox.Show("Radius should be greater than 50m!"); return; } CurvedTrack.BuildCurve(); } else { StraightTrack.BuildStraight(); } } //Create Platform if (MainTabs.SelectedTab.TabIndex == 2) { EingabeOK = double.TryParse(textBox_radius_platform.Text, out radius); if (EingabeOK == false) { MessageBox.Show(Resources.invalidradius); return; } //Check radius if ((radius != 0) && (radius <= 49) && (radius >= -49)) { MessageBox.Show("Radius for platforms should either be 0 for Straight or greater than 50m!"); return; } EingabeOK = Int32.TryParse(textBox_segmente_platform.Text, out segmente); if (EingabeOK == false) { MessageBox.Show(Resources.invalidsegements); return; } //Check platform widths are valid numbers EingabeOK = double.TryParse(textBox_platwidth_near.Text, out platwidth_near); if (EingabeOK == false) { MessageBox.Show(Resources.invalidwidth_n); return; } EingabeOK = double.TryParse(textBox_platwidth_far.Text, out platwidth_far); if (EingabeOK == false) { MessageBox.Show(Resources.invalidwidth_f); return; } //Check platform height is a valid number EingabeOK = double.TryParse(textBox_platheight.Text, out platheight); if (EingabeOK == false) { MessageBox.Show(Resources.invalidplatformheight); return; } //Parse fence height into number if (fence_yes.Checked == true) { EingabeOK = double.TryParse(fenceheight_tb.Text, out fenceheight); if (EingabeOK == false) { MessageBox.Show(Resources.invalidfenceheight); return; } if (fenceheight == 0) { MessageBox.Show("Fence Height should not be zero!"); return; } hasfence = true; } else { hasfence = false; } //Define L/R & RU/RD if (radioButton5.Checked == true) { if (radioButton7.Checked == true) { CurrentPlatformType = PlatformType.LeftLevel; } else if (radioButton8.Checked == true) { CurrentPlatformType = PlatformType.LeftRU; } else { CurrentPlatformType = PlatformType.LeftRD; } } else if (radioButton6.Checked == true) { if (radioButton7.Checked == true) { CurrentPlatformType = PlatformType.RightLevel; } else if (radioButton8.Checked == true) { CurrentPlatformType = PlatformType.RightRU; } else { CurrentPlatformType = PlatformType.RightRD; } } else { MessageBox.Show("Please select a left or right-sided platform!"); return; } Platforms.BuildPlatform(); } //Create Viaduct if (MainTabs.SelectedTab.TabIndex == 3) { EingabeOK = double.TryParse(viaductradius.Text, out radius); if (EingabeOK == false) { MessageBox.Show(Resources.invalidradius); return; } //Check radius if ((radius != 0) && (radius <= 49) && (radius >= -49)) { MessageBox.Show("Radius for viaducts should either be 0 for Straight or greater than 50m!"); return; } EingabeOK = double.TryParse(pierheight.Text, out additionalpierheight); if (EingabeOK == false) { MessageBox.Show(Resources.invalidpierheight); return; } EingabeOK = int.TryParse(tracks.Text, out numberoftracks); if (EingabeOK == false || numberoftracks <= 0) { MessageBox.Show(Resources.invalidtracks); return; } if (StoneType.Checked) { Viaducts.BuildViaduct(); } else { Viaducts.BuildSteelViaduct(); } } } //No write permission error! catch (UnauthorizedAccessException) { MessageBox.Show("You do not have write permission to the selected path."); return; } }