Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/11 10:00:31 (14 years ago)
Author:
abeham
Message:

#1465

  • updated branch with trunk changes
Location:
branches/histogram
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/IOperatorShapeInfo.cs

    r5445 r6046  
    3535    void RemoveConnector(string connectorName);
    3636
     37    IEnumerable<string> Labels { get; }
    3738    void UpdateLabels(IEnumerable<string> labels);
    3839  }
  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphVisualizationInfo.cs

    r5445 r6046  
    128128    }
    129129
    130     internal IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) {
     130    public IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) {
    131131      return this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
    132132    }
     
    192192
    193193    #region methods to manipulate operatorgraph by the shape info
    194     internal void AddShapeInfo(IOperator op, IOperatorShapeInfo shapeInfo) {
     194    public void AddShapeInfo(IOperator op, IOperatorShapeInfo shapeInfo) {
    195195      this.RegisterOperatorEvents(op);
    196196      this.operatorParameterCollectionMapping.Add(op, op.Parameters);
  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShape.cs

    r5445 r6046  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Drawing;
    25 using System.Drawing.Drawing2D;
    26 using System.Linq;
    27 using HeuristicLab.Netron;
    28 using Netron.Diagramming.Core;
    2922
    3023
    3124namespace HeuristicLab.Operators.Views.GraphVisualization {
    32   public class OperatorShape : ComplexShapeBase {
    33     private static int LABEL_HEIGHT = 16;
    34     private static int LABEL_WIDTH = 180;
    35     private static int LABEL_SPACING = 3;
    36     private int headerHeight = 30;
    37 
    38     private ExpandableIconMaterial expandIconMaterial;
    39     public OperatorShape()
    40       : base() {
    41       this.Resizable = false;
    42       this.additionalConnectors = new List<IConnector>();
    43       this.labels = new List<string>();
    44     }
    45 
    46     public override string EntityName {
    47       get { return "Operator Shape"; }
    48     }
    49 
    50     public bool Collapsed {
    51       get { return this.expandIconMaterial.Collapsed; }
    52       set {
    53         if (this.expandIconMaterial.Collapsed != value)
    54           this.expandIconMaterial.Collapsed = value;
    55       }
    56     }
    57 
    58     private Color lineColor;
    59     public Color LineColor {
    60       get { return this.lineColor; }
    61       set { this.lineColor = value; }
    62     }
    63 
    64     private float lineWidth;
    65     public float LineWidth {
    66       get { return this.lineWidth; }
    67       set { this.lineWidth = value; }
    68     }
    69 
    70     private Color color;
    71     public Color Color {
    72       get { return this.color; }
    73       set { this.color = value; }
    74     }
    75 
    76     private string title;
    77     public string Title {
    78       get { return title; }
    79       set { title = value; }
    80     }
    81 
    82     private IconMaterial iconMaterial;
    83     public Bitmap Icon {
    84       get { return this.iconMaterial.Icon; }
    85       set {
    86         this.iconMaterial.Icon = value;
    87         this.iconMaterial.Transform(new Rectangle(new Point(Rectangle.X + 5, Rectangle.Y + 5), this.iconMaterial.Icon.Size));
    88       }
    89     }
    90 
    91     #region additional connectors
    92     private List<IConnector> additionalConnectors;
    93     public IEnumerable<string> AdditionalConnectorNames {
    94       get { return this.additionalConnectors.Select(c => c.Name); }
    95     }
    96 
    97     private IConnector predecessor;
    98     public IConnector Predecessor {
    99       get { return this.predecessor; }
    100     }
    101 
    102     private IConnector successor;
    103     public IConnector Successor {
    104       get { return this.successor; }
    105     }
    106 
    107     private IConnector CreateConnector(string connectorName, Point location) {
    108       Connector connector = new Connector(location, this.Model);
    109       connector.ConnectorStyle = ConnectorStyle.Square;
    110       connector.Parent = this;
    111       connector.Name = connectorName;
    112       return connector;
    113     }
    114 
    115     public void AddConnector(string connectorName) {
    116       IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner);
    117 
    118       this.additionalConnectors.Add(connector);
    119       this.Connectors.Add(connector);
    120       this.UpdateConnectorLocation();
    121     }
    122 
    123     public void RemoveConnector(string connectorName) {
    124       IConnector connector = this.additionalConnectors.Where(c => c.Name == connectorName).FirstOrDefault();
    125       if (connector != null) {
    126         this.additionalConnectors.Remove(connector);
    127         this.Connectors.Remove(connector);
    128         this.UpdateConnectorLocation();
    129       }
    130     }
    131 
    132     private void UpdateConnectorLocation() {
    133       if (this.additionalConnectors.Count == 0)
    134         return;
    135 
    136       int spacing = this.Rectangle.Width / this.additionalConnectors.Count;
    137       int margin = spacing / 2;
    138       int posX = margin + this.Rectangle.X;
    139       for (int i = 0; i < this.additionalConnectors.Count; i++) {
    140         this.additionalConnectors[i].MoveBy(new Point(posX - this.additionalConnectors[i].Point.X, 0));
    141         posX += spacing;
    142       }
    143     }
    144     #endregion
    145 
    146     #region label material
    147     private List<string> labels;
    148     public IEnumerable<string> Labels {
    149       get { return this.labels; }
    150     }
    151 
    152     public void UpdateLabels(IEnumerable<string> labels) {
    153       this.labels = new List<string>(labels);
    154       this.expandIconMaterial.Visible = this.labels.Count != 0;
    155       this.UpdateLabels();
    156     }
    157     #endregion
    158 
    159     private void expandIconMaterial_OnExpand(object sender, EventArgs e) {
    160       this.UpdateLabels();
    161     }
    162 
    163     private void expandIconMaterial_OnCollapse(object sender, EventArgs e) {
    164       this.UpdateLabels();
    165     }
    166 
    167     private Size CalculateSize() {
    168       int width = this.Rectangle.Width;
    169       int height = headerHeight;
    170       if (!Collapsed)
    171         height += this.labels.Count * (LABEL_HEIGHT + LABEL_SPACING);
    172       return new Size(width, height);
    173     }
    174 
    175     private void UpdateLabels() {
    176       Size newSize = CalculateSize();
    177       if (this.Rectangle.Size != newSize) {
    178         foreach (IConnector connector in this.additionalConnectors)
    179           connector.MoveBy(new Point(0, newSize.Height - this.Rectangle.Height));
    180         this.mRectangle = new Rectangle(this.Rectangle.Location, newSize);
    181         this.Invalidate();
    182         this.RaiseOnChange(this, new EntityEventArgs(this));
    183       }
    184     }
    185 
    186     protected override void Initialize() {
    187       base.Initialize();
    188 
    189       //the initial size
    190       this.Transform(0, 0, 200, headerHeight);
    191       this.color = Color.LightBlue;
    192 
    193       this.iconMaterial = new IconMaterial();
    194       this.iconMaterial.Gliding = false;
    195       this.Children.Add(iconMaterial);
    196 
    197       Bitmap expandBitmap = new Bitmap(HeuristicLab.Common.Resources.VSImageLibrary.Expand);
    198       Bitmap collapseBitmap = new Bitmap(HeuristicLab.Common.Resources.VSImageLibrary.Collapse);
    199       this.expandIconMaterial = new ExpandableIconMaterial(expandBitmap, collapseBitmap);
    200       this.expandIconMaterial.Gliding = false;
    201       this.expandIconMaterial.Transform(new Rectangle(new Point(Rectangle.Right - 20, Rectangle.Y + 7), expandIconMaterial.Icon.Size));
    202       this.expandIconMaterial.Visible = false;
    203       this.expandIconMaterial.OnExpand += new EventHandler(expandIconMaterial_OnExpand);
    204       this.expandIconMaterial.OnCollapse += new EventHandler(expandIconMaterial_OnCollapse);
    205       this.Children.Add(expandIconMaterial);
    206 
    207       this.predecessor = this.CreateConnector(OperatorShapeInfoFactory.PredecessorConnector, new Point(Rectangle.Left, Center.Y));
    208       this.Connectors.Add(predecessor);
    209 
    210       this.successor = this.CreateConnector(OperatorShapeInfoFactory.SuccessorConnector, (new Point(Rectangle.Right, Center.Y)));
    211       this.Connectors.Add(successor);
    212     }
    213 
    214     public override void Paint(Graphics g) {
    215       base.Paint(g);
    216 
    217       g.SmoothingMode = SmoothingMode.HighQuality;
    218 
    219       Pen pen = new Pen(lineColor, lineWidth);
    220 
    221       SizeF titleSize = g.MeasureString(this.Title, ArtPalette.DefaultBoldFont, Rectangle.Width - 45);
    222       if (titleSize.Height + 10 > Rectangle.Height) {
    223         headerHeight = (int)titleSize.Height + 10;
    224         this.UpdateLabels();
    225       }
    226 
    227       GraphicsPath path = new GraphicsPath();
    228       path.AddArc(Rectangle.X, Rectangle.Y, 20, 20, -180, 90);
    229       path.AddLine(Rectangle.X + 10, Rectangle.Y, Rectangle.X + Rectangle.Width - 10, Rectangle.Y);
    230       path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y, 20, 20, -90, 90);
    231       path.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + 10, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 10);
    232       path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y + Rectangle.Height - 20, 20, 20, 0, 90);
    233       path.AddLine(Rectangle.X + Rectangle.Width - 10, Rectangle.Y + Rectangle.Height, Rectangle.X + 10, Rectangle.Y + Rectangle.Height);
    234       path.AddArc(Rectangle.X, Rectangle.Y + Rectangle.Height - 20, 20, 20, 90, 90);
    235       path.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height - 10, Rectangle.X, Rectangle.Y + 10);
    236       //shadow
    237       if (ArtPalette.EnableShadows) {
    238         Region darkRegion = new Region(path);
    239         darkRegion.Translate(5, 5);
    240         g.FillRegion(ArtPalette.ShadowBrush, darkRegion);
    241       }
    242       //background
    243       g.FillPath(Brush, path);
    244 
    245       using (LinearGradientBrush gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(Rectangle.X + Rectangle.Width, Rectangle.Y), this.Color, Color.White)) {
    246         Region gradientRegion = new Region(path);
    247         g.FillRegion(gradientBrush, gradientRegion);
    248       }
    249 
    250       if (!this.Collapsed) {
    251         TextStyle textStyle = new TextStyle(Color.Black, new Font("Arial", 7), StringAlignment.Near, StringAlignment.Near);
    252         StringFormat stringFormat = textStyle.StringFormat;
    253         stringFormat.Trimming = StringTrimming.EllipsisWord;
    254         stringFormat.FormatFlags = StringFormatFlags.LineLimit;
    255         Rectangle rect;
    256 
    257         for (int i = 0; i < this.labels.Count; i++) {
    258           rect = new Rectangle(Rectangle.X + 25, Rectangle.Y + headerHeight + i * (LABEL_HEIGHT + LABEL_SPACING), LABEL_WIDTH, LABEL_HEIGHT);
    259           g.DrawString(textStyle.GetFormattedText(this.labels[i]), textStyle.Font, textStyle.GetBrush(), rect, stringFormat);
    260         }
    261       }
    262 
    263       //the border
    264       g.DrawPath(pen, path);
    265 
    266       //the title
    267       g.DrawString(this.Title, ArtPalette.DefaultBoldFont, Brushes.Black, new Rectangle(Rectangle.X + 25, Rectangle.Y + 5, Rectangle.Width - 45, Rectangle.Height - 5));
    268 
    269 
    270       //the material
    271       foreach (IPaintable material in Children)
    272         material.Paint(g);
    273 
    274       //the connectors
    275       if (this.ShowConnectors) {
    276         for (int k = 0; k < Connectors.Count; k++)
    277           Connectors[k].Paint(g);
    278       }
    279     }
     25  internal class OperatorShape {
     26    //21.04.2011 mkommend
     27    //Do not delete this empty class, because this type was moved in to the plugin GraphVisualiation.Views
     28    //But it is referenced in persisted ShapeInfo objects and thus these files could not be loaded without this type
     29    //Should be removed with HL 3.4
    28030  }
    28131}
  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs

    r5445 r6046  
    2222using System.Collections.Generic;
    2323using System.Drawing;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using Netron.Diagramming.Core;
    2826
    2927namespace HeuristicLab.Operators.Views.GraphVisualization {
    3028  [StorableClass]
    31   internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
     29  public class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
    3230    [Storable]
    3331    private List<string> labels;
     32    public IEnumerable<string> Labels {
     33      get { return labels; }
     34    }
     35
     36    private object lockObject = new object();
    3437
    3538    [StorableConstructor]
     
    4245      lineWidth = original.lineWidth;
    4346      title = original.title;
    44       if (original.icon != null) icon = (Bitmap)original.icon.Clone();
     47
     48      //mkommend: necessary because cloning a Bitmap is not threadsafe
     49      //see http://stackoverflow.com/questions/1851292/invalidoperationexception-object-is-currently-in-use-elsewhere for further information
     50      if (original.icon != null) {
     51        lock (original.lockObject) {
     52          icon = (Bitmap)original.icon.Clone();
     53        }
     54      }
    4555
    4656      connectorNames = new List<string>(original.connectorNames);
     
    5262
    5363    public OperatorShapeInfo()
    54       : base(typeof(OperatorShape)) {
     64      : base() {
    5565      this.connectorNames = new List<string>();
    5666      this.labels = new List<string>();
     
    164174      }
    165175    }
    166 
    167     public override IShape CreateShape() {
    168       OperatorShape shape = (OperatorShape)base.CreateShape();
    169       shape.Title = this.Title;
    170       shape.Color = this.Color;
    171       shape.LineColor = this.LineColor;
    172       shape.LineWidth = this.LineWidth;
    173       shape.Icon = this.Icon;
    174       shape.Collapsed = this.Collapsed;
    175       foreach (string connectorName in this.connectorNames)
    176         if (connectorName != OperatorShapeInfoFactory.SuccessorConnector && connectorName != OperatorShapeInfoFactory.PredecessorConnector)
    177           shape.AddConnector(connectorName);
    178 
    179       shape.UpdateLabels(this.labels);
    180       return shape;
    181     }
    182 
    183     public override void UpdateShape(IShape shape) {
    184       base.UpdateShape(shape);
    185       OperatorShape operatorShape = (OperatorShape)shape;
    186       operatorShape.Title = this.Title;
    187       operatorShape.Color = this.Color;
    188       operatorShape.LineColor = this.LineColor;
    189       operatorShape.LineWidth = this.LineWidth;
    190       operatorShape.Icon = this.Icon;
    191       operatorShape.Collapsed = this.Collapsed;
    192 
    193       int i = 0;
    194       int j = 0;
    195       //remove old connectors and skip correct connectors
    196       List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
    197       while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
    198         if (connectorNames[i] == OperatorShapeInfoFactory.SuccessorConnector ||
    199           connectorNames[i] == OperatorShapeInfoFactory.PredecessorConnector)
    200           i++;
    201         else if (oldConnectorNames[j] == OperatorShapeInfoFactory.SuccessorConnector ||
    202           oldConnectorNames[j] == OperatorShapeInfoFactory.PredecessorConnector)
    203           j++;
    204         else if (this.connectorNames[i] != oldConnectorNames[j]) {
    205           operatorShape.RemoveConnector(oldConnectorNames[j]);
    206           j++;
    207         } else {
    208           i++;
    209           j++;
    210         }
    211       }
    212       //remove remaining old connectors
    213       for (; j < oldConnectorNames.Count; j++)
    214         operatorShape.RemoveConnector(oldConnectorNames[j]);
    215 
    216       //add new connectors except successor and connector
    217       for (; i < this.connectorNames.Count; i++)
    218         if (this.connectorNames[i] != OperatorShapeInfoFactory.SuccessorConnector && this.connectorNames[i] != OperatorShapeInfoFactory.PredecessorConnector)
    219           operatorShape.AddConnector(this.connectorNames[i]);
    220 
    221       operatorShape.UpdateLabels(this.labels);
    222     }
    223 
    224     public override void UpdateShapeInfo(IShape shape) {
    225       base.UpdateShapeInfo(shape);
    226       OperatorShape operatorShape = (OperatorShape)shape;
    227       this.Title = operatorShape.Title;
    228       this.Color = operatorShape.Color;
    229       this.LineColor = operatorShape.LineColor;
    230       this.LineWidth = operatorShape.LineWidth;
    231       this.Icon = operatorShape.Icon;
    232       this.Collapsed = operatorShape.Collapsed;
    233 
    234       //TODO update Connector and labels;
    235     }
    236176  }
    237177}
  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfoFactory.cs

    r5445 r6046  
    2626
    2727namespace HeuristicLab.Operators.Views.GraphVisualization {
    28   internal static class OperatorShapeInfoFactory {
     28  public static class OperatorShapeInfoFactory {
    2929    public const string PredecessorConnector = "Predecessor";
    3030    public const string SuccessorConnector = "Successor";
Note: See TracChangeset for help on using the changeset viewer.