Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/NetworkSelectChartMode.cs @ 13077

Last change on this file since 13077 was 13077, checked in by jkarder, 8 years ago

#2205: worked on optimization networks

  • added first version of network visualization
  • updated frame files
File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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
22using System.Linq;
23using System.Windows.Forms;
24using HeuristicLab.Core.Networks;
25using HeuristicLab.Visualization;
26
27namespace HeuristicLab.Networks.Views.NetworkVisualization.Views {
28  public class NetworkSelectChartMode : SelectChartMode {
29    public NetworkSelectChartMode(ChartControl control) : base(control) { }
30
31    public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
32      switch (e.KeyCode) {
33        case Keys.Delete:
34          if (e.KeyCode == Keys.Delete) {
35            try {
36              chartControl.SuspendRendering();
37              var primitives = chartControl.Chart.Group.SelectedPrimitives.ToList();
38              foreach (var connectionLine in primitives.OfType<ConnectionLine>()) {
39                chartControl.Chart.Group.Remove(connectionLine);
40                var startPortRectangle = connectionLine.StartPortRectangle;
41                if (startPortRectangle != null) {
42                  var startPort = (IMessagePort)startPortRectangle.NetworkItem;
43                  if (startPort != null) startPort.ConnectedPort = null;
44                }
45              }
46
47              foreach (var nodeRectangle in primitives.OfType<NodeRectangle>()) {
48                chartControl.Chart.Group.Remove(nodeRectangle);
49                var node = nodeRectangle.NetworkItem;
50                if (node != null) {
51                  var deletedPorts = node.Ports.OfType<IMessagePort>().ToList();
52                  foreach (var port in deletedPorts)
53                    port.ConnectedPort = null;
54
55                  var connectionLines = chartControl.Chart.Group.Primitives.OfType<ConnectionLine>();
56                  foreach (var connectionLine in connectionLines) {
57                    var startPortRectangle = connectionLine.StartPortRectangle;
58                    var endPortRectangle = connectionLine.EndPortRectangle;
59                    if (startPortRectangle != null && endPortRectangle != null) {
60                      var startPort = (IMessagePort)startPortRectangle.NetworkItem;
61                      var endPort = (IMessagePort)endPortRectangle.NetworkItem;
62                      if (startPort != null && endPort != null && deletedPorts.Contains(endPort))
63                        startPort.ConnectedPort = null;
64                    }
65                  }
66
67                  var parent = node.Parent;
68                  if (parent != null)
69                    parent.Nodes.Remove(node);
70                }
71              }
72            } finally { chartControl.ResumeRendering(); }
73          }
74          break;
75      }
76    }
77
78    public override void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) {
79      base.HandleOnMouseDoubleClick(sender, e);
80
81      switch (e.Button) {
82        case MouseButtons.Left:
83          var p = chartControl.Chart.GetPrimitive(e.Location) as NodeRectangle;
84          if (p != null)
85            MainForm.MainFormManager.MainForm.ShowContent(p.NetworkItem);
86          break;
87      }
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.