Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/17/10 11:17:15 (15 years ago)
Author:
mkommend
Message:

new version of graph visualization with menuitems (ticket #867)

Location:
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/HeuristicLab.Operators.Views.GraphVisualization-3.3.csproj

    r2803 r2819  
    9595    <None Include="HeuristicLabOperatorsViewsGraphVisualizationPlugin.cs.frame" />
    9696    <None Include="Properties\AssemblyInfo.frame" />
     97    <Compile Include="ToolBarItems\SelectToolBarItem.cs" />
     98    <Compile Include="ToolBarItems\PanToolBarItem.cs" />
     99    <Compile Include="ToolBarItems\ZoomOutToolBarItem.cs" />
     100    <Compile Include="ToolBarItems\ZoomInToolBarItem.cs" />
     101    <Compile Include="ToolBarItems\ZoomToolBarItem.cs" />
     102    <Compile Include="ToolBarItems\OperatorGraphVisualizationToolBarItemSeparator.cs" />
     103    <Compile Include="ToolBarItems\RelayoutToolBarItem.cs" />
    97104  </ItemGroup>
    98105  <ItemGroup>
     
    100107      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    101108      <Name>HeuristicLab.Collections-3.3</Name>
     109    </ProjectReference>
     110    <ProjectReference Include="..\..\HeuristicLab.Common.Resources\3.2\HeuristicLab.Common.Resources-3.2.csproj">
     111      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
     112      <Name>HeuristicLab.Common.Resources-3.2</Name>
    102113    </ProjectReference>
    103114    <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj">
     
    129140      <Name>HeuristicLab.Operators-3.3</Name>
    130141    </ProjectReference>
     142    <ProjectReference Include="..\..\HeuristicLab.Optimizer\3.3\HeuristicLab.Optimizer-3.3.csproj">
     143      <Project>{C664305E-497C-4533-A140-967DEDB05C19}</Project>
     144      <Name>HeuristicLab.Optimizer-3.3</Name>
     145    </ProjectReference>
     146    <ProjectReference Include="..\..\HeuristicLab.Parameters\3.3\HeuristicLab.Parameters-3.3.csproj">
     147      <Project>{56F9106A-079F-4C61-92F6-86A84C2D84B7}</Project>
     148      <Name>HeuristicLab.Parameters-3.3</Name>
     149    </ProjectReference>
    131150    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    132151      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualizationView.Designer.cs

    r2801 r2819  
    3535      this.graphVisualization.BackColor = System.Drawing.Color.DarkGray;
    3636      this.graphVisualization.BackgroundType = global::Netron.Diagramming.Core.CanvasBackgroundTypes.FlatColor;
    37       this.graphVisualization.Dock = System.Windows.Forms.DockStyle.Fill;
    38       this.graphVisualization.Document = ((global::Netron.Diagramming.Core.Document)(resources.GetObject("netronVisualization1.Document")));
     37      this.graphVisualization.Dock = System.Windows.Forms.DockStyle.Fill;     
    3938      this.graphVisualization.EnableAddConnection = true;
    4039      this.graphVisualization.FileName = "";
     
    4342      this.graphVisualization.Name = "graphVisualization";
    4443      this.graphVisualization.Origin = new System.Drawing.Point(0, 0);
    45       this.graphVisualization.PageSettings = ((System.Drawing.Printing.PageSettings)(resources.GetObject("netronVisualization1.PageSettings")));
    4644      this.graphVisualization.ShowConnectors = true;
    4745      this.graphVisualization.ShowRulers = false;
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualizationView.cs

    r2801 r2819  
    3232using HeuristicLab.Core.Views;
    3333using Netron.Diagramming.Core;
     34using HeuristicLab.Parameters;
    3435
    3536namespace HeuristicLab.Operators.Views.GraphVisualization {
     
    3738  public partial class OperatorGraphVisualizationView : ItemView {
    3839    private Dictionary<IOperator, IShape> operatorShapeMapping;
    39     private Dictionary<KeyValuePair<IOperator, IOperator>, IConnection> connectionMapping;
     40    private Dictionary<KeyValuePair<IOperator, IValueParameter<IOperator>>, IConnection> connectionMapping;
     41    private HashSet<IValueParameter<IOperator>> parameters;
    4042    /// <summary>
    4143    /// Initializes a new instance of <see cref="OperatorGraphVisualizationView"/> with caption "Operator Graph".
     
    4547      Caption = "Operator Graph";
    4648      this.operatorShapeMapping = new Dictionary<IOperator, IShape>();
    47       this.connectionMapping = new Dictionary<KeyValuePair<IOperator, IOperator>, IConnection>();
     49      this.connectionMapping = new Dictionary<KeyValuePair<IOperator, IValueParameter<IOperator>>, IConnection>();
     50      this.parameters = new HashSet<IValueParameter<IOperator>>();
     51
     52      this.graphVisualization.Controller.Model.OnEntityRemoved += new EventHandler<EntityEventArgs>(Model_OnEntityRemoved);
    4853    }
    4954
     
    5964    }
    6065
    61 
    6266    /// <summary>
    6367    /// Gets or sets the operator graph to represent visually.
     
    7478    }
    7579
     80
    7681    protected override void OnContentChanged() {
    7782      base.OnContentChanged();
    78       this.GraphModel.Shapes.Clear();
    79       this.operatorShapeMapping.Clear();
    80       this.connectionMapping.Clear();
    81 
    82       this.CreateGraph(null, this.Content);
     83      this.ClearGraph();
     84
     85      this.CreateGraph(null, new OperatorParameter(string.Empty, this.Content));
    8386      foreach (IShape shape in this.operatorShapeMapping.Values)
    8487        this.GraphModel.AddShape(shape);
     
    8790        this.GraphModel.AddConnection(connection);
    8891
    89       this.graphVisualization.Controller.View.Invalidate();
    90       this.graphVisualization.Controller.Model.LayoutRoot = this.operatorShapeMapping[this.Content];
    91       this.graphVisualization.Controller.RunActivity("Standard TreeLayout");
     92      if (this.Content == null)
     93        this.graphVisualization.Controller.Model.LayoutRoot = null;
     94      else
     95        this.graphVisualization.Controller.Model.LayoutRoot = this.operatorShapeMapping[this.Content];
     96      this.RelayoutOperatorGraph();
    9297    }
    9398
     
    96101        Invoke(new EventHandler(opParam_ValueChanged), sender, e);
    97102      else {
    98         //IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
    99         //foreach (TreeNode node in opParamNodeTable[opParam].ToArray())
    100         //  //remove nodes
    101         //foreach (TreeNode node in opParamNodeTable[opParam]) {
    102         //  //add nodes
    103         //}
    104       }
    105     }
    106 
    107     private void CreateGraph(IOperator parent, IOperator op) {
    108       if (op == null)
     103        this.OnContentChanged();
     104      }
     105    }
     106
     107    private void ClearGraph() {
     108      this.GraphModel.Clear();
     109      foreach (IValueParameter<IOperator> opParam in this.parameters)
     110        opParam.ValueChanged -= opParam_ValueChanged;
     111
     112      this.operatorShapeMapping.Clear();
     113      this.parameters.Clear();
     114      this.connectionMapping.Clear();
     115    }
     116
     117
     118
     119    private void CreateGraph(IOperator parent, IValueParameter<IOperator> op) {
     120      if (op == null || op.Value == null)
    109121        return;
    110122
    111123      IShape shape;
    112       if (!this.operatorShapeMapping.ContainsKey(op)) {
    113         shape = CreateOperatorShape(op);
    114         this.operatorShapeMapping[op] = shape;
    115 
    116         foreach (IParameter param in op.Parameters) {
     124      if (!this.operatorShapeMapping.ContainsKey(op.Value)) {
     125        shape = CreateOperatorShape(op.Value);
     126        this.operatorShapeMapping[op.Value] = shape;
     127
     128        foreach (IParameter param in op.Value.Parameters) {
    117129          IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    118130          if (opParam != null) {
    119             opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    120             this.CreateGraph(op, opParam.Value);
     131            HandleOperatorParameter(opParam);
     132            this.CreateGraph(op.Value, opParam);
    121133          }
    122134        }
     
    127139    }
    128140
    129     private void RemoveGraph(IOperator op) {
    130       if(op == null)
     141    private void HandleOperatorParameter(IValueParameter<IOperator> opParam) {
     142      if (opParam == null)
    131143        return;
    132       IShape shape = this.operatorShapeMapping[op];
    133       this.GraphModel.RemoveShape(shape);
    134     }
    135 
    136     private IConnection ConnectShapes(IOperator parent, IOperator op) {
    137       IShape operatorShape = this.operatorShapeMapping[op];
     144      opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
     145      parameters.Add(opParam);
     146    }
     147
     148    private IConnection ConnectShapes(IOperator parent, IValueParameter<IOperator> opParam) {
     149      IShape operatorShape = this.operatorShapeMapping[opParam.Value];
    138150      IShape parentShape = this.operatorShapeMapping[parent];
    139151      IConnector operatorConnector = parentShape.Connectors.Where(c => c.Name == "Bottom connector").First();
     
    144156      operatorConnector.AttachConnector(connection.To);
    145157
    146       this.connectionMapping[new KeyValuePair<IOperator, IOperator>(parent, op)] = connection;
     158      this.connectionMapping[new KeyValuePair<IOperator, IValueParameter<IOperator>>(parent, opParam)] = connection;
    147159      return connection;
    148160    }
     
    157169      return shape;
    158170    }
     171
     172    private void Model_OnEntityRemoved(object sender, EntityEventArgs e) {
     173      IShape shape = e.Entity as IShape;
     174      if (shape != null) {
     175        IOperator op = operatorShapeMapping.Where(os => os.Value == shape).First().Key;
     176        if (op == this.Content)
     177          this.Content = null;
     178        else {
     179          //clear all connections to the removed operator
     180          IEnumerable<IValueParameter<IOperator>> parentOperator = this.connectionMapping.Where(cs => cs.Key.Value.Value == op).Select(x => x.Key.Value);
     181          foreach(IValueParameter<IOperator> opParam in parentOperator.ToArray())
     182            opParam.Value = null;
     183
     184          //remove connections from graph view
     185          IEnumerable<IConnection> connections = this.connectionMapping.Where(cs => cs.Key.Value.Value == op).Select(x => x.Value);
     186          foreach (IConnection connection in connections)
     187            this.GraphModel.Remove(connection);
     188
     189          this.graphVisualization.Invalidate();
     190        }
     191
     192
     193      }
     194    }
     195
     196    #region methods for toolbar items
     197
     198    internal void RelayoutOperatorGraph() {
     199      if (this.operatorShapeMapping.Count > 0 && this.connectionMapping.Count > 0) { //otherwise the layout does not work
     200        this.graphVisualization.Invalidate();
     201        this.graphVisualization.Controller.RunActivity("Standard TreeLayout");
     202      }
     203    }
     204
     205    internal void ActivateZoomAreaTool() {
     206      this.graphVisualization.Controller.ActivateTool(ControllerBase.ZoomAreaToolName);
     207    }
     208
     209    internal void ActivateZoomInTool() {
     210      this.graphVisualization.Controller.ActivateTool(ControllerBase.ZoomInToolName);
     211    }
     212
     213    internal void ActivateZoomOutTool() {
     214      this.graphVisualization.Controller.ActivateTool(ControllerBase.ZoomOutToolName);
     215    }
     216
     217    internal void ActivatePanTool() {
     218      this.graphVisualization.Controller.ActivateTool(ControllerBase.PanToolName);
     219    }
     220
     221    internal void ActivateSelectTool() {
     222      this.graphVisualization.Controller.ActivateTool(ControllerBase.SelectionToolName);
     223    }
     224
     225    #endregion
    159226  }
    160227}
Note: See TracChangeset for help on using the changeset viewer.