From 1323b507598b66287e7009bc4dde143537130db3 Mon Sep 17 00:00:00 2001 From: Nathan Crawford Date: Fri, 6 Dec 2013 19:03:40 -0500 Subject: [PATCH] Moved PesFile support classes to their own files --- PesFile/PesColors.cs | 79 +++++++++++++++++++++++++++++++++++ PesFile/PesFile.cs | 95 +++--------------------------------------- PesFile/PesFile.csproj | 2 + PesFile/StitchBlock.cs | 20 +++++++++ 4 files changed, 107 insertions(+), 89 deletions(-) create mode 100644 PesFile/PesColors.cs create mode 100644 PesFile/StitchBlock.cs diff --git a/PesFile/PesColors.cs b/PesFile/PesColors.cs new file mode 100644 index 0000000..2462fa2 --- /dev/null +++ b/PesFile/PesColors.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace PesFile +{ + public class PesColors + { + public static int[,] colorMap = new int[,] { + //red grn blu + { 0, 0, 0}, // 0 Not used + { 14, 31, 124}, // 1 + { 10, 85, 163}, // 2 + { 48, 135, 119}, // 3 + { 75, 107, 175}, // 4 + {237, 23, 31}, // 5 + {209, 92, 0}, // 6 + {145, 54, 151}, // 7 + {228, 154, 203}, // 8 + {145, 95, 172}, // 9 + {157, 214, 125}, // 10 + {232, 169, 0}, // 11 + {254, 186, 53}, // 12 + {255, 255, 0}, // 13 + {112, 188, 31}, // 14 + {186, 152, 0}, // 15 + {168, 168, 168}, // 16 + {123, 111, 0}, // 17 + {255, 255, 179}, // 18 + { 79, 85, 86}, // 19 + { 0, 0, 0}, // 20 + { 11, 61, 145}, // 21 + {119, 1, 118}, // 22 + { 41, 49, 51}, // 23 + { 42, 19, 1}, // 24 + {246, 74, 138}, // 25 + {178, 118, 36}, // 26 + {252, 187, 196}, // 27 + {254, 55, 15}, // 28 + {240, 240, 240}, // 29 + {106, 28, 138}, // 30 + {168, 221, 196}, // 31 + { 37, 132, 187}, // 32 + {254, 179, 67}, // 33 + {255, 240, 141}, // 34 + {208, 166, 96}, // 35 + {209, 84, 0}, // 36 + {102, 186, 73}, // 37 + { 19, 74, 70}, // 38 + {135, 135, 135}, // 39 + {216, 202, 198}, // 40 + { 67, 86, 7}, // 41 + {254, 227, 197}, // 42 + {249, 147, 188}, // 43 + { 0, 56, 34}, // 44 + {178, 175, 212}, // 45 + {104, 106, 176}, // 46 + {239, 227, 185}, // 47 + {247, 56, 102}, // 48 + {181, 76, 100}, // 49 + { 19, 43, 26}, // 50 + {199, 1, 85}, // 51 + {254, 158, 50}, // 52 + {168, 222, 235}, // 53 + { 0, 103, 26}, // 54 + { 78, 41, 144}, // 55 + { 47, 126, 32}, // 56 + {253, 217, 222}, // 57 + {255, 217, 17}, // 58 + { 9, 91, 166}, // 59 + {240, 249, 112}, // 60 + {227, 243, 91}, // 61 + {255, 200, 100}, // 62 + {255, 200, 150}, // 63 + {255, 200, 200} // 64 + }; + } +} diff --git a/PesFile/PesFile.cs b/PesFile/PesFile.cs index c88ec8c..c5faaca 100644 --- a/PesFile/PesFile.cs +++ b/PesFile/PesFile.cs @@ -31,95 +31,11 @@ namespace PesFile { public enum statusEnum { NotOpen, IOError, ParseError, Ready }; - public class stitchBlock - { - public Color color; - public Int32 colorIndex; - public Int32 stitchesTotal; - public Stitch[] stitches; - public stitchBlock() - { - color = System.Drawing.Color.Black; - } - } - public struct intPair { public int a; public int b; } - - public class PesColors - { - public static int[,] colorMap = new int[,] { - //red grn blu - { 0, 0, 0}, // 0 Not used - { 14, 31, 124}, // 1 - { 10, 85, 163}, // 2 - { 48, 135, 119}, // 3 - { 75, 107, 175}, // 4 - {237, 23, 31}, // 5 - {209, 92, 0}, // 6 - {145, 54, 151}, // 7 - {228, 154, 203}, // 8 - {145, 95, 172}, // 9 - {157, 214, 125}, // 10 - {232, 169, 0}, // 11 - {254, 186, 53}, // 12 - {255, 255, 0}, // 13 - {112, 188, 31}, // 14 - {186, 152, 0}, // 15 - {168, 168, 168}, // 16 - {123, 111, 0}, // 17 - {255, 255, 179}, // 18 - { 79, 85, 86}, // 19 - { 0, 0, 0}, // 20 - { 11, 61, 145}, // 21 - {119, 1, 118}, // 22 - { 41, 49, 51}, // 23 - { 42, 19, 1}, // 24 - {246, 74, 138}, // 25 - {178, 118, 36}, // 26 - {252, 187, 196}, // 27 - {254, 55, 15}, // 28 - {240, 240, 240}, // 29 - {106, 28, 138}, // 30 - {168, 221, 196}, // 31 - { 37, 132, 187}, // 32 - {254, 179, 67}, // 33 - {255, 240, 141}, // 34 - {208, 166, 96}, // 35 - {209, 84, 0}, // 36 - {102, 186, 73}, // 37 - { 19, 74, 70}, // 38 - {135, 135, 135}, // 39 - {216, 202, 198}, // 40 - { 67, 86, 7}, // 41 - {254, 227, 197}, // 42 - {249, 147, 188}, // 43 - { 0, 56, 34}, // 44 - {178, 175, 212}, // 45 - {104, 106, 176}, // 46 - {239, 227, 185}, // 47 - {247, 56, 102}, // 48 - {181, 76, 100}, // 49 - { 19, 43, 26}, // 50 - {199, 1, 85}, // 51 - {254, 158, 50}, // 52 - {168, 222, 235}, // 53 - { 0, 103, 26}, // 54 - { 78, 41, 144}, // 55 - { 47, 126, 32}, // 56 - {253, 217, 222}, // 57 - {255, 217, 17}, // 58 - { 9, 91, 166}, // 59 - {240, 249, 112}, // 60 - {227, 243, 91}, // 61 - {255, 200, 100}, // 62 - {255, 200, 150}, // 63 - {255, 200, 200} // 64 - }; - } public class PesFile { @@ -132,7 +48,7 @@ namespace PesFile public List sewSegHeader = new List(); public List embPunchHeader = new List(); public List sewFigSegHeader = new List(); - public List blocks = new List(); + public List blocks = new List(); public List colorTable = new List(); private statusEnum readyStatus = statusEnum.NotOpen; Int64 startStitches = 0; @@ -240,6 +156,7 @@ namespace PesFile int pecstart = fileIn.ReadInt32(); + // Read number of colors in this design fileIn.BaseStream.Position = pecstart + 48; int numColors = fileIn.ReadByte() +1; List colorList = new List(); @@ -248,9 +165,10 @@ namespace PesFile colorList.Add(fileIn.ReadByte()); } + // Read stitch data fileIn.BaseStream.Position = pecstart + 532; bool thisPartIsDone = false; - stitchBlock curBlock; + StitchBlock curBlock; int prevX = 0; int prevY = 0; int maxX = 0; @@ -272,7 +190,7 @@ namespace PesFile thisPartIsDone = true; //add the last block - curBlock = new stitchBlock(); + curBlock = new StitchBlock(); curBlock.stitches = new Stitch[tempStitches.Count]; tempStitches.CopyTo(curBlock.stitches); curBlock.stitchesTotal = tempStitches.Count; @@ -286,7 +204,7 @@ namespace PesFile { //color switch, start a new block - curBlock = new stitchBlock(); + curBlock = new StitchBlock(); curBlock.stitches = new Stitch[tempStitches.Count]; tempStitches.CopyTo(curBlock.stitches); curBlock.stitchesTotal = tempStitches.Count; @@ -613,7 +531,6 @@ namespace PesFile private Color getColorFromIndex(int index) { - //Color retval;// = Color.White; if(index >= 1 && index <= 64) { return Color.FromArgb( diff --git a/PesFile/PesFile.csproj b/PesFile/PesFile.csproj index e23f459..8eafa6c 100644 --- a/PesFile/PesFile.csproj +++ b/PesFile/PesFile.csproj @@ -57,9 +57,11 @@ + + diff --git a/PesFile/StitchBlock.cs b/PesFile/StitchBlock.cs new file mode 100644 index 0000000..0dbddd7 --- /dev/null +++ b/PesFile/StitchBlock.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Drawing; + +namespace PesFile +{ + public class StitchBlock + { + public Color color; + public Int32 colorIndex; + public Int32 stitchesTotal; + public Stitch[] stitches; + public StitchBlock() + { + color = System.Drawing.Color.Black; + } + } +}