using System;
|
using System.Collections.Generic;
|
|
namespace TProduct.PumpGraph.Dxf
|
{
|
public class AutoCadHelper
|
{
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public CurrentViewModel(int r, int g, int b, short colorIndex)
|
{
|
this.R = r;
|
this.G = g;
|
this.B = b;
|
this.ColorIndex = colorIndex;
|
}
|
|
public int R { get; set; }
|
public int G { get; set; }
|
public int B { get; set; }
|
public short ColorIndex { get; set; }
|
}
|
|
private static List<CurrentViewModel> _list = null;
|
|
|
public static short RedColorIndex = 1;//红色
|
public static short YellowColorIndex = 2;//黄色
|
public static short GreenColorIndex = 3;//绿色
|
public static short CyanColorIndex = 4;//青色
|
public static short BlueColorIndex = 5;//蓝色
|
public static short MagentaColorIndex = 6;//洋红
|
public static short WhiteColorIndex = 7;//白色
|
|
public static WW.Cad.Model.Entities.EntityColor GetColor(System.Drawing.Color color)
|
{
|
if (_list == null)
|
{
|
_list = new List<CurrentViewModel>();
|
|
#region colorindex 18-248
|
_list.Add(new CurrentViewModel(38, 0, 0, 18));
|
_list.Add(new CurrentViewModel(38, 9, 0, 28));
|
_list.Add(new CurrentViewModel(38, 19, 0, 38));
|
_list.Add(new CurrentViewModel(38, 28, 0, 48));
|
_list.Add(new CurrentViewModel(38, 38, 0, 58));
|
_list.Add(new CurrentViewModel(28, 38, 0, 68));
|
_list.Add(new CurrentViewModel(19, 38, 0, 78));
|
_list.Add(new CurrentViewModel(9, 38, 0, 88));
|
_list.Add(new CurrentViewModel(0, 38, 0, 98));
|
_list.Add(new CurrentViewModel(0, 38, 9, 108));
|
_list.Add(new CurrentViewModel(0, 38, 19, 118));
|
_list.Add(new CurrentViewModel(0, 38, 28, 128));
|
_list.Add(new CurrentViewModel(0, 38, 38, 138));
|
_list.Add(new CurrentViewModel(0, 28, 38, 148));
|
_list.Add(new CurrentViewModel(0, 19, 38, 158));
|
_list.Add(new CurrentViewModel(0, 9, 38, 168));
|
_list.Add(new CurrentViewModel(0, 0, 38, 178));
|
_list.Add(new CurrentViewModel(9, 0, 38, 188));
|
_list.Add(new CurrentViewModel(19, 0, 38, 198));
|
_list.Add(new CurrentViewModel(28, 0, 38, 208));
|
_list.Add(new CurrentViewModel(38, 0, 38, 218));
|
_list.Add(new CurrentViewModel(38, 0, 28, 228));
|
_list.Add(new CurrentViewModel(38, 0, 19, 238));
|
_list.Add(new CurrentViewModel(38, 0, 9, 248));
|
#endregion
|
|
#region colorindex 19-249
|
_list.Add(new CurrentViewModel(38, 19, 19, 19));
|
_list.Add(new CurrentViewModel(38, 23, 19, 29));
|
_list.Add(new CurrentViewModel(38, 28, 19, 39));
|
_list.Add(new CurrentViewModel(38, 33, 19, 49));
|
_list.Add(new CurrentViewModel(38, 38, 19, 59));
|
_list.Add(new CurrentViewModel(33, 38, 19, 69));
|
_list.Add(new CurrentViewModel(28, 38, 19, 79));
|
_list.Add(new CurrentViewModel(23, 38, 19, 89));
|
_list.Add(new CurrentViewModel(19, 38, 19, 99));
|
_list.Add(new CurrentViewModel(19, 88, 23, 109));
|
_list.Add(new CurrentViewModel(19, 88, 28, 119));
|
_list.Add(new CurrentViewModel(19, 88, 88, 129));
|
_list.Add(new CurrentViewModel(19, 88, 88, 139));
|
_list.Add(new CurrentViewModel(19, 88, 88, 149));
|
_list.Add(new CurrentViewModel(19, 28, 88, 159));
|
_list.Add(new CurrentViewModel(19, 23, 88, 169));
|
_list.Add(new CurrentViewModel(19, 19, 88, 179));
|
_list.Add(new CurrentViewModel(23, 19, 88, 189));
|
_list.Add(new CurrentViewModel(28, 19, 88, 199));
|
_list.Add(new CurrentViewModel(88, 19, 88, 209));
|
_list.Add(new CurrentViewModel(88, 19, 88, 219));
|
_list.Add(new CurrentViewModel(88, 19, 88, 229));
|
_list.Add(new CurrentViewModel(88, 19, 28, 239));
|
_list.Add(new CurrentViewModel(88, 19, 23, 249));
|
|
#endregion
|
|
#region colorindex 16-246
|
_list.Add(new CurrentViewModel(76, 0, 0, 16));
|
_list.Add(new CurrentViewModel(76, 19, 0, 26));
|
_list.Add(new CurrentViewModel(76, 38, 0, 36));
|
_list.Add(new CurrentViewModel(76, 57, 0, 46));
|
_list.Add(new CurrentViewModel(76, 76, 0, 56));
|
_list.Add(new CurrentViewModel(57, 76, 0, 66));
|
_list.Add(new CurrentViewModel(38, 76, 0, 76));
|
_list.Add(new CurrentViewModel(19, 76, 0, 86));
|
_list.Add(new CurrentViewModel(0, 76, 0, 96));
|
_list.Add(new CurrentViewModel(0, 76, 19, 106));
|
_list.Add(new CurrentViewModel(0, 76, 38, 116));
|
_list.Add(new CurrentViewModel(0, 76, 57, 126));
|
_list.Add(new CurrentViewModel(0, 76, 76, 136));
|
_list.Add(new CurrentViewModel(0, 57, 76, 146));
|
_list.Add(new CurrentViewModel(0, 38, 76, 156));
|
_list.Add(new CurrentViewModel(0, 19, 76, 166));
|
_list.Add(new CurrentViewModel(0, 0, 76, 176));
|
_list.Add(new CurrentViewModel(19, 0, 76, 186));
|
_list.Add(new CurrentViewModel(38, 0, 76, 196));
|
_list.Add(new CurrentViewModel(57, 0, 76, 206));
|
_list.Add(new CurrentViewModel(76, 0, 76, 216));
|
_list.Add(new CurrentViewModel(76, 0, 57, 226));
|
_list.Add(new CurrentViewModel(76, 0, 38, 236));
|
_list.Add(new CurrentViewModel(76, 0, 19, 246));
|
#endregion
|
|
#region colorindex 17-247
|
_list.Add(new CurrentViewModel(76, 38, 38, 17));
|
_list.Add(new CurrentViewModel(76, 47, 38, 27));
|
_list.Add(new CurrentViewModel(76, 57, 38, 37));
|
_list.Add(new CurrentViewModel(76, 66, 38, 47));
|
_list.Add(new CurrentViewModel(76, 76, 38, 57));
|
_list.Add(new CurrentViewModel(66, 76, 38, 67));
|
_list.Add(new CurrentViewModel(57, 76, 38, 77));
|
_list.Add(new CurrentViewModel(47, 76, 38, 87));
|
_list.Add(new CurrentViewModel(38, 76, 38, 97));
|
_list.Add(new CurrentViewModel(38, 76, 47, 107));
|
_list.Add(new CurrentViewModel(38, 76, 57, 117));
|
_list.Add(new CurrentViewModel(38, 76, 66, 127));
|
_list.Add(new CurrentViewModel(38, 76, 76, 137));
|
_list.Add(new CurrentViewModel(38, 66, 126, 147));
|
_list.Add(new CurrentViewModel(38, 57, 126, 157));
|
_list.Add(new CurrentViewModel(38, 47, 126, 167));
|
_list.Add(new CurrentViewModel(38, 38, 126, 177));
|
_list.Add(new CurrentViewModel(47, 38, 126, 187));
|
_list.Add(new CurrentViewModel(57, 38, 126, 197));
|
_list.Add(new CurrentViewModel(66, 38, 126, 207));
|
_list.Add(new CurrentViewModel(76, 38, 76, 217));
|
_list.Add(new CurrentViewModel(76, 38, 66, 227));
|
_list.Add(new CurrentViewModel(76, 38, 57, 237));
|
_list.Add(new CurrentViewModel(76, 38, 47, 247));
|
#endregion
|
|
#region colorindex 14-244
|
_list.Add(new CurrentViewModel(127, 0, 0, 14));
|
_list.Add(new CurrentViewModel(127, 31, 0, 24));
|
_list.Add(new CurrentViewModel(127, 63, 0, 34));
|
_list.Add(new CurrentViewModel(127, 95, 0, 44));
|
_list.Add(new CurrentViewModel(127, 127, 0, 54));
|
_list.Add(new CurrentViewModel(95, 127, 0, 64));
|
_list.Add(new CurrentViewModel(63, 127, 0, 74));
|
_list.Add(new CurrentViewModel(31, 127, 0, 84));
|
_list.Add(new CurrentViewModel(0, 127, 0, 94));
|
_list.Add(new CurrentViewModel(0, 127, 31, 104));
|
_list.Add(new CurrentViewModel(0, 127, 63, 114));
|
_list.Add(new CurrentViewModel(0, 127, 95, 124));
|
_list.Add(new CurrentViewModel(0, 127, 127, 134));
|
_list.Add(new CurrentViewModel(0, 95, 127, 144));
|
_list.Add(new CurrentViewModel(0, 63, 127, 154));
|
_list.Add(new CurrentViewModel(0, 31, 127, 164));
|
_list.Add(new CurrentViewModel(0, 0, 127, 174));
|
_list.Add(new CurrentViewModel(31, 0, 127, 184));
|
_list.Add(new CurrentViewModel(63, 0, 127, 194));
|
_list.Add(new CurrentViewModel(95, 0, 127, 204));
|
_list.Add(new CurrentViewModel(127, 0, 127, 214));
|
_list.Add(new CurrentViewModel(127, 0, 95, 224));
|
_list.Add(new CurrentViewModel(127, 0, 63, 234));
|
_list.Add(new CurrentViewModel(127, 0, 31, 244));
|
|
#endregion
|
|
#region colorindex 15-245
|
_list.Add(new CurrentViewModel(127, 63, 63, 15));
|
_list.Add(new CurrentViewModel(127, 79, 63, 25));
|
_list.Add(new CurrentViewModel(127, 95, 63, 35));
|
_list.Add(new CurrentViewModel(127, 111, 63, 45));
|
_list.Add(new CurrentViewModel(127, 127, 63, 55));
|
_list.Add(new CurrentViewModel(111, 127, 63, 65));
|
_list.Add(new CurrentViewModel(95, 127, 63, 75));
|
_list.Add(new CurrentViewModel(79, 127, 63, 85));
|
_list.Add(new CurrentViewModel(63, 127, 63, 95));
|
_list.Add(new CurrentViewModel(63, 127, 79, 105));
|
_list.Add(new CurrentViewModel(63, 127, 95, 115));
|
_list.Add(new CurrentViewModel(63, 127, 111, 125));
|
_list.Add(new CurrentViewModel(63, 127, 127, 135));
|
_list.Add(new CurrentViewModel(63, 111, 127, 145));
|
_list.Add(new CurrentViewModel(63, 95, 127, 155));
|
_list.Add(new CurrentViewModel(63, 79, 127, 165));
|
_list.Add(new CurrentViewModel(63, 63, 127, 175));
|
_list.Add(new CurrentViewModel(79, 63, 127, 185));
|
_list.Add(new CurrentViewModel(95, 63, 127, 195));
|
_list.Add(new CurrentViewModel(111, 63, 127, 205));
|
_list.Add(new CurrentViewModel(127, 63, 127, 215));
|
_list.Add(new CurrentViewModel(127, 63, 111, 225));
|
_list.Add(new CurrentViewModel(127, 63, 95, 235));
|
_list.Add(new CurrentViewModel(127, 63, 79, 245));
|
|
#endregion
|
|
#region colorindex 10-240
|
_list.Add(new CurrentViewModel(255, 0, 0, 10));
|
_list.Add(new CurrentViewModel(255, 63, 0, 20));
|
_list.Add(new CurrentViewModel(255, 127, 0, 30));
|
_list.Add(new CurrentViewModel(255, 191, 0, 40));
|
_list.Add(new CurrentViewModel(255, 255, 0, 50));
|
_list.Add(new CurrentViewModel(191, 255, 0, 60));
|
_list.Add(new CurrentViewModel(127, 255, 0, 70));
|
_list.Add(new CurrentViewModel(63, 255, 0, 80));
|
_list.Add(new CurrentViewModel(0, 255, 0, 90));
|
_list.Add(new CurrentViewModel(0, 255, 63, 100));
|
_list.Add(new CurrentViewModel(0, 255, 127, 110));
|
_list.Add(new CurrentViewModel(0, 255, 191, 120));
|
_list.Add(new CurrentViewModel(0, 255, 255, 130));
|
_list.Add(new CurrentViewModel(0, 191, 255, 140));
|
_list.Add(new CurrentViewModel(0, 127, 255, 150));
|
_list.Add(new CurrentViewModel(0, 63, 255, 160));
|
_list.Add(new CurrentViewModel(0, 0, 255, 170));
|
_list.Add(new CurrentViewModel(63, 0, 255, 180));
|
_list.Add(new CurrentViewModel(127, 0, 255, 190));
|
_list.Add(new CurrentViewModel(191, 0, 255, 200));
|
_list.Add(new CurrentViewModel(255, 0, 255, 210));
|
_list.Add(new CurrentViewModel(255, 0, 191, 220));
|
_list.Add(new CurrentViewModel(255, 0, 127, 230));
|
_list.Add(new CurrentViewModel(255, 0, 63, 240));
|
#endregion
|
|
#region colorindex 11-241
|
_list.Add(new CurrentViewModel(255, 127, 127, 11));
|
_list.Add(new CurrentViewModel(255, 159, 127, 21));
|
_list.Add(new CurrentViewModel(255, 191, 127, 31));
|
_list.Add(new CurrentViewModel(255, 223, 127, 41));
|
_list.Add(new CurrentViewModel(255, 255, 127, 51));
|
_list.Add(new CurrentViewModel(223, 255, 127, 61));
|
_list.Add(new CurrentViewModel(191, 255, 127, 71));
|
_list.Add(new CurrentViewModel(159, 255, 127, 81));
|
_list.Add(new CurrentViewModel(127, 255, 127, 91));
|
_list.Add(new CurrentViewModel(101, 255, 159, 101));
|
_list.Add(new CurrentViewModel(127, 255, 191, 111));
|
_list.Add(new CurrentViewModel(127, 255, 223, 121));
|
_list.Add(new CurrentViewModel(127, 255, 255, 131));
|
_list.Add(new CurrentViewModel(127, 223, 255, 141));
|
_list.Add(new CurrentViewModel(127, 191, 255, 151));
|
_list.Add(new CurrentViewModel(127, 159, 255, 161));
|
_list.Add(new CurrentViewModel(127, 127, 255, 171));
|
_list.Add(new CurrentViewModel(159, 127, 255, 181));
|
_list.Add(new CurrentViewModel(191, 127, 255, 191));
|
_list.Add(new CurrentViewModel(223, 127, 255, 201));
|
_list.Add(new CurrentViewModel(255, 127, 255, 211));
|
_list.Add(new CurrentViewModel(255, 127, 223, 221));
|
_list.Add(new CurrentViewModel(255, 127, 191, 231));
|
_list.Add(new CurrentViewModel(255, 127, 159, 241));
|
#endregion
|
|
#region colorindex 12-242
|
_list.Add(new CurrentViewModel(165, 0, 0, 12));
|
_list.Add(new CurrentViewModel(165, 41, 0, 22));
|
_list.Add(new CurrentViewModel(165, 82, 0, 32));
|
_list.Add(new CurrentViewModel(165, 124, 0, 42));
|
_list.Add(new CurrentViewModel(165, 165, 0, 52));
|
_list.Add(new CurrentViewModel(124, 165, 0, 62));
|
_list.Add(new CurrentViewModel(82, 165, 0, 72));
|
_list.Add(new CurrentViewModel(41, 165, 0, 82));
|
_list.Add(new CurrentViewModel(0, 165, 0, 92));
|
_list.Add(new CurrentViewModel(0, 165, 41, 102));
|
_list.Add(new CurrentViewModel(0, 165, 82, 112));
|
_list.Add(new CurrentViewModel(0, 165, 124, 122));
|
_list.Add(new CurrentViewModel(0, 165, 165, 132));
|
_list.Add(new CurrentViewModel(0, 124, 165, 142));
|
_list.Add(new CurrentViewModel(0, 82, 165, 152));
|
_list.Add(new CurrentViewModel(0, 41, 165, 162));
|
_list.Add(new CurrentViewModel(0, 0, 165, 172));
|
_list.Add(new CurrentViewModel(41, 0, 165, 182));
|
_list.Add(new CurrentViewModel(82, 0, 165, 192));
|
_list.Add(new CurrentViewModel(124, 0, 165, 202));
|
_list.Add(new CurrentViewModel(165, 0, 165, 212));
|
_list.Add(new CurrentViewModel(165, 0, 124, 222));
|
_list.Add(new CurrentViewModel(165, 0, 82, 232));
|
_list.Add(new CurrentViewModel(165, 0, 41, 242));
|
#endregion
|
|
#region colorindex 13-243
|
_list.Add(new CurrentViewModel(165, 82, 82, 13));
|
_list.Add(new CurrentViewModel(165, 103, 82, 23));
|
_list.Add(new CurrentViewModel(165, 124, 82, 33));
|
_list.Add(new CurrentViewModel(165, 145, 82, 43));
|
_list.Add(new CurrentViewModel(165, 165, 82, 53));
|
_list.Add(new CurrentViewModel(145, 165, 82, 63));
|
_list.Add(new CurrentViewModel(124, 165, 82, 73));
|
_list.Add(new CurrentViewModel(103, 165, 82, 83));
|
_list.Add(new CurrentViewModel(82, 165, 82, 93));
|
_list.Add(new CurrentViewModel(82, 165, 103, 103));
|
_list.Add(new CurrentViewModel(82, 165, 124, 113));
|
_list.Add(new CurrentViewModel(82, 165, 145, 123));
|
_list.Add(new CurrentViewModel(82, 165, 165, 133));
|
_list.Add(new CurrentViewModel(82, 145, 165, 143));
|
_list.Add(new CurrentViewModel(82, 124, 165, 153));
|
_list.Add(new CurrentViewModel(82, 103, 165, 163));
|
_list.Add(new CurrentViewModel(82, 82, 165, 173));
|
_list.Add(new CurrentViewModel(103, 82, 165, 183));
|
_list.Add(new CurrentViewModel(124, 82, 165, 193));
|
_list.Add(new CurrentViewModel(145, 82, 165, 203));
|
_list.Add(new CurrentViewModel(165, 82, 165, 213));
|
_list.Add(new CurrentViewModel(165, 82, 145, 223));
|
_list.Add(new CurrentViewModel(165, 82, 124, 233));
|
_list.Add(new CurrentViewModel(165, 82, 103, 243));
|
#endregion
|
}
|
|
|
|
if (color.R == 255 && color.G == 255 && color.B == 255)
|
{
|
WW.Cad.Model.Color white_color = WW.Cad.Model.Color.CreateFromColorIndex(7);//CreateFromRgb(255, 255, 255);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(white_color);
|
}
|
|
|
foreach (var item in _list)
|
{
|
if (color.R == item.R && color.G == item.G && color.B == item.B)
|
{
|
WW.Cad.Model.Color colors = WW.Cad.Model.Color.CreateFromColorIndex(item.ColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(colors);
|
}
|
}
|
|
var min_dis = int.MaxValue;
|
short min_index = 0;
|
foreach (var item in _list)
|
{
|
int dis = Math.Abs(color.R - item.R) + Math.Abs(color.G - item.G) + Math.Abs(color.B - item.B);
|
if (dis < min_dis)
|
{
|
min_dis = dis;
|
min_index = item.ColorIndex;
|
}
|
}
|
|
WW.Cad.Model.Color min_colors = WW.Cad.Model.Color.CreateFromColorIndex(min_index);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(min_colors);
|
}
|
|
public static WW.Cad.Model.Entities.EntityColor GetColor(int r, int g, int b)
|
{
|
System.Drawing.Color color = System.Drawing.Color.FromArgb(r, g, b);
|
return GetColor(color);
|
}
|
public static WW.Cad.Model.Entities.EntityColor GetColor(short index)
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(index);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
|
public static WW.Cad.Model.Entities.EntityColor WhiteColor
|
{
|
get
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(WhiteColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
}
|
|
public static WW.Cad.Model.Entities.EntityColor BlueColor
|
{
|
get
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(BlueColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
}
|
|
public static WW.Cad.Model.Entities.EntityColor GreenColor
|
{
|
get
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(GreenColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
}
|
|
public static WW.Cad.Model.Entities.EntityColor YellowColor
|
{
|
get
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(YellowColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
}
|
public static WW.Cad.Model.Entities.EntityColor MagentaColor
|
{
|
get
|
{
|
WW.Cad.Model.Color color = WW.Cad.Model.Color.CreateFromColorIndex(MagentaColorIndex);
|
return WW.Cad.Model.Entities.EntityColor.CreateFrom(color);
|
}
|
}
|
|
}
|
}
|