- Timestamp:
- 02/24/10 17:58:03 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/IShapeInfo.cs
r2853 r2861 27 27 using System.Drawing; 28 28 using Netron.Diagramming.Core; 29 using HeuristicLab.Collections; 29 30 30 31 namespace HeuristicLab.Operators.Views.GraphVisualization { … … 34 35 Size Size { get; set; } 35 36 37 void AddConnector(string connectorName); 38 void RemoveConnector(string connectorName); 39 40 IEnumerable<KeyValuePair<string,IShapeInfo>> Connections {get;} 41 INotifyObservableDictionaryItemsChanged<string, IShapeInfo> ObservableConnections { get; } 42 43 void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo); 44 void RemoveConnection(string fromConnectorName); 45 void ChangeConnection(string fromConnector, IShapeInfo toShapeInfo); 46 36 47 IShape CreateShape(); 48 void UpdateShape(IShape shape); 37 49 } 38 50 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorGraphVisualizationInfo.cs
r2853 r2861 30 30 31 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 32 public sealed class OperatorGraphVisualizationInfo : Item{32 public sealed class OperatorGraphVisualizationInfo : DeepCloneable { 33 33 private BidirectionalLookup<IOperator, IShapeInfo> shapeInfoMapping; 34 35 public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) { 34 private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping; 35 private Dictionary<IValueParameter<IOperator>, IOperator> parameterOperatorMapping; 36 37 private OperatorGraphVisualizationInfo() { 38 this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>(); 39 this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>(); 40 this.parameterOperatorMapping = new Dictionary<IValueParameter<IOperator>, IOperator>(); 41 42 this.shapeInfos = new ObservableSet<IShapeInfo>(); 43 } 44 45 public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) 46 : this() { 36 47 this.operatorGraph = operatorGraph; 37 this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>(); 38 this.shapeInfos = new ObservableSet<IShapeInfo>(); 39 48 this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged); 40 49 foreach (IOperator op in operatorGraph.Operators) 41 50 this.AddOperator(op); 42 this.initialOperator = operatorGraph.InitialOperator;43 51 44 52 operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); … … 47 55 } 48 56 57 public event EventHandler InitialShapeChanged; 58 private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) { 59 if (this.InitialShapeChanged != null) 60 this.InitialShapeChanged(this, new EventArgs()); 61 } 62 63 public IShapeInfo InitialShape { 64 get { 65 IOperator op = this.operatorGraph.InitialOperator; 66 if (op == null) 67 return null; 68 return this.shapeInfoMapping.GetByFirst(op); 69 } 70 } 71 49 72 private OperatorGraph operatorGraph; 50 73 public OperatorGraph OperatorGraph { … … 56 79 get { return this.shapeInfos; } 57 80 } 58 59 81 public IEnumerable<IShapeInfo> ShapeInfos { 60 82 get { return this.shapeInfos; } 61 83 } 62 84 63 private IOperator initialOperator;64 public IOperator InitialOperator {65 get { return this.initialOperator; }66 set {67 if (this.initialOperator != value) {68 if (!this.shapeInfoMapping.ContainsFirst(value))69 throw new ArgumentException("Could not set initial operator in graph visualization information, because the operator " +70 value.ToString() + " is not contained in the operator set.");71 this.initialOperator = value;72 this.OnChanged();73 }74 }75 }76 77 85 internal void AddShapeInfo(IOperator op, IShapeInfo shapeInfo) { 78 86 this.RegisterOperatorEvents(op); 87 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 79 88 this.shapeInfoMapping.Add(op, shapeInfo); 80 89 this.shapeInfos.Add(shapeInfo); … … 90 99 #region operator events 91 100 private void AddOperator(IOperator op) { 92 if (!shapeInfoMapping.ContainsFirst(op)) { 93 this.RegisterOperatorEvents(op); 94 95 IShapeInfo shapeInfo = ShapeInfoFactory.CreateShapeInfo(op); 96 this.shapeInfoMapping.Add(op, shapeInfo); 97 this.shapeInfos.Add(shapeInfo); 98 } 101 if (shapeInfoMapping.ContainsFirst(op)) 102 return; 103 104 this.RegisterOperatorEvents(op); 105 IShapeInfo shapeInfo = Factory.CreateShapeInfo(op); 106 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 107 this.shapeInfoMapping.Add(op, shapeInfo); 108 foreach (IParameter param in op.Parameters) 109 this.AddParameter(op, param); 110 111 this.shapeInfos.Add(shapeInfo); 99 112 } 100 113 101 114 private void RemoveOperator(IOperator op) { 102 115 this.DeregisterOperatorEvents(op); 116 foreach (IParameter param in op.Parameters) 117 this.RemoveParameter(op, param); 103 118 104 119 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 120 this.operatorParameterCollectionMapping.RemoveByFirst(op); 105 121 this.shapeInfoMapping.RemoveByFirst(op); 106 122 this.shapeInfos.Remove(shapeInfo); … … 139 155 140 156 #region parameter events 141 private void AddParameter(I Parameter param) {157 private void AddParameter(IOperator op, IParameter param) { 142 158 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 143 159 if (opParam != null) { 144 RegisterOperatorParameterEvents(opParam); 145 //TODO add connector 146 } 147 } 148 private void RemoveParameter(IParameter param) { 160 this.RegisterOperatorParameterEvents(opParam); 161 this.parameterOperatorMapping.Add(opParam, op); 162 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 163 shapeInfo.AddConnector(param.Name); 164 165 if (opParam.Value != null) { 166 if (!this.shapeInfoMapping.ContainsFirst(opParam.Value)) 167 this.AddOperator(opParam.Value); 168 shapeInfo.AddConnection(param.Name, this.shapeInfoMapping.GetByFirst(opParam.Value)); 169 } 170 } 171 } 172 private void RemoveParameter(IOperator op, IParameter param) { 149 173 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 150 174 if (opParam != null) { 151 DeregisterOperatorParameterEvents(opParam); 152 //TODO remove connector 175 this.DeregisterOperatorParameterEvents(opParam); 176 this.parameterOperatorMapping.Remove(opParam); 177 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 178 shapeInfo.RemoveConnector(param.Name); 153 179 } 154 180 } … … 156 182 private void opParam_ValueChanged(object sender, EventArgs e) { 157 183 IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender; 158 //TODO update connections 184 if (opParam != null) { 185 IOperator op = this.parameterOperatorMapping[opParam]; 186 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 187 188 if (opParam.Value == null) 189 shapeInfo.RemoveConnection(opParam.Name); 190 else 191 shapeInfo.ChangeConnection(opParam.Name, this.shapeInfoMapping.GetByFirst(opParam.Value)); 192 } 159 193 } 160 194 161 195 private void Parameters_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 162 foreach (IParameter param in e.Items) 163 AddParameter(param); 196 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 197 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 198 foreach (IParameter param in e.Items) 199 AddParameter(op, param); 164 200 } 165 201 private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 166 foreach (IParameter param in e.Items) 167 RemoveParameter(param); 202 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 203 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 204 foreach (IParameter param in e.Items) 205 RemoveParameter(op, param); 168 206 } 169 207 private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 208 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 209 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 170 210 foreach (IParameter param in e.OldItems) 171 RemoveParameter( param);172 foreach (IParameter param in e.Items) 173 AddParameter( param);211 RemoveParameter(op, param); 212 foreach (IParameter param in e.Items) 213 AddParameter(op, param); 174 214 } 175 215 private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 216 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 217 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 176 218 foreach (IParameter param in e.OldItems) 177 RemoveParameter(param); 178 foreach (IParameter param in e.Items) 179 AddParameter(param); 180 } 219 RemoveParameter(op, param); 220 foreach (IParameter param in e.Items) 221 AddParameter(op, param); 222 } 223 181 224 182 225 private void RegisterOperatorParameterEvents(IValueParameter<IOperator> opParam) { … … 187 230 } 188 231 #endregion 189 190 191 192 193 194 195 196 197 private static IConnection CreateConnection(IShape from, IShape to) {198 IConnector parentConnector = from.Connectors.Where(c => c.Name == "Bottom connector").First();199 IConnector operatorConnector = to.Connectors.Where(c => c.Name == "Top connector").First();200 201 IConnection connection = new Connection(parentConnector.Point, operatorConnector.Point);202 203 parentConnector.AttachConnector(connection.From);204 operatorConnector.AttachConnector(connection.To);205 206 return connection;207 }208 232 } 209 233 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs
r2853 r2861 30 30 public class OperatorShape : ClassShape { 31 31 32 private BidirectionalLookup<string, IConnector> additionalConnectors;33 32 public OperatorShape() 34 33 : base() { 35 this.additionalConnectors = new BidirectionalLookup<string,IConnector>();34 this.additionalConnectors = new List<IConnector>(); 36 35 } 37 36 38 private Connector predecessor; 39 public Connector Predecessor { 37 private List<IConnector> additionalConnectors; 38 public IEnumerable<string> AdditionalConnectorNames { 39 get { return this.additionalConnectors.Select(c => c.Name); } 40 } 41 42 private IConnector predecessor; 43 public IConnector Predecessor { 40 44 get { return this.predecessor; } 41 45 } 42 46 43 private Connector successor;44 public Connector Successor {47 private IConnector successor; 48 public IConnector Successor { 45 49 get { return this.successor; } 46 50 } 47 51 52 private IConnector CreateConnector(string connectorName, Point location) { 53 Connector connector = new Connector(location); 54 connector.ConnectorStyle = ConnectorStyle.Square; 55 connector.Parent = this; 56 connector.Name = connectorName; 57 return connector; 58 } 59 60 48 61 49 62 public void AddConnector(string connectorName) { 50 Connector connector = new Connector(new Point(Rectangle.Right, Rectangle.Bottom));51 connector.ConnectorStyle = ConnectorStyle.Square; 52 connector.Parent = this;53 this. additionalConnectors.Add(connectorName,connector);54 Connectors.Add(connector);63 IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner); 64 65 this.additionalConnectors.Add(connector); 66 this.Connectors.Add(connector); 67 this.UpdateConnectorLocation(); 55 68 } 56 69 57 70 public void RemoveConnector(string connectorName) { 58 this.additionalConnectors.RemoveByFirst(connectorName); 59 this.UpdateConnectorLocation(); 71 IConnector connector = this.additionalConnectors.Where(c => c.Name ==connectorName).FirstOrDefault(); 72 if (connector != null) { 73 this.additionalConnectors.Remove(connector); 74 this.Connectors.Remove(connector); 75 this.UpdateConnectorLocation(); 76 } 60 77 } 61 78 62 private void UpdateConnectorLocation() { 63 //TODO set x position of connectors 79 private void UpdateConnectorLocation() { 80 int spacing = this.Rectangle.Width / this.additionalConnectors.Count + 1; 81 int margin = spacing / 2; 82 int posX = margin + this.Rectangle.X; 83 int posY = this.additionalConnectors[0].Point.Y; 84 for (int i = 0; i < this.additionalConnectors.Count; i++) { 85 this.additionalConnectors[i].Point = new Point(posX, posY); 86 posX += spacing; 87 } 64 88 } 65 89 … … 71 95 this.Connectors.Clear(); 72 96 73 predecessor = new Connector(new Point(Rectangle.Right, (int)(Rectangle.Top + Rectangle.Height / 2))); 74 predecessor.ConnectorStyle = ConnectorStyle.Square; 75 predecessor.Name = "Predecessor"; 76 predecessor.Parent = this; 97 predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y)); 77 98 Connectors.Add(predecessor); 78 99 79 successor = new Connector(new Point(Rectangle.Left, (int)(Rectangle.Top + Rectangle.Height / 2))); 80 predecessor.ConnectorStyle = ConnectorStyle.Square; 81 successor.Name = "Successor"; 82 successor.Parent = this; 100 successor = this.CreateConnector("Successor",(new Point(Rectangle.Right, Center.Y))); 83 101 Connectors.Add(successor); 84 102 #endregion -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs
r2853 r2861 27 27 using System.Drawing; 28 28 using Netron.Diagramming.Core; 29 using System.Windows.Forms; 29 30 30 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 31 32 internal class OperatorShapeInfo : ShapeInfo { 32 33 33 private HashSet<string> connectorNames;34 private List<string> connectorNames; 34 35 public OperatorShapeInfo() 35 36 : base(typeof(OperatorShape)) { 36 this.connectorNames = new HashSet<string>();37 this.connectorNames = new List<string>(); 37 38 } 38 39 … … 43 44 } 44 45 45 public void AddConnector(string connectorName) { 46 if (this.connectorNames.Add(connectorName)) 46 public override void AddConnector(string connectorName) { 47 if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") { 48 this.connectorNames.Add(connectorName); 47 49 this.OnChanged(); 50 } 48 51 } 49 52 50 public void RemoveConnector(string connectorName) { 51 if (this.connectorNames.Remove(connectorName)) 53 public override void RemoveConnector(string connectorName) { 54 if (this.connectorNames.Contains(connectorName)) { 55 this.connectorNames.Remove(connectorName); 56 if (this.connections.ContainsKey(connectorName)) 57 this.connections.Remove(connectorName); 52 58 this.OnChanged(); 59 } 53 60 } 54 61 62 public override void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo) { 63 this.connections.Add(fromConnectorName, toShapeInfo); 64 } 65 66 public override void RemoveConnection(string fromConnectorName) { 67 if (this.connections.ContainsKey(fromConnectorName)) 68 this.connections.Remove(fromConnectorName); 69 } 70 71 public override void ChangeConnection(string fromConnectorName, IShapeInfo toShapeInfo) { 72 this.connections[fromConnectorName] = toShapeInfo; 73 } 55 74 56 75 private string title; … … 96 115 return shape; 97 116 } 117 118 public override void UpdateShape(IShape shape) { 119 base.UpdateShape(shape); 120 OperatorShape operatorShape = shape as OperatorShape; 121 122 if (operatorShape != null) { 123 operatorShape.Title = this.Title; 124 operatorShape.SubTitle = this.Text; 125 operatorShape.HeadColor = this.HeadColor; 126 127 int i = 0; 128 int j = 0; 129 //remove old connectors and skip correct connectors 130 List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList(); 131 while (i < this.connectorNames.Count && j < oldConnectorNames.Count) { 132 if (this.connectorNames[i] != oldConnectorNames[j]) { 133 operatorShape.RemoveConnector(oldConnectorNames[j]); 134 } else 135 i++; 136 j++; 137 } 138 //remove old connectors 139 for (; j < oldConnectorNames.Count; i++) 140 operatorShape.RemoveConnector(oldConnectorNames[j]); 141 142 //add new connectors 143 for (; i < this.connectorNames.Count; i++) 144 operatorShape.AddConnector(this.connectorNames[i]); 145 } 146 } 98 147 } 99 148 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfo.cs
r2853 r2861 27 27 using System.Drawing; 28 28 using Netron.Diagramming.Core; 29 using HeuristicLab.Collections; 29 30 30 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 31 32 internal abstract class ShapeInfo : Item, IShapeInfo { 32 33 34 33 protected ShapeInfo(Type shapeType) { 35 34 if (!typeof(IShape).IsAssignableFrom(shapeType)) 36 35 throw new ArgumentException("The passed shape type " + shapeType + " must be derived from IShape."); 37 36 this.shapeType = shapeType; 37 this.connections = new ObservableDictionary<string, IShapeInfo>(); 38 38 } 39 39 … … 65 65 } 66 66 67 protected ObservableDictionary<string, IShapeInfo> connections; 68 public IEnumerable<KeyValuePair<string, IShapeInfo>> Connections { 69 get { return this.connections; } 70 } 71 public INotifyObservableDictionaryItemsChanged<string, IShapeInfo> ObservableConnections { 72 get { return this.connections; } 73 } 74 75 public abstract void AddConnector(string connectorName); 76 public abstract void RemoveConnector(string connectorName); 77 public abstract void AddConnection(string fromConnectorName, IShapeInfo toShapeInfo); 78 public abstract void RemoveConnection(string fromConnectorName); 79 public abstract void ChangeConnection(string fromConnectorName, IShapeInfo toShapeInfo); 80 81 67 82 public virtual IShape CreateShape() { 68 83 IShape shape = (IShape)Activator.CreateInstance(this.shapeType); … … 72 87 return shape; 73 88 } 89 90 public virtual void UpdateShape(IShape shape) { 91 shape.Location = this.Location; 92 shape.Height = this.Size.Height; 93 shape.Width = this.Size.Width; 94 } 74 95 } 75 96 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfoFactory.cs
r2853 r2861 25 25 using System.Text; 26 26 using HeuristicLab.Core; 27 using Netron.Diagramming.Core; 28 using System.Drawing; 29 using System.Drawing.Drawing2D; 27 30 28 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 29 public static class ShapeInfoFactory { 32 public static class Factory { 33 private static LinePenStyle connectionPenStyle; 34 35 static Factory() { 36 connectionPenStyle = new LinePenStyle(); 37 connectionPenStyle.EndCap = LineCap.ArrowAnchor; 38 } 39 30 40 public static IShapeInfo CreateShapeInfo(IOperator op) { 31 OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(); 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); 32 43 operatorShapeInfo.Title = op.Name; 33 44 operatorShapeInfo.Text = op.GetType().ToString(); … … 35 46 return operatorShapeInfo; 36 47 } 48 49 public static IConnection CreateConnection(IConnector from, IConnector to) { 50 Connection connection = new Connection(from.Point, to.Point); 51 connection.AllowMove = false; 52 from.AttachConnector(connection.From); 53 to.AttachConnector(connection.To); 54 connection.PenStyle = connectionPenStyle; 55 return connection; 56 } 37 57 } 38 58 }
Note: See TracChangeset
for help on using the changeset viewer.