Exemple #1
0
        static string GetColor(string Key,string Value , struCommand[] list =null )
        {
            string Color = string.Empty;

            if(Key== "SURF_ID")
            {
                foreach(struCommand cmd in list)
                {
                    if (string.IsNullOrEmpty(cmd.CMDID)) continue;
                    if(cmd.cmdEnum ==CommandEnum.SURF)
                    {
                        if (cmd.CMDID.Replace("'", "").Replace(",","")==Value.Replace("'", ""))
                        {
                            string temp = string.Empty;
                            if (cmd.Parameters.TryGetValue("RGB", out temp))
                            {
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    Key = "RGB";
                                    Value = temp;
                                    break;
                                }
                            }
                            temp = string.Empty;
                            if (cmd.Parameters.TryGetValue("COLOR", out temp))
                            {
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    Key = "COLOR";
                                    Value = temp;
                                    break;
                                }
                            }

                        }
                    }
                }

            }

            if(Key=="RGB")
            {
                string[] str = Value.Split(',');
                Color = Convert.ToInt32(str[0]).ToString("X2");
                Color += Convert.ToInt32(str[1]).ToString("X2");
                Color += Convert.ToInt32(str[2]).ToString("X2");
            }
            if(Key =="COLOR")
            {
                Value = Value.Replace("'", "");
                Value = Value.Replace("\"", "");
                if (Value == "RED") Color = "FF0000";
                if (Value == "GREEN") Color = "00FF00";
                if (Value == "BLUE") Color = "0000FF";
                if (Value == "BLACK") Color = "000000";
                if (Value == "BLACK") Color = "000000";
                if (Value == "GRAY 80") Color = "808080";
                if (Value == "GRAY 60") Color = "606060";
                if (Color == string.Empty) Console.WriteLine("Unknow Color:" + Value);
            }

            return Color;
        }
Exemple #2
0
        public static struCommand[] ProcCommand(string[] data)
        {
            //整理命令
            NoteList.Clear();
            NoteList.Add("other");
            List<struCommand> CmdList = new List<struCommand>();
            for (int i = 0; i < data.Length; i++)
            {
                string Cmd = data[i].Trim();
                if (string.IsNullOrEmpty(Cmd)) continue;
                if (Cmd.Substring(0, 1) == "&")
                {
                    struCommand Command = new struCommand();
                    string comm = Cmd.Substring(0, Cmd.IndexOf(" ")).Trim();

                    Command.strCommand = comm;
                    Command.cmdEnum = GetCommandEnum(comm);
                    Command.ID = Guid.NewGuid();
                    Command.LineNUM = i;
                    Command.Data = Cmd;
                    Command.Parameters = new Dictionary<string, string>();
                    string tmp = Cmd.Substring(Cmd.IndexOf(" "), Cmd.Length - Cmd.IndexOf(" ")).Trim();
                    //Console.WriteLine(tmp);
                    string Key = string.Empty;
                    string Value = string.Empty;

                    string[] NameValue = tmp.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string temp in NameValue)
                    {
                        if (string.IsNullOrEmpty(temp.Trim())) continue;
                        string[] info = temp.Trim().Split('=');
                        if (info.Length != 2) continue;

                        if (info[1].IndexOf('/') > 0)
                        {
                            string[] p = info[1].Split('/');
                            info[1] = p[0];
                            Command.Note = p[1];
                            AddNoteList(p[1]);
                        }

                        if(info[0]=="ID")
                        {
                            Command.CMDID = info[1];
                        }

                        Command.Parameters.Add(info[0], info[1]);

                    }
                    CmdList.Add(Command);
                }
            }

            struCommand[] cmdList = CmdList.ToArray();
            CmdList = null;
            for (int i = 0; i < cmdList.Length; i++)
            {

                string temp = string.Empty;
                if (cmdList[i].Parameters.TryGetValue("RGB", out temp))
                {
                    string rgb = GetColor("RGB", temp);
                    if (!string.IsNullOrEmpty(rgb)) cmdList[i].c = rgb;
                }
                if (cmdList[i].Parameters.TryGetValue("COLOR", out temp))
                {
                    string rgb = GetColor("COLOR", temp);
                    if (!string.IsNullOrEmpty(rgb)) cmdList[i].c = rgb;
                }
                if (cmdList[i].Parameters.TryGetValue("SURF_ID", out temp))
                {
                    string rgb = GetColor("SURF_ID", temp, cmdList);
                    if (!string.IsNullOrEmpty(rgb)) cmdList[i].c = rgb;
                }

                temp = string.Empty;
                if (cmdList[i].Parameters.TryGetValue("XB", out temp))
                {
                    string[] valuelist = temp.Split(',');
                    if (valuelist.Length >= 6)
                    {
                        cmdList[i].p1 = new Point();
                        cmdList[i].p2 = new Point();

                        cmdList[i].p1.X = Convert.ToDouble(valuelist[0]);
                        cmdList[i].p2.X = Convert.ToDouble(valuelist[1]);

                        cmdList[i].p1.Y = Convert.ToDouble(valuelist[2]);
                        cmdList[i].p2.Y = Convert.ToDouble(valuelist[3]);

                        cmdList[i].p1.Z = Convert.ToDouble(valuelist[4]);
                        cmdList[i].p2.Z = Convert.ToDouble(valuelist[5]);

                        if (cmdList[i].p1.X < MinX) MinX = cmdList[i].p1.X;
                        if (cmdList[i].p1.X > MaxX) MaxX = cmdList[i].p1.X;

                        if (cmdList[i].p1.Y < MinY) MinY = cmdList[i].p1.Y;
                        if (cmdList[i].p1.Y > MaxY) MaxY = cmdList[i].p1.Y;

                        if (cmdList[i].p1.Z < MinZ) MinZ = cmdList[i].p1.Z;
                        if (cmdList[i].p1.Z > MaxZ) MaxZ = cmdList[i].p1.Z;

                        if (cmdList[i].p2.X < MinX) MinX = cmdList[i].p2.X;
                        if (cmdList[i].p2.X > MaxX) MaxX = cmdList[i].p2.X;

                        if (cmdList[i].p2.Y < MinY) MinY = cmdList[i].p2.Y;
                        if (cmdList[i].p2.Y > MaxY) MaxY = cmdList[i].p2.Y;

                        if (cmdList[i].p2.Z < MinZ) MinZ = cmdList[i].p2.Z;
                        if (cmdList[i].p2.Z > MaxZ) MaxZ = cmdList[i].p2.Z;
                    }
                }
            }
            data = null;
            GC.Collect();
            return cmdList;
        }