public Polyline(EntityObject entity)
                : base(EdgeType.Polyline)
            {
                if (entity == null) throw new ArgumentNullException(nameof(entity));
                if (entity.Type == EntityType.LightWeightPolyline)
                {
                    Entities.LwPolyline poly = (Entities.LwPolyline)entity;
                    if (!poly.IsClosed) throw new ArgumentException("Only closed polyline are supported as hatch boundary edges.", nameof(entity));

                    this.Vertexes = new Vector3[poly.Vertexes.Count];
                    for (int i = 0; i < poly.Vertexes.Count; i++)
                    {
                        this.Vertexes[i] = new Vector3(poly.Vertexes[i].Position.X, poly.Vertexes[i].Position.Y, poly.Vertexes[i].Bulge);
                    }
                    this.IsClosed = true;
                }
                else if (entity.Type == EntityType.Polyline)
                {
                    Entities.Polyline poly = (Entities.Polyline)entity;
                    if (!poly.IsClosed) throw new ArgumentException("Only closed polyline are supported as hatch boundary edges.", nameof(entity));

                    this.Vertexes = new Vector3[poly.Vertexes.Count];
                    for (int i = 0; i < poly.Vertexes.Count; i++)
                    {
                        this.Vertexes[i] = new Vector3(poly.Vertexes[i].Position.X, poly.Vertexes[i].Position.Y, 0.0);
                    }
                    this.IsClosed = true;
                }
                else
                    throw new ArgumentException("The entity is not a LwPolyline or a Polyline", nameof(entity));               
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Extract and convert geometry attributes from the netDXF entity
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public static GeometryAttributes ExtractAttributes(netDxf.Entities.EntityObject entity)
 {
     AciColor color = entity.Color;
     if (color == null || color.IsByLayer) color = entity.Layer?.Color;
     return new GeometryAttributes(
         entity.Handle, 
         entity.Layer?.Name,
         new ColourBrush(Convert(color)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Set the display and other attributes of a netDXF entity from those of an Nucleus object
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="attributes"></param>
 public static void SetAttributes(nDE.EntityObject entity, GeometryAttributes attributes)
 {
     if (attributes != null)
     {
         if (attributes.Brush != null)
         {
             entity.Color = Convert(attributes.Brush.BaseColour);
         }
     }
 }
Ejemplo n.º 4
0
 private EntityObject ExportEllipse(GeoObject.Ellipse elli)
 {
     netDxf.Entities.EntityObject entity = null;
     if (elli.IsArc)
     {
         Plane dxfPlane;
         if (elli.CounterClockWise)
         {
             dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(elli.Plane.Normal));
         }
         else
         {
             dxfPlane = Import.Plane(Vector3(elli.Center), Vector3(-elli.Plane.Normal));
         }
         if (elli.IsCircle)
         {
             GeoObject.Ellipse aligned = GeoObject.Ellipse.Construct();
             aligned.SetArcPlaneCenterStartEndPoint(dxfPlane, dxfPlane.Project(elli.Center), dxfPlane.Project(elli.StartPoint), dxfPlane.Project(elli.EndPoint), dxfPlane, true);
             entity        = new netDxf.Entities.Arc(Vector3(aligned.Center), aligned.Radius, aligned.StartParameter / Math.PI * 180, (aligned.StartParameter + aligned.SweepParameter) / Math.PI * 180);
             entity.Normal = Vector3(dxfPlane.Normal);
         }
         else
         {
             netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius);
             entity        = expelli;
             entity.Normal = Vector3(elli.Plane.Normal);
             Plane       cdbplane = elli.Plane;
             GeoVector2D dir      = dxfPlane.Project(cdbplane.DirectionX);
             SweepAngle  rot      = new SweepAngle(GeoVector2D.XAxis, dir);
             expelli.Rotation = rot.Degree;
             SetEllipseParameters(expelli, elli.StartParameter, elli.StartParameter + elli.SweepParameter);
         }
     }
     else
     {
         if (elli.IsCircle)
         {
             entity        = new netDxf.Entities.Circle(Vector3(elli.Center), elli.Radius);
             entity.Normal = Vector3(elli.Plane.Normal);
         }
         else
         {
             netDxf.Entities.Ellipse expelli = new netDxf.Entities.Ellipse(Vector3(elli.Center), 2 * elli.MajorRadius, 2 * elli.MinorRadius);
             entity        = expelli;
             entity.Normal = Vector3(elli.Plane.Normal);
             Plane       dxfplane = Import.Plane(expelli.Center, expelli.Normal); // this plane is not correct, it has to be rotated
             Plane       cdbplane = elli.Plane;
             GeoVector2D dir      = dxfplane.Project(cdbplane.DirectionX);
             SweepAngle  rot      = new SweepAngle(GeoVector2D.XAxis, dir);
             expelli.Rotation = rot.Degree;
         }
     }
     return(entity);
 }
Ejemplo n.º 5
0
        private void SetUserData(netDxf.Entities.EntityObject entity, IGeoObject go)
        {
            if (entity is null || go is null || go.UserData is null || go.UserData.Count == 0)
            {
                return;
            }

            foreach (KeyValuePair <string, object> de in go.UserData)
            {
                if (de.Value is ExtendedEntityData xData)
                {
                    ApplicationRegistry registry = new ApplicationRegistry(xData.ApplicationName);
                    XData data = new XData(registry);

                    foreach (var item in xData.Data)
                    {
                        XDataCode   code   = item.Key;
                        XDataRecord record = new XDataRecord(code, item.Value);
                        data.XDataRecord.Add(record);
                    }

                    entity.XData.Add(data);
                }
                else
                {
                    ApplicationRegistry registry = new ApplicationRegistry(ApplicationRegistry.DefaultName);
                    XData data = new XData(registry);

                    XDataRecord record = null;

                    //TODO: Add more types
                    if (de.Value is string strValue)
                    {
                        record = new XDataRecord(XDataCode.String, strValue);
                    }
                    else if (de.Value is short shrValue)
                    {
                        record = new XDataRecord(XDataCode.Int16, shrValue);
                    }
                    else if (de.Value is int intValue)
                    {
                        record = new XDataRecord(XDataCode.Int32, intValue);
                    }

                    if (record != null)
                    {
                        data.XDataRecord.Add(record);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Convert a netDXF entity to a Nucleus geometry object
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public static VertexGeometry Convert(nDE.EntityObject entity)
 {
     if (entity is nDE.Point) return Convert((nDE.Point)entity);
     else if (entity is nDE.Line) return Convert((nDE.Line)entity);
     else if (entity is nDE.Arc) return Convert((nDE.Arc)entity);
     else if (entity is nDE.Circle) return Convert((nDE.Circle)entity);
     else if (entity is nDE.LwPolyline) return Convert((nDE.LwPolyline)entity);
     else if (entity is nDE.Polyline) return Convert((nDE.Polyline)entity);
     else if (entity is nDE.Spline) return Convert((nDE.Spline)entity);
     else if (entity is nDE.Text) return Convert((nDE.Text)entity);
     else if (entity is nDE.MText) return Convert((nDE.MText)entity);
     else if (entity is nDE.Mesh) return Convert((nDE.Mesh)entity);
     else if (entity is nDE.PolyfaceMesh) return Convert((nDE.PolyfaceMesh)entity);
     else return null;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Convert a netDXF entity to a Nucleus geometry object
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public static VertexGeometry Convert(nDE.EntityObject entity)
 {
     if (entity is nDE.Point)
     {
         return(Convert((nDE.Point)entity));
     }
     else if (entity is nDE.Line)
     {
         return(Convert((nDE.Line)entity));
     }
     else if (entity is nDE.Arc)
     {
         return(Convert((nDE.Arc)entity));
     }
     else if (entity is nDE.Circle)
     {
         return(Convert((nDE.Circle)entity));
     }
     else if (entity is nDE.LwPolyline)
     {
         return(Convert((nDE.LwPolyline)entity));
     }
     else if (entity is nDE.Polyline)
     {
         return(Convert((nDE.Polyline)entity));
     }
     else if (entity is nDE.Spline)
     {
         return(Convert((nDE.Spline)entity));
     }
     else if (entity is nDE.Text)
     {
         return(Convert((nDE.Text)entity));
     }
     else if (entity is nDE.MText)
     {
         return(Convert((nDE.MText)entity));
     }
     else if (entity is nDE.Mesh)
     {
         return(Convert((nDE.Mesh)entity));
     }
     else
     {
         return(null);
     }
 }
        public static void Entity2Shape(netDxf.Entities.EntityObject xEntity, System.Windows.Shapes.Shape wShape)
        {
            double dThickness = xEntity.getLineweightValue();
            double dScale     = xEntity.LinetypeScale;

            /* By Block */
            if (dThickness == -2)
            {
                dThickness = xEntity.Owner.Layer.getLineweightValue();
            }
            if (dScale == -2)
            {
                dScale = 1;
            }


            /* By Default */
            if (dThickness == -3)
            {
                dThickness = defaultThickness;
            }
            if (dScale == -3)
            {
                dScale = 1;
            }

            /*Debug.WriteLine("dThickness="+dThickness);*/
            /*Debug.WriteLine("dThickness="+dThickness+" dScale="+dScale);*/

            wShape.StrokeThickness = (dThickness > 0) ? dThickness * dScale * 3.4 : 0.1;

            DoubleCollection myCollec = new DoubleCollection(xEntity.Linetype.Segments.ToArray());

            wShape.StrokeDashArray = myCollec;

            AciColor myColor = xEntity.getColor();

            wShape.Stroke = new SolidColorBrush(TypeConverter.ToMediaColor(myColor.ToColor()));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of <c>EntityCollectionEventArgs</c>.
 /// </summary>
 /// <param name="item">Item that is being added or removed from the collection.</param>
 public EntityCollectionEventArgs(EntityObject item)
 {
     this.item = item;
     this.cancel = false;
 }
Ejemplo n.º 10
0
        private void WriteEntityCommonCodes(EntityObject entity, Layout layout)
        {
            this.chunk.Write(0, entity.CodeName);
            this.chunk.Write(5, entity.Handle);

            if (entity.Reactors.Count > 0)
            {
                this.chunk.Write(102, "{ACAD_REACTORS");
                foreach (DxfObject o in entity.Reactors)
                {
                    this.chunk.Write(330, o.Handle);
                }               
                this.chunk.Write(102, "}");
            }

            this.chunk.Write(330, entity.Owner.Record.Handle);

            this.chunk.Write(100, SubclassMarker.Entity);

            if (layout != null)
                this.chunk.Write(67, layout.IsPaperSpace ? (short) 1 : (short) 0);

            this.chunk.Write(8, this.EncodeNonAsciiCharacters(entity.Layer.Name));

            this.chunk.Write(62, entity.Color.Index);
            if (entity.Color.UseTrueColor)
                this.chunk.Write(420, AciColor.ToTrueColor(entity.Color));

            if (entity.Transparency.Value >= 0)
                this.chunk.Write(440, Transparency.ToAlphaValue(entity.Transparency));

            this.chunk.Write(6, this.EncodeNonAsciiCharacters(entity.LineType.Name));

            this.chunk.Write(370, entity.Lineweight.Value);
            this.chunk.Write(48, entity.LineTypeScale);
            this.chunk.Write(60, entity.IsVisible ? (short) 0 : (short) 1);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Removes an <see cref="EntityObject">entity</see> from the document.
 /// </summary>
 /// <param name="entity">The <see cref="EntityObject">entity</see> to remove from the document.</param>
 /// <returns>True if item is successfully removed; otherwise, false. This method also returns false if item was not found.</returns>
 /// <remarks>
 /// This function will not remove other tables objects that might be not in use as result from the elimination of the entity.<br />
 /// This includes empty layers, blocks not referenced anymore, line types, text styles, dimension styles, multiline styles, groups, and application registries.<br />
 /// Entities that are part of a block definition will not be removed.
 /// </remarks>
 public bool RemoveEntity(EntityObject entity)
 {
     return this.RemoveEntity(entity, false);
 }
 internal void AddContour(EntityObject entity)
 {
     this.contour.Add(entity);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Explodes the current insert.
        /// </summary>
        /// <returns>A list of entities.</returns>
        public List <EntityObject> Explode()
        {
            List <EntityObject> entities       = new List <EntityObject>();
            Matrix3             transformation = this.GetTransformation();
            Vector3             translation    = this.Position - transformation * this.block.Origin;

            foreach (EntityObject entity in this.block.Entities)
            {
                Vector3 localScale     = MathHelper.Transform(this.Scale, entity.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                bool    isUniformScale = MathHelper.IsEqual(localScale.X, localScale.Y);

                // entities with reactors are associated with other entities they will handle the transformation
                if (entity.Reactors.Count > 0)
                {
                    continue;
                }

                if (!isUniformScale)
                {
                    switch (entity.Type)
                    {
                    case EntityType.Circle:
                    {
                        Circle  circle  = (Circle)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center    = circle.Center,
                            MajorAxis = 2 * circle.Radius,
                            MinorAxis = 2 * circle.Radius,
                            Thickness = circle.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.Arc:
                    {
                        Arc     arc     = (Arc)entity;
                        Ellipse ellipse = new Ellipse
                        {
                            //EntityObject properties
                            Layer         = (Layer)entity.Layer.Clone(),
                            Linetype      = (Linetype)entity.Linetype.Clone(),
                            Color         = (AciColor)entity.Color.Clone(),
                            Lineweight    = entity.Lineweight,
                            Transparency  = (Transparency)entity.Transparency.Clone(),
                            LinetypeScale = entity.LinetypeScale,
                            Normal        = entity.Normal,
                            IsVisible     = entity.IsVisible,
                            //Ellipse properties
                            Center     = arc.Center,
                            MajorAxis  = 2 * arc.Radius,
                            MinorAxis  = 2 * arc.Radius,
                            StartAngle = arc.StartAngle,
                            EndAngle   = arc.EndAngle,
                            Thickness  = arc.Thickness
                        };

                        ellipse.TransformBy(transformation, translation);
                        entities.Add(ellipse);
                        break;
                    }

                    case EntityType.LwPolyline:
                    {
                        List <EntityObject> newEntities = ((LwPolyline)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    case EntityType.MLine:
                    {
                        List <EntityObject> newEntities = ((MLine)entity).Explode();
                        foreach (EntityObject newEntity in newEntities)
                        {
                            if (newEntity.Type == EntityType.Arc)
                            {
                                Arc     arc     = (Arc)newEntity;
                                Ellipse ellipse = new Ellipse
                                {
                                    //EntityObject properties
                                    Layer         = (Layer)entity.Layer.Clone(),
                                    Linetype      = (Linetype)entity.Linetype.Clone(),
                                    Color         = (AciColor)entity.Color.Clone(),
                                    Lineweight    = entity.Lineweight,
                                    Transparency  = (Transparency)entity.Transparency.Clone(),
                                    LinetypeScale = entity.LinetypeScale,
                                    Normal        = entity.Normal,
                                    IsVisible     = entity.IsVisible,
                                    //Ellipse properties
                                    Center     = arc.Center,
                                    MajorAxis  = 2 * arc.Radius,
                                    MinorAxis  = 2 * arc.Radius,
                                    StartAngle = arc.StartAngle,
                                    EndAngle   = arc.EndAngle,
                                    Thickness  = arc.Thickness
                                };

                                ellipse.TransformBy(transformation, translation);
                                entities.Add(ellipse);
                            }
                            else
                            {
                                newEntity.TransformBy(transformation, translation);
                                entities.Add(newEntity);
                            }
                        }
                        break;
                    }

                    default:
                    {
                        EntityObject newEntity = (EntityObject)entity.Clone();
                        newEntity.TransformBy(transformation, translation);
                        entities.Add(newEntity);
                        break;
                    }
                    }
                }
                else
                {
                    EntityObject newEntity = (EntityObject)entity.Clone();
                    newEntity.TransformBy(transformation, translation);
                    entities.Add(newEntity);
                }
            }

            foreach (Attribute attribute in this.attributes)
            {
                // the attributes will be exploded as a Text entity
                Text text = new Text
                {
                    //Attribute properties
                    Layer         = (Layer)attribute.Layer.Clone(),
                    Linetype      = (Linetype)attribute.Linetype.Clone(),
                    Color         = (AciColor)attribute.Color.Clone(),
                    Lineweight    = attribute.Lineweight,
                    Transparency  = (Transparency)attribute.Transparency.Clone(),
                    LinetypeScale = attribute.LinetypeScale,
                    Normal        = attribute.Normal,
                    IsVisible     = attribute.IsVisible,
                    Height        = attribute.Height,
                    WidthFactor   = attribute.WidthFactor,
                    ObliqueAngle  = attribute.ObliqueAngle,
                    Value         = attribute.Value.ToString(),
                    Style         = (TextStyle)attribute.Style.Clone(),
                    Position      = attribute.Position,
                    Rotation      = attribute.Rotation,
                    Alignment     = attribute.Alignment,
                    IsBackward    = attribute.IsBackward,
                    IsUpsideDown  = attribute.IsUpsideDown
                };
                entities.Add(text);
            }

            return(entities);
        }
Ejemplo n.º 14
0
        private List<DimensionStyleOverride> ReadDimensionStyleOverrideXData(XData xDataOverrides, EntityObject entity)
        {
            List<DimensionStyleOverride> overrides = new List<DimensionStyleOverride>();
            IEnumerator<XDataRecord> records = xDataOverrides.XDataRecord.GetEnumerator();
            short dimzin = -1;
            short dimazin = -1;
            while (records.MoveNext())
            {
                XDataRecord data = records.Current;

                // the dimension style overrides are stored under the string "DSTYLE"
                if (data.Code == XDataCode.String && string.Equals((string) data.Value, "DSTYLE", StringComparison.OrdinalIgnoreCase))
                {
                    if (records.MoveNext())
                        data = records.Current;
                    else
                        return overrides; // premature end

                    // all style overrides are enclosed between XDataCode.ControlString "{" and "}"
                    if (data.Code != XDataCode.ControlString && (string) data.Value != "{")
                        return overrides; // premature end

                    if (records.MoveNext())
                        data = records.Current;
                    else
                        return overrides; // premature end

                    while (!(data.Code == XDataCode.ControlString && (string) data.Value == "}"))
                    {
                        if (data.Code != XDataCode.Int16)
                            return overrides;
                        short styleOverrideCode = (short) data.Value;
                        if (records.MoveNext())
                            data = records.Current;
                        else
                            return overrides; // premature end

                        // the xData overrides must be read in pairs.
                        // the first is the dimension style property to override, the second is the new value
                        switch (styleOverrideCode)
                        {
                            case 176: // DimensionStyleOverrideType.DIMCLRD:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 345: // DimensionStyleOverrideType.DIMLTYPE:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltype = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltype == null)
                                    dimltype = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineLinetype, dimltype));
                                break;

                            case 371: // DimensionStyleOverrideType.DIMLWD:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineLineweight, (Lineweight) (short) data.Value));
                                break;

                            case 46: // DimensionStyleOverrideType.DIMDLE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineExtend, (double) data.Value));
                                break;

                            case 177: // DimensionStyleOverrideType.DIMCLRE:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 346: // DimensionStyleOverrideType.DIMLTEX1:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltex1 = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltex1 == null)
                                    dimltex1 = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1Linetype, dimltex1));
                                break;

                            case 347: // DimensionStyleOverrideType.DIMLTEX2:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltex2 = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltex2 == null)
                                    dimltex2 = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2Linetype, dimltex2));
                                break;

                            case 372: // DimensionStyleOverrideType.DIMLWE:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineLineweight, (Lineweight) (short) data.Value));
                                break;

                            case 75: // DimensionStyleOverrideType.DIMSE1:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add((short) data.Value == 0
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1, false)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1, true));
                                break;

                            case 76: // DimensionStyleOverrideType.DIMSE2:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add((short) data.Value == 0
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2, false)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2, true));
                                break;

                            case 42: // DimensionStyleOverrideType.DIMEXO:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineOffset, (double) data.Value));
                                break;

                            case 44: // DimensionStyleOverrideType.DIMEXE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineExtend, (double) data.Value));
                                break;

                            case 41: // DimensionStyleOverrideType.DIMASZ:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ArrowSize, (double) data.Value));
                                break;

                            case 141: // DimensionStyleOverrideType.DIMCEN:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.CenterMarkSize, (double) data.Value));
                                break;

                            case 341: // DimensionStyleOverrideType.DIMLDRBLK:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimldrblk = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimldrblk == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.LeaderArrow, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.LeaderArrow, this.doc.Blocks[dimldrblk.Name]));
                                break;

                            case 343: // DimensionStyleOverrideType.DIMBLK1:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimblk1 = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimblk1 == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow1, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow1, this.doc.Blocks[dimblk1.Name]));
                                break;

                            case 344: // DimensionStyleOverrideType.DIMBLK2:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimblk2 = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimblk2 == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow2, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow2, this.doc.Blocks[dimblk2.Name]));
                                break;

                            case 340: // DimensionStyleOverrideType.DIMTXSTY:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                TextStyle dimtxtsty = this.doc.GetObjectByHandle((string) data.Value) as TextStyle;
                                if (dimtxtsty == null)
                                    dimtxtsty = this.doc.TextStyles[TextStyle.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextStyle, dimtxtsty));
                                break;

                            case 178: // DimensionStyleOverrideType.DIMCLRT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 140: // DimensionStyleOverrideType.DIMTXT:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextHeight, (double) data.Value));
                                break;

                            case 147: // DimensionStyleOverrideType.DIMGAP:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextOffset, (double) data.Value));
                                break;

                            case 40: // DimensionStyleOverrideType.DIMSCALE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimScaleOverall, (double) data.Value));
                                break;

                            case 179: // DimensionStyleOverrideType.DIMADEC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.AngularPrecision, (short) data.Value));
                                break;

                            case 271: // DimensionStyleOverrideType.DIMDEC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.LengthPrecision, (short) data.Value));
                                break;

                            case 3: // DimensionStyleOverrideType.DIMPOST:
                                if (data.Code != XDataCode.String)
                                    return overrides; // premature end
                                string dimpost = this.DecodeEncodedNonAsciiCharacters((string) data.Value);
                                string[] textPrefixSuffix = GetDimStylePrefixAndSuffix(dimpost);

                                if (!string.IsNullOrEmpty(textPrefixSuffix[0]))
                                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimPrefix, textPrefixSuffix[0]));
                                if (!string.IsNullOrEmpty(textPrefixSuffix[1]))
                                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimSuffix, textPrefixSuffix[1]));

                                break;

                            case 278: // DimensionStyleOverrideType.DIMDSEP:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DecimalSeparator, (char) (short) data.Value));
                                break;

                            case 144: // DimensionStyleOverrideType.DIMLFAC:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimScaleLinear, (double) data.Value));
                                break;

                            case 277: // DimensionStyleOverrideType.DIMLUNIT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLengthUnits, (LinearUnitType) (short) data.Value));
                                break;

                            case 275: // DimensionStyleOverrideType.DIMAUNIT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimAngularUnits, (AngleUnitType) (short) data.Value));
                                break;

                            case 276: // DimensionStyleOverrideType.DIMFRAC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.FractionalType, (FractionFormatType) (short) data.Value));
                                break;
                            case 78: // DIMZIN
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                dimzin = (short) data.Value;
                                break;

                            case 79: // DIMAZIN
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                dimazin = (short) data.Value;
                                break;

                            case 45: // DimensionStyleOverrideType.DIMRND:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimRoundoff, (short) data.Value));
                                break;
                            case 70: // this code is only required by Leader entities
                                Leader leader = entity as Leader;
                                if (leader == null)
                                    break;
                                leader.TextVerticalPosition = (LeaderTextVerticalPosition) (short) data.Value;
                                break;
                        }

                        if (records.MoveNext())
                            data = records.Current;
                        else
                            return overrides; // premature end
                    }
                }
            }

            if (dimzin >= 0)
            {
                // suppress leading and/or trailing zeros
                if (12 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, true));
                    dimzin -= 12;
                }
                else if (8 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, true));
                    dimzin -= 8;
                }
                else if (4 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, false));
                    dimzin -= 4;
                }
                else
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, false));
                }
                // suppress feet and/or inches
                switch (dimzin)
                {
                    case 0:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                    case 1:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, false));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, false));
                        break;
                    case 2:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, false));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                    case 3:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, false));
                        break;
                    default:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                }
            }

            // suppress angular leading and/or trailing zeros
            switch (dimazin)
            {
                case 0:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, false));
                    break;
                case 1:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, false));
                    break;
                case 2:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, true));
                    break;
                case 3:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, true));
                    break;
            }

            return overrides;
        }
Ejemplo n.º 15
0
        private void AddDimensionStyleOverridesXData(XDataDictionary xdata, DimensionStyleOverrideDictionary overrides, EntityObject entity)
        {
            XData xdataEntry;
            if (xdata.ContainsAppId(ApplicationRegistry.DefaultName))
            {
                xdataEntry = xdata[ApplicationRegistry.DefaultName];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
                xdata.Add(xdataEntry);
            }
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, "DSTYLE"));
            xdataEntry.XDataRecord.Add(XDataRecord.OpenControlString);
            bool writeDIMPOST = false;
            string prefix = string.Empty;
            string suffix = string.Empty;
            bool writeDIMSAH = false;
            bool writeDIMZIN = false;
            bool writeDIMAZIN = false;
            bool suppressLinearLeadingZeros = false;
            bool suppressLinearTrailingZeros = false;
            bool suppressAngularLeadingZeros = false;
            bool suppressAngularTrailingZeros = false;
            bool suppressZeroFeet = true;
            bool suppressZeroInches = true;
            foreach (DimensionStyleOverride styleOverride in overrides.Values)
            {
                switch (styleOverride.Type)
                {
                    case DimensionStyleOverrideType.DimLineColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 176));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.DimLineLinetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 345));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.DimLineLineweight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 371));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (Lineweight) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimLineExtend:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 46));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLineColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 177));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.ExtLine1Linetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 346));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.ExtLine2Linetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 347));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.ExtLineLineweight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 372));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (Lineweight) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLine1:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 75));
                        if ((bool) styleOverride.Value)
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
                        else
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 0));
                        break;
                    case DimensionStyleOverrideType.ExtLine2:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 76));
                        if ((bool) styleOverride.Value)
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
                        else
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 0));
                        break;
                    case DimensionStyleOverrideType.ExtLineOffset:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 42));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLineExtend:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 44));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ArrowSize:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 41));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.CenterMarkSize:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 141));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.LeaderArrow:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 341));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.DimArrow1:
                        writeDIMSAH = true;
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 343));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.DimArrow2:
                        writeDIMSAH = true;
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 344));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.TextStyle:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 340));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((TextStyle) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.TextColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 178));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.TextHeight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 140));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.TextOffset:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 147));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimScaleOverall:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 40));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.AngularPrecision:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 179));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.LengthPrecision:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 271));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimPrefix:
                        writeDIMPOST = true;
                        prefix = (string) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DimSuffix:
                        writeDIMPOST = true;
                        suffix = (string) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DecimalSeparator:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 278));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (char) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimScaleLinear:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 144));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimLengthUnits:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 277));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (LinearUnitType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimAngularUnits:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 275));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (AngleUnitType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.FractionalType:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 276));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (FractionFormatType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.SuppressZeroFeet:
                        writeDIMZIN = true;
                        suppressZeroFeet = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressZeroInches:
                        writeDIMZIN = true;
                        suppressZeroInches = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressLinearLeadingZeros:
                        writeDIMZIN = true;
                        suppressLinearLeadingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressLinearTrailingZeros:
                        writeDIMZIN = true;
                        suppressLinearTrailingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressAngularLeadingZeros:
                        writeDIMAZIN = true;
                        suppressAngularLeadingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressAngularTrailingZeros:
                        writeDIMAZIN = true;
                        suppressAngularTrailingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DimRoundoff:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 45));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                }
            }

            if (writeDIMSAH)
            {
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 173));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
            }

            if (writeDIMPOST)
            {
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 3));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, this.EncodeNonAsciiCharacters(string.Format("{0}<>{1}", prefix, suffix))));
            }

            if (writeDIMZIN)
            {
                short linSupress = 0;
                if (suppressZeroFeet && suppressZeroInches)
                    linSupress = 0;
                else if (!suppressZeroFeet && !suppressZeroInches)
                    linSupress += 1;
                else if (!suppressZeroFeet && suppressZeroInches)
                    linSupress += 2;
                else if (suppressZeroFeet && !suppressZeroInches)
                    linSupress += 3;

                if (!suppressLinearLeadingZeros && !suppressLinearTrailingZeros)
                    linSupress += 0;
                else if (suppressLinearLeadingZeros && !suppressLinearTrailingZeros)
                    linSupress += 4;
                else if (!suppressLinearLeadingZeros && suppressLinearTrailingZeros)
                    linSupress += 8;
                else if (suppressLinearLeadingZeros && suppressLinearTrailingZeros)
                    linSupress += 12;

                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 78));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, linSupress));
            }

            if (writeDIMAZIN)
            {
                short angSupress = 3;
                if (suppressAngularLeadingZeros && suppressAngularTrailingZeros)
                    angSupress = 3;
                else if (!suppressAngularLeadingZeros && !suppressAngularTrailingZeros)
                    angSupress = 0;
                else if (!suppressAngularLeadingZeros && suppressAngularTrailingZeros)
                    angSupress = 2;
                else if (suppressAngularLeadingZeros && !suppressAngularTrailingZeros)
                    angSupress = 1;

                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 79));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, angSupress));
            }

            // this information is only required by the Leader entity
            Leader leader = entity as Leader;
            if (leader != null)
            {
                MText mText = leader.Annotation as MText;
                if (mText != null)
                {
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 70));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) mText.AttachmentPoint));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 77));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) leader.TextVerticalPosition));
                }
            }

            xdataEntry.XDataRecord.Add(XDataRecord.CloseControlString);
        }
Ejemplo n.º 16
0
 protected virtual void OnEntityAddedEvent(EntityObject item)
 {
     EntityAddedEventHandler ae = this.EntityAdded;
     if (ae != null)
         ae(this, new GroupEntityChangeEventArgs(item));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a new Group that is a copy of the current instance.
 /// </summary>
 /// <param name="newName">Group name of the copy.</param>
 /// <returns>A new Group that is a copy of this instance.</returns>
 /// <remarks>The entities that belong to the group will also be cloned.</remarks>
 public override TableObject Clone(string newName)
 {
     EntityObject[] copy = new EntityObject[this.entities.Count];
     for (int i = 0; i < this.entities.Count; i++)
     {
         copy[i] = (EntityObject) this.entities[i].Clone();
     }
   
     return new Group(newName, copy)
     {
         Description = this.description,
         IsSelectable = this.isSelectable
     };
 }
Ejemplo n.º 18
0
 protected virtual void OnEntityRemovedEvent(EntityObject item)
 {
     EntityRemovedEventHandler ae = this.EntityRemoved;
     if (ae != null)
         ae(this, new BlockEntityChangeEventArgs(item));
 }
Ejemplo n.º 19
0
        private void AddStyleOverrides(EntityObject entity, bool assignHandle)
        {
            DimensionStyleOverrideDictionary overrides;
            switch (entity.Type)
            {
                case EntityType.Dimension:
                    overrides = ((Dimension) entity).StyleOverrides;
                    break;
                case EntityType.Leader:
                    overrides = ((Leader) entity).StyleOverrides;
                    break;
                default:
                    return;
            }

            // add the style override referenced DxfObjects
            DimensionStyleOverride styleOverride;

            // add referenced text style
            overrides.TryGetValue(DimensionStyleOverrideType.TextStyle, out styleOverride);
            if (styleOverride != null)
            {
                TextStyle dimtxtsty = (TextStyle) styleOverride.Value;
                overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.textStyles.Add(dimtxtsty, assignHandle));
                this.textStyles.References[dimtxtsty.Name].Add(entity);
            }

            // add referenced blocks
            overrides.TryGetValue(DimensionStyleOverrideType.LeaderArrow, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.blocks.Add(block, assignHandle));
                    this.blocks.References[block.Name].Add(entity);
                }
            }

            overrides.TryGetValue(DimensionStyleOverrideType.DimArrow1, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.blocks.Add(block, assignHandle));
                    this.blocks.References[block.Name].Add(entity);
                }
            }

            overrides.TryGetValue(DimensionStyleOverrideType.DimArrow2, out styleOverride);
            if (styleOverride != null)
            {
                Block block = (Block) styleOverride.Value;
                if (block != null)
                {
                    overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.blocks.Add(block, assignHandle));
                    this.blocks.References[block.Name].Add(entity);
                }
            }

            // add referenced line types
            overrides.TryGetValue(DimensionStyleOverrideType.DimLineLinetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.linetypes.Add(linetype, assignHandle));
                this.linetypes.References[linetype.Name].Add(entity);
            }

            overrides.TryGetValue(DimensionStyleOverrideType.ExtLine1Linetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.linetypes.Add(linetype, assignHandle));
                this.linetypes.References[linetype.Name].Add(entity);
            }

            overrides.TryGetValue(DimensionStyleOverrideType.ExtLine2Linetype, out styleOverride);
            if (styleOverride != null)
            {
                Linetype linetype = (Linetype) styleOverride.Value;
                overrides[styleOverride.Type] = new DimensionStyleOverride(styleOverride.Type, this.linetypes.Add(linetype, assignHandle));
                this.linetypes.References[linetype.Name].Add(entity);
            }
        }
Ejemplo n.º 20
0
 public Viewport(EntityObject clippingBoundary)
     : this(2)
 {
     this.ClippingBoundary = clippingBoundary;
 }
Ejemplo n.º 21
0
 void Entity_XDataRemoveAppReg(EntityObject sender, ObservableCollectionEventArgs<ApplicationRegistry> e)
 {
     this.appRegistries.References[e.Item.Name].Remove(sender);
 }
 internal bool RemoveContour(EntityObject entity)
 {
     return this.contour.Remove(entity);
 }
 /// <summary>
 /// Initializes a new instance of <c>EntityChangeEventArgs</c>.
 /// </summary>
 /// <param name="item">The entity that is being added or removed from another entity.</param>
 public EntityChangeEventArgs(EntityObject item)
 {
     this.item = item;
 }
Ejemplo n.º 24
0
        internal bool RemoveEntity(EntityObject entity, bool isBlockEntity)
        {
            if (entity == null)
                return false;

            if (entity.Handle == null)
                return false;

            if (entity.Owner == null)
                return false;

            if (entity.Reactors.Count > 0)
                return false;

            if (entity.Owner.Record.Layout == null)
                return false;

            if (!this.AddedObjects.ContainsKey(entity.Handle))
                return false;

            // the entities that are part of a block do not belong to any of the entities lists but to the block definition
            // and they will not be removed from the drawing database
            switch (entity.Type)
            {
                case EntityType.Arc:
                    if (!isBlockEntity)
                        this.arcs.Remove((Arc) entity);
                    break;
                case EntityType.Circle:
                    if (!isBlockEntity)
                        this.circles.Remove((Circle) entity);
                    break;
                case EntityType.Dimension:
                    Dimension dim = (Dimension) entity;
                    if (!isBlockEntity)
                        this.dimensions.Remove(dim);
                    this.blocks.References[dim.Block.Name].Remove(entity);
                    dim.DimensionBlockChanged -= this.Dimension_DimBlockChanged;
                    this.dimStyles.References[dim.Style.Name].Remove(entity);
                    dim.DimensionStyleChanged -= this.Dimension_DimStyleChanged;
                    dim.Block = null;

                    this.RemoveDimensionStyleOverrides(dim.StyleOverrides, dim);
                    dim.DimensionStyleOverrideAdded -= this.Dimension_DimStyleOverrideAdded;
                    dim.DimensionStyleOverrideRemoved -= this.Dimension_DimStyleOverrideRemoved;

                    break;
                case EntityType.Leader:
                    Leader leader = (Leader) entity;
                    if (!isBlockEntity)
                        this.leaders.Remove(leader);
                    this.dimStyles.References[leader.Style.Name].Remove(entity);
                    leader.LeaderStyleChanged -= this.Leader_DimStyleChanged;

                    if (leader.Annotation != null)
                        leader.Annotation.RemoveReactor(leader);

                    this.RemoveDimensionStyleOverrides(leader.StyleOverrides, leader);
                    leader.DimensionStyleOverrideAdded -= this.Leader_DimStyleOverrideAdded;
                    leader.DimensionStyleOverrideRemoved -= this.Leader_DimStyleOverrideRemoved;
                    break;
                case EntityType.Tolerance:
                    Tolerance tolerance = (Tolerance) entity;
                    if (!isBlockEntity)
                        this.tolerances.Remove(tolerance);
                    this.dimStyles.References[tolerance.Style.Name].Remove(entity);
                    tolerance.ToleranceStyleChanged -= this.Tolerance_DimStyleChanged;
                    break;
                case EntityType.Ellipse:
                    if (!isBlockEntity)
                        this.ellipses.Remove((Ellipse) entity);
                    break;
                case EntityType.Face3D:
                    if (!isBlockEntity)
                        this.faces3d.Remove((Face3d) entity);
                    break;
                case EntityType.Spline:
                    if (!isBlockEntity)
                        this.splines.Remove((Spline) entity);
                    break;
                case EntityType.Hatch:
                    Hatch hatch = (Hatch) entity;
                    hatch.UnLinkBoundary();
                    if (!isBlockEntity)
                    {
                        hatch.HatchBoundaryPathAdded -= this.Hatch_BoundaryPathAdded;
                        hatch.HatchBoundaryPathRemoved -= this.Hatch_BoundaryPathRemoved;
                        this.hatches.Remove(hatch);
                    }
                    break;
                case EntityType.Insert:
                    Insert insert = (Insert) entity;
                    if (!isBlockEntity)
                        this.inserts.Remove(insert);
                    this.blocks.References[insert.Block.Name].Remove(entity);
                    foreach (Attribute att in insert.Attributes)
                    {
                        this.layers.References[att.Layer.Name].Remove(att);
                        att.LayerChanged -= this.Entity_LayerChanged;
                        this.linetypes.References[att.Linetype.Name].Remove(att);
                        att.LinetypeChanged -= this.Entity_LinetypeChanged;
                        this.textStyles.References[att.Style.Name].Remove(att);
                        att.TextStyleChanged -= this.Entity_TextStyleChanged;
                    }
                    insert.AttributeAdded -= this.Insert_AttributeAdded;
                    insert.AttributeRemoved -= this.Insert_AttributeRemoved;
                    break;
                case EntityType.LightWeightPolyline:
                    if (!isBlockEntity)
                        this.lwPolylines.Remove((LwPolyline) entity);
                    break;
                case EntityType.Line:
                    if (!isBlockEntity)
                        this.lines.Remove((Line) entity);
                    break;
                case EntityType.Point:
                    if (!isBlockEntity)
                        this.points.Remove((Point) entity);
                    break;
                case EntityType.PolyfaceMesh:
                    if (!isBlockEntity)
                        this.polyfaceMeshes.Remove((PolyfaceMesh) entity);
                    break;
                case EntityType.Polyline:
                    if (!isBlockEntity)
                        this.polylines.Remove((Polyline) entity);
                    break;
                case EntityType.Solid:
                    if (!isBlockEntity)
                        this.solids.Remove((Solid) entity);
                    break;
                case EntityType.Trace:
                    if (!isBlockEntity)
                        this.traces.Remove((Trace) entity);
                    break;
                case EntityType.Mesh:
                    if (!isBlockEntity)
                        this.meshes.Remove((Mesh) entity);
                    break;
                case EntityType.Text:
                    Text text = (Text) entity;
                    if (!isBlockEntity)
                        this.texts.Remove(text);
                    this.textStyles.References[text.Style.Name].Remove(entity);
                    text.TextStyleChanged -= this.Entity_TextStyleChanged;
                    break;
                case EntityType.MText:
                    MText mText = (MText) entity;
                    if (!isBlockEntity)
                        this.mTexts.Remove(mText);
                    this.textStyles.References[mText.Style.Name].Remove(entity);
                    mText.TextStyleChanged -= this.Entity_TextStyleChanged;
                    break;
                case EntityType.Image:
                    Image image = (Image) entity;
                    if (!isBlockEntity)
                        this.images.Remove(image);
                    this.imageDefs.References[image.Definition.Name].Remove(image);
                    image.Definition.Reactors.Remove(image.Handle);
                    break;
                case EntityType.MLine:
                    MLine mline = (MLine) entity;
                    if (!isBlockEntity)
                        this.mLines.Remove(mline);
                    this.mlineStyles.References[mline.Style.Name].Remove(entity);
                    mline.MLineStyleChanged -= this.MLine_MLineStyleChanged;
                    break;
                case EntityType.Ray:
                    if (!isBlockEntity)
                        this.rays.Remove((Ray) entity);
                    break;
                case EntityType.XLine:
                    if (!isBlockEntity)
                        this.xlines.Remove((XLine) entity);
                    break;
                case EntityType.Viewport:
                    Viewport viewport = (Viewport) entity;
                    if (!isBlockEntity)
                        this.viewports.Remove(viewport);
                    // delete the viewport boundary entity in case there is one
                    if (viewport.ClippingBoundary != null)
                    {
                        viewport.ClippingBoundary.RemoveReactor(viewport);
                        this.RemoveEntity(viewport.ClippingBoundary);
                    }
                    break;
                case EntityType.AttributeDefinition:
                    AttributeDefinition attDef = (AttributeDefinition) entity;
                    if (!isBlockEntity)
                        this.attributeDefinitions.Remove(attDef);
                    this.textStyles.References[attDef.Style.Name].Remove(entity);
                    break;
                default:
                    throw new ArgumentException("The entity " + entity.Type + " is not implemented or unknown");
            }

            if (!isBlockEntity)
                this.layouts.References[entity.Owner.Record.Layout.Name].Remove(entity);

            this.layers.References[entity.Layer.Name].Remove(entity);
            this.linetypes.References[entity.Linetype.Name].Remove(entity);
            foreach (string appReg in entity.XData.AppIds)
            {
                this.appRegistries.References[appReg].Remove(entity);
            }
            this.AddedObjects.Remove(entity.Handle);

            entity.Handle = null;
            entity.Owner = null;

            entity.LayerChanged -= this.Entity_LayerChanged;
            entity.LinetypeChanged -= this.Entity_LinetypeChanged;
            entity.XDataAddAppReg -= this.Entity_XDataAddAppReg;
            entity.XDataRemoveAppReg -= this.Entity_XDataRemoveAppReg;

            return true;
        }
Ejemplo n.º 25
0
        private void WriteEntity(EntityObject entity, Layout layout)
        {
            Debug.Assert(this.activeSection == DxfObjectCode.EntitiesSection || this.activeSection == DxfObjectCode.BlocksSection);

            this.WriteEntityCommonCodes(entity, layout);

            switch (entity.Type)
            {
                case EntityType.Ray:
                    this.WriteRay((Ray) entity);
                    break;
                case EntityType.XLine:
                    this.WriteXLine((XLine) entity);
                    break;
                case EntityType.Arc:
                    this.WriteArc((Arc) entity);
                    break;
                case EntityType.Circle:
                    this.WriteCircle((Circle) entity);
                    break;
                case EntityType.Ellipse:
                    this.WriteEllipse((Ellipse) entity);
                    break;
                case EntityType.Point:
                    this.WritePoint((Point) entity);
                    break;
                case EntityType.Face3D:
                    this.WriteFace3D((Face3d) entity);
                    break;
                case EntityType.Spline:
                    this.WriteSpline((Spline) entity);
                    break;
                case EntityType.Solid:
                    this.WriteSolid((Solid) entity);
                    break;
                case EntityType.Insert:
                    this.WriteInsert((Insert) entity);
                    break;
                case EntityType.Line:
                    this.WriteLine((Line) entity);
                    break;
                case EntityType.LightWeightPolyline:
                    this.WriteLightWeightPolyline((LwPolyline) entity);
                    break;
                case EntityType.Polyline:
                    this.WritePolyline((Polyline) entity);
                    break;
                case EntityType.PolyfaceMesh:
                    this.WritePolyfaceMesh((PolyfaceMesh) entity);
                    break;
                case EntityType.Text:
                    this.WriteText((Text) entity);
                    break;
                case EntityType.MText:
                    this.WriteMText((MText) entity);
                    break;
                case EntityType.Hatch:
                    this.WriteHatch((Hatch) entity);
                    break;
                case EntityType.Dimension:
                    this.WriteDimension((Dimension) entity);
                    break;
                case EntityType.Image:
                    this.WriteImage((Image) entity);
                    break;
                case EntityType.MLine:
                    this.WriteMLine((MLine) entity);
                    break;
                case EntityType.Viewport:
                    this.WriteViewport((Viewport) entity);
                    break;
                case EntityType.Mesh:
                    this.WriteMesh((Mesh) entity);
                    break;
                case EntityType.AttributeDefinition:
                    this.WriteAttributeDefinition((AttributeDefinition) entity);
                    break;
                default:
                    throw new ArgumentException("Entity unknown.", "entity");
            }
        }
Ejemplo n.º 26
0
 void Entity_XDataAddAppReg(EntityObject sender, ObservableCollectionEventArgs<ApplicationRegistry> e)
 {
     sender.XData[e.Item.Name].ApplicationRegistry = this.appRegistries.Add(sender.XData[e.Item.Name].ApplicationRegistry);
     this.appRegistries.References[e.Item.Name].Add(sender);
 }
 public static Polyline ConvertFrom(EntityObject entity)
 {
     return new Polyline(entity);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Adds an <see cref="EntityObject">entity</see> to the document.
 /// </summary>
 /// <param name="entity">An <see cref="EntityObject">entity</see> to add to the document.</param>
 public void AddEntity(EntityObject entity)
 {
     this.AddEntity(entity, false, true);
 }
            public Line(EntityObject entity)
                : base(EdgeType.Line)
            {
                if (entity == null) throw new ArgumentNullException(nameof(entity));

                Entities.Line line = entity as Entities.Line;
                if (line == null) throw new ArgumentException("The entity is not a Line", nameof(entity));

                this.Start = new Vector2(line.StartPoint.X, line.StartPoint.Y);
                this.End = new Vector2(line.EndPoint.X, line.EndPoint.Y);
            }
Ejemplo n.º 30
0
        internal void AddEntity(EntityObject entity, bool isBlockEntity, bool assignHandle)
        {
            // null entities are not allowed
            if (entity == null)
                throw new ArgumentNullException(nameof(entity));

            // entities already owned by another document are not allowed
            if (entity.Owner != null && !isBlockEntity)
                throw new ArgumentException("The entity already belongs to a document. Clone it instead.", nameof(entity));

            // assign a handle
            if (assignHandle || string.IsNullOrEmpty(entity.Handle))
                this.NumHandles = entity.AsignHandle(this.NumHandles);

            // assign the owner
            if (!isBlockEntity)
            {
                entity.Owner = this.layouts[this.activeLayout].AssociatedBlock;
                this.layouts.References[this.activeLayout].Add(entity);
            }

            // the entities that are part of a block do not belong to any of the entities lists but to the block definition.
            switch (entity.Type)
            {
                case EntityType.Arc:
                    if (!isBlockEntity)
                        this.arcs.Add((Arc) entity);
                    break;
                case EntityType.Circle:
                    if (!isBlockEntity)
                        this.circles.Add((Circle) entity);
                    break;
                case EntityType.Dimension:
                    Dimension dim = (Dimension) entity;
                    dim.Style = this.dimStyles.Add(dim.Style, assignHandle);
                    this.dimStyles.References[dim.Style.Name].Add(dim);

                    this.AddDimensionStyleOverrides(dim, assignHandle);

                    // create the block that represent the dimension drawing
                    Block dimBlock = dim.Block;
                    if (dimBlock == null)
                        dimBlock = dim.BuildBlock("*D" + ++this.DimensionBlocksGenerated);
                    dim.Block = this.blocks.Add(dimBlock);
                    this.blocks.References[dimBlock.Name].Add(dim);

                    dim.DimensionStyleChanged += this.Dimension_DimStyleChanged;
                    dim.DimensionBlockChanged += this.Dimension_DimBlockChanged;
                    dim.DimensionStyleOverrideAdded += this.Dimension_DimStyleOverrideAdded;
                    dim.DimensionStyleOverrideRemoved += this.Dimension_DimStyleOverrideRemoved;

                    if (!isBlockEntity)
                        this.dimensions.Add(dim);
                    break;
                case EntityType.Leader:
                    Leader leader = (Leader) entity;
                    leader.Style = this.dimStyles.Add(leader.Style, assignHandle);
                    this.dimStyles.References[leader.Style.Name].Add(leader);
                    leader.LeaderStyleChanged += this.Leader_DimStyleChanged;
                    // add the annotation entity
                    if (leader.Annotation != null)
                        this.AddEntity(leader.Annotation, isBlockEntity, assignHandle);

                    this.AddStyleOverrides(leader, assignHandle);
                    leader.DimensionStyleOverrideAdded += this.Leader_DimStyleOverrideAdded;
                    leader.DimensionStyleOverrideRemoved += this.Leader_DimStyleOverrideRemoved;

                    if (!isBlockEntity)
                        this.leaders.Add(leader);
                    break;
                case EntityType.Tolerance:
                    Tolerance tol = (Tolerance) entity;
                    tol.Style = this.dimStyles.Add(tol.Style, assignHandle);
                    this.dimStyles.References[tol.Style.Name].Add(tol);
                    tol.ToleranceStyleChanged += this.Tolerance_DimStyleChanged;
                    if (!isBlockEntity)
                        this.tolerances.Add(tol);
                    break;
                case EntityType.Ellipse:
                    if (!isBlockEntity)
                        this.ellipses.Add((Ellipse) entity);
                    break;
                case EntityType.Face3D:
                    if (!isBlockEntity)
                        this.faces3d.Add((Face3d) entity);
                    break;
                case EntityType.Spline:
                    if (!isBlockEntity)
                        this.splines.Add((Spline) entity);
                    break;
                case EntityType.Hatch:
                    Hatch hatch = (Hatch) entity;

                    // the boundary entities of an associative hatch that belong to a block will be handle by that block
                    if (!isBlockEntity)
                    {
                        foreach (HatchBoundaryPath path in hatch.BoundaryPaths)
                            this.Hatch_BoundaryPathAdded(hatch, new ObservableCollectionEventArgs<HatchBoundaryPath>(path));

                        hatch.HatchBoundaryPathAdded += this.Hatch_BoundaryPathAdded;
                        hatch.HatchBoundaryPathRemoved += this.Hatch_BoundaryPathRemoved;
                        this.hatches.Add(hatch);
                    }
                    break;
                case EntityType.Insert:
                    Insert insert = (Insert) entity;
                    insert.Block = this.blocks.Add(insert.Block, assignHandle);
                    this.blocks.References[insert.Block.Name].Add(insert);
                    foreach (Attribute attribute in insert.Attributes)
                    {
                        attribute.Layer = this.layers.Add(attribute.Layer, assignHandle);
                        this.layers.References[attribute.Layer.Name].Add(attribute);
                        attribute.LayerChanged += this.Entity_LayerChanged;

                        attribute.Linetype = this.linetypes.Add(attribute.Linetype, assignHandle);
                        this.linetypes.References[attribute.Linetype.Name].Add(attribute);
                        attribute.LinetypeChanged += this.Entity_LinetypeChanged;

                        attribute.Style = this.textStyles.Add(attribute.Style, assignHandle);
                        this.textStyles.References[attribute.Style.Name].Add(attribute);
                        attribute.TextStyleChanged += this.Entity_TextStyleChanged;
                    }
                    insert.AttributeAdded += this.Insert_AttributeAdded;
                    insert.AttributeRemoved += this.Insert_AttributeRemoved;
                    if (!isBlockEntity)
                        this.inserts.Add(insert);
                    break;
                case EntityType.LightWeightPolyline:
                    if (!isBlockEntity)
                        this.lwPolylines.Add((LwPolyline) entity);
                    break;
                case EntityType.Line:
                    if (!isBlockEntity)
                        this.lines.Add((Line) entity);
                    break;
                case EntityType.Point:
                    if (!isBlockEntity)
                        this.points.Add((Point) entity);
                    break;
                case EntityType.PolyfaceMesh:
                    if (!isBlockEntity)
                        this.polyfaceMeshes.Add((PolyfaceMesh) entity);
                    break;
                case EntityType.Polyline:
                    if (!isBlockEntity)
                        this.polylines.Add((Polyline) entity);
                    break;
                case EntityType.Solid:
                    if (!isBlockEntity)
                        this.solids.Add((Solid) entity);
                    break;
                case EntityType.Trace:
                    if (!isBlockEntity)
                        this.traces.Add((Trace) entity);
                    break;
                case EntityType.Mesh:
                    if (!isBlockEntity)
                        this.meshes.Add((Mesh) entity);
                    break;
                case EntityType.Text:
                    Text text = (Text) entity;
                    text.Style = this.textStyles.Add(text.Style, assignHandle);
                    this.textStyles.References[text.Style.Name].Add(text);
                    text.TextStyleChanged += this.Entity_TextStyleChanged;
                    if (!isBlockEntity)
                        this.texts.Add(text);
                    break;
                case EntityType.MText:
                    MText mText = (MText) entity;
                    mText.Style = this.textStyles.Add(mText.Style, assignHandle);
                    this.textStyles.References[mText.Style.Name].Add(mText);
                    mText.TextStyleChanged += this.Entity_TextStyleChanged;
                    if (!isBlockEntity)
                        this.mTexts.Add(mText);
                    break;
                case EntityType.Image:
                    Image image = (Image) entity;
                    image.Definition = this.imageDefs.Add(image.Definition, assignHandle);
                    this.imageDefs.References[image.Definition.Name].Add(image);
                    if (!image.Definition.Reactors.ContainsKey(image.Handle))
                    {
                        ImageDefinitionReactor reactor = new ImageDefinitionReactor(image.Handle);
                        this.NumHandles = reactor.AsignHandle(this.NumHandles);
                        image.Definition.Reactors.Add(image.Handle, reactor);
                    }
                    if (!isBlockEntity)
                        this.images.Add(image);
                    break;
                case EntityType.MLine:
                    MLine mline = (MLine) entity;
                    mline.Style = this.mlineStyles.Add(mline.Style, assignHandle);
                    this.mlineStyles.References[mline.Style.Name].Add(mline);
                    mline.MLineStyleChanged += this.MLine_MLineStyleChanged;
                    if (!isBlockEntity)
                        this.mLines.Add(mline);
                    break;
                case EntityType.Ray:
                    if (!isBlockEntity)
                        this.rays.Add((Ray) entity);
                    break;
                case EntityType.XLine:
                    if (!isBlockEntity)
                        this.xlines.Add((XLine) entity);
                    break;
                case EntityType.Underlay:
                    Underlay underlay = (Underlay) entity;
                    switch (underlay.Definition.Type)
                    {
                        case UnderlayType.DGN:
                            underlay.Definition = this.underlayDgnDefs.Add((UnderlayDgnDefinition) underlay.Definition, assignHandle);
                            this.underlayDgnDefs.References[underlay.Definition.Name].Add(underlay);
                            break;
                        case UnderlayType.DWF:
                            underlay.Definition = this.underlayDwfDefs.Add((UnderlayDwfDefinition) underlay.Definition, assignHandle);
                            this.underlayDwfDefs.References[underlay.Definition.Name].Add(underlay);
                            break;
                        case UnderlayType.PDF:
                            underlay.Definition = this.underlayPdfDefs.Add((UnderlayPdfDefinition) underlay.Definition, assignHandle);
                            this.underlayPdfDefs.References[underlay.Definition.Name].Add(underlay);
                            break;
                    }
                    if (!isBlockEntity)
                        this.underlays.Add(underlay);
                    break;
                case EntityType.Wipeout:
                    if (!isBlockEntity)
                        this.wipeouts.Add((Wipeout) entity);
                    break;
                case EntityType.Viewport:
                    Viewport viewport = (Viewport) entity;
                    if (viewport.ClippingBoundary != null)
                        this.AddEntity(viewport.ClippingBoundary, isBlockEntity, assignHandle);
                    if (!isBlockEntity)
                        this.viewports.Add(viewport);
                    break;
                case EntityType.AttributeDefinition:
                    AttributeDefinition attDef = (AttributeDefinition) entity;
                    attDef.Style = this.textStyles.Add(attDef.Style, assignHandle);
                    this.textStyles.References[attDef.Style.Name].Add(attDef);
                    attDef.TextStyleChange += this.Entity_TextStyleChanged;
                    if (!isBlockEntity)
                        this.attributeDefinitions.Add(attDef);
                    break;
                default:
                    throw new ArgumentException("The entity " + entity.Type + " is not implemented or unknown.");
            }

            foreach (string appReg in entity.XData.AppIds)
            {
                entity.XData[appReg].ApplicationRegistry = this.appRegistries.Add(entity.XData[appReg].ApplicationRegistry, assignHandle);
                this.appRegistries.References[appReg].Add(entity);
            }

            entity.Layer = this.layers.Add(entity.Layer, assignHandle);
            this.layers.References[entity.Layer.Name].Add(entity);

            entity.Linetype = this.linetypes.Add(entity.Linetype, assignHandle);
            this.linetypes.References[entity.Linetype.Name].Add(entity);

            this.AddedObjects.Add(entity.Handle, entity);

            entity.LayerChanged += this.Entity_LayerChanged;
            entity.LinetypeChanged += this.Entity_LinetypeChanged;
            entity.XDataAddAppReg += this.Entity_XDataAddAppReg;
            entity.XDataRemoveAppReg += this.Entity_XDataRemoveAppReg;
        }
            public Arc(EntityObject entity)
                : base(EdgeType.Arc)
            {
                if (entity == null) throw new ArgumentNullException(nameof(entity));

                switch (entity.Type)
                {
                    case EntityType.Arc:
                        Entities.Arc arc = (Entities.Arc) entity;
                        this.Center = new Vector2(arc.Center.X, arc.Center.Y);
                        this.Radius = arc.Radius;
                        this.StartAngle = arc.StartAngle;
                        this.EndAngle = arc.EndAngle;
                        this.IsCounterclockwise = true;
                        break;
                    case EntityType.Circle:
                        Entities.Circle circle = (Circle) entity;
                        this.Center = new Vector2(circle.Center.X, circle.Center.Y);
                        this.Radius = circle.Radius;
                        this.StartAngle = 0.0;
                        this.EndAngle = 360.0;
                        this.IsCounterclockwise = true;
                        break;
                    default:
                        throw new ArgumentException("The entity is not a Circle or an Arc", nameof(entity));
                }
            }
Ejemplo n.º 32
0
        private void WriteEntity(EntityObject entity, Layout layout)
        {
            Debug.Assert(this.activeSection == DxfObjectCode.EntitiesSection || this.activeSection == DxfObjectCode.BlocksSection);
            Debug.Assert(entity != null);

            // hatches with zero boundaries are not allowed
            if (entity.Type == EntityType.Hatch && ((Hatch)entity).BoundaryPaths.Count == 0) return;
            // leader entities with less than two vertexes are not allowed
            if (entity.Type == EntityType.Leader && ((Leader)entity).Vertexes.Count < 2) return;
            // polyline entities with less than two vertexes are not allowed
            if (entity.Type == EntityType.Polyline && ((Polyline)entity).Vertexes.Count < 2) return;
            // lwPolyline entities with less than two vertexes are not allowed
            if (entity.Type == EntityType.LightWeightPolyline && ((LwPolyline)entity).Vertexes.Count < 2) return;

            this.WriteEntityCommonCodes(entity, layout);

            switch (entity.Type)
            {
                case EntityType.Arc:
                    this.WriteArc((Arc) entity);
                    break;
                case EntityType.AttributeDefinition:
                    this.WriteAttributeDefinition((AttributeDefinition)entity);
                    break;
                case EntityType.Circle:
                    this.WriteCircle((Circle) entity);
                    break;
                case EntityType.Dimension:
                    this.WriteDimension((Dimension)entity);
                    break;
                case EntityType.Ellipse:
                    this.WriteEllipse((Ellipse) entity);
                    break;
                case EntityType.Face3D:
                    this.WriteFace3D((Face3d) entity);
                    break;
                case EntityType.Hatch:
                    this.WriteHatch((Hatch)entity);
                    break;
                case EntityType.Image:
                    this.WriteImage((Image)entity);
                    break;
                case EntityType.Insert:
                    this.WriteInsert((Insert) entity);
                    break;
                case EntityType.Leader:
                    this.WriteLeader((Leader)entity);
                    break;
                case EntityType.LightWeightPolyline:
                    this.WriteLightWeightPolyline((LwPolyline) entity);
                    break;
                case EntityType.Line:
                    this.WriteLine((Line) entity);
                    break;
                case EntityType.Mesh:
                    this.WriteMesh((Mesh)entity);
                    break;
                case EntityType.MLine:
                    this.WriteMLine((MLine)entity);
                    break;
                case EntityType.MText:
                    this.WriteMText((MText)entity);
                    break;
                case EntityType.Point:
                    this.WritePoint((Point) entity);
                    break;
                case EntityType.PolyfaceMesh:
                    this.WritePolyfaceMesh((PolyfaceMesh) entity);
                    break;
                case EntityType.Polyline:
                    this.WritePolyline((Polyline) entity);
                    break;
                case EntityType.Ray:
                    this.WriteRay((Ray) entity);
                    break;
                case EntityType.Solid:
                    this.WriteSolid((Solid) entity);
                    break;
                case EntityType.Spline:
                    this.WriteSpline((Spline) entity);
                    break;
                case EntityType.Text:
                    this.WriteText((Text) entity);
                    break;
                case EntityType.Tolerance:
                    this.WriteTolerance((Tolerance) entity);
                    break;
                case EntityType.Trace:
                    this.WriteTrace((Trace)entity);
                    break;
                case EntityType.Underlay:
                    this.WriteUnderlay((Underlay) entity);
                    break;
                case EntityType.Viewport:
                    this.WriteViewport((Viewport) entity);
                    break;
                case EntityType.Wipeout:
                    this.WriteWipeout((Wipeout) entity);
                    break;
                case EntityType.XLine:
                    this.WriteXLine((XLine) entity);
                    break;
                default:
                    throw new ArgumentException("Entity unknown.", nameof(entity));
            }
        }
 public static Arc ConvertFrom(EntityObject entity)
 {
     return new Arc(entity);
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Initializes a new instance of <c>BlockEntityChangeEventArgs</c>.
 /// </summary>
 /// <param name="item">The entity that is being added or removed from the block.</param>
 public GroupEntityChangeEventArgs(EntityObject item)
 {
     this.item = item;
 }
            public Ellipse(EntityObject entity)
                : base(EdgeType.Ellipse)
            {
                if (entity == null) throw new ArgumentNullException(nameof(entity));

                Entities.Ellipse ellipse = entity as Entities.Ellipse;
                if (ellipse == null) throw new ArgumentException("The entity is not an Ellipse", nameof(entity));

                this.Center = new Vector2(ellipse.Center.X, ellipse.Center.Y);
                double sine = 0.5 * ellipse.MajorAxis * Math.Sin(ellipse.Rotation * MathHelper.DegToRad);
                double cosine = 0.5 * ellipse.MajorAxis * Math.Cos(ellipse.Rotation * MathHelper.DegToRad);
                this.EndMajorAxis = new Vector2(cosine, sine);
                this.MinorRatio = ellipse.MinorAxis / ellipse.MajorAxis;
                if (ellipse.IsFullEllipse)
                {
                    this.StartAngle = 0;
                    this.EndAngle = 360;
                }
                else
                {
                    this.StartAngle = ellipse.StartAngle;
                    this.EndAngle = ellipse.EndAngle;
                }
                this.IsCounterclockwise = true;
            }
 public static Ellipse ConvertFrom(EntityObject entity)
 {
     return new Ellipse(entity);
 }
            public Spline(EntityObject entity)
                : base(EdgeType.Spline)
            {
                if (entity == null) throw new ArgumentNullException(nameof(entity));

                Entities.Spline spline = entity as Entities.Spline;
                if (spline == null) throw new ArgumentException("The entity is not an Spline", nameof(entity));

                this.Degree = spline.Degree;
                this.IsRational = (spline.Flags & SplineTypeFlags.Rational) == SplineTypeFlags.Rational;
                this.IsPeriodic = spline.IsPeriodic;
                if (spline.ControlPoints.Count == 0)
                    throw new ArgumentException("The HatchBoundaryPath spline edge requires a spline entity with control points.", nameof(entity));
                this.ControlPoints = new Vector3[spline.ControlPoints.Count];
                for (int i = 0; i < spline.ControlPoints.Count; i++)
                {
                    this.ControlPoints[i] = new Vector3(spline.ControlPoints[i].Position.X, spline.ControlPoints[i].Position.Y, spline.ControlPoints[i].Weigth);
                }
                this.Knots = new double[spline.Knots.Count];
                for (int i = 0; i < spline.Knots.Count; i++)
                {
                    this.Knots[i] = spline.Knots[i];
                }
            }
Ejemplo n.º 38
0
 protected virtual void OnAttributeDefinitionRemovedEvent(EntityObject item)
 {
     AttributeDefinitionRemovedEventHandler ae = this.AttributeDefinitionRemoved;
     if (ae != null)
         ae(this, new BlockEntityChangeEventArgs(item));
 }
 public static Spline ConvertFrom(EntityObject entity)
 {
     return new Spline(entity);
 }
Ejemplo n.º 40
0
 internal Viewport(short id)
     : base(EntityType.Viewport, DxfObjectCode.Viewport)
 {
     this.center = Vector3.Zero;
     this.width = 297;
     this.height = 210;
     this.stacking = id;
     this.id = id;
     this.viewCenter = Vector2.Zero;
     this.snapBase = Vector2.Zero;
     this.snapSpacing = new Vector2(10.0);
     this.gridSpacing = new Vector2(10.0);
     this.viewDirection = Vector3.UnitZ;
     this.viewTarget = Vector3.Zero;
     this.lensLength = 50.0;
     this.frontClipPlane = 0.0;
     this.backClipPlane = 0.0;
     this.viewHeight = 250;
     this.snapAngle = 0.0;
     this.twistAngle = 0.0;
     this.circleZoomPercent = 1000;
     this.status = ViewportStatusFlags.AdaptiveGridDisplay | ViewportStatusFlags.DisplayGridBeyondDrawingLimits | ViewportStatusFlags.CurrentlyAlwaysEnabled | ViewportStatusFlags.UcsIconVisibility;
     this.frozenLayers = new List<Layer>();
     this.ucsOrigin = Vector3.Zero;
     this.ucsXAxis = Vector3.UnitX;
     this.ucsYAxis = Vector3.UnitY;
     this.elevation = 0.0;
     this.boundary = null;
 }
Ejemplo n.º 41
0
        // TODO: apply the transformation directly to edges
        //public void TransformBy2(Matrix3 transformation, Vector3 translation)
        //{
        //    if (this.associative)
        //    {
        //        this.UnLinkBoundary();
        //    }

        //    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();

        //    Vector3 position = transOW * new Vector3(0.0, 0.0, this.Elevation);

        //    foreach (HatchBoundaryPath path in this.BoundaryPaths)
        //    {
        //        foreach (HatchBoundaryPath.Edge edge in path.Edges)
        //        {
        //            switch (edge.Type)
        //            {
        //                case HatchBoundaryPath.EdgeType.Arc:
        //                    break;

        //                case HatchBoundaryPath.EdgeType.Ellipse:
        //                    break;

        //                case HatchBoundaryPath.EdgeType.Line:
        //                    HatchBoundaryPath.Line line = (HatchBoundaryPath.Line)edge;
        //                    Vector3 start = new Vector3(line.Start.X, line.Start.Y, 0.0);
        //                    Vector3 end = new Vector3(line.End.X, line.End.Y, 0.0);

        //                    // to world coordinates
        //                    start = transOW * start + position;
        //                    end = transOW * end + position;

        //                    // transformation
        //                    start = transformation * start + translation;
        //                    end = transformation * end + translation;

        //                    Vector3 point;
        //                    point = transWO * start;
        //                    line.Start = new Vector2(point.X, point.Y);
        //                    point = transWO * end;
        //                    line.End = new Vector2(point.X, point.Y);
        //                    break;

        //                case HatchBoundaryPath.EdgeType.Polyline:
        //                    break;

        //                case HatchBoundaryPath.EdgeType.Spline:
        //                    break;
        //            }
        //        }
        //    }

        //    position = transformation * position + translation;
        //    position = transWO * position;

        //    Vector2 refAxis = Vector2.Rotate(Vector2.UnitX, this.Pattern.Angle * MathHelper.DegToRad);
        //    refAxis = this.Pattern.Scale * refAxis;
        //    Vector3 v = transOW * new Vector3(refAxis.X, refAxis.Y, 0.0);
        //    v = transformation * v;
        //    v = transWO * v;
        //    Vector2 axis = new Vector2(v.X, v.Y);
        //    double newAngle = Vector2.Angle(axis) * MathHelper.RadToDeg;

        //    double newScale = axis.Modulus();
        //    newScale = MathHelper.IsZero(newScale) ? MathHelper.Epsilon : newScale;

        //    this.Pattern.Scale = newScale;
        //    this.Pattern.Angle = newAngle;
        //    this.Elevation = position.Z;
        //    this.Normal = newNormal;
        //}

        /// <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)
        {
            if (this.associative)
            {
                this.UnLinkBoundary();
            }

            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();

            Vector3 position = transOW * new Vector3(0.0, 0.0, this.Elevation);

            List <HatchBoundaryPath> paths = new List <HatchBoundaryPath>();

            foreach (HatchBoundaryPath path in this.BoundaryPaths)
            {
                List <EntityObject> data = new List <EntityObject>();

                foreach (HatchBoundaryPath.Edge edge in path.Edges)
                {
                    EntityObject entity = edge.ConvertTo();

                    switch (entity.Type)
                    {
                    case EntityType.Arc:
                        entity = ProcessArc((Arc)entity, transOW, position);
                        break;

                    case EntityType.Circle:
                        entity = ProcessCircle((Circle)entity, transOW, position);
                        break;

                    case EntityType.Ellipse:
                        entity = ProcessEllipse((Ellipse)entity, transOW, position);
                        break;

                    case EntityType.Line:
                        entity = ProcessLine((Line)entity, transOW, position);
                        break;

                    case EntityType.Polyline2D:
                        entity = ProcessLwPolyline((Polyline2D)entity, this.Normal, this.Elevation);
                        break;

                    case EntityType.Spline:
                        entity = ProcessSpline((Spline)entity, transOW, position);
                        break;
                    }
                    entity.TransformBy(transformation, translation);
                    data.Add(entity);
                }
                paths.Add(new HatchBoundaryPath(data));
            }

            position = transformation * position + translation;
            position = transWO * position;

            Vector2 refAxis = Vector2.Rotate(Vector2.UnitX, this.Pattern.Angle * MathHelper.DegToRad);

            refAxis = this.Pattern.Scale * refAxis;
            Vector3 v = transOW * new Vector3(refAxis.X, refAxis.Y, 0.0);

            v = transformation * v;
            v = transWO * v;
            Vector2 axis     = new Vector2(v.X, v.Y);
            double  newAngle = Vector2.Angle(axis) * MathHelper.RadToDeg;

            double newScale = axis.Modulus();

            newScale = MathHelper.IsZero(newScale) ? MathHelper.Epsilon : newScale;

            this.Pattern.Scale = newScale;
            this.Pattern.Angle = newAngle;
            this.Elevation     = position.Z;

            this.Normal = newNormal;
            this.BoundaryPaths.Clear();
            this.BoundaryPaths.AddRange(paths);
        }