Files
ShrlAlgoToolkit/ConsoleApp/Program.cs

129 lines
4.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ACadSharp.Entities;
using CommunityToolkit.Diagnostics;
using CSMath;
using OpenAI.Chat;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
//TEST();
ChatClient client = new ChatClient("gpt-4o", Environment.GetEnvironmentVariable("OPEN_API_KEY"));
ChatCompletion completion = client.CompleteChat("say 'this is a test.'");
Console.WriteLine($"[ASSISTANT]:{completion.Content[0].Text}");
}
private static void TEST()
{
var str = "";
var a = 10.0;
double b = 100;
Debug.Assert(a == b);
//确保str满足条件才能继续执行不满足即抛出异常
Guard.IsNotNullOrEmpty(str);//抛出异常
Guard.IsLessThan(a, b);
}
public void ReadCAD()
{
var file = @"D:\Users\Zhanggg\Desktop\Drawing1.dwg";
var cad = new ACadSharp.IO.DwgReader(file).Read();
var polylines = cad.Entities.OfType<LwPolyline>().Where(l => l.Layer.Name == "RQ");
var sizes = cad.Entities.OfType<TextEntity>().Where(t => t.Layer.Name == "RQ");
var entities = cad.Entities.OfType<Insert>().Where(i => i.Layer.Name == "0" || i.Layer.Name == "RQ" || i.Layer.Name == "GAS" || i.Layer.Name == "燃具");
var sb = new StringBuilder();
sb.AppendLine("多段线");
foreach (var line in polylines)
{
var first = line.Vertices.First();
var last = line.Vertices.Last();
sb.AppendLine($"起点:{first.Location};终点:{last.Location}");
}
foreach (var insert in entities)
{
if (insert.Block.Name == "立管0")
{
var temp = double.MaxValue;
string t = default;
foreach (var item in sizes)
{
var current = item.InsertPoint.DistanceFrom(insert.InsertPoint);
if (current < temp)
{
temp = current;
t = item.Value;
}
}
}
//盲板
else if (insert.Block.Name == "盲板")
{
}
//旋塞阀
else if (insert.Block.Name.Contains("旋塞"))
{
}
//商业预留,法兰球阀
else if (insert.Block.Name.Contains("法兰球阀"))
{
}
//锁闭型螺纹铜球阀
else if (insert.Block.Name.Contains("户内阀"))
{
}
//燃气表
else if (insert.Block.Name == "计量表")
{
}
//自闭阀
else if (insert.Block.Name == "自闭阀")
{
}
//热水器
else if (insert.Block.Name == "RSQ")
{
}
//燃气灶
else if (insert.Block.Name == "燃气灶")
{
}
//球阀+丝堵
else if (insert.Block.Name.Contains("丝堵"))
{
}
sb.AppendLine($"图层名:{insert.Layer.Name};图块名:{insert.Block.Name};插入点:{insert.InsertPoint}");
}
File.WriteAllText(@"D:\Users\Zhanggg\Desktop\Drawing1.dwg" + ".txt", sb.ToString(), Encoding.UTF8);
//foreach (var insert in entities)
//{
// var blocks = insert.Block.Entities.OfType<Dimension>().Where(d=>d.Text.Contains("52D"));
//}
}
}
}