Создание программы-интерпретатора блок-схем
Дипломная работа - Компьютеры, программирование
Другие дипломы по предмету Компьютеры, программирование
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)
{.Width = ClientSize.Width;.Height = ClientSize.Height;(workAreaFormPictureBox.Width < panel1.Width || workAreaFormPictureBox.Height < panel1.Height)
{.Width = panel1.Width;.Height = panel1.Height;
_picture = new Bitmap(panel1.Width, panel1.Height);.Image = _picture;= Graphics.FromImage(workAreaFormPictureBox.Image);.SmoothingMode = SmoothingMode.AntiAlias;();
}
}void workAreaFormPictureBox_MouseMove(object sender, MouseEventArgs e)
{(!Insertion);movementResult = Chart.ProcessMouseMove(e.X, e.Y);= movementResult ? Cursors.Hand : Cursors.Arrow;(true);
}void workAreaFormPictureBox_MouseDoubleClick(object sender, MouseEventArgs e)
{block = Chart.ProcessMouseDoubleClick(e.X, e.Y);(block == null);(block is RegularBLock)
{= new BlockProreptiesEditor("regular", block, this);
}if (block is ConditionBlock)
{= new BlockProreptiesEditor("condition", block, this);
}if (block is LoopBlock)
{= new BlockProreptiesEditor("loop_for", block, this);
}.MdiParent = this.MdiParent;.Show();
}void DeleteBLock()
{(Chart.DeleteSelectedBlock())
{();();
}
}void ClearChart()
{.ClearChart();();();
}
}
}
) BlockProreptiesEditor.csSystem;System.Drawing;System.Windows.Forms;flowchart
{partial class BlockProreptiesEditor : Form
{Block blockToEdit;WorkAreaForm workAreaForm;string loopType;BlockProreptiesEditor(string type, Block block, WorkAreaForm workAreaForm)
{= type;();.blockToEdit = block;.workAreaForm = workAreaForm;.Text = block.Text;(type)
{"regular":.Text = "Текст";= "Обычный блок";();;"condition":.Text = "Условие";= "Условие";();;"loop_for":.Text = " Цикл";= "Цикл";.SelectedIndex = 0;;"loop_while":.Text = "Предусловие";= "Цикл";.SelectedIndex = 1;;"loop_do_while":.Text = "Постусловие";= "Цикл";.SelectedIndex = 2;;
}
}void AdjustFormFormForConditionOrRegular()
{.Visible = false;.Visible = false;= 300;= 170;.Top = 15;.Left = 1;.Top = 12;.Left = 55;.Height = 80;
}void loopTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
{(loopTypeComboBox.SelectedIndex)
{0:.Text = " Цикл";= "loop_for";;1:.Text = "Предусловие";= "loop_while";;2:.Text = "Постусловие";= "loop_do_while";;
}
}void cancelButton_Click(object sender, EventArgs e)
{();
}void okButton_Click(object sender, EventArgs e)
{(loopType == "loop_do_while")
{.Text = "do";.TextAtTheEnd = blockContentTextBox.Text;
}
{.Text = blockContentTextBox.Text;.TextAtTheEnd = "";
}(Block block in workAreaForm.Chart.blocks)
{.isSelected = false;
}.UpdateChart();.UpdateCode();();
}void BlockProreptiesEditor_Load(object sender, EventArgs e)
{= new Point(400, 150);
}
}
}
) Chart.csSystem;System.Collections.Generic;System.Drawing;flowchart.blocks;System.Xml.Serialization;flowchart
{
[Serializable]class Chart
{ChartMainBlock root;Block selectedBlock;
[XmlIgnore]CodeGenerator codeGen;
[XmlIgnore]List();
[XmlIgnore]List();
[XmlIgnore]int height;
[XmlIgnore]int width;Chart()
{= new ChartMainBlock("main block");rootMainBranch = new Branch("main branch");.Items.Add(rootMainBranch);.Add(root);.Add(rootMainBranch);();();= new CodeGenerator(root);
}void RealignBlocks()
{.AdjustSize();.AdjustPosition(0, 20);= root.width;= root.height+100;
}void RegenerateInsertionPoints()
{.Clear();(root);
}void GenerateInsertionPoints(Block block)
{(block is Branch)
{x = block.X + block.width / 2;(int i = 0; i < block.Items.Count; i++)
{y = block.Items[i].Y;point = new InsertionPoint();.branch = block;.x = x;.y = y;.index = i;.Add(point);(block.Items[i]);
}p = new InsertionPoint();.branch = block;(block.Items.Count == 0)
{.x = x;.y = block.Y + block.height / 2;
}
{.x = x;.y = block.Y + block.height;
}.index = block.Items.Count;.Add(p);
}
{(Block item in block.Items)
{(item);
}
}
}void InsertIntoBranch(Block branch, Block newBlock, int index)
{.Branch = branch;.