First commit.

This commit is contained in:
aj
2016-05-16 22:09:19 -04:00
commit f2595d7cba
189 changed files with 26944 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
using System.Collections.Generic;
namespace OpenNest.Collections
{
public class DrawingCollection : HashSet<Drawing>
{
}
}

View File

@@ -0,0 +1,177 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace OpenNest.Collections
{
public class PartCollection : IList<Part>, ICollection<Part>, IEnumerable<Part>
{
private readonly List<Part> parts;
public event EventHandler<PartAddedEventArgs> PartAdded;
public event EventHandler<PartRemovedEventArgs> PartRemoved;
public event EventHandler<PartChangedEventArgs> PartChanged;
public PartCollection()
{
parts = new List<Part>();
}
public void Add(Part item)
{
var index = parts.Count;
parts.Add(item);
if (PartAdded != null)
PartAdded.Invoke(this, new PartAddedEventArgs(item, index));
}
public void AddRange(IEnumerable<Part> collection)
{
var index = parts.Count;
parts.AddRange(collection);
if (PartAdded != null)
{
foreach (var part in collection)
PartAdded.Invoke(this, new PartAddedEventArgs(part, index++));
}
}
public void Insert(int index, Part item)
{
parts.Insert(index, item);
if (PartAdded != null)
PartAdded.Invoke(this, new PartAddedEventArgs(item, index));
}
public bool Remove(Part item)
{
var success = parts.Remove(item);
if (PartRemoved != null)
PartRemoved.Invoke(this, new PartRemovedEventArgs(item, success));
return success;
}
public void RemoveAt(int index)
{
if (PartRemoved != null)
{
var part = parts[index];
parts.RemoveAt(index);
PartRemoved.Invoke(this, new PartRemovedEventArgs(part, true));
}
else
{
parts.RemoveAt(index);
}
}
public void Clear()
{
for (int i = parts.Count - 1; i >= 0; --i)
RemoveAt(i);
}
public int IndexOf(Part item)
{
return parts.IndexOf(item);
}
public Part this[int index]
{
get
{
return parts[index];
}
set
{
var old = parts[index];
parts[index] = value;
if (PartChanged != null)
{
var eventArgs = new PartChangedEventArgs(old, value, index);
PartChanged.Invoke(this, eventArgs);
}
}
}
public bool Contains(Part item)
{
return parts.Contains(item);
}
public void CopyTo(Part[] array, int arrayIndex)
{
parts.CopyTo(array, arrayIndex);
}
public int Count
{
get { return parts.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public object ForEach { get; set; }
public IEnumerator<Part> GetEnumerator()
{
return parts.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return parts.GetEnumerator();
}
}
public class PartAddedEventArgs : EventArgs
{
public readonly Part Part;
public readonly int Index;
public PartAddedEventArgs(Part part, int index)
{
Part = part;
Index = index;
}
}
public class PartRemovedEventArgs : EventArgs
{
public readonly Part Part;
public readonly bool Succeeded;
public PartRemovedEventArgs(Part part, bool succeeded)
{
Part = part;
Succeeded = succeeded;
}
}
public class PartChangedEventArgs : EventArgs
{
public readonly Part OldPart;
public readonly Part NewPart;
public readonly int Index;
public PartChangedEventArgs(Part oldPart, Part newPart, int index)
{
OldPart = oldPart;
NewPart = newPart;
Index = index;
}
}
}

View File

@@ -0,0 +1,187 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest.Collections
{
public class PlateCollection : IList<Plate>, ICollection<Plate>, IEnumerable<Plate>
{
private List<Plate> plates;
public event EventHandler<PlateAddedEventArgs> PlateAdded;
public event EventHandler<PlateRemovedEventArgs> PlateRemoved;
public event EventHandler<PlateChangedEventArgs> PlateChanged;
public PlateCollection()
{
plates = new List<Plate>();
}
public void Add(Plate item)
{
var index = plates.Count;
plates.Add(item);
if (PlateAdded != null)
PlateAdded.Invoke(this, new PlateAddedEventArgs(item, index));
}
public void AddRange(IEnumerable<Plate> collection)
{
var index = plates.Count;
plates.AddRange(collection);
if (PlateAdded != null)
{
foreach (var plate in collection)
PlateAdded.Invoke(this, new PlateAddedEventArgs(plate, index++));
}
}
public void Insert(int index, Plate item)
{
plates.Insert(index, item);
if (PlateAdded != null)
PlateAdded.Invoke(this, new PlateAddedEventArgs(item, index));
}
public bool Remove(Plate item)
{
var success = plates.Remove(item);
if (PlateRemoved != null)
PlateRemoved.Invoke(this, new PlateRemovedEventArgs(item, success));
return success;
}
public void RemoveAt(int index)
{
var plate = plates[index];
plates.RemoveAt(index);
if (PlateRemoved != null)
PlateRemoved.Invoke(this, new PlateRemovedEventArgs(plate, true));
}
public void Clear()
{
for (int i = plates.Count - 1; i >= 0; --i)
RemoveAt(i);
}
public int IndexOf(Plate item)
{
return plates.IndexOf(item);
}
public Plate this[int index]
{
get
{
return plates[index];
}
set
{
var old = plates[index];
plates[index] = value;
if (PlateChanged != null)
{
var eventArgs = new PlateChangedEventArgs(old, value, index);
PlateChanged.Invoke(this, eventArgs);
}
}
}
public bool Contains(Plate item)
{
return plates.Contains(item);
}
public void CopyTo(Plate[] array, int arrayIndex)
{
plates.CopyTo(array, arrayIndex);
}
public int Count
{
get { return plates.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public IEnumerator<Plate> GetEnumerator()
{
return plates.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return plates.GetEnumerator();
}
public void RemoveEmptyPlates()
{
if (Count < 2)
return;
for (int i = Count - 1; i >= 0; --i)
{
if (this[i].Parts.Count == 0)
RemoveAt(i);
}
}
public int TotalCount
{
get { return plates.Sum(plate => plate.Quantity); }
}
}
public class PlateAddedEventArgs : EventArgs
{
public readonly Plate Plate;
public readonly int Index;
public PlateAddedEventArgs(Plate plate, int index)
{
Plate = plate;
Index = index;
}
}
public class PlateChangedEventArgs : EventArgs
{
public readonly Plate OldPlate;
public readonly Plate NewPlate;
public readonly int Index;
public PlateChangedEventArgs(Plate oldPlate, Plate newPlate, int index)
{
OldPlate = oldPlate;
NewPlate = newPlate;
Index = index;
}
}
public class PlateRemovedEventArgs : EventArgs
{
public readonly Plate Plate;
public readonly bool Succeeded;
public PlateRemovedEventArgs(Plate plate, bool succeeded)
{
Plate = plate;
Succeeded = succeeded;
}
}
}