aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Pulse/TwnFile.cs
blob: 40ee5847633e7470c4b01e6c4415690fa5767863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Pulse
{
    /// <summary>
    /// Represents a Pulse, twn embroidery file.
    /// </summary>
    public class TwnFile
    {
        /// <summary>
        /// Format Version (Default is 1.0).
        /// </summary>
        public float Version { get; set; }

        /// <summary>
        /// The name of the design or other labeling information as UTF-8 text.
        /// </summary>
        public String Name { get; set; }

        /// <summary>
        /// Number of copies. (The number 0 will be treated as 1, so the default is 0)
        /// </summary>
        public int NumberOfCopies { get; set; }

        /// <summary>
        /// 0 - Spool per segment. (default)
        /// 1 - Spool per copy.
        /// 2 - Single spool for all segments.
        /// </summary>
        public SpoolingMethods SpoolingMethod { get; set; }

        /// <summary>
        /// A unique code representing an optional media ID from Twine’s recommended media list
        /// </summary>
        public int MediaID { get; set; }

        /// <summary>
        /// 3 ASCII characters representing the embedded embroidery file extension (e.g dst, pes).
        /// </summary>
        public String EmbroideryFileFormat { get; set; }

        /// <summary>
        /// preview image in
        /// PNG format(transparent background). The size of the PNG byte array must be defined in the header.
        /// Recommended image width is 1280 pixels while maintaining aspect ratio.
        /// </summary>
        public Bitmap Thumbnail { get; set; }

        /// <summary>
        /// Gets or sets the thumbnail data.
        /// </summary>
        public byte[] ThumbnailData { get; set; }

        /// <summary>
        /// Array of Brush Segment. The number of brush segments must be defined in the header.
        /// </summary>
        public List<TwnSegment> Segments { get; set; }

        /// <summary>
        /// Byte array representing the standard embroidery file which can be extracted and inserted into an embroidery machine.
        /// </summary>
        public byte[] EmbroideryFile { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="TwnFile"/> class.
        /// </summary>
        public TwnFile()
        {
            Version = 1.0f;
            Segments = new List<TwnSegment>();
        }

        /// <summary>
        /// Writes the <see cref="TwnFile"/> to the specified output stream.
        /// </summary>
        /// <param name="output">The output stream.</param>
        public void ToStream(Stream output)
        {
            new TwnFileWriter().Write(this, output);
        }

        /// <summary>
        /// Writes the <see cref="TwnFile"/> to the specified file path.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void ToFile(String filePath)
        {
            using (FileStream fs = new FileStream(filePath, FileMode.Create))
            {
                ToStream(fs);
            }
        }

        /// <summary>
        /// Loads a <see cref="TwnFile"/> from the specified stream.
        /// </summary>
        /// <param name="twnStream">The TWN stream.</param>
        /// <returns></returns>
        public static TwnFile FromStream(Stream twnStream)
        {
            return new TwnFileReader().Read(twnStream);
        }

        /// <summary>
        /// Loads a <see cref="TwnFile"/> from the specified file path.
        /// </summary>
        /// <param name="twnFilePath">The TWN file path.</param>
        /// <returns></returns>
        public static TwnFile FromFile(String twnFilePath)
        {
            using (FileStream fs = new FileStream(twnFilePath, FileMode.Open))
            {
                return FromStream(fs);
            }
        }
    }
}