Разработка и экспериментальное исследование редактора схем программ
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
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.cs System;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(object sender, EventArgs e)
{.Insertion = true;.BlockType = 3;.UpdateChart(true);
}
void deleteButton_Click(object sender, EventArgs e)
{.DeleteBLock();
}
void MainForm_Resize(object sender, EventArgs e)
{.Height = ClientSize.Height - menuStrip1.Height;.Height = ClientSize.Height - menuStrip1.Height;.Left = ClientSize.Width - codePanel.Width;.Height = codePanel.Height - 200;.Top = codePanel.Top + codeTextBox.Height + 40;.Top = codeResultTextBox.Top - 25;
}
void button3_Click(object sender, EventArgs e)
{.ClearChart();
}
void saveToolStripMenuItem_Click(object sender, EventArgs e)
{(filePath != String.Empty)
{.Chart.root.SaveToXml(filePath);;
}
fileName = String.Empty;
(saveFileDialog.ShowDialog() == DialogResult.OK)= saveFileDialog.FileName;
(fileName == String.Empty);
.Chart.root.SaveToXml(fileName);= fileName;.Text = fileName;
}
void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{fileName = String.Empty;
(saveFileDialog.ShowDialog() == DialogResult.OK)= saveFileDialog.FileName;
(fileName == String.Empty);
.Chart.root.SaveToXml(fileName);= fileName;.Text = fileName;
}
void exitToolStripMenuItem_Click(object sender, EventArgs e)
{();
}
void openToolStripMenuItem_Click(object sender, EventArgs e)
{fileName = String.Empty;
(openFileDialog.ShowDialog() == DialogResult.OK)= openFileDialog.FileName;
(fileName == String.Empty);
fStream = File.OpenRead(fileName);
xmlFormat = new XmlSerializer((ChartMainBlock),Type[]
{(Block),(ConditionBlock),(RegularBLock),(Branch),(LoopBlock),(ChartMainBlock),(List),
}
);
rootBlockFromFile;
{= (ChartMainBlock)xmlFormat.Deserialize(fStream);
}(System.Exception ex)
{.Show(ex.Message, "Ошибка при попытке открыть файл");.Close();;
}.Close();= fileName;.Text = filePath;
.Items[0].SetBranches(rootBlockFromFile);
.Chart.root = rootBlockFromFile;.Chart.codeGen = new CodeGenerator(rootBlockFromFile);.Chart.RealignBlocks();.Chart.RegenerateInsertionPoints();.Chart.UpdateAllBlocksList(); .UpdateChart();.UpdateCode();
}
void newChartToolStripMenuItem_Click(object sender, EventArgs e)
{.ClearChart();= String.Empty;.Text = "Новая схема";
}
void executeToolStripMenuItem_Click(object sender, EventArgs e)
{ script = @codeTextBox.Text;engine = new JsCodeInterpreter(codeResultTextBox);
{.RunScript(script);
}(JintException ex)
{.Show(ex.Message, "Ошибка при выполнении программы");
}
}
}
}
) WorkAreaForm.csSystem.Drawing;System.Drawing.Drawing2D;System.Windows.Forms;flowchart.blocks;
flowchart
{partial class WorkAreaForm : Form
{Bitmap _picture;Graphics g;
TextBox codeTextBox;
Chart Chart;BlockProreptiesEditor blockProreptiesEditorForm;
bool Insertion = false;int BlockType = 0;
WorkAreaForm(TextBox textBox)
{= textBox;
();
.Width = ClientSize.Width;.Height = ClientSize.Height;.Top = panel1.Left = 0;
_picture = new Bitmap(ClientSize.Width, ClientSize.Height);
.Image = _picture;.Width = ClientSize.Width;.Height = ClientSize.Height;.Top = workAreaFormPictureBox.Left = 0;
= Graphics.FromImage(workAreaFormPictureBox.Image);.SmoothingMode = SmoothingMode.AntiAlias;
}
void WorkAreaForm_Load(object sender, System.EventArgs e)
{= new Point(95, 0);
}
void workAreaFormPictureBox_MouseClick(object sender, MouseEventArgs e)
{(e.Button == MouseButtons.Right)
{= false;();= 0; = Cursors.Arrow;;
}
(Insertion)
{.ProcessMouseClickInsertion(e.X, e.Y, BlockType);();= false;= 0;.Text = Chart.GetCode();= Cursors.Arrow;
}
{.ProcessMouseClickBlockSelection(e.X, e.Y);();
}
}
void UpdateChart(bool insertion = false)
ClientSize.Width)">{(Chart.width > ClientSize.Width)
{ .Width = Chart.width;
_picture = new Bitmap(Chart.width, ClientSize.Height);.Image = _picture;= Graphics.FromImage(workAreaFormPictureBox.Image);.SmoothingMode = SmoothingMode.AntiAlias;
ClientSize.Height)">}if (Chart.height > ClientSize.Height)
{ .Height = Chart.height;
_picture = new Bitmap(ClientSize.Width, Chart.height);.Image = _picture;= Graphics.FromImage(workAreaFormPictureBox.Image);.SmoothingMode = SmoothingMode.AntiAlias;
}();(insertion);
}
void UpdateCode()
{.Text = Chart.GetCode();
}
void DrawChart(bool insertion = false)
{.Draw(g, insertion);.Refresh();
}
void Clear()
{.Clear(Color.White);
}
void WorkAreaForm_Resize(object sender, System.EventArgs e)