1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Drawing.Drawing2D;
|
---|
6 | using System.Drawing;
|
---|
7 | using Netron.Diagramming.Core;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.Netron {
|
---|
10 | internal static class AntsFactory {
|
---|
11 | private static RectAnts mRectangular;
|
---|
12 | public readonly static Pen Pen = new Pen(Color.Black, 1f);
|
---|
13 | static AntsFactory() {
|
---|
14 | Pen.DashStyle = DashStyle.Dash;
|
---|
15 | }
|
---|
16 | public static IAnts GetAnts(object pars, AntTypes type) {
|
---|
17 | switch (type) {
|
---|
18 | case AntTypes.Rectangle:
|
---|
19 | if (mRectangular == null)
|
---|
20 | mRectangular = new RectAnts();
|
---|
21 | Point[] points = (Point[])pars;
|
---|
22 | mRectangular.Start = points[0];
|
---|
23 | mRectangular.End = points[1];
|
---|
24 | return mRectangular;
|
---|
25 | default:
|
---|
26 | return null;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | internal class RectAnts : AbstractAnt {
|
---|
31 | public RectAnts(Point s, Point e)
|
---|
32 | : this() {
|
---|
33 | this.Start = s;
|
---|
34 | this.End = e;
|
---|
35 |
|
---|
36 | }
|
---|
37 |
|
---|
38 | public RectAnts()
|
---|
39 | : base() {
|
---|
40 | Pen.DashStyle = DashStyle.Dash;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public override void Paint(Graphics g) {
|
---|
44 | if (g == null)
|
---|
45 | return;
|
---|
46 | g.DrawRectangle(AntsFactory.Pen, Start.X, Start.Y, End.X - Start.X, End.Y - Start.Y);
|
---|
47 |
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | internal abstract class AbstractAnt : IAnts {
|
---|
52 | private Point mStart;
|
---|
53 | public Point Start {
|
---|
54 | get {
|
---|
55 | return mStart;
|
---|
56 | }
|
---|
57 | set {
|
---|
58 | mStart = value;
|
---|
59 | }
|
---|
60 | }
|
---|
61 | private Point mEnd;
|
---|
62 | public Point End {
|
---|
63 | get {
|
---|
64 | return mEnd;
|
---|
65 | }
|
---|
66 | set {
|
---|
67 | mEnd = value;
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public Rectangle Rectangle {
|
---|
72 | get { return new Rectangle(mStart.X, mStart.Y, mEnd.X - mStart.X, mEnd.Y - mStart.Y); }
|
---|
73 | set {
|
---|
74 | mStart = new Point(value.X, value.Y);
|
---|
75 | mEnd = new Point(value.Right, value.Bottom);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | public abstract void Paint(Graphics g);
|
---|
80 | }
|
---|
81 | }
|
---|
82 | internal enum AntTypes {
|
---|
83 | Rectangle
|
---|
84 | }
|
---|
85 | }
|
---|