Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/10 12:37:59 (15 years ago)
Author:
mkommend
Message:

added parameters, corrected drag and drop position (ticket #867)

Location:
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/GraphVisualizationInfo.cs

    r2896 r2934  
    2828using System.Drawing;
    2929using HeuristicLab.Collections;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.Operators.Views.GraphVisualization {
    3233  public sealed class GraphVisualizationInfo : DeepCloneable {
    33     private BidirectionalLookup<IOperator, IShapeInfo> shapeInfoMapping;
     34    private BidirectionalLookup<IOperator, IOperatorShapeInfo> operatorShapeInfoMapping;
     35    [Storable]
     36    private BidirectionalLookup<IOperator, IOperatorShapeInfo> OperatorShapeInfoMappingStore {
     37      get { return this.operatorShapeInfoMapping; }
     38      set {
     39        foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in value.FirstEnumerable)
     40          this.AddShapeInfo(pair.Key, pair.Value);
     41      }
     42    }
     43
    3444    private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping;
    35     private Dictionary<IValueParameter<IOperator>, IOperator> parameterOperatorMapping;
     45    private Dictionary<IParameter, IOperator> parameterOperatorMapping;
    3646
    3747    private GraphVisualizationInfo() {
    38       this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>();
     48      this.operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>();
    3949      this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>();
    40       this.parameterOperatorMapping = new Dictionary<IValueParameter<IOperator>, IOperator>();
    41 
    42       this.shapeInfos = new ObservableSet<IShapeInfo>();
    43       this.connections = new ObservableDictionary<KeyValuePair<IShapeInfo, string>, IShapeInfo>();
     50      this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
     51
     52      this.shapeInfos = new ObservableSet<IOperatorShapeInfo>();
     53      this.connections = new ObservableDictionary<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>();
    4454    }
    4555
     
    5363
    5464      foreach (IOperator op in operatorGraph.Operators)
    55         if (!this.shapeInfoMapping.ContainsFirst(op))
     65        if (!this.operatorShapeInfoMapping.ContainsFirst(op))
    5666          this.AddOperator(op);
    5767
     
    6575
    6676    private void UpdateInitialShape() {
    67       OperatorShapeInfo old = this.oldInitialShape as OperatorShapeInfo;
     77      IOperatorShapeInfo old = this.oldInitialShape as OperatorShapeInfo;
    6878      if (old != null)
    69         old.HeadColor = oldInitialShapeColor;
     79        old.Color = oldInitialShapeColor;
    7080
    7181      OperatorShapeInfo newInitialShapeInfo = this.InitialShape as OperatorShapeInfo;
    7282      if (newInitialShapeInfo != null) {
    73         oldInitialShapeColor = newInitialShapeInfo.HeadColor;
    74         newInitialShapeInfo.HeadColor = Color.LightGreen;
     83        oldInitialShapeColor = newInitialShapeInfo.Color;
     84        newInitialShapeInfo.Color = Color.LightGreen;
    7585      }
    7686
     
    8090    }
    8191
    82     private IShapeInfo oldInitialShape;
     92    [Storable]
     93    private IOperatorShapeInfo oldInitialShape;
     94    [Storable]
    8395    private Color oldInitialShapeColor;
    84     public IShapeInfo InitialShape {
     96    public IOperatorShapeInfo InitialShape {
    8597      get {
    8698        IOperator op = this.operatorGraph.InitialOperator;
    8799        if (op == null)
    88100          return null;
    89         return this.shapeInfoMapping.GetByFirst(op);
     101        return this.operatorShapeInfoMapping.GetByFirst(op);
    90102      }
    91103      set {
     
    93105          this.OperatorGraph.InitialOperator = null;
    94106        else
    95           this.OperatorGraph.InitialOperator = this.shapeInfoMapping.GetBySecond(value);
    96       }
    97     }
    98 
     107          this.OperatorGraph.InitialOperator = this.operatorShapeInfoMapping.GetBySecond(value);
     108      }
     109    }
     110
     111    [Storable]
    99112    private OperatorGraph operatorGraph;
    100113    public OperatorGraph OperatorGraph {
     
    102115    }
    103116
    104     private ObservableSet<IShapeInfo> shapeInfos;
    105     public INotifyObservableCollectionItemsChanged<IShapeInfo> ObserveableShapeInfos {
     117    private ObservableSet<IOperatorShapeInfo> shapeInfos;
     118    public INotifyObservableCollectionItemsChanged<IOperatorShapeInfo> ObserveableShapeInfos {
    106119      get { return this.shapeInfos; }
    107120    }
    108     public IEnumerable<IShapeInfo> ShapeInfos {
     121    public IEnumerable<IOperatorShapeInfo> OperatorShapeInfos {
    109122      get { return this.shapeInfos; }
    110123    }
    111     public IOperator GetOperatorForShapeInfo(IShapeInfo shapeInfo) {
    112       return this.shapeInfoMapping.GetBySecond(shapeInfo);
    113     }
    114 
    115     private ObservableDictionary<KeyValuePair<IShapeInfo, string>, IShapeInfo> connections;
    116     public INotifyObservableDictionaryItemsChanged<KeyValuePair<IShapeInfo, string>, IShapeInfo> ObservableConnections {
     124    public IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) {
     125      return this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
     126    }
     127
     128    [Storable]
     129    private ObservableDictionary<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> connections;
     130    public INotifyObservableDictionaryItemsChanged<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> ObservableConnections {
    117131      get { return this.connections; }
    118132    }
    119     public IEnumerable<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> Connections {
     133    public IEnumerable<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> Connections {
    120134      get { return this.connections; }
    121135    }
    122136
    123137    #region methods to manipulate operatorgraph by the shape info
    124     internal void AddShapeInfo(IOperator op, IShapeInfo shapeInfo) {
     138    internal void AddShapeInfo(IOperator op, IOperatorShapeInfo shapeInfo) {
    125139      this.RegisterOperatorEvents(op);
    126140      this.operatorParameterCollectionMapping.Add(op, op.Parameters);
    127       this.shapeInfoMapping.Add(op, shapeInfo);
     141      this.operatorShapeInfoMapping.Add(op, shapeInfo);
    128142      this.shapeInfos.Add(shapeInfo);
    129143
     
    131145        this.AddParameter(op, param);
    132146
    133       this.operatorGraph.Operators.Add(op);
    134     }
    135 
    136     internal void RemoveShapeInfo(IShapeInfo shapeInfo) {
    137       IOperator op = this.shapeInfoMapping.GetBySecond(shapeInfo);
     147      if (!this.operatorGraph.Operators.Contains(op))
     148        this.operatorGraph.Operators.Add(op);
     149    }
     150
     151    internal void RemoveShapeInfo(IOperatorShapeInfo shapeInfo) {
     152      IOperator op = this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
    138153      this.operatorGraph.Operators.Remove(op);
    139154    }
    140155
    141     internal void AddConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) {
    142       IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom);
    143       IOperator opTo = this.shapeInfoMapping.GetBySecond(shapeInfoTo);
     156    internal void AddConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) {
     157      IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom);
     158      IOperator opTo = this.operatorShapeInfoMapping.GetBySecond(shapeInfoTo);
    144159
    145160      IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName];
     
    147162    }
    148163
    149     internal void ChangeConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) {
    150       IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom);
    151       IOperator opTo = this.shapeInfoMapping.GetBySecond(shapeInfoTo);
     164    internal void ChangeConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) {
     165      IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom);
     166      IOperator opTo = this.operatorShapeInfoMapping.GetBySecond(shapeInfoTo);
    152167
    153168      IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName];
     
    155170    }
    156171
    157     internal void RemoveConnection(IShapeInfo shapeInfoFrom, string connectorName) {
    158       IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom);
     172    internal void RemoveConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName) {
     173      IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom);
    159174      IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName];
    160175      param.Value = null;
     
    164179    #region operator events
    165180    private void AddOperator(IOperator op) {
    166       if (!this.shapeInfoMapping.ContainsFirst(op)) {
     181      if (!this.operatorShapeInfoMapping.ContainsFirst(op)) {
    167182        this.RegisterOperatorEvents(op);
    168         IShapeInfo shapeInfo = Factory.CreateShapeInfo(op);
     183        IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op);
    169184        this.operatorParameterCollectionMapping.Add(op, op.Parameters);
    170         this.shapeInfoMapping.Add(op, shapeInfo);
     185        this.operatorShapeInfoMapping.Add(op, shapeInfo);
    171186        foreach (IParameter param in op.Parameters)
    172187          this.AddParameter(op, param);
     
    181196        this.RemoveParameter(op, param);
    182197
    183       IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     198      IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
    184199      this.operatorParameterCollectionMapping.RemoveByFirst(op);
    185       this.shapeInfoMapping.RemoveByFirst(op);
     200      this.operatorShapeInfoMapping.RemoveByFirst(op);
    186201      this.shapeInfos.Remove(shapeInfo);
    187202    }
     
    189204    private void OperatorNameChanged(object sender, EventArgs e) {
    190205      IOperator op = (IOperator)sender;
    191       IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
    192       OperatorShapeInfo operatorShapeInfo = shapeInfo as OperatorShapeInfo;
    193       if (operatorShapeInfo != null)
    194         operatorShapeInfo.Title = op.Name;
     206      IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
     207      operatorShapeInfo.Title = op.Name;
    195208    }
    196209
     
    229242    #region parameter events
    230243    private void AddParameter(IOperator op, IParameter param) {
     244      this.parameterOperatorMapping.Add(param, op);
    231245      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    232246      if (opParam != null) {
    233247        this.RegisterOperatorParameterEvents(opParam);
    234         this.parameterOperatorMapping.Add(opParam, op);
    235         IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
     248        IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
    236249        shapeInfo.AddConnector(param.Name);
    237250
    238251        if (opParam.Value != null) {
    239           if (!this.shapeInfoMapping.ContainsFirst(opParam.Value))
     252          if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value))
    240253            this.AddOperator(opParam.Value);
    241           this.connections.Add(new KeyValuePair<IShapeInfo, string>(shapeInfo, param.Name), this.shapeInfoMapping.GetByFirst(opParam.Value));
     254          this.connections.Add(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name), this.operatorShapeInfoMapping.GetByFirst(opParam.Value));
    242255        }
    243       }
     256      } else
     257        this.RegisterParameterEvents(param);
    244258    }
    245259
     
    248262      if (opParam != null) {
    249263        this.DeregisterOperatorParameterEvents(opParam);
    250         this.parameterOperatorMapping.Remove(opParam);
    251         IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
    252 
    253         this.connections.Remove(new KeyValuePair<IShapeInfo, string>(shapeInfo, param.Name));
     264        IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
     265        this.connections.Remove(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name));
    254266        shapeInfo.RemoveConnector(param.Name);
    255       }
     267      } else
     268        this.DeregisterParameterEvents(param);
     269
     270      this.parameterOperatorMapping.Remove(param);
    256271    }
    257272
     
    260275      if (opParam != null) {
    261276        IOperator op = this.parameterOperatorMapping[opParam];
    262         IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);
    263         KeyValuePair<IShapeInfo, string> connectionFrom = new KeyValuePair<IShapeInfo, string>(shapeInfo, opParam.Name);
     277        IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
     278        KeyValuePair<IOperatorShapeInfo, string> connectionFrom = new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, opParam.Name);
    264279
    265280        if (opParam.Value == null)
    266281          this.connections.Remove(connectionFrom);
    267282        else {
    268           if (!this.shapeInfoMapping.ContainsFirst(opParam.Value))
     283          if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value))
    269284            this.AddOperator(opParam.Value);
    270           this.connections[connectionFrom] = this.shapeInfoMapping.GetByFirst(opParam.Value);
     285          this.connections[connectionFrom] = this.operatorShapeInfoMapping.GetByFirst(opParam.Value);
    271286        }
    272287      }
     
    278293      foreach (IParameter param in e.Items)
    279294        AddParameter(op, param);
     295      this.UpdateParameterLabels(op);
    280296    }
    281297    private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     
    284300      foreach (IParameter param in e.Items)
    285301        RemoveParameter(op, param);
     302      this.UpdateParameterLabels(op);
    286303    }
    287304    private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     
    292309      foreach (IParameter param in e.Items)
    293310        AddParameter(op, param);
     311      this.UpdateParameterLabels(op);
    294312    }
    295313    private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
     
    300318      foreach (IParameter param in e.Items)
    301319        AddParameter(op, param);
     320      this.UpdateParameterLabels(op);
    302321    }
    303322
     
    307326    private void DeregisterOperatorParameterEvents(IValueParameter<IOperator> opParam) {
    308327      opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
     328    }
     329    private void RegisterParameterEvents(IParameter param) {
     330      param.ToStringChanged += new EventHandler(param_ToStringChanged);
     331      param.NameChanged += new EventHandler(param_NameChanged);
     332    }
     333    private void DeregisterParameterEvents(IParameter param) {
     334      param.ToStringChanged -= new EventHandler(param_ToStringChanged);
     335      param.NameChanged -= new EventHandler(param_NameChanged);
     336    }
     337
     338    private void param_NameChanged(object sender, EventArgs e) {
     339      IParameter param = (IParameter)sender;
     340      IOperator op = this.parameterOperatorMapping[param];
     341      this.UpdateParameterLabels(op);
     342    }
     343    private void param_ToStringChanged(object sender, EventArgs e) {
     344      IParameter param = (IParameter)sender;
     345      IOperator op = this.parameterOperatorMapping[param];
     346      this.UpdateParameterLabels(op);
     347    }
     348
     349    private void UpdateParameterLabels(IOperator op) {
     350      IEnumerable<IParameter> parameters = op.Parameters.Where(p => !(p is IValueParameter<IOperator>));
     351      IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
     352      if (parameters.Count() > 0)
     353        operatorShapeInfo.UpdateLabels(parameters.Select(p => p.ToString()));
     354      else
     355        operatorShapeInfo.UpdateLabels(new List<string>());
    309356    }
    310357    #endregion
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/IShapeInfo.cs

    r2868 r2934  
    3333    Type ShapeType { get; }
    3434    Point Location { get; set; }
    35     Size Size { get; set; }
    36 
    37     void AddConnector(string connectorName);
    38     void RemoveConnector(string connectorName);
    3935
    4036    IShape CreateShape();
    4137    void UpdateShape(IShape shape);
     38
     39    event EventHandler Changed;
    4240  }
    4341}
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs

    r2872 r2934  
    2626using Netron.Diagramming.Core;
    2727using System.Drawing;
     28using System.Drawing.Drawing2D;
     29using HeuristicLab.Netron;
    2830
    2931namespace HeuristicLab.Operators.Views.GraphVisualization {
    30   public class OperatorShape : ClassShape {
    31 
     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 static int HEADER_HEIGHT = 30;
     37
     38    private ExpandableIconMaterial expandIconMaterial;
    3239    public OperatorShape()
    3340      : base() {
     41      this.Resizable = false;
    3442      this.additionalConnectors = new List<IConnector>();
    35     }
    36 
     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 color;
     59    public Color Color {
     60      get { return this.color; }
     61      set { this.color = value; }
     62    }
     63
     64    private string title;
     65    public string Title {
     66      get { return title; }
     67      set { title = value; }
     68    }
     69
     70    private IconMaterial iconMaterial;
     71    public Bitmap Icon {
     72      get { return this.iconMaterial.Icon; }
     73      set {
     74        this.iconMaterial.Icon = value;
     75        this.iconMaterial.Transform(new Rectangle(new Point(Rectangle.X + 5, Rectangle.Y + 5), this.iconMaterial.Icon.Size));
     76      }
     77    }
     78
     79    #region additional connectors
    3780    private List<IConnector> additionalConnectors;
    3881    public IEnumerable<string> AdditionalConnectorNames {
     
    58101    }
    59102
    60 
    61 
    62103    public void AddConnector(string connectorName) {
    63104      IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner);
     
    89130      }
    90131    }
    91 
     132    #endregion
     133
     134    #region label material
     135    private List<string> labels;
     136    public IEnumerable<string> Labels {
     137      get { return this.labels; }
     138    }
     139
     140    public void UpdateLabels(IEnumerable<string> labels) {
     141      this.labels = new List<string>(labels);
     142      this.expandIconMaterial.Visible = this.labels.Count != 0;
     143      this.UpdateLabels();
     144    }
     145    #endregion
     146
     147    private void expandIconMaterial_OnExpand(object sender, EventArgs e) {
     148      this.UpdateLabels();
     149    }
     150
     151    private void expandIconMaterial_OnCollapse(object sender, EventArgs e) {
     152      this.UpdateLabels();
     153    }
     154
     155    private Size CalculateSize() {
     156      int width = this.Rectangle.Width;
     157      int height = HEADER_HEIGHT;
     158      if (!Collapsed)
     159        height += this.labels.Count * (LABEL_HEIGHT + LABEL_SPACING);
     160      return new Size(width, height);
     161    }
     162
     163    private void UpdateLabels() {
     164      Size newSize = CalculateSize();
     165      if (this.Rectangle.Size != newSize) {
     166        foreach (IConnector connector in this.additionalConnectors)
     167          connector.MoveBy(new Point(0, newSize.Height - this.Rectangle.Height));
     168        this.mRectangle = new Rectangle(this.Rectangle.Location, newSize);
     169        this.Invalidate();
     170        this.RaiseOnChange(this, new EntityEventArgs(this));
     171      }
     172    }
    92173
    93174    protected override void Initialize() {
    94175      base.Initialize();
    95176
    96       #region Connectors
    97       this.Connectors.Clear();
    98 
    99       predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y));
    100       Connectors.Add(predecessor);
    101 
    102       successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y)));
    103       Connectors.Add(successor);
    104       #endregion
     177      //the initial size
     178      this.Transform(0, 0, 200, HEADER_HEIGHT);
     179      this.color = Color.LightBlue;
     180
     181      this.iconMaterial = new IconMaterial();
     182      this.iconMaterial.Gliding = false;
     183      this.Children.Add(iconMaterial);
     184
     185      Bitmap expandBitmap = new Bitmap(HeuristicLab.Common.Resources.VS2008ImageLibrary.Redo);
     186      Bitmap collapseBitmap = new Bitmap(HeuristicLab.Common.Resources.VS2008ImageLibrary.Undo);
     187      this.expandIconMaterial = new ExpandableIconMaterial(expandBitmap, collapseBitmap);
     188      this.expandIconMaterial.Gliding = false;
     189      this.expandIconMaterial.Transform(new Rectangle(new Point(Rectangle.Right - 20, Rectangle.Y + 7), expandIconMaterial.Icon.Size));
     190      this.expandIconMaterial.Visible = false;
     191      this.expandIconMaterial.OnExpand += new EventHandler(expandIconMaterial_OnExpand);
     192      this.expandIconMaterial.OnCollapse += new EventHandler(expandIconMaterial_OnCollapse);
     193      this.Children.Add(expandIconMaterial);
     194
     195      this.predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y));
     196      this.Connectors.Add(predecessor);
     197
     198      this.successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y)));
     199      this.Connectors.Add(successor);
     200    }
     201
     202    public override void Paint(Graphics g) {
     203      base.Paint(g);
     204
     205      g.SmoothingMode = SmoothingMode.HighQuality;
     206
     207      Pen pen;
     208      if (Hovered)
     209        pen = ArtPalette.HighlightPen;
     210      else
     211        pen = mPenStyle.DrawingPen();
     212
     213      GraphicsPath path = new GraphicsPath();
     214      path.AddArc(Rectangle.X, Rectangle.Y, 20, 20, -180, 90);
     215      path.AddLine(Rectangle.X + 10, Rectangle.Y, Rectangle.X + Rectangle.Width - 10, Rectangle.Y);
     216      path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y, 20, 20, -90, 90);
     217      path.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + 10, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 10);
     218      path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y + Rectangle.Height - 20, 20, 20, 0, 90);
     219      path.AddLine(Rectangle.X + Rectangle.Width - 10, Rectangle.Y + Rectangle.Height, Rectangle.X + 10, Rectangle.Y + Rectangle.Height);
     220      path.AddArc(Rectangle.X, Rectangle.Y + Rectangle.Height - 20, 20, 20, 90, 90);
     221      path.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height - 10, Rectangle.X, Rectangle.Y + 10);
     222      //shadow
     223      if (ArtPalette.EnableShadows) {
     224        Region darkRegion = new Region(path);
     225        darkRegion.Translate(5, 5);
     226        g.FillRegion(ArtPalette.ShadowBrush, darkRegion);
     227      }
     228      //background
     229      g.FillPath(Brush, path);
     230
     231      using (LinearGradientBrush gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(Rectangle.X + Rectangle.Width, Rectangle.Y), this.Color, Color.White)) {
     232        Region gradientRegion = new Region(path);
     233        g.FillRegion(gradientBrush, gradientRegion);
     234      }
     235
     236      if (!this.Collapsed) {
     237        TextStyle textStyle = new TextStyle(Color.Black, new Font("Arial", 7), StringAlignment.Near, StringAlignment.Near);
     238        StringFormat stringFormat = textStyle.StringFormat;
     239        stringFormat.Trimming = StringTrimming.EllipsisWord;
     240        stringFormat.FormatFlags = StringFormatFlags.LineLimit;
     241        Rectangle rect;
     242
     243        for (int i = 0; i < this.labels.Count; i++) {
     244          rect = new Rectangle(Rectangle.X + 25, Rectangle.Y + HEADER_HEIGHT + i * (LABEL_HEIGHT + LABEL_SPACING), LABEL_WIDTH, LABEL_HEIGHT);
     245          g.DrawString(textStyle.GetFormattedText(this.labels[i]), textStyle.Font, textStyle.GetBrush(), rect, stringFormat);
     246        }
     247      }
     248
     249      //the border
     250      g.DrawPath(pen, path);
     251
     252      //the title
     253      g.DrawString(this.Title, ArtPalette.DefaultBoldFont, Brushes.Black, new Rectangle(Rectangle.X + 25, Rectangle.Y + 5, Rectangle.Width - 45, 27));
     254
     255      //the material
     256      foreach (IPaintable material in Children)
     257        material.Paint(g);
     258
     259      //the connectors
     260      if (this.ShowConnectors) {
     261        for (int k = 0; k < Connectors.Count; k++)
     262          Connectors[k].Paint(g);
     263      }
    105264    }
    106265  }
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs

    r2868 r2934  
    2828using Netron.Diagramming.Core;
    2929using System.Windows.Forms;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.Operators.Views.GraphVisualization {
    32   internal class OperatorShapeInfo : ShapeInfo {
     33  internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
     34    [Storable]
     35    private List<string> connectorNames;
     36    [Storable]
     37    private List<string> labels;
    3338
    34     private List<string> connectorNames;
    3539    public OperatorShapeInfo()
    3640      : base(typeof(OperatorShape)) {
    3741      this.connectorNames = new List<string>();
     42      this.labels = new List<string>();
    3843    }
    3944
     
    4449    }
    4550
    46     public override void AddConnector(string connectorName) {
     51    public OperatorShapeInfo(IEnumerable<string> connectorNames, IEnumerable<string> labels)
     52      : this(connectorNames) {
     53      foreach (string label in labels)
     54        this.labels.Add(label);
     55    }
     56
     57    public void AddConnector(string connectorName) {
    4758      if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") {
    4859        this.connectorNames.Add(connectorName);
     
    5162    }
    5263
    53     public override void RemoveConnector(string connectorName) {
     64    public void RemoveConnector(string connectorName) {
    5465      if (this.connectorNames.Contains(connectorName)) {
    5566        this.connectorNames.Remove(connectorName);
     
    5869    }
    5970
     71    public void UpdateLabels(IEnumerable<string> labels) {
     72      this.labels = new List<string>(labels);
     73      this.OnChanged();
     74    }
     75
     76    [Storable]
     77    private bool collapsed;
     78    public bool Collapsed {
     79      get { return this.collapsed; }
     80      set {
     81        if (this.collapsed != value) {
     82          this.collapsed = value;
     83          this.OnChanged();
     84        }
     85      }
     86    }
     87
     88    [Storable]
    6089    private string title;
    6190    public string Title {
     
    6998    }
    7099
    71     private string text;
    72     public string Text {
    73       get { return this.text; }
     100    [Storable]
     101    private Color color;
     102    public Color Color {
     103      get { return this.color; }
    74104      set {
    75         if (this.text != value) {
    76           this.text = value;
     105        if (this.color != value) {
     106          this.color = value;
    77107          this.OnChanged();
    78108        }
     
    80110    }
    81111
    82     private Color headColor;
    83     public Color HeadColor {
    84       get { return this.headColor; }
     112    [Storable]
     113    private Bitmap icon;
     114    public Bitmap Icon {
     115      get { return this.icon; }
    85116      set {
    86         if (this.headColor != value) {
    87           this.headColor = value;
     117        if (this.icon != value) {
     118          this.icon = value;
    88119          this.OnChanged();
    89120        }
     
    94125      OperatorShape shape = (OperatorShape)base.CreateShape();
    95126      shape.Title = this.Title;
    96       shape.SubTitle = this.Text;
    97       shape.HeadColor = this.HeadColor;
     127      shape.Color = this.Color;
     128      shape.Icon = this.Icon;
     129      shape.Collapsed = this.Collapsed;
    98130      foreach (string connectorName in this.connectorNames)
    99131        shape.AddConnector(connectorName);
     132
     133      shape.UpdateLabels(this.labels);
    100134      return shape;
    101135    }
     
    104138      base.UpdateShape(shape);
    105139      OperatorShape operatorShape = shape as OperatorShape;
    106 
    107140      if (operatorShape != null) {
    108141        operatorShape.Title = this.Title;
    109         operatorShape.SubTitle = this.Text;
    110         operatorShape.HeadColor = this.HeadColor;
     142        operatorShape.Color = this.Color;
     143        operatorShape.Collapsed = this.Collapsed;
    111144
    112145        int i = 0;
     
    121154          j++;
    122155        }
    123         //remove old connectors
     156        //remove remaining old connectors
    124157        for (; j < oldConnectorNames.Count; j++)
    125158          operatorShape.RemoveConnector(oldConnectorNames[j]);
     
    128161        for (; i < this.connectorNames.Count; i++)
    129162          operatorShape.AddConnector(this.connectorNames[i]);
     163
     164        operatorShape.UpdateLabels(this.labels);
    130165      }
    131166    }
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfo.cs

    r2893 r2934  
    2828using Netron.Diagramming.Core;
    2929using HeuristicLab.Collections;
     30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
    3132namespace HeuristicLab.Operators.Views.GraphVisualization {
    32   internal abstract class ShapeInfo : Item, IShapeInfo {
     33  internal abstract class ShapeInfo : Item,IShapeInfo {
     34    private ShapeInfo() {
     35
     36    }
    3337    protected ShapeInfo(Type shapeType) {
    3438      if (!typeof(IShape).IsAssignableFrom(shapeType))
     
    3741    }
    3842
     43    public event EventHandler Changed;
     44
     45    [Storable]
    3946    private Type shapeType;
    4047    public Type ShapeType {
     
    4249    }
    4350
     51    [Storable]
    4452    private Point location;
    4553    public Point Location {
     
    5361    }
    5462
    55     private Size size;
    56     public Size Size {
    57       get { return this.size; }
    58       set {
    59         if (this.size != value) {
    60           this.size = value;
    61           this.OnChanged();
    62         }
    63       }
     63    protected void OnChanged() {
     64      if (this.Changed != null)
     65        this.Changed(this, EventArgs.Empty);
    6466    }
    65 
    66     public abstract void AddConnector(string connectorName);
    67     public abstract void RemoveConnector(string connectorName);
    6867
    6968    public virtual IShape CreateShape() {
     
    7170      shape.Tag = this;
    7271      shape.Location = this.Location;
    73       shape.Height = this.Size.Height;
    74       shape.Width = this.Size.Width;
    7572      return shape;
    7673    }
     
    7875    public virtual void UpdateShape(IShape shape) {
    7976      shape.Location = this.Location;
    80       shape.Height = this.Size.Height;
    81       shape.Width = this.Size.Width;
    8277    }
    8378  }
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfoFactory.cs

    r2875 r2934  
    3838    }
    3939
    40     public static IShapeInfo CreateShapeInfo(IOperator op) {
    41       IEnumerable<string> paramterNames = op.Parameters.Where(p => p is IValueParameter<IOperator> && p.Name != "Successor").Select(p => p.Name);
    42       OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(paramterNames);
     40    public static IOperatorShapeInfo CreateOperatorShapeInfo(IOperator op) {
     41      IEnumerable<string> operatorParameterNames = op.Parameters.Where(p => p is IValueParameter<IOperator> && p.Name != "Successor").Select(p => p.Name);
     42      IEnumerable<string> paramaterNameValues = op.Parameters.Where(p => !(p is IValueParameter<IOperator>)).Select(p => p.ToString());
     43
     44      OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames,paramaterNameValues);
     45      operatorShapeInfo.Collapsed = true;
    4346      operatorShapeInfo.Title = op.Name;
    44       operatorShapeInfo.Text = op.GetType().ToString();
    45       operatorShapeInfo.HeadColor = Color.LightBlue;
     47      operatorShapeInfo.Color = Color.LightBlue;
     48      operatorShapeInfo.Icon = new Bitmap(op.ItemImage);
    4649
    4750      return operatorShapeInfo;
Note: See TracChangeset for help on using the changeset viewer.