Ejemplo n.º 1
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="startingIndex"></param>
 /// <param name="list"></param>
 public HeaderSectionArgs(int startingIndex, TaggedDataList list)
     : base(startingIndex, list)
 {
     AutoCadVersion = new AutoCadVersionVar(string.Empty);
     LastSavedBy    = new StringVar(FileVariableCodes.LastSavedBy, string.Empty);
     CurrentLayer   = new StringVar(FileVariableCodes.CurrentLayer, string.Empty);
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     Parse a <see cref="GeoArc" /> from the boundary data in the Hatch
        /// </summary>
        /// <param name="list">The Tagged Data List</param>
        /// <param name="index">The current index</param>
        /// <returns>A GeoArc</returns>
        private static GeoArc ParseCircularArcEdge(TaggedDataList list, ref int index)
        {
            var cpX        = 0.0;
            var cpY        = 0.0;
            var radius     = 0.0;
            var startAngle = 0.0;
            var endAngle   = 0.0;

            for ( ; index < list.Length; ++index)
            {
                var currentData = list.GetPair(index);
                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    cpX = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    cpY = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.Radius:
                    radius = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.StartAngle:
                    startAngle = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.EndAngle:
                    endAngle = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.IsCounterClockWise:
                    // Counter Clockwise Arc
                    if (currentData.Value.Contains("1"))
                    {
                        return(new GeoArc(
                                   new Vertex(cpX, cpY),
                                   GeoMath.DegToRad(startAngle),
                                   GeoMath.DegToRad(endAngle), radius));
                    }
                    // AutoCAD not using Absolute angles when the
                    // Arc is not counter clock wise
                    startAngle -= 180;
                    endAngle   -= 180;
                    // Clockwise Arc
                    return(new GeoArc(
                               new Vertex(cpX, cpY),
                               GeoMath.DegToRad(startAngle),
                               GeoMath.DegToRad(endAngle), radius));

                default:
                    continue;
                }
            }

            throw new ArgumentOutOfRangeException();
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        /// <summary>
        ///     Main Parsing function for the LineBuffer.
        /// </summary>
        /// <remarks>
        ///     This parsing function will first try and parse
        ///     the information for the base class <see cref="T:Dxflib.Entities.EntityBuffer" />.
        ///     If that function returns false then it will attempt to parse based on
        ///     the <see cref="T:Dxflib.Entities.LineGroupCodes" />. If that fails then the line buffer
        ///     does not fill anything and the extraction process moves to the next line.
        /// </remarks>
        /// <param name="list">The List of Tagged Data</param>
        /// <param name="index">The Index where the entity starts</param>
        /// <returns>True if parse was successful</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            // Iterate through the file and extract data until the current line
            // is an entity end marker
            for (var currentIndex = index + 1;
                 currentIndex < list.Length;
                 ++currentIndex)
            {
                // The current data is set
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                // Check to see if the entity bass class can parse first
                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                // If not then parse here
                // If this class can still not parse then continue
                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    X0 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.XPointEnd:
                    X1 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    Y0 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPointEnd:
                    Y1 = double.Parse(currentData.Value);
                    continue;

                case LineGroupCodes.Thickness:
                    Thickness = double.Parse(currentData.Value);
                    continue;

                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        /// <summary>
        ///     The Parse Function for the CircularArc Entity
        /// </summary>
        /// <param name="list">The Tagged Data list</param>
        /// <param name="index">The Current Index</param>
        /// <returns>Always True</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1; currentIndex < list.Length; ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    CenterPointX = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    CenterPointY = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.ZPoint:
                    CenterPointZ = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.Thickness:
                    Thickness = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.Radius:
                    Radius = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.StartAngle:
                    StartAngle = double.Parse(currentData.Value);
                    continue;

                case CircularArcCodes.EndAngle:
                    EndAngle = double.Parse(currentData.Value);
                    continue;

                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Parsing the Boundary Edge from edge Data
        /// </summary>
        /// <param name="list">The <see cref="TaggedDataList" /> list</param>
        /// <param name="index">The current index</param>
        /// <returns>A GeoPolyline</returns>
        private static GeoPolyline ParseBoundary(TaggedDataList list, ref int index)
        {
            var geoPolyline = new GeoPolyline(); // The Geo Polyline to be returned

            for ( ; index < list.Length; ++index)
            {
                var currentData = list.GetPair(index);

                switch (currentData.GroupCode)
                {
                // Edge Types
                case HatchCodes.EdgeType:
                    switch ((EdgeTypes)int.Parse(currentData.Value))
                    {
                    case EdgeTypes.Line:
                        geoPolyline.Add(ParseLineEdge(list, ref index));
                        break;

                    case EdgeTypes.CircularArc:
                        geoPolyline.Add(ParseCircularArcEdge(list, ref index));
                        break;

                    case EdgeTypes.EllipticalArc:
                        break;

                    case EdgeTypes.Spline:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    continue;

                // When to exit the loop
                case HatchCodes.SourceObjectsCount:
                    --index;
                    return(geoPolyline);

                default:
                    continue;
                }
            }

            // This area of code should not be reachable
            throw new ArgumentOutOfRangeException();
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     The Parse Virtual Function that is to be overriden by
        ///     each entity that is to be extracted. This function also,
        ///     Parses global entity properties such as handle or <see cref="LayerName" />.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <returns>True if the parse was successful</returns>
        public virtual bool Parse(TaggedDataList list, int index)
        {
            var currentData = list.GetPair(index);

            switch (currentData.GroupCode)
            {
            case GroupCodesBase.Handle:
                Handle = currentData.Value;
                return(true);

            case GroupCodesBase.LayerName:
                LayerName = currentData.Value;
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Constructor that requires a path to a file.
        ///     This constructor will read the file and set up all of the required
        ///     tools for the DxfFile class
        /// </summary>
        /// <param name="pathToFile">An absolute or relative path to a dxf file</param>
        public DxfFile(string pathToFile)
        {
            // Initialize
            var fileReader = new DxfReader(pathToFile);

            Layers = new LayerDictionary();

            // Setup file
            PathToFile  = fileReader.PathToFile;
            FileName    = Path.GetFileName(PathToFile);
            DxfFileData = new TaggedDataList(fileReader.ReadFile());

            // The Main Parsing Calling Function
            var asciiParser = new AsciiParser(this);

            asciiParser.ParseFile();

            // Update the layer dictionary now that the Entities are all built
            Layers.UpdateDictionary(Entities.Values);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        /// <summary>
        /// The Parse Function for the <see cref="T:Dxflib.Entities.Point" /> Entity
        /// </summary>
        /// <param name="list">The Tagged data list of group codes and values</param>
        /// <param name="index">The current Index of the parser</param>
        /// <returns>Always True</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1; currentIndex < list.Length; ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    X = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    Y = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.ZPoint:
                    Z = double.Parse(currentData.Value);
                    continue;

                case PointCodes.AngleOfXAxis:
                    continue;

                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Parse a geoline from a hatch boundary
        /// </summary>
        /// <param name="list">The <see cref="TaggedDataList" /> list</param>
        /// <param name="index">The current index</param>
        /// <returns>The GeoLine Parsed</returns>
        private static GeoLine ParseLineEdge(TaggedDataList list, ref int index)
        {
            // All of the variables for the GeoLine
            var x0 = 0.0;
            var x1 = 0.0;
            var y0 = 0.0;

            // Iterate through the list
            for ( ; index < list.Length; ++index)
            {
                var currentData = list.GetPair(index);

                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    x0 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.XPointEnd:
                    x1 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    y0 = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPointEnd:
                    var y1 = double.Parse(currentData.Value);
                    // This is the last data point so return
                    return(new GeoLine(new Vertex(x0, y0), new Vertex(x1, y1)));

                default:
                    continue;
                }
            }

            // this part of the code should never be reached
            throw new ArgumentOutOfRangeException();
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        /// <summary>
        ///     The Parsing function of the MText Object
        /// </summary>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1; currentIndex < list.Length; ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    PositionVertex.X = double.Parse(currentData.Value);
                    break;

                case GroupCodesBase.YPoint:
                    PositionVertex.Y = double.Parse(currentData.Value);
                    break;

                case GroupCodesBase.ZPoint:
                    PositionVertex.Z = double.Parse(currentData.Value);
                    break;

                case TextCodes.TextHeight:
                    Height = double.Parse(currentData.Value);
                    break;

                case MTextCodes.ReferenceRectangleWidth:
                    ReferenceRecWidth = double.Parse(currentData.Value);
                    continue;

                case MTextCodes.AttachmentPoint:
                    Justify = ParseAttachmentPoint(int.Parse(currentData.Value));
                    continue;

                case MTextCodes.DrawDirection:
                    var value = int.Parse(currentData.Value);
                    switch (value)
                    {
                    case 1:
                        DrawDirection = DrawDirections.LeftToRight;
                        break;

                    case 3:
                        DrawDirection = DrawDirections.TopToBottom;
                        break;

                    case 5:
                        DrawDirection = DrawDirections.ByStyle;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;

                case TextCodes.TextString:
                    Contents = currentData.Value;
                    break;

                case MTextCodes.AdditionalText:
                    Contents += currentData.Value;
                    break;

                case TextCodes.TextStyleName:
                    TextStyle.Name = currentData.Value;
                    break;

                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 11
0
        /// <inheritdoc />
        /// <summary>
        ///     Main Parse Function for the Lwpolyline Class
        /// </summary>
        /// <param name="list"></param>
        /// <param name="index"></param>
        /// <returns>True or false if the parse was successful</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1;
                 currentIndex < list.Length;
                 ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                // Number of Vertices
                case LwPolylineCodes.NumberOfVertices:
                    NumberOfVertices = int.Parse(currentData.Value);
                    continue;

                // Lwpolyline Flag
                case LwPolylineCodes.PolylineFlag:
                    PolyLineFlag = currentData.Value.Contains("1");
                    continue;

                // Constant Width
                case LwPolylineCodes.ConstantWidth:
                    ConstantWidth = double.Parse(currentData.Value);
                    continue;

                // Elevation
                case LwPolylineCodes.Elevation:
                    Elevation = double.Parse(currentData.Value);
                    continue;

                // Thickness
                case LwPolylineCodes.Thickness:
                    Thickness = double.Parse(currentData.Value);
                    continue;

                // X values
                case GroupCodesBase.XPoint:
                    BulgeList.Add(Bulge.BulgeNull);
                    XValues.Add(double.Parse(currentData.Value));
                    continue;

                // Y values
                case GroupCodesBase.YPoint:
                    YValues.Add(double.Parse(currentData.Value));
                    continue;

                // Bulge Values
                case LwPolylineCodes.Bulge:
                    BulgeList.RemoveAt(BulgeList.Count - 1);
                    BulgeList.Add(double.Parse(currentData.Value));
                    continue;

                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        /// <summary>
        ///     The Parsing Function for the <see cref="Hatch" /> entity
        /// </summary>
        /// <param name="list">The Tagged Data List</param>
        /// <param name="index">The current index of the list</param>
        /// <returns></returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1;
                 currentIndex < list.Length;
                 ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                // Hatch Pattern Name
                case HatchCodes.HatchPatternName:
                    HatchPatternName = currentData.Value;
                    continue;

                // Solid Fill Flag
                case HatchCodes.SolidFillFlag:
                    SolidFillFlag = currentData.Value.Contains("1");
                    continue;

                // Associativity Flag
                case HatchCodes.AssociativityFlag:
                    AssociativityFlag = currentData.Value.Contains("1");
                    continue;

                // Number of Boundary Paths (Loops)
                case HatchCodes.NumberOfBoundaryLoops:
                    NumberOfLoops = int.Parse(currentData.Value);
                    continue;

                // Hatch Style
                case HatchCodes.HatchStyle:
                    switch ((HatchStyles)int.Parse(currentData.Value))
                    {
                    case HatchStyles.Normal:
                        HatchStyle = HatchStyles.Normal;
                        break;

                    case HatchStyles.Outer:
                        HatchStyle = HatchStyles.Outer;
                        break;

                    case HatchStyles.Ignore:
                        HatchStyle = HatchStyles.Ignore;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    continue;

                // Pattern Type
                case HatchCodes.HatchPatternType:
                    switch ((HatchPatternType)int.Parse(currentData.Value))
                    {
                    case HatchPatternType.UserDefined:
                        PatternType = HatchPatternType.UserDefined;
                        break;

                    case HatchPatternType.Predefined:
                        PatternType = HatchPatternType.Predefined;
                        break;

                    case HatchPatternType.Custom:
                        PatternType = HatchPatternType.Custom;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    continue;

                // Pattern Angle
                case HatchCodes.HatchPatternAngle:
                    PatternAngle = double.Parse(currentData.Value);
                    continue;

                // Pattern Scale
                case HatchCodes.HatchPatternScale:
                    PatternScale = double.Parse(currentData.Value);
                    continue;

                // Parsing the Boundary Data
                case HatchCodes.NumberOfEdgesInBoundary:
                    BoundaryEdgesCount = int.Parse(currentData.Value);

                    // If the polyline is associative then continue
                    if (AssociativityFlag)
                    {
                        continue;
                    }

                    // Set the boundary
                    Boundary = ParseBoundary(list, ref currentIndex);

                    // Throw an exception if the number of objects does not match
                    // what the file is saying
                    if (Boundary.SectionCount != BoundaryEdgesCount)
                    {
                        throw new DxfParseException(
                                  "Boundary Objects count do not match the file");
                    }
                    continue;

                // Source Objects count
                case HatchCodes.SourceObjectsCount:
                    SourceObjectsCount  = int.Parse(currentData.Value);
                    EntityReferenceList = new List <string>(SourceObjectsCount);
                    break;

                // Source Object SoftPointers
                case GroupCodesBase.SoftPointer:
                    if (SourceObjectsCount > 0)
                    {
                        EntityReferenceList.Add(currentData.Value);
                    }
                    break;

                // The default case
                default:
                    continue;
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        /// <summary>
        ///     The <see cref="T:Dxflib.Entities.Text.TextBuffer" /> Parse Function
        /// </summary>
        /// <param name="list"><see cref="T:Dxflib.IO.TaggedDataList" /> list</param>
        /// <param name="index">The current index of extraction</param>
        /// <returns>Always True</returns>
        public override bool Parse(TaggedDataList list, int index)
        {
            for (var currentIndex = index + 1; currentIndex < list.Length; ++currentIndex)
            {
                var currentData = list.GetPair(currentIndex);

                if (currentData.GroupCode == GroupCodesBase.EntityType)
                {
                    break;
                }

                if (base.Parse(list, currentIndex))
                {
                    continue;
                }

                switch (currentData.GroupCode)
                {
                case GroupCodesBase.XPoint:
                    PositionVertex.X = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.YPoint:
                    PositionVertex.Y = double.Parse(currentData.Value);
                    continue;

                case GroupCodesBase.ZPoint:
                    PositionVertex.Z = double.Parse(currentData.Value);
                    continue;

                case TextCodes.TextHeight:
                    Height = double.Parse(currentData.Value);
                    continue;

                case TextCodes.TextString:
                    Contents = currentData.Value;
                    continue;

                case TextCodes.TextRotation:
                    Rotation = double.Parse(currentData.Value);
                    continue;

                case TextCodes.RelativeXScale:
                    WidthFactor = double.Parse(currentData.Value);
                    continue;

                case TextCodes.ObliqueAngle:
                    Obliquing = double.Parse(currentData.Value);
                    continue;

                case TextCodes.TextStyleName:
                    TextStyle.Name = currentData.Value;
                    continue;

                case TextCodes.HorizontalJustification:
                    _horizontalJustify = int.Parse(currentData.Value);
                    continue;

                case TextCodes.VerticalJustification:
                    _verticalJustify = int.Parse(currentData.Value);
                    continue;

                case TextCodes.TextGenerationFlag:
                    var value = int.Parse(currentData.Value);
                    switch (value)
                    {
                    case 2:
                        IsBackwards = true;
                        break;

                    case 4:
                        IsUpsideDown = true;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    continue;

                default:
                    continue;
                }
            }

            Justify = GetJustification(_horizontalJustify, _verticalJustify);
            return(true);
        }