Ejemplo n.º 1
0
        /// <summary>
        /// Converts the RGB (red, green, blue) components of an <see cref="AciColor">AciColor</see> to HSL (hue, saturation, lightness) values.
        /// </summary>
        /// <param name="color">A <see cref="AciColor">color</see>.</param>
        /// <param name="hue">Hue (output values range from 0 to 1).</param>
        /// <param name="saturation">Saturation percentage (output values range from 0 to 1).</param>
        /// <param name="lightness">Lightness percentage (output values range from 0 to 1).</param>
        public static void ToHsl(AciColor color, out double hue, out double saturation, out double lightness)
        {
            double red   = color.R / 255.0;
            double green = color.G / 255.0;
            double blue  = color.B / 255.0;

            hue        = 0;
            saturation = 0;
            double v = Math.Max(red, green);

            v = Math.Max(v, blue);
            double m = Math.Min(red, green);

            m = Math.Min(m, blue);

            lightness = (m + v) / 2.0;
            if (lightness <= 0.0)
            {
                return;
            }

            double vm = v - m;

            saturation = vm;
            if (saturation > 0.0)
            {
                saturation /= (lightness <= 0.5) ? (v + m) : (2.0 - v - m);
            }
            else
            {
                return;
            }

            double red2   = (v - red) / vm;
            double green2 = (v - green) / vm;
            double blue2  = (v - blue) / vm;

            if (MathHelper.IsEqual(red, v))
            {
                hue = (MathHelper.IsEqual(green, m) ? 5.0 + blue2 : 1.0 - green2);
            }
            else if (MathHelper.IsEqual(green, v))
            {
                hue = (MathHelper.IsEqual(blue, m) ? 1.0 + red2 : 3.0 - blue2);
            }
            else
            {
                hue = (MathHelper.IsEqual(red, m) ? 3.0 + green2 : 5.0 - red2);
            }

            hue /= 6.0;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns>A new object that is a copy of this instance.</returns>
        public object Clone()
        {
            AciColor color = new AciColor
            {
                r            = this.r,
                g            = this.g,
                b            = this.b,
                useTrueColor = this.useTrueColor,
                index        = this.index
            };

            return(color);
        }
Ejemplo n.º 3
0
        internal static AciColor FromCadIndex(short index)
        {
            AciColor color;

            switch (index)
            {
            case 0:
                color = ByBlock;
                break;

            case 256:
                color = ByLayer;
                break;

            default:
                color = new AciColor(index);
                break;
            }

            return(color);
        }
Ejemplo n.º 4
0
 internal static int ToTrueColor(AciColor color)
 {
     return(color.B + (color.G * 256) + (color.R * 65536));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Check if the components of two colors are equal.
 /// </summary>
 /// <param name="obj">Another color to compare to.</param>
 /// <returns>True if the three components are equal or false in anyother case.</returns>
 public bool Equals(AciColor obj)
 {
     return((obj.r == this.r) && (obj.g == this.g) && (obj.b == this.b));
 }
Ejemplo n.º 6
0
        private Attribute ReadAttribute(Block block, ref CodeValuePair code)
        {
            string handle = string.Empty;
            AttributeDefinition attdef = null;
            Layer layer = Layer.Default;
            AciColor color = AciColor.ByLayer;
            LineType lineType = LineType.ByLayer;
            Object value = null;
            code = this.ReadCodePair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        break;
                    case 2:
                        attdef = block.Attributes[code.Value];
                        break;
                    case 1:
                        value = code.Value;
                        break;
                    case 8: //layer code
                        layer = this.GetLayer(code.Value);
                        break;
                    case 62: //aci color code
                        color = new AciColor(short.Parse(code.Value));
                        break;
                    case 6: //type line code
                        lineType = this.GetLineType(code.Value);
                        break;
                }
                code = this.ReadCodePair();
            }

            return new Attribute(attdef)
                       {
                           Color = color,
                           Layer = layer,
                           LineType = lineType,
                           Value = value,
                           Handle = handle
                       };
        }
Ejemplo n.º 7
0
        private AttributeDefinition ReadAttributeDefinition(ref CodeValuePair code)
        {
            string handle = string.Empty;
            string id = string.Empty;
            string text = string.Empty;
            object value = null;
            AttributeFlags flags = AttributeFlags.Visible;
            Vector3d firstAlignmentPoint = Vector3d.Zero;
            Vector3d secondAlignmentPoint = Vector3d.Zero;
            Layer layer = Layer.Default;
            AciColor color = AciColor.ByLayer;
            LineType lineType = LineType.ByLayer;
            TextStyle style = TextStyle.Default;
            float height = 0;
            float widthFactor = 0;
            int horizontalAlignment = 0;
            int verticalAlignment = 0;
            float rotation = 0;
            Vector3d normal = Vector3d.UnitZ;

            code = this.ReadCodePair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        break;
                    case 2:
                        id = code.Value;
                        break;
                    case 3:
                        text = code.Value;
                        break;
                    case 1:
                        value = code.Value;
                        break;
                    case 8: //layer code
                        layer = this.GetLayer(code.Value);
                        break;
                    case 62: //aci color code
                        color = new AciColor(short.Parse(code.Value));
                        break;
                    case 6: //type line code
                        lineType = this.GetLineType(code.Value);
                        break;
                    case 70:
                        flags = (AttributeFlags) int.Parse(code.Value);
                        break;
                    case 10:
                        firstAlignmentPoint.X = double.Parse(code.Value);
                        break;
                    case 20:
                        firstAlignmentPoint.Y = double.Parse(code.Value);
                        break;
                    case 30:
                        firstAlignmentPoint.Z = double.Parse(code.Value);
                        break;
                    case 11:
                        secondAlignmentPoint.X = double.Parse(code.Value);
                        break;
                    case 21:
                        secondAlignmentPoint.Y = double.Parse(code.Value);
                        break;
                    case 31:
                        secondAlignmentPoint.Z = double.Parse(code.Value);
                        break;
                    case 7:
                        style = this.GetTextStyle(code.Value);
                        break;
                    case 40:
                        height = float.Parse(code.Value);
                        break;
                    case 41:
                        widthFactor = float.Parse(code.Value);
                        break;
                    case 50:
                        rotation = float.Parse(code.Value);
                        break;
                    case 72:
                        horizontalAlignment = int.Parse(code.Value);
                        break;
                    case 74:
                        verticalAlignment = int.Parse(code.Value);
                        break;
                    case 210:
                        normal.X = double.Parse(code.Value);
                        break;
                    case 220:
                        normal.Y = double.Parse(code.Value);
                        break;
                    case 230:
                        normal.Z = double.Parse(code.Value);
                        break;
                }

                code = this.ReadCodePair();
            }

            TextAlignment alignment = ObtainAlignment(horizontalAlignment, verticalAlignment);

            return new AttributeDefinition(id)
                       {
                           BasePoint = (alignment == TextAlignment.BaselineLeft ? firstAlignmentPoint : secondAlignmentPoint),
                           Normal = normal,
                           Alignment = alignment,
                           Text = text,
                           Value = value,
                           Flags = flags,
                           Layer = layer,
                           Color = color,
                           LineType = lineType,
                           Style = style,
                           Height = height,
                           WidthFactor = widthFactor,
                           Rotation = rotation,
                           Handle = handle
                       };
        }
Ejemplo n.º 8
0
        private Vertex ReadVertex(ref CodeValuePair code)
        {
            string handle = string.Empty;
            Layer layer = Layer.Default;
            AciColor color = AciColor.ByLayer;
            LineType lineType = LineType.ByLayer;
            Vector3d location = new Vector3d();
            Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();
            float endThickness = 0.0f;
            float beginThickness = 0.0f;
            double bulge = 0.0;
            List<int> vertexIndexes = new List<int>();
            VertexTypeFlags flags = VertexTypeFlags.PolylineVertex;

            code = this.ReadCodePair();

            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 8:
                        layer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 62:
                        color = new AciColor(short.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 6:
                        lineType = this.GetLineType(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 10:
                        location.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 20:
                        location.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        location.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 40:
                        beginThickness = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 41:
                        endThickness = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 42:
                        bulge = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 70:
                        flags = (VertexTypeFlags) int.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 71:
                        vertexIndexes.Add(int.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 72:
                        vertexIndexes.Add(int.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 73:
                        vertexIndexes.Add(int.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 74:
                        vertexIndexes.Add(int.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 1001:
                        XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                        xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                        break;
                    default:
                        if (code.Code >= 1000 && code.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "The extended data of an entity must start with the application registry code " + this.fileLine);

                        code = this.ReadCodePair();
                        break;
                }
            }

            return new Vertex
                       {
                           Flags = flags,
                           Location = location,
                           BeginThickness = beginThickness,
                           Bulge = bulge,
                           Color = color,
                           EndThickness = endThickness,
                           Layer = layer,
                           LineType = lineType,
                           VertexIndexes = vertexIndexes.ToArray(),
                           XData = xData,
                           Handle = handle
                       };

            //IVertex vertex;
            //if ((flags & (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh)) == (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh))
            //{
            //    vertex = new PolyfaceMeshVertex
            //                 {
            //                     Location=location
            //                 };
            //    vertex.XData=xData;
            //}
            //else if ((flags & (VertexTypeFlags.PolyfaceMeshVertex)) == (VertexTypeFlags.PolyfaceMeshVertex))
            //{
            //    vertex = new PolyfaceMeshFace(vertexIndexes.ToArray());
            //}
            //else if ((flags & (VertexTypeFlags.Polyline3dVertex)) == (VertexTypeFlags.Polyline3dVertex))
            //{
            //    vertex = new Polyline3dVertex
            //    {
            //        Location = location,
            //    };

            //    vertex.XData=xData;
            //}
            //else
            //{
            //    vertex = new PolylineVertex
            //                 {
            //                     Location =new Vector2d(location.X, location.Y),
            //                     Bulge = bulge,
            //                     BeginThickness = beginThickness,
            //                     EndThickness = endThickness
            //                 };

            //    vertex.XData=xData;
            //}

            //return vertex;
        }
Ejemplo n.º 9
0
        private IPolyline ReadPolyline(ref CodeValuePair code)
        {
            string handle = string.Empty;
            Layer layer = Layer.Default;
            AciColor color = AciColor.ByLayer;
            LineType lineType = LineType.ByLayer;
            PolylineTypeFlags flags = PolylineTypeFlags.OpenPolyline;
            double elevation = 0.0;
            float thickness = 0.0f;
            Vector3d normal = Vector3d.UnitZ;
            List<Vertex> vertexes = new List<Vertex>();
            Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();
            //int numVertexes = -1;
            //int numFaces = -1;

            code = this.ReadCodePair();

            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 8:
                        layer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 62:
                        color = new AciColor(short.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 6:
                        lineType = this.GetLineType(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        elevation = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 39:
                        thickness = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 70:
                        flags = (PolylineTypeFlags) (int.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 71:
                        //this field might not exist for polyface meshes, we cannot depend on it
                        //numVertexes = int.Parse(code.Value); code = this.ReadCodePair();
                        code = this.ReadCodePair();
                        break;
                    case 72:
                        //this field might not exist for polyface meshes, we cannot depend on it
                        //numFaces  = int.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 210:
                        normal.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 220:
                        normal.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 230:
                        normal.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 1001:
                        XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                        xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                        break;
                    default:
                        if (code.Code >= 1000 && code.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "The extended data of an entity must start with the application registry code " + this.fileLine);

                        code = this.ReadCodePair();
                        break;
                }
            }

            //begin to read the vertex list
            if (code.Value != DxfObjectCode.Vertex)
                throw new DxfEntityException(DxfObjectCode.Polyline, this.file, "Vertex not found in line " + this.fileLine);
            while (code.Value != StringCode.EndSequence)
            {
                if (code.Value == DxfObjectCode.Vertex)
                {
                    Debug.Assert(code.Code == 0);
                    Vertex vertex = this.ReadVertex(ref code);
                    vertexes.Add(vertex);
                }
            }

            // read the end end sequence object until a new element is found
            if (code.Value != StringCode.EndSequence)
                throw new DxfEntityException(DxfObjectCode.Polyline, this.file, "End sequence entity not found in line " + this.fileLine);
            code = this.ReadCodePair();
            string endSequenceHandle = string.Empty;
            Layer endSequenceLayer = layer;
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        endSequenceHandle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 8:
                        endSequenceLayer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    default:
                        code = this.ReadCodePair();
                        break;
                }
            }

            IPolyline pol;
            bool isClosed = false;

            if ((flags & PolylineTypeFlags.ClosedPolylineOrClosedPolygonMeshInM) == PolylineTypeFlags.ClosedPolylineOrClosedPolygonMeshInM)
            {
                isClosed = true;
            }

            //to avoid possible error between the vertex type and the polyline type
            //the polyline type will decide which information to use from the read vertex
            if ((flags & PolylineTypeFlags.Polyline3D) == PolylineTypeFlags.Polyline3D)
            {
                List<Polyline3dVertex> polyline3dVertexes = new List<Polyline3dVertex>();
                foreach (Vertex v in vertexes)
                {
                    Polyline3dVertex vertex = new Polyline3dVertex
                                                  {
                                                      Color = v.Color,
                                                      Layer = v.Layer,
                                                      LineType = v.LineType,
                                                      Location = v.Location,
                                                      Handle = v.Handle
                                                  };
                    vertex.XData = v.XData;
                    polyline3dVertexes.Add(vertex);
                }

                ////posible error avoidance, the polyline is marked as polyline3d code:(70,8) but the vertex is marked as PolylineVertex code:(70,0)
                //if (v.Type == EntityType.PolylineVertex)
                //{
                //    Polyline3dVertex polyline3dVertex = new Polyline3dVertex(((PolylineVertex)v).Location.X, ((PolylineVertex)v).Location.Y,0);
                //    polyline3dVertexes.Add(polyline3dVertex);
                //}
                //else
                //{
                //    polyline3dVertexes.Add((Polyline3dVertex)v);
                //}
                //}
                pol = new Polyline3d(polyline3dVertexes, isClosed)
                          {
                              Handle = handle
                          };
                ((Polyline3d) pol).EndSequence.Handle = endSequenceHandle;
                ((Polyline3d) pol).EndSequence.Layer = endSequenceLayer;
            }
            else if ((flags & PolylineTypeFlags.PolyfaceMesh) == PolylineTypeFlags.PolyfaceMesh)
            {
                //the vertex list created contains vertex and face information
                List<PolyfaceMeshVertex> polyfaceVertexes = new List<PolyfaceMeshVertex>();
                List<PolyfaceMeshFace> polyfaceFaces = new List<PolyfaceMeshFace>();
                foreach (Vertex v in vertexes)
                {
                    if ((v.Flags & (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh)) == (VertexTypeFlags.PolyfaceMeshVertex | VertexTypeFlags.Polygon3dMesh))
                    {
                        PolyfaceMeshVertex vertex = new PolyfaceMeshVertex
                                                        {
                                                            Color = v.Color,
                                                            Layer = v.Layer,
                                                            LineType = v.LineType,
                                                            Location = v.Location,
                                                            Handle = v.Handle
                                                        };
                        vertex.XData = xData;
                        polyfaceVertexes.Add(vertex);
                    }
                    else if ((v.Flags & (VertexTypeFlags.PolyfaceMeshVertex)) == (VertexTypeFlags.PolyfaceMeshVertex))
                    {
                        PolyfaceMeshFace vertex = new PolyfaceMeshFace
                                                      {
                                                          Color = v.Color,
                                                          Layer = v.Layer,
                                                          LineType = v.LineType,
                                                          VertexIndexes = v.VertexIndexes,
                                                          Handle = v.Handle
                                                      };
                        vertex.XData = xData;
                        polyfaceFaces.Add(vertex);
                    }

                    //if (v.Type == EntityType.PolyfaceMeshVertex)
                    //{
                    //    polyfaceVertexes.Add((PolyfaceMeshVertex) v);
                    //}
                    //else if (v.Type == EntityType.PolyfaceMeshFace)
                    //{
                    //    polyfaceFaces.Add((PolyfaceMeshFace) v);
                    //}
                    //else
                    //{
                    //    throw new EntityDxfException(v.Type.ToString(), this.file, "Error in vertex type.");
                    //}
                }
                pol = new PolyfaceMesh(polyfaceVertexes, polyfaceFaces)
                          {
                              Handle = handle
                          };
                ((PolyfaceMesh) pol).EndSequence.Handle = endSequenceHandle;
                ((PolyfaceMesh) pol).EndSequence.Layer = endSequenceLayer;
            }
            else
            {
                List<PolylineVertex> polylineVertexes = new List<PolylineVertex>();
                foreach (Vertex v in vertexes)
                {
                    PolylineVertex vertex = new PolylineVertex
                                                {
                                                    Location = new Vector2d(v.Location.X, v.Location.Y),
                                                    BeginThickness = v.BeginThickness,
                                                    Bulge = v.Bulge,
                                                    Color = v.Color,
                                                    EndThickness = v.EndThickness,
                                                    Layer = v.Layer,
                                                    LineType = v.LineType,
                                                    Handle = v.Handle
                                                };
                    vertex.XData = xData;

                    ////posible error avoidance, the polyline is marked as polyline code:(70,0) but the vertex is marked as Polyline3dVertex code:(70,32)
                    //if (v.Type==EntityType.Polyline3dVertex)
                    //{
                    //    PolylineVertex polylineVertex = new PolylineVertex(((Polyline3dVertex)v).Location.X, ((Polyline3dVertex)v).Location.Y);
                    //    polylineVertexes.Add(polylineVertex);
                    //}
                    //else
                    //{
                    //    polylineVertexes.Add((PolylineVertex) v);
                    //}
                    polylineVertexes.Add(vertex);
                }

                pol = new Polyline(polylineVertexes, isClosed)
                          {
                              Thickness = thickness,
                              Elevation = elevation,
                              Normal = normal,
                              Handle = handle
                          };
                ((Polyline) pol).EndSequence.Handle = endSequenceHandle;
                ((Polyline) pol).EndSequence.Layer = endSequenceLayer;
            }

            pol.Color = color;
            pol.Layer = layer;
            pol.LineType = lineType;
            pol.XData = xData;

            return pol;
        }
Ejemplo n.º 10
0
        private Layer ReadLayer(ref CodeValuePair code)
        {
            string handle = string.Empty;
            string name = string.Empty;
            bool isVisible = true;
            AciColor color = null;
            LineType lineType = null;

            code = this.ReadCodePair();

            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        break;
                    case 2:
                        if (string.IsNullOrEmpty(code.Value))
                        {
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "Invalid value " + code.Value + " in code " + code.Code + " line " + this.fileLine);
                        }
                        name = code.Value;
                        break;
                    case 62:
                        short index;
                        if (short.TryParse(code.Value, out index))
                        {
                            if (index < 0)
                            {
                                isVisible = false;
                                index = Math.Abs(index);
                            }
                            if (index > 256)
                            {
                                throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                             "Invalid value " + code.Value + " in code " + code.Code + " line " + this.fileLine);
                            }
                        }
                        else
                        {
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "Invalid value " + code.Value + " in code " + code.Code + " line " + this.fileLine);
                        }

                        color = new AciColor(short.Parse(code.Value));
                        break;
                    case 6:
                        if (string.IsNullOrEmpty(code.Value))
                        {
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "Invalid value " + code.Value + " in code " + code.Code + " line " + this.fileLine);
                        }
                        lineType = this.GetLineType(code.Value);
                        break;
                }

                code = this.ReadCodePair();
            }

            return new Layer(name)
                       {
                           Color = color,
                           LineType = lineType,
                           IsVisible = isVisible,
                           Handle = handle
                       };
        }
Ejemplo n.º 11
0
        private Insert ReadInsert(ref CodeValuePair code)
        {
            string handle = string.Empty;
            Vector3d basePoint = Vector3d.Zero;
            Vector3d normal = Vector3d.UnitZ;
            Vector3d scale = new Vector3d(1, 1, 1);
            float rotation = 0.0f;
            Block block = null;
            Layer layer = Layer.Default;
            AciColor color = AciColor.ByLayer;
            LineType lineType = LineType.ByLayer;
            List<Attribute> attributes = new List<Attribute>();
            Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();

            code = this.ReadCodePair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        handle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 2:
                        block = this.GetBlock(code.Value);
                        if (block == null)
                            throw new DxfEntityException(DxfObjectCode.Insert, this.file, "Block " + code.Value + " not defined line " + this.fileLine);
                        code = this.ReadCodePair();
                        break;
                    case 8: //layer code
                        layer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 62: //aci color code
                        color = new AciColor(short.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 6: //type line code
                        lineType = this.GetLineType(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 10:
                        basePoint.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 20:
                        basePoint.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        basePoint.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 41:
                        scale.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 42:
                        scale.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 43:
                        scale.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 50:
                        rotation = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 210:
                        normal.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 220:
                        normal.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 230:
                        normal.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 1001:
                        XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                        xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                        break;
                    default:
                        if (code.Code >= 1000 && code.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "The extended data of an entity must start with the application registry code " + this.fileLine);

                        code = this.ReadCodePair();
                        break;
                }
            }

            // if there are attributes
            string endSequenceHandle = string.Empty;
            Layer endSequenceLayer = Layer.Default;
            if (code.Value == DxfObjectCode.Attribute)
            {
                while (code.Value != StringCode.EndSequence)
                {
                    if (code.Value == DxfObjectCode.Attribute)
                    {
                        Debug.Assert(code.Code == 0);
                        Attribute attribute = this.ReadAttribute(block, ref code);
                        attributes.Add(attribute);
                    }
                }
                // read the end end sequence object until a new element is found
                code = this.ReadCodePair();
                while (code.Code != 0)
                {
                    switch (code.Code)
                    {
                        case 5:
                            endSequenceHandle = code.Value;
                            code = this.ReadCodePair();
                            break;
                        case 8:
                            endSequenceLayer = this.GetLayer(code.Value);
                            code = this.ReadCodePair();
                            break;
                        default:
                            code = this.ReadCodePair();
                            break;
                    }
                }
            }

            Insert insert = new Insert(block)
                                {
                                    Color = color,
                                    Layer = layer,
                                    LineType = lineType,
                                    InsertionPoint = basePoint,
                                    Rotation = rotation,
                                    Scale = scale,
                                    Normal = normal,
                                    Handle = handle
                                };

            insert.EndSequence.Handle = endSequenceHandle;
            insert.EndSequence.Layer = endSequenceLayer;
            insert.Attributes.Clear();
            insert.Attributes.AddRange(attributes);
            insert.XData = xData;

            return insert;
        }
Ejemplo n.º 12
0
        private static void WriteGradientPattern()
        {
            List<LwPolylineVertex> vertexes = new List<LwPolylineVertex>
                                            {
                                                new LwPolylineVertex(new Vector2(0, 0)),
                                                new LwPolylineVertex(new Vector2(0, 150)),
                                                new LwPolylineVertex(new Vector2(150, 150)),
                                                new LwPolylineVertex(new Vector2(150, 0))
                                            };
            LwPolyline pol = new LwPolyline(vertexes, true);


            Line line1 = new Line(new Vector2(0, 0), new Vector2(0, 150));
            Line line2 = new Line(new Vector2(0, 150), new Vector2(150, 150));
            Line line3 = new Line(new Vector2(150, 150), new Vector2(150, 0));
            Line line4 = new Line(new Vector2(150, 0), new Vector2(0, 0));

            AciColor color = new AciColor(63, 79, 127);
            HatchGradientPattern gradient = new HatchGradientPattern(color, AciColor.Blue, HatchGradientPatternType.Linear);
            //HatchGradientPattern gradient = new HatchGradientPattern(AciColor.Red, 0.75, HatchGradientPatternType.Linear);
            gradient.Angle = 30;

            List<HatchBoundaryPath> boundary = new List<HatchBoundaryPath>
                                                    {
                                                        new HatchBoundaryPath(new List<EntityObject> {pol})
                                                    };
            Hatch hatch = new Hatch(gradient, boundary, true);
            
            // gradients are only supported for AutoCad2004 and later
            DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2004);
            dxf.AddEntity(hatch);
            dxf.Save("gradient test.dxf");

            //DxfDocument dxf2 = DxfDocument.Load("gradient test.dxf");

            //dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000;

            //dxf.Save("gradient test 2000.dxf");

        }