Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14906 was 13789, checked in by bburlacu, 9 years ago

#2288:

  • Refactor RunCollectionVariableInteractionNetworkView improving functionality, modularity and code organisation.
  • Small tweaks to the DirectedGraphChart and DirectedGraphChartMode
File size: 4.9 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.Visualization;
28
29namespace HeuristicLab.VariableInteractionNetworks.Views {
30  public class DirectedGraphChartMode : SelectChartMode {
31    public DirectedGraphChartMode(DirectedGraphChart control) : base(control) { }
32
33    public DirectedGraphChart Control {
34      get { return (DirectedGraphChart)chartControl; }
35    }
36
37    public override void HandleOnMouseDoubleClick(object sender, MouseEventArgs e) {
38      try {
39        switch (e.Button) {
40          case MouseButtons.Left:
41            try {
42              chartControl.SuspendRendering();
43              var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
44              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
45                p.Selected = false;
46              var sp = chartControl.Chart.GetPrimitive(e.Location);
47              if (sp != null) sp.Selected = true;
48              if (sp is RectangularPrimitiveBase) {
49                var vertex = Control.GetVertex(sp) as IVertex<IDeepCloneable>;
50                if (vertex != null) {
51                  var content = vertex.Data as IContent;
52                  if (content != null) {
53                    MainFormManager.MainForm.ShowContent(content);
54                  }
55                }
56              }
57            }
58            finally { chartControl.ResumeRendering(); }
59            break;
60        }
61      }
62      finally {
63        base.HandleOnMouseDown(sender, e);
64      }
65    }
66
67    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
68      try {
69        switch (e.Button) {
70          case MouseButtons.Left:
71            var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
72            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
73            var offset = worldLocation - previousWorldLocation;
74            try {
75              chartControl.SuspendRendering();
76              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation))) {
77                var lp = p as LabeledPrimitive;
78                if (lp == null) continue;
79                p.Move(previousWorldLocation, offset);
80                var rect = lp.Primitive as Rectangle;
81                var ell = lp.Primitive as Ellipse;
82                if (rect == null && ell == null) continue;
83                var v = Control.GetVertex(p);
84                if (v == null) continue;
85                // ends of outgoing arcs need to be properly adjusted
86                foreach (var arc in v.InArcs) {
87                  var r = (LabeledPrimitive)Control.GetVertexShape(arc.Source);
88                  var line = (Line)Control.GetArcShape(arc);
89                  var tmp = new Line(this.chartControl.Chart, r.Primitive.Center(), lp.Primitive.Center());
90                  var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp);
91                  if (intersect.Any())
92                    line.SetPosition(tmp.Start, intersect.First());
93                }
94                foreach (var arc in v.OutArcs) {
95                  var r = (LabeledPrimitive)Control.GetVertexShape(arc.Target);
96                  rect = r.Primitive as Rectangle;
97                  ell = r.Primitive as Ellipse;
98                  var line = (Line)Control.GetArcShape(arc);
99                  var tmp = new Line(this.chartControl.Chart, lp.Primitive.Center(), r.Primitive.Center());
100                  var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp);
101                  if (intersect.Any())
102                    line.SetPosition(tmp.Start, intersect.First());
103                }
104              }
105            }
106            finally { chartControl.ResumeRendering(); }
107            break;
108        }
109      }
110      finally {
111        base.HandleOnMouseMove(sender, e);
112      }
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.