Changeset 8219 for branches/HeuristicLab.Visualization
- Timestamp:
- 07/04/12 21:14:26 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/Group.cs
r8215 r8219 24 24 using System.Collections.ObjectModel; 25 25 using System.Drawing; 26 using System.Linq; 26 27 using System.Windows.Forms; 27 28 28 29 namespace HeuristicLab.Visualization { 29 30 public class Group : PrimitiveBase, IGroup { 30 private IList<IPrimitive> myPrimitives;31 private LinkedList<IPrimitive> myPrimitives; 31 32 private HashSet<IPrimitive> myPrimitivesLookup; 32 33 public virtual ReadOnlyCollection<IPrimitive> Primitives { 33 get { return new ReadOnlyCollection<IPrimitive>( myPrimitives); }34 get { return new ReadOnlyCollection<IPrimitive>(new List<IPrimitive>(myPrimitives)); } 34 35 } 35 36 public virtual ReadOnlyCollection<IPrimitive> SelectedPrimitives { … … 56 57 public Group(IChart chart) 57 58 : base(chart) { 58 myPrimitives = new Li st<IPrimitive>();59 myPrimitives = new LinkedList<IPrimitive>(); 59 60 myPrimitivesLookup = new HashSet<IPrimitive>(); 60 61 } … … 64 65 throw new ArgumentException("Primitive already added"); 65 66 66 myPrimitives. Insert(0,primitive);67 myPrimitives.AddFirst(primitive); 67 68 myPrimitivesLookup.Add(primitive); 68 69 primitive.Group = this; … … 75 76 throw new ArgumentException("Primitive already added"); 76 77 77 myPrimitives. Insert(0,primitive);78 myPrimitives.AddFirst(primitive); 78 79 myPrimitivesLookup.Add(primitive); 79 80 primitive.Group = this; … … 106 107 107 108 public virtual IPrimitive GetPrimitive(PointD point) { 108 int i = 0; 109 while ((i < myPrimitives.Count) && (!myPrimitives[i].ContainsPoint(point))) 110 i++; 111 if (i == myPrimitives.Count) return null; 112 else return myPrimitives[i]; 113 } 109 return myPrimitives.FirstOrDefault(primitive => primitive.ContainsPoint(point)); 110 } 111 114 112 public IPrimitive GetPrimitive(double x, double y) { 115 113 return GetPrimitive(new PointD(x, y)); 116 114 } 117 115 public virtual IList<IPrimitive> GetAllPrimitives(PointD point) { 118 List<IPrimitive> primitives = new List<IPrimitive>(); 119 for (int i = 0; i < myPrimitives.Count; i++) { 120 if (myPrimitives[i].ContainsPoint(point)) { 121 primitives.Add(myPrimitives[i]); 122 if (myPrimitives[i] is IGroup) { 123 primitives.AddRange(((IGroup)myPrimitives[i]).Primitives); 124 } 125 } 116 var primitives = new List<IPrimitive>(); 117 foreach (var primitive in myPrimitives.Where(primitive => primitive.ContainsPoint(point))) { 118 primitives.Add(primitive); 119 var @group = primitive as IGroup; 120 if (@group != null) 121 primitives.AddRange((@group).Primitives); 126 122 } 127 123 return primitives; … … 159 155 throw new ArgumentException("Primitive not found"); 160 156 161 int index = myPrimitives.IndexOf(primitive); 162 if (index > 0) { 163 myPrimitives.Remove(primitive); 164 myPrimitives.Insert(index - 1, primitive); 165 OnUpdate(); 166 } 167 } 157 var curr = myPrimitives.Find(primitive); 158 if (curr == null) return; 159 var prev = curr.Previous; 160 var temp = curr.Value; 161 curr.Value = prev.Value; 162 prev.Value = temp; 163 164 OnUpdate(); 165 } 166 168 167 public void OneLayerDown(IPrimitive primitive) { 169 168 if (!Contains(primitive)) 170 169 throw new ArgumentException("Primitive not found"); 171 170 172 int index = myPrimitives.IndexOf(primitive);173 if ( index < myPrimitives.Count - 1) {174 myPrimitives.Remove(primitive);175 myPrimitives.Insert(index + 1, primitive);176 OnUpdate();177 }171 var curr = myPrimitives.Find(primitive); 172 if (curr == null) return; 173 var next = curr.Next; 174 var temp = curr.Value; 175 curr.Value = next.Value; 176 next.Value = temp; 178 177 } 179 178 public void IntoForeground(IPrimitive primitive) { … … 182 181 183 182 myPrimitives.Remove(primitive); 184 myPrimitives. Insert(0,primitive);183 myPrimitives.AddFirst(primitive); 185 184 OnUpdate(); 186 185 } … … 190 189 191 190 myPrimitives.Remove(primitive); 192 myPrimitives.Add (primitive);191 myPrimitives.AddLast(primitive); 193 192 OnUpdate(); 194 193 } 195 194 196 195 public override void Draw(Graphics graphics) { 197 for (int i = myPrimitives.Count - 1; i >= 0; i--) {198 myPrimitives[i].PreDraw(graphics);199 myPrimitives[i].Draw(graphics);200 myPrimitives[i].PostDraw(graphics);196 foreach (var primitive in myPrimitives) { 197 primitive.PreDraw(graphics); 198 primitive.Draw(graphics); 199 primitive.PostDraw(graphics); 201 200 } 202 201 }
Note: See TracChangeset
for help on using the changeset viewer.