164 lines
4.8 KiB
C#
164 lines
4.8 KiB
C#
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using ACadSharp.Entities;
|
||
using CommunityToolkit.Diagnostics;
|
||
using CommunityToolkit.Mvvm.ComponentModel;
|
||
using CommunityToolkit.Mvvm.Messaging;
|
||
using CommunityToolkit.Mvvm.Messaging.Messages;
|
||
using CSMath;
|
||
|
||
|
||
//using OpenAI.Chat;
|
||
|
||
namespace WpfApp;
|
||
|
||
internal class Test
|
||
{
|
||
static void Run()
|
||
{
|
||
//TEST();
|
||
var re = new Receive();
|
||
var p = new Person();
|
||
var value = new ValueChangedMessage<Person>(p);
|
||
var propChange = new PropertyChangedMessage<string>(new Test(), nameof(Person.Name), "bob", "jenny");
|
||
|
||
WeakReferenceMessenger.Default.Send(propChange);
|
||
WeakReferenceMessenger.Default.Send(value);
|
||
WeakReferenceMessenger.Default.Send(p);
|
||
//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 = string.Empty;
|
||
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"));
|
||
//}
|
||
}
|
||
}
|
||
public class Person
|
||
{
|
||
public int Id { get; set; }
|
||
public string Name { get; set; }
|
||
}
|
||
public partial class Receive : ObservableRecipient, IRecipient<ValueChangedMessage<Person>>, IRecipient<Person>, IRecipient<PropertyChangedMessage<string>>
|
||
{
|
||
public Receive()
|
||
{
|
||
IsActive = true;
|
||
//WeakReferenceMessenger.Default
|
||
// .Register<Person>(
|
||
// this,
|
||
// (r, m) =>
|
||
// {
|
||
|
||
// });
|
||
}
|
||
|
||
void IRecipient<ValueChangedMessage<Person>>.Receive(ValueChangedMessage<Person> message)
|
||
{
|
||
}
|
||
|
||
void IRecipient<Person>.Receive(Person message)
|
||
{
|
||
}
|
||
|
||
void IRecipient<PropertyChangedMessage<string>>.Receive(PropertyChangedMessage<string> message)
|
||
{
|
||
|
||
}
|
||
} |