Создание программы-интерпретатора блок-схем

Дипломная работа - Компьютеры, программирование

Другие дипломы по предмету Компьютеры, программирование



= 10;= 10;(this is ChartMainBlock)

{= 40;= 18;

}if (this is RegularBLock)

{= 16;= 10;= 120;= 60;

}if (this is ConditionBlock)

{= 92;= 16;

}if (this is LoopBlock)

{= 80;= 80;

}= marginLeft + clientWidth + marginRight;= marginTop + clientHeight + marginBottom;

}

}void AdjustPosition(int ox, int oy)

{= ox;= oy;(this is Branch)

{cy = Y;(Block item in Items)

{.AdjustPosition(ox + (width - item.width) / 2, cy);+= item.height;

}

}

{cx = X + marginLeft;(Block item in Items)

{.AdjustPosition(cx, Y + marginTop);

cx += item.width;

}

}

}

///

/// Если открыть блок из файла, то информация о том какой ветке принадлежит каждый блок теряется

/// Метод устанавливает для каждого блока какой ветке он принадлежит

/// void SetBranches(Block branch)

{.Branch = branch;(this is RegularBLock);(Block block in Items)

{.SetBranches(this);

}

}abstract void Draw(Graphics g);

}

}

) RegularBlock.csSystem;System.Drawing;System.Drawing.Drawing2D;flowchart.blocks

{

[Serializable]class RegularBLock : Block

{RegularBLock() { }RegularBLock(string text) : base(text) { }override void Draw(Graphics g)

{containerCenter = X + width / 2;pen = isSelected ? new Pen(Color.Firebrick, 3) : new Pen(Color.Black, 1);.EndCap = LineCap.ArrowAnchor;.DrawLine(pen, containerCenter, Y, containerCenter, Y + dy);.EndCap = LineCap.NoAnchor;.DrawRectangle(pen, containerCenter - w/2, Y + dy, w, h);r = new Rectangle(containerCenter - w / 2, Y + dy, w, h);.DrawString(Text, drawFont, drawBrush, r, strFormat);.DrawLine(pen, containerCenter, Y + height - dy, containerCenter, Y + height);

}

}

}

) Branch.csSystem;System.Drawing;flowchart.blocks

{

[Serializable]class Branch : Block

{Branch() { }Branch(string text): base(text) { }override void Draw(Graphics g)

{pen = isSelected ? new Pen(Color.Firebrick, 3) : new Pen(Color.Black, 1);containerCenter = X + width / 2;.DrawLine(pen, containerCenter, Y, containerCenter, Y + dy);;

}

}

}

) ChartMainBlock.csSystem;System.Collections.Generic;System.Drawing;System.Drawing.Drawing2D;System.IO;System.Xml.Serialization;flowchart.blocks

{

[Serializable]class ChartMainBlock : Block

{ChartMainBlock() { }ChartMainBlock(string text) : base(text) { }override bool PointInsideBlock(int x, int y)

{blockX = X + width / 2 - w / 2;blockY = Y - dy;((x > blockX && x blockY && y < blockY + h));

}override void Draw(Graphics g)

{

//центр контейнераcontainerCenter = X + width / 2;

//центр контейнера минус половина ширины блока

int dx = X + width/2 - w/2;pen = isSelected ? new Pen(Color.Firebrick, 3) : new Pen(Color.Black, 1);.DrawLine(pen, dx + h / 2, Y - dy, dx + w - h / 2, Y - dy);.DrawLine(pen, dx + h / 2, Y + h - dy, dx + w - h / 2, Y + h - dy);.DrawArc(pen, dx, Y - dy, h, h, 90, 180);.DrawArc(pen, dx + w - h, Y - dy, h, h, 270, 180);.DrawLine(pen, containerCenter, Y + h - dy, containerCenter, Y + h);r = new Rectangle(dx, Y - dy, w, h);.DrawString("begin", drawFont, drawBrush, r, strFormat);

//блок в конце схемыdowny = Y + height;.DrawLine(pen, dx + h / 2, downy, dx + w - h / 2, downy);.DrawLine(pen, dx + h / 2, downy + h, dx + w - h / 2, downy + h);.DrawArc(pen, dx, downy, h, h, 90, 180);.DrawArc(pen, dx + w - h, downy, h, h, 270, 180);= new Rectangle(dx, downy, w, h);.DrawString("end", drawFont, drawBrush, r, strFormat);.EndCap = LineCap.ArrowAnchor;.DrawLine(pen, containerCenter, Y + height - dy, containerCenter, Y + height);.EndCap = LineCap.NoAnchor;

}void SaveToXml(string path)

{fStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);xmlFormat = new XmlSerializer((ChartMainBlock),Type[]

{(Block),(ConditionBlock),(RegularBLock),(Branch),(LoopBlock),(ChartMainBlock),(List),

}

);.Serialize(fStream, this);.Close();

}

}

}

) ConditionBLock.csSystem;System.Drawing;System.Drawing.Drawing2D;flowchart.blocks

{

[Serializable]class ConditionBlock : Block

{ConditionBlock() { }ConditionBlock(string text) : base(text) { }override void Draw(Graphics g)

{

//центр контейнераcontainerCenter = X + width / 2;

//центр контейнера минус половина ширины блока

int dx = containerCenter - w / 2;pen = isSelected ? new Pen(Color.Firebrick, 3) : new Pen(Color.Black, 1);

//верхняя линия.EndCap = LineCap.ArrowAnchor;.DrawLine(pen, containerCenter, Y, containerCenter, Y + dy);.EndCap = LineCap.NoAnchor;

//сам блок в виде ромба[] points = new Point[]

{Point(dx + w / 2, Y + dy),Point(dx + w, Y + h / 2 + dy),Point(dx + w / 2, Y + h + dy),Point(dx, Y + h / 2 + dy),Point(dx + w / 2, Y + dy),

};.DrawCurve(pen, points, 0);r = new Rectangle(dx, Y + dy, w, h);.DrawString(Text, drawFont, drawBrush, r, strFormat);

//подпись да= new Rectangle(dx - w/2, Y + dy, w/2, h/2);.DrawString("да", drawFont, drawBrush, r, strFormat);

//подпись нет= new Rectangle(dx + w , Y + dy, w / 2, h / 2);.DrawString("нет", drawFont, drawBrush, r, strFormat);left = Items[0];right = Items[1];

//левая линия= new Point[]

{Point(containerCenter - w / 2, Y + dy + h/2),Point(left.X + left.width/2, Y + dy + h/2),Point(left.X + left.width/2, left.Y),

};.DrawCurve(pen, points, 0);

//правая линия= new Point[]

{Point(containerCenter + w/2, Y + dy + h/2),Point(right.X + right.width/2, Y + dy + h/2),Point(right.X + right.width/2, right.Y),

};.DrawCurve(pen, points, 0);

//нижняя часть= new Point[]

{Point(left.X + left.width/2, left.Y + left.height),Point(left.X + left.width/2, Y + height - 20),Point(right.X + right.width/2, Y + height - 20),Point(right.X + right.width/2, right.Y + right.height),

};.DrawCurve(pen, points, 0);.DrawLine(pen, containerCenter, Y + height - 20, containerCenter, Y + height);

}

}

}

) LoopBlock.csSystem;System.Drawing;System.Drawing.Drawing2D;flowchart.blocks

{

[Serializable]class LoopBlock : Block

{LoopBlock() { }LoopBlock(string text) : base(text) { }override void Draw(Graphics g)

{containerCenter = X + width / 2;dx = containerCenter - w / 2;pen = isSelected ? new Pen(Color.Firebrick, 3) : new Pen(Color.Black, 1);.EndCap = LineCap.ArrowAnchor;.DrawLine(pen, containerCenter, Y, containerCenter, Y + dy);.EndCap = LineCap.NoAnchor;

//начало цикла[] points = new Point[]

{Point(dx + h / 3, Y + dy),Point(dx + w - h/3, Y + dy),Point(dx + w, Y + dy + h/3),Point(dx + w, Y + h + dy),Point(dx , Y + h + dy),Point(dx, Y + dy + h/3),Point(dx + h / 3, Y + dy),

};.DrawCurve(pen, points, 0);.DrawLine(pen, containerCenter, Y + h + dy*2, containerCenter, Y + h + dy);r = new Rectangle(containerCenter - w / 2, Y + dy, w, h);.DrawString(Text, drawFont, drawBrush, r, strFormat);

//смещение к низу контейнераdelta = height - h - 35;

pen.EndCap = LineCap.ArrowAnchor;.DrawLine(pen, containerCenter, Y + delta, containerCenter, Y + dy + delta);.EndCap = LineCap.NoAnchor;

//конец цикла= new Point[]

{Point(dx, Y + dy + delta),Point(dx + w, Y + dy+ delta),Point(dx + w, Y + dy + h - h/3+ delta),Point(dx + w - h/3, Y + h + dy+ delta),Point(dx + h/3, Y + h + dy+ delta),Point(dx, Y + dy + h - h/3+ delta),Point(dx, Y + dy + delta),

};.DrawCurve(pen, points, 0);= new Rectangle(containerCenter - w / 2, Y + dy + delta, w, h);.DrawString(TextAtTheEnd, drawFont, drawBrush, r, strFormat);.DrawLine(pen, containerCenter, Y + h + dy + delta, containerCenter, Y + h + dy*2 + delta);

}

}

}

) MainForm.csSystem;System.Collections.Generic;System.IO;System.Windows.Forms;System.Xml.Serialization;Jint;flowchart.blocks;flowchart

{partial class MainForm : Form

{WorkAreaForm workAreaForm;saveFileDialog = new SaveFileDialog { Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" };openFileDialog = new OpenFileDialog { Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" };string filePath = String.Empty;MainForm()

{();= new WorkAreaForm(codeTextBox);.MdiParent = this;.Clear();.Show();.Chart = new Chart();.DrawChart();.Text = workAreaForm.Chart.GetCode();.Height = ClientSize.Height;.Left = 0;.Top = menuStrip1.Height + 1;.Height = ClientSize.Height - menuStrip1.Height;.Left = ClientSize.Width - codePanel.Width;.Top = menuStrip1.Height + 1;.Left = 0;.Width = codePanel.Width;.Height = codePanel.Height- 200;.Height = 130;.Width = codePanel.Width;.Left = 0;.Top = codePanel.Top + codeTextBox.Height + 40;.Top = codeResultTextBox.Top - 25;

}void button1_Click(object sender, EventArgs e)

{.Insertion = true;.BlockType = 1;.UpdateChart(true);

}void button2_Click(object sender, EventArgs e)

{.Insertion = true;.BlockType = 2;.UpdateChart(true);

}void loopButton_Click(