예제 #1
0
        private void button_dec2bin_Click(object sender, EventArgs e)
        {
            List <int> v = GetDecimalHeights();

            Encoder.TileEncoder enc = new Encoder.TileEncoder((int)numericUpDown_maxheight.Value,
                                                              (byte)numericUpDown_Rangevalue.Value,
                                                              (int)numericUpDown_TilesizeHoriz.Value,
                                                              (int)numericUpDown_TilesizeVert.Value,
                                                              v);
            int idx = 0;

            try {
                int  count       = -1;
                bool bTileIsFull = false;
                while (count != 0 && !bTileIsFull)
                {
                    count = enc.ComputeNext(out bTileIsFull);
                    idx  += count;
                }
                richTextBox_Bin.BackColor = col_bin_ok;
            } catch (Exception ex) {
                MessageBox.Show("Exception bei Index " + idx.ToString() + " mit Wert " + v[idx].ToString() + ": " + ex.Message, "Fehler");
                return;
            }

            richTextBox_Bin.Text = enc.GetBinText();

            int bytes = richTextBox_Bin.TextLength / 8;

            if ((richTextBox_Bin.TextLength % 8) != 0)
            {
                bytes++;
            }
            label_Bytes.Text = bytes.ToString() + " Bytes";
        }
예제 #2
0
        private void FormDetail_Shown(object sender, EventArgs e)
        {
            this.KeyPreview = true;

            Encoder.TileEncoder enc = new Encoder.TileEncoder(HeightMax, Codingtype, TileSizeHorz, TileSizeVert, HeightData);
            textBox_Encoder.AppendText(string.Format("{0}{1}", enc, System.Environment.NewLine));

            textBox_Encoder.Visible = false;
            textBox_Data.Visible    = false;

            try {
                int  line        = -1;
                int  count       = -1;
                bool bTileIsFull = false;
                while (count != 0 && !bTileIsFull)
                {
                    count = enc.ComputeNext(out bTileIsFull);
                    if (count > 0)
                    {
                        for (int i = enc.Elements.Count - count; i < enc.Elements.Count; i++)
                        {
                            if (enc.Elements[i].Line >= 0 &&
                                line != enc.Elements[i].Line)
                            {
                                line = enc.Elements[i].Line;
                                textBox_Encoder.AppendText("Line " + line.ToString());
                                textBox_Encoder.AppendText(System.Environment.NewLine);
                                textBox_Data.AppendText(System.Environment.NewLine);
                            }

                            switch (enc.Elements[i].ElementTyp)
                            {
                            case Encoder.TileEncoder.HeightElement.Typ.Plateau:
                                textBox_Encoder.AppendText(string.Format("Idx={0}, Plateau Length={1} TableIdx={2} Bits={3} [{4}] <{5}>{6}",
                                                                         enc.Elements[i].Column,
                                                                         enc.Elements[i].Data,
                                                                         enc.Elements[i].PlateauTableIdx,
                                                                         enc.Elements[i].PlateauBinBits,
                                                                         enc.Elements[i].GetBinText(),
                                                                         enc.Elements[i].GetPlateauUnitsText(),
                                                                         System.Environment.NewLine));

                                StringBuilder sb = new StringBuilder();
                                for (int j = 0; j < enc.Elements[i].Data; j++)
                                {
                                    if (enc.Elements[i].Column > 0 || j > 0)
                                    {
                                        sb.Append("\t");
                                    }
                                    sb.Append("*");
                                }
                                textBox_Data.AppendText(sb.ToString());
                                break;

                            case Encoder.TileEncoder.HeightElement.Typ.PlateauFollower:
                                textBox_Encoder.AppendText(string.Format("Idx={0}, PlateauFollower ActualHeigth={1}, Value={2} [{3}] {4}{5} ddiff={6}{7}",
                                                                         enc.Elements[i].Column,
                                                                         enc.ActualHeigth,
                                                                         enc.Elements[i].Data,
                                                                         enc.Elements[i].GetBinText(),
                                                                         enc.Elements[i].Encoding,
                                                                         enc.Elements[i].Encoding == Encoder.TileEncoder.EncodeMode.Hybrid ?
                                                                         enc.Elements[i].HUnit.ToString() :
                                                                         "",
                                                                         enc.Elements[i].PlateauFollowerDdiff,
                                                                         System.Environment.NewLine));
                                if (enc.Elements[i].Column > 0)
                                {
                                    textBox_Data.AppendText("\t");
                                }

                                textBox_Data.AppendText("[" + enc.Elements[i].Data.ToString() + "]");
                                break;

                            case Encoder.TileEncoder.HeightElement.Typ.Value:
                                textBox_Encoder.AppendText(string.Format("Idx={0}, ActualHeigth={1}, Value={2} [{3}] {4}{5}{6}",
                                                                         enc.Elements[i].Column,
                                                                         enc.ActualHeigth,
                                                                         enc.Elements[i].Data,
                                                                         enc.Elements[i].GetBinText(),
                                                                         enc.Elements[i].Encoding,
                                                                         enc.Elements[i].Encoding == Encoder.TileEncoder.EncodeMode.Hybrid ?
                                                                         enc.Elements[i].HUnit.ToString() :
                                                                         "",
                                                                         System.Environment.NewLine));
                                if (enc.Elements[i].Column > 0)
                                {
                                    textBox_Data.AppendText("\t");
                                }

                                textBox_Data.AppendText(enc.Elements[i].Data.ToString());
                                break;
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                textBox_Encoder.AppendText("Exception: " + ex.Message);
            } finally {
                textBox_Encoder.Visible = true;
                textBox_Encoder.Select(textBox_Encoder.TextLength, 0);
                textBox_Encoder.ScrollToCaret();

                textBox_Data.Visible = true;
                textBox_Data.Select(textBox_Data.TextLength, 0);
                textBox_Data.ScrollToCaret();

                textBox_Encoder.Focus();
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.Error.WriteLine("Es muss mindestens eine Textdatei für die Daten angegeben werden.");
                Console.Error.WriteLine("Es kann außerdem ein Codiertyp, eine Basishöhe, eine Differenzhöhe und die Ausgabe eines Protokolls angegeben werden.");
            }
            else
            {
                string txtfile    = args[0];
                byte   codingtype = args.Length > 1 ? Convert.ToByte(args[1]) : (byte)0;
                int    baseheight = args.Length > 2 ? Convert.ToInt32(args[2]) : int.MinValue;
                int    diffheight = args.Length > 3 ? Convert.ToInt32(args[3]) : int.MinValue;
                bool   bWithProt  = args.Length > 4 ? Convert.ToBoolean(args[4]) : false;

                int tilewidth;
                int tileheight;
                int maxheight;
                int minheight;

                List <int> heights = ReadData(txtfile, out tilewidth, out tileheight, out minheight, out maxheight);

                if (heights.Count > 0)
                {
                    if (baseheight == int.MinValue)
                    {
                        baseheight = minheight;
                    }
                    if (diffheight == int.MinValue)
                    {
                        diffheight = maxheight - minheight;
                    }
                    if (baseheight + diffheight < maxheight)
                    {
                        Console.WriteLine("Die Differenzhöhe muss min. " + (maxheight - baseheight).ToString() + " sein.");
                        return;
                    }

                    if (baseheight > 0)
                    {
                        for (int i = 0; i < heights.Count; i++)
                        {
                            heights[i] -= baseheight;
                        }
                        maxheight -= baseheight;
                    }

                    Encoder.TileEncoder enc = new Encoder.TileEncoder(maxheight, codingtype, tilewidth, tileheight, heights);

                    StringBuilder sbProtData    = new StringBuilder();
                    StringBuilder sbProtEncoder = new StringBuilder();

                    try {
                        Console.WriteLine("encodiere Daten aus '" + txtfile + "' ...");
                        int  line = -1;
                        bool bTileIsFull;
                        do
                        {
                            int count = enc.ComputeNext(out bTileIsFull);
                            if (bWithProt &&
                                count > 0)
                            {
                                for (int i = enc.Elements.Count - count; i < enc.Elements.Count; i++)
                                {
                                    if (enc.Elements[i].Line >= 0 &&
                                        line != enc.Elements[i].Line)
                                    {
                                        line = enc.Elements[i].Line;
                                        sbProtEncoder.Append("Line " + line.ToString());
                                        sbProtEncoder.AppendLine();
                                        sbProtData.AppendLine();
                                    }

                                    switch (enc.Elements[i].ElementTyp)
                                    {
                                    case Encoder.TileEncoder.HeightElement.Typ.Plateau:
                                        sbProtEncoder.AppendLine(string.Format("Idx={0}, Plateau Length={1} TableIdx={2} Bits={3} [{4}] <{5}>",
                                                                               enc.Elements[i].Column,
                                                                               enc.Elements[i].Data,
                                                                               enc.Elements[i].PlateauTableIdx,
                                                                               enc.Elements[i].PlateauBinBits,
                                                                               enc.Elements[i].GetBinText(),
                                                                               enc.Elements[i].GetPlateauUnitsText()));

                                        StringBuilder sb = new StringBuilder();
                                        for (int j = 0; j < enc.Elements[i].Data; j++)
                                        {
                                            if (enc.Elements[i].Column > 0 || j > 0)
                                            {
                                                sb.Append("\t");
                                            }
                                            sb.Append("*");
                                        }
                                        sbProtData.Append(sb.ToString());
                                        break;

                                    case Encoder.TileEncoder.HeightElement.Typ.PlateauFollower:
                                        sbProtEncoder.AppendLine(string.Format("Idx={0}, PlateauFollower ActualHeigth={1}, Value={2} [{3}] {4}{5} ddiff={6}",
                                                                               enc.Elements[i].Column,
                                                                               enc.ActualHeigth,
                                                                               enc.Elements[i].Data,
                                                                               enc.Elements[i].GetBinText(),
                                                                               enc.Elements[i].Encoding,
                                                                               enc.Elements[i].Encoding == Encoder.TileEncoder.EncodeMode.Hybrid ?
                                                                               enc.Elements[i].HUnit.ToString() :
                                                                               "",
                                                                               enc.Elements[i].PlateauFollowerDdiff));
                                        if (enc.Elements[i].Column > 0)
                                        {
                                            sbProtData.Append("\t");
                                        }

                                        sbProtData.Append("[" + enc.Elements[i].Data.ToString() + "]");
                                        break;

                                    case Encoder.TileEncoder.HeightElement.Typ.Value:
                                        sbProtEncoder.AppendLine(string.Format("Idx={0}, ActualHeigth={1}, Value={2} [{3}] {4}{5}",
                                                                               enc.Elements[i].Column,
                                                                               enc.ActualHeigth,
                                                                               enc.Elements[i].Data,
                                                                               enc.Elements[i].GetBinText(),
                                                                               enc.Elements[i].Encoding,
                                                                               enc.Elements[i].Encoding == Encoder.TileEncoder.EncodeMode.Hybrid ?
                                                                               enc.Elements[i].HUnit.ToString() :
                                                                               ""));
                                        if (enc.Elements[i].Column > 0)
                                        {
                                            sbProtData.Append("\t");
                                        }

                                        sbProtData.Append(enc.Elements[i].Data.ToString());
                                        break;
                                    }
                                }
                            }
                        } while (!bTileIsFull);

                        string destfile   = Path.GetFileName(txtfile) + ".bin";
                        int    datalength = 0;

                        Console.WriteLine("schreibe Binärdaten in '" + destfile + "' ...");
                        using (BinaryWriter w = new BinaryWriter(File.Open(destfile, FileMode.Create))) {
                            byte[] buff = enc.GetCodedBytes();
                            datalength = buff.Length;
                            w.Write(buff);
                        }

                        Console.WriteLine("schreibe Konfiguration in '" + destfile + "'.info ...");
                        using (StreamWriter w = new StreamWriter(Path.GetFullPath(destfile + ".info"))) {
                            w.WriteLine("FILE=" + destfile);
                            w.WriteLine("TILEWIDTH=" + tilewidth.ToString());
                            w.WriteLine("TILEHEIGHT=" + tileheight.ToString());
                            w.WriteLine("BASE=" + baseheight.ToString());
                            w.WriteLine("DIFF=" + diffheight.ToString());
                            w.WriteLine("TYPE=" + codingtype.ToString());
                            w.WriteLine("LENGTH=" + datalength.ToString());
                        }

                        if (bWithProt)
                        {
                            Console.WriteLine("schreibe Protokoll in '" + destfile + "'.prot.txt ...");
                            using (StreamWriter w = new StreamWriter(Path.GetFullPath(destfile + ".prot.txt"))) {
                                w.WriteLine(sbProtEncoder.ToString());
                                w.WriteLine();
                                w.WriteLine(sbProtData.ToString());
                            }
                        }
                    } catch (Exception ex) {
                        Console.WriteLine("Fehler:");
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }