Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.VariableInteractionNetworks/HeuristicLab.VariableInteractionNetworks.Views/3.3/DirectedGraphChartMode.cs @ 13773

Last change on this file since 13773 was 13727, checked in by bburlacu, 8 years ago

#2288: Added directed graph chart and layout class for the visualization of knowledge network graphs. Added RunCollectionVariableInteractionNetworkView and removed the old view.

File size: 5.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Common;
25using HeuristicLab.Core;
26using HeuristicLab.MainForm;
27using HeuristicLab.Problems.DataAnalysis;
28using HeuristicLab.Visualization;
29
30namespace HeuristicLab.VariableInteractionNetworks.Views {
31  public class DirectedGraphChartMode : SelectChartMode {
32    public DirectedGraphChartMode(DirectedGraphChart control) : base(control) { }
33
34    public DirectedGraphChart Control {
35      get { return (DirectedGraphChart)chartControl; }
36    }
37
38    public override void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) {
39      try {
40        switch (e.Button) {
41          case MouseButtons.Left:
42            try {
43              chartControl.SuspendRendering();
44              var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
45              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
46                p.Selected = false;
47              var sp = chartControl.Chart.GetPrimitive(e.Location);
48              if (sp != null) sp.Selected = true;
49              if (sp is RectangularPrimitiveBase) {
50                var vertex = Control.GetVertex(sp) as IVertex<IDeepCloneable>;
51                if (vertex != null) {
52                  var content = vertex.Data as IContent;
53                  if (content != null) {
54                    MainFormManager.MainForm.ShowContent(content);
55                  }
56                }
57              }
58            } finally { chartControl.ResumeRendering(); }
59            break;
60        }
61      } finally {
62        base.HandleOnMouseDown(sender, e);
63      }
64    }
65
66    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
67      try {
68        switch (e.Button) {
69          case MouseButtons.None:
70            try {
71              chartControl.SuspendRendering();
72              var sp = chartControl.Chart.GetPrimitive(e.Location);
73              if (sp is RectangularPrimitiveBase) {
74                var vertex = Control.GetVertex(sp) as IVertex<IDeepCloneable>;
75                var junctionNode = vertex as JunctionNetworkNode;
76                if (junctionNode != null) {
77                  var solution = vertex.Data as IRegressionSolution;
78                  if (solution != null) {
79                    var toolTip = string.Format("Target: {0}\nQuality: {1}", solution.ProblemData.TargetVariable, solution.TrainingRSquared);
80                    Control.ToolTip.SetToolTip(Control, toolTip);
81                  }
82                }
83              }
84            } finally { chartControl.ResumeRendering(); }
85            break;
86          case MouseButtons.Left:
87            var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
88            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
89            var offset = worldLocation - previousWorldLocation;
90            try {
91              chartControl.SuspendRendering();
92              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation))) {
93                var lp = p as LabeledPrimitive;
94                if (lp == null) continue;
95                p.Move(previousWorldLocation, offset);
96                var rect = lp.Primitive as Rectangle;
97                var ell = lp.Primitive as Ellipse;
98                if (rect == null && ell == null) continue;
99                var v = Control.GetVertex(p);
100                if (v == null) continue;
101                // ends of outgoing arcs need to be properly adjusted
102                foreach (var arc in v.InArcs) {
103                  var r = (LabeledPrimitive)Control.GetVertexShape(arc.Source);
104                  var line = (Line)Control.GetArcShape(arc);
105                  var tmp = new Line(this.chartControl.Chart, r.Primitive.Center(), lp.Primitive.Center());
106                  var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp);
107                  if (intersect.Any())
108                    line.SetPosition(tmp.Start, intersect.First());
109                }
110                foreach (var arc in v.OutArcs) {
111                  var r = (LabeledPrimitive)Control.GetVertexShape(arc.Target);
112                  rect = r.Primitive as Rectangle;
113                  ell = r.Primitive as Ellipse;
114                  var line = (Line)Control.GetArcShape(arc);
115                  var tmp = new Line(this.chartControl.Chart, lp.Primitive.Center(), r.Primitive.Center());
116                  var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp);
117                  if (intersect.Any())
118                    line.SetPosition(tmp.Start, intersect.First());
119                }
120              }
121            } finally { chartControl.ResumeRendering(); }
122            break;
123        }
124      } finally {
125        chartControl.UpdatePicture();
126        base.HandleOnMouseMove(sender, e);
127      }
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.