Restructure project layout to flatten directory structure
Move all projects from Source/ to repository root for simpler navigation. - Remove External/ dependency DLLs (will use NuGet packages) - Remove Installer/ NSIS script - Replace PartCollection/PlateCollection with ObservableList - Add packages.config for NuGet dependencies 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
117
OpenNest.Core/Drawing.cs
Normal file
117
OpenNest.Core/Drawing.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenNest.CNC;
|
||||
|
||||
namespace OpenNest
|
||||
{
|
||||
public class Drawing
|
||||
{
|
||||
private Program program;
|
||||
|
||||
public Drawing()
|
||||
: this(string.Empty, new Program())
|
||||
{
|
||||
}
|
||||
|
||||
public Drawing(string name)
|
||||
: this(name, new Program())
|
||||
{
|
||||
}
|
||||
|
||||
public Drawing(string name, Program pgm)
|
||||
{
|
||||
Name = name;
|
||||
Material = new Material();
|
||||
Program = pgm;
|
||||
Constraints = new NestConstraints();
|
||||
Source = new SourceInfo();
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Customer { get; set; }
|
||||
|
||||
public int Priority { get; set; }
|
||||
|
||||
public Quantity Quantity;
|
||||
|
||||
public Material Material { get; set; }
|
||||
|
||||
public Program Program
|
||||
{
|
||||
get { return program; }
|
||||
set
|
||||
{
|
||||
program = value;
|
||||
UpdateArea();
|
||||
}
|
||||
}
|
||||
|
||||
public Color Color { get; set; }
|
||||
|
||||
public NestConstraints Constraints { get; set; }
|
||||
|
||||
public SourceInfo Source { get; set; }
|
||||
|
||||
public double Area { get; protected set; }
|
||||
|
||||
public void UpdateArea()
|
||||
{
|
||||
var geometry = ConvertProgram.ToGeometry(Program).Where(entity => entity.Layer != SpecialLayers.Rapid);
|
||||
var shapes = Helper.GetShapes(geometry);
|
||||
|
||||
if (shapes.Count == 0)
|
||||
return;
|
||||
|
||||
var areas = new double[shapes.Count];
|
||||
|
||||
for (int i = 0; i < shapes.Count; i++)
|
||||
{
|
||||
var shape = shapes[i];
|
||||
areas[i] = shape.Area();
|
||||
}
|
||||
|
||||
int largestAreaIndex = 0;
|
||||
|
||||
for (int i = 1; i < areas.Length; i++)
|
||||
{
|
||||
var area = areas[i];
|
||||
|
||||
if (area > areas[largestAreaIndex])
|
||||
largestAreaIndex = i;
|
||||
}
|
||||
|
||||
var outerArea = areas[largestAreaIndex];
|
||||
|
||||
Area = outerArea - (areas.Sum() - outerArea);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Drawing == false)
|
||||
return false;
|
||||
|
||||
var dwg = (Drawing)obj;
|
||||
|
||||
return Name == dwg.Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public class SourceInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Path to the source file.
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Offset distances to the original location.
|
||||
/// </summary>
|
||||
public Vector Offset { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user