Got all functionality except reading colors working for sample file

Branch_1.5.0
Nathan Crawford 2007-07-27 03:04:19 +00:00
rodzic 141ff56992
commit 2a9fbc7cb9
12 zmienionych plików z 258 dodań i 69 usunięć

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -28,46 +28,108 @@ namespace embroideryReader
/// </summary>
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;
}
}

Wyświetl plik

@ -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<Point> tmpPoints = new List<Point>();
//int tmpx;
//int tmpy;
//List<Point> tmpPoints = new List<Point>();
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<Point> tmpPoints = new List<Point>();
//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();
}
}
}
}

Wyświetl plik

@ -117,4 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>100, 17</value>
</metadata>
</root>

Wyświetl plik

@ -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);

Wyświetl plik

@ -11,19 +11,44 @@ namespace embroideryReader
public partial class Form2 : Form
{
//public List<Point> pointList = new List<Point>();
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;
}
}
}

Wyświetl plik

@ -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")]

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.