示例#1
0
        private Material SetMaterial(PartColors materialColor)
        {
            PartColor pc = KnownPartColors.GetColor(materialColor);

            //SolidColorBrush sb = new SolidColorBrush(color.Color);
            //if (color.Alpha > 0)
            //    sb.Opacity = color.Alpha / 255.0;

            return(new DiffuseMaterial(pc.Color));
        }
示例#2
0
        public static PartColor GetColor(PartColors color)
        {
            PartColor c = null;

            try {
                c = KnownPartColors.Colors[(int)color];
            }
            catch (Exception) {
                c = KnownPartColors.GetColor(PartColors.Black);
            }

            return(c);
        }
示例#3
0
        private static PartColor ParseColor(string line)
        {
            PartColor       c     = new PartColor();
            MatchCollection words = wordsEx.Matches(line);

            for (int i = 1; i < words.Count; i += 2)
            {
                string keyword = words[i].Value.Trim();
                string value   = string.Empty;

                switch (keyword)
                {
                case "!COLOUR":
                    value     = words[i + 1].Value.Trim().Replace("Trans", "Transparent");
                    value     = value.Replace("_", " ");
                    c.Tooltip = value;
                    c.Name    = value.Replace(" ", "");
                    break;

                case "CODE":
                    value  = words[i + 1].Value.Trim();
                    c.Code = Convert.ToInt32(value);
                    break;

                case "VALUE":
                    value = words[i + 1].Value.Trim();
                    System.Drawing.Color color = System.Drawing.ColorTranslator.FromHtml(value);
                    c.Color = new SolidColorBrush(Color.FromRgb(color.R, color.G, color.B));
                    break;

                case "EDGE":
                    value = words[i + 1].Value.Trim();
                    System.Drawing.Color edgeColor = System.Drawing.ColorTranslator.FromHtml(value);
                    c.EdgeColor = Color.FromRgb(edgeColor.R, edgeColor.G, edgeColor.B);
                    break;

                case "ALPHA":
                    value           = words[i + 1].Value.Trim();
                    c.Alpha         = Convert.ToByte(value);
                    c.Color.Opacity = c.Alpha / 255.0;
                    break;

                case "LUMINANCE":
                    value       = words[i + 1].Value.Trim();
                    c.Luminance = Convert.ToByte(value);
                    break;
                }
            }

            return(c);
        }
示例#4
0
        private static void ColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            PartUI s = (PartUI)d;

            if (s.Visual3DModel != null)
            {
                s.PartColor = (PartColors)e.NewValue;
                Model3DGroup    mg  = (Model3DGroup)s.Visual3DModel;
                DiffuseMaterial mat = ((GeometryModel3D)mg.Children[0]).Material as DiffuseMaterial;

                PartColor newColor = KnownPartColors.GetColor(s.PartColor);
                if (mat != null)
                {
                    mat.Brush = newColor.Color;
                }
            }
        }
示例#5
0
        static KnownPartColors()
        {
            if (Colors != null)
            {
                return;
            }

            //string ldconfig_path = System.Configuration.ConfigurationManager.AppSettings["LDRAW"];
            string[] lines = File.ReadAllLines("ldconfig.ldr");
            Colors = new Dictionary <int, PartColor>();

            foreach (string line in lines)
            {
                if (line.StartsWith("0 !COLOUR"))
                {
                    PartColor c = ParseColor(line);
                    Colors.Add(c.Code, c);
                }
            }
        }