private bool SaveOrSaveAs(bool saveAs) { L3dFilePath p; if (saveAs || L3dFilePath.IsNullOrEmpty(CurrentFile.OwnPath)) { p = DialogHelpers.SaveLoksimFile(CurrentFile.OwnPath, FileExtensionForSaveAs, SAVEAS_DLG_GUID); } else { p = CurrentFile.OwnPath; } try { if (p != null) { CurrentFile.SaveToFile(p); return(true); } } catch (Exception ex) { MessageBox.Show(String.Format(CultureInfo.CurrentCulture, Resources.Strings.FileSaveError, CurrentFile.OwnPath, ex.Message), Resources.Strings.AppName, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } return(false); }
protected LoksimFile() { _filePicture = new L3dFilePath(); _fileDoku = new L3dFilePath(); _fileAuthor = Settings.RegistrySettings.Default.DefaultFileAuthor; _fileInfo = Settings.RegistrySettings.Default.DefaultFileInfo; }
private void ValidateCurrentPath() { BindingExpression bindingExpression = BindingOperations.GetBindingExpression(tbPath, AutoCompleteBox.IsEnabledProperty); if (L3dFilePath.IsNullOrEmpty(_curPath)) { //ctrl.TbText = string.Empty; tbPath.Text = string.Empty; Validation.ClearInvalid(bindingExpression); } else { //ctrl.TbText = newPath.PathRelativeToParentFile; tbPath.Text = _curPath.PathRelativeToParentFile; if (_curPath.Exists) { Validation.ClearInvalid(bindingExpression); } else { ValidationError validationError = new ValidationError(new ExceptionValidationRule(), bindingExpression); validationError.ErrorContent = String.Format(Loksim3D.WetterEdit.Resources.Strings.File_0_NotFound, _curPath.PathRelativeToL3dDir); Validation.MarkInvalid(bindingExpression, validationError); } } }
protected override XDocument SaveToXmlDocument(XElement rootPropsElement, L3dFilePath filePath) { XElement root = new XElement(FileDescriptions.FILE_WEATHER_EL_ROOT); if (!string.IsNullOrWhiteSpace(_header)) { rootPropsElement.SetAttributeValue(FileDescriptions.FILE_WEATHER_AT_PROPS_HEADER, _header); root.Add(rootPropsElement); } root.Add(Illumination.ConvertToXml()); foreach (var w in WeatherSet) { foreach (var t in w.AllTextures.Where(el => el != null)) { t._texture.ParentFile = filePath; } } root.Add(new XElement(FileDescriptions.FILE_WEATHER_EL_WEATHER_SET, WeatherSet.Select(w => w.ConvertToXml(filePath) ))); return(new XDocument(root)); }
private void SetFilePicSource(L3dFilePath file) { try { BitmapImage b = new BitmapImage(); // BitmapImage.UriSource must be in a BeginInit/EndInit block b.BeginInit(); b.UriSource = new Uri(file.AbsolutePath); //b.CacheOption = BitmapCacheOption.OnLoad; // To save significant application memory, set the DecodePixelWidth or // DecodePixelHeight of the BitmapImage value of the image source to the desired // height or width of the rendered image. If you don't do this, the application will // cache the image as though it were rendered as its normal size rather then just // the size that is displayed. // Note: In order to preserve aspect ratio, set DecodePixelWidth // or DecodePixelHeight but not both. b.DecodePixelWidth = 512; b.CacheOption = BitmapCacheOption.OnLoad; b.EndInit(); FilePicture = b; } catch (Exception) { } }
/// <summary> /// Datei zur Liste zuletzt verwendeter Dateien hinzufügen /// <br>Falls Datei bereits in Liste vorhanden ist, wird sie vorgereiht</br> /// </summary> /// <param name="filePath">Dateipfad</param> public void AddRecentFile(L3dFilePath filePath) { if (_recentFiles == null) { LoadRecentFiles(); } for (int i = 0; i < _recentFiles.Count; i++) { if (_recentFiles[i].Equals(filePath)) { _recentFiles.RemoveAt(i); break; } } _recentFiles.Insert(0, filePath); if (_recentFiles.Count > 10) { _recentFiles.RemoveAt(10); } using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Loksim-Group\WetterEdit\Recent File List")) { if (key != null) { for (int i = 0; i < _recentFiles.Count; i++) { key.SetValue("File" + (i + 1), _recentFiles[i].AbsolutePath); } } } }
/// <summary> /// Speichert die Datei ab /// </summary> /// <param name="saveToFile">Dateipfad</param> public void SaveToFile(L3dFilePath outputPath) { if (OwnPath != outputPath && !L3dFilePath.IsNullOrEmpty(FilePicture)) { try { string newPath = Path.Combine(outputPath.Directory, outputPath.Filename + ".jpg"); File.Copy(FilePicture.AbsolutePath, newPath); FilePicture = new L3dFilePath(newPath); } catch (Exception) { FilePicture = new L3dFilePath(); } } XDocument xDoc = SaveToXmlDocument(GetRootPropsElement(outputPath), outputPath); string output = GetOutputString(xDoc); string tmpFile = TempFileUtility.GetTempFileName("tmp", 0, outputPath.Directory); if (File.Exists(outputPath.AbsolutePath)) { xDoc.Save(tmpFile); File.Replace(tmpFile, outputPath.AbsolutePath, null); } else { File.Delete(tmpFile); xDoc.Save(outputPath.AbsolutePath); } _lastSavedDoc = output; OwnPath = outputPath; }
/// <summary> /// Liefert XElement mit den "allgemeinen" Daten /// </summary> /// <param name="saveToFile">Pfad in welche Datei gespeichert wird (wichtig für relativen Pfad des FilePictures)</param> /// <returns>Erzeugtes XElement</returns> protected XElement GetRootPropsElement(L3dFilePath saveToFile) { return(new XElement(FileDescriptions.FILE_GENERAL_EL_PROPS, new XAttribute(FileDescriptions.FILE_GENERAL_AT_AUTHOR, FileAuthor ?? ""), new XAttribute(FileDescriptions.FILE_GENERAL_AT_INFO, FileInfo ?? ""), new XAttribute(FileDescriptions.FILE_GENERAL_AT_PICTURE, FilePicture.GetPathRelativeToFile(saveToFile)), new XAttribute(FileDescriptions.FILE_GENERAL_AT_DOKU, FileDoku.GetPathRelativeToFile(saveToFile)))); }
public XElement ConvertToXml(L3dFilePath ownerPath = null) { return(new XElement(FileDescriptions.FILE_SKY_EL_WEATHER, new XElement(FileDescriptions.FILE_SKY_EL_WEATHER_PROPS, new XAttribute(FileDescriptions.FILE_SKY_AT_WEATHER_PROBABILITY, Probability), new XAttribute(FileDescriptions.FILE_SKY_AT_WEATHER_FILE, WeatherFile != null ? WeatherFile.GetPathRelativeToFile(ownerPath) : string.Empty) ) )); }
private void Button_Click(object sender, RoutedEventArgs e) { string p = DialogHelpers.OpenLoksimFile(FilePath, FileDialogFilters, null); if (!string.IsNullOrEmpty(p)) { FilePath = L3dFilePath.CreateRelativeToFile(p, FilePath != null ? FilePath.ParentFile : null); } }
private static void OnTbTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { string newTxt = e.NewValue as string; FilePathControl ctrl = (FilePathControl)d; if (ctrl.FilePath == null || ctrl.FilePath.PathRelativeToParentFile != newTxt) { ctrl.FilePath = L3dFilePath.CreateRelativeToFile(newTxt, ctrl.FilePath != null ? ctrl.FilePath.ParentFile : null); } }
/// <summary> /// Zeigt Datei-Speichern Dialog an /// </summary> /// <param name="selectedFile">Zurzeit gewählte Datei (kann null sein)</param> /// <param name="fileExtensions">Dateiendungen</param> /// <param name="guid">GUID für FileDialog (Vista+ relevant; OS merkt sich pro GUID wo der Dialog das letzte Mal geöffnet war)</param> /// <returns>Gewählte Datei oder null</returns> public static L3dFilePath SaveLoksimFile(L3dFilePath selectedFile, IEnumerable <CommonFileDialogFilter> fileExtensions, Guid guid = default(Guid)) { if (CommonSaveFileDialog.IsPlatformSupported) { using (CommonSaveFileDialog dlg = new CommonSaveFileDialog("Loksim3D")) { if (selectedFile != null) { dlg.InitialDirectory = selectedFile.Directory; dlg.DefaultFileName = selectedFile.Filename; } if (Directory.Exists(L3dFilePath.LoksimDirectory.AbsolutePath)) { dlg.AddPlace(L3dFilePath.LoksimDirectory.AbsolutePath, Microsoft.WindowsAPICodePack.Shell.FileDialogAddPlaceLocation.Bottom); dlg.ShowPlacesList = true; } dlg.CookieIdentifier = guid; if (fileExtensions != null) { foreach (CommonFileDialogFilter f in fileExtensions) { dlg.Filters.Add(f); } dlg.DefaultExtension = "." + dlg.Filters[0].Extensions[0]; } if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { return(new L3dFilePath(dlg.FileName)); } } } else { SaveFileDialog dlg = new SaveFileDialog(); if (selectedFile != null) { dlg.FileName = selectedFile.Filename; } dlg.Title = "Loksim3D"; if (selectedFile != null) { dlg.InitialDirectory = selectedFile.Directory; } if (fileExtensions != null) { dlg.Filter = FileExtensions.CommonDlgFilterToClassicFilter(fileExtensions); dlg.DefaultExt = "." + fileExtensions.First().Extensions[0]; } if (dlg.ShowDialog().GetValueOrDefault(false)) { return(new L3dFilePath(dlg.FileName)); } } return(null); }
public static Weather ReadFromXml(string xmlEl, IUndoManager undoManager, L3dFilePath ownerPath = null) { try { return(ReadFromXml(XElement.Parse(xmlEl), undoManager, ownerPath)); } catch (XmlException) { } return(null); }
private static void OnFilePathChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { L3dFilePath newPath = e.NewValue as L3dFilePath; FilePathControl ctrl = (FilePathControl)d; if (!L3dFilePath.Equals(newPath, ctrl._curPath)) { ctrl._curPath = newPath; ctrl.ValidateCurrentPath(); } }
void tbPath_TextChanged(object sender, RoutedEventArgs e) { string newTxt = tbPath.Text; if (_curPath == null || _curPath.PathRelativeToParentFile != newTxt) { _curPath = L3dFilePath.CreateRelativeToFile(newTxt, _curPath != null ? _curPath.ParentFile : null); if (newTxt != "\\") { ValidateCurrentPath(); } } }
public DrivingCabFile() { //TODO nur zum debuggen Schleudern = new OnOffGauge(this); Sanden = new OnOffGauge(this); Bitmap = L3dFilePath.CreateRelativeToL3dDir(@"\Lok\Diesel-Loks\BR 218\UPeters\BR 218 822-5.bmp"); Schleudern.OnPosition.X = 10; Schleudern.OnPosition.Y = 20; Schleudern.OffPosition.X = 100; Schleudern.OffPosition.Y = 200; Schleudern.Dimension.Width = 1000; Schleudern.Dimension.Height = 2000; }
protected override XDocument SaveToXmlDocument(XElement rootPropsElement, L3dFilePath filePath) { XElement root = new XElement(FileDescriptions.FILE_SKY_EL_ROOT); root.Add(rootPropsElement); foreach (var w in WeatherSets.Where(el => el.WeatherFile != null)) { w.WeatherFile.ParentFile = filePath; } root.Add(new XElement(FileDescriptions.FILE_SKY_EL_WEATHER_SETS, WeatherSets.Select(w => w.ConvertToXml(OwnPath)))); return(new XDocument(root)); }
public WeatherTimeRange(IUndoManager undoManager, L3dFilePath parentFile = null) : base(undoManager) { _sightDistance = 10000; _brightnessFactor = 1.0f; _variables = new UndoAwareObservableCollection <L3dVariable>(undoManager); _textures = new List <TextureEntry>(5); for (int i = 0; i < 5; i++) { TextureEntry en = new TextureEntry(); en._texture = L3dFilePath.CreateRelativeToFile(string.Empty, parentFile); en._tileU = 1; en._tileV = 1; _textures.Add(en); } }
public static Weather ReadFromXml(XElement xmlEl, IUndoManager undoManager, L3dFilePath ownerPath = null) { if (xmlEl != null && xmlEl.Name == FileDescriptions.FILE_SKY_EL_WEATHER) { XElement props = xmlEl.Element(FileDescriptions.FILE_SKY_EL_WEATHER_PROPS); if (props != null) { Weather w = new Weather(undoManager); w._propability = props.Attribute(FileDescriptions.FILE_SKY_AT_WEATHER_PROBABILITY).Read <int>(1); w._weatherFile = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_SKY_AT_WEATHER_FILE).Read <string>(), ownerPath); return(w); } } return(null); }
/// <summary> /// Lädt Daten in diese Instanz von der angegebenen Datei /// </summary> /// <param name="path">Dateipfad</param> public void LoadFromFile(L3dFilePath path) { if (!L3dFilePath.IsNullOrEmpty(path)) { XDocument doc = XDocument.Load(path.AbsolutePath); XElement props = doc.Elements().First().Element(FileDescriptions.FILE_GENERAL_EL_PROPS); if (props != null) { FileAuthor = props.Attribute(FileDescriptions.FILE_GENERAL_AT_AUTHOR).Read <string>(); FileInfo = props.Attribute(FileDescriptions.FILE_GENERAL_AT_INFO).Read <string>(); FilePicture = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_GENERAL_AT_PICTURE).Read <string>(), path); FileDoku = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_GENERAL_AT_DOKU).Read <string>(), path); } OwnPath = path; LoadFromDoc(doc); _lastSavedDoc = GetOutputString(SaveToXmlDocument(GetRootPropsElement(OwnPath), OwnPath)); } }
void tbPath_Populating(object sender, PopulatingEventArgs e) { L3dFilePath parentFile = _curPath.ParentFile; string startDir; if (L3dFilePath.IsNullOrEmpty(parentFile) || e.Parameter.StartsWith("\\")) { startDir = L3dFilePath.LoksimDirectory.AbsolutePath; } else { startDir = parentFile.Directory; } startDir = startDir + System.IO.Path.DirectorySeparatorChar + e.Parameter; if (!string.IsNullOrEmpty(startDir)) { string dir = System.IO.Path.GetDirectoryName(startDir); if (Directory.Exists(dir)) { string file = System.IO.Path.GetFileName(startDir); var res = Directory.EnumerateDirectories(dir, file + "*").Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile); if (_possibleExtensions.Count() == 0) { res = res.Union(Directory.EnumerateFiles(dir, file + "*").Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile)); } else { foreach (var ext in _possibleExtensions) { res = res.Union(Directory.EnumerateFiles(dir, file + "*." + ext).Select(p => L3dFilePath.CreateRelativeToFile(p, parentFile).PathRelativeToParentFile)); } } tbPath.ItemsSource = res.Take(15); } else { tbPath.ItemsSource = Enumerable.Empty <string>(); } } }
public XElement ConvertToXml(L3dFilePath ownerPath = null) { var elem = new XElement(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE, new XElement(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PROPS, new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BEGIN, Begin.TotalSeconds), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_END, End.TotalSeconds), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BRIGHTNESS_FACTOR, BrightnessFactor), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SIGHT_DISTANCE, SightDistance) ), Variables.Select(v => new XElement(FileDescriptions.File_WEATHER_EL_TIME_RANGE_VARIABLE, new XAttribute(FileDescriptions.File_WEATHER_AT_TIME_RANGE_VARIABLE_NAME, v.Name), v.Value) ), new XElement(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX, new XElement(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX_TEXTURES, new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH, TextureNorth != null ? TextureNorth.GetPathRelativeToFile(ownerPath) : string.Empty), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST, TextureEast != null ? TextureEast.GetPathRelativeToFile(ownerPath) : string.Empty), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH, TextureSouth != null ? TextureSouth.GetPathRelativeToFile(ownerPath) : string.Empty), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST, TextureWest != null ? TextureWest.GetPathRelativeToFile(ownerPath) : string.Empty), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE, TextureNorth != null ? TextureAbove.GetPathRelativeToFile(ownerPath) : string.Empty), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_U, TextureNorthTileU), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_V, TextureNorthTileV), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_U, TextureEastTileU), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_V, TextureEastTileV), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_U, TextureSouthTileU), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_V, TextureSouthTileV), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_U, TextureWestTileU), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_V, TextureWestTileV), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_U, TextureAboveTileU), new XAttribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_V, TextureAboveTileV) )) ); if (_snowfall) { elem.Add(new XElement(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION, new XAttribute(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION_TYPE, 1))); } return(elem); }
public Weather(IUndoManager undoManager, L3dFilePath weatherFile) : base(undoManager) { _weatherFile = weatherFile; _propability = 1; }
public static AmbientIllumination ReadFromXml(XElement xmlEl, IUndoManager undoManager, L3dFilePath ownerPath = null) { if (xmlEl != null && xmlEl.Name == FileDescriptions.FILE_WEATHER_EL_ILLUMINATION) { XElement illuminationProps = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_ILLUMINATION_PROPS); if (illuminationProps != null) { AmbientIllumination ill = new AmbientIllumination(undoManager); ill._brightnessDay = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_BRIGHTNESS_DAY).Read <float>(1.0f); ill._brightnessNight = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_BRIGHTNESS_NIGHT).Read <float>(0.0f); ill._dawnBegin = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_DAWN_BEGIN).ReadTime(new TimeSpan(3, 0, 0)); ill._dawnEnd = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_DAWN_END).ReadTime(new TimeSpan(6, 0, 0)); ill._duskBegin = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_DUSK_BEGIN).ReadTime(new TimeSpan(17, 0, 0)); ill._duskEnd = illuminationProps.Attribute(FileDescriptions.FILE_WEATHER_AT_ILLUMINATION_DUSK_END).ReadTime(new TimeSpan(23, 0, 0)); return(ill); } } return(null); }
public static WeatherTimeRange ReadFromXml(XElement xmlEl, IUndoManager undoManager, L3dFilePath ownerPath = null) { if (xmlEl != null && xmlEl.Name == FileDescriptions.FILE_WEATHER_EL_TIME_RANGE) { XElement props = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PROPS); if (props != null) { WeatherTimeRange t = new WeatherTimeRange(undoManager, ownerPath); using (var tk = undoManager.EnterNoUndoSection()) { t._begin = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BEGIN).ReadTime(); t._end = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_END).ReadTime(); t._brightnessFactor = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_BRIGHTNESS_FACTOR).Read <float>(1.0f); t._sightDistance = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SIGHT_DISTANCE).Read <int>(6000); foreach (L3dVariable v in xmlEl.Elements(FileDescriptions.File_WEATHER_EL_TIME_RANGE_VARIABLE).Select(el => { return(new L3dVariable(undoManager) { Name = el.Attribute(FileDescriptions.File_WEATHER_AT_TIME_RANGE_VARIABLE_NAME).Read <string>("UnnamedVar"), Value = el.Value }); })) { t.Variables.Add(v); } XElement skybox = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX); if (skybox != null) { props = skybox.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_SKYBOX_TEXTURES); if (props != null) { t.TextureNorth = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH).Read <string>(string.Empty), ownerPath); t.TextureEast = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST).Read <string>(string.Empty), ownerPath); t.TextureSouth = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH).Read <string>(string.Empty), ownerPath); t.TextureWest = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST).Read <string>(string.Empty), ownerPath); t.TextureAbove = L3dFilePath.CreateRelativeToFile(props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE).Read <string>(string.Empty), ownerPath); t.TextureNorthTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_U).Read <float>(0); t.TextureNorthTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURENORTH_TILE_V).Read <float>(0); t.TextureEastTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_U).Read <float>(0); t.TextureEastTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREEAST_TILE_V).Read <float>(0); t.TextureSouthTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_U).Read <float>(0); t.TextureSouthTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTURESOUTH_TILE_V).Read <float>(0); t.TextureWestTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_U).Read <float>(0); t.TextureWestTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREWEST_TILE_V).Read <float>(0); t.TextureAboveTileU = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_U).Read <float>(0); t.TextureAboveTileV = props.Attribute(FileDescriptions.FILE_WEATHER_AT_TIME_RANGE_SKYBOX_TEXTUREABOVE_TILE_V).Read <float>(0); } } XElement xmlPreci = xmlEl.Element(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION); if (xmlPreci != null) { t._snowfall = xmlPreci.Attribute(FileDescriptions.FILE_WEATHER_EL_TIME_RANGE_PRECIPITATION_TYPE).Read <int>(0) == 1; } return(t); } } } return(null); }
public FilePropertiesViewModel(LoksimFile file, Window parentWindow) { _fileAuthor = file.FileAuthor; _fileInfo = file.FileInfo; _fileDoku = file.FileDoku; _parentWindow = parentWindow; if (!L3dFilePath.IsNullOrEmpty(file.FilePicture)) { SetFilePicSource(file.FilePicture); } OtherPictureCmd = new RelayCommand(obj => { string s = DialogHelpers.OpenLoksimFile(file.FilePicture.AbsolutePath, FileExtensions.ImageFiles, _parentWindow); if (!string.IsNullOrEmpty(s)) { L3dFilePath p = new L3dFilePath(s); RemovePictureCmd.Execute(null); Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { SetFilePicSource(p); }), System.Windows.Threading.DispatcherPriority.Background); } }, obj => { return(!L3dFilePath.IsNullOrEmpty(file.OwnPath)); }); PictureFromClipboardCmd = new RelayCommand(obj => { if (Clipboard.ContainsImage()) { FilePicture = Clipboard.GetImage(); } }, obj => { return(Clipboard.ContainsImage() && !L3dFilePath.IsNullOrEmpty(file.OwnPath)); }); RemovePictureCmd = new RelayCommand(obj => { FilePicture = null; }, obj => { return(FilePicture != null); }); OkCmd = new RelayCommand(obj => { file.FileAuthor = FileAuthor; file.FileInfo = FileInfo; file.FileDoku = FileDoku; try { if (_picChanged) { if (_filePicture != null) { Image bmp = null; JpegBitmapEncoder enc = new JpegBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(_filePicture)); using (System.IO.MemoryStream memStream = new System.IO.MemoryStream()) { enc.Save(memStream); bmp = new Bitmap(memStream); } using (Image img = ImageHelper.ScaleBitmap(bmp, 512, 512)) { file.FilePicture = new L3dFilePath(file.OwnPath.AbsolutePath + ".jpg"); img.Save(file.FilePicture.AbsolutePath, System.Drawing.Imaging.ImageFormat.Jpeg); } bmp.Dispose(); } else { file.FilePicture = null; } } FilePicture = null; } catch (Exception ex) { Debug.WriteLine(ex); } if (RequestClose != null) { RequestClose(true); } }, obj => { return(true); }); CancelCmd = new RelayCommand(obj => { if (RequestClose != null) { RequestClose(false); } }, obj => { return(true); }); _picChanged = false; }
protected override System.Xml.Linq.XDocument SaveToXmlDocument(System.Xml.Linq.XElement rootPropsElement, L3dFilePath filePath) { throw new NotImplementedException(); }
protected BaseL3dFileViewModel(LoksimFile openFile, Window parentWindow) { CurrentFile = openFile; ParentWindow = parentWindow; _fileSaveCmd = new RelayCommand(obj => { SaveOrSaveAs(false); }, obj => { return(CurrentFile != null && !L3dFilePath.IsNullOrEmpty(CurrentFile.OwnPath)); } ); _fileSaveAsCmd = new RelayCommand(obj => { SaveOrSaveAs(true); }, obj => { return(CurrentFile != null); } ); FilePropertiesCmd = new RelayCommand(obj => { Window dlg = new FilePropertiesWindow(CurrentFile); dlg.Owner = ParentWindow; dlg.ShowDialog(); }, obj => { return(CurrentFile != null); } ); UndoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Undo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.UndoPossible); } ); RedoCmd = new RelayCommand(obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; if (f != null) { f.Redo(); } }, obj => { UndoAwareFile f = CurrentFile as UndoAwareFile; return(f != null && f.RedoPossible); } ); }
private void tbPath_LostFocus(object sender, RoutedEventArgs e) { FilePath = _curPath; }
/// <summary> /// Konkrete Klassen implementieren diese Methode um die Datei in die XML-Darstellung umzuwandeln /// </summary> /// <param name="rootPropsElement">XML-Element mit den allgemeinen Eigenschaften (FileAuthor, FileInfo,...)</param> /// <param name="filePath">Pfad in welche Datei gespeichert wird</param> /// <returns>Erzeugtes XDocument mit allen zu speichernden Daten</returns> protected abstract XDocument SaveToXmlDocument(XElement rootPropsElement, L3dFilePath filePath);