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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.MainForm;
|
---|
31 | using HeuristicLab.Core;
|
---|
32 | using HeuristicLab.Core.Views;
|
---|
33 | using Netron.Diagramming.Core;
|
---|
34 | using HeuristicLab.Parameters;
|
---|
35 | using HeuristicLab.MainForm.WindowsForms;
|
---|
36 | using HeuristicLab.Collections;
|
---|
37 |
|
---|
38 | namespace 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.RelayoutGraph();
|
---|
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 drag and drop
|
---|
161 | private void OperatorGraphView_DragEnter(object sender, DragEventArgs e) {
|
---|
162 | e.Effect = DragDropEffects.None;
|
---|
163 | Type type = e.Data.GetData("Type") as Type;
|
---|
164 | if ((type != null) && (typeof(IOperator).IsAssignableFrom(type))) {
|
---|
165 | e.Effect = DragDropEffects.Copy;
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | private void OperatorGraphView_DragDrop(object sender, DragEventArgs e) {
|
---|
170 | if (e.Effect != DragDropEffects.None) {
|
---|
171 | IOperator op = e.Data.GetData("Value") as IOperator;
|
---|
172 | IShapeInfo shapeInfo = Factory.CreateShapeInfo(op);
|
---|
173 | Point mouse = new Point(MousePosition.X, MousePosition.Y);
|
---|
174 | Point p = new Point(e.X, e.Y);
|
---|
175 | Point screen = this.PointToScreen(new Point(0, 0));
|
---|
176 | PointF worldPoint = this.graphVisualizationInfoView.Controller.View.WorldToView(new Point(mouse.X - screen.X, mouse.Y - screen.Y));
|
---|
177 |
|
---|
178 | shapeInfo.Location = Point.Round(worldPoint);
|
---|
179 | this.VisualizationInfo.AddShapeInfo(op, shapeInfo);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | #endregion
|
---|
184 |
|
---|
185 | private void selectButton_Click(object sender, EventArgs e) {
|
---|
186 | ITool tool = this.graphVisualizationInfoView.Controller.Tools.Where(t => t.Name == ControllerBase.SelectionToolName).First();
|
---|
187 | tool.IsSuspended = false;
|
---|
188 | tool = this.graphVisualizationInfoView.Controller.Tools.Where(t => t.Name == ControllerBase.PanToolName).First();
|
---|
189 | this.graphVisualizationInfoView.Controller.DeactivateTool(tool);
|
---|
190 | }
|
---|
191 |
|
---|
192 | private void panButton_Click(object sender, EventArgs e) {
|
---|
193 | ITool tool = this.graphVisualizationInfoView.Controller.Tools.Where(t => t.Name == ControllerBase.SelectionToolName).First();
|
---|
194 | tool.IsSuspended = true;
|
---|
195 | this.graphVisualizationInfoView.Controller.ActivateTool(ControllerBase.PanToolName);
|
---|
196 | }
|
---|
197 |
|
---|
198 | private void connectButton_Click(object sender, EventArgs e) {
|
---|
199 | this.graphVisualizationInfoView.Controller.ActivateTool(ControllerBase.ConnectionToolName);
|
---|
200 | }
|
---|
201 |
|
---|
202 | private void relayoutButton_Click(object sender, EventArgs e) {
|
---|
203 | this.graphVisualizationInfoView.RelayoutGraph();
|
---|
204 | }
|
---|
205 |
|
---|
206 | private void zoomAreaButton_Click(object sender, EventArgs e) {
|
---|
207 | this.graphVisualizationInfoView.Controller.ActivateTool(ControllerBase.ZoomAreaToolName);
|
---|
208 | }
|
---|
209 |
|
---|
210 | private void zoomInButton_Click(object sender, EventArgs e) {
|
---|
211 | this.graphVisualizationInfoView.Controller.ActivateTool(ControllerBase.ZoomInToolName);
|
---|
212 | }
|
---|
213 |
|
---|
214 | private void zoomOutButton_Click(object sender, EventArgs e) {
|
---|
215 | this.graphVisualizationInfoView.Controller.ActivateTool(ControllerBase.ZoomOutToolName);
|
---|
216 | }
|
---|
217 | }
|
---|
218 | }
|
---|