示例#1
0
        /// <summary>
        /// Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector.
        /// </summary>
        /// <param name="transformation">Transformation matrix.</param>
        /// <param name="translation">Translation vector.</param>
        /// <remarks>Matrix3 adopts the convention of using column vectors to represent a transformation matrix.</remarks>
        public override void TransformBy(Matrix3 transformation, Vector3 translation)
        {
            double newElevation = this.Elevation;

            Vector3 newNormal = transformation * this.Normal;

            if (Vector3.Equals(Vector3.Zero, newNormal))
            {
                newNormal = this.Normal;
            }

            Matrix3 transOW = MathHelper.ArbitraryAxis(this.Normal);
            Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal).Transpose();

            List <Vector2> vertexes = new List <Vector2>();

            foreach (Vector2 vertex in this.ClippingBoundary.Vertexes)
            {
                Vector3 v = transOW * new Vector3(vertex.X, vertex.Y, this.Elevation);
                v = transformation * v + translation;
                v = transWO * v;
                vertexes.Add(new Vector2(v.X, v.Y));
                newElevation = v.Z;
            }

            ClippingBoundary newClipping = this.ClippingBoundary.Type == ClippingBoundaryType.Rectangular
                ? new ClippingBoundary(vertexes[0], vertexes[1])
                : new ClippingBoundary(vertexes);

            this.Normal           = newNormal;
            this.Elevation        = newElevation;
            this.ClippingBoundary = newClipping;
        }
示例#2
0
        /// <summary>
        /// Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector.
        /// </summary>
        /// <param name="transformation">Transformation matrix.</param>
        /// <param name="translation">Translation vector.</param>
        public override void TransformBy(Matrix3 transformation, Vector3 translation)
        {
            Vector3 newNormal;
            double  newElevation = Elevation;

            newNormal = transformation * Normal;

            Matrix3 transOW = MathHelper.ArbitraryAxis(Normal);
            Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal).Transpose();

            List <Vector2> vertexes = new List <Vector2>();

            foreach (Vector2 vertex in ClippingBoundary.Vertexes)
            {
                Vector3 v = transOW * new Vector3(vertex.X, vertex.Y, Elevation);
                v = transformation * v + translation;
                v = transWO * v;
                vertexes.Add(new Vector2(v.X, v.Y));
                newElevation = v.Z;
            }

            ClippingBoundary newClipping = ClippingBoundary.Type == ClippingBoundaryType.Rectangular
                ? new ClippingBoundary(vertexes[0], vertexes[1])
                : new ClippingBoundary(vertexes);

            Normal           = newNormal;
            Elevation        = newElevation;
            ClippingBoundary = newClipping;
        }
示例#3
0
        public Underlay(UnderlayDefinition definition)
            : base(EntityType.Underlay, DxfObjectCode.Underlay)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }
            this.definition       = definition;
            this.position         = Vector3.Zero;
            this.scale            = new Vector3(1.0);
            this.rotation         = 0.0;
            this.contrast         = 100;
            this.fade             = 0;
            this.displayOptions   = UnderlayDisplayFlags.ShowUnderlay;
            this.clippingBoundary = null;
            switch (this.definition.Type)
            {
            case UnderlayType.DGN:
                this.CodeName = DxfObjectCode.UnderlayDgn;
                break;

            case UnderlayType.DWF:
                this.CodeName = DxfObjectCode.UnderlayDwf;
                break;

            case UnderlayType.PDF:
                this.CodeName = DxfObjectCode.UnderlayPdf;
                break;
            }
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <c>Image</c> class.
        /// </summary>
        /// <param name="imageDefinition">Image definition.</param>
        /// <param name="position">Image <see cref="Vector3">position</see> in world coordinates.</param>
        /// <param name="width">Image width in world coordinates.</param>
        /// <param name="height">Image height in world coordinates.</param>
        public Image(ImageDefinition imageDefinition, Vector3 position, double width, double height)
            : base(EntityType.Image, DxfObjectCode.Image)
        {
            if (imageDefinition == null)
            {
                throw new ArgumentNullException("imageDefinition");
            }

            this.imageDefinition = imageDefinition;
            this.position        = position;
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width", width, "The Image width must be greater than zero.");
            }
            this.width = width;
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height", height, "The Image height must be greater than zero.");
            }
            this.height           = height;
            this.rotation         = 0;
            this.clipping         = false;
            this.brightness       = 50;
            this.contrast         = 50;
            this.fade             = 0;
            this.displayOptions   = ImageDisplayFlags.ShowImage | ImageDisplayFlags.ShowImageWhenNotAlignedWithScreen | ImageDisplayFlags.UseClippingBoundary;
            this.clippingBoundary = new ClippingBoundary(0, 0, imageDefinition.Width, imageDefinition.Height);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <c>Underlay</c> class.
        /// </summary>
        /// <param name="definition"><see cref="UnderlayDefinition">Underlay definition</see>.</param>
        /// <param name="position">Underlay <see cref="Vector3">position</see> in world coordinates.</param>
        /// <param name="scale">Underlay scale.</param>
        public Underlay(UnderlayDefinition definition, Vector3 position, double scale)
            : base(EntityType.Underlay, DxfObjectCode.Underlay)
        {
            if (definition == null)
            {
                throw new ArgumentNullException(nameof(definition));
            }
            this.definition = definition;
            this.position   = position;
            if (scale <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(scale), scale, "The Underlay scale must be greater than zero.");
            }
            this.scale            = new Vector2(scale);
            this.rotation         = 0.0;
            this.contrast         = 100;
            this.fade             = 0;
            this.displayOptions   = UnderlayDisplayFlags.ShowUnderlay;
            this.clippingBoundary = null;
            switch (this.definition.Type)
            {
            case UnderlayType.DGN:
                this.CodeName = DxfObjectCode.UnderlayDgn;
                break;

            case UnderlayType.DWF:
                this.CodeName = DxfObjectCode.UnderlayDwf;
                break;

            case UnderlayType.PDF:
                this.CodeName = DxfObjectCode.UnderlayPdf;
                break;
            }
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <c>Wipeout</c> class.
 /// </summary>
 /// <param name="clippingBoundary">The wipeout clipping boundary.</param>
 public Wipeout(ClippingBoundary clippingBoundary)
     : base(EntityType.Wipeout, DxfObjectCode.Wipeout)
 {
     if (clippingBoundary == null)
     {
         throw new ArgumentNullException(nameof(clippingBoundary));
     }
     this.clippingBoundary = clippingBoundary;
     this.elevation        = 0.0;
 }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <c>Image</c> class.
 /// </summary>
 /// <param name="imageDefinition">Image definition.</param>
 /// <param name="position">Image <see cref="Vector3">position</see> in world coordinates.</param>
 /// <param name="width">Image width in world coordinates.</param>
 /// <param name="height">Image height in world coordinates.</param>
 public Image(ImageDefinition imageDefinition, Vector3 position, double width, double height)
     : base(EntityType.Image, DxfObjectCode.Image)
 {
     this.imageDefinition  = imageDefinition;
     this.position         = position;
     this.width            = width;
     this.height           = height;
     this.rotation         = 0;
     this.clipping         = false;
     this.brightness       = 50;
     this.contrast         = 50;
     this.fade             = 0;
     this.displayOptions   = ImageDisplayFlags.ShowImage | ImageDisplayFlags.ShowImageWhenNotAlignedWithScreen | ImageDisplayFlags.UseClippingBoundary;
     this.clippingBoundary = new ClippingBoundary(-0.5, -0.5, imageDefinition.Width, imageDefinition.Height);
 }
示例#8
0
文件: Underlay.cs 项目: Core2D/netdxf
 /// <summary>
 /// Initializes a new instance of the <c>Underlay</c> class.
 /// </summary>
 /// <param name="definition">Underlay definition.</param>
 public Underlay(UnderlayDefinition definition)
     : base(EntityType.Underlay, DxfObjectCode.Underlay)
 {
     this.definition = definition;
     this.position = Vector3.Zero;
     this.scale = new Vector3(1.0);
     this.rotation = 0.0;
     this.contrast = 100;
     this.fade = 0;
     this.displayOptions = UnderlayDisplayFlags.ShowUnderlay;
     this.clippingBoundary = null;
     switch (this.definition.Type)
     {
         case UnderlayType.DGN:
             this.CodeName = DxfObjectCode.UnderlayDgn;
             break;
         case UnderlayType.DWF:
             this.CodeName = DxfObjectCode.UnderlayDwf;
             break;
         case UnderlayType.PDF:
             this.CodeName = DxfObjectCode.UnderlayPdf;
             break;
     }
 }
示例#9
0
        /// <summary>
        /// Creates a new Wipeout that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Wipeout that is a copy of this instance.</returns>
        public override object Clone()
        {
            Wipeout entity = new Wipeout((ClippingBoundary)ClippingBoundary.Clone())
            {
                //EntityObject properties
                Layer         = (Layer)Layer.Clone(),
                Linetype      = (Linetype)Linetype.Clone(),
                Color         = (AciColor)Color.Clone(),
                Lineweight    = Lineweight,
                Transparency  = (Transparency)Transparency.Clone(),
                LinetypeScale = LinetypeScale,
                Normal        = Normal,
                IsVisible     = IsVisible,
                //Wipeout properties
                Elevation = elevation
            };

            foreach (XData data in XData.Values)
            {
                entity.XData.Add((XData)data.Clone());
            }

            return(entity);
        }
示例#10
0
 /// <summary>
 /// Initializes a new instance of the <c>Wipeout</c> class.
 /// </summary>
 /// <param name="clippingBoundary">The wipeout clipping boundary.</param>
 public Wipeout(ClippingBoundary clippingBoundary)
     : base(EntityType.Wipeout, DxfObjectCode.Wipeout)
 {
     this.clippingBoundary = clippingBoundary;
     this.elevation        = 0.0;
 }
示例#11
0
        private Underlay ReadUnderlay()
        {
            string underlayDefHandle = null;
            Vector3 position = Vector3.Zero;
            Vector3 scale = new Vector3(1.0);
            double rotation = 0.0;
            Vector3 normal = Vector3.UnitZ;
            UnderlayDisplayFlags displayOptions = UnderlayDisplayFlags.ShowUnderlay;
            short contrast = 100;
            short fade = 0;
            Vector2 clippingVertex = Vector2.Zero;
            List<Vector2> clippingVertexes = new List<Vector2>();
            ClippingBoundary clippingBoundary;
            List<XData> xData = new List<XData>();

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 10:
                        position.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 20:
                        position.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 30:
                        position.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 41:
                        scale.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 42:
                        scale.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 43:
                        scale.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 50:
                        rotation = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 210:
                        normal.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 220:
                        normal.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 230:
                        normal.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 340:
                        underlayDefHandle = this.chunk.ReadHex();
                        this.chunk.Next();
                        break;
                    case 280:
                        displayOptions = (UnderlayDisplayFlags) this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 281:
                        contrast = this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 282:
                        fade = this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 11:
                        clippingVertex = new Vector2();
                        clippingVertex.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 21:
                        clippingVertex.Y = this.chunk.ReadDouble();
                        clippingVertexes.Add(clippingVertex);
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId));
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new Exception("The extended data of an entity must start with the application registry code.");

                        this.chunk.Next();
                        break;
                }
            }

            Vector3 wcsPosition = MathHelper.Transform(position, normal, CoordinateSystem.Object, CoordinateSystem.World);
            if (clippingVertexes.Count < 2)
                clippingBoundary = null;
            else if (clippingVertexes.Count == 2)
                clippingBoundary = new ClippingBoundary(clippingVertexes[0], clippingVertexes[1]);
            else
                clippingBoundary = new ClippingBoundary(clippingVertexes);

            Underlay underlay = new Underlay
            {
                Position = wcsPosition,
                Scale = scale,
                Normal = normal,
                Rotation = rotation,
                DisplayOptions = displayOptions,
                Contrast = contrast,
                Fade = fade,
                ClippingBoundary = clippingBoundary
            };

            underlay.XData.AddRange(xData);

            if (string.IsNullOrEmpty(underlayDefHandle) || underlayDefHandle == "0")
                return null;

            this.underlayToDefinitionHandles.Add(underlay, underlayDefHandle);

            return underlay;
        }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <c>Wipeout</c> class.
 /// </summary>
 /// <param name="clippingBoundary">The wipeout clipping boundary.</param>
 public Wipeout(ClippingBoundary clippingBoundary)
     : base(EntityType.Wipeout, DxfObjectCode.Wipeout)
 {
     this.clippingBoundary = clippingBoundary;
     this.elevation = 0.0;
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <c>Image</c> class.
 /// </summary>
 /// <param name="imageDefinition">Image definition.</param>
 /// <param name="position">Image <see cref="Vector3">position</see> in world coordinates.</param>
 /// <param name="width">Image width in world coordinates.</param>
 /// <param name="height">Image height in world coordinates.</param>
 public Image(ImageDefinition imageDefinition, Vector3 position, double width, double height)
     : base(EntityType.Image, DxfObjectCode.Image)
 {
     this.imageDefinition = imageDefinition;
     this.position = position;
     this.width = width;
     this.height = height;
     this.rotation = 0;
     this.clipping = false;
     this.brightness = 50;
     this.contrast = 50;
     this.fade = 0;
     this.displayOptions = ImageDisplayFlags.ShowImage | ImageDisplayFlags.ShowImageWhenNotAlignedWithScreen | ImageDisplayFlags.UseClippingBoundary;
     this.clippingBoundary = new ClippingBoundary(-0.5, -0.5, imageDefinition.Width, imageDefinition.Height);
 }