aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.Synchronization/Properties/Settings.settings
blob: 033d7a5e9e2266753180f4e3a9299f575046701e (plain)
1
2
3
4
5
6
7
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
  <Profiles>
    <Profile Name="(Default)" />
  </Profiles>
  <Settings />
</SettingsFile>
e */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .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);
        }
    }
}