示例#1
0
        public static async Task <Image> ToImage(this DxfImage i, Func <string, Task <byte[]> > contentResolver)
        {
            var data = await contentResolver(i.ImageDefinition.FilePath);

            var width    = i.UVector.Length * i.ImageSize.X;
            var height   = i.VVector.Length * i.ImageSize.Y;
            var rotation = Math.Atan2(i.UVector.Y, i.UVector.X) * MathHelper.RadiansToDegrees;
            var image    = new Image(i.Location.ToPoint(), i.ImageDefinition.FilePath, data, width, height, rotation, i.GetEntityColor());

            return(image);
        }
示例#2
0
        public static DxfImage ToDxfImage(this Image image, Layer layer)
        {
            var(pixelWidth, pixelHeight) = ImageHelpers.GetImageDimensions(image.Path, image.ImageData);
            var dxfImage = new DxfImage(image.Path, image.Location.ToDxfPoint(), pixelWidth, pixelHeight, DxfVector.XAxis);

            dxfImage.Layer = layer.Name;
            var radians       = image.Rotation * MathHelper.DegreesToRadians;
            var uVector       = new DxfVector(Math.Cos(radians), Math.Sin(radians), 0.0);
            var vVector       = new DxfVector(-Math.Sin(radians), Math.Cos(radians), 0.0);
            var uVectorLength = dxfImage.ImageSize.X / image.Width;
            var vVectorLength = dxfImage.ImageSize.Y / image.Height;

            uVector         /= uVectorLength;
            vVector         /= vVectorLength;
            dxfImage.UVector = uVector;
            dxfImage.VVector = vVector;
            return(dxfImage);
        }
示例#3
0
 public void Visit(DxfImage image)
 {
     this.method_0((DxfEntity)image);
 }
示例#4
0
 public void Visit(DxfImage image)
 {
     this.bool_0 = true;
 }
 /// <summary>
 /// Visits the specified entity.
 /// See the <see cref="IEntityVisitor"/> for more details.
 /// </summary>
 public override void Visit(DxfImage image)
 {
     HandleEntity(image);
 }
示例#6
0
        private static List <DxfEntity> OffsetToNest(IList <DxfEntity> dxfEntities, DxfPoint pivot, DxfPoint offset, double rotationAngle)
        {
            List <DxfEntity> dxfreturn = new List <DxfEntity>();
            List <DxfPoint>  tmpPts;

            foreach (DxfEntity entity in dxfEntities)
            {
                switch (entity.EntityType)
                {
                case DxfEntityType.Arc:
                    DxfArc dxfArc = (DxfArc)entity;
                    dxfArc.Center      = RotateLocation(rotationAngle, dxfArc.Center);
                    dxfArc.Center     += offset;
                    dxfArc.StartAngle += rotationAngle;
                    dxfArc.EndAngle   += rotationAngle;
                    dxfreturn.Add(dxfArc);
                    break;

                case DxfEntityType.ArcAlignedText:
                    DxfArcAlignedText dxfArcAligned = (DxfArcAlignedText)entity;
                    dxfArcAligned.CenterPoint  = RotateLocation(rotationAngle, dxfArcAligned.CenterPoint);
                    dxfArcAligned.CenterPoint += offset;
                    dxfArcAligned.StartAngle  += rotationAngle;
                    dxfArcAligned.EndAngle    += rotationAngle;
                    dxfreturn.Add(dxfArcAligned);
                    break;

                case DxfEntityType.Attribute:
                    DxfAttribute dxfAttribute = (DxfAttribute)entity;
                    dxfAttribute.Location  = RotateLocation(rotationAngle, dxfAttribute.Location);
                    dxfAttribute.Location += offset;
                    dxfreturn.Add(dxfAttribute);
                    break;

                case DxfEntityType.AttributeDefinition:
                    DxfAttributeDefinition dxfAttributecommon = (DxfAttributeDefinition)entity;
                    dxfAttributecommon.Location  = RotateLocation(rotationAngle, dxfAttributecommon.Location);
                    dxfAttributecommon.Location += offset;
                    dxfreturn.Add(dxfAttributecommon);
                    break;

                case DxfEntityType.Circle:
                    DxfCircle dxfCircle = (DxfCircle)entity;
                    dxfCircle.Center  = RotateLocation(rotationAngle, dxfCircle.Center);
                    dxfCircle.Center += offset;
                    dxfreturn.Add(dxfCircle);
                    break;

                case DxfEntityType.Ellipse:
                    DxfEllipse dxfEllipse = (DxfEllipse)entity;
                    dxfEllipse.Center  = RotateLocation(rotationAngle, dxfEllipse.Center);
                    dxfEllipse.Center += offset;
                    dxfreturn.Add(dxfEllipse);
                    break;

                case DxfEntityType.Image:
                    DxfImage dxfImage = (DxfImage)entity;
                    dxfImage.Location  = RotateLocation(rotationAngle, dxfImage.Location);
                    dxfImage.Location += offset;

                    dxfreturn.Add(dxfImage);
                    break;

                case DxfEntityType.Leader:
                    DxfLeader dxfLeader = (DxfLeader)entity;
                    tmpPts = new List <DxfPoint>();

                    foreach (DxfPoint vrt in dxfLeader.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    dxfLeader.Vertices.Clear();
                    dxfLeader.Vertices.Concat(tmpPts);
                    dxfreturn.Add(dxfLeader);
                    break;

                case DxfEntityType.Line:
                    DxfLine dxfLine = (DxfLine)entity;
                    dxfLine.P1  = RotateLocation(rotationAngle, dxfLine.P1);
                    dxfLine.P2  = RotateLocation(rotationAngle, dxfLine.P2);
                    dxfLine.P1 += offset;
                    dxfLine.P2 += offset;
                    dxfreturn.Add(dxfLine);
                    break;

                case DxfEntityType.LwPolyline:
                    DxfPolyline dxfPoly = (DxfPolyline)entity;
                    foreach (DxfVertex vrt in dxfPoly.Vertices)
                    {
                        vrt.Location  = RotateLocation(rotationAngle, vrt.Location);
                        vrt.Location += offset;
                    }

                    dxfreturn.Add(dxfPoly);
                    break;

                case DxfEntityType.MLine:
                    DxfMLine mLine = (DxfMLine)entity;
                    tmpPts            = new List <DxfPoint>();
                    mLine.StartPoint += offset;

                    mLine.StartPoint = RotateLocation(rotationAngle, mLine.StartPoint);

                    foreach (DxfPoint vrt in mLine.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    mLine.Vertices.Clear();
                    mLine.Vertices.Concat(tmpPts);
                    dxfreturn.Add(mLine);
                    break;

                case DxfEntityType.Polyline:
                    DxfPolyline polyline = (DxfPolyline)entity;

                    List <DxfVertex> verts = new List <DxfVertex>();
                    foreach (DxfVertex vrt in polyline.Vertices)
                    {
                        var tmppnt = vrt;
                        tmppnt.Location  = RotateLocation(rotationAngle, tmppnt.Location);
                        tmppnt.Location += offset;
                        verts.Add(tmppnt);
                    }

                    DxfPolyline polyout = new DxfPolyline(verts);
                    polyout.Location = polyline.Location + offset;
                    polyout.IsClosed = polyline.IsClosed;
                    polyout.Layer    = polyline.Layer;
                    dxfreturn.Add(polyout);

                    break;

                case DxfEntityType.Body:
                case DxfEntityType.DgnUnderlay:
                case DxfEntityType.Dimension:
                case DxfEntityType.DwfUnderlay:
                case DxfEntityType.Face:
                case DxfEntityType.Helix:
                case DxfEntityType.Insert:
                case DxfEntityType.Light:
                case DxfEntityType.ModelerGeometry:
                case DxfEntityType.MText:
                case DxfEntityType.OleFrame:
                case DxfEntityType.Ole2Frame:
                case DxfEntityType.PdfUnderlay:
                case DxfEntityType.Point:
                case DxfEntityType.ProxyEntity:
                case DxfEntityType.Ray:
                case DxfEntityType.Region:
                case DxfEntityType.RText:
                case DxfEntityType.Section:
                case DxfEntityType.Seqend:
                case DxfEntityType.Shape:
                case DxfEntityType.Solid:
                case DxfEntityType.Spline:
                case DxfEntityType.Text:
                case DxfEntityType.Tolerance:
                case DxfEntityType.Trace:
                case DxfEntityType.Underlay:
                case DxfEntityType.Vertex:
                case DxfEntityType.WipeOut:
                case DxfEntityType.XLine:
                    throw new ArgumentException("unsupported entity type: " + entity.EntityType);
                }
            }

            return(dxfreturn);
        }