- Timestamp:
- 03/05/10 12:37:59 (15 years ago)
- 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 28 28 using System.Drawing; 29 29 using HeuristicLab.Collections; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 31 32 namespace HeuristicLab.Operators.Views.GraphVisualization { 32 33 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 34 44 private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping; 35 private Dictionary<I ValueParameter<IOperator>, IOperator> parameterOperatorMapping;45 private Dictionary<IParameter, IOperator> parameterOperatorMapping; 36 46 37 47 private GraphVisualizationInfo() { 38 this. shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>();48 this.operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>(); 39 49 this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>(); 40 this.parameterOperatorMapping = new Dictionary<I ValueParameter<IOperator>, IOperator>();41 42 this.shapeInfos = new ObservableSet<I ShapeInfo>();43 this.connections = new ObservableDictionary<KeyValuePair<I ShapeInfo, 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>(); 44 54 } 45 55 … … 53 63 54 64 foreach (IOperator op in operatorGraph.Operators) 55 if (!this. shapeInfoMapping.ContainsFirst(op))65 if (!this.operatorShapeInfoMapping.ContainsFirst(op)) 56 66 this.AddOperator(op); 57 67 … … 65 75 66 76 private void UpdateInitialShape() { 67 OperatorShapeInfo old = this.oldInitialShape as OperatorShapeInfo;77 IOperatorShapeInfo old = this.oldInitialShape as OperatorShapeInfo; 68 78 if (old != null) 69 old. HeadColor = oldInitialShapeColor;79 old.Color = oldInitialShapeColor; 70 80 71 81 OperatorShapeInfo newInitialShapeInfo = this.InitialShape as OperatorShapeInfo; 72 82 if (newInitialShapeInfo != null) { 73 oldInitialShapeColor = newInitialShapeInfo. HeadColor;74 newInitialShapeInfo. HeadColor = Color.LightGreen;83 oldInitialShapeColor = newInitialShapeInfo.Color; 84 newInitialShapeInfo.Color = Color.LightGreen; 75 85 } 76 86 … … 80 90 } 81 91 82 private IShapeInfo oldInitialShape; 92 [Storable] 93 private IOperatorShapeInfo oldInitialShape; 94 [Storable] 83 95 private Color oldInitialShapeColor; 84 public I ShapeInfo InitialShape {96 public IOperatorShapeInfo InitialShape { 85 97 get { 86 98 IOperator op = this.operatorGraph.InitialOperator; 87 99 if (op == null) 88 100 return null; 89 return this. shapeInfoMapping.GetByFirst(op);101 return this.operatorShapeInfoMapping.GetByFirst(op); 90 102 } 91 103 set { … … 93 105 this.OperatorGraph.InitialOperator = null; 94 106 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] 99 112 private OperatorGraph operatorGraph; 100 113 public OperatorGraph OperatorGraph { … … 102 115 } 103 116 104 private ObservableSet<I ShapeInfo> shapeInfos;105 public INotifyObservableCollectionItemsChanged<I ShapeInfo> ObserveableShapeInfos {117 private ObservableSet<IOperatorShapeInfo> shapeInfos; 118 public INotifyObservableCollectionItemsChanged<IOperatorShapeInfo> ObserveableShapeInfos { 106 119 get { return this.shapeInfos; } 107 120 } 108 public IEnumerable<I ShapeInfo>ShapeInfos {121 public IEnumerable<IOperatorShapeInfo> OperatorShapeInfos { 109 122 get { return this.shapeInfos; } 110 123 } 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 { 117 131 get { return this.connections; } 118 132 } 119 public IEnumerable<KeyValuePair<KeyValuePair<I ShapeInfo, string>, IShapeInfo>> Connections {133 public IEnumerable<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> Connections { 120 134 get { return this.connections; } 121 135 } 122 136 123 137 #region methods to manipulate operatorgraph by the shape info 124 internal void AddShapeInfo(IOperator op, I ShapeInfo shapeInfo) {138 internal void AddShapeInfo(IOperator op, IOperatorShapeInfo shapeInfo) { 125 139 this.RegisterOperatorEvents(op); 126 140 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 127 this. shapeInfoMapping.Add(op, shapeInfo);141 this.operatorShapeInfoMapping.Add(op, shapeInfo); 128 142 this.shapeInfos.Add(shapeInfo); 129 143 … … 131 145 this.AddParameter(op, param); 132 146 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); 138 153 this.operatorGraph.Operators.Remove(op); 139 154 } 140 155 141 internal void AddConnection(I ShapeInfo 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); 144 159 145 160 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; … … 147 162 } 148 163 149 internal void ChangeConnection(I ShapeInfo 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); 152 167 153 168 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; … … 155 170 } 156 171 157 internal void RemoveConnection(I ShapeInfo 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); 159 174 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 160 175 param.Value = null; … … 164 179 #region operator events 165 180 private void AddOperator(IOperator op) { 166 if (!this. shapeInfoMapping.ContainsFirst(op)) {181 if (!this.operatorShapeInfoMapping.ContainsFirst(op)) { 167 182 this.RegisterOperatorEvents(op); 168 I ShapeInfo shapeInfo = Factory.CreateShapeInfo(op);183 IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op); 169 184 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 170 this. shapeInfoMapping.Add(op, shapeInfo);185 this.operatorShapeInfoMapping.Add(op, shapeInfo); 171 186 foreach (IParameter param in op.Parameters) 172 187 this.AddParameter(op, param); … … 181 196 this.RemoveParameter(op, param); 182 197 183 I ShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);198 IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op); 184 199 this.operatorParameterCollectionMapping.RemoveByFirst(op); 185 this. shapeInfoMapping.RemoveByFirst(op);200 this.operatorShapeInfoMapping.RemoveByFirst(op); 186 201 this.shapeInfos.Remove(shapeInfo); 187 202 } … … 189 204 private void OperatorNameChanged(object sender, EventArgs e) { 190 205 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; 195 208 } 196 209 … … 229 242 #region parameter events 230 243 private void AddParameter(IOperator op, IParameter param) { 244 this.parameterOperatorMapping.Add(param, op); 231 245 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 232 246 if (opParam != null) { 233 247 this.RegisterOperatorParameterEvents(opParam); 234 this.parameterOperatorMapping.Add(opParam, op); 235 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 248 IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op); 236 249 shapeInfo.AddConnector(param.Name); 237 250 238 251 if (opParam.Value != null) { 239 if (!this. shapeInfoMapping.ContainsFirst(opParam.Value))252 if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value)) 240 253 this.AddOperator(opParam.Value); 241 this.connections.Add(new KeyValuePair<I ShapeInfo, 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)); 242 255 } 243 } 256 } else 257 this.RegisterParameterEvents(param); 244 258 } 245 259 … … 248 262 if (opParam != null) { 249 263 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)); 254 266 shapeInfo.RemoveConnector(param.Name); 255 } 267 } else 268 this.DeregisterParameterEvents(param); 269 270 this.parameterOperatorMapping.Remove(param); 256 271 } 257 272 … … 260 275 if (opParam != null) { 261 276 IOperator op = this.parameterOperatorMapping[opParam]; 262 I ShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op);263 KeyValuePair<I ShapeInfo, 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); 264 279 265 280 if (opParam.Value == null) 266 281 this.connections.Remove(connectionFrom); 267 282 else { 268 if (!this. shapeInfoMapping.ContainsFirst(opParam.Value))283 if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value)) 269 284 this.AddOperator(opParam.Value); 270 this.connections[connectionFrom] = this. shapeInfoMapping.GetByFirst(opParam.Value);285 this.connections[connectionFrom] = this.operatorShapeInfoMapping.GetByFirst(opParam.Value); 271 286 } 272 287 } … … 278 293 foreach (IParameter param in e.Items) 279 294 AddParameter(op, param); 295 this.UpdateParameterLabels(op); 280 296 } 281 297 private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) { … … 284 300 foreach (IParameter param in e.Items) 285 301 RemoveParameter(op, param); 302 this.UpdateParameterLabels(op); 286 303 } 287 304 private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) { … … 292 309 foreach (IParameter param in e.Items) 293 310 AddParameter(op, param); 311 this.UpdateParameterLabels(op); 294 312 } 295 313 private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) { … … 300 318 foreach (IParameter param in e.Items) 301 319 AddParameter(op, param); 320 this.UpdateParameterLabels(op); 302 321 } 303 322 … … 307 326 private void DeregisterOperatorParameterEvents(IValueParameter<IOperator> opParam) { 308 327 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>()); 309 356 } 310 357 #endregion -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/IShapeInfo.cs
r2868 r2934 33 33 Type ShapeType { get; } 34 34 Point Location { get; set; } 35 Size Size { get; set; }36 37 void AddConnector(string connectorName);38 void RemoveConnector(string connectorName);39 35 40 36 IShape CreateShape(); 41 37 void UpdateShape(IShape shape); 38 39 event EventHandler Changed; 42 40 } 43 41 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs
r2872 r2934 26 26 using Netron.Diagramming.Core; 27 27 using System.Drawing; 28 using System.Drawing.Drawing2D; 29 using HeuristicLab.Netron; 28 30 29 31 namespace 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; 32 39 public OperatorShape() 33 40 : base() { 41 this.Resizable = false; 34 42 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 37 80 private List<IConnector> additionalConnectors; 38 81 public IEnumerable<string> AdditionalConnectorNames { … … 58 101 } 59 102 60 61 62 103 public void AddConnector(string connectorName) { 63 104 IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner); … … 89 130 } 90 131 } 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 } 92 173 93 174 protected override void Initialize() { 94 175 base.Initialize(); 95 176 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 } 105 264 } 106 265 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs
r2868 r2934 28 28 using Netron.Diagramming.Core; 29 29 using System.Windows.Forms; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 31 32 namespace 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; 33 38 34 private List<string> connectorNames;35 39 public OperatorShapeInfo() 36 40 : base(typeof(OperatorShape)) { 37 41 this.connectorNames = new List<string>(); 42 this.labels = new List<string>(); 38 43 } 39 44 … … 44 49 } 45 50 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) { 47 58 if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") { 48 59 this.connectorNames.Add(connectorName); … … 51 62 } 52 63 53 public overridevoid RemoveConnector(string connectorName) {64 public void RemoveConnector(string connectorName) { 54 65 if (this.connectorNames.Contains(connectorName)) { 55 66 this.connectorNames.Remove(connectorName); … … 58 69 } 59 70 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] 60 89 private string title; 61 90 public string Title { … … 69 98 } 70 99 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; } 74 104 set { 75 if (this. text!= value) {76 this. text= value;105 if (this.color != value) { 106 this.color = value; 77 107 this.OnChanged(); 78 108 } … … 80 110 } 81 111 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; } 85 116 set { 86 if (this. headColor!= value) {87 this. headColor= value;117 if (this.icon != value) { 118 this.icon = value; 88 119 this.OnChanged(); 89 120 } … … 94 125 OperatorShape shape = (OperatorShape)base.CreateShape(); 95 126 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; 98 130 foreach (string connectorName in this.connectorNames) 99 131 shape.AddConnector(connectorName); 132 133 shape.UpdateLabels(this.labels); 100 134 return shape; 101 135 } … … 104 138 base.UpdateShape(shape); 105 139 OperatorShape operatorShape = shape as OperatorShape; 106 107 140 if (operatorShape != null) { 108 141 operatorShape.Title = this.Title; 109 operatorShape. SubTitle = this.Text;110 operatorShape. HeadColor = this.HeadColor;142 operatorShape.Color = this.Color; 143 operatorShape.Collapsed = this.Collapsed; 111 144 112 145 int i = 0; … … 121 154 j++; 122 155 } 123 //remove old connectors156 //remove remaining old connectors 124 157 for (; j < oldConnectorNames.Count; j++) 125 158 operatorShape.RemoveConnector(oldConnectorNames[j]); … … 128 161 for (; i < this.connectorNames.Count; i++) 129 162 operatorShape.AddConnector(this.connectorNames[i]); 163 164 operatorShape.UpdateLabels(this.labels); 130 165 } 131 166 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfo.cs
r2893 r2934 28 28 using Netron.Diagramming.Core; 29 29 using HeuristicLab.Collections; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 31 31 32 namespace HeuristicLab.Operators.Views.GraphVisualization { 32 internal abstract class ShapeInfo : Item, IShapeInfo { 33 internal abstract class ShapeInfo : Item,IShapeInfo { 34 private ShapeInfo() { 35 36 } 33 37 protected ShapeInfo(Type shapeType) { 34 38 if (!typeof(IShape).IsAssignableFrom(shapeType)) … … 37 41 } 38 42 43 public event EventHandler Changed; 44 45 [Storable] 39 46 private Type shapeType; 40 47 public Type ShapeType { … … 42 49 } 43 50 51 [Storable] 44 52 private Point location; 45 53 public Point Location { … … 53 61 } 54 62 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); 64 66 } 65 66 public abstract void AddConnector(string connectorName);67 public abstract void RemoveConnector(string connectorName);68 67 69 68 public virtual IShape CreateShape() { … … 71 70 shape.Tag = this; 72 71 shape.Location = this.Location; 73 shape.Height = this.Size.Height;74 shape.Width = this.Size.Width;75 72 return shape; 76 73 } … … 78 75 public virtual void UpdateShape(IShape shape) { 79 76 shape.Location = this.Location; 80 shape.Height = this.Size.Height;81 shape.Width = this.Size.Width;82 77 } 83 78 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/ShapeInfoFactory.cs
r2875 r2934 38 38 } 39 39 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; 43 46 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); 46 49 47 50 return operatorShapeInfo;
Note: See TracChangeset
for help on using the changeset viewer.