123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- using InABox.Core;
- using netDxf.Entities;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace InABox.Dxf;
- internal interface IDxfObject
- {
- void Draw(DrawData data);
- }
- internal class DxfLine : IDxfObject
- {
- public Line Line { get; set; }
- public void Draw(DrawData data)
- {
- if (!Line.IsVisible || !data.HasLayer(Line.Layer)) return;
- data.Graphics.DrawLine(new Pen(Color.Black, (float)Line.Thickness), DrawData.ConvertPoint(Line.StartPoint), DrawData.ConvertPoint(Line.EndPoint));
- }
- }
- internal class DxfInsert : IDxfObject
- {
- public Insert Insert { get; set; }
- public List<IDxfObject> Objects { get; set; }
- public DxfInsert(Insert insert)
- {
- Insert = insert;
- Objects = insert.Block.Entities.Select(DxfUtils.ConvertEl).NotNull().ToList();
- }
- public void Draw(DrawData data)
- {
- if (!Insert.IsVisible) return;
- data.PushTransform();
- data.Translate(new PointF((float)Insert.Position.X, (float)Insert.Position.Y));
- data.Rotate((float)Insert.Rotation);
- data.Scale((float)Insert.Scale.X, (float)Insert.Scale.Y);
- foreach(var obj in Objects)
- {
- obj.Draw(data);
- }
- data.PopTransform();
- }
- }
- internal class DxfEllipse : IDxfObject
- {
- public Ellipse Ellipse { get; set; }
- public DxfEllipse(Ellipse ellipse)
- {
- Ellipse = ellipse;
- }
- public void Draw(DrawData data)
- {
- if (!Ellipse.IsVisible || !data.HasLayer(Ellipse.Layer)) return;
- var center = DrawData.ConvertPoint(Ellipse.Center);
- var size = new SizeF((float)Ellipse.MajorAxis, (float)Ellipse.MinorAxis);
- data.Graphics.DrawEllipse(new Pen(Color.Black, (float)Ellipse.Thickness), center.X - size.Width / 2, center.Y - size.Height / 2, size.Width, size.Height);
- }
- }
- internal class DxfPolyline2D : IDxfObject
- {
- public Polyline2D Polyline { get; set; }
- public DxfPolyline2D(Polyline2D polyline)
- {
- Polyline = polyline;
- }
- public void Draw(DrawData data)
- {
- if (!Polyline.IsVisible || !data.HasLayer(Polyline.Layer)) return;
- if(Polyline.SmoothType == PolylineSmoothType.NoSmooth)
- {
- if (Polyline.Layer.Name != "Swipe Lines") return;
- var vertices = Polyline.Vertexes.ToArray(x => new PointF((float)x.Position.X, (float)x.Position.Y));
- if (Polyline.IsClosed)
- {
- data.Graphics.DrawPolygon(
- new Pen(Color.Black, (float)Polyline.Thickness),
- vertices);
- }
- else
- {
- data.Graphics.DrawLines(
- new Pen(Color.Black, (float)Polyline.Thickness),
- vertices);
- }
- }
- else
- {
- }
- }
- }
- internal class DxfMText : IDxfObject
- {
- public MText MText { get; set; }
- public DxfMText(MText text)
- {
- MText = text;
- }
- public void Draw(DrawData data)
- {
- if (!MText.IsVisible || !data.HasLayer(MText.Layer)) return;
- var fontFamily = new FontFamily(MText.Style.FontFamilyName);
- var font = new Font(fontFamily, (float)MText.Height, MText.Style.FontStyle switch
- {
- netDxf.Tables.FontStyle.Bold => FontStyle.Bold,
- netDxf.Tables.FontStyle.Italic => FontStyle.Italic,
- netDxf.Tables.FontStyle.Regular or _ => FontStyle.Regular,
- });
- data.PushTransform();
- data.Translate(new PointF((float)MText.Position.X, (float)MText.Position.Y));
- data.Rotate((float)MText.Rotation);
- data.Scale(1, -1);
- var size = data.Graphics.MeasureString(MText.PlainText(), font);
- switch (MText.AttachmentPoint)
- {
- case MTextAttachmentPoint.MiddleLeft:
- case MTextAttachmentPoint.MiddleCenter:
- case MTextAttachmentPoint.MiddleRight:
- data.Translate(new PointF(0, -size.Height / 2));
- break;
- case MTextAttachmentPoint.BottomLeft:
- case MTextAttachmentPoint.BottomCenter:
- case MTextAttachmentPoint.BottomRight:
- data.Translate(new PointF(0, -size.Height));
- break;
- }
- switch (MText.AttachmentPoint)
- {
- case MTextAttachmentPoint.TopLeft:
- case MTextAttachmentPoint.MiddleLeft:
- case MTextAttachmentPoint.BottomLeft:
- break;
- case MTextAttachmentPoint.TopCenter:
- case MTextAttachmentPoint.MiddleCenter:
- case MTextAttachmentPoint.BottomCenter:
- data.Translate(new PointF(-(float)size.Width / 2, 0));
- break;
- case MTextAttachmentPoint.TopRight:
- case MTextAttachmentPoint.MiddleRight:
- case MTextAttachmentPoint.BottomRight:
- data.Translate(new PointF(-(float)size.Width, 0));
- break;
- }
- data.Graphics.DrawString(MText.PlainText(), font, new SolidBrush(Color.Black), new PointF(0, 0));
- data.PopTransform();
- }
- }
- internal class DxfDimension : IDxfObject
- {
- public Dimension Dimension { get; set; }
- public DxfDimension(Dimension dimension)
- {
- Dimension = dimension;
- }
- public void Draw(DrawData data)
- {
- if (!Dimension.IsVisible || !data.HasLayer(Dimension.Layer)) return;
- if(Dimension is AlignedDimension aligned)
- {
- data.Graphics.DrawLine(new Pen(Color.Black, (float)10), DrawData.ConvertPoint(aligned.FirstReferencePoint), DrawData.ConvertPoint(aligned.SecondReferencePoint));
- }
- }
- }
|