1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using Netron.Diagramming.Core;
|
---|
27 | using System.Drawing;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
30 | public class OperatorShape : ClassShape {
|
---|
31 |
|
---|
32 | public OperatorShape()
|
---|
33 | : base() {
|
---|
34 | this.additionalConnectors = new List<IConnector>();
|
---|
35 | }
|
---|
36 |
|
---|
37 | private List<IConnector> additionalConnectors;
|
---|
38 | public IEnumerable<string> AdditionalConnectorNames {
|
---|
39 | get { return this.additionalConnectors.Select(c => c.Name); }
|
---|
40 | }
|
---|
41 |
|
---|
42 | private IConnector predecessor;
|
---|
43 | public IConnector Predecessor {
|
---|
44 | get { return this.predecessor; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | private IConnector successor;
|
---|
48 | public IConnector Successor {
|
---|
49 | get { return this.successor; }
|
---|
50 | }
|
---|
51 |
|
---|
52 | private IConnector CreateConnector(string connectorName, Point location) {
|
---|
53 | Connector connector = new Connector(location, this.Model);
|
---|
54 | connector.ConnectorStyle = ConnectorStyle.Square;
|
---|
55 | connector.Parent = this;
|
---|
56 | connector.Name = connectorName;
|
---|
57 | return connector;
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | public void AddConnector(string connectorName) {
|
---|
63 | IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner);
|
---|
64 |
|
---|
65 | this.additionalConnectors.Add(connector);
|
---|
66 | this.Connectors.Add(connector);
|
---|
67 | this.UpdateConnectorLocation();
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void RemoveConnector(string connectorName) {
|
---|
71 | IConnector connector = this.additionalConnectors.Where(c => c.Name == connectorName).FirstOrDefault();
|
---|
72 | if (connector != null) {
|
---|
73 | this.additionalConnectors.Remove(connector);
|
---|
74 | this.Connectors.Remove(connector);
|
---|
75 | this.UpdateConnectorLocation();
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void UpdateConnectorLocation() {
|
---|
80 | if (this.additionalConnectors.Count == 0)
|
---|
81 | return;
|
---|
82 |
|
---|
83 | int spacing = this.Rectangle.Width / this.additionalConnectors.Count;
|
---|
84 | int margin = spacing / 2;
|
---|
85 | int posX = margin + this.Rectangle.X;
|
---|
86 | int posY = this.additionalConnectors[0].Point.Y;
|
---|
87 | for (int i = 0; i < this.additionalConnectors.Count; i++) {
|
---|
88 | this.additionalConnectors[i].Point = new Point(posX, posY);
|
---|
89 | posX += spacing;
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | protected override void Initialize() {
|
---|
95 | base.Initialize();
|
---|
96 |
|
---|
97 | #region Connectors
|
---|
98 | this.Connectors.Clear();
|
---|
99 |
|
---|
100 | predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y));
|
---|
101 | Connectors.Add(predecessor);
|
---|
102 |
|
---|
103 | successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y)));
|
---|
104 | Connectors.Add(successor);
|
---|
105 | #endregion
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|