Changeset 10685 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs
- Timestamp:
- 03/31/14 17:24:36 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs
r10677 r10685 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; 24 25 using System.Linq; 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Visualization; 26 28 … … 35 37 public double PreferredNodeWidth { get; set; } 36 38 public double PreferredNodeHeight { get; set; } 39 40 public Size Size { 41 get { 42 int xmin = 0, ymin = 0, xmax = 0, ymax = 0; 43 44 foreach (var p in Primitives.OfType<RectangularPrimitiveBase>()) { 45 if (xmin > p.LowerLeft.X) xmin = (int)Math.Floor(p.LowerLeft.X); 46 if (xmax < p.UpperRight.X) xmax = (int)Math.Ceiling(p.UpperRight.X); 47 if (ymin > p.LowerLeft.Y) ymin = (int)Math.Floor(p.LowerLeft.Y); 48 if (ymax < p.UpperRight.Y) ymax = (int)Math.Ceiling(p.UpperRight.Y); 49 } 50 51 return new Size(xmax - xmin, ymax - ymin); 52 } 53 } 54 55 private Point position; 56 public Point Position { 57 get { return position; } 58 set { 59 var oldpos = position; 60 position = value; 61 int ox = position.X - oldpos.X; 62 int oy = position.Y - oldpos.Y; 63 // translate all primitives to the new position 64 foreach (var p in Primitives) { 65 var rpb = p as RectangularPrimitiveBase; 66 if (rpb != null) { 67 var lowerLeft = new Point((int)Math.Floor(rpb.LowerLeft.X) + ox, (int)Math.Floor(rpb.LowerLeft.Y + oy)); 68 var upperRight = new PointD(lowerLeft.X + rpb.Size.Width, lowerLeft.Y + rpb.Size.Height); 69 rpb.SetPosition(lowerLeft, upperRight); 70 } 71 var line = p as LinearPrimitiveBase; 72 if (line != null) { 73 var start = new Point((int)Math.Floor(line.Start.X) + ox, (int)Math.Floor(line.Start.Y) + oy); 74 var end = new Point(start.X + (int)line.Size.Width, start.Y + (int)line.Size.Height); 75 line.SetPosition(start, end); 76 } 77 } 78 } 79 } 80 37 81 private ISymbolicExpressionTree symbolicExpressionTree; 38 82 public ISymbolicExpressionTree SymbolicExpressionTree { … … 63 107 : base(chart) { 64 108 primitiveMap = new Dictionary<IPrimitive, ISymbolicExpressionTreeNode>(); 65 109 PreferredNodeWidth = 80; 110 PreferredNodeHeight = 40; 66 111 Group = new Group(chart); 67 112 } 68 113 public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree) 69 114 : this(chart) { 70 PreferredNodeWidth = 80;71 PreferredNodeHeight = 40;72 115 SymbolicExpressionTree = tree; 73 116 } … … 95 138 primitiveMap.Add(rectangularPrimitive, node); // to be able to retrieve nodes via primitives 96 139 this.Add(rectangularPrimitive); 140 141 // int x = Position.X, y = Position.Y; 142 // if (x > rectangularPrimitive.LowerLeft.X) { 143 // x = (int)Math.Floor(rectangularPrimitive.LowerLeft.X); 144 // } 145 // if (y > rectangularPrimitive.LowerLeft.Y) { 146 // y = (int)Math.Floor(rectangularPrimitive.LowerLeft.Y); 147 // } 148 // Position = new Point(x, y); 149 // int w = Size.Width, h = Size.Height; 150 151 152 if (rectangularPrimitive.Size.Width.IsAlmost(0) || rectangularPrimitive.Size.Height.IsAlmost(0)) { 153 throw new Exception("Primitive size cannot be zero."); 154 } 97 155 } 98 156
Note: See TracChangeset
for help on using the changeset viewer.