Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphView.cs @ 2898

Last change on this file since 2898 was 2898, checked in by mkommend, 14 years ago

added details view for parameters (ticket #867)

File size: 8.1 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.MainForm;
31using HeuristicLab.Core;
32using HeuristicLab.Core.Views;
33using Netron.Diagramming.Core;
34using HeuristicLab.Parameters;
35using HeuristicLab.MainForm.WindowsForms;
36using HeuristicLab.Collections;
37
38namespace HeuristicLab.Operators.Views.GraphVisualization {
39  [View("Operator Graph Visualization")]
40  [Content(typeof(OperatorGraph), false)]
41  public partial class OperatorGraphView : ContentView {
42    public OperatorGraphView() {
43      InitializeComponent();
44      Caption = "Operator Graph Visualization";
45
46      this.graphVisualizationInfoView.Controller.OnShowContextMenu += new EventHandler<EntityMenuEventArgs>(Controller_OnShowContextMenu);
47      this.graphVisualizationInfoView.Controller.Model.Selection.OnNewSelection += new EventHandler(Controller_SelectionChanged);
48    }
49
50    public OperatorGraphView(OperatorGraph content)
51      : this() {
52      this.Content = content;
53    }
54
55    public new OperatorGraph Content {
56      get { return (OperatorGraph)base.Content; }
57      set { base.Content = value; }
58    }
59
60    protected override void OnContentChanged() {
61      bool createdVisualizationInfo = false;
62      if (this.VisualizationInfo == null) {
63        this.VisualizationInfo = new GraphVisualizationInfo(this.Content);
64        createdVisualizationInfo = true;
65      }
66      this.graphVisualizationInfoView.Content = this.VisualizationInfo;
67      if (createdVisualizationInfo)
68        this.graphVisualizationInfoView.RelayoutOperatorGraph();
69    }
70
71    private GraphVisualizationInfo VisualizationInfo {
72      get { return Content.VisualizationInfo as GraphVisualizationInfo; }
73      set { this.Content.VisualizationInfo = value; }
74    }
75
76
77    #region connector tooltips
78
79    #endregion
80
81    private void Controller_SelectionChanged(object sender, EventArgs e) {
82      CollectionBase<IDiagramEntity> selectedObjects = this.graphVisualizationInfoView.Controller.Model.Selection.SelectedItems;
83      this.detailsViewHost.ViewType = null;
84      if (selectedObjects.Count == 1) {
85        IShape shape = selectedObjects[0] as IShape;
86        if (shape != null) {
87          IShapeInfo shapeInfo = shape.Tag as ShapeInfo;
88          IOperator op = this.VisualizationInfo.GetOperatorForShapeInfo(shapeInfo);
89          this.detailsViewHost.Content = op;
90          return;
91        }
92      }
93      IConnector connector = this.graphVisualizationInfoView.Controller.Model.Selection.Connector;
94      if (connector != null) {
95        IShape shape = connector.Parent as IShape;
96        string connectorName = connector.Name;
97        if (shape == null) {
98          shape = connector.AttachedTo.Parent as IShape; //connection connector selected
99          connectorName = connector.AttachedTo.Name;
100        }
101        if (shape != null) {
102          IShapeInfo shapeInfo = shape.Tag as ShapeInfo;
103          IOperator op = this.VisualizationInfo.GetOperatorForShapeInfo(shapeInfo);
104          if (connectorName != "Predecessor") {
105            IParameter parameter = op.Parameters.Where(p => p.Name == connectorName).First();
106            this.detailsViewHost.Content = parameter;
107            return;
108          }
109        }
110      }
111      this.detailsViewHost.ViewType = null;
112      this.detailsViewHost.Content = null;
113    }
114
115    #region context menu
116    private void Controller_OnShowContextMenu(object sender, EntityMenuEventArgs e) {
117      IShape shape = this.graphVisualizationInfoView.Controller.Model.GetShapeAt(e.MouseEventArgs.Location);
118      if (shape != null) {
119        IShapeInfo shapeInfo = shape.Tag as IShapeInfo;
120        this.shapeContextMenu.Tag = shapeInfo;
121        PointF worldPoint = this.graphVisualizationInfoView.Controller.View.WorldToView(e.MouseEventArgs.Location);
122        this.shapeContextMenu.Show(this, Point.Round(worldPoint));
123      }
124    }
125
126    private void shapeContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
127      IShapeInfo shapeInfo = this.shapeContextMenu.Tag as ShapeInfo;
128      if (shapeInfo != null) {
129        IOperator op = this.VisualizationInfo.GetOperatorForShapeInfo(shapeInfo);
130        this.initialToolStripMenuItem.Checked = this.Content.InitialOperator == op;
131        this.breakPointToolStripMenuItem.Checked = op.Breakpoint;
132      }
133    }
134
135    private void openViewToolStripMenuItem_Click(object sender, EventArgs e) {
136      IShapeInfo shapeInfo = this.shapeContextMenu.Tag as ShapeInfo;
137      if (shapeInfo != null) {
138        IOperator op = this.VisualizationInfo.GetOperatorForShapeInfo(shapeInfo);
139        MainFormManager.CreateDefaultView(op).Show();
140      }
141    }
142
143    private void initialOperatorToolStripMenuItem_Click(object sender, EventArgs e) {
144      IShapeInfo shapeInfo = this.shapeContextMenu.Tag as ShapeInfo;
145      if (this.VisualizationInfo.InitialShape == shapeInfo)
146        this.VisualizationInfo.InitialShape = null;
147      else
148        this.VisualizationInfo.InitialShape = shapeInfo;
149    }
150
151    private void breakPointToolStripMenuItem_Click(object sender, EventArgs e) {
152      IShapeInfo shapeInfo = this.shapeContextMenu.Tag as ShapeInfo;
153      if (shapeInfo != null) {
154        IOperator op = this.VisualizationInfo.GetOperatorForShapeInfo(shapeInfo);
155        op.Breakpoint = !op.Breakpoint;
156      }
157    }
158    #endregion
159
160    #region methods for toolbar items
161    internal void RelayoutOperatorGraph() {
162      this.graphVisualizationInfoView.RelayoutOperatorGraph();
163    }
164
165    internal void ActivateConnectionTool() {
166      this.graphVisualizationInfoView.ActivateConnectionTool();
167    }
168
169    internal void ActivateZoomAreaTool() {
170      this.graphVisualizationInfoView.ActivateZoomAreaTool();
171    }
172
173    internal void ActivateZoomInTool() {
174      this.graphVisualizationInfoView.ActivateZoomInTool();
175    }
176
177    internal void ActivateZoomOutTool() {
178      this.graphVisualizationInfoView.ActivateZoomOutTool();
179    }
180
181    internal void ActivatePanTool() {
182      this.graphVisualizationInfoView.ActivatePanTool();
183    }
184
185    internal void ActivateSelectTool() {
186      this.graphVisualizationInfoView.ActivateSelectTool();
187    }
188    #endregion
189
190    #region drag and drop
191    private void OperatorGraphView_DragEnter(object sender, DragEventArgs e) {
192      e.Effect = DragDropEffects.None;
193      Type type = e.Data.GetData("Type") as Type;
194      if ((type != null) && (typeof(IOperator).IsAssignableFrom(type))) {
195        e.Effect = DragDropEffects.Copy;
196      }
197    }
198
199    private void OperatorGraphView_DragDrop(object sender, DragEventArgs e) {
200      if (e.Effect != DragDropEffects.None) {
201        IOperator op = e.Data.GetData("Value") as IOperator;
202        IShapeInfo shapeInfo = Factory.CreateShapeInfo(op);
203        Point mouse = new Point(MousePosition.X, MousePosition.Y);
204        Point p = new Point(e.X, e.Y);
205        Point screen = this.PointToScreen(new Point(0, 0));
206        PointF worldPoint = this.graphVisualizationInfoView.Controller.View.WorldToView(new Point(mouse.X - screen.X, mouse.Y - screen.Y));
207
208        shapeInfo.Location = Point.Round(worldPoint);
209        this.VisualizationInfo.AddShapeInfo(op, shapeInfo);
210      }
211    }
212
213    #endregion
214  }
215}
Note: See TracBrowser for help on using the repository browser.