refactor(PepLib.Core): reorganize files into logical folder structure
Move 38 files from root directory into organized subfolders: - Enums/ (7 files): StatusType, ApplicationType, DrawingType, etc. - Geometry/ (5 files): Vector, Box, Size, Spacing, Node - Models/ (15 files): Nest, Plate, Part, Program, Report, etc. - Utilities/ (7 files): MathHelper, Tolerance, ZipHelper, etc. - Extensions/ (2 files): PartListExtensions, PlateListExtensions - Interfaces/ (1 file): IMovable Update namespaces to follow folder hierarchy (e.g., PepLib.Models). Add GlobalUsings.cs for internal backward compatibility. Update Codes/ and IO/ files with new using statements. Update PepApi.Core consumers to reference new namespaces. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
100
PepLib.Core/Utilities/IniConfig.cs
Normal file
100
PepLib.Core/Utilities/IniConfig.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using PepLib.Geometry;
|
||||
|
||||
namespace PepLib.Utilities
|
||||
{
|
||||
public class IniConfig
|
||||
{
|
||||
public List<Node> Nodes;
|
||||
|
||||
public IniConfig()
|
||||
{
|
||||
Nodes = new List<Node>();
|
||||
}
|
||||
|
||||
private static int LeadingWhitespaceCount(string s)
|
||||
{
|
||||
for (int i = 0; i < s.Length; ++i)
|
||||
if (s[i] != ' ') return i;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Node FindNode(string path)
|
||||
{
|
||||
return FindNode(path, Nodes);
|
||||
}
|
||||
|
||||
private Node FindNode(string path, List<Node> nodes)
|
||||
{
|
||||
var a = path.Split('/');
|
||||
|
||||
var b = nodes.FirstOrDefault(node =>
|
||||
{
|
||||
if (node is KeyNode)
|
||||
{
|
||||
var c = node as KeyNode;
|
||||
return c.Name.ToUpper() == a[0].ToUpper();
|
||||
}
|
||||
else
|
||||
{
|
||||
return node.Value == a[0].Trim();
|
||||
}
|
||||
});
|
||||
|
||||
string path2 = string.Empty;
|
||||
|
||||
for (int i = 1; i < a.Length; ++i)
|
||||
path2 += a[i] + '/';
|
||||
|
||||
if (b == null || a.Length == 1)
|
||||
return b;
|
||||
else
|
||||
return FindNode(path2.TrimEnd('/'), b.Children);
|
||||
}
|
||||
|
||||
public static IniConfig Load(string file)
|
||||
{
|
||||
var doc = new IniConfig();
|
||||
var reader = new StreamReader(file);
|
||||
|
||||
Node currentNode = null;
|
||||
string line;
|
||||
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
int spaces = LeadingWhitespaceCount(line) / 2;
|
||||
var node = new Node();
|
||||
node.Value = line.Trim();
|
||||
|
||||
var keyNode = KeyNode.Parse(node);
|
||||
|
||||
if (keyNode != null)
|
||||
node = keyNode;
|
||||
|
||||
int currentdepth = currentNode != null ? currentNode.Level : 0;
|
||||
|
||||
if (spaces == 0)
|
||||
doc.Nodes.Add(node);
|
||||
else if (spaces == currentdepth)
|
||||
currentNode.Parent.AddChild(node);
|
||||
else if (spaces > currentdepth)
|
||||
currentNode.AddChild(node);
|
||||
else if (spaces < currentdepth)
|
||||
{
|
||||
var n = currentNode.Parent;
|
||||
|
||||
while (spaces < n.Level)
|
||||
n = n.Parent;
|
||||
|
||||
n.Parent.AddChild(node);
|
||||
}
|
||||
|
||||
currentNode = node;
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user