Inheritance: RleObject
示例#1
0
 public VectorLine(string vectordata, ColorTable colortable)
     : base()
 {
     this.ColorTable = colortable;
     string[] lines = vectordata.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var line in lines)
     {
         try
         {
             switch (line.Substring(0, 4))
             {
                 case "LNST":
                     LNST = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                         //TODO: what does it mean? - means ID
                     ObjectId = Convert.ToInt32(LNST.Substring(2, 5));
                     break;
                 case "LIND":
                     Code = RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(0, 8);
                     //SymbolType = RleParser.StripLenFromString(line.Substring(4).Trim())[8];
                     OffsetX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(8, 5));
                     OffsetY =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(13, 5));
                     Width =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(18, 5));
                     Height =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(23, 5));
                     HotspotX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(28, 5));
                     HotspotY =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(33, 5));
                     break;
                 case "LXPO":
                     Description = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     break;
                 case "LCRF":
                     string pal = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     while (pal.Length > 0)
                     {
                         try
                         {
                             Colors.Add(pal[0], colortable.Colors[pal.Substring(1, 5)]);
                         }
                         catch (Exception e)
                         {
                             _isvalid = false;
                             Debug.Print(
                                 "Symbol {0}. The requested color {1} doesn't exist in the palette.",
                                 this.Code,
                                 pal.Substring(1, 5));
                         }
                         pal = pal.Substring(6);
                     }
                     break;
                 case "LVCT":
                     AddLine(RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term));
                     break;
             }
         }
         catch (Exception ex)
         {
             Debug.Print("Error while parsing object: {0}", vectordata);
         }
     }
 }
示例#2
0
 public BitmapPattern(string bitmapdata, ColorTable colortable)
     : base()
 {
     this.ColorTable = colortable;
     string[] lines = bitmapdata.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     foreach (var line in lines)
     {
         try
         {
             switch (line.Substring(0, 4))
             {
                 case "PATT":
                     PATT = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                         //TODO: what does it mean?
                     ObjectId = Convert.ToInt32(PATT.Substring(2, 5));
                     break;
                 case "PATD":
                     Code = RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(0, 8);
                     SymbolType = RleParser.StripLenFromString(line.Substring(4).Trim())[8];
                     Value2 = RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(9, 6);
                     Value3 =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(15, 5));
                     Value4 =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(20, 5));
                     OffsetX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(25, 5));
                     OffsetY =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(30, 5));
                     Width =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(35, 5));
                     Height =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(40, 5));
                     HotspotX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(45, 5));
                     HotspotY =
                         Convert.ToInt32(
                             RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(50).Trim(
                                 RleParser.Term));
                         //TODO: it looks shorter, should be 55 in total, but is just 54!
                     break;
                 case "PXPO":
                     Description = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     break;
                 case "PCRF":
                     string pal = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     Colors.Clear();
                     while (pal.Length > 0)
                     {
                         try
                         {
                             Colors.Add(pal[0], colortable.Colors[pal.Substring(1, 5)]);
                         }
                         catch (Exception e)
                         {
                             _isvalid = false;
                             Debug.Print(
                                 "Symbol {0}. The requested color {1} doesn't exist in the palette.",
                                 this.Code,
                                 pal.Substring(1, 5));
                         }
                         pal = pal.Substring(6);
                     }
                     break;
                 case "PBTM":
                     AddLine(RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term));
                     break;
             }
         }
         catch (Exception ex)
         {
             Debug.Print("Error while parsing object: {0}", bitmapdata);
         }
     }
 }
示例#3
0
 public void SaveColorTableToFile(string fileName, ColorTable table)
 {
     TextWriter tw = new StreamWriter(fileName, false);
     tw.WriteLine(table.ToString());
     tw.Close();
 }
示例#4
0
        public RleParser(string rleFilename)
        {
            ColorTables = new Dictionary<string, ColorTable>();
            SymbolBitmaps = new Dictionary<string, BitmapSymbol>();
            PatternBitmaps = new Dictionary<string, BitmapPattern>();
            SymbolVectors = new Dictionary<string, VectorSymbol>();
            LineVectors = new Dictionary<string, VectorLine>();
            PatternVectors = new Dictionary<string, VectorPattern>();
            LookupTables = new Dictionary<string, Dictionary<int, LookupTable>>();
            LookupTables.Add(PLAIN_BOUNDARIES, new Dictionary<int, LookupTable>());
            LookupTables.Add(SYMBOLIZED_BOUNDARIES, new Dictionary<int, LookupTable>());
            LookupTables.Add(LINES, new Dictionary<int, LookupTable>());
            LookupTables.Add(SIMPLIFIED, new Dictionary<int, LookupTable>());
            LookupTables.Add(PAPER_CHART, new Dictionary<int, LookupTable>());

            StringBuilder sb = new StringBuilder();
            StringBuilder sbremarks = new StringBuilder();
            StreamReader sr = new StreamReader(rleFilename);
            string line;
            int counter = 1;
            while ((line = sr.ReadLine()) != null)
            {
                if (!line.Trim().StartsWith(";") && line.Trim() != string.Empty)
                {
                    if (line.StartsWith("0001"))
                    {
                        sb.Length = 0;
                    }
                    sb.AppendLine(line);
                    if (line.StartsWith("****"))
                    {
                        datacomponents.Add(sb.ToString());
                        if (IsColorTable(sb.ToString()))
                        {
                            ColorTable ct = new ColorTable(sb.ToString());
                            if (DefaultColorTable == null)
                            {
                                DefaultColorTable = ct;
                            }
                            ColorTables.Add(ct.Name, ct);
                        }

                        if (IsBitmap(sb.ToString()))
                        {
                            MergeBitmaps(sb.ToString());
                        }

                        if (IsVector(sb.ToString()))
                        {
                            MergeVectors(sb.ToString());
                        }
                        if (IsPaperChart(sb.ToString()))
                        {
                            LookupTable bp = new LookupTable(sb.ToString());
                            try
                            {
                                LookupTables[PAPER_CHART].Add(bp.ObjectId, bp);
                            }
                            catch (Exception ex)
                            {
                                Debug.Print("Lookup table {0} ({1}) can't be loaded with following message: {2}, replacing with the later definition",
                                                              bp.ObjectId, bp.Code, ex.Message);
                                LookupTables[PAPER_CHART][bp.ObjectId] = bp;
                            }
                            if (bp.ObjectId >= NextId)
                            {
                                NextId = bp.ObjectId + 1;
                            }
                        }

                        if (IsSimplified(sb.ToString()))
                        {
                            LookupTable bp = new LookupTable(sb.ToString());
                            try
                            {
                                LookupTables[RleParser.SIMPLIFIED].Add(bp.ObjectId, bp);
                            }
                            catch (Exception ex)
                            {
                                Debug.Print("Lookup table {0} ({1}) can't be loaded with following message: {2}, replacing with the later definition",
                                                              bp.ObjectId, bp.Code, ex.Message);
                                LookupTables[RleParser.SIMPLIFIED][bp.ObjectId] = bp;
                            }
                            if (bp.ObjectId >= NextId)
                            {
                                NextId = bp.ObjectId + 1;
                            }
                        }

                        if (IsLines(sb.ToString()))
                        {
                            LookupTable bp = new LookupTable(sb.ToString());
                            try
                            {
                                LookupTables[LINES].Add(bp.ObjectId, bp);
                            }
                            catch (Exception ex)
                            {
                                Debug.Print(
                                    "Lookup table {0} ({1}) can't be loaded with following message: {2}, replacing with the later definition",
                                    bp.ObjectId, bp.Code, ex.Message);
                                LookupTables[LINES][bp.ObjectId] = bp;
                            }
                            if (bp.ObjectId >= NextId)
                            {
                                NextId = bp.ObjectId + 1;
                            }
                        }

                        if (IsPlainBoundaries(sb.ToString()))
                        {
                            LookupTable bp = new LookupTable(sb.ToString());
                            try
                            {
                                LookupTables[PLAIN_BOUNDARIES].Add(bp.ObjectId, bp);
                            }
                            catch (Exception ex)
                            {
                                Debug.Print(
                                    "Lookup table {0} ({1}) can't be loaded with following message: {2}, replacing with the later definition",
                                    bp.ObjectId, bp.Code, ex.Message);
                                LookupTables[PLAIN_BOUNDARIES][bp.ObjectId] = bp;
                            }
                            if (bp.ObjectId >= NextId)
                            {
                                NextId = bp.ObjectId + 1;
                            }
                        }

                        if (IsSymbolizedBoundaries(sb.ToString()))
                        {
                            LookupTable bp = new LookupTable(sb.ToString());
                            try
                            {
                                LookupTables[SYMBOLIZED_BOUNDARIES].Add(bp.ObjectId, bp);
                            }
                            catch (Exception ex)
                            {
                                Debug.Print(
                                    "Lookup table {0} ({1}) can't be loaded with following message: {2}, replacing with the later definition",
                                    bp.ObjectId, bp.Code, ex.Message);
                                LookupTables[SYMBOLIZED_BOUNDARIES][bp.ObjectId] = bp;
                            }
                            if (bp.ObjectId >= NextId)
                            {
                                NextId = bp.ObjectId + 1;
                            }
                        }
                        sb.Length = 0; //Just to make sure in the official file at least one '0001' was missing...
                    }
                }
                else
                {
                    sbremarks.AppendLine(String.Format("{0:00000;-0000}: {1}", counter, line));
                }
                counter++;
            }
            sr.Close();
            remarks = sbremarks.ToString();
        }
示例#5
0
 public BitmapSymbol(string bitmapdata, ColorTable colortable)
     : base()
 {
     this.ColorTable = colortable;
     string[] lines = bitmapdata.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
     foreach (var line in lines)
     {
         try
         {
             switch (line.Substring(0, 4))
             {
                 case "SYMB":
                     SYMB = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                         //TODO: what does it mean?
                     ObjectId = Convert.ToInt32(SYMB.Substring(2, 5));
                     break;
                 case "SYMD":
                     Code = RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(0, 8);
                     SymbolType = RleParser.StripLenFromString(line.Substring(4).Trim())[8];
                     OffsetX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(9, 5));
                     OffsetY =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(14, 5));
                     Width =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(19, 5));
                     Height =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(24, 5));
                     HotspotX =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(29, 5));
                     HotspotY =
                         Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(34, 5));
                     break;
                 case "SXPO":
                     Description = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     break;
                 case "SCRF":
                     string pal = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                     Colors.Clear();
                     while (pal.Length > 0)
                     {
                         try
                         {
                             Colors.Add(pal[0], colortable.Colors[pal.Substring(1, 5)]);
                         }
                         catch (Exception e)
                         {
                             _isvalid = false;
                             Debug.Print(
                                 "Symbol {0}. The requested color {1} doesn't exist in the palette.",
                                 this.Code,
                                 pal.Substring(1, 5));
                         }
                         pal = pal.Substring(6);
                     }
                     break;
                 case "SBTM":
                     AddLine(RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term));
                     break;
             }
         }
         catch(Exception ex)
         {
             Debug.Print("Error while parsing object: {0}", bitmapdata);
         }
     }
 }
示例#6
0
        //vector symbols
        public Bitmap GetVectorRendering(ColorTable colortable)
        {
            double reduction = 5;

            string[]     commands      = _symboldata.ToString().Replace(Environment.NewLine, string.Empty).Split(';');
            Bitmap       btmp          = new Bitmap((int)(Width / reduction) + 1, (int)(Height / reduction) + 1);
            Graphics     canvas        = Graphics.FromImage(btmp);
            Point        curpos        = new Point();
            Point        newpos        = new Point();
            Pen          curpen        = new Pen(Color.Transparent, 1);
            List <Point> polygonbuffer = new List <Point>();
            bool         polygonmode   = false;

            foreach (string command in commands)
            {
                if (command.Length >= 2)
                {
                    string[] points;
                    switch (command.Substring(0, 2))
                    //http://www.informatics-consulting.de/software/plot2emf/p2e_hpgl.htm and http://www.isoplotec.co.jp/HPGL/eHPGL.htm
                    {
                    case "SP":     //Select pen
                        //curpen.Color = Colors[command[command.Length - 1]].Color;
                        curpen.Color = colortable.Colors[Colors[command[command.Length - 1]].Code].Color;
                        break;

                    case "SW":     //Select width - TODO: not part of the standard, is it really line width
                        curpen.Width = Convert.ToInt32(command[command.Length - 1].ToString()) * 2;
                        break;

                    case "PU":     //Move with pen up
                        points = command.Substring(2).Split(',');
                        for (int i = 0; i < points.Length / 2; i++)
                        {
                            curpos.X = Convert.ToInt32(command.Substring(2).Split(',')[2 * i]) - HotspotX;
                            curpos.X = (int)(curpos.X / reduction);
                            curpos.Y = Convert.ToInt32(command.Substring(2).Split(',')[2 * i + 1]) - HotspotY;
                            curpos.Y = (int)(curpos.Y / reduction);
                            if (polygonmode)
                            {
                                polygonbuffer.Add(curpos);
                            }
                        }
                        break;

                    case "PD":     //Move with pen down
                        if (command.Length > 2)
                        {
                            points = command.Substring(2).Split(',');
                            for (int i = 0; i < points.Length / 2; i++)
                            {
                                newpos.X = Convert.ToInt32(command.Substring(2).Split(',')[2 * i]) - HotspotX;
                                newpos.X = (int)(newpos.X / reduction);
                                newpos.Y = Convert.ToInt32(command.Substring(2).Split(',')[2 * i + 1]) - HotspotY;
                                newpos.Y = (int)(newpos.Y / reduction);
                                canvas.DrawLine(curpen, curpos, newpos);
                                curpos = newpos;
                                if (polygonmode)
                                {
                                    polygonbuffer.Add(curpos);
                                }
                            }
                        }
                        else     //Weird, but some symbols have just PD without coordinates so I assume it to be a point
                        {
                            canvas.DrawEllipse(curpen, curpos.X, curpos.Y, 1, 1);
                        }
                        break;

                    case "CI":     //CI r [, qd]    Draw Circle
                        int radius = Convert.ToInt32(command.Substring(2));
                        radius = (int)(radius / reduction);
                        if (polygonmode)
                        {
                            canvas.FillEllipse(new SolidBrush(curpen.Color), curpos.X - radius, curpos.Y - radius,
                                               radius * 2, radius * 2);
                        }
                        else
                        {
                            canvas.DrawEllipse(curpen, curpos.X - radius, curpos.Y - radius, radius * 2, radius * 2);
                        }
                        break;

                    case "PM":     //PM [n]     Polygon mode (HPGL/2)
                        polygonmode = !polygonmode;
                        if (polygonmode)
                        {
                            polygonbuffer.Add(curpos);
                        }
                        break;

                    case "FP":     //FP     Filled Polygon (HPGL/2)
                        if (polygonbuffer.Count > 0)
                        {
                            canvas.FillPolygon(new SolidBrush(curpen.Color), polygonbuffer.ToArray());
                            polygonbuffer.Clear();
                        }
                        break;

                    default:
                        Debug.Print("HP-GL command {0} unknown.", command);
                        break;
                    }
                }
            }
            return(btmp);
        }
示例#7
0
        public VectorLine(string vectordata, ColorTable colortable)
            : base()
        {
            this.ColorTable = colortable;
            string[] lines = vectordata.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var line in lines)
            {
                try
                {
                    switch (line.Substring(0, 4))
                    {
                    case "LNST":
                        LNST = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                        //TODO: what does it mean? - means ID
                        ObjectId = Convert.ToInt32(LNST.Substring(2, 5));
                        break;

                    case "LIND":
                        Code = RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(0, 8);
                        //SymbolType = RleParser.StripLenFromString(line.Substring(4).Trim())[8];
                        OffsetX =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(8, 5));
                        OffsetY =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(13, 5));
                        Width =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(18, 5));
                        Height =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(23, 5));
                        HotspotX =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(28, 5));
                        HotspotY =
                            Convert.ToInt32(RleParser.StripLenFromString(line.Substring(4).Trim()).Substring(33, 5));
                        break;

                    case "LXPO":
                        Description = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                        break;

                    case "LCRF":
                        string pal = RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term);
                        while (pal.Length > 0)
                        {
                            try
                            {
                                Colors.Add(pal[0], colortable.Colors[pal.Substring(1, 5)]);
                            }
                            catch (Exception e)
                            {
                                _isvalid = false;
                                Debug.Print(
                                    "Symbol {0}. The requested color {1} doesn't exist in the palette.",
                                    this.Code,
                                    pal.Substring(1, 5));
                            }
                            pal = pal.Substring(6);
                        }
                        break;

                    case "LVCT":
                        AddLine(RleParser.StripLenFromString(line.Substring(4).Trim()).Trim(RleParser.Term));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("Error while parsing object: {0}", vectordata);
                }
            }
        }