diff --git a/embroideryReader.suo b/embroideryReader.suo index 076b28a..4555b94 100644 Binary files a/embroideryReader.suo and b/embroideryReader.suo differ diff --git a/embroideryReader/Form1.Designer.cs b/embroideryReader/Form1.Designer.cs index 988a912..f260dcb 100644 --- a/embroideryReader/Form1.Designer.cs +++ b/embroideryReader/Form1.Designer.cs @@ -28,46 +28,108 @@ namespace embroideryReader /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.colorDialog1 = new System.Windows.Forms.ColorDialog(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // - this.button1.Location = new System.Drawing.Point(94, 116); + this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.Size = new System.Drawing.Size(53, 23); this.button1.TabIndex = 0; - this.button1.Text = "button1"; + this.button1.Text = "Open"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // + // button3 + // + this.button3.Location = new System.Drawing.Point(189, 12); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(53, 23); + this.button3.TabIndex = 2; + this.button3.Text = "Step 1x"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 45); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(35, 13); + this.label1.TabIndex = 3; + this.label1.Text = "label1"; + // + // timer1 + // + this.timer1.Interval = 10; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(71, 12); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(53, 23); + this.button4.TabIndex = 4; + this.button4.Text = "Play"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(130, 12); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(53, 23); + this.button5.TabIndex = 5; + this.button5.Text = "Pause"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // // button2 // - this.button2.Location = new System.Drawing.Point(106, 198); + this.button2.Location = new System.Drawing.Point(248, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); - this.button2.TabIndex = 1; + this.button2.TabIndex = 6; this.button2.Text = "button2"; this.button2.UseVisualStyleBackColor = true; - this.button2.Click += new System.EventHandler(this.button2_Click); + this.button2.Click += new System.EventHandler(this.button2_Click_1); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(292, 273); + this.ClientSize = new System.Drawing.Size(376, 67); this.Controls.Add(this.button2); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.label1); + this.Controls.Add(this.button3); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Timer timer1; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.ColorDialog colorDialog1; private System.Windows.Forms.Button button2; } } diff --git a/embroideryReader/Form1.cs b/embroideryReader/Form1.cs index 9127be8..babebab 100644 --- a/embroideryReader/Form1.cs +++ b/embroideryReader/Form1.cs @@ -12,6 +12,12 @@ namespace embroideryReader { private Form2 _form2 = new Form2(); private long bytesRead = 0; + System.IO.BinaryReader fileIn; + Random rnd = new Random(); + int stitchCount = 0; + int stitchesLeft = 0; + int skipStitches = 0; + public Form1() { @@ -20,97 +26,90 @@ namespace embroideryReader private void button1_Click(object sender, EventArgs e) { - System.IO.BinaryReader fileIn; + //System.IO.BinaryReader fileIn; //char charIn; string message = ""; fileIn = new System.IO.BinaryReader(System.IO.File.Open("118866.pes", System.IO.FileMode.Open)); //charIn = fileIn.ReadChar(); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++)//8 bytes { message += fileIn.ReadChar(); bytesRead++; } message += Environment.NewLine; - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++)//16 bytes { message += fileIn.ReadInt16().ToString(); message += Environment.NewLine; bytesRead += 2; } - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++)//7 bytes + { + message += fileIn.ReadChar(); + + bytesRead++; + } + message += Environment.NewLine; + //MessageBox.Show(message); + + //message = ""; + for (int i = 0; i < 11; i++) //read 66 bytes + { + message += fileIn.ReadInt16().ToString(); + message += "\t| "; + message += fileIn.ReadInt16().ToString(); + message += "\t| "; + message += fileIn.ReadInt16().ToString(); + message += Environment.NewLine; + bytesRead += 6; + } + //MessageBox.Show(message); + + //message = ""; + for (int i = 0; i < 7; i++)//7 bytes { message += fileIn.ReadChar(); bytesRead++; } //MessageBox.Show(message); - message = ""; - for (int i = 0; i < 33; i++) //read 66 bytes - { - message += fileIn.ReadInt16().ToString(); - //message += "\t| "; - //message += fileIn.ReadInt32().ToString(); - //message += "\t| "; - //message += fileIn.ReadByte().ToString(); - message += Environment.NewLine; - bytesRead += 2; - } - //MessageBox.Show(message); - - message = ""; - for (int i = 0; i < 7; i++) - { - message += fileIn.ReadChar(); - bytesRead++; - } - //MessageBox.Show(message); - - message = ""; - for (int i = 0; i < 10; i++) + //message = ""; + MessageBox.Show(fileIn.BaseStream.Position.ToString()); + for (int i = 0; i < 7; i++)//14 bytes { message += fileIn.ReadInt16(); message += Environment.NewLine; bytesRead += 2; } MessageBox.Show(message); - - //int tmpRed; - //int tmpGreen; - //int tmpBlue; - - //tmpRed = fileIn.ReadByte(); - //tmpGreen = fileIn.ReadByte(); - //tmpBlue = fileIn.ReadByte(); - //fileIn.ReadByte(); - - //Color tmpColor = System.Drawing.Color.FromArgb(tmpRed, tmpGreen, tmpBlue); - //_form2.drawColor = tmpColor; //start of point pairs? message = ""; - int tmpx; - int tmpy; - List tmpPoints = new List(); + //int tmpx; + //int tmpy; + //List tmpPoints = new List(); long startPos = fileIn.BaseStream.Position; bytesRead = fileIn.BaseStream.Position; - while (bytesRead + 4 <= fileIn.BaseStream.Length) - //while (bytesRead + 4 <= startPos + 1204 + 200) - { - //if (bytesRead > 1322) - //{ - // int junk = 0; - // junk++; - //} - tmpy = Convert.ToInt32( (fileIn.ReadInt16() / 2.0) + 600); - tmpx = Convert.ToInt32( (fileIn.ReadInt16() / 2.0) + 600); - bytesRead += 4; - tmpPoints.Add(new Point(tmpx, tmpy)); - } - _form2.points = new Point[tmpPoints.Count]; - tmpPoints.CopyTo(_form2.points); - fileIn.Close(); + //MessageBox.Show(fileIn.BaseStream.Position.ToString()); + //while (bytesRead + 4 <= 10000) + ////while (bytesRead + 4 <= startPos + 1204 + 200) + //{ + // //if (bytesRead > 1322) + // //{ + // // int junk = 0; + // // junk++; + // //} + // tmpy = Convert.ToInt32( (fileIn.ReadInt16() / 2.0) + 600); + // tmpx = Convert.ToInt32( (fileIn.ReadInt16() / 2.0) + 600); + // bytesRead += 4; + // tmpPoints.Add(new Point(tmpx, tmpy)); + //} + //_form2.points = new Point[tmpPoints.Count]; + //tmpPoints.CopyTo(_form2.points); + //fileIn.Close(); //MessageBox.Show(tmpPoints.Count.ToString()); _form2.Show(); + _form2.drawColor = Color.FromArgb((rnd.Next(0, 255)), (rnd.Next(0, 255)), (rnd.Next(0, 255))); } private void button2_Click(object sender, EventArgs e) @@ -118,5 +117,101 @@ namespace embroideryReader _form2.Show(); } + private void button3_Click(object sender, EventArgs e) + { + nextStitch(); + } + + private void nextStitch() + { + int tmpx; + int tmpy; + //List tmpPoints = new List(); + //while (bytesRead + 4 <= 10000) + //while (bytesRead + 4 <= startPos + 1204 + 200) + //{ + //if (bytesRead > 1322) + //{ + // int junk = 0; + // junk++; + //} + Int32 realx; + Int32 realy; + if (fileIn.BaseStream.Position + 4 < fileIn.BaseStream.Length) + { + realx = fileIn.ReadInt16(); + realy = fileIn.ReadInt16(); + if (realx == -32765) + { + + if (realy == 1) + { + //timer1.Enabled = false; + //colorDialog1.ShowDialog(); + //_form2.drawColor = colorDialog1.Color; + _form2.drawColor = Color.FromArgb((rnd.Next(0, 255)), (rnd.Next(0, 255)), (rnd.Next(0, 255))); + _form2.Invalidate(); + _form2.prevPoint = new Point(-1, -1); + } + fileIn.ReadInt16();//don't know what this is, maybe color index? + stitchesLeft = fileIn.ReadInt16(); + if (realy == 1) + { + skipStitches = stitchesLeft;//skip these stiches, since they just seem to get in the way + } + } + else + { + tmpx = Convert.ToInt32((realx / 2.0) + 100); + tmpy = Convert.ToInt32((realy / 2.0) + 600); + bytesRead += 4; + //tmpPoints.Add(new Point(tmpx, tmpy)); + if (skipStitches > 0) + { + skipStitches--; + } + else + { + _form2.addPoint(new Point(tmpx, tmpy)); + } + stitchCount++; + stitchesLeft--; + _form2.Invalidate(); + } + label1.Text = "file pos: " + fileIn.BaseStream.Position.ToString() + ", last values: " + realx.ToString() + ", " + realy.ToString() + ", stiches: " + stitchCount.ToString() + ", stitches left: " + stitchesLeft.ToString(); + if (stitchesLeft < 0) + { + timer1.Enabled = false; + fileIn.Close(); + } + } + //_form2.points = new Point[tmpPoints.Count]; + //tmpPoints.CopyTo(_form2.points); + + } + + private void timer1_Tick(object sender, EventArgs e) + { + nextStitch(); + } + + private void button4_Click(object sender, EventArgs e) + { + timer1.Enabled = true; + } + + private void button5_Click(object sender, EventArgs e) + { + timer1.Enabled = false; + } + + private void button2_Click_1(object sender, EventArgs e) + { + while (stitchesLeft >= 0) + { + nextStitch(); + } + } + } } \ No newline at end of file diff --git a/embroideryReader/Form1.resx b/embroideryReader/Form1.resx index ff31a6d..c856f6c 100644 --- a/embroideryReader/Form1.resx +++ b/embroideryReader/Form1.resx @@ -117,4 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 100, 17 + \ No newline at end of file diff --git a/embroideryReader/Form2.Designer.cs b/embroideryReader/Form2.Designer.cs index e85c70f..b8d99d1 100644 --- a/embroideryReader/Form2.Designer.cs +++ b/embroideryReader/Form2.Designer.cs @@ -35,6 +35,7 @@ namespace embroideryReader this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 273); + this.DoubleBuffered = true; this.Name = "Form2"; this.Text = "Form2"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form2_Paint); diff --git a/embroideryReader/Form2.cs b/embroideryReader/Form2.cs index 57620ea..11231d3 100644 --- a/embroideryReader/Form2.cs +++ b/embroideryReader/Form2.cs @@ -11,19 +11,44 @@ namespace embroideryReader public partial class Form2 : Form { //public List pointList = new List(); - public Point[] points = new Point[0]; + //public Point[] points = new Point[0]; public Color drawColor = System.Drawing.Color.Black; + private Bitmap DrawArea; + public Point prevPoint = new Point(-1,-1); public Form2() { InitializeComponent(); + DrawArea = new Bitmap(1000, 1000); } private void Form2_Paint(object sender, PaintEventArgs e) { //Point[] points = new Point[pointList.Count]; //pointList.CopyTo(points); - e.Graphics.DrawLines(new System.Drawing.Pen(drawColor), points); + //if (points.Length >= 2) + //{ + // e.Graphics.DrawLines(new System.Drawing.Pen(drawColor), points); + //} + e.Graphics.DrawImage(DrawArea, 0, 0); + } + + public void addPoint(Point p) + { + //Point[] tmp = new Point[points.Length + 1]; + //points.CopyTo(tmp,0); + //tmp[tmp.Length - 1] = p; + //points = tmp; + + if (prevPoint != null && prevPoint.X != -1 && prevPoint.Y != -1) + { + Graphics xGraph; + xGraph = Graphics.FromImage(DrawArea); + xGraph.DrawLine(new Pen(drawColor), prevPoint, p); + xGraph.Dispose(); + } + prevPoint = p; + } } } \ No newline at end of file diff --git a/embroideryReader/Properties/AssemblyInfo.cs b/embroideryReader/Properties/AssemblyInfo.cs index d80260f..55ad708 100644 --- a/embroideryReader/Properties/AssemblyInfo.cs +++ b/embroideryReader/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.0.0.183")] -[assembly: AssemblyFileVersion("1.0.0.183")] +[assembly: AssemblyVersion("1.0.0.260")] +[assembly: AssemblyFileVersion("1.0.0.260")] diff --git a/embroideryReader/bin/Debug/embroideryReader.exe b/embroideryReader/bin/Debug/embroideryReader.exe index 24dbf08..90118a5 100644 Binary files a/embroideryReader/bin/Debug/embroideryReader.exe and b/embroideryReader/bin/Debug/embroideryReader.exe differ diff --git a/embroideryReader/bin/Debug/embroideryReader.pdb b/embroideryReader/bin/Debug/embroideryReader.pdb index 82883cb..a331af6 100644 Binary files a/embroideryReader/bin/Debug/embroideryReader.pdb and b/embroideryReader/bin/Debug/embroideryReader.pdb differ diff --git a/embroideryReader/obj/Debug/embroideryReader.csproj.GenerateResource.Cache b/embroideryReader/obj/Debug/embroideryReader.csproj.GenerateResource.Cache index cd0798c..ccd9643 100644 Binary files a/embroideryReader/obj/Debug/embroideryReader.csproj.GenerateResource.Cache and b/embroideryReader/obj/Debug/embroideryReader.csproj.GenerateResource.Cache differ diff --git a/embroideryReader/obj/Debug/embroideryReader.exe b/embroideryReader/obj/Debug/embroideryReader.exe index 24dbf08..90118a5 100644 Binary files a/embroideryReader/obj/Debug/embroideryReader.exe and b/embroideryReader/obj/Debug/embroideryReader.exe differ diff --git a/embroideryReader/obj/Debug/embroideryReader.pdb b/embroideryReader/obj/Debug/embroideryReader.pdb index 82883cb..a331af6 100644 Binary files a/embroideryReader/obj/Debug/embroideryReader.pdb and b/embroideryReader/obj/Debug/embroideryReader.pdb differ