aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Properties/AssemblyInfo.cs
blob: ba3c4751c4a735135cdfd82f675cf9ff58ecdacf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

[assembly: AssemblyTitle("Tango - Machine Studio Technician Module")]
[assembly: AssemblyVersion("2.0.17.1608")]

[assembly: ComVisible(false)]

[assembly:ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                             //(used if a resource is not found in the page,
                             // or application resource dictionaries)
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
                                      //(used if a resource is not found in the page,
                                      // app, or any theme specific resource dictionaries)
)]
.bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

namespace Tango.Pulse
{
    /// <summary>
    /// Represents a Pulse, twn file writer.
    /// </summary>
    public class TwnFileWriter
    {
        /// <summary>
        /// Writes the specified TWN file.
        /// </summary>
        /// <param name="twnFile">The TWN file.</param>
        /// <param name="output">The output.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">Invalid design name length.</exception>
        /// <exception cref="System.NullReferenceException">
        /// Thumbnail image is null.
        /// or
        /// Could not serialize a null embroidery file.
        /// </exception>
        /// <exception cref="System.ArgumentException">The embroidery format must contain exactly 3 characters.</exception>
        public void Write(TwnFile twnFile, Stream output)
        {
            BinaryWriter writer = new BinaryWriter(output);

            //Format Version (Default is 1.0).
            writer.Write(twnFile.Version);


            //The name of the design or other labeling information as UTF - 8 text padded with white spaces and limited to 50 bytes.
            byte[] nameBytes = Encoding.UTF8.GetBytes(twnFile.Name.PadRight(50, ' '));

            if (nameBytes.Length < 50)
            {
                throw new ArgumentOutOfRangeException("Invalid design name length.");
            }
            writer.Write(nameBytes, 0, 50);


            //The embedded preview image size in byte length as a 32 bit unsigned integer.
            if (twnFile.Thumbnail == null)
            {
                throw new NullReferenceException("Thumbnail image is null.");
            }

            byte[] thumbnailBytes = null; //For later use.
            using (MemoryStream ms = new MemoryStream())
            {
                twnFile.Thumbnail.Save(ms, ImageFormat.Png);
                writer.Write((UInt32)ms.Length);
                thumbnailBytes = ms.ToArray();
            }

            //The total number of brush segments as a 32 bit unsigned integer.
            writer.Write((UInt32)twnFile.Segments.Count);


            //Number of copies. (The number 0 will be treated as 1, so the default is 0)
            writer.Write((UInt32)twnFile.NumberOfCopies);


            //0 - Spool per segment. (default)
            //1 - Spool per copy.
            //2 - Single spool for all segments.
            writer.Write((byte)twnFile.SpoolingMethod);


            //A unique code representing an optional media ID from Twine’s recommended media list.
            writer.Write((UInt32)twnFile.MediaID);


            //3 ASCII characters representing the embedded embroidery file extension (e.g dst, pes).
            if (twnFile.EmbroideryFileFormat.Length != 3)
            {
                throw new ArgumentException("The embroidery format must contain exactly 3 characters.");
            }
            writer.Write(Encoding.ASCII.GetBytes(twnFile.EmbroideryFileFormat));


            //The byte array length of the embedded embroidery file.
            if (twnFile.EmbroideryFile == null)
            {
                throw new NullReferenceException("Could not serialize a null embroidery file.");
            }
            writer.Write((UInt32)twnFile.EmbroideryFile.Length);


            //Array of bytes representing the design 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.
            writer.Write(thumbnailBytes);


            //Array of Brush Segment. The number of brush segments must be defined in the header.
            foreach (var segment in twnFile.Segments)
            {
                //Required thread length in centimeters.
                writer.Write(segment.Length);

                //Number of brush stops.
                writer.Write((UInt32)segment.BrushStops.Count);

                //Array of brush stops.
                foreach (var stop in segment.BrushStops)
                {
                    //The RGB red component.
                    writer.Write(stop.R);

                    //The RGB green component.
                    writer.Write(stop.G);

                    //The RGB blue component.
                    writer.Write(stop.B);

                    //The Brush stop offset position within the parent brush length in percentage (0-1).
                    writer.Write(stop.Offset);
                }
            }


            //Byte array representing the standard embroidery file which can be extracted and inserted into an embroidery machine.
            writer.Write(twnFile.EmbroideryFile);
        }
    }
}