1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Text;
|
---|
25 | using HeuristicLab.Charting;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Collections;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Charting.Grid {
|
---|
30 | public class Gridchart : Chart {
|
---|
31 | private int rows;
|
---|
32 | public int RowCount {
|
---|
33 | get { return rows; }
|
---|
34 | set { rows = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | private int columns;
|
---|
38 | public int ColumnCount {
|
---|
39 | get { return columns; }
|
---|
40 | set { columns = value; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | private Dictionary<string, ICell> myCells;
|
---|
44 | public ICollection<ICell> Cells {
|
---|
45 | get { return myCells.Values; }
|
---|
46 | }
|
---|
47 |
|
---|
48 | private bool dragDropEnabled;
|
---|
49 | public bool DragDropEnabled {
|
---|
50 | get { return dragDropEnabled; }
|
---|
51 | set {
|
---|
52 | if(dragDropEnabled != (bool)value) {
|
---|
53 | dragDropEnabled = (bool)value;
|
---|
54 | foreach(IPrimitive cell in this.Group.Primitives) {
|
---|
55 | if(cell is CellBase) {
|
---|
56 | CellBase b = (CellBase)cell;
|
---|
57 | b.DragDropEnabled = dragDropEnabled;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | private bool displayEmptyCells;
|
---|
65 | public bool DisplayEmptyCells {
|
---|
66 | get { return displayEmptyCells; }
|
---|
67 | set {
|
---|
68 | if(displayEmptyCells != (bool)value) {
|
---|
69 | displayEmptyCells = (bool)value;
|
---|
70 | foreach(IPrimitive cell in this.Group.Primitives) {
|
---|
71 | if (cell is EmptyCell) {
|
---|
72 | EmptyCell e = (EmptyCell)cell;
|
---|
73 | e.Display = displayEmptyCells;
|
---|
74 | }
|
---|
75 | }
|
---|
76 | DragDropEnabled = displayEmptyCells;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public Gridchart(PointD lowerLeft, PointD upperRight)
|
---|
82 | : base(lowerLeft, upperRight) {
|
---|
83 | myCells = new Dictionary<string, ICell>();
|
---|
84 | Mode = ChartMode.Select;
|
---|
85 | displayEmptyCells = true;
|
---|
86 | dragDropEnabled = true;
|
---|
87 | this.Group.Add(new Grid(this, lowerLeft, upperRight, 0, 0));
|
---|
88 | }
|
---|
89 |
|
---|
90 | public Gridchart(double x1, double y1, double x2, double y2)
|
---|
91 | : this(new PointD(x1, y1), new PointD(x2, y2)) {
|
---|
92 | }
|
---|
93 |
|
---|
94 | public void Redim(int rows, int cols) {
|
---|
95 | int oldRowCount = RowCount;
|
---|
96 | int oldColumnCount = ColumnCount;
|
---|
97 | RowCount = rows;
|
---|
98 | ColumnCount = cols;
|
---|
99 | ((Grid)Group.Primitives[Group.Primitives.Count - 1]).SetRowsCols(rows, cols);
|
---|
100 | if(rows < oldRowCount) {
|
---|
101 | for(int i = rows; i < oldRowCount; i++) {
|
---|
102 | for(int j = 0; j < oldColumnCount; j++) {
|
---|
103 | myCells.Remove(GenerateKey(i, j));
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|
107 | if(cols < oldColumnCount) {
|
---|
108 | for(int i = cols; i < oldColumnCount; i++) {
|
---|
109 | for(int j = 0; j < Math.Min(oldRowCount, rows); j++) {
|
---|
110 | myCells.Remove(GenerateKey(j, i));
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | for(int i = oldRowCount; i < rows; i++) {
|
---|
116 | for(int j = 0; j < cols; j++) {
|
---|
117 | this[i, j] = new EmptyCell(this);
|
---|
118 | if(!DisplayEmptyCells)
|
---|
119 | this[i, j].Display = false;
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | for(int i = oldColumnCount; i < cols; i++) {
|
---|
124 | for(int j = 0; j < oldRowCount; j++) {
|
---|
125 | this[j, i] = new EmptyCell(this);
|
---|
126 | if(!DisplayEmptyCells)
|
---|
127 | this[i, j].Display = false;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | private string GenerateKey(int row, int col) {
|
---|
133 | return (row.ToString() + ";" + col.ToString());
|
---|
134 | }
|
---|
135 |
|
---|
136 | public ICell this[int row, int col] {
|
---|
137 | get {
|
---|
138 | ICell cell;
|
---|
139 | if(myCells.TryGetValue(GenerateKey(row, col), out cell)) {
|
---|
140 | return cell;
|
---|
141 | } else {
|
---|
142 | return null;
|
---|
143 | }
|
---|
144 | }
|
---|
145 | set {
|
---|
146 | string key = GenerateKey(row, col);
|
---|
147 | if (myCells.ContainsKey(key)) {
|
---|
148 | myCells.Remove(key);
|
---|
149 | }
|
---|
150 | myCells.Add(key, value);
|
---|
151 | PointD ll = this.LowerLeft;
|
---|
152 | SizeD s = this.Size;
|
---|
153 | double w = s.Width / ColumnCount;
|
---|
154 | double h = s.Width / RowCount;
|
---|
155 | if ((bool) value.Display) {
|
---|
156 | value.RenderCell(new PointD(ll.X + col*w, ll.Y + (RowCount - row - 1)*h), new PointD(ll.X +(col+1)*w, ll.Y + (RowCount - row)*h));
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | public override void Render(Graphics graphics, int width, int height) {
|
---|
162 | base.Render(graphics, width, height);
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|