- Timestamp:
- 02/25/10 17:28:31 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/IShapeInfo.cs
r2861 r2868 38 38 void RemoveConnector(string connectorName); 39 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 47 40 IShape CreateShape(); 48 41 void UpdateShape(IShape shape); -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorGraphVisualizationInfo.cs
r2861 r2868 41 41 42 42 this.shapeInfos = new ObservableSet<IShapeInfo>(); 43 this.connections = new ObservableDictionary<KeyValuePair<IShapeInfo, string>, IShapeInfo>(); 43 44 } 44 45 … … 48 49 this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged); 49 50 foreach (IOperator op in operatorGraph.Operators) 50 this.AddOperator(op); 51 if (!this.shapeInfoMapping.ContainsFirst(op)) 52 this.AddOperator(op); 51 53 52 54 operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); … … 83 85 } 84 86 87 private ObservableDictionary<KeyValuePair<IShapeInfo, string>, IShapeInfo> connections; 88 public INotifyObservableDictionaryItemsChanged<KeyValuePair<IShapeInfo, string>, IShapeInfo> ObservableConnections { 89 get { return this.connections; } 90 } 91 public IEnumerable<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> Connections { 92 get { return this.connections; } 93 } 94 95 #region methods to manipulate operatorgraph by the shape info 85 96 internal void AddShapeInfo(IOperator op, IShapeInfo shapeInfo) { 86 97 this.RegisterOperatorEvents(op); … … 89 100 this.shapeInfos.Add(shapeInfo); 90 101 102 foreach (IParameter param in op.Parameters) 103 this.AddParameter(op, param); 104 91 105 this.operatorGraph.Operators.Add(op); 92 106 } … … 97 111 } 98 112 113 internal void AddConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) { 114 IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom); 115 IOperator opTo = this.shapeInfoMapping.GetBySecond(shapeInfoTo); 116 117 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 118 param.Value = opTo; 119 } 120 121 internal void ChangeConnection(IShapeInfo shapeInfoFrom, string connectorName, IShapeInfo shapeInfoTo) { 122 IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom); 123 IOperator opTo = this.shapeInfoMapping.GetBySecond(shapeInfoTo); 124 125 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 126 param.Value = opTo; 127 } 128 129 internal void RemoveConnection(IShapeInfo shapeInfoFrom, string connectorName) { 130 IOperator opFrom = this.shapeInfoMapping.GetBySecond(shapeInfoFrom); 131 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 132 param.Value = null; 133 } 134 #endregion 135 99 136 #region operator events 100 137 private void AddOperator(IOperator op) { 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); 138 if (!this.shapeInfoMapping.ContainsFirst(op)) { 139 this.RegisterOperatorEvents(op); 140 IShapeInfo shapeInfo = Factory.CreateShapeInfo(op); 141 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 142 this.shapeInfoMapping.Add(op, shapeInfo); 143 foreach (IParameter param in op.Parameters) 144 this.AddParameter(op, param); 145 146 this.shapeInfos.Add(shapeInfo); 147 } 112 148 } 113 149 … … 166 202 if (!this.shapeInfoMapping.ContainsFirst(opParam.Value)) 167 203 this.AddOperator(opParam.Value); 168 shapeInfo.AddConnection(param.Name, this.shapeInfoMapping.GetByFirst(opParam.Value));204 this.connections.Add(new KeyValuePair<IShapeInfo, string>(shapeInfo, param.Name), this.shapeInfoMapping.GetByFirst(opParam.Value)); 169 205 } 170 206 } 171 207 } 208 172 209 private void RemoveParameter(IOperator op, IParameter param) { 173 210 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; … … 176 213 this.parameterOperatorMapping.Remove(opParam); 177 214 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 215 216 this.connections.Remove(new KeyValuePair<IShapeInfo, string>(shapeInfo, param.Name)); 178 217 shapeInfo.RemoveConnector(param.Name); 179 218 } … … 185 224 IOperator op = this.parameterOperatorMapping[opParam]; 186 225 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 226 KeyValuePair<IShapeInfo, string> connectionFrom = new KeyValuePair<IShapeInfo, string>(shapeInfo, opParam.Name); 187 227 188 228 if (opParam.Value == null) 189 shapeInfo.RemoveConnection(opParam.Name);229 this.connections.Remove(connectionFrom); 190 230 else 191 shapeInfo.ChangeConnection(opParam.Name, this.shapeInfoMapping.GetByFirst(opParam.Value));231 this.connections[connectionFrom] = this.shapeInfoMapping.GetByFirst(opParam.Value); 192 232 } 193 233 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs
r2861 r2868 51 51 52 52 private IConnector CreateConnector(string connectorName, Point location) { 53 Connector connector = new Connector(location );53 Connector connector = new Connector(location, this.Model); 54 54 connector.ConnectorStyle = ConnectorStyle.Square; 55 55 connector.Parent = this; … … 69 69 70 70 public void RemoveConnector(string connectorName) { 71 IConnector connector = this.additionalConnectors.Where(c => c.Name == connectorName).FirstOrDefault();71 IConnector connector = this.additionalConnectors.Where(c => c.Name == connectorName).FirstOrDefault(); 72 72 if (connector != null) { 73 73 this.additionalConnectors.Remove(connector); … … 78 78 79 79 private void UpdateConnectorLocation() { 80 int spacing = this.Rectangle.Width / this.additionalConnectors.Count + 1; 80 if (this.additionalConnectors.Count == 0) 81 return; 82 83 int spacing = this.Rectangle.Width / this.additionalConnectors.Count; 81 84 int margin = spacing / 2; 82 85 int posX = margin + this.Rectangle.X; … … 98 101 Connectors.Add(predecessor); 99 102 100 successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y)));103 successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y))); 101 104 Connectors.Add(successor); 102 105 #endregion -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs
r2861 r2868 54 54 if (this.connectorNames.Contains(connectorName)) { 55 55 this.connectorNames.Remove(connectorName); 56 if (this.connections.ContainsKey(connectorName))57 this.connections.Remove(connectorName);58 56 this.OnChanged(); 59 57 } 60 }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 58 } 74 59 … … 137 122 } 138 123 //remove old connectors 139 for (; j < oldConnectorNames.Count; i++)124 for (; j < oldConnectorNames.Count; j++) 140 125 operatorShape.RemoveConnector(oldConnectorNames[j]); 141 126 -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfo.cs
r2861 r2868 35 35 throw new ArgumentException("The passed shape type " + shapeType + " must be derived from IShape."); 36 36 this.shapeType = shapeType; 37 this.connections = new ObservableDictionary<string, IShapeInfo>();38 37 } 39 38 … … 65 64 } 66 65 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 66 public abstract void AddConnector(string connectorName); 76 67 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 68 82 69 public virtual IShape CreateShape() {
Note: See TracChangeset
for help on using the changeset viewer.