private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3(10, 10, 0), 10, 45, 135);
            arc.Layer = new Layer("arc");
            arc.Layer.Color.Index = 1;
            dxf.AddEntity(arc);

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            XData xdata2 = new XData(new ApplicationRegistry("other application"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3 extrusion = new Vector3(1, 1, 1);
            Vector3 centerWCS = new Vector3(1, 1, 1);
            Vector3 centerOCS = MathHelper.Transform(centerWCS,
                                                        extrusion,
                                                        CoordinateSystem.World,
                                                        CoordinateSystem.Object);

            Circle circle = new Circle(centerOCS, 5);
            circle.Layer = new Layer("circle with spaces");
            circle.Layer.Color=AciColor.Yellow;
            circle.LineType = LineType.Dashed;
            circle.Normal = extrusion;
            circle.XData.Add(xdata);
            circle.XData.Add(xdata2);

            dxf.AddEntity(circle);

            //points
            Point point1 = new Point(new Vector3(-3, -3, 0));
            point1.Layer = new Layer("point");
            point1.Color = new AciColor(30);
            Point point2 = new Point(new Vector3(1, 1, 1));
            point2.Layer = point1.Layer;
            point2.Layer.Color.Index = 9;
            point2.Normal = new Vector3(1, 1, 1);
            dxf.AddEntity(point1);
            dxf.AddEntity(point2);

            //3dface
            Face3d face3D = new Face3d(new Vector3(-5, -5, 5),
                                        new Vector3(5, -5, 5),
                                        new Vector3(5, 5, 5),
                                        new Vector3(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);
            
            //polyline
            LwPolylineVertex polyVertex;
            List<LwPolylineVertex> polyVertexes = new List<LwPolylineVertex>();
            polyVertex = new LwPolylineVertex(new Vector2(-50, -50));
            polyVertex.StartWidth = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, -50));
            polyVertex.StartWidth = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new LwPolylineVertex(new Vector2(-50, 50));
            polyVertexes.Add(polyVertex);
            LwPolyline polyline2d = new LwPolyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3(1, 1, 1);
            polyline2d.Elevation = 100.0f;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LwPolylineVertex lwVertex;
            List<LwPolylineVertex> lwVertexes = new List<LwPolylineVertex>();
            lwVertex = new LwPolylineVertex(new Vector2(-25, -25));
            lwVertex.StartWidth = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, -25));
            lwVertex.StartWidth = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LwPolylineVertex(new Vector2(-25, 25));
            lwVertexes.Add(lwVertex);
            LwPolyline lwPolyline = new LwPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3(1, 1, 1);
            lwPolyline.Elevation = 100.0f;
            dxf.AddEntity(lwPolyline);

            // polyfaceMesh
            List<PolyfaceMeshVertex> meshVertexes = new List<PolyfaceMeshVertex>
                                                    {
                                                        new PolyfaceMeshVertex(0, 0, 0),
                                                        new PolyfaceMeshVertex(10, 0, 0),
                                                        new PolyfaceMeshVertex(10, 10, 0),
                                                        new PolyfaceMeshVertex(5, 15, 0),
                                                        new PolyfaceMeshVertex(0, 10, 0)
                                                    };
            List<PolyfaceMeshFace> faces = new List<PolyfaceMeshFace>
                                                {
                                                    new PolyfaceMeshFace(new short[] {1, 2, -3}),
                                                    new PolyfaceMeshFace(new short[] {-1, 3, -4}),
                                                    new PolyfaceMeshFace(new short[] {-1, 4, 5})
                                                };

            PolyfaceMesh mesh = new PolyfaceMesh(meshVertexes, faces);
            mesh.Layer = new Layer("polyfacemesh");
            mesh.Layer.Color.Index = 104;
            dxf.AddEntity(mesh);

            //line
            Line line = new Line(new Vector3(0, 0, 0), new Vector3(10, 10, 10));
            line.Layer = new Layer("line");
            line.Layer.Color.Index = 6;
            dxf.AddEntity(line);

            //3d polyline
            PolylineVertex vertex;
            List<PolylineVertex> vertexes = new List<PolylineVertex>();
            vertex = new PolylineVertex(new Vector3(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new PolylineVertex(new Vector3(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline polyline = new Polyline(vertexes, true);
            polyline.Layer = new Layer("polyline3d");
            polyline.Layer.Color.Index = 24;
            dxf.AddEntity(polyline);

            //block definition
            Block block = new Block("TestBlock");
            block.Entities.Add(new Line(new Vector3(-5, -5, 5), new Vector3(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3(5, -5, 5), new Vector3(-5, 5, 5)));
           
            //insert
            Insert insert = new Insert(block, new Vector3(5, 5, 5));
            insert.Layer = new Layer("insert");
            insert.Layer.Color.Index = 4;
            dxf.AddEntity(insert);

            //text
            TextStyle style=new TextStyle("True type font","Arial.ttf");
            Text text = new Text("Hello world!", Vector3.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("AutoCad2010.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save("AutoCad2007.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("AutoCad2004.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2000;
            dxf.Save("AutoCad2000.dxf");
            dxf = DxfDocument.Load("AutoCad2000.dxf");
            dxf.Save("AutoCad2000 result.dxf");
        }
Beispiel #2
0
 protected virtual TextStyle OnTextStyleChangeEvent(TextStyle oldTextStyle, TextStyle newTextStyle)
 {
     TextStyleChangeEventHandler ae = this.TextStyleChange;
     if (ae != null)
     {
         TableObjectChangeEventArgs<TextStyle> eventArgs = new TableObjectChangeEventArgs<TextStyle>(oldTextStyle, newTextStyle);
         ae(this, eventArgs);
         return eventArgs.NewValue;
     }
     return newTextStyle;
 }
 /// <summary>
 /// Initializes a new instance of the <c>MTextFormattingOptions</c> class
 /// </summary>
 /// <param name="style">Current style of the <see cref="MText">multiline text</see> entity.</param>
 public MTextFormattingOptions(TextStyle style)
 {
     this.bold = false;
     this.italic = false;
     this.overline = false;
     this.underline = false;
     this.color = null;
     this.fontName = null;
     this.aligment = TextAligment.Default;
     this.heightFactor = 1.0;
     this.obliqueAngle = 0.0;
     this.characterSpaceFactor = 1.0;
     this.widthFactor = 1.0;
     this.style = style;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <c>Text</c> class.
 /// </summary>
 public Text()
     : base(DxfObjectCode.Text)
 {
     this.value = string.Empty;
     this.basePoint = Vector3d.Zero;
     this.alignment = TextAlignment.BaselineLeft;
     this.layer = Layer.Default;
     this.color = AciColor.ByLayer;
     this.lineType = LineType.ByLayer;
     this.normal = Vector3d.UnitZ;
     this.style = TextStyle.Default;
     this.rotation = 0.0f;
     this.height = 0.0f;
     this.widthFactor = 1.0f;
     this.obliqueAngle = 0.0f;
 }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the <c>AttributeDefiniton</c> class.
        /// </summary>
        /// <param name="tag">Attribute identifier.</param>
        /// <param name="style">Attribute <see cref="TextStyle">text style</see>.</param>
        public AttributeDefinition(string tag, TextStyle style)
            : base(EntityType.AttributeDefinition, DxfObjectCode.AttributeDefinition)
        {
            if (string.IsNullOrEmpty(tag))
                throw new ArgumentNullException(nameof(tag));

            this.tag = tag;
            this.flags = AttributeFlags.Visible;
            this.prompt = string.Empty;
            this.value = null;
            this.position = Vector3.Zero;
            if (style == null)
                throw new ArgumentNullException(nameof(style));
            this.style = style;
            this.height = MathHelper.IsZero(style.Height) ? 1.0 : style.Height;
            this.widthFactor = style.WidthFactor;
            this.obliqueAngle = style.ObliqueAngle;
            this.rotation = 0.0;
            this.alignment = TextAlignment.BaselineLeft;
        }
Beispiel #6
0
        public static void Draw(DxfDocument dxf, Location location,List<string> configurations)
        {
            Vector3f confStrVector3f = new Vector3f(location.X + 5.0f, location.Y - 5.0f, location.Z);
            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Text text1 = new Text("CONFIGURATION:                   NOTE:  Assembly drawing for overall dimesions,  actual door size and handle position may vary",
                confStrVector3f, 2.0f, style);
            Layer layer = new Layer("text");
            text1.Layer = layer;
            //text1.Layer.Color.Index = 8;
            text1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(text1);

            for (int i = 0; i < configurations.Count(); i++)
            {
                Vector3f confVector3f = new Vector3f(location.X+10.0f, location.Y - 5.0f * (i + 2), location.Z);
                Text text = new Text(configurations[i], confVector3f, 2.0f, style);
                text.Layer = layer;
                //text.Layer.Color.Index = 8;
                text.Alignment = TextAlignment.TopLeft;
                dxf.AddEntity(text);
            }
        }
 /// <summary>
 /// Intitializes a new instance of the <c>AttributeDefiniton</c> class.
 /// </summary>
 /// <param name="id">Attribute identifier, the parameter <c>id</c> string cannot contain spaces.</param>
 public AttributeDefinition(string id)
     : base(DxfObjectCode.AttributeDefinition)
 {
     if (id.Contains(" "))
         throw new ArgumentException("The id string cannot contain spaces", "id");
     this.id = id;
     this.flags = AttributeFlags.Visible;
     this.text = string.Empty;
     this.value = null;
     this.basePoint = Vector3d.Zero;
     this.layer = Layer.Default;
     this.color = AciColor.ByLayer;
     this.lineType = LineType.ByLayer;
     this.style = TextStyle.Default;
     this.alignment = TextAlignment.BaselineLeft;
     this.height = this.style.Height == 0 ? 1.0f : this.style.Height;
     this.widthFactor = this.style.WidthFactor;
     this.rotation = 0.0f;
     this.normal = Vector3d.UnitZ;
 }
        /// <summary>
        /// Writes a new text style to the table section.
        /// </summary>
        /// <param name="style">TextStyle.</param>
        private void WriteTextStyle(TextStyle style)
        {
            Debug.Assert(this.activeTable == DxfObjectCode.TextStyleTable);

            this.chunk.Write(0, style.CodeName);
            this.chunk.Write(5, style.Handle);
            this.chunk.Write(330, style.Owner.Handle);

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

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

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

            if (!style.Registered)
                this.chunk.Write(3, this.EncodeNonAsciiCharacters(style.FontName));

            this.chunk.Write(70, style.IsVertical ? (short) 4 : (short) 0);

            if (style.IsBackward && style.IsUpsideDown)
            {
                this.chunk.Write(71, (short) 6);
            }
            else if (style.IsBackward)
            {
                this.chunk.Write(71, (short) 2);
            }
            else if (style.IsUpsideDown)
            {
                this.chunk.Write(71, (short) 4);
            }
            else
            {
                this.chunk.Write(71, (short) 0);
            }

            this.chunk.Write(40, style.Height);
            this.chunk.Write(41, style.WidthFactor);
            this.chunk.Write(42, style.Height);
            this.chunk.Write(50, style.ObliqueAngle);

            if (style.Registered)
            {
                this.chunk.Write(XDataCode.AppReg, "ACAD");
                this.chunk.Write(XDataCode.String, this.EncodeNonAsciiCharacters(style.FontFamilyName));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Writes a new text style to the table section.
        /// </summary>
        /// <param name="style">TextStyle.</param>
        public void WriteTextStyle(TextStyle style)
        {
            if (this.activeTable != StringCode.TextStyleTable)
            {
                throw new InvalidDxfTableException(this.activeTable, this.file);
            }

            this.WriteCodePair(0, style.CodeName);
            this.WriteCodePair(5, style.Handle);
            this.WriteCodePair(100, SubclassMarker.TableRecord);

            this.WriteCodePair(100, SubclassMarker.TextStyle);

            this.WriteCodePair(2, style);
            this.WriteCodePair(3, style.Font);

            if (style.IsVertical)
            {
                this.WriteCodePair(70, 4);
            }
            else
            {
                this.WriteCodePair(70, 0);
            }

            if (style.IsBackward && style.IsUpsideDown)
            {
                this.WriteCodePair(71, 6);
            }
            else if (style.IsBackward)
            {
                this.WriteCodePair(71, 2);
            }
            else if (style.IsUpsideDown)
            {
                this.WriteCodePair(71, 4);
            }
            else
            {
                this.WriteCodePair(71, 0);
            }

            this.WriteCodePair(40, style.Height);
            this.WriteCodePair(41, style.WidthFactor);
            this.WriteCodePair(42, style.Height);
            this.WriteCodePair(50, style.ObliqueAngle);
        }
Beispiel #10
0
        /// <summary>
        /// Initializes a new instance of the <c>Attribute</c> class.
        /// </summary>
        /// <param name="definition"><see cref="AttributeDefinition">Attribute definition</see>.</param>
        /// <remarks>
        /// Although the attribute entity could override values defined in its definition for simplicity the implementation has restricted this possibility.
        /// </remarks>
        public Attribute(AttributeDefinition definition)
            : base(DxfObjectCode.Attribute)
        {
            if (definition == null)
                throw new ArgumentNullException("definition");

            //EntityObject properties
            this.color = definition.Color;
            this.layer = definition.Layer;
            this.lineType = definition.LineType;
            this.lineweight = definition.Lineweight;
            this.lineTypeScale = definition.LineTypeScale;
            this.transparency = definition.Transparency;
            this.isVisible = definition.IsVisible;
            this.normal = definition.Normal;

            //Attribute definition properties
            this.definition = definition;
            this.tag = definition.Tag;
            this.value = definition.Value;
            this.style = definition.Style;
            this.position = definition.Position;
            this.flags = definition.Flags;
            this.height = definition.Height;
            this.widthFactor = definition.WidthFactor;
            this.obliqueAngle = definition.ObliqueAngle;
            this.rotation = definition.Rotation;
            this.alignment = definition.Alignment;
        }
Beispiel #11
0
        /// <summary>
        /// Writes a new text style to the table section.
        /// </summary>
        /// <param name="style">TextStyle.</param>
        private void WriteTextStyle(TextStyle style)
        {
            Debug.Assert(this.activeTable == DxfObjectCode.TextStyleTable);

            this.chunk.Write(0, style.CodeName);
            this.chunk.Write(5, style.Handle);
            this.chunk.Write(330, style.Owner.Handle);

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

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

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

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

            this.chunk.Write(70, style.IsVertical ? (short) 4 : (short) 0);

            if (style.IsBackward && style.IsUpsideDown)
                this.chunk.Write(71, (short) 6);
            else if (style.IsBackward)
                this.chunk.Write(71, (short) 2);
            else if (style.IsUpsideDown)
                this.chunk.Write(71, (short) 4);
            else
                this.chunk.Write(71, (short) 0);

            this.chunk.Write(40, style.Height);
            this.chunk.Write(41, style.WidthFactor);
            this.chunk.Write(42, style.Height);
            this.chunk.Write(50, style.ObliqueAngle);

            if (style.GlyphTypeface == null)
                return;

            this.chunk.Write((short) XDataCode.AppReg, "ACAD");
            this.chunk.Write((short) XDataCode.String, this.EncodeNonAsciiCharacters(style.FontFamilyName));
            byte[] st = new byte[4];
            if (style.GlyphTypeface.Style == FontStyles.Italic || style.GlyphTypeface.Style == FontStyles.Oblique)
                st[3] += 1;
            if (style.GlyphTypeface.Weight == FontWeights.Bold)
                st[3] += 2;
            this.chunk.Write((short) XDataCode.Int32, BitConverter.ToInt32(st, 0));
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <c>Text</c> class.
 /// </summary>
 /// <param name="text">Text string.</param>
 /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param>
 /// <param name="height">Text height.</param>
 /// <param name="style">Text <see cref="TextStyle">style</see>.</param>
 public Text(string text, Vector2 position, double height, TextStyle style)
     : this(text, new Vector3(position.X, position.Y, 0.0), height, style)
 {
 }
        private static void TestingTrueTypeFonts()
        {
            DxfDocument dxfText = new DxfDocument();
            TextStyle textStyle1 = new TextStyle("arial.ttf");
            TextStyle textStyle2 = new TextStyle("arialbi.ttf");
            TextStyle textStyle3 = new TextStyle("92642.ttf");
            Text text1 = new Text("testing", Vector2.Zero, 6, textStyle1);
            Text text2 = new Text("testing", Vector2.Zero, 6, textStyle2);
            Text text3 = new Text("testing", Vector2.Zero, 6, textStyle3);
            dxfText.AddEntity(text1);
            dxfText.AddEntity(text2);
            dxfText.AddEntity(text3);
            dxfText.Save("text3.dxf");

            DxfDocument load = DxfDocument.Load("text3.dxf");
            load.Save("test.dxf");

        }
        private static void BlockWithAttributes()
        {
            DxfDocument dxf = new DxfDocument();
            Block block = new Block("BlockWithAttributes");
            block.Layer = new Layer("BlockSample");
            // It is possible to change the block position, even though it is recommended to keep it at Vector3.Zero,
            // since the block geometry is expressed in local coordinates of the block.
            // The block position defines the base point when inserting an Insert entity.
            block.Origin = new Vector3(10, 5, 0);

            // create an attribute definition, the attDef tag must be unique as it is the way to identify the attribute.
            // even thought AutoCad allows multiple attribute definition in block definitions, it is not recommended
            AttributeDefinition attdef = new AttributeDefinition("NewAttribute");
            // this is the text prompt shown to introduce the attribute value when a new Insert entity is inserted into the drawing
            attdef.Prompt = "InfoText";
            // optionally we can set a default value for new Insert entities
            attdef.Value = 0;
            // the attribute definition position is in local coordinates to the Insert entity to which it belongs
            attdef.Position = new Vector3(1, 1, 0);

            // modifying directly the text style might not get the desired results. Create one or get one from the text style table, modify it and assign it to the attribute text style.
            // one thing to note, if there is already a text style with the assigned name, the existing one in the text style table will override the new one.
            //attdef.Style.IsVertical = true;

            TextStyle txt = new TextStyle("MyStyle", "Arial.ttf");
            txt.IsVertical = true;
            attdef.Style = txt;
            attdef.WidthFactor = 2;
            // not all alignment options are available for TTF fonts 
            attdef.Alignment = TextAlignment.MiddleCenter;
            attdef.Rotation = 90;

            // remember, netDxf does not allow adding attribute definitions with the same tag, even thought AutoCad allows this behavior, it is not recommended in anyway.
            // internally attributes and their associated attribute definitions are handled through dictionaries,
            // and the tags work as ids to easily identify the information stored in the attribute value.
            // When reading a file the attributes or attribute definitions with duplicate tags will be automatically removed.
            // This is subject to change on public demand, it is possible to reimplement this behavior with simple collections to allow for duplicate tags.
            block.AttributeDefinitions.Add(attdef);

            // The entities list defines the actual geometry of the block, they are expressed in th block local coordinates
            Line line1 = new Line(new Vector3(-5, -5, 0), new Vector3(5, 5, 0));
            Line line2 = new Line(new Vector3(5, -5, 0), new Vector3(-5, 5, 0));
            block.Entities.Add(line1);
            block.Entities.Add(line2);

            // You can check the entity ownership with:
            Block line1Owner = line1.Owner;
            Block line2Owner = line2.Owner;
            // in this example line1Oner = line2Owner = block
            // As explained in the PaperSpace() sample, the layout associated with a common block will always be null
            Layout associatedLayout = line1.Owner.Record.Layout;
            // associatedLayout = null

            // create an Insert entity with the block definition, during the initialization the Insert attributes list will be created with the default attdef properties
            Insert insert1 = new Insert(block)
            {
                Position = new Vector3(5, 5, 5),
                Normal = new Vector3(1, 1, 1),
                Rotation = 45
            };

            // When the insert position, rotation, normal and/or scale are modified we need to transform the attributes.
            // It is not recommended to manually change the attribute position and orientation and let the Insert entity handle the transformations to maintain them in the same local position.
            // In this particular case we have changed the position, normal and rotation.
            insert1.TransformAttributes();
            
            // Once the insert has been created we can modify the attributes properties, the list cannot be modified only the items stored in it
            insert1.Attributes[0].Value = 24;

            // Modifying directly the layer might not get the desired results. Create one or get one from the layers table, modify it and assign it to the insert
            // One thing to note, if there is already a layer with the same name, the existing one in the layers table will override the new one, when the entity is added to the document.
            Layer layer = new Layer("MyInsertLayer");
            layer.Color.Index = 4;

            // optionally we can add the new layer to the document, if not the new layer will be added to the Layers collection when the insert entity is added to the document
            // in case a new layer is found in the list the add method will return the layer already stored in the list
            // this behavior is similar for all TableObject elements, all table object names must be unique (case insensitive)
            layer = dxf.Layers.Add(layer);

            // assign the new layer to the insert
            insert1.Layer = layer;

            // add the entity to the document
            dxf.AddEntity(insert1);

            // create a second insert entity
            // the constructor will automatically reposition the insert2 attributes to the insert local position
            Insert insert2 = new Insert(block, new Vector3(10, 5, 0));

            // as before now we can change the insert2 attribute value
            insert2.Attributes[0].Value = 34;

            // additionally we can insert extended data information
            XData xdata1 = new XData(new ApplicationRegistry("netDxf"));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata1.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0.0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0.0));
            xdata1.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0.0));
            xdata1.XDataRecord.Add(XDataRecord.CloseControlString);

            insert2.XData.Add(xdata1);
            dxf.AddEntity(insert2);

            // all entities support this feature
            XData xdata2 = new XData(new ApplicationRegistry("MyApplication1"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata2.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata2.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            // multiple extended data entries might be added
            XData xdata3 = new XData(new ApplicationRegistry("MyApplication2"));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata3.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.String, "string record"));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5));
            xdata3.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350));
            xdata3.XDataRecord.Add(XDataRecord.CloseControlString);

            Circle circle = new Circle(Vector3.Zero, 5);
            circle.Layer = new Layer("MyCircleLayer");
            // AutoCad 2000 does not support true colors, in that case an approximated color index will be used instead
            circle.Layer.Color = new AciColor(Color.MediumSlateBlue);
            circle.XData.Add(xdata2);
            circle.XData.Add(xdata3);

            dxf.AddEntity(circle);

            dxf.Save("BlockWithAttributes.dxf");
            DxfDocument dxfLoad = DxfDocument.Load("BlockWithAttributes.dxf");
        }
        private static void MTextEntity()
        {
            TextStyle style = new TextStyle("Arial");

            MText text1 = new MText(Vector2.Zero, 10, 0, style);
            // you can set manually the text value with all available formatting commands
            text1.Value = "{\\C71;\\c10938556;Text} with true color\\P{\\C140;Text} with indexed color";

            MText text2 = new MText(new Vector2(0, 30), 10, 0, style);
            // or use the Write() method
            MTextFormattingOptions op = new MTextFormattingOptions(text2.Style);
            op.Color = new AciColor(188, 232, 166); // using true color
            text2.Write("Text", op);
            op.Color = null; // set color to the default defined in text2.Style
            text2.Write(" with true color");
            text2.EndParagraph();
            op.Color = new AciColor(140); // using index color
            text2.Write("Text", op); // set color to the default defined in text2.Style
            op.Color = null;
            text2.Write(" with indexed color");

            // both text1 and text2 should yield to the same result
            DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010);
            dxf.AddEntity(text1);
            dxf.AddEntity(text2);

            dxf.Save("MText format.dxf");

            // now you can retrieve the MText text value without any formatting codes, control characters like tab '\t' will be preserved in the result,
            // the new paragraph command "\P" will be converted to new line feed '\r\n'.
            Console.WriteLine(text1.PlainText());
            Console.WriteLine();
            Console.WriteLine(text2.PlainText());
            Console.WriteLine();
            Console.WriteLine("Press a key to finish...");
            Console.ReadKey();

        }
Beispiel #16
0
        /// <summary>
        /// Initializes a new instance of the <c>AttributeDefiniton</c> class.
        /// </summary>
        /// <param name="tag">Attribute identifier, the parameter <c>id</c> string cannot contain spaces.</param>
        /// <param name="textHeight">Height of the attribute definition text.</param>
        /// <param name="style">Attribute <see cref="TextStyle">text style</see>.</param>
        public AttributeDefinition(string tag, double textHeight, TextStyle style)
            : base(EntityType.AttributeDefinition, DxfObjectCode.AttributeDefinition)
        {
            if (string.IsNullOrEmpty(tag))
                throw new ArgumentNullException(nameof(tag));

            if (tag.Contains(" "))
                throw new ArgumentException("The tag string cannot contain spaces.", nameof(tag));
            this.tag = tag;
            this.flags = AttributeFlags.Visible;
            this.prompt = string.Empty;
            this.value = null;
            this.position = Vector3.Zero;
            if (style == null)
                throw new ArgumentNullException(nameof(style));
            this.style = style;
            if (textHeight <= 0.0)
                throw new ArgumentOutOfRangeException(nameof(textHeight), this.value, "The attribute definition text height must be greater than zero.");
            this.height = textHeight;
            this.widthFactor = style.WidthFactor;
            this.obliqueAngle = style.ObliqueAngle;
            this.rotation = 0.0;
            this.alignment = TextAlignment.BaselineLeft;
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <c>LinetypeShapeSegment</c> class.
 /// </summary>
 /// <param name="text">Text to display on the linetype segment.</param>
 /// <param name="style">Name of the TextStyle.</param>
 /// <param name="length">Dash, dot, or space length of the linetype segment.</param>
 public LinetypeTextSegment(string text, TextStyle style, double length) : this(text, style, length, Vector2.Zero, LinetypeSegmentRotationType.Relative, 0.0, 1.0)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <c>DimensionStyle</c> class.
 /// </summary>
 public DimensionStyle(string name)
     : base(name, DxfObjectCode.DimStyle, true)
 {
     this.reserved  = name.Equals("Standard", StringComparison.OrdinalIgnoreCase);
     this.textStyle = TextStyle.Default;
 }
        private static void Text()
        {
            // use a font that has support for Chinese characters
            TextStyle textStyle = new TextStyle("Chinese text", "simsun.ttf");

            // for dxf database version 2007 and later you can use directly the characters,
            DxfDocument dxf1 = new DxfDocument(DxfVersion.AutoCad2010);
            Text text1 = new Text("这是中国文字", Vector2.Zero, 10, textStyle);
            MText mtext1 = new MText("这是中国文字", new Vector2(0, 30), 10, 0, textStyle);
            dxf1.AddEntity(text1);
            dxf1.AddEntity(mtext1);
            dxf1.Save("textCad2010.dxf");

            foreach (Text text in dxf1.Texts)
            {
                Console.WriteLine(text.Value);
            }
            foreach (MText text in dxf1.MTexts)
            {
                Console.WriteLine(text.Value);
            }

            Console.WriteLine("Press a key to continue...");
            Console.ReadLine();

            DxfDocument loadDxf = DxfDocument.Load("textCad2010.dxf");

            // for previous version (this method will also work for later ones) you will need to supply the unicode value (U+value),
            // you can get this value with the Windows Character Map application
            DxfDocument dxf2 = new DxfDocument(DxfVersion.AutoCad2010);
            Text text2 = new Text("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", Vector2.Zero, 10, textStyle);
            MText mtext2 = new MText("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", new Vector2(0, 30), 10, 0, textStyle);
            dxf2.AddEntity(text2);
            dxf2.AddEntity(mtext2);
            dxf2.Save("textCad2000.dxf");
        }
Beispiel #20
0
        protected virtual TextStyle OnLinetypeTextSegmentStyleChangedEvent(TextStyle oldTextStyle, TextStyle newTextStyle)
        {
            LinetypeTextSegmentStyleChangedEventHandler ae = this.LinetypeTextSegmentStyleChanged;

            if (ae != null)
            {
                TableObjectChangedEventArgs <TextStyle> eventArgs = new TableObjectChangedEventArgs <TextStyle>(oldTextStyle, newTextStyle);
                ae(this, eventArgs);
                return(eventArgs.NewValue);
            }
            return(newTextStyle);
        }
        private static void WriteNoAsciiText()
        {
            TextStyle textStyle = new TextStyle("Arial.ttf");
            DxfDocument dxf = new DxfDocument();
            dxf.DrawingVariables.LastSavedBy = "ЉЊЋЌЍжзицрлЯ";
            //Text text = new Text("ÁÉÍÓÚ áéíóú Ññ àèìòù âêîôû", Vector2.Zero,10);
            Text text = new Text("ЉЊЋЌЍжзицрлЯ", Vector2.Zero, 10, textStyle);
            MText mtext = new MText("ЉЊЋЌЍжзицрлЯ", new Vector2(0, 50), 10, 0, textStyle);

            dxf.AddEntity(text);
            dxf.AddEntity(mtext);
            foreach (Text t in dxf.Texts)
            {
                Console.WriteLine(t.Value);
            }
            foreach (MText t in dxf.MTexts)
            {
                Console.WriteLine(t.Value);
            }
            Console.WriteLine("Press a key to continue...");
            Console.ReadLine();
            dxf.Save("text1.dxf");

            dxf = DxfDocument.Load("text1.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("text2.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save("text3.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("text4.dxf");

        }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <c>Text</c> class.
 /// </summary>
 /// <param name="text">Text string.</param>
 /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param>
 /// <param name="height">Text height.</param>
 /// <param name="style">Text <see cref="TextStyle">style</see>.</param>
 public Text(string text, Vector3 position, double height, TextStyle style)
     : base(EntityType.Text, DxfObjectCode.Text)
 {
     this.value = text;
     this.position = position;
     this.alignment = TextAlignment.BaselineLeft;
     this.normal = Vector3.UnitZ;
     if (style == null)
         throw new ArgumentNullException("style", "The Text style cannot be null.");
     this.style = style;
     if (height <= 0)
         throw (new ArgumentOutOfRangeException("height", this.value, "The Text height must be greater than zero."));
     this.height = height;
     this.widthFactor = style.WidthFactor;
     this.obliqueAngle = style.ObliqueAngle;
     this.rotation = 0.0;
 }
        private static void AddAndRemove()
        {
            Layer layer1 = new Layer("layer1") { Color = AciColor.Blue };
            Layer layer2 = new Layer("layer2") { Color = AciColor.Green };

            Line line = new Line(new Vector2(0, 0), new Vector2(10, 10));
            line.Layer = layer1;
            Circle circle = new Circle(new Vector2(0, 0), 10);
            circle.Layer = layer2;

            double offset = -0.9;
            Vector3 p1 = new Vector3(1, 2, 0);
            Vector3 p2 = new Vector3(2, 6, 0);
            Line line1 = new Line(p1, p2);
            Vector3 l1;
            Vector3 l2;
            MathHelper.OffsetLine(line1.StartPoint, line1.EndPoint, line1.Normal, offset, out l1, out l2);

            DimensionStyle myStyle = new DimensionStyle("MyDimStyle");
            myStyle.DIMPOST = "<>mm";
            AlignedDimension dim1 = new AlignedDimension(p1, p2, offset, myStyle);

            //text
            TextStyle style = new TextStyle("MyTextStyle", "Arial.ttf");
            Text text = new Text("Hello world!", Vector3.Zero, 10.0f, style)
                            {
                                Layer = new Layer("text")
                                            {
                                                Color = {Index = 8}
                                            }
                            };
            text.Alignment = TextAlignment.TopRight;

            HeaderVariables variables = new HeaderVariables
                                            {
                                                AcadVer = DxfVersion.AutoCad2004
                                            };
            DxfDocument dxf = new DxfDocument();
            dxf.AddEntity(new EntityObject[] {line, circle, dim1, text});
            dxf.Save("before remove.dxf");

            dxf.RemoveEntity(circle);
            dxf.Save("after remove.dxf");

            dxf.AddEntity(circle);
            dxf.Save("after remove and add.dxf");

            dxf.RemoveEntity(dim1);
            dxf.Save("remove dim.dxf");

            dxf.AddEntity(dim1);
            dxf.Save("add dim.dxf");

            DxfDocument dxf2 = DxfDocument.Load("dim block names.dxf");
            dxf2.AddEntity(dim1);
            dxf2.Save("dim block names2.dxf");
        }
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
                throw new ArgumentNullException(nameof(name), "The dimension style name should be at least one character long.");

            this.reserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension lines
            this.dimclrd = AciColor.ByBlock;
            this.dimltype = LineType.ByBlock;
            this.dimlwd = Lineweight.ByBlock;
            this.dimdli = 0.38;
            this.dimdle = 0.0;

            // extension lines
            this.dimclre = AciColor.ByBlock;
            this.dimltex1 = LineType.ByBlock;
            this.dimltex2 = LineType.ByBlock;
            this.dimlwe = Lineweight.ByBlock;
            this.dimse1 = false;
            this.dimse2 = false;
            this.dimexo = 0.0625;
            this.dimexe = 0.18;

            // symbols and arrows
            this.dimasz = 0.18;
            this.dimcen = 0.09;
            this.dimsah = false;
            this.dimldrblk = null;
            this.dimblk = null;
            this.dimblk1 = null;
            this.dimblk2 = null;

            // text
            this.dimtxsty = TextStyle.Default;
            this.dimclrt = AciColor.ByBlock;
            this.dimtxt = 0.18;
            this.dimtad = 1;
            this.dimjust = 0;
            this.dimgap = 0.09;

            // fit
            this.dimscale = 1.0;

            // primary units
            this.dimdec = 2;
            this.dimadec = 0;
            this.dimpost = "<>";
            this.dimtih = 0;
            this.dimtoh = 0;
            this.dimdsep = '.';
            this.dimlfac = 1.0;
            this.dimaunit = AngleUnitType.DecimalDegrees;
            this.dimlunit = LinearUnitType.Decimal;
            this.dimfrac = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros = false;
            this.suppressLinearTrailingZeros = false;
            this.suppressAngularLeadingZeros = false;
            this.suppressAngularTrailingZeros = false;
            this.suppressZeroFeet = true;
            this.suppressZeroInches = true;
            this.dimrnd = 0.0;
        }
        private static void WriteMText()
        {
            DxfDocument dxf = new DxfDocument();

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            //text
            TextStyle style = new TextStyle("Times.ttf");
            //TextStyle style = TextStyle.Default;
            MText mText = new MText(new Vector3(3,2,0), 1.0f, 100.0f, style);
            mText.Layer = new Layer("Multiline Text");
            //mText.Layer.Color.Index = 8;
            mText.Rotation = 0;
            mText.LineSpacingFactor = 1.0;
            mText.ParagraphHeightFactor = 1.0;

            //mText.AttachmentPoint = MTextAttachmentPoint.TopCenter;
            //mText.Write("Hello World!");
            //mText.Write(" we keep writting on the same line.");
            //mText.WriteLine("This text is in a new line");

            //mText.Write("Hello World! ");
            //for (int i = 0; i < 50; i++)
            //{
            //    mText.Write("1234567890");
            //}
            //mText.Write(" This text is over the limit of the 250 character chunk");
            //mText.NewParagraph();
            //mText.Write("This is a text in a new paragraph");
            //mText.Write(" and we continue writing in the previous paragraph");
            //mText.NewParagraph();
            MTextFormattingOptions options = new MTextFormattingOptions(mText.Style);
            options.Bold = true;
            mText.Write("Bold text in mText.Style", options);
            mText.EndParagraph();
            options.Italic = true;
            mText.Write("Bold and italic text in mText.Style", options);
            mText.EndParagraph();
            options.Bold = false;
            options.FontName = "Arial";
            options.Color = AciColor.Blue;
            mText.ParagraphHeightFactor = 2;
            mText.Write("Italic text in Arial", options);
            mText.EndParagraph();
            options.Italic = false;
            options.Color = null; // back to the default text color
            mText.Write("Normal text in Arial with the default paragraph height factor", options);
            mText.EndParagraph();
            mText.ParagraphHeightFactor = 1;
            mText.Write("No formatted text uses mText.Style");
            mText.Write(" and the text continues in the same paragraph.");
            mText.EndParagraph();

            //options.HeightPercentage = 2.5;
            //options.Color = AciColor.Red;
            //options.Overstrike = true;
            //options.Underline = true;
            //options.FontFile = "times.ttf";
            //options.ObliqueAngle = 15;
            //options.CharacterSpacePercentage = 2.35;
            //options.WidthFactor = 1.8;
            
            //for unknown reasons the aligment doesn't seem to change anything
            //mText.Write("Formatted text", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Center;
            //mText.Write("Center", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Top;
            //mText.Write("Top", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Bottom;
            //mText.Write("Bottom", options);

            mText.XData.Add(xdata);
            
            dxf.AddEntity(mText);

            dxf.Save("MText sample.dxf");

        }
Beispiel #26
0
        /// <summary>
        /// 绘制订单信息块
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        /// <param name="boxWidth"></param>
        /// <param name="configurations"></param>
        public static void Draw(DxfDocument dxf, Location location,float boxWidth, OrderEntity orderEntity)
        {
            float factor = 0.6f;
            Vector3f v1 = new Vector3f(location.X,location.Y,location.Z);
            Vector3f v2 = new Vector3f(location.X + boxWidth, location.Y, location.Z);
            Vector3f v3 = new Vector3f(location.X + boxWidth, location.Y + 40.0f * factor, location.Z);
            Vector3f v4 = new Vector3f(location.X, location.Y + 40.0f * factor, location.Z);

            Vector3f v5 = new Vector3f(location.X, location.Y + 10.0f * factor, location.Z);
            Vector3f v6 = new Vector3f(location.X + boxWidth / 4, location.Y + 10.0f * factor, location.Z);
            Vector3f v7 = new Vector3f(location.X + boxWidth / 2, location.Y + 10.0f * factor, location.Z);
            Vector3f v8 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 10.0f * factor, location.Z);
            Vector3f v9 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 10.0f * factor, location.Z);

            Vector3f v10 = new Vector3f(location.X + boxWidth / 4, location.Y + 20.0f * factor, location.Z);
            Vector3f v11 = new Vector3f(location.X + boxWidth / 2, location.Y + 20.0f * factor, location.Z);
            Vector3f v12 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 20.0f * factor, location.Z);
            Vector3f v13 = new Vector3f(location.X + boxWidth * 7 / 8, location.Y + 20.0f * factor, location.Z);
            Vector3f v14 = new Vector3f(location.X + boxWidth, location.Y + 20.0f * factor, location.Z);

            Vector3f v15 = new Vector3f(location.X + boxWidth / 4, location.Y + 40.0f * factor, location.Z);
            Vector3f v16 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y + 40.0f * factor, location.Z);

            Vector3f v17 = new Vector3f(location.X + boxWidth / 4, location.Y, location.Z);
            Vector3f v18 = new Vector3f(location.X + boxWidth / 2, location.Y, location.Z);
            Vector3f v19 = new Vector3f(location.X + boxWidth * 3 / 4, location.Y, location.Z);

            Vector3f v20 = new Vector3f(location.X + boxWidth, location.Y + 10.0f * factor, location.Z);

            Layer layer = new Layer("line");

            //横向四道
            Line line12 = new Line(v1, v2);
            line12.Layer = layer;
            dxf.AddEntity(line12);

            Line line520 = new Line(v5, v20);
            line520.Layer = layer;
            dxf.AddEntity(line520);

            Line line1014 = new Line(v10, v14);
            line1014.Layer = layer;
            dxf.AddEntity(line1014);

            Line line43 = new Line(v4, v3);
            line43.Layer = layer;
            dxf.AddEntity(line43);

            //纵向6道
            Line line41 = new Line(v4, v1);
            line41.Layer = layer;
            dxf.AddEntity(line41);

            Line line1517 = new Line(v15, v17);
            line1517.Layer = layer;
            dxf.AddEntity(line1517);

            Line line1118 = new Line(v11, v18);
            line1118.Layer = layer;
            dxf.AddEntity(line1118);

            Line line1619 = new Line(v16, v19);
            line1619.Layer = layer;
            dxf.AddEntity(line1619);

            Line line139 = new Line(v13, v9);
            line139.Layer = layer;
            dxf.AddEntity(line139);

            Line line32= new Line(v3, v2);
            line32.Layer = layer;
            dxf.AddEntity(line32);

            //文字

            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Vector3f vt1 = new Vector3f(v1.X + 1.0f, v1.Y + 2.5f, v1.Z);
            Text t1 = new Text("Celebrity 1.0.0", vt1, 2.0f, style);
            t1.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t1);

            Vector3f vt2 = new Vector3f(v17.X + 1.0f, v17.Y + 2.5f, v1.Z);
            Text t2 = new Text("PREPARER:  "+orderEntity.Preparer, vt2, 2.0f, style);
            t2.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t2);

            Vector3f vt3 = new Vector3f(v18.X + 1.0f, v18.Y + 2.5f, v1.Z);
            Text t3 = new Text("ENGINEER:  "+orderEntity.Engineer, vt3, 2.0f, style);
            t3.Layer = layer;
            t3.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t3);

            Vector3f vt4 = new Vector3f(v19.X + 1.0f, v19.Y + 2.5f, v1.Z);
            Text t4 = new Text("SHIP ORDER NO:  "+orderEntity.ShipOrderNo, vt4, 2.0f, style);
            t4.Layer = layer;
            t4.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t4);

            Vector3f vt5 = new Vector3f(v4.X + 1.0f, v10.Y + 2.5f, v1.Z);
            Text t5= new Text("     AAON  COIL  PRODUCTS  inc.", vt5, 3.0f, style);
            t5.Layer = layer;
            t5.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t5);

            Vector3f vt6 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v1.Z);
            Text t6 = new Text("LONGVIEW  TEXAS", vt6, 2.0f, style);
            t6.Layer = layer;
            t6.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t6);

            Vector3f vt7 = new Vector3f(v6.X + 1.0f, v6.Y + 2.5f, v1.Z);
            Text t7 = new Text("PURCHASER:  " + orderEntity.Purchaser, vt7, 2.0f, style);
            t7.Layer = layer;
            t7.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t7);

            Vector3f vt8 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v1.Z);
            Text t8 = new Text("PURCHASE ORDER:  " + orderEntity.PurchaseOrder, vt8, 2.0f, style);
            t8.Layer = layer;
            t8.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t8);

            Vector3f vt9 = new Vector3f(v8.X + 1.0f, v8.Y + 2.5f, v1.Z);
            Text t9 = new Text("SERIAL NO:  " + orderEntity.SeriaNo, vt9, 2.0f, style);
            t9.Layer = layer;
            t9.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t9);

            Vector3f vt10 = new Vector3f(v9.X + 1.0f, v9.Y + 2.5f, v1.Z);
            Text t10 = new Text("DATE: "+DateTime.Now.ToShortDateString(), vt10, 2.0f, style);
            t10.Layer = layer;
            t10.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t10);

            Vector3f vt11 = new Vector3f(v15.X + 1.0f, v15.Y - 7.5f, v1.Z);
            Text t11 = new Text("JOB NAME:", vt11, 2.0f, style);
            t11.Layer = layer;
            t11.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t11);

            Vector3f vt12 = new Vector3f(v10.X + 10.0f, v10.Y + 2.5f, v1.Z);
            Text t12 = new Text(orderEntity.JobName, vt12, 2.0f, style);
            t12.Layer = layer;
            t12.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t12);

            Vector3f vt13 = new Vector3f(v16.X + 1.0f, v16.Y - 7.5f, v1.Z);
            Text t13 = new Text("UNIT TAG:", vt13, 2.0f, style);
            t13.Layer = layer;
            t13.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t13);

            Vector3f vt14 = new Vector3f(v12.X + 20.0f, v12.Y + 2.5f, v1.Z);
            Text t14 = new Text(orderEntity.UnitTag, vt14, 2.0f, style);
            t14.Layer = layer;
            t14.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t14);
        }
Beispiel #27
0
        /// <inheritdoc/>
        public override void Draw(object dc, TextShape text, double dx, double dy, object db, object r)
        {
            var dxf = dc as DxfDocument;

            var properties = (ImmutableArray <Property>)db;
            var record     = (Record)r;
            var tbind      = text.BindText(properties, record);

            if (string.IsNullOrEmpty(tbind))
            {
                return;
            }

            var style             = text.Style;
            var stroke            = ToColor(style.Stroke);
            var strokeTansparency = ToTransparency(style.Stroke);

            var    attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var    rect = Spatial.Rect2.FromPoints(
                text.TopLeft.X,
                text.TopLeft.Y,
                text.BottomRight.X,
                text.BottomRight.Y,
                dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
            default:
            case TextHAlignment.Left:
                x = rect.X;
                break;

            case TextHAlignment.Center:
                x = rect.X + rect.Width / 2.0;
                break;

            case TextHAlignment.Right:
                x = rect.X + rect.Width;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case TextVAlignment.Top:
                y = rect.Y;
                break;

            case TextVAlignment.Center:
                y = rect.Y + rect.Height / 2.0;
                break;

            case TextVAlignment.Bottom:
                y = rect.Y + rect.Height;
                break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
            default:
            case TextVAlignment.Top:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.TopLeft;
                    break;

                case TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.TopCenter;
                    break;

                case TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.TopRight;
                    break;
                }
                break;

            case TextVAlignment.Center:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                    break;

                case TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                    break;

                case TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.MiddleRight;
                    break;
                }
                break;

            case TextVAlignment.Bottom:
                switch (text.Style.TextStyle.TextHAlignment)
                {
                default:
                case TextHAlignment.Left:
                    attachmentPoint = MTextAttachmentPoint.BottomLeft;
                    break;

                case TextHAlignment.Center:
                    attachmentPoint = MTextAttachmentPoint.BottomCenter;
                    break;

                case TextHAlignment.Right:
                    attachmentPoint = MTextAttachmentPoint.BottomRight;
                    break;
                }
                break;
            }

            var ts       = new netDxf.Tables.TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * _targetDpi / _sourceDpi,
                rect.Width,
                ts);

            dxfMText.AttachmentPoint = attachmentPoint;

            var options = new MTextFormattingOptions(dxfMText.Style);
            var fs      = text.Style.TextStyle.FontStyle;

            if (fs != null)
            {
                options.Bold          = fs.Flags.HasFlag(FontStyleFlags.Bold);
                options.Italic        = fs.Flags.HasFlag(FontStyleFlags.Italic);
                options.Underline     = fs.Flags.HasFlag(FontStyleFlags.Underline);
                options.StrikeThrough = fs.Flags.HasFlag(FontStyleFlags.Strikeout);
            }

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color    = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            dxf.AddEntity(dxfMText);
        }
Beispiel #28
0
 /// <summary>
 /// Initializes a new instance of the <c>MText</c> class.
 /// </summary>
 /// <param name="text">Text string.</param>
 /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param>
 /// <param name="height">Text height.</param>
 /// <param name="rectangleWidth">Reference rectangle width.</param>
 /// <param name="style">Text <see cref="TextStyle">style</see>.</param>
 public MText(string text, Vector2 position, double height, double rectangleWidth, TextStyle style)
     : this(text, new Vector3(position.X, position.Y, 0.0), height, rectangleWidth, style)
 {
 }
Beispiel #29
0
 /// <summary>
 /// Initializes a new instance of the <c>Text</c> class.
 /// </summary>
 /// <param name="text">Text string.</param>
 /// <param name="basePoint">Text base <see cref="Vector3d">point</see>.</param>
 /// <param name="height">Text height.</param>
 /// <param name="style">Text <see cref="TextStyle">style</see>.</param>
 public Text(string text, Vector3d basePoint, float height, TextStyle style)
     : base(DxfObjectCode.Text)
 {
     this.value = text;
     this.basePoint = basePoint;
     this.alignment = TextAlignment.BaselineLeft;
     this.layer = Layer.Default;
     this.color = AciColor.ByLayer;
     this.lineType = LineType.ByLayer;
     this.normal = Vector3d.UnitZ;
     this.style = style;
     this.height = height;
     this.widthFactor = style.WidthFactor;
     this.obliqueAngle = style.ObliqueAngle;
     this.rotation = 0.0f;
 }
Beispiel #30
0
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "The dimension style name should be at least one character long.");
            }

            this.IsReserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension and extension lines
            this.dimclrd  = AciColor.ByBlock;
            this.dimltype = Linetype.ByBlock;
            this.dimlwd   = Lineweight.ByBlock;
            this.dimdle   = 0.0;
            this.dimdli   = 0.38;
            this.dimsd1   = false;
            this.dimsd2   = false;

            this.dimclre  = AciColor.ByBlock;
            this.dimltex1 = Linetype.ByBlock;
            this.dimltex2 = Linetype.ByBlock;
            this.dimlwe   = Lineweight.ByBlock;
            this.dimse1   = false;
            this.dimse2   = false;
            this.dimexo   = 0.0625;
            this.dimexe   = 0.18;
            this.dimfxlon = false;
            this.dimfxl   = 1.0;

            // symbols and arrows
            this.dimldrblk = null;
            this.dimblk1   = null;
            this.dimblk2   = null;
            this.dimasz    = 0.18;
            this.dimcen    = 0.09;

            // text
            this.dimtxsty        = TextStyle.Default;
            this.dimclrt         = AciColor.ByBlock;
            this.dimtfillclr     = null;
            this.dimtxt          = 0.18;
            this.dimtad          = DimensionStyleTextVerticalPlacement.Centered;
            this.dimjust         = DimensionStyleTextHorizontalPlacement.Centered;
            this.dimgap          = 0.09;
            this.dimtih          = false;
            this.dimtoh          = false;
            this.dimtxtdirection = DimensionStyleTextDirection.LeftToRight;
            this.dimtfac         = 1.0;

            // fit
            this.dimtofl  = false;
            this.dimsoxd  = true;
            this.dimscale = 1.0;
            this.dimatfit = DimensionStyleFitOptions.BestFit;
            this.dimtix   = false;
            this.dimtmove = DimensionStyleFitTextMove.BesideDimLine;

            // primary units
            this.dimdec    = 4;
            this.dimadec   = 0;
            this.dimPrefix = string.Empty;
            this.dimSuffix = string.Empty;
            this.dimdsep   = '.';
            this.dimlfac   = 1.0;
            this.dimaunit  = AngleUnitType.DecimalDegrees;
            this.dimlunit  = LinearUnitType.Decimal;
            this.dimfrac   = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros   = false;
            this.suppressLinearTrailingZeros  = false;
            this.suppressZeroFeet             = true;
            this.suppressZeroInches           = true;
            this.suppressAngularLeadingZeros  = false;
            this.suppressAngularTrailingZeros = false;
            this.dimrnd = 0.0;

            // alternate units
            this.alternateUnits = new DimensionStyleAlternateUnits();

            // tolerances
            this.tolerances = new DimensionStyleTolerances();
        }
Beispiel #31
0
        /// <summary>
        /// 绘制左下角区域的Section块
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        /// <param name="configurations"></param>
        public static void Draw(DxfDocument dxf, Location location,SectionEntity sectionEntity)
        {
            float factor=0.6f;
            Vector3f v1 = new Vector3f(location.X, location.Y + 40.0f*factor, location.Z);
            Vector3f v2 = new Vector3f(location.X + 50.0f * factor, location.Y + 40.0f * factor, location.Z);
            Vector3f v3 = new Vector3f(location.X + 90.0f * factor, location.Y + 40.0f * factor, location.Z);
            Vector3f v4 = new Vector3f(location.X + 140.0f * factor, location.Y + 40.0f * factor, location.Z);

            Vector3f v5 = new Vector3f(location.X, location.Y + 50.0f * factor, location.Z);
            Vector3f v6 = new Vector3f(location.X + 140.0f * factor, location.Y + 50.0f * factor, location.Z);

            Vector3f v7 = new Vector3f(location.X, location.Y + 60.0f * factor, location.Z);
            Vector3f v8 = new Vector3f(location.X + 140.0f * factor, location.Y + 60.0f * factor, location.Z);

            Vector3f v9 = new Vector3f(location.X, location.Y + 70.0f * factor, location.Z);
            Vector3f v10 = new Vector3f(location.X + 50.0f * factor, location.Y + 70.0f * factor, location.Z);
            Vector3f v11 = new Vector3f(location.X + 90.0f * factor, location.Y + 70.0f * factor, location.Z);
            Vector3f v12 = new Vector3f(location.X + 140.0f * factor, location.Y + 70.0f * factor, location.Z);

            Layer layer = new Layer("line");

            //横向四道
            Line line14 = new Line(v1, v4);
            line14.Layer = layer;
            dxf.AddEntity(line14);

            Line line56 = new Line(v5, v6);
            line56.Layer = layer;
            dxf.AddEntity(line56);

            Line line78 = new Line(v7, v8);
            line78.Layer = layer;
            dxf.AddEntity(line78);

            Line line912 = new Line(v9, v12);
            line912.Layer = layer;
            dxf.AddEntity(line912);

            //纵向四道
            Line line91 = new Line(v9, v1);
            line91.Layer = layer;
            dxf.AddEntity(line91);

            Line line210 = new Line(v2, v10);
            line210.Layer = layer;
            dxf.AddEntity(line210);

            Line line311 = new Line(v3, v11);
            line311.Layer = layer;
            dxf.AddEntity(line311);

            Line line412 = new Line(v4, v12);
            line412.Layer = layer;
            dxf.AddEntity(line412);

            TextStyle style = new TextStyle("True type font", "Arial.ttf");
            Vector3f vt1 = new Vector3f(v1.X+1.0f, v1.Y+2.5f, v1.Z);
            Text t1 = new Text("COIL", vt1, 2.0f, style);
            t1.Layer = layer;
            t1.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t1);

            Vector3f vt2 = new Vector3f(v2.X + 1.0f, v2.Y + 2.5f, v2.Z);
            Text t2 = new Text("CLF", vt2, 2.0f, style);
            t2.Layer = layer;
            t2.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t2);

            Vector3f vt3 = new Vector3f(v3.X + 1.0f, v3.Y + 2.5f, v3.Z);
            Text t3 = new Text(sectionEntity.CoolValue, vt3, 2.0f, style);
            t3.Layer = layer;
            t3.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t3);

            Vector3f vt4 = new Vector3f(v5.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t4 = new Text("FILTER", vt4, 2.0f, style);
            t4.Layer = layer;
            t4.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t4);

            Vector3f vt5 = new Vector3f(v2.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t5 = new Text("FTA", vt5, 2.0f, style);
            t5.Layer = layer;
            t5.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t5);

            Vector3f vt6 = new Vector3f(v3.X + 1.0f, v5.Y + 2.5f, v5.Z);
            Text t6 = new Text(sectionEntity.FilterValue, vt6, 2.0f, style);
            t6.Layer = layer;
            t6.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t6);

            Vector3f vt7 = new Vector3f(v7.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t7 = new Text("SECTION", vt7, 2.0f, style);
            t7.Layer = layer;
            t7.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t7);

            Vector3f vt8 = new Vector3f(v2.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t8 = new Text("MODULE", vt8, 2.0f, style);
            t8.Layer = layer;
            t8.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t8);

            Vector3f vt9 = new Vector3f(v3.X + 1.0f, v7.Y + 2.5f, v7.Z);
            Text t9 = new Text("CLEARANCE", vt9, 2.0f, style);
            t9.Layer = layer;
            t9.Alignment = TextAlignment.TopLeft;
            dxf.AddEntity(t9);
        }
Beispiel #32
0
        private TextStyle GetTextStyle(string name)
        {
            if (this.textStyles.ContainsKey(name))
            {
                return this.textStyles[name];
            }

            //just in case the text style has not been defined in the table section
            var textStyle = new TextStyle(name, "Arial");
            this.textStyles.Add(textStyle.Name, textStyle);
            return textStyle;
        }
Beispiel #33
0
 /// <summary>
 /// Initializes a new instance of the <c>MText</c> class.
 /// </summary>
 /// <param name="text">Text string.</param>
 /// <param name="position">Text <see cref="Vector2">position</see> in world coordinates.</param>
 /// <param name="height">Text height.</param>
 /// <param name="rectangleWidth">Reference rectangle width.</param>
 /// <param name="style">Text <see cref="TextStyle">style</see>.</param>
 public MText(string text, Vector3 position, double height, double rectangleWidth, TextStyle style)
     : base(EntityType.MText, DxfObjectCode.MText)
 {
     this.value = text;
     this.position = position;
     this.attachmentPoint = MTextAttachmentPoint.TopLeft;
     if (style == null)
         throw new ArgumentNullException(nameof(style), "The Text style cannot be null.");
     this.style = style;
     this.rectangleWidth = rectangleWidth;
     if (height <= 0.0)
         throw new ArgumentOutOfRangeException(nameof(height), this.value, "The MText height must be greater than zero.");
     this.height = height;
     this.lineSpacing = 1.0;
     this.paragraphHeightFactor = 1.0;
     this.lineSpacingStyle = MTextLineSpacingStyle.AtLeast;
     this.rotation = 0.0;
 }
Beispiel #34
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Test2d.XText text, double dx, double dy, ImmutableArray<Test2d.ShapeProperty> db, Test2d.Record r)
        {
            var _doc = doc as DxfDocument;

            var tbind = text.BindToTextProperty(db, r);
            if (string.IsNullOrEmpty(tbind))
                return;

            var style = text.Style;
            var stroke = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);

            var attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var rect = Test2d.Rect2.Create(text.TopLeft, text.BottomRight, dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
                default:
                case Test2d.TextHAlignment.Left:
                    x = rect.X;
                    break;
                case Test2d.TextHAlignment.Center:
                    x = rect.X + rect.Width / 2.0;
                    break;
                case Test2d.TextHAlignment.Right:
                    x = rect.X + rect.Width;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Test2d.TextVAlignment.Top:
                    y = rect.Y;
                    break;
                case Test2d.TextVAlignment.Center:
                    y = rect.Y + rect.Height / 2.0;
                    break;
                case Test2d.TextVAlignment.Bottom:
                    y = rect.Y + rect.Height;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Test2d.TextVAlignment.Top:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.TopLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.TopCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.TopRight;
                            break;
                    }
                    break;
                case Test2d.TextVAlignment.Center:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.MiddleRight;
                            break;
                    }
                    break;
                case Test2d.TextVAlignment.Bottom:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.BottomLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.BottomCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.BottomRight;
                            break;
                    }
                    break;
            }

            var ts = new TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * 72.0 / 96.0,
                rect.Width,
                ts);
            dxfMText.AttachmentPoint = attachmentPoint;

            var fs = text.Style.TextStyle.FontStyle;
            var options = new MTextFormattingOptions(dxfMText.Style);
            options.Bold = fs.Flags.HasFlag(Test2d.FontStyleFlags.Bold);
            options.Italic = fs.Flags.HasFlag(Test2d.FontStyleFlags.Italic);
            options.Underline = fs.Flags.HasFlag(Test2d.FontStyleFlags.Underline);
            options.StrikeThrough = fs.Flags.HasFlag(Test2d.FontStyleFlags.Strikeout);

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            _doc.AddEntity(dxfMText);
        }
Beispiel #35
0
        internal DimensionStyle(string name, bool checkName)
            : base(name, DxfObjectCode.DimStyle, checkName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name), "The dimension style name should be at least one character long.");
            }

            this.IsReserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase);

            // dimension lines
            this.dimclrd  = AciColor.ByBlock;
            this.dimltype = Linetype.ByBlock;
            this.dimlwd   = Lineweight.ByBlock;
            this.dimsd    = false;
            this.dimdli   = 0.38;
            this.dimdle   = 0.0;

            // extension lines
            this.dimclre  = AciColor.ByBlock;
            this.dimltex1 = Linetype.ByBlock;
            this.dimltex2 = Linetype.ByBlock;
            this.dimlwe   = Lineweight.ByBlock;
            this.dimse1   = false;
            this.dimse2   = false;
            this.dimexo   = 0.0625;
            this.dimexe   = 0.18;

            // symbols and arrows
            this.dimasz    = 0.18;
            this.dimcen    = 0.09;
            this.dimldrblk = null;
            this.dimblk1   = null;
            this.dimblk2   = null;

            // text
            this.dimtxsty = TextStyle.Default;
            this.dimclrt  = AciColor.ByBlock;
            this.dimtxt   = 0.18;
            this.dimtad   = 1;
            this.dimjust  = 0;
            this.dimgap   = 0.09;

            // fit
            this.dimscale = 1.0;

            // primary units
            this.dimdec    = 2;
            this.dimadec   = 0;
            this.dimPrefix = string.Empty;
            this.dimSuffix = string.Empty;
            this.dimtih    = 0;
            this.dimtoh    = 0;
            this.dimdsep   = '.';
            this.dimlfac   = 1.0;
            this.dimaunit  = AngleUnitType.DecimalDegrees;
            this.dimlunit  = LinearUnitType.Decimal;
            this.dimfrac   = FractionFormatType.Horizontal;
            this.suppressLinearLeadingZeros   = false;
            this.suppressLinearTrailingZeros  = false;
            this.suppressAngularLeadingZeros  = false;
            this.suppressAngularTrailingZeros = false;
            this.suppressZeroFeet             = true;
            this.suppressZeroInches           = true;
            this.dimrnd = 0.0;
        }
Beispiel #36
0
 static TextStyle()
 {
     standard = new TextStyle("Standard", "simplex.shx");
 }
Beispiel #37
0
        private static LinetypeSegment ReadLineTypeComplexSegment(string data, double length)
        {
            // the data is enclosed in brackets
            if (data[0] != '[' || data[data.Length - 1] != ']')
            {
                return(null);
            }

            // the first data item in a complex linetype definition segment
            // can be a shape name or a text string, the last always is enclosed in ""
            LinetypeSegmentType type = data[1] != '"' ? LinetypeSegmentType.Shape : LinetypeSegmentType.Text;

            data = data.Substring(1, data.Length - 2);

            string  name;
            string  style;
            Vector2 position = Vector2.Zero;
            LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative;
            double rotation = 0.0;
            double scale    = 0.1;

            string[] tokens = data.Split(',');

            // at least two items must be present the shape name and file
            if (tokens.Length < 2)
            {
                return(null);
            }
            name  = tokens[0].Trim('"');
            style = tokens[1];
            for (int i = 2; i < tokens.Length; i++)
            {
                string value = tokens[i].Remove(0, 2);
                if (tokens[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double x;
                    if (double.TryParse(value, out x))
                    {
                        position.X = x;
                    }
                }
                else if (tokens[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double y;
                    if (double.TryParse(value, out y))
                    {
                        position.Y = y;
                    }
                }
                else if (tokens[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase))
                {
                    double s;
                    if (double.TryParse(value, out s))
                    {
                        scale = s;
                    }
                    if (scale <= 0.0)
                    {
                        scale = 0.1;
                    }
                }
                else if (tokens[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Relative;
                    rotation     = ReadRotation(value);
                }
                else if (tokens[i].StartsWith("Q=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Absolute;
                    rotation     = ReadRotation(value);
                }
                else if (tokens[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Upright;
                    rotation     = ReadRotation(value);
                }
            }

            if (type == LinetypeSegmentType.Text)
            {
                TextStyle textStyle = new TextStyle(style);
                return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale));
            }
            if (type == LinetypeSegmentType.Shape)
            {
                ShapeStyle shapeStyle = new ShapeStyle(style);
                return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale));
            }

            return(null);
        }
Beispiel #38
0
        /// <summary>
        /// 门把手绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="location"></param>
        public static void Draw(DxfDocument dxf, Location location)
        {
            float factor = 0.05f;
             float distance = 30;
            //底部小圆的圆心
             Vector3f sCircle = new Vector3f(location.X + 10 * factor, location.Y, location.Z);
            //上部同心圆圆心
             Vector3f bCircle = new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance*factor, location.Z);

             double alpha = Math.Asin(3 / distance);
             double beta = Math.Acos(0.8);

             Vector3f v1 = new Vector3f(
                 location.X + 10 * factor - float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                 location.Z);

             Vector3f v2 = new Vector3f(
                  location.X + 10 * factor + float.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                  location.Y + 5 * factor - float.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                  location.Z);

             Vector3f v4 = new Vector3f(
                 location.X + 10 * factor -float.Parse((8*factor* Math.Cos(alpha)).ToString()),
                 location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
                 location.Z
                 );

             Vector3f v5 = new Vector3f(
             location.X + 10 * factor  + float.Parse((8*factor*Math.Cos(alpha)).ToString()),
             location.Y + 5 * factor + distance * factor - float.Parse((8 * factor * Math.Sin(alpha)).ToString()),
             location.Z
             );
             Layer layer = new Layer("line");
             Line line14 = new Line(v1, v4);
             line14.Layer = layer;
             line14.Layer.Color.Index = 6;
             dxf.AddEntity(line14);

             Line line25 = new Line(v2, v5);
             line25.Layer = new Layer("line");
             line25.Layer = layer;
             dxf.AddEntity(line25);

             //arc
             Arc arc = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor, location.Z),
                 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI));
             arc.Layer = layer;
             dxf.AddEntity(arc);

             //arcup
             Arc arcup = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI));
             arcup.Layer = layer;
             dxf.AddEntity(arcup);

             //arcround
             Arc arcround = new Arc(
                 new Vector3f(location.X + 10 * factor, location.Y + 5 * factor + distance * factor, location.Z),
                 10 * factor,
                 Convert.ToInt32(-(alpha +beta) * 180 / Math.PI),
                 Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI));
             arcround.Layer = layer;
             dxf.AddEntity(arcround);

             //circle
             Vector3f extrusion = new Vector3f(0, 0, 1);
             Vector3f centerWCS = new Vector3f(location.X+10*factor, location.Y+5*factor+distance*factor, location.Z);
             Vector3d centerOCS = MathHelper.Transform((Vector3d)centerWCS,
                                                       (Vector3d)extrusion,
                                                       MathHelper.CoordinateSystem.World,
                                                       MathHelper.CoordinateSystem.Object);

             Circle circle = new Circle((Vector3f)centerOCS, 7*factor);
             circle.Layer = layer;
             circle.LineType = LineType.Continuous;
             circle.Normal = extrusion;
             dxf.AddEntity(circle);

             //上部同心圆圆心
             Vector3f t1 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.7f,
                 location.Z);
             Vector3f t2 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.5f,
                 location.Z);
             Vector3f t3 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.3f,
                 location.Z);
             Vector3f t4 = new Vector3f(
                 location.X + 8 * factor,
                 location.Y + 5 * factor + (distance - 7) * factor * 0.1f,
                 location.Z);

             //text
             TextStyle style = new TextStyle("True type font", "Arial.ttf");
             Text text1 = new Text("A", t1, 0.2f, style);
             text1.Layer = layer;
             text1.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text1);

             //text
             Text text2 = new Text("A", t2, 0.2f, style);
             text2.Layer = layer;
             text2.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text2);

             //text
             Text text3 = new Text("O", t3, 0.2f, style);
             text3.Layer = layer;
             text3.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text3);

             //text
             Text text4 = new Text("N", t4, 0.2f, style);
             text4.Layer = layer;
             text4.Alignment = TextAlignment.TopLeft;
             dxf.AddEntity(text4);
        }
Beispiel #39
0
        private static LinetypeSegment ReadLineTypeComplexSegment(string[] data, double length)
        {
            // the data is enclosed in brackets
            Debug.Assert(data[0][0] == '[' || data[data.Length - 1][data[data.Length - 1].Length - 1] == ']', "The data is enclosed in brackets.");

            // the first data item in a complex linetype definition segment
            // can be a shape name or a text string, the last always is enclosed in ""
            LinetypeSegmentType type = data[0][1] == '"' ? LinetypeSegmentType.Text : LinetypeSegmentType.Shape;

            // remove the start and end brackets
            data[0] = data[0].Remove(0, 1);
            data[data.Length - 1] = data[data.Length - 1].Remove(data[data.Length - 1].Length - 1, 1);

            Vector2 position = Vector2.Zero;
            LinetypeSegmentRotationType rotationType = LinetypeSegmentRotationType.Relative;
            double rotation = 0.0;
            double scale    = 0.1;

            // at least two items must be present the shape name and file
            if (data.Length < 2)
            {
                return(null);
            }

            string name  = data[0].Trim('"');
            string style = data[1];

            for (int i = 2; i < data.Length; i++)
            {
                string value = data[i].Remove(0, 2);
                if (data[i].StartsWith("X=", StringComparison.InvariantCultureIgnoreCase))
                {
                    position.X = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                }
                else if (data[i].StartsWith("Y=", StringComparison.InvariantCultureIgnoreCase))
                {
                    position.Y = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                }
                else if (data[i].StartsWith("S=", StringComparison.InvariantCultureIgnoreCase))
                {
                    scale = double.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
                    if (scale <= 0.0)
                    {
                        scale = 0.1;
                    }
                }
                else if (data[i].StartsWith("R=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Relative;
                    rotation     = ReadRotation(value);
                }
                else if (data[i].StartsWith("Q=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Absolute;
                    rotation     = ReadRotation(value);
                }
                else if (data[i].StartsWith("U=", StringComparison.InvariantCultureIgnoreCase))
                {
                    rotationType = LinetypeSegmentRotationType.Upright;
                    rotation     = ReadRotation(value);
                }
            }

            if (type == LinetypeSegmentType.Text)
            {
                // complex text linetype segments only holds the name of the style
                TextStyle textStyle = new TextStyle(style, "simplex.shx");
                return(new LinetypeTextSegment(name, textStyle, length, position, rotationType, rotation, scale));
            }
            if (type == LinetypeSegmentType.Shape)
            {
                ShapeStyle shapeStyle = new ShapeStyle(style);
                return(new LinetypeShapeSegment(name, shapeStyle, length, position, rotationType, rotation, scale));
            }

            return(null);
        }