83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using System;
|
||
using Autodesk.AutoCAD.Geometry;
|
||
using CadParamPluging.Cad;
|
||
using CadParamPluging.Common;
|
||
using CadParamPluging.Data;
|
||
using CadParamPluging.Domain.Models;
|
||
|
||
namespace CadParamPluging.Domain
|
||
{
|
||
public static class DomainFacade
|
||
{
|
||
private static readonly ITemplateRepository TemplateRepository = new DefaultTemplateRepository();
|
||
|
||
public static TemplateInfo SelectTemplate(TemplateParams templateParams)
|
||
{
|
||
var definition = TemplateRepository.FindTemplate(templateParams);
|
||
|
||
if (definition == null)
|
||
{
|
||
throw new BusinessException("未找到匹配的模板,或匹配结果不唯一。");
|
||
}
|
||
|
||
return new TemplateInfo
|
||
{
|
||
Name = definition.Description ?? definition.FilePath,
|
||
FilePath = definition.FilePath,
|
||
Description = definition.Description
|
||
};
|
||
}
|
||
|
||
public static void ValidateParameters(TemplateParams templateParams, DrawingParams drawingParams)
|
||
{
|
||
if (templateParams == null)
|
||
{
|
||
throw new BusinessException("模板参数不能为空。");
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(templateParams.ProjectType) ||
|
||
string.IsNullOrWhiteSpace(templateParams.DrawingType))
|
||
{
|
||
throw new BusinessException("请填写项目类型和图纸类型。");
|
||
}
|
||
|
||
if (drawingParams == null || !drawingParams.HasValidSize())
|
||
{
|
||
throw new BusinessException("请填写有效的出图尺寸(宽度和高度需大于 0)。");
|
||
}
|
||
}
|
||
|
||
public static void DrawByParams(TemplateInfo template, DrawingParams drawingParams, CadDrawingService cadService)
|
||
{
|
||
if (template == null)
|
||
{
|
||
throw new ArgumentNullException(nameof(template));
|
||
}
|
||
|
||
if (cadService == null)
|
||
{
|
||
throw new ArgumentNullException(nameof(cadService));
|
||
}
|
||
|
||
var width = drawingParams?.Width ?? 0;
|
||
var height = drawingParams?.Height ?? 0;
|
||
|
||
if (width <= 0 || height <= 0)
|
||
{
|
||
width = width <= 0 ? 5000 : width;
|
||
height = height <= 0 ? 3000 : height;
|
||
}
|
||
|
||
var p1 = new Point3d(0, 0, 0);
|
||
var p2 = new Point3d(width, 0, 0);
|
||
var p3 = new Point3d(width, height, 0);
|
||
var p4 = new Point3d(0, height, 0);
|
||
|
||
cadService.DrawLine(p1, p2);
|
||
cadService.DrawLine(p2, p3);
|
||
cadService.DrawLine(p3, p4);
|
||
cadService.DrawLine(p4, p1);
|
||
}
|
||
}
|
||
}
|