/// <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;
        }
Ejemplo n.º 2
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
            }
        }