/// <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;
        }
        static bool IsProteinVisible(Style style)
        {
            if (style.GeometryStyle.HelixWidth * style.GeometryStyle.HelixHeight <= 0.01 &&
                style.GeometryStyle.SheetWidth * style.GeometryStyle.SheetHeight <= 0.01 &&
                style.GeometryStyle.TurnWidth * style.GeometryStyle.TurnHeight <= 0.01) return false;

            return true;
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="substance">Substance</param>
        /// <param name="style">Style</param>
        public Render(Substance substance, Style style)
        {
            this.substance = substance;
            this.style = style;
            handle = CreateRender();

            style.ColorStyle.ColorScheme.Invalidated += OnColorSchemeInvalidated;
            style.ColorStyle.Invalidated += OnColorStyleInvalidated;
            style.GeometryStyle.Invalidated += OnGeometryStyleInvalidated;
        }
        /// <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)
        {
            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(48, 48, 96, 96, PixelFormats.Pbgra32);
            Data.Molecule molecule = value as Data.Molecule;
            if (molecule == null) return renderTargetBitmap;

            Dispatcher.CurrentDispatcher.BeginInvoke((Action) delegate
                                                                  {
                                                                      Style style = new Style();
                                                                      if (molecule.Chains.Count > 0)
                                                                          style.LoadCartoonDeafult();
                                                                      else style.LoadBallAndStickDeafult();

                                                                      substance.Molecules.Clear();
                                                                      substance.Molecules.Add(molecule);
                                                                      visualizer.SubstanceStyle = style;
                                                                      visualizer.Substance = substance;
                                                                      visualizer.CreatePreview(renderTargetBitmap);
                                                                  },DispatcherPriority.ApplicationIdle);

            return renderTargetBitmap;
        }
Esempio n. 5
0
        static Style()
        {
            if (Storage.DirectoryExists(StylesStorageDirectoryName))
            {
                string[] files = Storage.GetFileNames(StylesStorageDirectoryName + "\\*");
                for (int i = 0; i < files.Length; i++)
                {
                    Styles.Add(Path.GetFileNameWithoutExtension(files[i]));
                }
            }
            else
            {
                Storage.CreateDirectory(StylesStorageDirectoryName);

                #region Add default styles

                Transaction.Suspend();
                try
                {
                    Style style = new Style();
                    style.LoadBallAndStickDeafult();
                    style.SaveAs("Default");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 1;
                    style.GeometryStyle.BondSize = 0.01;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.VanderWaals;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    style.ColorStyle.ColorScheme.LoadCoreyPaulingKoltunScheme();
                    style.SaveAs("Space-filling");

                    style = new Style();
                    style.LoadCartoonDeafult();
                    style.SaveAs("Cartoon");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 0.8;
                    style.GeometryStyle.BondSize = 0.5;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.Calculated;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    style.ColorStyle.ColorScheme.LoadCoreyPaulingKoltunScheme();
                    style.SaveAs("Ball-and-stick");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 1;
                    style.GeometryStyle.BondSize = 0.6;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.Uniform;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    style.ColorStyle.ColorScheme.LoadCoreyPaulingKoltunScheme();
                    style.SaveAs("Ball-and-stick (Uniform)");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 1.0;
                    style.GeometryStyle.BondSize = 0.5;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.Uniform;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    foreach (Element element in Element.Elements)
                    {
                        style.ColorStyle.ColorScheme[element].Diffuse = Colors.Blue;
                    }
                    style.ColorStyle.UseSingleBondMaterial = true;
                    style.ColorStyle.BondMaterial.Diffuse = Colors.White;
                    style.SaveAs("Blue");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 0.75;
                    style.GeometryStyle.BondSize = 1;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.Uniform;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    style.ColorStyle.ColorScheme.LoadCoreyPaulingKoltunScheme();
                    style.SaveAs("Wireframe");

                    style = new Style();
                    style.GeometryStyle.AtomSize = 0.45;
                    style.GeometryStyle.BondSize = 1;
                    style.GeometryStyle.AtomSizeStyle = AtomSizeStyle.Uniform;
                    style.GeometryStyle.SheetHeight = 0;
                    style.GeometryStyle.HelixHeight = 0;
                    style.GeometryStyle.TurnHeight = 0;
                    style.ColorStyle.ColorScheme.LoadCoreyPaulingKoltunScheme();
                    style.SaveAs("Wireframe (Thin)");
                }
                finally
                {
                    Transaction.Resume();
                }

                #endregion
            }
        }