Разработка и экспериментальное исследование редактора схем программ

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

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



>

{.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;.Items.Insert(index, newBlock); ();();

}

Block CreateNewBlock(int type)

{(type)

{(1):regularBLock = new RegularBLock("action");.Add(regularBLock);regularBLock;

(2):conditionBlock = new ConditionBlock("condition");left = new Branch("condition left branch");right = new Branch("condition right branch");

//left.Branch = right.Branch = conditionBlock;.Items.Add(left);.Items.Add(right);.Add(conditionBlock);.Add(left);.Add(right);conditionBlock;

(3):loopBlock = new LoopBlock("loop");.TextAtTheEnd = "loop end";loopBranch = new Branch("loop branch");

//loopBranch.Branch = loopBlock;.Items.Add(loopBranch); .Add(loopBlock);.Add(loopBranch); loopBlock;

:null;

}

}

///

/// Проверить является ли расстояние между двумя точками меньше заданного

/// bool CheckTwoPoints(int x1, int y1, int x2, int y2, int r)

{dx = Math.Abs(x1 - x2);dy = Math.Abs(y1 - y2);dx * dx + dy * dy <= r * r;

}

InsertionPoint GetPointAt(int x, int y)

{(InsertionPoint ip in insertionPoints)

{ (CheckTwoPoints(ip.x, ip.y, x, y, ip.R))

{ip;

}

}null;

}

///

/// Удаляет выбранный блок схемы

///

///

public bool DeleteSelectedBlock()

{(selectedBlock == null)false;

.Branch.Items.Remove(selectedBlock);();

();();true;

}

void UpdateAllBlocksList()

{.Clear();(root);

}

void WalkChart(Block block)

{.Add(block);(var item in block.Items)

{(item);

}

}

void ClearChart()

{.Items[0].Items.Clear();.Clear();();();

}

#region mouse events handling

void ProcessMouseClickInsertion(int mouseX, int mouseY, int blockType)

{insertionPointClicked = GetPointAt(mouseX, mouseY);(insertionPointClicked == null);

newBLock = CreateNewBlock(blockType);(insertionPointClicked.branch, newBLock, insertionPointClicked.index);

}

void ProcessMouseClickBlockSelection(int mouseX, int mouseY)

{= null;(Block block in blocks)

{.isSelected = false;

}

(Block block in blocks)

{(block is Branch || block is ChartMainBlock);

(block.PointInsideBlock(mouseX, mouseY))

{= block;(block);;

}

}

}

bool ProcessMouseMove(int mouseX, int mouseY)

{result = false;(InsertionPoint ip in insertionPoints)

{(CheckTwoPoints(ip.x, ip.y, mouseX, mouseY, ip.R))

{.underCursor = true;= true;

}

{.underCursor = false;

}

}result;

}

Block ProcessMouseDoubleClick(int mouseX, int mouseY)

{(Block block in blocks)

{(block is Branch || block is ChartMainBlock);

(block.PointInsideBlock(mouseX, mouseY))

{block;

}

}null;

}

#endregion

void selectBlock(Block block)

{.isSelected = true;

(block is RegularBLock);

(Block item in block.Items)

{ (item);

}

}

//отрисовка схемыvoid Draw(Graphics g, bool insertion = false)

{.Draw(g);(root, g);

(!insertion) return;

(InsertionPoint insertionPoint in insertionPoints)

{.draw(g);

}

}

void drawBlockItems(Block block, Graphics g)

{(Block item in block.Items)

{.Draw(g);(item, g);

}

}

string GetCode()

{codeGen.GetGeneratedCode();

}

}

}

) CodeGenerator.csSystem;flowchart.blocks;

flowchart

{class CodeGenerator

{Block root;string code;

//новая строкаstring br = Environment.NewLine;int tab = 2;

CodeGenerator(Block root)

{.root = root;

}

string GetGeneratedCode()

{= "";(root, 0);code;<