
использование объектно-ориентированной концепции;
сохранение результата;
визуализация работы;
обработка ошибок;
Руководство пользователя.
Таким образом, поставленная в рамках данной курсовой работы задача была успешно выполнена.
Список использованных источников
Сайт энциклопедии Wikipedia [Электронный ресурс] : Электрон., текстовые и граф. дан. – URL : http://ru.wikipedia.org/wiki/ /Объектно-ориентированное_программирование (дата обращения: 25.12.2012).
ГОСТ 19.701–90 ЕСПД. Схемы алгоритмов, программ, данных и систем. Условные обозначения и правила выполнения. Введ. 1992–01–01. М : Ордена «Знак почета» Издательство стандартов, 1991. 27 с.
Сайт MSDN [Электронный ресурс] : Электрон., текстовые и граф. дан. – URL : http://msdn.microsoft.com/ru-ru/library/kx37x362%28v=vs.100%29.aspx (дата обращения: 25.12.2012).
Сайт энциклопедии Wikipedia [Электронный ресурс] : Электрон., текстовые и граф. дан. – URL : http://ru.wikipedia.org/Алгоритм (дата обращения: 25.12.2012).
Сайт энциклопедии Wikipedia [Электронный ресурс] : Электрон., текстовые и граф. дан. – URL : http://ru.wikipedia.org/Блок-схема (дата обращения: 25.12.2012).
Приложение А
Листинг программы
«Program.cs»:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace test_app1
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
//--------------------------------------------------------------------------
«my_class.cs»:
//--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
namespace test_app1
{
public static class Settings
{
public static Image BackImg;
public static int Paint_Width, Paint_Height;
public static int GridStep;
}
public abstract class Figure
{
protected int x;
protected int y;
protected int bottom;
protected int right;
protected int size;
protected int width;
protected int height;
protected bool selected;
protected string _Text;
protected int font_offsetX, font_offsetY;
protected Pen _pen;
protected Font _font;
protected PointF posf;
public int X
{
get { return x; }
set
{
x = value;
UpdateFigure();
}
}
public int Y
{
get { return y; }
set
{
y = value;
UpdateFigure();
}
}
public int FontX
{
get { return this.font_offsetX; }
set
{
this.font_offsetX = value;
UpdateFigure();
}
}
public int FontY
{
get { return this.font_offsetY; }
set
{
this.font_offsetY = value;
UpdateFigure();
}
}
public int Width
{
get { return this.width; }
set
{
this.width = value;
UpdateFigure();
}
}
public int Height
{
get { return this.height; }
set
{
this.height = value;
UpdateFigure();
}
}
public void Highlight(Color color)
{
///Выполняет выделение объекта цветом color
this._pen.Color = color;
}
public void Highlight(bool DoHightlight = true)
{
//В зависимости от параметра выполняет выделение объекта цветом //по умолчанию (красный), либо снятие выделения
if (DoHightlight)
{
this._pen.Color = Color.Red;
}
else
{
this._pen.Color = Color.Black;
}
this.selected = DoHightlight;
}
public abstract void Draw(Graphics g);
protected abstract void UpdateFigure();
public bool Covered(int x, int y)
{
if (x >= this.x && x <= this.Right && y >= this.y &&
y <= this.Bottom)
{
return true;
}
else
{
return false;
}
}
public int FontSize
{
set
{
this._font = new Font("Times new roman", value);
UpdateFigure();
}
get { return Convert.ToInt32(this._font.Size); }
}
public void ChangeFont(Font new_font)
{
this._font.Dispose();
this._font = new_font;
}
public string Text
{
get { return _Text; }
set { _Text = value; }
}
public PointF LocationF
{
get { return posf; }
}
public int Bottom
{
get { return this.bottom; }
}
public int Right
{
get { return this.right; }
}
public int GetWidth
{
get { return this.width; }
}
public bool Selected
{
get { return this.selected; }
}
}
public class Action:Figure
{
public Action() { }
public Action(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
_Text = "";
this.height = height;
this.width = width;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~Action()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
this.bottom = this.y + this.height;
this.right = this.x + this.width;
}
public override void Draw(Graphics g)
{
g.DrawRectangle(_pen, this.x, this.y, this.width, this.height);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class Begin:Figure
{
protected struct TArc
{
public int x1, y, x2;
public int Size;
}
protected struct TLine
{
public int x1, y, x2;
}
TArc arc;
TLine line1, line2;
public Begin(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~Begin()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
arc.Size = height;
arc.x1 = this.x; //дуга левая
arc.x2 = arc.x1 + width - (arc.Size); //дуга правая
arc.y = this.y;
this.bottom = this.y + this.height;
this.right = this.x + this.width;
line1.x1 = arc.x1 + arc.Size / 2 - 1;
line1.x2 = 1 + arc.x2 + arc.Size /2 ;
line1.y = arc.y; //верхняя линия
line2.x1 = line1.x1;
line2.x2 = line1.x2;
line2.y = line1.y + arc.Size;
}
public override void Draw(Graphics g)
{
g.DrawArc(_pen, arc.x1, arc.y, arc.Size, arc.Size, 90, 180);
g.DrawArc(_pen, arc.x2, arc.y, arc.Size, arc.Size, -90, 180);
g.DrawLine(_pen, line1.x1, line1.y, line1.x2, line1.y);
g.DrawLine(_pen, line2.x1, line2.y, line2.x2, line2.y);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class Condition:Figure
{
public struct TRomb
{
public int xh1, xh2, yh;
public int xv, yv1, yv2;
}
TRomb romb;
public Condition(int x, int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~Condition()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
romb.xh1 = this.x;
romb.yh = this.y + height / 2;
romb.xh2 = romb.xh1 + width;
romb.xv = romb.xh1 + width / 2;
romb.yv1 = romb.yh - height / 2;
romb.yv2 = romb.yh + height / 2;
this.bottom = romb.yv2;
this.right = romb.xh2;
}
public override void Draw(Graphics g)
{
g.DrawLine(_pen, romb.xh1, romb.yh, romb.xv, romb.yv1);
g.DrawLine(_pen, romb.xv, romb.yv1, romb.xh2, romb.yh);
g.DrawLine(_pen, romb.xh2, romb.yh, romb.xv, romb.yv2);
g.DrawLine(_pen, romb.xv, romb.yv2, romb.xh1, romb.yh);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class Cycle:Figure
{
public struct TCycle
{
public int xh1, xh2, yh; //horizontal
public int xi1, xi2, yu, yd; //vertical
}
TCycle cl;
public Cycle(int x,int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~Cycle()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
cl.xh1 = x;
cl.yh = y + height / 2;
this.bottom = this.y + this.height;
this.right = this.x + this.width;
cl.xh2 = cl.xh1 + width;
cl.xi1 = cl.xh1 + ((width - height) / 2);
cl.xi2 = cl.xi1 + height;
cl.yu = cl.yh - height / 2;
cl.yd = cl.yu + height;
}
public override void Draw(Graphics g)
{
g.DrawLine(_pen, cl.xh1, cl.yh, cl.xi1, cl.yu);
g.DrawLine(_pen, cl.xi1, cl.yu, cl.xi2, cl.yu);
g.DrawLine(_pen, cl.xi2, cl.yu, cl.xh2, cl.yh);
g.DrawLine(_pen, cl.xh2, cl.yh, cl.xi2, cl.yd);
g.DrawLine(_pen, cl.xi2, cl.yd, cl.xi1, cl.yd);
g.DrawLine(_pen, cl.xi1, cl.yd, cl.xh1, cl.yh);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class Subroutine:Action
{
protected struct TLines
{
public int xl, yl1, yl2;
public int xr, yr1, yr2;
}
protected PointF TextPos;
TLines lines;
public Subroutine(int x,int y, int width, int height)
{
this.x = x;
this.y = y;
_Text = "";
this.height = height;
this.width = width;
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
UpdateFigure();
}
~Subroutine()
{
_pen.Dispose();
_font.Dispose();
}
public override void Draw(Graphics g)
{
g.DrawRectangle(_pen, this.x, this.y, this.width, this.height);
g.DrawLine(_pen, lines.xl, lines.yl1, lines.xl, lines.yl2);
g.DrawLine(_pen, lines.xr, lines.yl1, lines.xr, lines.yl2);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, this.posf);
}
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
this.bottom = this.y + this.height;
this.right = this.x + this.width;
lines.xl = x + Convert.ToInt32(height * 0.15);
lines.yl1 = y; //begin 1
lines.yl2 = y + height; //end 1
lines.xr = x + width - Convert.ToInt32(height * 0.15);
}
}
public class IOData:Figure
{
public struct TPar
{
public int xu1, xu2, yu;
public int xd1, xd2, yd;
}
TPar par;
public IOData(int x,int y, int width, int height)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~IOData()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
this.bottom = this.y + this.height;
this.right = this.x + this.width;
int k = Convert.ToInt32(0.25 * height);
par.xu1 = x;
par.xu2 = par.xu1 + width;
par.yu = y;
par.xd1 = par.xu1 - k;
par.xd2 = par.xd1 + width;
par.yd = par.yu + height;
}
public override void Draw(Graphics g)
{
g.DrawLine(_pen, par.xu1, par.yu, par.xu2, par.yu);
g.DrawLine(_pen, par.xu2, par.yu, par.xd2, par.yd);
g.DrawLine(_pen, par.xd2, par.yd, par.xd1, par.yd);
g.DrawLine(_pen, par.xd1, par.yd, par.xu1, par.yu);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class Cycle2 : Figure
{
public struct TCycle
{
public int xu1, xu2, xl, xr;
public int yu, ym, yd;
}
bool isEnd;
TCycle _c;
public Cycle2(int x, int y, int width, int height,
bool isEnd = false) //isEnd – фигура - окончание цикла
{
this.x = x;
this.y = y;
this.isEnd = isEnd;
this.width = width;
this.height = height;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~Cycle2()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
int k = Convert.ToInt32(0.15 * height);
this.bottom = this.y + this.height;
if (!isEnd)
{
this.right = this.x + this.width - k;
_c.xu1 = x;
_c.yu = y;
_c.xu2 = _c.xu1 + width - k*2;
_c.xl = _c.xu1 - k;
_c.xr = _c.xl + width;
_c.ym = _c.yu + k;
_c.yd = _c.yu + height;
}
else
{
this.right = this.x + this.width;
_c.xl = x;
_c.xr = _c.xl + width;
_c.yu = y;
_c.ym = _c.yu + height - k;
_c.xu1 = _c.xl + k;
_c.xu2 = _c.xr - k;
_c.yd = _c.yu + height;
}
}
public override void Draw(Graphics g)
{
if (!isEnd)
{
g.DrawLine(_pen, _c.xu1, _c.yu, _c.xu2, _c.yu);
g.DrawLine(_pen, _c.xu2, _c.yu, _c.xr, _c.ym);
g.DrawLine(_pen, _c.xr, _c.ym, _c.xr, _c.yd);
g.DrawLine(_pen, _c.xr, _c.yd, _c.xl, _c.yd);
g.DrawLine(_pen, _c.xl, _c.yd, _c.xl, _c.ym);
g.DrawLine(_pen, _c.xl, _c.ym, _c.xu1, _c.yu);
}
else
{
g.DrawLine(_pen, _c.xl, _c.yu, _c.xr, _c.yu);
g.DrawLine(_pen, _c.xr, _c.yu, _c.xr, _c.ym);
g.DrawLine(_pen, _c.xr, _c.ym, _c.xu2, _c.yd);
g.DrawLine(_pen, _c.xu2, _c.yd, _c.xu1, _c.yd);
g.DrawLine(_pen, _c.xu1, _c.yd, _c.xl, _c.ym);
g.DrawLine(_pen, _c.xl, _c.ym, _c.xl, _c.yu);
}
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class JumpCurrent : Figure
{
public JumpCurrent(int x,int y, int size)
{
this.x = x;
this.y = y;
this.width = size;
this.height = size;
this.size = size;
UpdateFigure();
_Text = "";
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~JumpCurrent()
{
_pen.Dispose();
_font.Dispose();
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
this.size = this.width;
this.bottom = this.y + this.size;
this.right = this.x + this.size;
}
public override void Draw(Graphics g)
{
g.DrawEllipse(_pen, x, y, size, size);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class JumpPage:Figure
{
public struct TJump
{
public int xL, xR, xD;
public int yU1, yU2, yD;
}
TJump jump;
public JumpPage(int x,int y, int size)
{
this.x = x;
this.y = y;
this.size = size;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
_font = new Font("Times new roman", 10);
}
~JumpPage()
{
_pen.Dispose();
_font.Dispose();
}
public int Size
{
get { return this.size; }
set
{
size = value;
UpdateFigure();
}
}
protected override void UpdateFigure()
{
this.posf.X = this.x + this.font_offsetX;
this.posf.Y = this.y + this.font_offsetY;
this.width = size;
this.height = size;
this.size = width;
this.bottom = this.y + this.size;
this.right = this.x + this.size;
jump.xL = x;
jump.yU1 = y;
jump.xR = jump.xL + size;
jump.yU2 = jump.yU1 + size / 2;
jump.xD = jump.xL + size / 2;
jump.yD = jump.yU1 + size;
}
public override void Draw(Graphics g)
{
g.DrawLine(_pen, jump.xL, jump.yU1, jump.xR, jump.yU1);
g.DrawLine(_pen, jump.xR, jump.yU1, jump.xR, jump.yU2);
g.DrawLine(_pen, jump.xR, jump.yU2, jump.xD, jump.yD);
g.DrawLine(_pen, jump.xD, jump.yD, jump.xL, jump.yU2);
g.DrawLine(_pen, jump.xL, jump.yU2, jump.xL, jump.yU1);
if (_Text != "")
{
g.DrawString(_Text, _font, Brushes.Black, posf);
}
}
}
public class TLine
{
protected int x;
protected int y;
protected Point end;
protected Pen _pen;
protected bool UseArrow;
int y2, xl, xr;
protected Figure ConnectedFirst, ConnectedSecond;
public int X
{
get { return x; }
set { x = value; }
}
public int Y
{
get { return y; }
set { y = value; }
}
public Figure SetFirstConnect
{
get { return this.ConnectedFirst; }
set { this.ConnectedFirst = value; }
}
public Figure SetsecondConnect
{
get { return this.ConnectedSecond; }
set { this.ConnectedSecond = value; }
}
public void Highlight(bool Param)
{
if (Param)
{
this._pen.Color = Color.Red;
}
else
{
this._pen.Color = Color.Black;
}
}
public bool Covered(int x, int y)
{
if (x >= this.x && x <= this.x + this._pen.Width+3 &&
y >= this.y && y <= this.end.Y)
{
return true;
}
else
{
return false;
}
}
public TLine(Figure FirstFigure, Figure SecondFigure,
bool UseArrow = false)
{
this.ConnectedFirst = FirstFigure;
this.ConnectedSecond = SecondFigure;
this.UseArrow = UseArrow;
UpdateFigure();
_pen = new Pen(Color.Black, 2);
}
public void Draw(Graphics g)
{
g.DrawLine(_pen, x, y, end.X, end.Y);
if (UseArrow)
{
g.DrawLine(_pen, end.X, end.Y, xl, y2);
g.DrawLine(_pen, end.X, end.Y, xr, y2);
}
}
public void UpdateFigure()
{
this.x = ConnectedFirst.Right - ConnectedFirst.Width/2;
end.X = ConnectedSecond.Right - ConnectedSecond.Width/2;
if (ConnectedFirst.Y < ConnectedSecond.Y)
{
this.y = ConnectedFirst.Bottom;
end.Y = ConnectedSecond.Y;
y2 = end.Y - 8;
}
else
{
this.y = ConnectedFirst.Y;
end.Y = ConnectedSecond.Bottom;
y2 = end.Y + 8;
}
xl = end.X - 3;
xr = end.X + 3;
}
~TLine()
{
_pen.Dispose();
}
}
}
//--------------------------------------------------------------------------
«Form1.cs»:
//--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace test_app1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Process p = new Process();
bool isDragging = false;
sbyte pressed = -1; //ничего не нажато
fPageSettings x;
int lastClick = -1; //не было предыдущего клика
bool SomethingSelected = false;
int line_selected = -1;
int x_start, y_start;
List<Figure> shapes = new List<Figure>();
List<TLine> lines = new List<TLine>();
private void bAction_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
int width = 60;
int height = 20;
int X = (bAction.Width - width) / 2;
int Y = (bAction.Height - height) / 2;
e.Graphics.DrawRectangle(p, X, Y, width, height);
}
private void bFigureButtons_Click(object sender, EventArgs e)
{
if (pressed == -1) //если ничего не нажато
{
(sender as Button).BackColor = Color.FromArgb(255,155,55);
pressed = (sbyte)(sender as Button).TabIndex;
}
else //если что-то было нажато
{
if (pressed != (sender as Button).TabIndex)
//второй раз нажата другая кнопка
{
foreach (Button b in grTools.Controls)
{
b.BackColor = Control.DefaultBackColor;
}
(sender as Button).BackColor = Color.FromArgb(255,173,91);
pressed = (sbyte)(sender as Button).TabIndex;
}
else
{
pressed = -1;
(sender as Button).BackColor = Control.DefaultBackColor;
}
}
}
private void bSubroutine_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
int width = 60;
int height = 20;
int X = (bSubroutine.Width - width) / 2;
int Y = (bSubroutine.Height - height) / 2;
int xl = X + Convert.ToInt32(height * 0.15);
int yl1 = Y; //begin 1
int yl2 = Y + height; //end 1
int xr = X + width - Convert.ToInt32(height * 0.15);
e.Graphics.DrawRectangle(p, X, Y, width, height);
e.Graphics.DrawLine(p, xl, yl1, xl, yl2);
e.Graphics.DrawLine(p, xr, yl1, xr, yl2);
}
private void bCondition_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int width = 60;
int height = 20;
int X = (bCondition.Width - width) / 2;
int Y = (height / 2)+7;
int xh1 = X;
int yh = Y;
int xh2 = xh1 + width;
int xv = xh1 + width / 2;
int yv1 = yh - height / 2;
int yv2 = yh + height / 2;
e.Graphics.DrawLine(p, xh1, yh, xv, yv1);
e.Graphics.DrawLine(p, xv, yv1, xh2, yh);
e.Graphics.DrawLine(p, xh2, yh, xv, yv2);
e.Graphics.DrawLine(p, xv, yv2, xh1, yh);
}
private void bCycle_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int width = 60;
int height = 20;
int X = (bCycle.Width - width) / 2;
int Y = 16;
int xh1 = X;
int yh = Y;
int xh2 = xh1 + width;
int xi1 = xh1 + ((width - height) / 2);
int xi2 = xi1 + height;
int yu = yh - height / 2;
int yd = yu + height;
e.Graphics.DrawLine(p, xh1, yh, xi1, yu);
e.Graphics.DrawLine(p, xi1, yu, xi2, yu);
e.Graphics.DrawLine(p, xi2, yu, xh2, yh);
e.Graphics.DrawLine(p, xh2, yh, xi2, yd);
e.Graphics.DrawLine(p, xi2, yd, xi1, yd);
e.Graphics.DrawLine(p, xi1, yd, xh1, yh);
}
private void bBegin_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int width = 50;
int height = 20;
int X = 9;
int Y = 6;
int aSize = height;
int ax1 = X; //дуга левая
int ax2 = ax1 + width - (aSize / 2); //дуга правая
int ay = Y;
int line1_x1 = ax1 + aSize / 2 - 1;
int line1_x2 = 1 + ax2 + aSize / 2;
int line1_y = ay; //верхняя линия
int line2_x1 = line1_x1;
int line2_x2 = line1_x2;
int line2_y = line1_y + aSize;
e.Graphics.DrawArc(p, ax1, ay, aSize, aSize, 90, 180);
e.Graphics.DrawArc(p, ax2, ay, aSize, aSize, -90, 180);
e.Graphics.DrawLine(p, line1_x1, line1_y, line1_x2, line1_y);
e.Graphics.DrawLine(p, line2_x1, line2_y, line2_x2, line2_y);
}
private void bIO_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int width = 50;
int height = 20;
int k = Convert.ToInt32(0.25 * height);
int X = 16;
int Y = 7;
int xu1 = X;
int xu2 = xu1 + width;
int yu = Y;
int xd1 = xu1 - k;
int xd2 = xd1 + width;
int yd = yu + height;
e.Graphics.DrawLine(p, xu1, yu, xu2, yu);
e.Graphics.DrawLine(p, xu2, yu, xd2, yd);
e.Graphics.DrawLine(p, xd2, yd, xd1, yd);
e.Graphics.DrawLine(p, xd1, yd, xu1, yu);
}
private void bJumpCurrent_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int size = 20;
int X = (bJumpCurrent.Width / 2)-size/2;
int Y = (bJumpCurrent.Height / 2)-size/2;
e.Graphics.DrawEllipse(p, X, Y, size, size);
}
private void bJumpDoc_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
int size = 20;
int X = (bJumpDoc.Width / 2) - size / 2;
int Y = (bJumpDoc.Height / 2) - size / 2;
int xL = X;
int yU1 = Y;
int xR = xL + size;
int yU2 = yU1 + size / 2;
int xD = xL + size / 2;
int yD = yU1 + size;
e.Graphics.DrawLine(p, xL, yU1, xR, yU1);
e.Graphics.DrawLine(p, xR, yU1, xR, yU2);
e.Graphics.DrawLine(p, xR, yU2, xD, yD);
e.Graphics.DrawLine(p, xD, yD, xL, yU2);
e.Graphics.DrawLine(p, xL, yU2, xL, yU1);
}
private void bCycle2_Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
int width = 55;
int height = 20;
int k = Convert.ToInt32(height * 0.15);
int X = 3 + (bCycle2.Width - width) / 2;
int Y = (bCycle2.Height - height) / 2;
int xu1 = X;
int yu = Y;
int xu2 = xu1 + width - k * 2;
int xl = xu1 - k;
int xr = xl + width;
int ym = yu + k;
int yd = yu + height;
e.Graphics.DrawLine(p, xu1, yu, xu2, yu);
e.Graphics.DrawLine(p, xu2, yu, xr, ym);
e.Graphics.DrawLine(p, xr, ym, xr, yd);
e.Graphics.DrawLine(p, xr, yd, xl, yd);
e.Graphics.DrawLine(p, xl, yd, xl, ym);
e.Graphics.DrawLine(p, xl, ym, xu1, yu);
}
private void bCycle2__Paint(object sender, PaintEventArgs e)
{
Pen p = new Pen(Color.Black, 1);
int width = 55;
int height = 20;
int k = Convert.ToInt32(height * 0.15);
int X = (bCycle2.Width - width) / 2;
int Y = (bCycle2.Height - height) / 2;
int xl = X;
int xr = xl + width;
int yu = Y;
int ym = yu + height - k;
int xu1 = xl + k;
int xu2 = xr - k;
int yd = yu + height;
e.Graphics.DrawLine(p, xl, yu, xr, yu);
e.Graphics.DrawLine(p, xr, yu, xr, ym);
e.Graphics.DrawLine(p, xr, ym, xu2, yd);
e.Graphics.DrawLine(p, xu2, yd, xu1, yd);
e.Graphics.DrawLine(p, xu1, yd, xl, ym);
e.Graphics.DrawLine(p, xl, ym, xl, yu);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
foreach (TLine s in lines)
{
s.Draw(e.Graphics);
}
foreach (Figure s in shapes)
{
s.Draw(e.Graphics);
}
}
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int found = -1; //ничего не найдено
foreach (Figure s in shapes) //ищем перекрытую мышью фигуру
{
if (s.Covered(e.X, e.Y))
{
found = shapes.IndexOf(s); //запоминаем ее индекс
break;
}
}
if (found == -1) //если мышь на пустом месте
{
if (pressed >= 0) //если выбрана фигура
{
lastClick = -1;
switch (pressed) //ищем нужную и рисуем
{
case 1:
shapes.Add(new Action(e.X, e.Y, 100, 40));
Refresh();
break;
case 2:
shapes.Add(new Condition(e.X, e.Y, 100, 40));
Refresh();
break;
case 3:
shapes.Add(new Subroutine(e.X, e.Y, 100, 40));
Refresh();
break;
case 4:
shapes.Add(new Cycle(e.X, e.Y, 100, 40));
Refresh();
break;
case 5:
shapes.Add(new IOData(e.X, e.Y, 100, 40));
Refresh();
break;
case 6:
shapes.Add(new Begin(e.X, e.Y, 100, 40));
Refresh();
break;
case 7:
shapes.Add(new Cycle2(e.X, e.Y, 100, 40));
Refresh();
break;
case 8:
shapes.Add(new Cycle2(e.X, e.Y, 100, 40, true));
Refresh();
break;
case 9:
shapes.Add(new JumpPage(e.X, e.Y, 40));
Refresh();
break;
case 10:
shapes.Add(new JumpCurrent(e.X, e.Y, 40));
Refresh();
break;
}
}
}
else //если что-то нашлось
{
if (lastClick == -1) //если нажатие "первое"
{
shapes[found].Highlight(Color.Green); //выделяем
panel1.Refresh();
lastClick = found; //считаем нажатие не первым
}
else //иначе (если было нажатие до этого)
{
lines.Add(new TLine(shapes[lastClick], shapes[found], true)); //добавляем линию связи
shapes[lastClick].Highlight(false);
panel1.Refresh();
lastClick = -1;
}
}
}
else
{
if (e.Button == MouseButtons.Right)
{
bool found = false;
foreach (Figure s in shapes)
{
if (s.Covered(e.X, e.Y))
{
s.Highlight();
tbFontSize.Text = Convert.ToString(s.FontSize);
tbText.Text = s.Text;
found = true;
SomethingSelected = true;
}
}
if (!found)
{
SomethingSelected = false;
foreach (Figure s in shapes)
{
s.Highlight(false);
}
tbFontSize.Text = "";
}
foreach (TLine l in lines)
{
if (l.Covered(e.X, e.Y))
{
l.Highlight(true);
line_selected = lines.IndexOf(l);
break;
}
}
panel1.Refresh();
if (! SomethingSelected)
{
tbFontSize.Enabled = false;
bSetFontSize.Enabled = false;
}
else
{
tbFontSize.Enabled = true;
}
}
else
{
if (e.Button == MouseButtons.Middle && SomethingSelected)
{
x_start = e.X;
y_start = e.Y;
isDragging ^= true;
}
}
}
}
private void miPageSettings_Click(object sender, EventArgs e)
{
x.ShowDialog();
panel1.Width = Settings.Paint_Width;
panel1.Height = Settings.Paint_Height;
panel1.BackgroundImage = Settings.BackImg;
}
private void Form1_Load(object sender, EventArgs e)
{
x = new fPageSettings();
p.StartInfo.FileName = "help.chm";
p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo.UseShellExecute = true;
}
public void UpdateLines()
{
foreach (TLine l in lines)
{
l.UpdateFigure();
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (SomethingSelected && isDragging)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
s.X += e.X - x_start;
s.Y += e.Y - y_start;
}
}
UpdateLines();
x_start = e.X;
y_start = e.Y;
panel1.Refresh();
}
}
private void bHp_Click(object sender, EventArgs e)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
if (cbTextPos.Checked)
{
s.FontY--;
}
else
{
s.Height++;
}
}
}
UpdateLines();
panel1.Refresh();
}
private void bHm_Click(object sender, EventArgs e)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
if (cbTextPos.Checked)
{
s.FontY++;
}
else
{
s.Height--;
}
}
}
UpdateLines();
panel1.Refresh();
}
private void bWm_Click(object sender, EventArgs e)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
if (cbTextPos.Checked)
{
s.FontX--;
}
else
{
s.Width--;
}
}
}
UpdateLines();
panel1.Refresh();
}
private void bWp_Click(object sender, EventArgs e)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
if (cbTextPos.Checked)
{
s.FontX++;
}
else
{
s.Width++;
}
}
}
UpdateLines();
panel1.Refresh();
}
private void tbText_TextChanged(object sender, EventArgs e)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
s.Text = tbText.Text;
}
}
panel1.Refresh();
}
private void miSave_Click(object sender, EventArgs e)
{
DialogResult dr = save_dialog1.ShowDialog();
if (dr == DialogResult.OK)
{
Graphics g;
Image Img = new Bitmap(panel1.Width, panel1.Height);
g = Graphics.FromImage(Img);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
foreach (TLine s in lines)
{
s.Draw(g);
}
foreach (Figure s in shapes)
{
s.Draw(g);
}
Img.Save(save_dialog1.FileName);
}
}
private void tbFontSize_TextChanged(object sender, EventArgs e)
{
bool flag = true;
if (tbFontSize.Text != "")
{
for (int i = 0; i < tbFontSize.Text.Length; i++)
{
if (tbFontSize.Text[i] < '0' || tbFontSize.Text[i] > '9')
{
flag = false;
break;
}
}
if (flag)
{
if (Convert.ToInt32(tbFontSize.Text) == 0)
{
flag = false;
}
}
}
else
{
flag = false;
}
bSetFontSize.Enabled = flag;
}
private void bSetFontSize_Click(object sender, EventArgs e)
{
tbFontSize.Enabled = false;
foreach (Figure s in shapes)
{
if (s.Selected)
{
tbFontSize.Enabled = true;
s.FontSize = Convert.ToInt32(tbFontSize.Text);
}
}
panel1.Refresh();
}
private void bRemove_Click(object sender, EventArgs e)
{
int temp = 0;
if (line_selected > -1)
{
lines.RemoveAt(line_selected);
line_selected = -1;
}
if (SomethingSelected && !isDragging)
{
foreach (Figure s in shapes)
{
if (s.Selected)
{
temp = shapes.IndexOf(s);
break;
}
}
shapes.RemoveAt(temp);
}
panel1.Refresh();
}
private void miHelp_Click(object sender, EventArgs e)
{
p.Start();
}
}
}
//--------------------------------------------------------------------------
«fPageSettings.cs»:
//--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test_app1
{
public partial class fPageSettings : Form
{
const double dpi_cm = 96 / 2.54;
public Image img;
public fPageSettings()
{
InitializeComponent();
}
private void cbPages_SelectionChangeCommitted(object sender, EventArgs e)
{
rbLandscape.Enabled = true;
switch (cbPages.SelectedIndex)
{
case 0:
tbSizeW.Text = "841";
tbSizeH.Text = "1189";
break;
case 1:
tbSizeW.Text = "594";
tbSizeH.Text = "841";
break;
case 2:
tbSizeW.Text = "420";
tbSizeH.Text = "594";
break;
case 3:
tbSizeW.Text = "297";
tbSizeH.Text = "420";
break;
case 4:
tbSizeW.Text = "210";
tbSizeH.Text = "297";
rbLandscape.Enabled = false;
rbPortrait.Checked = true;
break;
}
}
private void fPageSettings_Load(object sender, EventArgs e)
{
cbPages.SelectedIndex = 4;
cbPages_SelectionChangeCommitted(cbPages, null);
}
private void bOK_Click(object sender, EventArgs e)
{
Settings.GridStep = Convert.ToInt32(tbGreedStep.Text);
float step_px = Convert.ToSingle(((Settings.GridStep * dpi_cm) / 10));
int h = Convert.ToInt32(Convert.ToInt32(tbSizeH.Text) / 10 * dpi_cm);
int w = Convert.ToInt32(Convert.ToInt32(tbSizeW.Text) / 10 * dpi_cm);
if (rbPortrait.Checked)
{
Settings.Paint_Width = Math.Min(w, h);
Settings.Paint_Height = Math.Max(w, h);
}
else
{
Settings.Paint_Width = Math.Max(w, h);
Settings.Paint_Height = Math.Min(w, h);
}
w = Settings.Paint_Width;
h = Settings.Paint_Height;
if (cbShowGrid.Checked)
{
Graphics g;
Settings.BackImg = new Bitmap(w, h);
g = Graphics.FromImage(Settings.BackImg);
Pen pen = new Pen(Color.FromArgb(127, 127, 127), (float)1);
float limit = h / step_px;
float _s = step_px;
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
for (int i = 0; i < limit; i++) //horizontal lines
{
g.DrawLine(pen, (float)0,(float)_s,(float)w-1,(float)_s);
_s += step_px;
}
limit = w / step_px;
_s = step_px;
for (int i = 0; i < limit; i++) //vertical lines
{
g.DrawLine(pen,(float)_s,(float)0,(float)_s,(float)h-1);
_s += step_px;
}
}
this.Close();
}
private void rbDefinedSize_CheckedChanged(object sender, EventArgs e)
{
cbPages.Enabled = true;
tbSizeH.Enabled = false;
tbSizeW.Enabled = false;
}
private void rbUserSize_CheckedChanged(object sender, EventArgs e)
{
cbPages.Enabled = false;
tbSizeH.Enabled = true;
tbSizeW.Enabled = true;
}
private void tbSize_TextChanged(object sender, EventArgs e)
{
if (tbSizeH.Text != "" && tbSizeW.Text != "")
{
bOK.Enabled = true;
}
else
{
bOK.Enabled = false;
}
}
private void tbGreedStep_TextChanged(object sender, EventArgs e)
{
bool flag = true;
if (tbGreedStep.Text != "")
{
for (int i = 0; i < tbGreedStep.Text.Length; i++)
{
if (tbGreedStep.Text[i] < '0' || tbGreedStep.Text[i] > '9')
{
flag = false;
break;
}
}
if (flag)
{
if (Convert.ToInt32(tbGreedStep.Text) == 0)
{
flag = false;
}
}
}
else
{
flag = false;
}
bOK.Enabled = flag;
}
}
}
//--------------------------------------------------------------------------