示例#1
0
 /// <summary>
 /// Create an instance of <see cref="Entity"/> using a template.
 /// </summary>
 /// <param name="template"></param>
 internal Entity(DxfEntityTemplate template)
 {
     Handle      = template.Handle;
     OwnerHandle = template.OwnerHandle;
     Layer       = template.Layer;
     Color       = template.Color;
     Lineweight  = template.Lineweight;
 }
示例#2
0
        private PolyLine readPolyline(DxfEntityTemplate template)
        {
            PolyLine polyline = new PolyLine(template);

            //Pre-declare structures
            XYZ normal = XYZ.Zero = XYZ.AxisZ;

            while (m_reader.LastDxfCode != DxfCode.Start)
            {
            }

            polyline.Normal = normal;

            return(polyline);
        }
示例#3
0
        private Hatch readHatch(DxfEntityTemplate template)
        {
            Hatch hatch = new Hatch(template);

            //Pre-declare structures
            XYZ normal = XYZ.Zero = XYZ.AxisZ;

            while (m_reader.LastDxfCode != DxfCode.Start)
            {
            }

            hatch.Normal = normal;

            return(hatch);
        }
示例#4
0
 internal Hatch(DxfEntityTemplate template) : base(template)
 {
 }
示例#5
0
 internal Point(DxfEntityTemplate template) : base(template)
 {
 }
示例#6
0
 internal MText(DxfEntityTemplate template) : base(template)
 {
 }
示例#7
0
 internal Insert(DxfEntityTemplate template) : base(template)
 {
 }
示例#8
0
 internal Attribute(DxfEntityTemplate template) : base(template)
 {
 }
示例#9
0
 internal AttributeDefinition(DxfEntityTemplate template) : base(template)
 {
 }
示例#10
0
 internal Ellipse(DxfEntityTemplate template) : base(template)
 {
 }
示例#11
0
        private Circle readCircle(DxfEntityTemplate template)
        {
            Circle circle = new Circle(template);

            //Pre-declare structures
            XYZ center = XYZ.Zero;
            XYZ normal = XYZ.Zero = XYZ.AxisZ;

            while (m_reader.LastDxfCode != DxfCode.Start)
            {
                switch (m_reader.LastCode)
                {
                //Subclass marker (AcDbCircle)
                case 100:
                    Debug.Assert(m_reader.LastValueAsString == "AcDbCircle");
                    break;

                //Thickness (optional; default = 0)
                case 39:
                    circle.Thickness = m_reader.LastValueAsDouble;
                    break;

                //Center point (in OCS)
                //DXF: X value; APP: 3D point
                case 10:
                    center.X = m_reader.LastValueAsDouble;
                    break;

                //DXF: Y and Z values of center point (in OCS)
                case 20:
                    center.Y = m_reader.LastValueAsDouble;
                    break;

                case 30:
                    center.Z = m_reader.LastValueAsDouble;
                    break;

                //Radius
                case 40:
                    circle.Radius = m_reader.LastValueAsDouble;
                    break;

                //Extrusion direction (optional; default = 0, 0, 1)
                //DXF: X value; APP: 3D vector
                case 210:
                    normal.X = m_reader.LastValueAsDouble;
                    break;

                //DXF: Y and Z values of extrusion direction (optional)
                case 220:
                    normal.Y = m_reader.LastValueAsDouble;
                    break;

                case 230:
                    normal.Z = m_reader.LastValueAsDouble;
                    break;

                default:
                    Debug.Fail($"Unhandeled dxf code {m_reader.LastCode} at line {m_reader.Line}.");
                    break;
                }

                m_reader.ReadNext();
            }

            circle.Center = center;
            circle.Normal = normal;

            return(circle);
        }
示例#12
0
        private Arc readArc(DxfEntityTemplate template)
        {
            //Create the arc based on the template
            Arc arc = new Arc(template);

            //Pre-declare structures
            XYZ center = XYZ.Zero;
            XYZ normal = XYZ.Zero = XYZ.AxisZ;

            while (m_reader.LastDxfCode != DxfCode.Start)
            {
                switch (m_reader.LastCode)
                {
                //Subclass marker (AcDbCircle)
                //Subclass marker (AcDbArc)
                case 100:
                    Debug.Assert(m_reader.LastValueAsString == "AcDbArc" || m_reader.LastValueAsString == "AcDbCircle");
                    break;

                //Thickness (optional; default = 0)
                case 39:
                    arc.Thickness = m_reader.LastValueAsDouble;
                    break;

                //Center point (in OCS)
                //DXF: X value; APP: 3D point
                case 10:
                    center.X = m_reader.LastValueAsDouble;
                    break;

                //DXF: Y and Z values of center point (in OCS)
                case 20:
                    center.Y = m_reader.LastValueAsDouble;
                    break;

                case 30:
                    center.Z = m_reader.LastValueAsDouble;
                    break;

                //Radius
                case 40:
                    arc.Radius = m_reader.LastValueAsDouble;
                    break;

                //Start angle
                case 50:
                    arc.StartAngle = m_reader.LastValueAsDouble;
                    break;

                //End angle
                case 51:
                    arc.EndAngle = m_reader.LastValueAsDouble;
                    break;

                //Extrusion direction (optional; default = 0, 0, 1)
                //DXF: X value; APP: 3D vector
                case 210:
                    normal.X = m_reader.LastValueAsDouble;
                    break;

                //DXF: Y and Z values of extrusion direction (optional)
                case 220:
                    normal.Y = m_reader.LastValueAsDouble;
                    break;

                case 230:
                    normal.Z = m_reader.LastValueAsDouble;
                    break;

                default:
                    Debug.Fail($"Unhandeled dxf code {m_reader.LastCode} at line {m_reader.Line}.");
                    break;
                }

                m_reader.ReadNext();
            }

            //Assign the structures
            arc.Center = center;
            arc.Normal = normal;

            return(arc);
        }
示例#13
0
        /// <summary>
        /// Reflection method to read entities.
        /// </summary>
        /// <remarks>
        /// Is functional but not very reliable so it should disapear in the future and have a method for each entity.
        /// </remarks>
        /// <param name="template"></param>
        /// <returns></returns>
        private Entity readEntity(DxfEntityTemplate template)
        {
            Entity entity = null;

            //Get the current entity
            switch (template.EntityName)
            {
            //TODO: Check the SubclassMarker
            case DxfFileToken.EntityArc:
                entity = new Arc(template);
                break;

            case DxfFileToken.EntityCircle:
                entity = new Circle(template);
                break;

            case DxfFileToken.EntityPolyline:
                entity = new PolyLine(template);
                break;

            case DxfFileToken.EntityText:
                entity = new Text(template);
                break;

            case DxfFileToken.EntityVertex:
                entity = new Vertex(template);
                break;

            case DxfFileToken.EntityAttributeDefinition:
                Debug.Fail("Check the property VerticalJustification and see the assigned code, should be 74");
                entity = new AttributeDefinition(template);
                break;

            default:
                //Debug.Fail($"Unhandeled entity {template.EntityName}.");
                break;
            }

            //Jump the SubclassMarker
            m_reader.ReadNext();

            Dictionary <DxfCode, object> map = entity?.GetCadObjectMap() ?? new Dictionary <DxfCode, object>();

            while (m_reader.LastValueAsString != DxfFileToken.EndSection)
            {
                if (m_reader.LastDxfCode == DxfCode.Start)
                {
                    //Check if the entity has children in it
                    Dictionary <string, PropertyInfo> subEntity = entity?.GetSubEntitiesMap() ?? new Dictionary <string, PropertyInfo>();

                    if (!subEntity.ContainsKey(m_reader.LastValueAsString))
                    {
                        //Is a separated entity
                        break;
                    }

                    //Read the sequence
                    while (m_reader.LastValueAsString != DxfFileToken.EndSequence)
                    {
                        Entity child = this.readEntity();

                        PropertyInfo prop = subEntity[child.ObjectName];

                        if (prop.GetValue(entity, null) is ICollection <Entity> pvalue)
                        {
                            pvalue.Add(child);
                        }
                        else
                        {
                            //Will be used for something??
                            Debug.Fail("");
                            prop.SetValue(entity, child);
                        }
                    }

                    //Read the end of sequence
                    m_reader.ReadNext();
                    while (m_reader.LastDxfCode != DxfCode.Start)
                    {
                        m_reader.ReadNext();
                    }

                    //The end of the sequence is the end of the entity
                    break;
                }
                else if (map.ContainsKey(m_reader.LastDxfCode))
                {
                    //Set the value
                    map[m_reader.LastDxfCode] = m_reader.LastValue;
                }

                //Get the next line
                m_reader.ReadNext();
            }

            //Build the entity based on the map
            entity?.Build(map);

            return(entity);
        }
示例#14
0
        private Entity readEntity()
        {
            //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-3610039E-27D1-4E23-B6D3-7E60B22BB5BD

            DxfEntityTemplate template = new DxfEntityTemplate();

            //Loop until the common data
            while (m_reader.LastDxfCode != DxfCode.Subclass)
            {
                switch (m_reader.LastCode)
                {
                //APP: entity name(changes each time a drawing is opened)
                case -1:
                    break;

                //Entity type
                case 0:
                    template.EntityName = m_reader.LastValueAsString;
                    break;

                //Handle
                case 5:
                    template.Handle = m_reader.LastValueAsHandle;
                    break;

                //Start of application - defined group
                case 102:
                    //TODO: read dictionary groups for entities
                    while (m_reader.LastDxfCode != DxfCode.ControlString)
                    {
                        m_reader.ReadNext();
                    }
                    break;

                //Soft - pointer ID / handle to owner BLOCK_RECORD object
                case 330:
                    template.OwnerHandle = m_reader.LastValueAsHandle;
                    break;

                default:
                    //Debug.Fail($"Unhandeled dxf code {m_reader.LastCode} at line {m_reader.Line}.");
                    break;
                }

                //Get the next code/value
                m_reader.ReadNext();
            }

            //Get the subclass common entity data
            Debug.Assert(m_reader.LastValueAsString == DxfSubclassMarker.Entity);
            m_reader.ReadNext();

            while (m_reader.LastDxfCode != DxfCode.Subclass)
            {
                switch (m_reader.LastCode)
                {
                //Absent or zero indicates entity is in model space. 1 indicates entity is in paper space (optional).
                case 67:
                    break;

                //APP: layout tab name
                case 410:
                    break;

                //Layer name
                case 8:
                    //TODO: Create a link with the file layers
                    template.Layer = new Layer(m_reader.LastValueAsString);
                    break;

                //Linetype name(present if not BYLAYER). The special name BYBLOCK indicates a floating linetype(optional)
                case 6:
                    break;

                //Hard - pointer ID / handle to material object(present if not BYLAYER)
                case 347:
                    break;

                //Color number(present if not BYLAYER); zero indicates the BYBLOCK(floating) color; 256 indicates BYLAYER; a negative value indicates that the layer is turned off (optional)
                case 62:

                    break;

                //Lineweight enum value. Stored and moved around as a 16-bit integer.
                case 370:
                    template.Lineweight = (Lineweight)m_reader.LastValueAsShort;
                    break;

                //Linetype scale (optional)
                case 48:
                    template.LinetypeScale = m_reader.LastValueAsDouble;
                    break;

                //Object visibility (optional)
                case 60:
                    template.IsInvisible = m_reader.LastValueAsBool;
                    break;

                //Number of bytes in the proxy entity graphics represented in the subsequent 310 groups, which are binary chunk records (optional)
                case 92:
                    break;

                //Proxy entity graphics data (multiple lines; 256 characters max. per line) (optional)
                case 310:
                    break;

                //A 24 - bit color value that should be dealt with in terms of bytes with values of 0 to 255.The lowest byte is the blue value, the middle byte is the green value, and the third byte is the red value.The top byte is always 0.The group code cannot be used by custom entities for their own data because the group code is reserved for AcDbEntity, class-level color data and AcDbEntity, class-level transparency data
                case 420:
                    break;

                //Color name. The group code cannot be used by custom entities for their own data because the group code is reserved for AcDbEntity, class-level color data and AcDbEntity, class-level transparency data
                case 430:
                    break;

                //Transparency value. The group code cannot be used by custom entities for their own data because the group code is reserved for AcDbEntity, class-level color data and AcDbEntity, class-level transparency data
                case 440:
                    template.Transparency = new Transparency(m_reader.LastValueAsShort);
                    break;

                //Hard-pointer ID/handle to the plot style object
                case 390:
                    break;

                //Shadow mode
                case 284:
                    break;

                default:
                    //Debug.Fail($"Unhandeled dxf code {m_reader.LastCode} at line {m_reader.Line}.");
                    break;
                }

                //Get the next code/value
                m_reader.ReadNext();
            }

            Entity entity = null;

            switch (template.EntityName)
            {
            case DxfFileToken.EntityArc:
                entity = readArc(template);
                break;

            case DxfFileToken.EntityCircle:
                entity = readCircle(template);
                break;

            case DxfFileToken.EntityPolyline:
            //	entity = readPolyline(template);
            //	break;
            //case DxfFileToken.EntityText:
            //	entity = readText(template);
            //	break;
            default:
                entity = readEntity(template);
                //Debug.Fail($"Unhandeled entity {template.EntityName}.");
                break;
            }

            return(entity);
        }
示例#15
0
 internal Solid3D(DxfEntityTemplate template) : base(template)
 {
 }
示例#16
0
 internal Vertex(DxfEntityTemplate template) : base(template)
 {
 }
示例#17
0
文件: Arc.cs 项目: lanicon/ACadSharp
 internal Arc(DxfEntityTemplate template) : base(template)
 {
 }
示例#18
0
 internal PolyLine(DxfEntityTemplate template) : base(template)
 {
 }
示例#19
0
 internal Circle(DxfEntityTemplate template) : base(template)
 {
 }
示例#20
0
 internal Face3D(DxfEntityTemplate template) : base(template)
 {
 }
示例#21
0
 internal TextEntity(DxfEntityTemplate template) : base(template)
 {
 }
示例#22
0
        private Text readText(DxfEntityTemplate template)
        {
            //https://help.autodesk.com/view/OARX/2021/ENU/?guid=GUID-62E5383D-8A14-47B4-BFC4-35824CAE8363

            //Create the arc based on the template
            Text text = new Text(template);

            //Pre-declare structures
            XYZ firstAlignmentPoint  = XYZ.Zero;
            XYZ secondAlignmentPoint = XYZ.Zero;
            XYZ normal = XYZ.Zero = XYZ.AxisZ;

            while (m_reader.LastDxfCode != DxfCode.Start)
            {
                switch (m_reader.LastCode)
                {
                //Subclass marker(AcDbText)
                case 100:
                    Debug.Assert(m_reader.LastValueAsString == "AcDbText");
                    break;

                //Thickness(optional; default = 0)
                case 39:
                    text.Thickness = m_reader.LastValueAsDouble;
                    break;

                //First alignment point (in OCS)
                //DXF: X value; APP: 3D point
                case 10:
                    firstAlignmentPoint.X = m_reader.LastValueAsDouble;
                    break;

                //DXF: Y and Z values of center point (in OCS)
                case 20:
                    firstAlignmentPoint.Y = m_reader.LastValueAsDouble;
                    break;

                case 30:
                    firstAlignmentPoint.Z = m_reader.LastValueAsDouble;
                    break;

                //Text height
                case 40:
                    text.Height = m_reader.LastValueAsDouble;
                    break;

                //Default value(the string itself)
                case 1:
                    text.Value = m_reader.LastValueAsString;
                    break;

                //Text rotation (optional; default = 0)
                case 50:
                    text.Rotation = m_reader.LastValueAsDouble;
                    break;

                default:
                    //Debug.Fail($"Unhandeled dxf code {m_reader.LastCode} at line {m_reader.Line}.");
                    break;
                }

                m_reader.ReadNext();
            }

            return(null);
        }