예제 #1
4
        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");
        }
예제 #2
0
        /*Draw Text*/
        public static void DrawText(netDxf.Entities.Text xTxt, Canvas mainCanvas)
        {
            TextBlock wTxt = new TextBlock();

            /*wTxt.Text = xTxt.Value;*/
            TextUtils.CADTxtToInlineCollection(wTxt.Inlines, xTxt.Value.ToString(), wTxt.FontSize);
            wTxt.FontWeight = FontWeights.Bold;
            wTxt.FontSize   = TypeConverter.PointsToPixels(xTxt.Height);
            wTxt.FontFamily = new FontFamily(xTxt.Style.FontFamilyName);

            Size txtSize = TypeConverter.MeasureString(wTxt, xTxt.Value);

            wTxt.Width  = txtSize.Width;
            wTxt.Height = txtSize.Height;

            wTxt.HorizontalAlignment = HorizontalAlignment.Center;
            wTxt.VerticalAlignment   = VerticalAlignment.Center;
            wTxt.TextAlignment       = System.Windows.TextAlignment.Center;
            wTxt.Foreground          = TypeConverter.AciColorToBrush(xTxt.Color);

            Canvas.SetLeft(wTxt, xTxt.Position.X - wTxt.Width / 2);
            Canvas.SetTop(wTxt, mainCanvas.Height - (xTxt.Position.Y + wTxt.Height / 2));

            mainCanvas.Children.Add(wTxt);
        }
예제 #3
0
파일: ToDXF.cs 프로젝트: lulzzz/Nucleus
        /// <summary>
        /// Convert a Nucleus label to a netDXF text object
        /// </summary>
        /// <param name="label"></param>
        /// <returns></returns>
        public static nDE.Text Convert(Label label)
        {
            var result = new nDE.Text(label.Text, Convert(label.Position), label.TextSize * ConversionScaling);

            result.Alignment = Convert(label.HorizontalSetOut, label.VerticalSetOut);
            SetAttributes(result, label.Attributes);
            return(result);
        }
예제 #4
0
		/*Draw Leader*/
		public static void DrawLeader(Leader xLeader, Canvas mainCanvas)
		{
			Size txtSize = new Size(0, 0);
			/*ajout du texte*/
			if (xLeader.Annotation.Type == EntityType.MText) {
				netDxf.Entities.MText mText = (netDxf.Entities.MText)xLeader.Annotation;
				txtSize = DrawMText(mText, mainCanvas);
			}
			
			if (xLeader.Annotation.Type == EntityType.Text) {
				netDxf.Entities.Text mText = (netDxf.Entities.Text)xLeader.Annotation;
				DrawText(mText, mainCanvas);
			}
			if (xLeader.Annotation.Type == EntityType.Insert) {
				netDxf.Entities.Insert mText = (netDxf.Entities.Insert)xLeader.Annotation;
				DrawInsert(mText, mainCanvas);
			}
			
			
			
			
			
			System.Windows.Shapes.Polyline wPoly = new System.Windows.Shapes.Polyline();
			
			foreach (netDxf.Vector2 xVertex in xLeader.Vertexes) {
				System.Windows.Point myPt = TypeConverter.Vertex2ToPoint(xVertex);
				myPt.Y = mainCanvas.Height - myPt.Y;
				wPoly.Points.Add(myPt);
			}
			System.Windows.Point myPt2 = TypeConverter.Vertex2ToPoint(xLeader.Hook);
			myPt2.Y = mainCanvas.Height - myPt2.Y;
			wPoly.Points.Add(myPt2);
			
			if (txtSize.Width > 0) {
				myPt2.X = myPt2.X + txtSize.Width;
				wPoly.Points.Add(myPt2);
			}
			
			xLeader.Lineweight = Lineweight.W0;
			
			TypeConverter.Entity2Shape(xLeader, wPoly);
			
			if (xLeader.ShowArrowhead == true) {
				System.Windows.Shapes.Polygon arrow = DrawUtils.GetArrowhead(xLeader.Vertexes[0], xLeader.Vertexes[1], mainCanvas);
				TypeConverter.Entity2Shape(xLeader, arrow);
				arrow.StrokeThickness = 0.1;
				arrow.Fill = arrow.Stroke;
				mainCanvas.Children.Add(arrow);
			}
			
			mainCanvas.Children.Add(wPoly);
			
			

			

		}
예제 #5
0
        private EntityObject ExportText(GeoObject.Text text)
        {
            System.Drawing.FontStyle fs = System.Drawing.FontStyle.Regular;
            if (text.Bold)
            {
                fs |= System.Drawing.FontStyle.Bold;
            }
            if (text.Italic)
            {
                fs |= System.Drawing.FontStyle.Italic;
            }
            System.Drawing.Font  font = new System.Drawing.Font(text.Font, 1000.0f, fs);
            netDxf.Entities.Text res  = new netDxf.Entities.Text(text.TextString, Vector2.Zero, text.TextSize * 1000 / font.Height, new TextStyle(text.Font + ".ttf"));
            ModOp toText = ModOp.Fit(GeoPoint.Origin, new GeoVector[] { GeoVector.XAxis, GeoVector.YAxis, GeoVector.ZAxis }, text.Location, new GeoVector[] { text.LineDirection.Normalized, text.GlyphDirection.Normalized, text.LineDirection.Normalized ^ text.GlyphDirection.Normalized });

            // res.TransformBy(Matrix4(toText)); // easier than setting normal and rotation
            return(res);
        }
예제 #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);
            }
        }
예제 #7
0
        //画标注
        public static void writeDimension(DxfDocument doc,Location firstLocation,Location secondLocation,float textHeight,float textWidth,float dimensionHeight,string dimensionDirection)
        {
            float numWidth;
            string strNumWidth = "";
            Layer dimensionLayer=new Layer("dimensionLayer");
            Line line1 = new Line();
            Line line2 = new Line();
            Line leftLine = new Line();
            Line rightLine = new Line();
            Line upLeftLine = new Line();
            Line downLeftLine = new Line();
            Line upRightLine = new Line();
            Line downRightLine = new Line();
            Text strText = new Text();
            line1.Layer = dimensionLayer;
            line2.Layer = dimensionLayer;
            leftLine.Layer = dimensionLayer;
            rightLine.Layer = dimensionLayer;
            upLeftLine.Layer = dimensionLayer;
            downLeftLine.Layer = dimensionLayer;
            upRightLine.Layer = dimensionLayer;
            downRightLine.Layer = dimensionLayer;
            strText.Layer = dimensionLayer;
            if (dimensionDirection.Equals("top"))
            {
                line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z);
                line1.EndPoint = new Vector3f(firstLocation.X, firstLocation.Y + dimensionHeight, firstLocation.Z);
                line2.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y,secondLocation.Z);
                line2.EndPoint = new Vector3f(secondLocation.X,secondLocation.Y+dimensionHeight,secondLocation.Z);
                leftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8,firstLocation.Z);
                leftLine.EndPoint = new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2,firstLocation.Y+7*dimensionHeight/8, firstLocation.Z);
                upLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8,firstLocation.Z);
                upLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y + 7 * dimensionHeight / 8+0.2f,firstLocation.Z);
                downLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y + 7 * dimensionHeight / 8, firstLocation.Z);
                downLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y + 7 * dimensionHeight / 8 - 0.2f, firstLocation.Z);
                upRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y + 7 * dimensionHeight/8,secondLocation.Z);
                upRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y + 7 * dimensionHeight / 8 + 0.2f, secondLocation.Z);
                downRightLine.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z);
                downRightLine.EndPoint = new Vector3f(secondLocation.X-0.2f,secondLocation.Y+7*dimensionHeight/8-0.2f,secondLocation.Z);

                rightLine.StartPoint = new Vector3f(secondLocation.X,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z);
                rightLine.EndPoint = new Vector3f(secondLocation.X-Math.Abs(firstLocation.X-secondLocation.X)/2+textWidth/2,secondLocation.Y+7*dimensionHeight/8,secondLocation.Z);

                numWidth = secondLocation.X - firstLocation.X;
                strNumWidth = "" + numWidth;
               strText.BasePoint=new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2+0.2f,firstLocation.Y+7*dimensionHeight/8, firstLocation.Z);
               strText.Height=0.5f;
                strText.Value=strNumWidth;
            }
            else if(dimensionDirection.Equals("bottom")){
                line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z);
                line1.EndPoint = new Vector3f(firstLocation.X, firstLocation.Y - dimensionHeight, firstLocation.Z);
                line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z);
                line2.EndPoint = new Vector3f(secondLocation.X, secondLocation.Y - dimensionHeight, secondLocation.Z);
                leftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z);
                leftLine.EndPoint = new Vector3f(firstLocation.X + Math.Abs(firstLocation.X - secondLocation.X) / 2 - textWidth / 2, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z);
                upLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z);
                upLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y - 7 * dimensionHeight / 8 + 0.2f, firstLocation.Z);
                downLeftLine.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y - 7 * dimensionHeight / 8, firstLocation.Z);
                downLeftLine.EndPoint = new Vector3f(firstLocation.X + 0.2f, firstLocation.Y - 7 * dimensionHeight / 8 - 0.2f, firstLocation.Z);
                upRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z);
                upRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y - 7 * dimensionHeight / 8 + 0.2f, secondLocation.Z);
                downRightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z);
                downRightLine.EndPoint = new Vector3f(secondLocation.X - 0.2f, secondLocation.Y - 7 * dimensionHeight / 8 - 0.2f, secondLocation.Z);

                rightLine.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z);
                rightLine.EndPoint = new Vector3f(secondLocation.X - Math.Abs(firstLocation.X - secondLocation.X) / 2 + textWidth / 2, secondLocation.Y - 7 * dimensionHeight / 8, secondLocation.Z);

                numWidth = secondLocation.X - firstLocation.X;
                strNumWidth = "" + numWidth;
                strText.BasePoint=new Vector3f(firstLocation.X+Math.Abs(firstLocation.X-secondLocation.X)/2-textWidth/2+0.2f,firstLocation.Y-7*dimensionHeight/8, firstLocation.Z);
               strText.Height=0.5f;
                strText.Value=strNumWidth;
            }
            else if(dimensionDirection.Equals("left")){
                line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z);
                line1.EndPoint = new Vector3f(firstLocation.X - dimensionHeight, firstLocation.Y, firstLocation.Z);
                line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z);
                line2.EndPoint = new Vector3f(secondLocation.X - dimensionHeight, secondLocation.Y, secondLocation.Z);
                leftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                leftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2, firstLocation.Z);
                upLeftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                upLeftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8 - 0.2f, firstLocation.Y + 0.2f, firstLocation.Z);
                downLeftLine.StartPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                downLeftLine.EndPoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8 + 0.2f, firstLocation.Y+0.2f, firstLocation.Z);
                upRightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                upRightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8 - 0.2f, secondLocation.Y - 0.2f, secondLocation.Z);
                downRightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                downRightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8 + 0.2f, secondLocation.Y-0.2f, secondLocation.Z);

                rightLine.StartPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                rightLine.EndPoint = new Vector3f(secondLocation.X - 7 * dimensionHeight / 8, secondLocation.Y - Math.Abs(firstLocation.Y - secondLocation.Y) / 2 + textWidth / 2, secondLocation.Z);

                numWidth = secondLocation.Y - firstLocation.Y;
                strNumWidth = "" + numWidth;
                strText.BasePoint = new Vector3f(firstLocation.X - 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2 + 0.2f, firstLocation.Z);
               strText.Height=0.5f;
                strText.Value=strNumWidth;
            }
            else if (dimensionDirection.Equals("right"))
            {
                line1.StartPoint = new Vector3f(firstLocation.X, firstLocation.Y, firstLocation.Z);
                line1.EndPoint = new Vector3f(firstLocation.X + dimensionHeight, firstLocation.Y, firstLocation.Z);
                line2.StartPoint = new Vector3f(secondLocation.X, secondLocation.Y, secondLocation.Z);
                line2.EndPoint = new Vector3f(secondLocation.X + dimensionHeight, secondLocation.Y, secondLocation.Z);
                leftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                leftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2, firstLocation.Z);
                upLeftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                upLeftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8 - 0.2f, firstLocation.Y + 0.2f, firstLocation.Z);
                downLeftLine.StartPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y, firstLocation.Z);
                downLeftLine.EndPoint = new Vector3f(firstLocation.X + 7 * dimensionHeight / 8 + 0.2f, firstLocation.Y + 0.2f, firstLocation.Z);
                upRightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                upRightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8 - 0.2f, secondLocation.Y - 0.2f, secondLocation.Z);
                downRightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                downRightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8 + 0.2f, secondLocation.Y - 0.2f, secondLocation.Z);

                rightLine.StartPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y, secondLocation.Z);
                rightLine.EndPoint = new Vector3f(secondLocation.X + 7 * dimensionHeight / 8, secondLocation.Y - Math.Abs(firstLocation.Y - secondLocation.Y) / 2 + textWidth / 2, secondLocation.Z);

                numWidth = secondLocation.Y - firstLocation.Y;
                strNumWidth = "" + numWidth;
                strText.BasePoint=new Vector3f(firstLocation.X + 7 * dimensionHeight / 8, firstLocation.Y + Math.Abs(firstLocation.Y - secondLocation.Y) / 2 - textWidth / 2+0.2f, firstLocation.Z);
               strText.Height=0.5f;
                strText.Value=strNumWidth;
            }
            doc.AddEntity(line1);
            doc.AddEntity(line2);
            doc.AddEntity(leftLine);
            doc.AddEntity(rightLine);
            doc.AddEntity(upLeftLine);
            doc.AddEntity(downLeftLine);
            doc.AddEntity(upRightLine);
            doc.AddEntity(downRightLine);
            doc.AddEntity(strText);
        }
예제 #8
0
        private void WriteText(Text text)
        {
            if (this.activeSection != StringCode.EntitiesSection && !this.isBlockEntities)
            {
                throw new InvalidDxfSectionException(this.activeSection, this.file);
            }

            this.WriteCodePair(0, text.CodeName);
            this.WriteCodePair(100, SubclassMarker.Entity);
            this.WriteEntityCommonCodes(text);
            this.WriteCodePair(5, text.Handle);
            this.WriteCodePair(100, SubclassMarker.Text);

            this.WriteCodePair(1, text.Value);

            this.WriteCodePair(10, text.BasePoint.X);
            this.WriteCodePair(20, text.BasePoint.Y);
            this.WriteCodePair(30, text.BasePoint.Z);

            this.WriteCodePair(40, text.Height);

            this.WriteCodePair(41, text.WidthFactor);

            this.WriteCodePair(50, text.Rotation);

            this.WriteCodePair(51, text.ObliqueAngle);

            this.WriteCodePair(7, text.Style);

            this.WriteCodePair(11, text.BasePoint.X);
            this.WriteCodePair(21, text.BasePoint.Y);
            this.WriteCodePair(31, text.BasePoint.Z);

            this.WriteCodePair(210, text.Normal.X);
            this.WriteCodePair(220, text.Normal.Y);
            this.WriteCodePair(230, text.Normal.Z);

            switch (text.Alignment)
            {
                case TextAlignment.TopLeft:

                    this.WriteCodePair(72, 0);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 3);
                    break;

                case TextAlignment.TopCenter:

                    this.WriteCodePair(72, 1);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 3);
                    break;

                case TextAlignment.TopRight:

                    this.WriteCodePair(72, 2);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 3);
                    break;

                case TextAlignment.MiddleLeft:

                    this.WriteCodePair(72, 0);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 2);
                    break;

                case TextAlignment.MiddleCenter:

                    this.WriteCodePair(72, 1);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 2);
                    break;

                case TextAlignment.MiddleRight:

                    this.WriteCodePair(72, 2);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 2);
                    break;

                case TextAlignment.BottomLeft:

                    this.WriteCodePair(72, 0);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 1);
                    break;
                case TextAlignment.BottomCenter:

                    this.WriteCodePair(72, 1);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 1);
                    break;

                case TextAlignment.BottomRight:

                    this.WriteCodePair(72, 2);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 1);
                    break;

                case TextAlignment.BaselineLeft:
                    this.WriteCodePair(72, 0);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 0);
                    break;

                case TextAlignment.BaselineCenter:
                    this.WriteCodePair(72, 1);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 0);
                    break;

                case TextAlignment.BaselineRight:
                    this.WriteCodePair(72, 2);
                    this.WriteCodePair(100, SubclassMarker.Text);
                    this.WriteCodePair(73, 0);
                    break;
            }

            this.WriteXData(text.XData);
        }
예제 #9
0
 /// <summary>
 /// Convert a netDXF text object to a Nucleus label.
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public static Label Convert(netDxf.Entities.Text text)
 {
     return(new Label(Convert(text.Position), text.Value, text.Height * ConversionScaling));
 }
예제 #10
0
파일: Order.cs 프로젝트: Spritutu/ntxx
        /// <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);
        }
예제 #11
0
        bool WriteText(ISpatialObject item)
        {
            TextFeature text = (item as TextFeature);

            if (this.IsTopological)
            {
                ExportKey(text);

            }
            else
            {
            }

            // Skip if the AutoCad layer cannot be determined
            Layer layer = m_Layers.GetLayer(text, m_ContinuousLineType, this.IsTopological);
            if (layer != null)
            {
                TextGeometry geom = text.TextGeometry;
                Text acText = new Text(geom.Text, GetVector(geom.Position), geom.Height);
                acText.Rotation = (float)geom.Rotation.Degrees;
                acText.Layer = layer;

                m_Dxf.AddEntity(acText);
            }
            return true;
        }
예제 #12
0
        void ExportKey(TextFeature text)
        {
            Layer layer = m_Layers.GetLayer(text, m_ContinuousLineType, true);
            if (layer == null)
                return;

            // Get the label's key string. It HAS to be defined.
            string keystr = text.FormattedKey;
            if (String.IsNullOrEmpty(keystr))
                return;

            // Get the label's reference position.
            IPointGeometry refpos = text.GetPolPosition();

            // Define the position for AutoCad (bottom right corner).

            TextGeometry geom = text.TextGeometry;
            Text acText = new Text(geom.Text, GetVector(geom.Position), geom.Height);
            acText.Rotation = (float)geom.Rotation.Degrees;
            acText.Layer = layer;

            m_Dxf.AddEntity(acText);
        }
예제 #13
0
파일: Section.cs 프로젝트: Spritutu/ntxx
        /// <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);
        }
예제 #14
0
        private void WriteText(Text text)
        {
            this.chunk.Write(100, SubclassMarker.Text);

            this.chunk.Write(1, this.EncodeNonAsciiCharacters(text.Value));

            // another example of this OCS vs WCS non sense.
            // while the MText position is written in WCS the position of the Text is written in OCS (different rules for the same concept).
            Vector3 ocsBasePoint = MathHelper.Transform(text.Position, text.Normal, CoordinateSystem.World, CoordinateSystem.Object);

            this.chunk.Write(10, ocsBasePoint.X);
            this.chunk.Write(20, ocsBasePoint.Y);
            this.chunk.Write(30, ocsBasePoint.Z);

            this.chunk.Write(40, text.Height);

            this.chunk.Write(41, text.WidthFactor);

            this.chunk.Write(50, text.Rotation);

            this.chunk.Write(51, text.ObliqueAngle);

            this.chunk.Write(7, this.EncodeNonAsciiCharacters(text.Style.Name));

            this.chunk.Write(11, ocsBasePoint.X);
            this.chunk.Write(21, ocsBasePoint.Y);
            this.chunk.Write(31, ocsBasePoint.Z);

            this.chunk.Write(210, text.Normal.X);
            this.chunk.Write(220, text.Normal.Y);
            this.chunk.Write(230, text.Normal.Z);

            switch (text.Alignment)
            {
                case TextAlignment.TopLeft:

                    this.chunk.Write(72, (short) 0);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 3);
                    break;

                case TextAlignment.TopCenter:

                    this.chunk.Write(72, (short) 1);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 3);
                    break;

                case TextAlignment.TopRight:

                    this.chunk.Write(72, (short) 2);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 3);
                    break;

                case TextAlignment.MiddleLeft:

                    this.chunk.Write(72, (short) 0);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 2);
                    break;

                case TextAlignment.MiddleCenter:

                    this.chunk.Write(72, (short) 1);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 2);
                    break;

                case TextAlignment.MiddleRight:

                    this.chunk.Write(72, (short) 2);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 2);
                    break;

                case TextAlignment.BottomLeft:

                    this.chunk.Write(72, (short) 0);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 1);
                    break;
                case TextAlignment.BottomCenter:

                    this.chunk.Write(72, (short) 1);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 1);
                    break;

                case TextAlignment.BottomRight:

                    this.chunk.Write(72, (short) 2);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 1);
                    break;

                case TextAlignment.BaselineLeft:
                    this.chunk.Write(72, (short) 0);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;

                case TextAlignment.BaselineCenter:
                    this.chunk.Write(72, (short) 1);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;

                case TextAlignment.BaselineRight:
                    this.chunk.Write(72, (short) 2);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;

                case TextAlignment.Aligned:
                    this.chunk.Write(72, (short) 3);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;

                case TextAlignment.Middle:
                    this.chunk.Write(72, (short) 4);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;

                case TextAlignment.Fit:
                    this.chunk.Write(72, (short) 5);
                    this.chunk.Write(100, SubclassMarker.Text);
                    this.chunk.Write(73, (short) 0);
                    break;
            }

            this.WriteXData(text.XData);
        }
예제 #15
0
        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");

        }
예제 #16
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");
        }
예제 #17
0
        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");

        }
예제 #18
0
        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");
        }
예제 #19
0
        private static void EntityLineWeight()
        {
            // the lineweight is always defined as 1/100 mm, this property is the equivalent of stroke width, outline width in other programs. Do not confuse with line.Thickness
            // it follow the AutoCAD naming style, check the documentation in case of doubt
            Line line = new Line(new Vector3(0, 0, 0), new Vector3(100, 100, 0));
            line.Lineweight.Value = 100; // 1.0 mm
            Text text = new Text("Text with lineweight", Vector3.Zero, 10);
            text.Lineweight.Value = 50; // 0.5 mm

            Layer layer = new Layer("MyLayer");
            layer.Lineweight.Value = 200; // 2 mm all entities in the layer with Color.ByLayer will inherit this value
            layer.Color = AciColor.Green;
            Line line2 = new Line(new Vector3(0, 100, 0), new Vector3(100, 0, 0));
            line2.Layer = layer;

            DxfDocument dxf = new DxfDocument();
            dxf.AddEntity(line);
            dxf.AddEntity(line2);
            dxf.AddEntity(text);
            dxf.Save("line weight.dxf");
            dxf = DxfDocument.Load("line weight.dxf");
        }
예제 #20
0
        private Text ReadText(ref CodeValuePair code)
        {
            var text = new Text();

            Vector3d firstAlignmentPoint = Vector3d.Zero;
            Vector3d secondAlignmentPoint = Vector3d.Zero;
            Vector3d normal = Vector3d.UnitZ;
            int horizontalAlignment = 0;
            int verticalAlignment = 0;
            Dictionary<ApplicationRegistry, XData> xData = new Dictionary<ApplicationRegistry, XData>();

            code = this.ReadCodePair();
            while (code.Code != 0)
            {
                switch (code.Code)
                {
                    case 5:
                        text.Handle = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 1:
                        text.Value = code.Value;
                        code = this.ReadCodePair();
                        break;
                    case 8: //layer code
                        text.Layer = this.GetLayer(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 62: //aci color code
                        text.Color = new AciColor(short.Parse(code.Value));
                        code = this.ReadCodePair();
                        break;
                    case 6: //type line code
                        text.LineType = this.GetLineType(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 10:
                        firstAlignmentPoint.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 20:
                        firstAlignmentPoint.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 30:
                        firstAlignmentPoint.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 11:
                        secondAlignmentPoint.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 21:
                        secondAlignmentPoint.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 31:
                        secondAlignmentPoint.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 40:
                        text.Height = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 41:
                        text.WidthFactor = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 50:
                        text.Rotation = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 51:
                        text.ObliqueAngle = float.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 7:
                        text.Style = this.GetTextStyle(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 72:
                        horizontalAlignment = int.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 73:
                        verticalAlignment = int.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 210:
                        normal.X = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 220:
                        normal.Y = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 230:
                        normal.Z = double.Parse(code.Value);
                        code = this.ReadCodePair();
                        break;
                    case 1001:
                        XData xDataItem = this.ReadXDataRecord(code.Value, ref code);
                        xData.Add(xDataItem.ApplicationRegistry, xDataItem);
                        break;
                    default:
                        if (code.Code >= 1000 && code.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(code.Code, code.Value, this.file,
                                                                         "The extended data of an entity must start with the application registry code " + this.fileLine);

                        code = this.ReadCodePair();
                        break;
                }
            }

            TextAlignment alignment = ObtainAlignment(horizontalAlignment, verticalAlignment);

            text.BasePoint = alignment == TextAlignment.BaselineLeft ? firstAlignmentPoint : secondAlignmentPoint;
            text.Normal = normal;
            text.Alignment = alignment;
            text.XData = xData;

            return text;
        }
예제 #21
0
        //画无门栓的矩形框
        public static void writeDoorRectangle(DxfDocument doc, Location location, string[] text, float height, float width, float outer_mid_space, float outer_in_space)
        {
            Layer doorRectangleLayer = new Layer("nonDoorBarLayer");
            //最外围矩形
            writeOuterDoorRectangle(doc,location,height,width);
            //中间矩形
            Line midBottomLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+outer_mid_space,location.Z),new Vector3f(location.X+width-outer_mid_space,location.Y+outer_mid_space,location.Z));
            midBottomLine.Layer=doorRectangleLayer;
            Line midLeftLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+outer_mid_space,location.Z),new Vector3f(location.X+outer_mid_space,location.Y+height-outer_mid_space,location.Z));
            midLeftLine.Layer=doorRectangleLayer;
            Line midTopLine=new Line(new Vector3f(location.X+outer_mid_space,location.Y+height-outer_mid_space,location.Z),new Vector3f(location.X+width-outer_mid_space,location.Y+height-outer_mid_space,location.Z));
            midTopLine.Layer=doorRectangleLayer;
            Line midRightLine = new Line(new Vector3f(location.X + width - outer_mid_space, location.Y + height - outer_mid_space, location.Z), new Vector3f(location.X + width - outer_mid_space, location.Y + outer_mid_space, location.Z));
            midRightLine.Layer = doorRectangleLayer;

            doc.AddEntity(midBottomLine);
            doc.AddEntity(midLeftLine);
            doc.AddEntity(midTopLine);
            doc.AddEntity(midRightLine);

            //内部矩形
            Line inBottomLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + outer_in_space, location.Z));
            inBottomLine.Layer = doorRectangleLayer;
            Line inLeftLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + outer_in_space, location.Z), new Vector3f(location.X + outer_in_space, location.Y + height - outer_in_space, location.Z));
            inLeftLine.Layer = doorRectangleLayer;
            Line inTopLine = new Line(new Vector3f(location.X + outer_in_space, location.Y + height - outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + height - outer_in_space, location.Z));
            inTopLine.Layer = doorRectangleLayer;
            Line inRightLine = new Line(new Vector3f(location.X + width - outer_in_space, location.Y + height - outer_in_space, location.Z), new Vector3f(location.X + width - outer_in_space, location.Y + outer_in_space, location.Z));
            inRightLine.Layer = doorRectangleLayer;

            doc.AddEntity(inBottomLine);
            doc.AddEntity(inLeftLine);
            doc.AddEntity(inTopLine);
            doc.AddEntity(inRightLine);

            //门中文字
            float textHeight=DoorInitHeightAndWidth.textHeight;
            for(int i=0;i<text.Length;i++){
                Text doorRectangleText = new Text(text[i], new Vector3f(location.X + width / 3, location.Y + 3*height / 4- i * textHeight, location.Z), textHeight);
                doorRectangleText.Layer = doorRectangleLayer;
                doc.AddEntity(doorRectangleText);
            }
        }
예제 #22
0
        /// <summary>
        /// Creates a new Text that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Text that is a copy of this instance.</returns>
        public override object Clone()
        {
            Text entity = new Text
            {
                //EntityObject properties
                Layer = (Layer)this.layer.Clone(),
                LineType = (LineType)this.lineType.Clone(),
                Color = (AciColor)this.color.Clone(),
                Lineweight = (Lineweight)this.lineweight.Clone(),
                Transparency = (Transparency)this.transparency.Clone(),
                LineTypeScale = this.lineTypeScale,
                Normal = this.normal,
                //Text properties
                Position = this.position,
                Rotation = this.rotation,
                Height = this.height,
                WidthFactor = this.widthFactor,
                ObliqueAngle = this.obliqueAngle,
                Alignment = this.alignment,
                Style = (TextStyle) this.style.Clone(),
                Value = this.value
            };

            foreach (XData data in this.XData.Values)
                entity.XData.Add((XData)data.Clone());

            return entity;

        }
예제 #23
0
파일: DxfReader.cs 프로젝트: Core2D/netdxf
        private Text ReadText()
        {
            string textString = string.Empty;
            double height = 0.0;
            double widthFactor = 1.0;
            double rotation = 0.0;
            double obliqueAngle = 0.0;
            TextStyle style = TextStyle.Default;
            Vector3 firstAlignmentPoint = Vector3.Zero;
            Vector3 secondAlignmentPoint = Vector3.Zero;
            Vector3 normal = Vector3.UnitZ;
            short horizontalAlignment = 0;
            short verticalAlignment = 0;
            List<XData> xData = new List<XData>();

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 1:
                        textString = this.chunk.ReadString();
                        this.chunk.Next();
                        break;
                    case 10:
                        firstAlignmentPoint.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 20:
                        firstAlignmentPoint.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 30:
                        firstAlignmentPoint.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 11:
                        secondAlignmentPoint.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 21:
                        secondAlignmentPoint.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 31:
                        secondAlignmentPoint.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 40:
                        height = this.chunk.ReadDouble();
                        if (height <= 0.0)
                            height = this.doc.DrawingVariables.TextSize;
                        this.chunk.Next();
                        break;
                    case 41:
                        widthFactor = this.chunk.ReadDouble();
                        if (widthFactor < 0.01 || widthFactor > 100.0)
                            widthFactor = this.doc.DrawingVariables.TextSize;
                        this.chunk.Next();
                        break;
                    case 50:
                        rotation = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 51:
                        obliqueAngle = this.chunk.ReadDouble();
                        if (obliqueAngle < -85.0 || obliqueAngle > 85.0)
                            obliqueAngle = 0.0;
                        this.chunk.Next();
                        break;
                    case 7:
                        string styleName = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        if (string.IsNullOrEmpty(styleName))
                            styleName = this.doc.DrawingVariables.TextStyle;
                        style = this.GetTextStyle(styleName);
                        this.chunk.Next();
                        break;
                    case 72:
                        horizontalAlignment = this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 73:
                        verticalAlignment = this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 210:
                        normal.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 220:
                        normal.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 230:
                        normal.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId));
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new Exception("The extended data of an entity must start with the application registry code.");

                        this.chunk.Next();
                        break;
                }
            }

            TextAlignment alignment = ObtainAlignment(horizontalAlignment, verticalAlignment);
            Vector3 ocsBasePoint = alignment == TextAlignment.BaselineLeft ? firstAlignmentPoint : secondAlignmentPoint;

            // another example of this OCS vs WCS non sense.
            // while the MText position is written in WCS the position of the Text is written in OCS (different rules for the same concept).
            textString = this.DecodeEncodedNonAsciiCharacters(textString);
            Text text = new Text
            {
                Value = textString,
                Height = height,
                WidthFactor = widthFactor,
                Rotation = rotation,
                ObliqueAngle = obliqueAngle,
                Style = style,
                Position = MathHelper.Transform(ocsBasePoint, normal, CoordinateSystem.Object, CoordinateSystem.World),
                Normal = normal,
                Alignment = alignment
            };

            text.XData.AddRange(xData);

            return text;
        }
예제 #24
0
파일: Handle.cs 프로젝트: Spritutu/ntxx
        /// <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);
        }
예제 #25
0
        private static void WriteDxfFile()
        {
            DxfDocument dxf = new DxfDocument();

            //arc
            Arc arc = new Arc(new Vector3d(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.Long, 350));
            xdata2.XDataRecord.Add(XDataRecord.CloseControlString);

            //circle
            Vector3d extrusion = new Vector3d(1, 1, 1);
            Vector3d centerWCS = new Vector3d(1, 1, 1);
            Vector3d centerOCS = MathHelper.Transform(centerWCS,
                                                      extrusion,
                                                      MathHelper.CoordinateSystem.World,
                                                      MathHelper.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=new Dictionary<ApplicationRegistry, XData>
                             {
                                 {xdata.ApplicationRegistry, xdata},
                                 {xdata2.ApplicationRegistry, xdata2}
                             };

            dxf.AddEntity(circle);

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

            //3dface
            Face3d face3D = new Face3d(new Vector3d(-5, -5, 5),
                                       new Vector3d(5, -5, 5),
                                       new Vector3d(5, 5, 5),
                                       new Vector3d(-5, 5, 5));
            face3D.Layer = new Layer("3dface");
            face3D.Layer.Color.Index = 3;
            dxf.AddEntity(face3D);

            //polyline
            PolylineVertex polyVertex;
            List<PolylineVertex> polyVertexes = new List<PolylineVertex>();
            polyVertex = new PolylineVertex(new Vector2d(-50, -50));
            polyVertex.BeginThickness = 2;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, -50));
            polyVertex.BeginThickness = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(50, 50));
            polyVertex.Bulge = 1;
            polyVertexes.Add(polyVertex);
            polyVertex = new PolylineVertex(new Vector2d(-50, 50));
            polyVertexes.Add(polyVertex);
            Polyline polyline2d = new Polyline(polyVertexes, true);
            polyline2d.Layer = new Layer("polyline2d");
            polyline2d.Layer.Color.Index = 5;
            polyline2d.Normal = new Vector3d(1, 1, 1);
            polyline2d.Elevation = 100.0;
            dxf.AddEntity(polyline2d);

            //lightweight polyline
            LightWeightPolylineVertex lwVertex;
            List<LightWeightPolylineVertex> lwVertexes = new List<LightWeightPolylineVertex>();
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, -25));
            lwVertex.BeginThickness = 2;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, -25));
            lwVertex.BeginThickness = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(25, 25));
            lwVertex.Bulge = 1;
            lwVertexes.Add(lwVertex);
            lwVertex = new LightWeightPolylineVertex(new Vector2d(-25, 25));
            lwVertexes.Add(lwVertex);
            LightWeightPolyline lwPolyline = new LightWeightPolyline(lwVertexes, true);
            lwPolyline.Layer = new Layer("lwpolyline");
            lwPolyline.Layer.Color.Index = 5;
            lwPolyline.Normal = new Vector3d(1, 1, 1);
            lwPolyline.Elevation = 100.0;
            dxf.AddEntity(lwPolyline);

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

            //3d polyline
            Polyline3dVertex vertex;
            List<Polyline3dVertex> vertexes = new List<Polyline3dVertex>();
            vertex = new Polyline3dVertex(new Vector3d(-50, -50, 0));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, -50, 10));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(50, 50, 25));
            vertexes.Add(vertex);
            vertex = new Polyline3dVertex(new Vector3d(-50, 50, 50));
            vertexes.Add(vertex);
            Polyline3d polyline = new Polyline3d(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 Vector3d(-5, -5, 5), new Vector3d(5, 5, 5)));
            block.Entities.Add(new Line(new Vector3d(5, -5, 5), new Vector3d(-5, 5, 5)));

            //insert
            Insert insert = new Insert(block, new Vector3d(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!", Vector3d.Zero, 10.0f,style);
            text.Layer = new Layer("text");
            text.Layer.Color.Index = 8;
            text.Alignment = TextAlignment.TopRight;
            dxf.AddEntity(text);

            dxf.Save("AutoCad2007.dxf", DxfVersion.AutoCad2007);
            dxf.Save("AutoCad2004.dxf", DxfVersion.AutoCad2004);
            dxf.Save("AutoCad2000.dxf", DxfVersion.AutoCad2000);
            dxf.Save("AutoCad12.dxf", DxfVersion.AutoCad12);
        }