Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 public Leader(ToleranceEntry tolerance, IEnumerable <Vector2> vertexes, DimensionStyle style)
     : base(EntityType.Leader, DxfObjectCode.Leader)
 {
     if (vertexes == null)
     {
         throw new ArgumentNullException(nameof(vertexes));
     }
     this.vertexes = new List <Vector2>(vertexes);
     if (this.vertexes.Count < 2)
     {
         throw new ArgumentOutOfRangeException(nameof(vertexes), this.vertexes.Count, "The leader vertexes list requires at least two points.");
     }
     if (style == null)
     {
         throw new ArgumentNullException(nameof(style));
     }
     this.style          = style;
     this.hasHookline    = false;
     this.showArrowhead  = true;
     this.pathType       = LeaderPathType.StraightLineSegements;
     this.lineColor      = AciColor.ByLayer;
     this.elevation      = 0.0;
     this.offset         = Vector2.Zero;
     this.styleOverrides = new DimensionStyleOverrideDictionary();
     this.styleOverrides.BeforeAddItem    += this.StyleOverrides_BeforeAddItem;
     this.styleOverrides.AddItem          += this.StyleOverrides_AddItem;
     this.styleOverrides.BeforeRemoveItem += this.StyleOverrides_BeforeRemoveItem;
     this.styleOverrides.RemoveItem       += this.StyleOverrides_RemoveItem;
     this.annotation = this.BuildAnnotation(tolerance);
     this.annotation.AddReactor(this);
 }
Exemple #2
0
 private Tolerance BuildAnnotation(ToleranceEntry tolerance)
 {
     return(new Tolerance(tolerance, this.vertexes[this.vertexes.Count - 1])
     {
         Color = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor,
         Style = this.style
     });
 }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <c>Tolerance</c> class.
        /// </summary>
        /// <param name="tolerance"></param>
        /// <param name="position"></param>
        public Tolerance(ToleranceEntry tolerance, Vector3 position)
            : base(EntityType.Tolerance, DxfObjectCode.Tolerance)
        {
            this.entry1 = tolerance;
            this.entry2 = null;
            this.height = string.Empty;
            this.showProjectedToleranceZoneSymbol = false;
            this.datumIdentifier = string.Empty;

            this.style    = DimensionStyle.Default;
            this.position = position;
            this.rotation = 0.0;
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <c>Tolerance</c> class.
        /// </summary>
        /// <param name="tolerance"></param>
        /// <param name="position"></param>
        public Tolerance(ToleranceEntry tolerance, Vector3 position)
            : base(EntityType.Tolerance, DxfObjectCode.Tolerance)
        {
            this.entry1 = tolerance;
            this.entry2 = null;
            this.height = string.Empty;
            this.showProjectedToleranceZoneSymbol = false;
            this.datumIdentifier = string.Empty;

            this.style = DimensionStyle.Default;
            this.position = position;
            this.rotation = 0.0;
        }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 public Leader(ToleranceEntry tolerance, IList <Vector2> vertexes, DimensionStyle style)
     : base(EntityType.Leader, DxfObjectCode.Leader)
 {
     if (vertexes == null)
     {
         throw new ArgumentNullException(nameof(vertexes));
     }
     if (vertexes.Count < 2)
     {
         throw new ArgumentOutOfRangeException(nameof(vertexes), "The leader vertexes list requires at least two points.");
     }
     this.vertexes      = new List <Vector2>(vertexes);
     this.style         = style;
     this.hasHookline   = false;
     this.showArrowhead = true;
     this.pathType      = LeaderPathType.StraightLineSegements;
     this.textPosition  = LeaderTextVerticalPosition.Above;
     this.lineColor     = AciColor.ByLayer;
     this.elevation     = 0.0;
     this.offset        = Vector2.Zero;
     this.annotation    = this.BuildAnnotation(tolerance);
     this.annotation.AddReactor(this);
 }
Exemple #6
0
        private static string ToleranceEntryToString(ToleranceEntry entry)
        {
            StringBuilder value = new StringBuilder();
            switch (entry.GeometricSymbol)
            {
                case ToleranceGeometricSymbol.None:
                    break;
                case ToleranceGeometricSymbol.Position:
                    value.Append("{\\Fgdt;j}");
                    break;
                case ToleranceGeometricSymbol.Concentricity:
                    value.Append("{\\Fgdt;r}");
                    break;
                case ToleranceGeometricSymbol.Symmetry:
                    value.Append("{\\Fgdt;i}");
                    break;
                case ToleranceGeometricSymbol.Parallelism:
                    value.Append("{\\Fgdt;f}");
                    break;
                case ToleranceGeometricSymbol.Perpendicularity:
                    value.Append("{\\Fgdt;b}");
                    break;
                case ToleranceGeometricSymbol.Angularity:
                    value.Append("{\\Fgdt;a}");
                    break;
                case ToleranceGeometricSymbol.Cylindricity:
                    value.Append("{\\Fgdt;g}");
                    break;
                case ToleranceGeometricSymbol.Flatness:
                    value.Append("{\\Fgdt;c}");
                    break;
                case ToleranceGeometricSymbol.Roundness:
                    value.Append("{\\Fgdt;e}");
                    break;
                case ToleranceGeometricSymbol.Straightness:
                    value.Append("{\\Fgdt;u}");
                    break;
                case ToleranceGeometricSymbol.ProfileSurface:
                    value.Append("{\\Fgdt;d}");
                    break;
                case ToleranceGeometricSymbol.ProfileLine:
                    value.Append("{\\Fgdt;k}");
                    break;
                case ToleranceGeometricSymbol.CircularRunout:
                    value.Append("{\\Fgdt;h}");
                    break;
                case ToleranceGeometricSymbol.TotalRunOut:
                    value.Append("{\\Fgdt;t}");
                    break;
            }

            value.Append(ToleranceValueToString(entry.Tolerance1));
            value.Append(ToleranceValueToString(entry.Tolerance2));
            value.Append(DatumValueToString(entry.Datum1));
            value.Append(DatumValueToString(entry.Datum2));
            value.Append(DatumValueToString(entry.Datum3));

            return value.ToString();
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <c>Tolerance</c> class.
 /// </summary>
 /// <param name="tolerance"></param>
 public Tolerance(ToleranceEntry tolerance)
     : this(tolerance, Vector3.Zero)
 {
 }
Exemple #8
0
        private static ToleranceEntry ParseToleranceEntry(string line)
        {
            string[] values = Regex.Split(line, "%%v");

            ToleranceGeometricSymbol geom = ToleranceGeometricSymbol.None;
            ToleranceValue t1 = null;
            ToleranceValue t2 = null;
            DatumReferenceValue d1 = null;
            DatumReferenceValue d2 = null;
            DatumReferenceValue d3 = null;

            if (!string.IsNullOrEmpty(values[0]))
            {
                if (values[0].StartsWith("{"))
                {
                    // geometric symbol
                    CharEnumerator chars = values[0].GetEnumerator();
                    char symbol = Symbol(chars);
                    geom = ParseGeometricSymbol(symbol);
                }
            }

            for (int i = 1; i < values.Length; i++)
            {
                string value = values[i];

                switch (i)
                {
                    case 1:
                        t1 = ParseToleranceValue(value);
                        break;
                    case 2:
                        t2 = ParseToleranceValue(value);
                        break;
                    case 3:
                        d1 = ParseDatumReferenceValue(value);
                        break;
                    case 4:
                        d2 = ParseDatumReferenceValue(value);
                        break;
                    case 5:
                        d3 = ParseDatumReferenceValue(value);
                        break;
                    default:
                        throw new FormatException("The tolerance string representation is not well formatted");
                }
            }

            ToleranceEntry t = new ToleranceEntry
            {
                GeometricSymbol = geom,
                Tolerance1 = t1,
                Tolerance2 = t2,
                Datum1 = d1,
                Datum2 = d2,
                Datum3 = d3
            };

            return t;
        }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <c>Tolerance</c> class.
 /// </summary>
 /// <param name="tolerance"></param>
 /// <param name="position"></param>
 public Tolerance(ToleranceEntry tolerance, Vector2 position)
     : this(tolerance, new Vector3(position.X, position.Y, 0.0))
 {
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <c>Tolerance</c> class.
 /// </summary>
 /// <param name="tolerance"></param>
 public Tolerance(ToleranceEntry tolerance)
     : this(tolerance, Vector3.Zero)
 {
 }
Exemple #11
0
        private static ToleranceEntry ParseToleranceEntry(string line)
        {
            string[] values = Regex.Split(line, "%%v");

            ToleranceGeometricSymbol geom = ToleranceGeometricSymbol.None;
            ToleranceValue           t1   = null;
            ToleranceValue           t2   = null;
            DatumReferenceValue      d1   = null;
            DatumReferenceValue      d2   = null;
            DatumReferenceValue      d3   = null;

            if (!string.IsNullOrEmpty(values[0]))
            {
                if (values[0].StartsWith("{"))
                {
                    // geometric symbol
                    CharEnumerator chars  = values[0].GetEnumerator();
                    char           symbol = Symbol(chars);
                    geom = ParseGeometricSymbol(symbol);
                }
            }

            for (int i = 1; i < values.Length; i++)
            {
                string value = values[i];

                switch (i)
                {
                case 1:
                    t1 = ParseToleranceValue(value);
                    break;

                case 2:
                    t2 = ParseToleranceValue(value);
                    break;

                case 3:
                    d1 = ParseDatumReferenceValue(value);
                    break;

                case 4:
                    d2 = ParseDatumReferenceValue(value);
                    break;

                case 5:
                    d3 = ParseDatumReferenceValue(value);
                    break;

                default:
                    throw new FormatException("The tolerance string representation is not well formatted");
                }
            }

            ToleranceEntry t = new ToleranceEntry
            {
                GeometricSymbol = geom,
                Tolerance1      = t1,
                Tolerance2      = t2,
                Datum1          = d1,
                Datum2          = d2,
                Datum3          = d3
            };

            return(t);
        }
Exemple #12
0
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 /// <param name="tolerance">Leader tolerance annotation.</param>
 /// <param name="vertexes">List of leader vertexes in local coordinates.</param>
 /// <param name="style">Leader style.</param>
 public Leader(ToleranceEntry tolerance, IEnumerable <Vector2> vertexes, DimensionStyle style)
     : this(vertexes, style)
 {
     this.Annotation = this.BuildAnnotation(tolerance);
 }
Exemple #13
0
        /// <summary>
        /// Converts the string representation of a tolerance to its tolerance entity equivalent.
        /// </summary>
        /// <param name="s">A string that represents a tolerance to convert.</param>
        /// <returns>The Tolerance entity equivalent to the tolerance contained in s.</returns>
        public static Tolerance ParseRepresentation(string s)
        {
            string[] lines = Regex.Split(s, "\\^J");

            ToleranceEntry t1              = null;
            ToleranceEntry t2              = null;
            string         height          = string.Empty;
            bool           showProjSymbol  = false;
            string         datumIdentifier = string.Empty;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.StartsWith("{") || line.StartsWith("%%v"))
                {
                    switch (i)
                    {
                    case 0:
                        t1 = ParseToleranceEntry(line);
                        break;

                    case 1:
                        t2 = ParseToleranceEntry(line);
                        break;
                    }
                }
                else
                {
                    if (i == lines.Length - 1)
                    {
                        datumIdentifier = line;
                    }
                    else
                    {
                        StringBuilder value = new StringBuilder();

                        CharEnumerator chars = line.GetEnumerator();
                        while (chars.MoveNext())
                        {
                            char token = chars.Current;
                            if (token == '{')
                            {
                                char symbol = Symbol(chars);
                                if (symbol == 'p')
                                {
                                    showProjSymbol = true;
                                }
                            }
                            else
                            {
                                value.Append(token);
                            }
                        }
                        height = value.ToString();
                    }
                }
            }

            Tolerance tolerance = new Tolerance
            {
                Entry1 = t1,
                Entry2 = t2,
                Height = height,
                ShowProjectedToleranceZoneSymbol = showProjSymbol,
                DatumIdentifier = datumIdentifier
            };

            return(tolerance);
        }
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 public Leader(ToleranceEntry tolerance, IList<Vector2> vertexes, DimensionStyle style)
     : base(EntityType.Leader, DxfObjectCode.Leader)
 {
     if (vertexes == null)
         throw new ArgumentNullException(nameof(vertexes));
     if (vertexes.Count < 2)
         throw new ArgumentOutOfRangeException(nameof(vertexes), "The leader vertexes list requires at least two points.");
     this.vertexes = new List<Vector2>(vertexes);
     this.style = style;
     this.hasHookline = false;
     this.showArrowhead = true;
     this.pathType = LeaderPathType.StraightLineSegements;
     this.textPosition = LeaderTextVerticalPosition.Above;
     this.lineColor = AciColor.ByLayer;
     this.elevation = 0.0;
     this.offset = Vector2.Zero;
     this.annotation = this.BuildAnnotation(tolerance);
     this.annotation.AddReactor(this);
 }
 private Tolerance BuildAnnotation(ToleranceEntry tolerance)
 {
     return new Tolerance(tolerance, this.vertexes[this.vertexes.Count - 1])
     {
         Color = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT,
         Style = this.style
     };
 }
        private static void ToleranceEntity()
        {
            ToleranceEntry entry = new ToleranceEntry
            {
                GeometricSymbol = ToleranceGeometricSymbol.Symmetry,
                Tolerance1 = new ToleranceValue(true, "12.5", ToleranceMaterialCondition.Maximum)
            };
            Tolerance tolerance = new Tolerance();
            tolerance.Entry1 = entry;
            tolerance.Rotation = 30;

            DxfDocument doc = new DxfDocument();
            doc.AddEntity(tolerance);
            doc.Save("Tolerance.dxf");

            DxfDocument dxf = DxfDocument.Load("Tolerance.dxf");
            dxf.Save("Test.dxf");
        }
Exemple #17
0
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 public Leader(ToleranceEntry tolerance, IEnumerable <Vector2> vertexes)
     : this(tolerance, vertexes, DimensionStyle.Default)
 {
 }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the <c>Tolerance</c> class.
 /// </summary>
 /// <param name="tolerance"></param>
 /// <param name="position"></param>
 public Tolerance(ToleranceEntry tolerance, Vector2 position)
     : this(tolerance, new Vector3(position.X, position.Y, 0.0))
 {
 }
Exemple #19
0
        private static string ToleranceEntryToString(ToleranceEntry entry)
        {
            StringBuilder value = new StringBuilder();

            switch (entry.GeometricSymbol)
            {
            case ToleranceGeometricSymbol.None:
                break;

            case ToleranceGeometricSymbol.Position:
                value.Append("{\\Fgdt;j}");
                break;

            case ToleranceGeometricSymbol.Concentricity:
                value.Append("{\\Fgdt;r}");
                break;

            case ToleranceGeometricSymbol.Symmetry:
                value.Append("{\\Fgdt;i}");
                break;

            case ToleranceGeometricSymbol.Parallelism:
                value.Append("{\\Fgdt;f}");
                break;

            case ToleranceGeometricSymbol.Perpendicularity:
                value.Append("{\\Fgdt;b}");
                break;

            case ToleranceGeometricSymbol.Angularity:
                value.Append("{\\Fgdt;a}");
                break;

            case ToleranceGeometricSymbol.Cylindricity:
                value.Append("{\\Fgdt;g}");
                break;

            case ToleranceGeometricSymbol.Flatness:
                value.Append("{\\Fgdt;c}");
                break;

            case ToleranceGeometricSymbol.Roundness:
                value.Append("{\\Fgdt;e}");
                break;

            case ToleranceGeometricSymbol.Straightness:
                value.Append("{\\Fgdt;u}");
                break;

            case ToleranceGeometricSymbol.ProfileSurface:
                value.Append("{\\Fgdt;d}");
                break;

            case ToleranceGeometricSymbol.ProfileLine:
                value.Append("{\\Fgdt;k}");
                break;

            case ToleranceGeometricSymbol.CircularRunout:
                value.Append("{\\Fgdt;h}");
                break;

            case ToleranceGeometricSymbol.TotalRunOut:
                value.Append("{\\Fgdt;t}");
                break;
            }

            value.Append(ToleranceValueToString(entry.Tolerance1));
            value.Append(ToleranceValueToString(entry.Tolerance2));
            value.Append(DatumValueToString(entry.Datum1));
            value.Append(DatumValueToString(entry.Datum2));
            value.Append(DatumValueToString(entry.Datum3));

            return(value.ToString());
        }
 /// <summary>
 /// Initializes a new instance of the <c>Leader</c> class.
 /// </summary>
 public Leader(ToleranceEntry tolerance, IList<Vector2> vertexes)
     : this(tolerance, vertexes, DimensionStyle.Default)
 {
 }
        private static void LeaderEntity()
        {
            // a basic text annotation
            List<Vector2> vertexes1 = new List<Vector2>();
            vertexes1.Add(new Vector2(0, 0));
            vertexes1.Add(new Vector2(-5, 5));
            Leader leader1 = new Leader("Sample annotation", vertexes1);
            leader1.Offset = new Vector2(0, -0.5);
            // We need to call manually the method Update if the annotation position is modified,
            // or the Leader properties like Style, Normal, Elevation, Annotation, TextVerticalPosition, and/or Offset.
            leader1.Update();

            // leader not in the XY plane
            Leader cloned = (Leader) leader1.Clone();
            cloned.Normal = new Vector3(1);
            cloned.Elevation = 5;

            // a text annotation with style
            DimensionStyle style = new DimensionStyle("MyStyle");
            style.DIMCLRD = AciColor.Green;
            style.DIMCLRT = AciColor.Blue;
            style.DIMLDRBLK = DimensionArrowhead.DotBlank;
            style.DIMSCALE = 2.0;

            List<Vector2> vertexes2 = new List<Vector2>();
            vertexes2.Add(new Vector2(0, 0));
            vertexes2.Add(new Vector2(5, 5));
            Leader leader2 = new Leader("Sample annotation", vertexes2, style);
            ((MText) leader2.Annotation).AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
            leader2.TextVerticalPosition = LeaderTextVerticalPosition.Centered;
            leader2.Update();

            // a tolerance annotation,
            // its hook point will always appear at the left since I have no way of measuring the real length of a tolerance,
            // and it has no alignment options as the MText does.
            List<Vector2> vertexes3 = new List<Vector2>();
            vertexes3.Add(new Vector2(0));
            vertexes3.Add(new Vector2(5, -5));
            vertexes3.Add(new Vector2(7.5, -5));
            ToleranceEntry entry = new ToleranceEntry
            {
                GeometricSymbol = ToleranceGeometricSymbol.Symmetry,
                Tolerance1 = new ToleranceValue(true, "12.5", ToleranceMaterialCondition.Maximum)
            };
            Leader leader3 = new Leader(entry, vertexes3);

            // a block annotation
            Block block = new Block("BlockAnnotation");
            block.Entities.Add(new Line(new Vector2(-1, -1), new Vector2(1, 1)));
            block.Entities.Add(new Line(new Vector2(-1, 1), new Vector2(1, -1)));
            block.Entities.Add(new Circle(Vector2.Zero, 0.5));

            List<Vector2> vertexes4 = new List<Vector2>();
            vertexes4.Add(new Vector2(0));
            vertexes4.Add(new Vector2(-5, -5));
            vertexes4.Add(new Vector2(-7.5, -5));
            Leader leader4 = new Leader(block, vertexes4);
            // change the leader offset to move  the leader hook (the last vertex of the leader vertexes list) in relation to the annotation position.
            leader4.Offset = new Vector2(1, 1);
            leader4.Update();

            // add entities to the document
            DxfDocument doc = new DxfDocument();
            doc.AddEntity(cloned);
            doc.AddEntity(leader1);
            doc.AddEntity(leader2);
            doc.AddEntity(leader3);
            doc.AddEntity(leader4);
            doc.Save("Leader.dxf");

            DxfDocument test = DxfDocument.Load("Leader.dxf");
            test.Save("test.dxf");
        }