Exemplo n.º 1
0
        private static void DrawPolyline(Size destSize, LwPolyline line, Graphics g)
        {
            var list = line.Vertexes.Select(x => x.Location).ToList();

            float ratio, xoffset, yoffset;

            CalcTransform(destSize, list, out ratio, out xoffset, out yoffset);

            var pt1 = list[0];
            var pt2 = list[list.Count - 1];

            if (Math.Abs(pt1.X - pt2.X) > double.Epsilon || Math.Abs(pt1.Y - pt2.Y) > double.Epsilon)
            {
                list.Add(new Vector2(pt1.X, pt1.Y));
            }

            Pen pen = new Pen(Color.FromArgb(255, 0, 0));

            pen.Width = 2;

            var pts =
                list.Select(
                    x => new System.Drawing.Point((int)((x.X - xoffset) * ratio), destSize.Height - (int)((x.Y - yoffset) * ratio))).ToArray();

            g.DrawLines(pen, pts);
        }
Exemplo n.º 2
0
        private LwPolyline AddDxfPolyLine(string layerName, LayoutPolyLine line, LineExportConfig lineConfig)
        {
            var splinePoints = new List <Vector2>();

            foreach (var pt in line.Points)
            {
                splinePoints.Add(PointToVector(pt));
            }

            var polyLine = new LwPolyline(splinePoints)
            {
                Layer = GetLayer(layerName),
                Color = GetColor(lineConfig.Color),
            };

            //foreach (var vec in splinePoints)
            //    polyLine.Vertexes.Add(new LwPolylineVertex(vec));

            if (lineConfig.IsDashed)
            {
                polyLine.Linetype = Linetype.Dashed;
            }

            Document.AddEntity(polyLine);
            return(polyLine);
        }
        public IPolygon GeneratePolygon(LwPolyline line)
        {
            var pg       = new PolygonClass();
            var pc       = (IPointCollection)pg;
            var o        = Type.Missing;
            var vertexes = line.PoligonalVertexes(int.Parse(ConfigurationManager.AppSettings["BulgePrecision"]), double.Parse(ConfigurationManager.AppSettings["WeldThreshold"]), double.Parse(ConfigurationManager.AppSettings["BulgeThreshold"]));

            foreach (var vertex in vertexes)
            {
                var pt = new PointClass();
                pt.PutCoords(vertex.X, vertex.Y);
                pc.AddPoint(pt, ref o, ref o);
            }

            var pt1 = pc.get_Point(0);
            var pt2 = pc.get_Point(pc.PointCount - 1);

            if (Math.Abs(pt1.X - pt2.X) > double.Epsilon || Math.Abs(pt1.Y - pt2.Y) > double.Epsilon)
            {
                var pt = new PointClass();
                pt.PutCoords(pt1.X, pt1.Y);
                pc.AddPoint(pt, ref o, ref o);
            }
            return(pg);
        }
Exemplo n.º 4
0
        public static Bitmap Generate(LwPolyline line, Size size)
        {
            var bmp = new Bitmap(size.Width, size.Height);

            Graphics g = Graphics.FromImage(bmp);

            DrawPolyline(bmp.Size, line, g);
            return(bmp);
        }
Exemplo n.º 5
0
        private void button_export(object sender, EventArgs e)
        {
            DxfDocument Doc = new DxfDocument();

            /* Отрисовка участков */
            for (int z = 0; z < MyXmlReader.spatials.Count; z++)
            {
                LwPolyline parcel = new LwPolyline();

                foreach (var Point in MyXmlReader.spatials[z].Points)
                {
                    centerX += (ulong)Point.X;
                    centerY += (ulong)Point.Y;
                    centerCounter++;
                    if (Switch.Checked)//Перевернуть X Y
                    {
                        parcel.Vertexes.Add(new LwPolylineVertex(new Vector2(Point.Y, Point.X)));
                    }
                    else
                    {
                        parcel.Vertexes.Add(new LwPolylineVertex(Point));
                    }
                }
                Doc.AddEntity(parcel);
            }

            /* Создаем надпись кад. номера */
            Text cad_number = new Text();

            cad_number.Value     = MyXmlReader.CadastralNumber;
            cad_number.Alignment = TextAlignment.MiddleCenter;
            cad_number.Height    = 2.5d;
            if (Switch.Checked)
            {
                Vector3 textPosition = new Vector3((double)centerY / centerCounter, (double)centerX / centerCounter, 0);
                cad_number.Position = textPosition;
            }
            else
            {
                Vector3 textPosition = new Vector3((double)centerX / centerCounter, (double)centerY / centerCounter, 0);
                cad_number.Position = textPosition;
            }

            Doc.AddEntity(cad_number);

            try
            {
                Doc.Save(textBoxTo.Text);
            }
            catch (IOException x)
            {
                MessageBox.Show(x.Message);
            }
            Application.Exit();
        }
Exemplo n.º 6
0
        public static Caly.Common.Point[] ToPoints(this LwPolyline lw)
        {
            var result = lw.Vertexes.Select(x => x.Position.ToPoint());

            while (result.First().Equals(result.Last()))
            {
                result = result.SkipLast(1);
            }

            return(result.ToArray());
        }
Exemplo n.º 7
0
        /// <summary>
        /// enumerate as Vector3D given dxf lwpolyline vertexes
        /// </summary>
        public static IEnumerable <Vector3D> Vector3DCoords(this LwPolyline lwp)
        {
            var res = new List <Vector3D>();
            var N   = lwp.Normal;
            var ocs = new CoordinateSystem3D(Vector3D.Zero, N);

            foreach (var v in lwp.Vertexes)
            {
                yield return(MathHelper.Transform(
                                 new Vector3(v.Position.X, v.Position.Y, lwp.Elevation), lwp.Normal, CoordinateSystem.Object, CoordinateSystem.World));
            }
        }
Exemplo n.º 8
0
        void fixDXF(string[] files)
        {
            foreach (string file in files)
            {
                //open in the version that supports saving and opening R12, do all the work in latest version, then save as R12

                string fileName     = Path.GetFileName(file);
                string tempFileName = file.Substring(0, file.Length - fileName.Length) + "TMP.DXF";
                Console.WriteLine(fileName.Substring(fileName.Length - 4).ToLower());
                if (fileName == null || fileName.Substring(fileName.Length - 4).ToLower() != ".dxf")
                {
                    continue;
                }

                //open as R12 and save in different format for newer library
                R12.netDxf.DxfDocument inputDxf = new R12.netDxf.DxfDocument();
                inputDxf.Load(file);

                inputDxf.Save(tempFileName, R12.netDxf.Header.DxfVersion.AutoCad2010);

                //open in new library and do all the editing
                DxfDocument workingDxf = DxfDocument.Load(tempFileName);

                Arc[]        toRemove = new Arc[workingDxf.Arcs.Count()];
                LwPolyline[] toAdd    = new LwPolyline[workingDxf.Arcs.Count()];
                int          count    = 0;
                foreach (Arc i in workingDxf.Arcs)
                {
                    toRemove[count] = i;
                    toAdd[count]    = i.ToPolyline(1000);
                    count++;
                }

                for (int i = 0; i < toRemove.Length; i++)
                {
                    workingDxf.RemoveEntity(toRemove[i]);
                    workingDxf.AddEntity(toAdd[i]);
                }

                workingDxf.Save(tempFileName);

                //open it back in R12 library and save as R12
                R12.netDxf.DxfDocument outputDxf = new R12.netDxf.DxfDocument();
                outputDxf.Load(tempFileName);

                outputDxf.Save(file.Insert(file.Length - 4, "_FIXED"), R12.netDxf.Header.DxfVersion.AutoCad12);
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 9
0
        public void WriteLwPolyLine2DXF(List <PointF> pointFs, bool IsClose)
        {
            List <Vector2> vector2s = new List <Vector2>();

            foreach (var point in pointFs)
            {
                vector2s.Add(point);
            }
            LwPolyline lwPolyline = new LwPolyline(vector2s, IsClose)
            {
                Layer = layerWrite
            };

            docWrite.AddEntity(lwPolyline);
        }
Exemplo n.º 10
0
		/*Draw LwPolyline*/
		public static void DrawLwPolyline(LwPolyline xPoly, Canvas mainCanvas)
		{
			System.Windows.Shapes.Polyline wPoly = new System.Windows.Shapes.Polyline();

			foreach (netDxf.Entities.LwPolylineVertex xVertex in xPoly.Vertexes) {
				System.Windows.Point myPt = TypeConverter.Vertex2ToPoint(xVertex.Position);
				getMaxPt(myPt);
				myPt.Y = mainCanvas.Height - myPt.Y;
				wPoly.Points.Add(myPt);
				
			}
			
			if (xPoly.IsClosed == true)
				wPoly.Points.Add(wPoly.Points[0]);
			TypeConverter.Entity2Shape(xPoly, wPoly);
			mainCanvas.Children.Add(wPoly);
		}
Exemplo n.º 11
0
        /// <summary>
        /// 椭圆转换
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        private static List <LwPolylineModel> ToConverter(this IEnumerable <Ellipse> paras)
        {
            //List<EllipseModel> values = new List<EllipseModel>();
            //int channelPort = 1;//所在图层,默认给第一层
            //foreach (var p in paras)
            //{
            //    int.TryParse(p.Layer.Name, out channelPort);
            //    channelPort = (channelPort <= 0 || channelPort > 15) ? 1 : channelPort;
            //    values.Add(new EllipseModel()
            //    {
            //        SN = SN++,//p.Handle,
            //        LayerId = channelPort == 0 ? 1 : channelPort,
            //        StartAngle = p.StartAngle,
            //        EndAngle = p.EndAngle,
            //        IsFill = p.IsFullEllipse,
            //        MajorAxis = p.MajorAxis,
            //        MinorAxis = p.MinorAxis,
            //        Rotation = p.Rotation,
            //        Center = new UnitPoint() { X = p.Center.X, Y = p.Center.Y }
            //    });
            //}
            //return values;
            List <LwPolylineModel> values = new List <LwPolylineModel>();
            int channelPort = 1;//所在图层,默认给第一层

            foreach (var p in paras)
            {
                int.TryParse(p.Layer.Name, out channelPort);
                channelPort = (channelPort <= 0 || channelPort > 15) ? 1 : channelPort;
                LwPolyline lwpolyline = p.ToPolyline(precision * 5);
                values.Add(new LwPolylineModel()
                {
                    GroupParam = new GroupParam()
                    {
                        FigureSN = SN++, GroupSN = new List <int>()
                        {
                            0
                        }
                    },
                    LayerId = channelPort,
                    IsFill  = lwpolyline.IsClosed,
                    Points  = lwpolyline.Vertexes.Select(e => new UnitPointBulge(new UnitPoint(e.Position.X, e.Position.Y), e.Bulge == 0 ? double.NaN : e.Bulge)).ToList()
                });
            }
            return(values);
        }
Exemplo n.º 12
0
        public bool CheckCoordinates(LwPolyline line)
        {
            var lyr = new FeatureLayerClass();

            lyr.FeatureClass = dltbFC;
            var ext = lyr.Extent;

            foreach (var vertex in line.Vertexes)
            {
                if (vertex.Location.X < ext.XMin || vertex.Location.X > ext.XMax || vertex.Location.Y < ext.YMin ||
                    vertex.Location.Y > ext.YMax)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 13
0
        private void btnLWPolyline_Click(object sender, EventArgs e)
        {
            var poly = new LwPolyline();

            poly.Add(new LwPolyLineVertex(55.3005f, 125.1903f, 0));
            poly.Add(new LwPolyLineVertex(80.5351f, 161.2085f, 0));
            poly.Add(new LwPolyLineVertex(129.8027f, 148.6021f, -1.3108f));
            poly.Add(new LwPolyLineVertex(107.5722f, 109.5824f, 0.8155f));
            poly.Add(new LwPolyLineVertex(77.5310f, 89.7724f, 0));
            poly.IsClosed = true;
            var form = new PropertyForm(poly);

            if (DialogResult.OK != form.ShowDialog(this))
            {
                return;
            }
            this.Document.Action.ActEntityAdd(poly);
        }
Exemplo n.º 14
0
        public int IfAnyPolylineVertexIsOutsideTheBiggestCircleThenEntityMustBeDeleted(bool hasPolylineVertexOutsideTheBiggestCircle)
        {
            var document = new DxfDocument();

            document.AddEntity(new Circle(new Vector2(0, 0), 100));
            var polyline = new LwPolyline(new[] { new LwPolylineVertex(10, 10), new LwPolylineVertex(20, 20) }, true);

            if (hasPolylineVertexOutsideTheBiggestCircle)
            {
                polyline.Vertexes.Add(new LwPolylineVertex(200, 300));
            }
            document.AddEntity(polyline);
            var entity = World.NewEntity();

            entity.Get <DxfFileDefinition>().path     = "C:\\tmp\\dxf_file.dxf";
            entity.Get <DxfFileContent>().dfxDocument = document;

            System.Run();

            return(dxfFileContentFilter.GetEntitiesCount());
        }
Exemplo n.º 15
0
        private void PopulateDXF(List <ColoBox> boxes2relo, DxfDocument dxf)
        {
            //creating the result layer
            Layer layer = new Layer("MyLayer")
            {
                Color    = AciColor.Red,
                LineType = LineType.Continuous
            };

            foreach (ColoBox box in boxes2relo)
            {
                LwPolyline poly = new LwPolyline();
                poly.Layer = layer;
                foreach (Point v in box.Points)
                {
                    poly.Vertexes.Add(new LwPolylineVertex(v.X, v.Y));
                }
                poly.IsClosed = true;
                dxf.AddEntity(poly);
            }
        }
Exemplo n.º 16
0
        private IPolygon GeneratePolygon(LwPolyline line)
        {
            var pg = new PolygonClass();
            var pc = (IPointCollection)pg;
            var o  = Type.Missing;

            foreach (var vertex in line.Vertexes)
            {
                var pt = new PointClass();
                pt.PutCoords(vertex.Location.X, vertex.Location.Y);
                pc.AddPoint(pt, ref o, ref o);
            }

            var pt1 = pc.get_Point(0);
            var pt2 = pc.get_Point(pc.PointCount - 1);

            if (Math.Abs(pt1.X - pt2.X) > double.Epsilon || Math.Abs(pt1.Y - pt2.Y) > double.Epsilon)
            {
                var pt = new PointClass();
                pt.PutCoords(pt1.X, pt1.Y);
                pc.AddPoint(pt, ref o, ref o);
            }
            return(pg);
        }
Exemplo n.º 17
0
        /// <summary>
        /// versucht, Liste von Listen von polylinien zu LwPolylinien umzuwandeln
        /// </summary>
        /// <param name="listPLs">List Polylinien</param>
        /// <returns>Liste Lw Polylinien</returns>
        List <List <LwPolyline> > ToLwPolyline2(List <List <shapes.Polyline> > listPLs)
        {
            List <List <LwPolyline> > all_Lists_LWPL = new List <List <LwPolyline> >();

            foreach (List <shapes.Polyline> listPL in listPLs)
            {
                List <LwPolyline> new_List_LwPL = new List <LwPolyline>();
                foreach (shapes.Polyline PL in listPL)
                {
                    LwPolyline new_LWPL = new LwPolyline();
                    List <LwPolylineVertex> new_LWPL_Vertex = new List <LwPolylineVertex>();
                    foreach (System.Windows.Point Pt in PL.Points)
                    {
                        new_LWPL.Vertexes.Add(new LwPolylineVertex(Pt.X, Pt.Y));
                    }

                    new_List_LwPL.Add(new_LWPL);
                }
                all_Lists_LWPL.Add(new_List_LwPL);
            }


            return(all_Lists_LWPL);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 保存为DXF格式
        /// </summary>
        /// <param name="figures"></param>
        /// <param name="path"></param>
        public static void WriteDXF(List <FigureBaseModel> figures, string path)
        {
            DxfDocument dxf = new DxfDocument();

            foreach (FigureBaseModel figure in figures)
            {
                switch (figure.Type)
                {
                case FigureTypes.Arc:
                {
                    var    fg         = figure as ArcModel;
                    double startAngle = double.IsNaN(fg.StartAngle) ? 0 : fg.StartAngle;
                    double endAngle   = double.IsNaN(fg.EndAngle) ? 0 : fg.EndAngle;
                    double sweepAngle = double.IsNaN(fg.AngleSweep) ? 0 : fg.AngleSweep;
                    if (fg.IsClockwise)
                    {
                        endAngle = startAngle - sweepAngle;
                    }
                    else
                    {
                        endAngle = startAngle + sweepAngle;
                    }
                    if (endAngle > 360)
                    {
                        endAngle = endAngle - 360;
                    }
                    if (sweepAngle < 0)
                    {
                        double temp = startAngle;
                        startAngle = endAngle;
                        endAngle   = temp;
                    }

                    Arc arc = new Arc(new Vector3(fg.Center.X, fg.Center.Y, 0),
                                      fg.Radius,
                                      startAngle,
                                      endAngle
                                      );
                    arc.Layer             = new Layer("arc");
                    arc.Layer.Color.Index = (short)(figure.LayerId);
                    arc.Layer.Name        = (figure.LayerId).ToString();
                    dxf.AddEntity(arc);
                }
                break;

                case FigureTypes.Circle:
                {
                    var    fg     = figure as CircleModel;
                    Circle circle = new Circle(new Vector3(fg.Center.X, fg.Center.Y, 0), fg.Radius);
                    circle.Layer             = new Layer("circle with spaces");
                    circle.Layer.Color.Index = (short)(figure.LayerId);
                    circle.Layer.Name        = (figure.LayerId).ToString();
                    dxf.AddEntity(circle);
                }
                break;

                case FigureTypes.Point:
                {
                    var   fg     = figure as PointModel;
                    Point point1 = new Point(new Vector3(fg.Point.X, fg.Point.Y, 0));
                    point1.Layer             = new Layer("point");
                    point1.Layer.Color.Index = (short)(figure.LayerId);
                    point1.Layer.Name        = (figure.LayerId).ToString();
                    dxf.AddEntity(point1);
                }
                break;

                case FigureTypes.LwPolyline:
                {
                    var fg = figure as LwPolylineModel;
                    List <LwPolylineVertex> lwVertexes = new List <LwPolylineVertex>();
                    foreach (UnitPointBulge pt in fg.Points)
                    {
                        LwPolylineVertex lwVertex = new LwPolylineVertex(pt.Point.X, pt.Point.Y, double.IsNaN(pt.Bulge) ? 0 : pt.Bulge);
                        lwVertexes.Add(lwVertex);
                    }
                    LwPolyline lwPolyline = new LwPolyline(lwVertexes, true);
                    lwPolyline.IsClosed          = fg.IsFill;
                    lwPolyline.Layer.Color.Index = (short)(figure.LayerId);
                    lwPolyline.Layer             = new Layer("lwpolyline");
                    lwPolyline.Layer.Name        = (figure.LayerId).ToString();
                    dxf.AddEntity(lwPolyline);
                }
                break;

                case FigureTypes.PolyBezier:
                {
                }
                break;

                default:
                    break;
                }
            }
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save(path);
        }
Exemplo n.º 19
0
        private DXFItem AtualizarPosicaoEntidades(ItemOrganizado item)
        {
            DXFItem figura = item.Figura;

            //Circulos
            List <Circle> circles = figura.entities.OfType <Circle>().ToList();

            foreach (var circle in circles)
            {
                figura.entities.Remove(circle);
                Circle circleAtualizado = new Circle(
                    new Vector2(circle.Center.X + item.X - figura.Origem[0], circle.Center.Y + item.Y - figura.Origem[1]), //Centro
                    circle.Radius);                                                                                        //Raio
                figura.entities.Add(circleAtualizado);
            }

            //Linhas
            List <Line> lines = figura.entities.OfType <Line>().ToList();

            foreach (var line in lines)
            {
                figura.entities.Remove(line);
                Line linha = new Line(
                    new Vector2(line.StartPoint.X + item.X - figura.Origem[0], line.StartPoint.Y + item.Y - figura.Origem[1]), //Start
                    new Vector2(line.EndPoint.X + item.X - figura.Origem[0], line.EndPoint.Y + item.Y - figura.Origem[1])      //End
                    );
                figura.entities.Add(linha);
            }

            //Elipses
            List <Ellipse> ellipses = figura.entities.OfType <Ellipse>().ToList();

            foreach (var ellipse in ellipses)
            {
                figura.entities.Remove(ellipse);
                Ellipse ellipseAtualizado = new Ellipse(
                    new Vector2(ellipse.Center.X + item.X, ellipse.Center.Y + item.Y),
                    ellipse.MajorAxis,
                    ellipse.MinorAxis
                    );
                figura.entities.Add(ellipseAtualizado);
            }

            //LwPolilinhas
            List <LwPolyline> lwPolylines = figura.entities.OfType <LwPolyline>().ToList();

            foreach (var lwPolyline in lwPolylines)
            {
                figura.entities.Remove(lwPolyline);
                LwPolyline polyline = new LwPolyline();
                foreach (var vertex in lwPolyline.Vertexes)
                {
                    polyline.Vertexes.Add(new LwPolylineVertex(new Vector2(vertex.Position.X + item.X, vertex.Position.Y + item.Y), vertex.Bulge));
                }

                figura.entities.Add(polyline);
            }

            //Arcos(entities.OfType<Arc>());
            List <Arc> arcs = figura.entities.OfType <Arc>().ToList();

            foreach (var arc in arcs)
            {
                figura.entities.Remove(arc);
                Arc arco = new Arc(new Vector2(arc.Center.X + item.X, arc.Center.X + item.X), arc.Radius, arc.StartAngle, arc.EndAngle);
                figura.entities.Add(arco);
            }

            return(figura);
        }
Exemplo n.º 20
0
        private void AddLwPolylines()
        {
            foreach (var lp in dxf.LwPolylines)
            {
                if (lp.Type == EntityType.LwPolyline)
                {
                    LwPolyline polygon = (LwPolyline)lp;

                    PathFigure           path     = new PathFigure();
                    float                bulge    = 0;
                    System.Windows.Point prePoint = new System.Windows.Point();
                    System.Windows.Point point    = new System.Windows.Point();

                    path.IsClosed = polygon.IsClosed;

                    for (int i = 0; i < polygon.Vertexes.Count(); ++i)
                    {
                        var seg = polygon.Vertexes[i];
                        //point = new System.Windows.Point(seg.Location.X, -seg.Location.Y);
                        point = new System.Windows.Point(seg.Position.X, -seg.Position.Y);

                        if (i == 0)
                        {
                            path.StartPoint = point;
                            prePoint        = point;
                            //bulge = seg.Bulge;
                            //angle = 4 * System.Math.Atan(seg.Bulge) / Math.PI * 180;
                        }
                        else
                        {
                            ArcSegment arc = new ArcSegment();
                            arc.Point = point;

                            //if (angle != 0)
                            if (bulge != 0)
                            {
                                double angle  = 4 * Math.Atan(Math.Abs(bulge)) / Math.PI * 180;
                                double length = Math.Sqrt((point.X - prePoint.X) * (point.X - prePoint.X) + (point.Y - prePoint.Y) * (point.Y - prePoint.Y));
                                //double radius = length / (Math.Sqrt(2 * (1 - Math.Cos(angle / 180 * Math.PI))));

                                double radius = Math.Abs(length / (2 * Math.Sin(angle / 360 * Math.PI)));

                                arc.Size          = new System.Windows.Size(radius, radius);
                                arc.RotationAngle = angle;

                                arc.SweepDirection = bulge < 0 ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                                arc.IsLargeArc     = Math.Abs(bulge) > 1 ? true : false;
                            }

                            prePoint = point;
                            //bulge = seg.Bulge;
                            //angle = 4 * System.Math.Atan(seg.Bulge) / Math.PI * 180;
                            path.Segments.Add(arc);
                        }
                    }
                    PathGeometry pathgeo = new PathGeometry();
                    pathgeo.Figures.Add(path);

                    //foreach (var _p in MyCanvas.Children)
                    //{
                    //    System.Windows.Shapes.Path _path = (System.Windows.Shapes.Path)_p;

                    //    if ((string)_path.Tag == p.Layer.Name)
                    //    {

                    //        ((GeometryGroup)_path.Data).Children.Add(pathgeo);
                    //    }
                    //}
                    System.Windows.Shapes.Path _path = new System.Windows.Shapes.Path();

                    GeometryGroup GeoGroup = new GeometryGroup();
                    GeoGroup.Children.Add(pathgeo);
                    _path.Stroke = new SolidColorBrush(System.Windows.Media.Colors.White);

                    _path.Data                 = GeoGroup;
                    _path.Tag                  = "polylines";
                    _path.StrokeThickness      = 2;
                    _path.MouseLeftButtonDown += (o, s) =>
                    {
                        CalculateIntersection(_path);
                    };


                    MyCanvas.Children.Add(_path);
                }
            }
        }
Exemplo n.º 21
0
 protected override void InternalWrite()
 {
     foreach (EntityObject entity in Document.Entities)
     {
         if (entity is AcadProxyEntity)
         {
             AcadProxyEntity e = entity as AcadProxyEntity;
             TextWriter.Write(Utilities.AcadProxyEntityToDxfFormat(e));
             continue;
         }
         if (entity is Arc)
         {
             Arc e = entity as Arc;
             TextWriter.Write(Utilities.ArcToDxfFormat(e));
             continue;
         }
         if (entity is Attrib)
         {
             Attrib e = entity as Attrib;
             TextWriter.Write(Utilities.AttribToDxfFormat(e));
             continue;
         }
         if (entity is AttributeDefinition)
         {
             AttributeDefinition e = entity as AttributeDefinition;
             TextWriter.Write(Utilities.AttributeDefinitionToDxfFormat(e));
             continue;
         }
         if (entity is Body)
         {
             Body e = entity as Body;
             TextWriter.Write(Utilities.BodyToDxfFormat(e));
             continue;
         }
         if (entity is Circle)
         {
             Circle e = entity as Circle;
             TextWriter.Write(Utilities.CircleToDxfFormat(e));
             continue;
         }
         if (entity is Dimension)
         {
             Dimension e = entity as Dimension;
             TextWriter.Write(Utilities.DimensionToDxfFormat(e));
             continue;
         }
         if (entity is Ellipse)
         {
             Ellipse e = entity as Ellipse;
             TextWriter.Write(Utilities.EllipseToDxfFormat(e));
             continue;
         }
         if (entity is EndSection)
         {
             EndSection e = entity as EndSection;
             TextWriter.Write(Utilities.EndSectionToDxfFormat(e));
             continue;
         }
         if (entity is Face3d)
         {
             Face3d e = entity as Face3d;
             TextWriter.Write(Utilities.Face3dToDxfFormat(e));
             continue;
         }
         if (entity is Hatch)
         {
             Hatch e = entity as Hatch;
             TextWriter.Write(Utilities.HatchToDxfFormat(e));
             continue;
         }
         if (entity is Helix)
         {
             Helix e = entity as Helix;
             TextWriter.Write(Utilities.HelixToDxfFormat(e));
             continue;
         }
         if (entity is Image)
         {
             Image e = entity as Image;
             TextWriter.Write(Utilities.ImageToDxfFormat(e));
             continue;
         }
         if (entity is Insert)
         {
             Insert e = entity as Insert;
             TextWriter.Write(Utilities.InsertToDxfFormat(e));
             continue;
         }
         if (entity is Leader)
         {
             Leader e = entity as Leader;
             TextWriter.Write(Utilities.LeaderToDxfFormat(e));
             continue;
         }
         if (entity is Light)
         {
             Light e = entity as Light;
             TextWriter.Write(Utilities.LightToDxfFormat(e));
             continue;
         }
         if (entity is Line)
         {
             Line e = entity as Line;
             TextWriter.Write(Utilities.LineToDxfFormat(e));
             continue;
         }
         if (entity is LwPolyline)
         {
             LwPolyline e = entity as LwPolyline;
             TextWriter.Write(Utilities.LwPolylineToDxfFormat(e));
             continue;
         }
         if (entity is Mesh)
         {
             Mesh e = entity as Mesh;
             TextWriter.Write(Utilities.MeshToDxfFormat(e));
             continue;
         }
         if (entity is MultiLeader)
         {
             MultiLeader e = entity as MultiLeader;
             TextWriter.Write(Utilities.MultiLeaderToDxfFormat(e));
             continue;
         }
         if (entity is MultiLeaderStyle)
         {
             MultiLeaderStyle e = entity as MultiLeaderStyle;
             TextWriter.Write(Utilities.MultiLeaderStyleToDxfFormat(e));
             continue;
         }
         if (entity is MultiLine)
         {
             MultiLine e = entity as MultiLine;
             TextWriter.Write(Utilities.MultiLineToDxfFormat(e));
             continue;
         }
         if (entity is MultiText)
         {
             MultiText e = entity as MultiText;
             TextWriter.Write(Utilities.MultiTextToDxfFormat(e));
             continue;
         }
         if (entity is Ole2Frame)
         {
             Ole2Frame e = entity as Ole2Frame;
             TextWriter.Write(Utilities.Ole2FrameToDxfFormat(e));
             continue;
         }
         if (entity is OleFrame)
         {
             OleFrame e = entity as OleFrame;
             TextWriter.Write(Utilities.OleFrameToDxfFormat(e));
             continue;
         }
         if (entity is Point)
         {
             Point e = entity as Point;
             TextWriter.Write(Utilities.PointToDxfFormat(e));
             continue;
         }
         if (entity is PolyLine)
         {
             PolyLine e = entity as PolyLine;
             TextWriter.Write(Utilities.PolyLineToDxfFormat(e));
             continue;
         }
         if (entity is Ray)
         {
             Ray e = entity as Ray;
             TextWriter.Write(Utilities.RayToDxfFormat(e));
             continue;
         }
         if (entity is Region)
         {
             Region e = entity as Region;
             TextWriter.Write(Utilities.RegionToDxfFormat(e));
             continue;
         }
         if (entity is Section)
         {
             Section e = entity as Section;
             TextWriter.Write(Utilities.SectionToDxfFormat(e));
             continue;
         }
         if (entity is Shape)
         {
             Shape e = entity as Shape;
             TextWriter.Write(Utilities.ShapeToDxfFormat(e));
             continue;
         }
         if (entity is Solid)
         {
             Solid e = entity as Solid;
             TextWriter.Write(Utilities.SolidToDxfFormat(e));
             continue;
         }
         if (entity is Solid3d)
         {
             Solid3d e = entity as Solid3d;
             TextWriter.Write(Utilities.Solid3dToDxfFormat(e));
             continue;
         }
         if (entity is Spline)
         {
             Spline e = entity as Spline;
             TextWriter.Write(Utilities.SplineToDxfFormat(e));
             continue;
         }
         if (entity is Sun)
         {
             Sun e = entity as Sun;
             TextWriter.Write(Utilities.SunToDxfFormat(e));
             continue;
         }
         if (entity is Surface)
         {
             Surface e = entity as Surface;
             TextWriter.Write(Utilities.SurfaceToDxfFormat(e));
             continue;
         }
         if (entity is Table)
         {
             Table e = entity as Table;
             TextWriter.Write(Utilities.TableToDxfFormat(e));
             continue;
         }
         if (entity is Text)
         {
             Text e = entity as Text;
             TextWriter.Write(Utilities.TextToDxfFormat(e));
             continue;
         }
         if (entity is Tolerance)
         {
             Tolerance e = entity as Tolerance;
             TextWriter.Write(Utilities.ToleranceToDxfFormat(e));
             continue;
         }
         if (entity is Trace)
         {
             Trace e = entity as Trace;
             TextWriter.Write(Utilities.TraceToDxfFormat(e));
             continue;
         }
         if (entity is Underlay)
         {
             Underlay e = entity as Underlay;
             TextWriter.Write(Utilities.UnderlayToDxfFormat(e));
             continue;
         }
         if (entity is Vertex)
         {
             Vertex e = entity as Vertex;
             TextWriter.Write(Utilities.VertexToDxfFormat(e));
             continue;
         }
         if (entity is ViewPort)
         {
             ViewPort e = entity as ViewPort;
             TextWriter.Write(Utilities.ViewPortToDxfFormat(e));
             continue;
         }
         if (entity is WipeOut)
         {
             WipeOut e = entity as WipeOut;
             TextWriter.Write(Utilities.WipeOutToDxfFormat(e));
             continue;
         }
         if (entity is XLine)
         {
             XLine e = entity as XLine;
             TextWriter.Write(Utilities.XLineToDxfFormat(e));
             continue;
         }
     }
 }
Exemplo n.º 22
0
        public DxfDocument DrawRbar(int id, bool inside, double offset)
        {
            //decides where to put the rbar to avoid overlaping
            double factor, shift = Math.Max(Math.Abs(this.Y1 - this.Y0), Math.Abs(this.Y3 - this.Y2)) + 10;

            if (inside == true)
            {
                factor = 0;
            }
            else
            {
                factor = -Convert.ToInt32(id) % 2;
            }

            //checks if there are any hooks
            double shiftLeft = 0, bulgeLeft = 0, shiftRight = 0, bulgeRight = 0,
                   flipLeft = 1, flipRight = 1;

            if (this.Y1 - this.Y0 != 0)
            {
                shiftLeft = 2 * this.Diameter / 10;
                bulgeLeft = 0.4;
            }
            if (this.Y3 - this.Y2 != 0)
            {
                shiftRight = 2 * this.Diameter / 10;
                bulgeRight = 0.4;
            }
            if (this.Y0 < this.Y1)
            {
                flipLeft = -1;
            }
            if (this.Y3 < this.Y2)
            {
                flipRight = -1;
            }

            //find rbar boundary to draw
            List <netDxf.Entities.LwPolylineVertex> vertexes = new List <netDxf.Entities.LwPolylineVertex>()
            {
                new netDxf.Entities.LwPolylineVertex(this.X0, this.Y0 + offset - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X1, this.Y1 + offset + flipLeft * shiftLeft - shift * factor, flipLeft * bulgeLeft),
                new netDxf.Entities.LwPolylineVertex(this.X1 + shiftLeft, this.Y1 + offset - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X2 - shiftRight, this.Y2 + offset - shift * factor, flipRight * bulgeRight),
                new netDxf.Entities.LwPolylineVertex(this.X2, this.Y2 + offset + flipRight * shiftRight - shift * factor),
                new netDxf.Entities.LwPolylineVertex(this.X3, this.Y3 + offset - shift * factor),
            };

            //draw rbar
            LwPolyline rbar = new LwPolyline(vertexes.GetRange(0, 6));

            rbar.SetConstantWidth(this.Diameter / 10);
            Beam.I.Dxf.AddEntity(rbar);

            //if inside of the beam, return
            if (inside)
            {
                return(Beam.I.Dxf);
            }

            //find rbar points to annotate
            Vector2[] points =
            {
                new Vector2(this.X0, this.Y0 + offset - shift * factor),
                new Vector2(this.X1, this.Y1 + offset - shift * factor),
                new Vector2(this.X2, this.Y2 + offset - shift * factor),
                new Vector2(this.X3, this.Y3 + offset - shift * factor),
            };

            //generate description text
            string descriptionText = "(" + id + ") " + this.NumberOfRbars.ToString() + "#" + this.Diameter.ToString() + " L=";

            descriptionText += (Math.Abs(this.Y0 - this.Y1) + Math.Abs(this.X0 - this.X2) + Math.Abs(this.Y3 - this.Y2)).ToString();

            //add description of a rbar
            LinearDimension dim = new LinearDimension(
                points[1],
                points[2],
                1.8,
                0,
                Beam.I.DimensionStyles.Annotation);

            dim.UserText = descriptionText;
            Beam.I.Dxf.AddEntity(dim);

            //check if there's a left hook and dim
            if (this.Y0 != this.Y1)
            {
                LinearDimension leftHookDim = new LinearDimension(
                    points[0],
                    points[1],
                    -5.4,
                    90,
                    Beam.I.DimensionStyles.Rbars);
                Beam.I.Dxf.AddEntity(leftHookDim);
            }

            //draw dimension of the main part of a rbar
            LinearDimension rbarDim = new LinearDimension(
                points[1],
                points[2],
                -5.4,
                0,
                Beam.I.DimensionStyles.Rbars);

            Beam.I.Dxf.AddEntity(rbarDim);

            //check if there's a right hook and dim
            if (this.Y2 != this.Y3)
            {
                LinearDimension rightHookDim = new LinearDimension(
                    points[2],
                    points[3],
                    -5.4,
                    90,
                    Beam.I.DimensionStyles.Rbars);
                Beam.I.Dxf.AddEntity(rightHookDim);
            }
            return(Beam.I.Dxf);
        }
Exemplo n.º 23
0
        private void DrawPolyline(LwPolyline l)
        {
            var ex = l.Explode();

            EntitiesToFcs(ex);
        }
Exemplo n.º 24
0
        public void ImportDxfDrawing(string dxfName, ProjectLoadingView loadingForm)
        {

            loadingForm.ShowProgress(0,"导入环境初始化...");
            //DbConnection.GetConnection().Open();
            MainService mainService = ServiceFactory.GetMainService();
            TmpCaddService caddService = ServiceFactory.GetTmpCaddService();
            TmpCadxService cadxService = ServiceFactory.GetTmpCadxService();
            TmpCadmService cadmService = ServiceFactory.GetTmpCadmService();
            TmpCadzjService cadzjService = ServiceFactory.GetTmpCadzjService();
            TmpCadxdataService cadxdataService = ServiceFactory.GetTmpCadxdataService();
            
            int srid = mainService.GetGeometryColumnSRID("tmpcadd", "geometry");
            mainService.ClearCADTemps();
           
            
            DataSource ds = Ogr.Open(dxfName, 0);
            Driver drv = ds.GetDriver();
            loadingForm.ShowProgress(0, "导入图形数据...");
            for (int i = 0; i < ds.GetLayerCount(); i++)
            {
                Layer pLayer = ds.GetLayerByIndex(i);
                Feature feat = pLayer.GetNextFeature();
                while (feat != null)
                {
                    string handle = feat.GetFieldAsString(4);
                    string typeName = feat.GetFieldAsString(1).Trim().Replace("AcDbEntity:","");
                    string geomtryStr = "";
                    Geometry geometry = feat.GetGeometryRef();
                    geometry.FlattenTo2D();
                    geometry.ExportToWkt(out geomtryStr);
                    switch (typeName)
                    {
                        case "AcDbPolyline":
                        case "AcDbLine":
                            TmpCadx cadx = new TmpCadx(handle, geomtryStr, "POLYLINE", dxfName);
                            cadxService.Create(cadx);
                            break;
                        case "AcDbBlockReference":
                            //TmpCadd cadd=new TmpCadd(handle, geomtryStr, "POINT");
                            //caddService.Create(cadd);
                            //因为GDAL直接读取了块图形,因此,块在下面的方法和属性一起读取
                            break;
                        case "AcDbText:AcDbText":
                            TmpCadzj cadzj = new TmpCadzj(handle, geomtryStr, "TEXT", dxfName);
                            cadzjService.Create(cadzj);
                            break;
                      
                    }
                  
                    feat.Dispose();
                    feat = pLayer.GetNextFeature();
                }
            }
            

            //开始使用netDxf读取数据
            DxfDocument doc=DxfDocument.Load(dxfName);
            //开始读取点数据
            loadingForm.ShowProgress(40, "导入块参照属性...");
            for (int i = 0; i < doc.Inserts.Count; i++)
            {
                Insert insert= doc.Inserts[i];
                TmpCadd cadd=new TmpCadd();
                cadd.Handle = insert.Handle;
                cadd.EntityType = "POINT";
                cadd.FileName = dxfName;
                cadd.Geometry =
                    DbGeometry.FromText(string.Format("POINT({0} {1})", insert.Position.X, insert.Position.Y));
                caddService.Create(cadd);

                TmpCadxdata cadxdata = new TmpCadxdata();
                cadxdata.Handle = insert.Handle;
                cadxdata.Tc = insert.Layer.Name;
                cadxdata.Fh = insert.Block.Name;
                cadxdata.Fhdx = insert.Scale.X;
                cadxdata.Xzjd = insert.Rotation;
                cadxdata.FileName = dxfName;
                cadxdata = ReadXData(cadxdata, insert.XData);
                cadxdataService.Create(cadxdata);
            }

            //开始读取点数据
            loadingForm.ShowProgress(50, "导入文本数据...");
            for (int i = 0; i < doc.Texts.Count; i++)
            {
                Text insert = doc.Texts[i];
                //TmpCadd cadd = new TmpCadd();
                //cadd.Handle = insert.Handle;
                //cadd.EntityType = "POINT";
                //cadd.Geometry =
                //    DbGeometry.FromText(string.Format("POINT({0} {1})", insert.Position.X, insert.Position.Y));
                //caddService.Create(cadd);

                TmpCadxdata cadxdata = new TmpCadxdata();
                cadxdata.Handle = insert.Handle;
                cadxdata.Tc = insert.Layer.Name;
                cadxdata.Fh = insert.Style.FontFamilyName;
                cadxdata.Fhdx = insert.Height;
                cadxdata.Xzjd = insert.Rotation;
                cadxdata.Wbnr = insert.Value;
                cadxdata.FileName = dxfName;
                cadxdata = ReadXData(cadxdata, insert.XData);
                cadxdataService.Create(cadxdata);
            }

            //开始读取线数据
            loadingForm.ShowProgress(60, "导入线数据...");
            for (int i = 0; i < doc.Lines.Count; i++)
            {
                Line insert = doc.Lines[i];
                //TmpCadd cadd = new TmpCadd();
                //cadd.Handle = insert.Handle;
                //cadd.EntityType = "POINT";
                //cadd.Geometry =
                //    DbGeometry.FromText(string.Format("POINT({0} {1})", insert.Position.X, insert.Position.Y));
                //caddService.Create(cadd);

                TmpCadxdata cadxdata = new TmpCadxdata();
                cadxdata.Handle = insert.Handle;
                cadxdata.Tc = insert.Layer.Name;
                cadxdata.Fh = insert.Linetype.Name;
                cadxdata.Fhdx = insert.LinetypeScale;
                cadxdata.Xzjd = 0.0;
                cadxdata.Wbnr = "";
                cadxdata.FileName = dxfName;
                cadxdata = ReadXData(cadxdata, insert.XData);
                cadxdataService.Create(cadxdata);
            }
            loadingForm.ShowProgress(80, "导入多边形数据...");
            for (int i = 0; i < doc.LwPolylines.Count; i++)
            {
                LwPolyline insert = doc.LwPolylines[i];
                if (insert.IsClosed)
                {
                    //插入多边形
                    TmpCadx cadx = cadxService.GetTmpCadx(insert.Handle);
                    if (cadx != null)
                    {
                        TmpCadm cadm=new TmpCadm() {Handle = cadx.Handle,EntityType="POLYGON",FileName=dxfName};
                        string wkt = cadx.Geometry.AsText();
                        Geometry geometry = Ogr.ForceToPolygon(Geometry.CreateFromWkt(wkt));
                        string geomStr = "";
                        geometry.ExportToWkt(out geomStr);
                        geomStr = geomStr.Replace("LINESTRING", "POLYGON (") + ")";
                        cadm.Geometry = DbGeometry.FromText(geomStr);
                        cadmService.Create(cadm);
                    }
                }
                //TmpCadd cadd = new TmpCadd();
                //cadd.Handle = insert.Handle;
                //cadd.EntityType = "POINT";
                //cadd.Geometry =
                //    DbGeometry.FromText(string.Format("POINT({0} {1})", insert.Position.X, insert.Position.Y));
                //caddService.Create(cadd);

                TmpCadxdata cadxdata = new TmpCadxdata();
                cadxdata.Handle = insert.Handle;
                cadxdata.Tc = insert.Layer.Name;
                cadxdata.Fh = insert.Linetype.Name;
                cadxdata.Fhdx = insert.LinetypeScale;
                cadxdata.Xzjd = 0.0;
                cadxdata.Wbnr = "";
                cadxdata.FileName = dxfName;
                cadxdata = ReadXData(cadxdata, insert.XData);
                cadxdataService.Create(cadxdata);
            }

            for (int i = 0; i < doc.Polylines.Count; i++)
            {
                Polyline insert = doc.Polylines[i];
                if (insert.IsClosed)
                {
                    //插入多边形
                    TmpCadx cadx = cadxService.GetTmpCadx(insert.Handle);
                    if (cadx != null)
                    {
                        TmpCadm cadm = new TmpCadm() { Handle = cadx.Handle, EntityType = "POLYGON" ,FileName = dxfName};
                        string wkt = cadx.Geometry.AsText();
                        Geometry geometry = Ogr.ForceToPolygon(Geometry.CreateFromWkt(wkt));
                        string geomStr = "";
                        geometry.ExportToWkt(out geomStr);
                        geomStr=geomStr.Replace("LINESTRING", "POLYGON (")+")";
                        cadm.Geometry = DbGeometry.FromText(geomStr);
                        cadmService.Create(cadm);
                    }
                }
                //TmpCadd cadd = new TmpCadd();
                //cadd.Handle = insert.Handle;
                //cadd.EntityType = "POINT";
                //cadd.Geometry =
                //    DbGeometry.FromText(string.Format("POINT({0} {1})", insert.Position.X, insert.Position.Y));
                //caddService.Create(cadd);

                TmpCadxdata cadxdata = new TmpCadxdata();
                cadxdata.Handle = insert.Handle;
                cadxdata.Tc = insert.Layer.Name;
                cadxdata.Fh = insert.Linetype.Name;
                cadxdata.Fhdx = insert.LinetypeScale;
                cadxdata.Xzjd = 0.0;
                cadxdata.Wbnr = "";
                cadxdata.FileName = dxfName;
                cadxdata = ReadXData(cadxdata, insert.XData);
                cadxdataService.Create(cadxdata);
            }
            loadingForm.ShowProgress(100, "导入完成...");
            //mainService.Close();
        }
Exemplo n.º 25
0
        public DxfDocument DrawSectionMarks(List <Section> sections)
        {
            List <LwPolylineVertex> vertexes = new List <LwPolylineVertex>()
            {
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH, Beam.I.Height + 3 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH, Beam.I.Height + 1 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH, -3 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH, -5 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH, Beam.I.Height + 3 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH, Beam.I.Height + 1 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH, -3 * this._SectionMarkOffsetV),
                new LwPolylineVertex(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH, -5 * this._SectionMarkOffsetV),
            };

            Vector2[] textLocations =
            {
                new Vector2(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH + 2,                   Beam.I.Height + 2 * this._SectionMarkOffsetV - 4),
                new Vector2(this._Translation + this.LeftSupportWidth + this._SectionMarkOffsetH + 2,                                  -4 * this._SectionMarkOffsetV - 4),
                new Vector2(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH + 2, Beam.I.Height + 2 * this._SectionMarkOffsetV - 4),
                new Vector2(this._Translation + this.LeftSupportWidth + this.SpanLength - this._SectionMarkOffsetH + 2,                -4 * this._SectionMarkOffsetV - 4),
            };

            Section sectionL = new Section(
                this._TopLeftRbarDiameter / 10,
                this._NumberOfTopLeftRbars,
                this._BottomRbarDiameter / 10,
                this._NumberOfBottomRbars,
                string.Format("{0} - {0}L", this._Id));

            sections.Add(sectionL);

            Section sectionR = new Section(
                this._TopRightRbarDiameter / 10,
                this._NumberOfTopRightRbars,
                this._BottomRbarDiameter / 10,
                this._NumberOfBottomRbars,
                string.Format("{0} - {0}P", this._Id));

            sections.Add(sectionR);

            if (this.DrawLeftSection == true)
            {
                sectionL.Draw = true;

                LwPolyline markUpL = new LwPolyline(vertexes.GetRange(0, 2));
                markUpL.SetConstantWidth(this._SectionMarkWidth);
                Beam.I.Dxf.AddEntity(markUpL);

                Beam.I.Dxf.AddEntity(new Text(
                                         string.Format("{0}L", this._Id),
                                         textLocations[0],
                                         this._SectionMarkTextHeight));

                LwPolyline markDownL = new LwPolyline(vertexes.GetRange(2, 2));
                markDownL.SetConstantWidth(this._SectionMarkWidth);
                Beam.I.Dxf.AddEntity(markDownL);

                Beam.I.Dxf.AddEntity(new Text(
                                         string.Format("{0}L", this._Id),
                                         textLocations[1],
                                         this._SectionMarkTextHeight));
            }

            if (this.DrawRightSection == true)
            {
                sectionR.Draw = true;

                LwPolyline markUpR = new LwPolyline(vertexes.GetRange(4, 2));
                markUpR.SetConstantWidth(this._SectionMarkWidth);
                Beam.I.Dxf.AddEntity(markUpR);

                Beam.I.Dxf.AddEntity(new Text(
                                         string.Format("{0}P", this._Id),
                                         textLocations[2],
                                         this._SectionMarkTextHeight));

                LwPolyline markDownR = new LwPolyline(vertexes.GetRange(6, 2));
                markDownR.SetConstantWidth(this._SectionMarkWidth);
                Beam.I.Dxf.AddEntity(markDownR);

                Beam.I.Dxf.AddEntity(new Text(
                                         string.Format("{0}P", this._Id),
                                         textLocations[3],
                                         this._SectionMarkTextHeight));
            }
            return(Beam.I.Dxf);
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            var dxf = new netDxf.DxfDocument();

            var rValues1 = new List <double>()
            {
                1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9,
                4.7, 5.6, 6.8, 8.2, 10, 12, 15, 18, 22,
                27, 33, 39, 47, 56, 68, 82, 100,
                120, 150, 180, 220, 270, 330, 390, 470,
                560, 680, 820,

                1e3, 1.2e3, 1.5e3, 1.8e3, 2.2e3, 2.7e3,
                3.3e3, 3.9e3, 4.7e3, 5.5e3, 6.8e3, 7.2e3, 8.2e3, 10e3, 12e3,
                15e3, 18e3, 22e3, 27e3, 33e3, 39e3, 47e3, 56e3, 82e3, 100e3,
                120e3, 150e3, 180e3, 220e3, 270e3, 330e3, 380e3,
                470e3, 560e3, 680e3, 820e3,

                1e6, 1.2e6, 1.5e6, 1.8e6, 2.2e6, 2.7e6, 3.3e6, 3.9e6, 4.7e6,
                5.6e6, 6.8e6, 8.2e6, 10e6
            };

            var rValues2 = new List <double>()
            {
                7.5, 75, 200, 510,

                2e3, 3e3, 5.1e3, 7.5e3, 20e3, 51e3, 68e3, 75e3, 200e3, 510e3, 750e3,

                2e6
            };

            var rValues3 = new List <double>()
            {
                1.2, 1.5, 1.8, 2.7, 3.3, 3.9, 6.8, 12, 18, 560, 820,
                1.2e3, 1.8e3, 2.7e3, 12e3, 18e3, 27e3, 270e3, 380e3,
                5.6e3, 300e3,
                1.2e6, 1.8e6, 2.2e6, 2.7e6, 3.9e6, 6.8e6, 8.2e6
            };

            var DATA = rValues1.Union(rValues2).Union(rValues3).OrderBy(w => w).ToList();

            var PAGE_W = 210d;
            var PAGE_H = 297d;

            var LABEL_W = 25d;
            var LABEL_H = 20d;

            var MARGINS_LTRB = new[] { 10d, 10d, 10d, 10d };

            var COLS = Math.Truncate((PAGE_W - MARGINS_LTRB[0] - MARGINS_LTRB[2]) / LABEL_W);
            var ROWS = Math.Truncate((PAGE_H - MARGINS_LTRB[1] - MARGINS_LTRB[3]) / LABEL_H);

            var XORIGIN = 0d;
            var YORIGIN = 0d;

            var TXT_HEIGHT = 5d;
            var OHM_HEIGHT = 3d;
            var TXT_FONT   = new netDxf.Tables.TextStyle("Ubuntu Condensed", netDxf.Tables.FontStyle.Regular);

            var x = XORIGIN;
            var y = YORIGIN;

            int page = 0;

            for (int i = 0; i < DATA.Count; ++i)
            {
                var r = DATA[i];

                var prefix = "";
                if (r >= 1e6)
                {
                    prefix = " M";
                    r     /= 1e6;
                }
                else if (r >= 1e3)
                {
                    prefix = " k";
                    r     /= 1e3;
                }

                var txt = Invariant($"\\H{TXT_HEIGHT};{r}{prefix} \\H{OHM_HEIGHT};Ω");

                {
                    var ent = new LwPolyline(new[]
                    {
                        new Vector2(x, y),
                        new Vector2(x + LABEL_W, y),
                        new Vector2(x + LABEL_W, y + LABEL_H),
                        new Vector2(x, y + LABEL_H),
                    }, isClosed: true);
                    dxf.AddEntity(ent);
                }

                {
                    var ent = new MText(txt)
                    {
                        Position        = new Vector3(x + LABEL_W / 2, y + LABEL_H / 2, 0),
                        Height          = TXT_HEIGHT,
                        RectangleWidth  = LABEL_W,
                        AttachmentPoint = MTextAttachmentPoint.MiddleCenter,
                        Style           = TXT_FONT
                    };
                    dxf.AddEntity(ent);
                }

                x += LABEL_W;
                if ((i + 1) % COLS == 0)
                {
                    y += LABEL_H;

                    if (y >= ROWS * LABEL_H)
                    {
                        y = YORIGIN;
                        ++page;
                    }
                    x = XORIGIN + page * (PAGE_W + LABEL_W);
                }
            }

            dxf.Save("output.dxf", isBinary: false);

            Process.Start(new ProcessStartInfo("output.dxf")
            {
                UseShellExecute = true
            });
        }
Exemplo n.º 27
0
        private List <int> DrawPolyline(LwPolyline l)
        {
            var ex = l.Explode();
            var v  = new List <Vector3Middle>();

            var i = 0;

            foreach (var en in ex)
            {
                if (en is Line line)
                {
                    var A = line.StartPoint;
                    var B = line.EndPoint;

                    if (i == 0)
                    {
                        v.Add(new Vector3Middle(A));
                        v.Add(new Vector3Middle(B));
                    }
                    else
                    {
                        var L = v[v.Count - 1].Point;

                        // if the first entity was in wrong orientation
                        if (i == 1 && !L.Equals(A, Math.Pow(10, -8)) && !L.Equals(B, Math.Pow(10, -8)))
                        {
                            ReverseFcsPolyline(v);
                        }

                        // if current entity is in wrong orientation
                        if (!L.Equals(A, Math.Pow(10, -8)))
                        {
                            v.Add(new Vector3Middle(A));
                        }
                        else
                        {
                            v.Add(new Vector3Middle(B));
                        }
                    }
                }

                else if (en is Arc arc)
                {
                    AddArcToArc(arc, i, v);
                }

                i++;
            }

            var Lc = v.Last().Point;

            if (l.IsClosed && !Lc.Equals(v[0].Point, Math.Pow(10, -8)))
            {
                v.Add(v[0]);
            }

            var ids = new List <int>();

            // drawing
            var polyline = new List <Vector3>();

            polyline.Add(v[0].Point);

            for (int j = 1; j < v.Count; j++)
            {
                var cr = v[j];

                if (cr.MiddlePoint == default)
                {
                    polyline.Add(cr.Point);
                }
                else
                {
                    if (polyline.Count > 1)
                    {
                        ids.Add(DrawCurve(polyline));
                    }

                    var A = polyline.Last();
                    var B = cr.Point;
                    var C = cr.MiddlePoint;

                    ids.Add(DrawArc(A, B, C));

                    polyline.Clear();
                    polyline.Add(B);
                }
            }

            if (polyline.Count > 1)
            {
                ids.Add(DrawCurve(polyline));
            }

            return(ids);
        }
Exemplo n.º 28
0
 public void GetPolyline()
 {
     LaneHeights_Polyline.LwPolyline o = new LwPolyline();
     o.SelectPolyline("\nSelect a Polyline");
 }