Ejemplo n.º 1
0
 protected virtual MLineStyle OnMLineStyleChangeEvent(MLineStyle oldMLineStyle, MLineStyle newMLineStyle)
 {
     MLineStyleChangeEventHandler ae = this.MLineStyleChange;
     if (ae != null)
     {
         TableObjectChangeEventArgs<MLineStyle> eventArgs = new TableObjectChangeEventArgs<MLineStyle>(oldMLineStyle, newMLineStyle);
         ae(this, eventArgs);
         return eventArgs.NewValue;
     }
     return newMLineStyle;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <c>MLine</c> class.
        /// </summary>
        /// <param name="vertexes">MLine <see cref="Vector2">vertex</see> location list in object coordinates.</param>
        /// <param name="style">MLine <see cref="MLineStyle">style.</see></param>
        /// <param name="scale">MLine scale.</param>
        /// <param name="isClosed">Sets if the multiline is closed</param>
        public MLine(ICollection<Vector2> vertexes, MLineStyle style, double scale, bool isClosed = false)
            : base(EntityType.MLine, DxfObjectCode.MLine)
        {
            this.scale = scale;
            if (style == null)
                throw new ArgumentNullException("style", "The MLine style cannot be null.");
            if (isClosed)
                this.flags = MLineFlags.Has | MLineFlags.Closed;
            else
                this.flags = MLineFlags.Has;

            this.style = style;
            this.justification = MLineJustification.Zero;
            this.elevation = 0.0;
            if (vertexes == null)
                throw new ArgumentNullException("vertexes");
            this.SetVertexes(vertexes);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <c>MLine</c> class.
        /// </summary>
        /// <param name="vertexes">MLine <see cref="Vector2">vertex</see> location list in object coordinates.</param>
        /// <param name="style">MLine <see cref="MLineStyle">style.</see></param>
        /// <param name="scale">MLine scale.</param>
        /// <param name="isClosed">Sets if the multiline is closed  (default: false).</param>
        public MLine(IEnumerable<Vector2> vertexes, MLineStyle style, double scale, bool isClosed)
            : base(EntityType.MLine, DxfObjectCode.MLine)
        {
            this.scale = scale;
            if (style == null)
                throw new ArgumentNullException(nameof(style));
            if (isClosed)
                this.flags = MLineFlags.Has | MLineFlags.Closed;
            else
                this.flags = MLineFlags.Has;

            this.style = style;
            this.justification = MLineJustification.Zero;
            this.elevation = 0.0;
            if (vertexes == null)
                throw new ArgumentNullException(nameof(vertexes));
            this.vertexes = new List<MLineVertex>();
            foreach (Vector2 point in vertexes)
                this.vertexes.Add(new MLineVertex(point, Vector2.Zero, Vector2.Zero, null));
            this.Update();
        }
Ejemplo n.º 4
0
        private void WriteMLineStyle(MLineStyle style, string ownerHandle)
        {
            this.chunk.Write(0, style.CodeName);
            this.chunk.Write(5, style.Handle);
            this.chunk.Write(330, ownerHandle);

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

            this.chunk.Write(2, this.EncodeNonAsciiCharacters(style.Name));

            this.chunk.Write(70, (short) style.Flags);

            this.chunk.Write(3, this.EncodeNonAsciiCharacters(style.Description));

            this.chunk.Write(62, style.FillColor.Index);
            if (style.FillColor.UseTrueColor) // && this.doc.DrawingVariables.AcadVer > DxfVersion.AutoCad2000)
                this.chunk.Write(420, AciColor.ToTrueColor(style.FillColor));
            this.chunk.Write(51, style.StartAngle);
            this.chunk.Write(52, style.EndAngle);
            this.chunk.Write(71, (short) style.Elements.Count);
            foreach (MLineStyleElement element in style.Elements)
            {
                this.chunk.Write(49, element.Offset);
                this.chunk.Write(62, element.Color.Index);
                if (element.Color.UseTrueColor) // && this.doc.DrawingVariables.AcadVer > DxfVersion.AutoCad2000)
                    this.chunk.Write(420, AciColor.ToTrueColor(element.Color));

                this.chunk.Write(6, this.EncodeNonAsciiCharacters(element.LineType.Name));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <c>MLine</c> class.
 /// </summary>
 /// <param name="vertexes">MLine <see cref="Vector2">vertex</see> location list in object coordinates.</param>
 /// <param name="style">MLine <see cref="MLineStyle">style.</see></param>
 /// <param name="scale">MLine scale.</param>
 public MLine(IEnumerable<Vector2> vertexes, MLineStyle style, double scale)
     : this(vertexes, style, scale, false)
 {
 }
Ejemplo n.º 6
0
        private MLineStyle ReadMLineStyle()
        {
            string handle = null;
            string name = null;
            string description = null;
            AciColor fillColor = AciColor.ByLayer;
            double startAngle = 90.0;
            double endAngle = 90.0;
            MLineStyleFlags flags = MLineStyleFlags.None;
            List<MLineStyleElement> elements = new List<MLineStyleElement>();

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 5:
                        handle = this.chunk.ReadHex();
                        this.chunk.Next();
                        break;
                    case 2:
                        name = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 3:
                        description = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 62:
                        if (!fillColor.UseTrueColor)
                            fillColor = AciColor.FromCadIndex(this.chunk.ReadShort());
                        this.chunk.Next();
                        break;
                    case 420:
                        fillColor = AciColor.FromTrueColor(this.chunk.ReadInt());
                        this.chunk.Next();
                        break;
                    case 70:
                        flags = (MLineStyleFlags) this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 51:
                        startAngle = this.chunk.ReadDouble();
                        if (startAngle < 10.0 || startAngle > 170.0)
                            startAngle = 90.0;
                        this.chunk.Next();
                        break;
                    case 52:
                        endAngle = this.chunk.ReadDouble();
                        if (endAngle < 10.0 || endAngle > 170.0)
                            endAngle = 90.0;
                        this.chunk.Next();
                        break;
                    case 71:
                        short numElements = this.chunk.ReadShort();
                        elements = this.ReadMLineStyleElements(numElements);
                        break;
                    default:
                        this.chunk.Next();
                        break;
                }
            }
            if (string.IsNullOrEmpty(name))
                return null;

            MLineStyle style = new MLineStyle(name, elements, description)
            {
                Handle = handle,
                FillColor = fillColor,
                Flags = flags,
                StartAngle = startAngle,
                EndAngle = endAngle
            };

            return style;
        }
Ejemplo n.º 7
0
        public static void ModifyingMLineStyles()
        {
            DxfDocument doc = new DxfDocument(DxfVersion.AutoCad2010);
            doc.DrawingVariables.LtScale = 10;

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
         
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();           
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;

            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
           
            doc.AddEntity(mline);

            // change the multi line style after it has been added to the document
            mline.Style = style;
            Debug.Assert(ReferenceEquals(mline.Style, doc.MlineStyles[mline.Style.Name]), "Reference not equals.");

            // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method.
            // It is also necessary when manually editing the vertex distances.
            mline.Update();
            
            // the line type will be automatically added to the document
            foreach (MLineStyleElement e in style.Elements)
            {
                // making changes after the MLineStyle has been added to the document
                e.LineType = LineType.Dashed;
                Debug.Assert(ReferenceEquals(e.LineType, doc.LineTypes[e.LineType.Name]), "Reference not equals.");
            }

            MLine copy = (MLine) mline.Clone();
            copy.Scale = 100;
            doc.AddEntity(copy);
            // once the entity has been added to the document, changing its style requires that the new style is also present in the document.
            copy.Style = doc.MlineStyles["standard"];
            // VERY IMPORTANT: We have modified the MLine after setting its vertexes so we need to manually call this method.
            // It is also necessary when manually editing the vertex distances.
            copy.Update();

            doc.Save("ModifyingMLineStyle.dxf");
            Test("ModifyingMLineStyle.dxf");
        }
Ejemplo n.º 8
0
        private static void WriteMLine()
        {
            DxfDocument dxf = new DxfDocument();
            //MLineStyle style = MLineStyle.Default;
            //dxf.AddMLineStyle(style);

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;
            //mline.IsClosed = true;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;
            //style.StartAngle = 25.0;
            //style.EndAngle = 160.0;
            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
            mline.Style = style;
            // we have modified the multiline after setting its vertexes so we need to manually call this method.
            // also when manually editing the vertex distances
            mline.Update();

            // we can manually create cuts or gaps in the individual elements that made the multiline.
            // the cuts are defined as distances from the start point of the element along its direction.
            mline.Vertexes[0].Distances[0].Add(50);
            mline.Vertexes[0].Distances[0].Add(100);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count-1].Add(50);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count-1].Add(100);

            dxf.AddEntity(mline);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("MLine.dxf");

            //dxf = DxfDocument.Load("Drawing1.dxf");
            //dxf.Save("Drawing1 copy.dxf");

            //dxf = DxfDocument.Load("Drawing3.dxf");
            //dxf.Save("Drawing3 copy.dxf");

            //dxf = DxfDocument.Load("Drawing2.dxf");
            //dxf.Save("Drawing2 copy.dxf");

            // empty mline
            //List<Vector2> vertexes2 = new List<Vector2>
            //                             {
            //                                 new Vector2(0, 0),
            //                                 new Vector2(100, 100),
            //                                 new Vector2(100, 100),
            //                                 new Vector2(200, 0)
            //                             };

            //MLine mline2 = new MLine(vertexes2){Scale = 20};
            //mline2.CalculateVertexesInfo();

            //DxfDocument dxf2 = new DxfDocument();
            //dxf2.AddEntity(mline2);
            ////dxf2.Save("void mline.dxf");

            //MLine mline3 = new MLine();
            //dxf2.AddEntity(mline3);
            ////dxf2.Save("void mline.dxf");

            //Polyline pol = new Polyline();
            //LwPolyline lwPol = new LwPolyline();
            //dxf2.AddEntity(pol);
            //dxf2.AddEntity(lwPol);
            //dxf2.Save("void mline.dxf");
            //dxf2 = DxfDocument.Load("void mline.dxf");
            
        }
Ejemplo n.º 9
0
        private static void MLineStyleUsesAndRemove()
        {
            DxfDocument dxf = new DxfDocument();
            //MLineStyle style = MLineStyle.Default;
            //dxf.AddMLineStyle(style);

            List<Vector2> vertexes = new List<Vector2>
                                            {
                                                new Vector2(0, 0),
                                                new Vector2(0, 150),
                                                new Vector2(150, 150),
                                                new Vector2(150, 0)
                                            };

            MLine mline = new MLine(vertexes);
            mline.Scale = 20;
            mline.Justification = MLineJustification.Zero;
            //mline.IsClosed = true;

            MLineStyle style = new MLineStyle("MyStyle", "Personalized style.");
            style.Elements.Add(new MLineStyleElement(0.25));
            style.Elements.Add(new MLineStyleElement(-0.25));
            // if we add new elements directly to the list we need to sort the list,
            style.Elements.Sort();
            style.Flags = MLineStyleFlags.EndInnerArcsCap | MLineStyleFlags.EndRoundCap | MLineStyleFlags.StartInnerArcsCap | MLineStyleFlags.StartRoundCap;
            //style.StartAngle = 25.0;
            //style.EndAngle = 160.0;
            // AutoCad2000 dxf version does not support true colors for MLineStyle elements
            style.Elements[0].Color = new AciColor(180, 230, 147);
            mline.Style = style;
            // we have modified the mline after setting its vertexes so we need to manually call this method.
            // also when manually editting the vertex distances
            mline.Update();

            // we can manually create cuts or gaps in the individual elements that made the multiline.
            // the cuts are defined as distances from the start point of the element along its direction.
            mline.Vertexes[0].Distances[0].Add(50);
            mline.Vertexes[0].Distances[0].Add(100);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count - 1].Add(50);
            mline.Vertexes[0].Distances[mline.Style.Elements.Count - 1].Add(100);
            dxf.AddEntity(mline);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("MLine.dxf");

            DxfDocument dxf2 = DxfDocument.Load("MLine.dxf");

            // "MyStyle" is used only once
            List<DxfObject> uses;
            uses = dxf.MlineStyles.GetReferences(mline.Style.Name);

            // if we try to get the LineTypeUses, we will find out that "MyStyle" appears several times,
            // this is due to that each MLineStyleElement of a MLineStyle has an associated LineType
            uses = dxf.LineTypes.GetReferences(LineType.ByLayerName);

            bool ok;
            ok = dxf.RemoveEntity(mline);

            // "MyStyle" is not used its reference has been deleted
            uses = dxf.MlineStyles.GetReferences(mline.Style.Name);
            // we can safely remove it
            dxf.MlineStyles.Remove(mline.Style.Name);

            dxf.Save("MLine2.dxf");

            dxf.Layers.Clear();

            dxf.Save("MLine2.dxf");
        }