Ejemplo n.º 1
0
	// Get a brush for a system color.
	public static Brush FromSystemColor(Color c)
			{
				if(c.IsSystemColor)
				{
					return GetOrCreateBrush(c.ToKnownColor());
				}
				else
				{
					throw new ArgumentException(S._("Arg_NotSystemColor"));
				}
			}
        /// <include file='doc\ColorTranslator.uex' path='docs/doc[@for="ColorTranslator.ToHtml"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Translates the specified <see cref='System.Drawing.Color'/> to an Html string color representation.
        ///    </para>
        /// </devdoc>
        public static string ToHtml(Color c)
        {
            var colorString = String.Empty;

            if (c.IsEmpty)
            {
                return(colorString);
            }

            if (c.IsSystemColor)
            {
                switch (c.ToKnownColor())
                {
                case KnownColor.ActiveBorder: colorString = "activeborder"; break;

                case KnownColor.GradientActiveCaption:
                case KnownColor.ActiveCaption: colorString = "activecaption"; break;

                case KnownColor.AppWorkspace: colorString = "appworkspace"; break;

                case KnownColor.Desktop: colorString = "background"; break;

                case KnownColor.Control: colorString = "buttonface"; break;

                case KnownColor.ControlLight: colorString = "buttonface"; break;

                case KnownColor.ControlDark: colorString = "buttonshadow"; break;

                case KnownColor.ControlText: colorString = "buttontext"; break;

                case KnownColor.ActiveCaptionText: colorString = "captiontext"; break;

                case KnownColor.GrayText: colorString = "graytext"; break;

                case KnownColor.HotTrack:
                case KnownColor.Highlight: colorString = "highlight"; break;

                case KnownColor.MenuHighlight:
                case KnownColor.HighlightText: colorString = "highlighttext"; break;

                case KnownColor.InactiveBorder: colorString = "inactiveborder"; break;

                case KnownColor.GradientInactiveCaption:
                case KnownColor.InactiveCaption: colorString = "inactivecaption"; break;

                case KnownColor.InactiveCaptionText: colorString = "inactivecaptiontext"; break;

                case KnownColor.Info: colorString = "infobackground"; break;

                case KnownColor.InfoText: colorString = "infotext"; break;

                case KnownColor.MenuBar:
                case KnownColor.Menu: colorString = "menu"; break;

                case KnownColor.MenuText: colorString = "menutext"; break;

                case KnownColor.ScrollBar: colorString = "scrollbar"; break;

                case KnownColor.ControlDarkDark: colorString = "threeddarkshadow"; break;

                case KnownColor.ControlLightLight: colorString = "buttonhighlight"; break;

                case KnownColor.Window: colorString = "window"; break;

                case KnownColor.WindowFrame: colorString = "windowframe"; break;

                case KnownColor.WindowText: colorString = "windowtext"; break;
                    // Something evil you say?
                }
            }
            else if (c.IsNamedColor)
            {
                if (c == Color.LightGray)
                {
                    // special case due to mismatch between Html and enum spelling
                    colorString = "LightGrey";
                }
                else
                {
                    colorString = c.Name;
                }
            }
            else
            {
                colorString = "#" + c.R.ToString("X2", null) +
                              c.G.ToString("X2", null) +
                              c.B.ToString("X2", null);
            }

            return(colorString);
        }
Ejemplo n.º 3
0
 public void Write(TextWriter writer)
 {
     Console.WriteLine($"Line: {Color.ToKnownColor()}, {Start}, {End}.");
 }
	// Convert a "Color" value into a HTML color name.
	public static String ToHtml(Color color)
			{
				String ret = "";
				int value = (int)(color.ToKnownColor());
				if(color.IsKnownColor)//(value>=1) && (value<=167))
				{
					//int value = (int)(color.ToKnownColor());
					if(value >= 1 && value <= oleSystemColors.Length)
					{
						switch(value)
						{
							case (int)KnownColor.ActiveCaptionText:
								ret = "captiontext";
								break;
							case (int)KnownColor.Control:
								ret = "buttonface";
								break;
							case (int)KnownColor.ControlDark:
								ret = "buttonshadow";
								break;
							case (int)KnownColor.ControlDarkDark:
								ret = "threeddarkshadow";
								break;
							case (int)KnownColor.ControlLight:
								ret = "buttonface";
								break;
							case (int)KnownColor.ControlLightLight:
								ret = "buttonhighlight";
								break;
							case (int)KnownColor.ControlText:
								ret = "buttontext";
								break;
							case (int)KnownColor.Desktop:
								ret = "background";
								break;
							case (int)KnownColor.HotTrack:
								ret = "highlight";
								break;
							case (int)KnownColor.Info:
								ret = "infobackground";
								break;
							//case (int)KnownColor.LightGray: ret = "LightGrey";break; // -> MS BUG.
							// This last case cause a compare error but the good result is
							// LightGray. So, never replace LightGray by LightGrey.
							default:
								ret = color.Name.ToLower();
								break;
						}
					}
					else
					{
						ret = color.Name;
					}
				}
				else if(color.Name != "0")
				{
					ret = "#" + color.Name.Substring(2).ToUpper();
					/// GET R,G,B -> Format to hexa RRGGBB prepend '#'
				}
				return ret;
			}
Ejemplo n.º 5
0
        public void writeKML(string filename)
        {
            try
            {
                writeGPX(filename);

                writeRinex(filename);

                writeWPFile(filename);
            }
            catch
            {
            }

            Color[] colours =
            {
                Color.Red,    Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo,
                Color.Violet, Color.Pink
            };

            AltitudeMode altmode = AltitudeMode.absolute;

            KMLRoot kml  = new KMLRoot();
            Folder  fldr = new Folder("Log");

            Style style = new Style();

            style.Id = "yellowLineGreenPoly";
            style.Add(new LineStyle(HexStringToColor("7f00ffff"), 4));

            Style style1 = new Style();

            style1.Id = "spray";
            style1.Add(new LineStyle(HexStringToColor("4c0000ff"), 0));
            style1.Add(new PolyStyle()
            {
                Color = HexStringToColor("4c0000ff")
            });

            PolyStyle pstyle = new PolyStyle();

            pstyle.Color = HexStringToColor("7f00ff00");
            style.Add(pstyle);

            kml.Document.AddStyle(style);
            kml.Document.AddStyle(style1);

            int stylecode = 0xff;
            int g         = -1;

            foreach (List <Point3D> poslist in position)
            {
                g++;
                if (poslist == null)
                {
                    continue;
                }

                /*
                 * List<PointLatLngAlt> pllalist = new List<PointLatLngAlt>();
                 *
                 * foreach (var point in poslist)
                 * {
                 *  pllalist.Add(new PointLatLngAlt(point.Y, point.X, point.Z, ""));
                 * }
                 *
                 * var ans = Utilities.LineOffset.GetPolygon(pllalist, 2);
                 *
                 *
                 *
                 * while (ans.Count > 0)
                 * {
                 *  var first = ans[0];
                 *  var second = ans[1];
                 *  var secondlast = ans[ans.Count - 2];
                 *  var last = ans[ans.Count-1];
                 *
                 *  ans.Remove(first);
                 *  ans.Remove(last);
                 *
                 *  var polycoords = new BoundaryIs();
                 *
                 *  polycoords.LinearRing = new LinearRing();
                 *
                 *  polycoords.LinearRing.Coordinates.Add(new Point3D(first.Lng, first.Lat, 1));
                 *  polycoords.LinearRing.Coordinates.Add(new Point3D(second.Lng, second.Lat, 1));
                 *  polycoords.LinearRing.Coordinates.Add(new Point3D(secondlast.Lng, secondlast.Lat, 1));
                 *  polycoords.LinearRing.Coordinates.Add(new Point3D(last.Lng, last.Lat, 1));
                 *  polycoords.LinearRing.Coordinates.Add(new Point3D(first.Lng, first.Lat, 1));
                 *
                 *  //if (!IsClockwise(polycoords.LinearRing.Coordinates))
                 *    //  polycoords.LinearRing.Coordinates.Reverse();
                 *
                 *  Polygon kmlpoly = new Polygon() { AltitudeMode = AltitudeMode.relativeToGround, Extrude = false, OuterBoundaryIs = polycoords };
                 *
                 *  Placemark pmpoly = new Placemark();
                 *  pmpoly.Polygon = kmlpoly;
                 *  pmpoly.name = g + " test";
                 *  pmpoly.styleUrl = "#spray";
                 *
                 *  fldr.Add(pmpoly);
                 * }
                 */
                LineString ls = new LineString();
                ls.AltitudeMode = altmode;
                ls.Extrude      = true;
                //ls.Tessellate = true;

                Coordinates coords = new Coordinates();
                coords.AddRange(poslist);

                ls.coordinates = coords;

                Placemark pm = new Placemark();

                string mode = "";
                if (g < modelist.Count)
                {
                    mode = modelist[g];
                }

                pm.name       = g + " Flight Path " + mode;
                pm.styleUrl   = "#yellowLineGreenPoly";
                pm.LineString = ls;

                stylecode = colours[g % (colours.Length - 1)].ToArgb();

                Style style2 = new Style();
                Color color  = Color.FromArgb(0xff, (stylecode >> 16) & 0xff, (stylecode >> 8) & 0xff,
                                              (stylecode >> 0) & 0xff);
                log.Info("colour " + color.ToArgb().ToString("X") + " " + color.ToKnownColor().ToString());
                style2.Add(new LineStyle(color, 4));


                pm.AddStyle(style2);

                fldr.Add(pm);
            }

            Placemark pmPOS = new Placemark();

            pmPOS.name                   = "POS Message";
            pmPOS.LineString             = new LineString();
            pmPOS.LineString.coordinates = new Coordinates();
            Point3D        lastPoint3D = new Point3D();
            PointLatLngAlt lastplla    = PointLatLngAlt.Zero;

            foreach (var item in PosLatLngAlts)
            {
                var newpoint = new Point3D(item.Lng, item.Lat, item.Alt);

                if (item.GetDistance(lastplla) < 0.1 &&
                    lastPoint3D.Z >= (newpoint.Z - 0.3) &&
                    lastPoint3D.Z <= (newpoint.Z + 0.3))
                {
                    continue;
                }

                pmPOS.LineString.coordinates.Add(newpoint);
                lastPoint3D = newpoint;
                lastplla    = item;
                if (pmPOS.LineString.coordinates.Count > 20000)
                {
                    //add current
                    pmPOS.AddStyle(style);
                    fldr.Add(pmPOS);

                    // create new
                    pmPOS                        = new Placemark();
                    pmPOS.name                   = "POS Message - extra";
                    pmPOS.LineString             = new LineString();
                    pmPOS.LineString.coordinates = new Coordinates();
                    lastPoint3D                  = new Point3D();
                    lastplla                     = PointLatLngAlt.Zero;
                }
            }
            pmPOS.AddStyle(style);
            fldr.Add(pmPOS);

            Folder planes = new Folder();

            planes.name = "Planes";
            fldr.Add(planes);

            Folder waypoints = new Folder();

            waypoints.name = "Waypoints";
            fldr.Add(waypoints);


            LineString lswp = new LineString();

            lswp.AltitudeMode = AltitudeMode.relativeToGround;
            lswp.Extrude      = true;

            Coordinates coordswp = new Coordinates();

            foreach (PointLatLngAlt p1 in cmd)
            {
                if (p1.Lng == 0 && p1.Lat == 0)
                {
                    continue;
                }

                coordswp.Add(new Point3D(p1.Lng, p1.Lat, p1.Alt));
            }

            lswp.coordinates = coordswp;

            Placemark pmwp = new Placemark();

            pmwp.name = "Waypoints";
            //pm.styleUrl = "#yellowLineGreenPoly";
            pmwp.LineString = lswp;

            if (coordswp.Count > 0)
            {
                waypoints.Add(pmwp);
            }

            int a = 0;
            int l = -1;

            Model lastmodel = null;

            foreach (Data mod in flightdata)
            {
                l++;
                if (mod.model.Location.latitude == 0)
                {
                    continue;
                }

                if (lastmodel != null)
                {
                    if (lastmodel.Location.Equals(mod.model.Location))
                    {
                        continue;
                    }
                }
                Placemark pmplane = new Placemark();
                pmplane.name = "Plane " + a;

                pmplane.visibility = false;

                Model model = mod.model;
                model.AltitudeMode = altmode;
                model.Scale.x      = 2;
                model.Scale.y      = 2;
                model.Scale.z      = 2;

                try
                {
                    pmplane.description = @"<![CDATA[
              <table>
                <tr><td>Roll: " + model.Orientation.roll + @" </td></tr>
                <tr><td>Pitch: " + model.Orientation.tilt + @" </td></tr>
                <tr><td>Yaw: " + model.Orientation.heading + @" </td></tr>
                <tr><td>WP dist " + mod.ntun[2] + @" </td></tr>
				<tr><td>tar bear "                 + mod.ntun[3] + @" </td></tr>
				<tr><td>nav bear "                 + mod.ntun[4] + @" </td></tr>
				<tr><td>alt error "                 + mod.ntun[5] + @" </td></tr>
              </table>
            ]]>";
                }
                catch
                {
                }

                try
                {
                    pmplane.Point = new KmlPoint((float)model.Location.longitude, (float)model.Location.latitude,
                                                 (float)model.Location.altitude);
                    pmplane.Point.AltitudeMode = altmode;

                    Link link = new Link();
                    link.href = "block_plane_0.dae";

                    model.Link = link;

                    pmplane.Model = model;

                    planes.Add(pmplane);
                }
                catch
                {
                } // bad lat long value

                lastmodel = mod.model;

                a++;
            }

            kml.Document.Add(fldr);

            kml.Save(filename);

            // create kmz - aka zip file

            FileStream fs = File.Open(filename.ToLower().Replace(".log.kml", ".kmz").Replace(".bin.kml", ".kmz"),
                                      FileMode.Create);
            ZipOutputStream zipStream = new ZipOutputStream(fs);

            zipStream.SetLevel(9);             //0-9, 9 being the highest level of compression
            zipStream.UseZip64 = UseZip64.Off; // older zipfile

            // entry 1
            string entryName = ZipEntry.CleanName(Path.GetFileName(filename));
            // Removes drive from name and fixes slash direction
            ZipEntry newEntry = new ZipEntry(entryName);

            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            byte[] buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();

            File.Delete(filename);

            filename = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar +
                       "block_plane_0.dae";

            // entry 2
            entryName = ZipEntry.CleanName(Path.GetFileName(filename));
            // Removes drive from name and fixes slash direction
            newEntry          = new ZipEntry(entryName);
            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();


            zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream
            zipStream.Close();

            positionindex = 0;
            modelist.Clear();
            flightdata.Clear();
            position = new List <Core.Geometry.Point3D> [200];
            cmd.Clear();
            cmdraw.Clear();
        }
Ejemplo n.º 6
0
            public HLSColor(Color color)
            {
                _isSystemColors_Control = color.ToKnownColor() == SystemColors.Control.ToKnownColor();

                ARGB argb = color;
                int  r = argb.R;
                int  g = argb.G;
                int  b = argb.B;
                int  Rdelta, Gdelta, Bdelta; // intermediate value: % of spread from max

                // calculate lightness
                int max = Math.Max(Math.Max(r, g), b);
                int min = Math.Min(Math.Min(r, g), b);
                int sum = max + min;

                Luminosity = ((sum * HLSMax) + RGBMax) / (2 * RGBMax);

                int dif = max - min;

                if (dif == 0)
                {
                    // r=g=b --> achromatic case
                    _saturation = 0;
                    _hue        = Undefined;
                }
                else
                {
                    // chromatic case
                    _saturation = Luminosity <= (HLSMax / 2)
                        ? ((dif * HLSMax) + (sum / 2)) / sum
                        : ((dif * HLSMax) + (2 * RGBMax - sum) / 2) / (2 * RGBMax - sum);

                    Rdelta = (((max - r) * (HLSMax / 6)) + (dif / 2)) / dif;
                    Gdelta = (((max - g) * (HLSMax / 6)) + (dif / 2)) / dif;
                    Bdelta = (((max - b) * (HLSMax / 6)) + (dif / 2)) / dif;

                    if (r == max)
                    {
                        _hue = Bdelta - Gdelta;
                    }
                    else if (g == max)
                    {
                        _hue = (HLSMax / 3) + Rdelta - Bdelta;
                    }
                    else
                    {
                        // B == cMax
                        _hue = (2 * HLSMax / 3) + Gdelta - Rdelta;
                    }

                    if (_hue < 0)
                    {
                        _hue += HLSMax;
                    }

                    if (_hue > HLSMax)
                    {
                        _hue -= HLSMax;
                    }
                }
            }
Ejemplo n.º 7
0
        private void writeKML(string filename)
        {
            try
            {
                writeGPX(filename);
            }
            catch { }

            Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink };

            AltitudeMode altmode = AltitudeMode.absolute;

            if (MainV2.cs.firmware == MainV2.Firmwares.ArduCopter2)
            {
                altmode = AltitudeMode.relativeToGround; // because of sonar, this is both right and wrong. right for sonar, wrong in terms of gps as the land slopes off.
            }

            KMLRoot kml  = new KMLRoot();
            Folder  fldr = new Folder("Log");

            Style style = new Style();

            style.Id = "yellowLineGreenPoly";
            style.Add(new LineStyle(HexStringToColor("7f00ffff"), 4));

            PolyStyle pstyle = new PolyStyle();

            pstyle.Color = HexStringToColor("7f00ff00");
            style.Add(pstyle);

            kml.Document.AddStyle(style);

            int stylecode = 0xff;
            int g         = -1;

            foreach (List <Point3D> poslist in position)
            {
                g++;
                if (poslist == null)
                {
                    continue;
                }

                LineString ls = new LineString();
                ls.AltitudeMode = altmode;
                ls.Extrude      = true;
                //ls.Tessellate = true;

                Coordinates coords = new Coordinates();
                coords.AddRange(poslist);

                ls.coordinates = coords;

                Placemark pm = new Placemark();

                string mode = "";
                if (g < modelist.Count)
                {
                    mode = modelist[g];
                }

                pm.name       = g + " Flight Path " + mode;
                pm.styleUrl   = "#yellowLineGreenPoly";
                pm.LineString = ls;

                stylecode = colours[g % (colours.Length - 1)].ToArgb();

                Style style2 = new Style();
                Color color  = Color.FromArgb(0xff, (stylecode >> 16) & 0xff, (stylecode >> 8) & 0xff, (stylecode >> 0) & 0xff);
                log.Info("colour " + color.ToArgb().ToString("X") + " " + color.ToKnownColor().ToString());
                style2.Add(new LineStyle(color, 4));



                pm.AddStyle(style2);

                fldr.Add(pm);
            }

            Folder planes = new Folder();

            planes.name = "Planes";
            fldr.Add(planes);

            Folder waypoints = new Folder();

            waypoints.name = "Waypoints";
            fldr.Add(waypoints);


            LineString lswp = new LineString();

            lswp.AltitudeMode = AltitudeMode.relativeToGround;
            lswp.Extrude      = true;

            Coordinates coordswp = new Coordinates();

            foreach (PointLatLngAlt p1 in cmd)
            {
                coordswp.Add(new Point3D(p1.Lng, p1.Lat, p1.Alt));
            }

            lswp.coordinates = coordswp;

            Placemark pmwp = new Placemark();

            pmwp.name = "Waypoints";
            //pm.styleUrl = "#yellowLineGreenPoly";
            pmwp.LineString = lswp;

            waypoints.Add(pmwp);

            int a = 0;
            int l = -1;

            Model lastmodel = null;

            foreach (Data mod in flightdata)
            {
                l++;
                if (mod.model.Location.latitude == 0)
                {
                    continue;
                }

                if (lastmodel != null)
                {
                    if (lastmodel.Location.Equals(mod.model.Location))
                    {
                        continue;
                    }
                }
                Placemark pmplane = new Placemark();
                pmplane.name = "Plane " + a;

                pmplane.visibility = false;

                Model model = mod.model;
                model.AltitudeMode = altmode;
                model.Scale.x      = 2;
                model.Scale.y      = 2;
                model.Scale.z      = 2;

                try
                {
                    pmplane.description = @"<![CDATA[
              <table>
                <tr><td>Roll: " + model.Orientation.roll + @" </td></tr>
                <tr><td>Pitch: " + model.Orientation.tilt + @" </td></tr>
                <tr><td>Yaw: " + model.Orientation.heading + @" </td></tr>
                <tr><td>WP dist " + mod.ntun[2] + @" </td></tr>
				<tr><td>tar bear "                 + mod.ntun[3] + @" </td></tr>
				<tr><td>nav bear "                 + mod.ntun[4] + @" </td></tr>
				<tr><td>alt error "                 + mod.ntun[5] + @" </td></tr>
              </table>
            ]]>";
                }
                catch { }

                try
                {
                    pmplane.Point = new KmlPoint((float)model.Location.longitude, (float)model.Location.latitude, (float)model.Location.altitude);
                    pmplane.Point.AltitudeMode = altmode;

                    Link link = new Link();
                    link.href = "block_plane_0.dae";

                    model.Link = link;

                    pmplane.Model = model;

                    planes.Add(pmplane);
                }
                catch { } // bad lat long value

                lastmodel = mod.model;

                a++;
            }

            kml.Document.Add(fldr);

            kml.Save(filename);

            // create kmz - aka zip file

            FileStream      fs        = File.Open(filename.Replace(".log.kml", ".kmz"), FileMode.Create);
            ZipOutputStream zipStream = new ZipOutputStream(fs);

            zipStream.SetLevel(9);             //0-9, 9 being the highest level of compression
            zipStream.UseZip64 = UseZip64.Off; // older zipfile

            // entry 1
            string   entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            ZipEntry newEntry  = new ZipEntry(entryName);

            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            byte[] buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();

            File.Delete(filename);

            filename = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "block_plane_0.dae";

            // entry 2
            entryName         = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction
            newEntry          = new ZipEntry(entryName);
            newEntry.DateTime = DateTime.Now;

            zipStream.PutNextEntry(newEntry);

            // Zip the file in buffered chunks
            // the "using" will close the stream even if an exception occurs
            buffer = new byte[4096];
            using (FileStream streamReader = File.OpenRead(filename))
            {
                StreamUtils.Copy(streamReader, zipStream, buffer);
            }
            zipStream.CloseEntry();


            zipStream.IsStreamOwner = true;     // Makes the Close also Close the underlying stream
            zipStream.Close();

            positionindex = 0;
            modelist.Clear();
            flightdata.Clear();
            position = new List <Core.Geometry.Point3D> [200];
            cmd.Clear();
        }
Ejemplo n.º 8
0
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="color">RGBA颜色</param>
            public HLSColor(Color color)
            {
                isSystemColors_Control = (color.ToKnownColor() == SystemColors.Control.ToKnownColor());
                int r = color.R;
                int g = color.G;
                int b = color.B;
                int max, min;               /* max and min RGB values */
                int sum, dif;
                int Rdelta, Gdelta, Bdelta; /* intermediate value: % of spread from max */

                /* calculate lightness */
                max = Math.Max(Math.Max(r, g), b);
                min = Math.Min(Math.Min(r, g), b);
                sum = max + min;

                luminosity = (((sum * HLSMax) + RGBMax) / (2 * RGBMax));

                dif = max - min;
                if (dif == 0)
                {                           /* r=g=b --> achromatic case */
                    saturation = 0;         /* saturation */
                    hue        = Undefined; /* hue */
                }
                else
                {                           /* chromatic case */
                    /* saturation */
                    if (luminosity <= (HLSMax / 2))
                    {
                        saturation = (int)(((dif * (int)HLSMax) + (sum / 2)) / sum);
                    }
                    else
                    {
                        saturation = (int)((int)((dif * (int)HLSMax) + (int)((2 * RGBMax - sum) / 2))
                                           / (2 * RGBMax - sum));
                    }
                    /* hue */
                    Rdelta = (int)((((max - r) * (int)(HLSMax / 6)) + (dif / 2)) / dif);
                    Gdelta = (int)((((max - g) * (int)(HLSMax / 6)) + (dif / 2)) / dif);
                    Bdelta = (int)((((max - b) * (int)(HLSMax / 6)) + (dif / 2)) / dif);

                    if ((int)r == max)
                    {
                        hue = Bdelta - Gdelta;
                    }
                    else if ((int)g == max)
                    {
                        hue = (HLSMax / 3) + Rdelta - Bdelta;
                    }
                    else /* B == cMax */
                    {
                        hue = ((2 * HLSMax) / 3) + Gdelta - Rdelta;
                    }

                    if (hue < 0)
                    {
                        hue += HLSMax;
                    }
                    if (hue > HLSMax)
                    {
                        hue -= HLSMax;
                    }
                }
            }
Ejemplo n.º 9
0
        public bool Read(string xmlFileName)
        {
            bool success = false;

            try
            {
                XmlDocument xn_doc = new XmlDocument();
                xn_doc.Load(xmlFileName);
                XmlNode xn_root = xn_doc.DocumentElement;

                if (m_xmlDataReaderUtils.VerifyVersion(xn_doc, xmlFileName, "version", "Version Numbers", "00.00.04", moduleName) &&
                    m_xmlDataReaderUtils.GetByte(xn_doc, xmlFileName, "unknown_indl", "Unknown Indent Level", ref AttrData.unknownIndentLevel, 0, byte.MaxValue, (byte)4, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "key_width", "Key Width", ref AttrData.columns.keyWidth, 0, (int)byte.MaxValue, 70, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "con_hnd_width", "Connection Handle Width", ref AttrData.columns.connHandleWidth, 0, (int)byte.MaxValue, 55, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "handle_width", "Handle Width", ref AttrData.columns.handleWidth, 0, (int)byte.MaxValue, 55, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "uuid_width", "UUID Width", ref AttrData.columns.uuidWidth, 0, (int)byte.MaxValue, 55, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "uuid_desc_width", "UUID Desc Width", ref AttrData.columns.uuidDescWidth, 0, (int)byte.MaxValue, 225, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "value_width", "Value Width", ref AttrData.columns.valueWidth, 0, (int)byte.MaxValue, 150, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "value_desc_width", "Value Desc Width", ref AttrData.columns.valueDescWidth, 0, (int)byte.MaxValue, 175, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "properties_width", "Properties Width", ref AttrData.columns.propertiesWidth, 0, (int)byte.MaxValue, 144, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "max_packet_size", "Max Packet Size", ref AttrData.writeLimits.MaxPacketSize, 16, 512, (int)sbyte.MaxValue, moduleName) &&
                    m_xmlDataReaderUtils.GetInt32(xn_doc, xmlFileName, "max_num_prepare_writes", "Max Num Prepare Writes", ref AttrData.writeLimits.MaxNumPreparedWrites, 1, 28, 5, moduleName))
                {
                    success = true;
                    #region Parse
                    foreach (XmlNode xmlNode2 in xn_root.SelectNodes("descendant::data_set"))
                    {
                        XmlNodeList xn_data_set_name = xmlNode2.SelectNodes("data_set_name");
                        XmlNodeList xn_uuid          = xmlNode2.SelectNodes("uuid");
                        XmlNodeList xn_indl          = xmlNode2.SelectNodes("indl");
                        XmlNodeList xn_vdsp          = xmlNode2.SelectNodes("vdsp");
                        XmlNodeList xn_vedt          = xmlNode2.SelectNodes("vedt");
                        XmlNodeList xn_udsc          = xmlNode2.SelectNodes("udsc");
                        XmlNodeList xn_vdsc          = xmlNode2.SelectNodes("vdsc");
                        XmlNodeList xn_fore          = xmlNode2.SelectNodes("fore");
                        XmlNodeList xn_back          = xmlNode2.SelectNodes("back");
                        string      tagName          = "Unknown";
                        try
                        {
                            for (int index = 0; index < xn_uuid.Count; ++index)
                            {
                                UuidData uuidData = new UuidData();

                                tagName = "Key";
                                string key = xn_uuid[index].InnerText.Replace("0x", "").Trim();

                                tagName       = "Uuid";
                                uuidData.Uuid = key;

                                tagName = "Indent Level";
                                try
                                {
                                    uuidData.IndentLevel = Convert.ToByte(xn_indl[index].InnerText.Trim());
                                }
                                catch (Exception ex)
                                {
                                    success = m_xmlDataReaderUtils.InvalidTagValueFound(tagName, xmlFileName, xn_indl[index].InnerText.Trim(), 0.ToString(), ex.Message, moduleName);
                                    uuidData.IndentLevel = (byte)0;
                                }

                                tagName = "Value Display";
                                switch (xn_vdsp[index].InnerText.Trim())
                                {
                                case "Hex":
                                    uuidData.ValueDisplay = ValueDisplay.Hex;
                                    break;

                                case "Dec":
                                    uuidData.ValueDisplay = ValueDisplay.Dec;
                                    break;

                                case "Asc":
                                    uuidData.ValueDisplay = ValueDisplay.Ascii;
                                    break;

                                default:
                                    success = m_xmlDataReaderUtils.InvalidTagValueFound(tagName, xmlFileName, xn_vdsp[index].InnerText.Trim(), ValueDisplay.Hex.ToString(), null, moduleName);
                                    uuidData.ValueDisplay = ValueDisplay.Hex;
                                    break;
                                }

                                tagName = "Value Edit";
                                switch (xn_vedt[index].InnerText.Trim())
                                {
                                case "Edit":
                                    uuidData.ValueEdit = ValueEdit.Editable;
                                    break;

                                case "Read":
                                    uuidData.ValueEdit = ValueEdit.ReadOnly;
                                    break;

                                default:
                                    success            = m_xmlDataReaderUtils.InvalidTagValueFound(tagName, xmlFileName, xn_vedt[index].InnerText.Trim(), ValueEdit.Editable.ToString(), null, moduleName);
                                    uuidData.ValueEdit = ValueEdit.Editable;
                                    break;
                                }

                                tagName           = "Uuid Description";
                                uuidData.UuidDesc = xn_udsc[index].InnerText.Trim();

                                tagName            = "Value Description";
                                uuidData.ValueDesc = xn_vdsc[index].InnerText.Trim();

                                tagName = "Foreground Color";
                                Color color = Color.FromName(xn_fore[index].InnerText.Trim());
                                if (color.ToKnownColor() == (KnownColor)0)
                                {
                                    success            = m_xmlDataReaderUtils.InvalidTagValueFound(tagName, xmlFileName, xn_fore[index].InnerText.Trim(), AttrData.defaultForeground.ToString(), null, moduleName);
                                    uuidData.ForeColor = AttrData.defaultForeground;
                                }
                                else
                                {
                                    uuidData.ForeColor = color;
                                }

                                tagName = "Background Color";
                                color   = Color.FromName(xn_back[index].InnerText.Trim());
                                if (color.ToKnownColor() == (KnownColor)0)
                                {
                                    success            = m_xmlDataReaderUtils.InvalidTagValueFound(tagName, xmlFileName, xn_back[index].InnerText.Trim(), AttrData.defaultBackground.ToString(), null, moduleName);
                                    uuidData.BackColor = AttrData.defaultBackground;
                                }
                                else
                                {
                                    uuidData.BackColor = color;
                                }

                                tagName = "Store Data Item";
                                try
                                {
                                    uuidData.DataSetName = xn_data_set_name.Item(0).FirstChild.Value;
                                }
                                catch
                                {
                                    uuidData.DataSetName = "Unknown Data Set Name";
                                }

                                AttrUuid.uuidDictAccess.WaitOne();
                                try
                                {
                                    AttrUuid.uuidDict.Add(key, uuidData);
                                }
                                catch (Exception ex)
                                {
                                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error,
                                                        "XML File Data Error\n" + ex.Message +
                                                        "\nUUID = 0x" + key +
                                                        "\nData Set Name = " + uuidData.DataSetName +
                                                        "\nTag Field = " + tagName +
                                                        "\n" + xmlFileName + "\nXmlDataReader\n"
                                                        );
                                    success = false;
                                }
                                AttrUuid.uuidDictAccess.ReleaseMutex();

                                if (!success)
                                {
                                    break;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Error Reading XML File\n" + ex.Message + "\nTag Field = " + tagName + "\n" + xmlFileName + "\nXmlDataReader\n");
                            success = false;
                        }
                        if (!success)
                        {
                            break;
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error,
                                    "Error Reading XML File\n" + ex.Message +
                                    "\n" + xmlFileName + "\nXmlDataReader\n"
                                    );
                success = false;
            }
            return(success);
        }
Ejemplo n.º 10
0
 public Pixel(Color color)
 {
     IsPath = color.ToKnownColor() == KnownColor.White;
 }
Ejemplo n.º 11
0
        public HlsColor(Color color)
        {
            _isSystemColorsControl = (color.ToKnownColor() == SystemColors.Control.ToKnownColor());
            int r = color.R;
            int g = color.G;
            int b = color.B;
            int max, min;               /* max and min RGB values */
            int sum, dif;
            int rdelta, gdelta, bdelta; /* intermediate value: % of spread from max */

            /* calculate lightness */
            max = Math.Max(Math.Max(r, g), b);
            min = Math.Min(Math.Min(r, g), b);
            sum = max + min;

            _luminosity = (((sum * HlsMax) + RgbMax) / (2 * RgbMax));

            dif = max - min;
            if (dif == 0)
            {
                /* r=g=b --> achromatic case */
                _saturation = 0;         /* saturation */
                _hue        = Undefined; /* hue */
            }
            else
            {
                /* chromatic case */
                /* saturation */
                if (_luminosity <= (HlsMax / 2))
                {
                    _saturation = ((dif * HlsMax) + (sum / 2)) / sum;
                }
                else
                {
                    _saturation = ((dif * HlsMax) + (2 * RgbMax - sum) / 2)
                                  / (2 * RgbMax - sum);
                }
                /* hue */
                rdelta = (((max - r) * (HlsMax / 6)) + (dif / 2)) / dif;
                gdelta = (((max - g) * (HlsMax / 6)) + (dif / 2)) / dif;
                bdelta = (((max - b) * (HlsMax / 6)) + (dif / 2)) / dif;

                if (r == max)
                {
                    _hue = bdelta - gdelta;
                }
                else if (g == max)
                {
                    _hue = (HlsMax / 3) + rdelta - bdelta;
                }
                else /* B == cMax */
                {
                    _hue = ((2 * HlsMax) / 3) + gdelta - rdelta;
                }

                if (_hue < 0)
                {
                    _hue += HlsMax;
                }
                if (_hue > HlsMax)
                {
                    _hue -= HlsMax;
                }
            }
        }
Ejemplo n.º 12
0
 public void Write(TextWriter writer)
 {
     Console.WriteLine($"Rectangle: {Color.ToKnownColor()}, {(Filled ? "Filled" : "Not Filled")}, {Rectangle}.");
 }
Ejemplo n.º 13
0
 public void Write(TextWriter writer)
 {
     Console.WriteLine($"Arc: {Color.ToKnownColor()}, {(Filled ? "Filled" : "Not Filled")}, {Rectangle}, Start:{Start}, End:{End}.");
 }
Ejemplo n.º 14
0
 public void Write(TextWriter writer)
 {
     Console.WriteLine($"Bezier: {color.ToKnownColor()}, {curveStart}, {curveEnd}, {controlFirst}, {controlSecond}.");
 }
Ejemplo n.º 15
0
 public static bool IsSystemColor(Color c) =>
 c.IsKnownColor && IsSystemColor(c.ToKnownColor());
Ejemplo n.º 16
0
        public static NSColor AsNSColor(this Color c)
        {
            if (c.IsSystemColor)
            {
                switch (c.ToKnownColor())
                {
                case KnownColor.ActiveBorder: return(NSColor.WindowFrame);

                case KnownColor.ActiveCaption: return(NSColor.Grid);

                case KnownColor.ActiveCaptionText: return(NSColor.HeaderText);

                // KnownColor.AppWorkspace
                case KnownColor.Control: return(NSColor.Control);

                case KnownColor.ControlText: return(NSColor.ControlText);

                case KnownColor.ControlDark: return(NSColor.ControlShadow);

                case KnownColor.ControlDarkDark: return(NSColor.ControlDarkShadow);

                case KnownColor.ControlLight: return(NSColor.ControlHighlight);

                case KnownColor.ControlLightLight: return(NSColor.ControlBackground);

                // KnownColor.Desktop
                case KnownColor.GrayText: return(NSColor.SystemGrayColor);

                case KnownColor.Highlight: return(NSColor.SelectedTextBackground);

                case KnownColor.HighlightText: return(NSColor.SelectedText);

                // KnownColor.HotTrack
                // KnownColor.InactiveBorder
                // KnownColor.InactiveCaption
                // KnownColor.InactiveCaptionText
                // KnownColor.Info
                // KnownColor.InfoText
                // KnownColor.Menu
                // KnownColor.MenuText
                case KnownColor.ScrollBar: return(NSColor.ScrollBar);

                case KnownColor.Window: return(NSColor.WindowBackground);

                case KnownColor.WindowText: return(NSColor.WindowFrameText);

                case KnownColor.WindowFrame: return(NSColor.WindowFrame);

                case KnownColor.ButtonFace: return(NSColor.Control);

                case KnownColor.ButtonHighlight: return(NSColor.ControlHighlight);

                case KnownColor.ButtonShadow: return(NSColor.ControlShadow);
                }
            }

            if (c.IsNamedColor)
            {
                if (c.Name == textBackgroundColor.Name)
                {
                    return(NSColor.TextBackground);
                }
            }

            return(null);
        }
Ejemplo n.º 17
0
 public void Write(TextWriter writer)
 {
     writer.WriteLine(
         $"Rectangle(Color: {Color.ToKnownColor()}, Filled: {Filled}, AABB: {Rectangle})");
 }
Ejemplo n.º 18
0
 public void SetColor(string keyName, Color value)
 {
     SetString(keyName, value.ToKnownColor().ToString());
 }
Ejemplo n.º 19
0
 public override string ToString()
 {
     return(string.Format("WIRE : Net {0} : {1}", NetName, WireColor.ToKnownColor().ToString()));
 }
 /// <summary>
 /// Gets the name of the known colour.
 /// </summary>
 /// <param name="colour">The colour.</param>
 /// <returns></returns>
 public static string GetKnownColourName(Color colour)
 {
     return(colour.ToKnownColor().ToString());
 }
Ejemplo n.º 21
0
 public override string ToString()
 {
     return(string.Format("PIN : {0}.{1} : Net {2} : {3}", Component, Number, NetName, PinColor.ToKnownColor().ToString()));
 }
Ejemplo n.º 22
0
        // Convert a "Color" value into a HTML color name.
        public static String ToHtml(Color color)
        {
            String ret   = "";
            int    value = (int)(color.ToKnownColor());

            if (color.IsKnownColor)                   //(value>=1) && (value<=167))
            {
                //int value = (int)(color.ToKnownColor());
                if (value >= 1 && value <= oleSystemColors.Length)
                {
                    switch (value)
                    {
                    case (int)KnownColor.ActiveCaptionText:
                        ret = "captiontext";
                        break;

                    case (int)KnownColor.Control:
                        ret = "buttonface";
                        break;

                    case (int)KnownColor.ControlDark:
                        ret = "buttonshadow";
                        break;

                    case (int)KnownColor.ControlDarkDark:
                        ret = "threeddarkshadow";
                        break;

                    case (int)KnownColor.ControlLight:
                        ret = "buttonface";
                        break;

                    case (int)KnownColor.ControlLightLight:
                        ret = "buttonhighlight";
                        break;

                    case (int)KnownColor.ControlText:
                        ret = "buttontext";
                        break;

                    case (int)KnownColor.Desktop:
                        ret = "background";
                        break;

                    case (int)KnownColor.HotTrack:
                        ret = "highlight";
                        break;

                    case (int)KnownColor.Info:
                        ret = "infobackground";
                        break;

                    //case (int)KnownColor.LightGray: ret = "LightGrey";break; // -> MS BUG.
                    // This last case cause a compare error but the good result is
                    // LightGray. So, never replace LightGray by LightGrey.
                    default:
                        ret = color.Name.ToLower();
                        break;
                    }
                }
                else
                {
                    ret = color.Name;
                }
            }
            else if (color.Name != "0")
            {
                ret = "#" + color.Name.Substring(2).ToUpper();
                /// GET R,G,B -> Format to hexa RRGGBB prepend '#'
            }
            return(ret);
        }
Ejemplo n.º 23
0
 private static string ColorToStr(Color color)
 {
     return(color.IsKnownColor
         ? color.ToKnownColor().ToString().ToLower()
         : string.Format("rgb({0},{1},{2})", color.R, color.G, color.B));
 }
Ejemplo n.º 24
0
        public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
        {
            Color color = Color.FromKnownColor(known);

            Assert.Equal((KnownColor)0, color.ToKnownColor());
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Formats a color instance to a code expression.
        /// </summary>
        /// <param name="color">The color to format.</param>
        /// <returns>A code expression referencing to a property defined in the <see cref="System.Drawing.Color"/> class,
        /// a call to <see cref="System.Drawing.Color.FromKnownColor(KnownColor)"/>, or a call to
        /// <see cref="System.Drawing.Color.FromArgb(Int32,Int32,Int32)"/>.</returns>
        public static CodeExpression FormatColor(Color color)
        {
            var colorTypeExpression = new CodeTypeReferenceExpression(typeof(Color));

            if (color.IsKnownColor)
            {
                return(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(colorTypeExpression, "FromKnownColor"),
                                                      new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(typeof(KnownColor)), color.ToKnownColor().ToString())));
            }

            if (color.IsNamedColor)
            {
                return(new CodePropertyReferenceExpression(colorTypeExpression, color.Name));
            }

            return(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(colorTypeExpression, "FromArgb"),
                                                  new CodePrimitiveExpression(color.A),
                                                  new CodePrimitiveExpression(color.R),
                                                  new CodePrimitiveExpression(color.G),
                                                  new CodePrimitiveExpression(color.B)));
        }
	// Convert a "Color" value into an OLE color value.
	public static int ToOle(Color color)
			{
				if(color.IsKnownColor)
				{
					int value = (int)(color.ToKnownColor());
					if(value >= 1 && value <= oleSystemColors.Length)
					{
						return (int)(oleSystemColors[value - 1]);
					}
				}
				return ToWin32(color);
			}
Ejemplo n.º 27
0
 public override string ToString()
 {
     return("This house is at " + _address + " and it's color is " + _color.ToKnownColor());
 }