/// <summary> /// Converts a value. /// </summary> /// <returns> /// A converted value. If the method returns null, the valid null value is used. /// </returns> /// <param name="value">The value produced by the binding source.</param><param name="targetType">The type of the binding target property.</param><param name="parameter">The converter parameter to use.</param><param name="culture">The culture to use in the converter.</param> public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string styleName = value as string; if (styleName != null && cache.ContainsKey(styleName)) return cache[styleName]; RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(70, 50, 96, 96, PixelFormats.Pbgra32); if (styleName == null) return renderTargetBitmap; Style style = new Style(styleName); if (mol.Molecules.Count == 0) { // Load mol string data = (new StreamReader(Application.GetResourceStream(new Uri("pack://application:,,,/NuGenBioChem;component/Resources/Molecules/Preview.mol")).Stream)).ReadToEnd(); mol.Molecules.Add(Molefile.Parse(data)); // Load pdb data = (new StreamReader(Application.GetResourceStream(new Uri("pack://application:,,,/NuGenBioChem;component/Resources/Molecules/Preview.pdb")).Stream)).ReadToEnd(); ProteinDataBankFile pdbImporter = new ProteinDataBankFile(data.Split(new string[]{"\r\n"}, StringSplitOptions.None)); pdb.Molecules.Add(pdbImporter.Molecules[0]); } visualizer.Substance = IsProteinVisible(style) ? pdb : mol; visualizer.SubstanceStyle = style; visualizer.CreatePreview(renderTargetBitmap); cache.Add(styleName, renderTargetBitmap); return renderTargetBitmap; }
// Opens file with the given path void Open(string path) { IFileImporter importer; string extension = Path.GetExtension(path).ToLowerInvariant(); if (extension == ".pdb" || extension == ".ent" || extension == ".brk") importer = new ProteinDataBankFile(path); else if (extension == ".mol" || extension == ".mdl" || extension == ".sd" || extension == ".sdf") importer = new Molefile(path); else throw new NotSupportedException(); // Apply appropriate style if (importer.Molecules.Count > 0 && importer.Molecules[0].Chains.Count > 0) style.LoadCartoonDeafult(); else style.LoadBallAndStickDeafult(); substance.Molecules.Clear(); substance.Molecules.AddRange(importer.Molecules); visualizer.ShowAll(); printTab.Visualizer.ShowAll(); publishTab.Visualizer.ShowAll(); // Change application title string[] splitted = Title.Split(new string[] { " - " }, StringSplitOptions.None); string applicationTitle = splitted[splitted.Length - 1]; Title = Path.GetFileNameWithoutExtension(path) + " - " + applicationTitle; // Add opened file to recent files Settings.AddRecentFile(path); // Reset transaction context to clear all undo/redo transactionContext.Reset(); fileName = Path.GetFullPath(path); }