Beispiel #1
0
 private void WriteCircle(DxfCircle circle)
 {
     WriteItemType(DxbItemType.Circle);
     WriteN(circle.Center.X);
     WriteN(circle.Center.Y);
     WriteN(circle.Radius);
 }
Beispiel #2
0
        /// <summary>
        /// 方法,向模型空间添加一个圆
        /// </summary>
        /// <param name="_centerX">圆心的X坐标</param>
        /// <param name="_centerY">圆心的Y坐标</param>
        /// <param name="_radius">圆的半径</param>
        /// <param name="_isSolid">实心或空心,true为实心</param>
        /// <returns></returns>
        public DxfCircle AddCircle(double _centerX, double _centerY, double _radius, bool _isSolid)
        {
            DxfCircle circle = new DxfCircle(new Point2D(_centerX, _centerY), _radius);

            Model.Entities.Add(circle);

            if (_isSolid)
            {
                DxfHatch hatch = new DxfHatch();

                DxfHatch.BoundaryPath boundary = new DxfHatch.BoundaryPath();
                boundary.Type = BoundaryPathType.Outermost;
                hatch.BoundaryPaths.Add(boundary);
                DxfHatch.BoundaryPath.ArcEdge arcEdge = new DxfHatch.BoundaryPath.ArcEdge();
                arcEdge.Center     = new Point2D(_centerX, _centerY);
                arcEdge.Radius     = 1;
                arcEdge.StartAngle = 0;
                arcEdge.EndAngle   = System.Math.PI * 2;
                boundary.Edges.Add(arcEdge);

                Model.Entities.Add(hatch);
            }

            return(circle);
        }
Beispiel #3
0
 public void RenderEntity(DxfCircle dxfCircle, Graphics graphics, int height)
 {
     graphics.DrawEllipse(Pens.Black,
                          (float)(dxfCircle.Center.X - dxfCircle.Radius) * ScaleFactor + OffsetX,
                          height - (float)(dxfCircle.Center.Y + dxfCircle.Radius) * ScaleFactor + OffsetY,
                          (float)dxfCircle.Radius * 2f * ScaleFactor,
                          (float)dxfCircle.Radius * 2f * ScaleFactor);
 }
        public static DxfPoint GetPointFromAngle(this DxfCircle circle, double angleInDegrees)
        {
            var angleInRadians = angleInDegrees * Math.PI / 180.0;
            var sin            = Math.Sin(angleInRadians);
            var cos            = Math.Cos(angleInRadians);

            return(new DxfPoint(cos * circle.Radius, sin * circle.Radius, 0.0) + circle.Center);
        }
Beispiel #5
0
 void ProcessDxfCircle(DxfCircle dxfCircle)
 {
     PicArc picArc = Factory.AddArc(
         DxfColor2PicLT(dxfCircle), DxfLayer2PicGrp(dxfCircle.Layer), 0
         , new Vector2D(dxfCircle.Center.X, dxfCircle.Center.Y)
         , dxfCircle.Radius
         , 0.0, 360.0
         );
 }
Beispiel #6
0
        public string EntityToJson(DxfCircle dxfCircle)
        {
            // We dont care about center

            return(string.Format(Format, "[\"circle\",{0:F},{1:F},{2:F}]",
                                 dxfCircle.Center.X,
                                 dxfCircle.Center.Y,
                                 dxfCircle.Radius));
        }
Beispiel #7
0
        public void CircleAngleToPointTest()
        {
            var circle = new DxfCircle(new DxfPoint(1.0, 2.0, 3.0), 4.0);

            AssertClose(new DxfPoint(5.0, 2.0, 3.0), circle.GetPointFromAngle(0.0));
            AssertClose(new DxfPoint(1.0, 6.0, 3.0), circle.GetPointFromAngle(90.0));
            AssertClose(new DxfPoint(-3.0, 2.0, 3.0), circle.GetPointFromAngle(180.0));
            AssertClose(new DxfPoint(1.0, -2.0, 3.0), circle.GetPointFromAngle(270.0));
            AssertClose(new DxfPoint(5.0, 2.0, 3.0), circle.GetPointFromAngle(360.0));
        }
        private static IEnumerable <IPdfPathItem> ConvertCircle(DxfCircle circle, DxfLayer layer, Matrix4 affine, Matrix4 scale)
        {
            var pdfStreamState = new PdfStreamState(
                strokeColor: GetPdfColor(circle, layer),
                strokeWidth: GetStrokeWidth(circle, layer));
            // a circle becomes an ellipse, unless aspect ratio is kept.
            var center = affine.Transform(circle.Center).ToPdfPoint(PdfMeasurementType.Point);
            var radius = scale.Transform(new Vector(circle.Radius, circle.Radius, circle.Radius))
                         .ToPdfPoint(PdfMeasurementType.Point);

            yield return(new PdfEllipse(center, radius.X, radius.Y, state: pdfStreamState));
        }
 public static XElement ToXElement(this DxfCircle circle)
 {
     return(new XElement(DxfToSvgConverter.Xmlns + "ellipse",
                         new XAttribute("cx", circle.Center.X.ToDisplayString()),
                         new XAttribute("cy", circle.Center.Y.ToDisplayString()),
                         new XAttribute("rx", circle.Radius.ToDisplayString()),
                         new XAttribute("ry", circle.Radius.ToDisplayString()),
                         new XAttribute("fill-opacity", 0))
            .AddStroke(circle.Color)
            .AddStrokeWidth(circle.Thickness)
            .AddVectorEffect());
 }
Beispiel #10
0
        public void RenderCircleTest()
        {
            var circle   = new DxfCircle(new DxfPoint(1.0, 2.0, 3.0), 4.0);
            var expected = new XElement("ellipse",
                                        new XAttribute("cx", "1.0"), new XAttribute("cy", "2.0"),
                                        new XAttribute("rx", "4.0"), new XAttribute("ry", "4.0"),
                                        new XAttribute("fill-opacity", "0"),
                                        new XAttribute("stroke-width", "1.0px"),
                                        new XAttribute("vector-effect", "non-scaling-stroke"));
            var actual = circle.ToXElement();

            AssertXElement(expected, actual);
        }
Beispiel #11
0
 public void Visit(DxfCircle circle)
 {
     this.bool_0 = true;
 }
Beispiel #12
0
 public void Visit(DxfCircle circle)
 {
     this.method_0((DxfEntity)circle);
 }
Beispiel #13
0
 /// <summary>
 /// 圆圈
 /// </summary>
 /// <param name="doc"></param>
 /// <param name="DLocation"></param>
 /// <param name="radius"></param>
 public static void writeCirle(DxfModel doc, DLocation DLocation,double radius)
 {
     DxfCircle dxfCirle = new DxfCircle(new Point3D(DLocation.X, DLocation.Y, DLocation.Z), radius);
     doc.Entities.Add(dxfCirle);
 }
Beispiel #14
0
        public static RawDetail LoadDxf(string path)
        {
            FileInfo  fi      = new FileInfo(path);
            DxfFile   dxffile = DxfFile.Load(fi.FullName);
            RawDetail s       = new RawDetail();

            s.Name = fi.FullName;
            IEnumerable <DxfEntity> entities = dxffile.Entities.ToArray();

            List <LineElement> elems = new List <LineElement>();

            foreach (DxfEntity ent in entities)
            {
                switch (ent.EntityType)
                {
                case DxfEntityType.LwPolyline:
                {
                    DxfLwPolyline poly = (DxfLwPolyline)ent;
                    if (poly.Vertices.Count() < 2)
                    {
                        continue;
                    }
                    LocalContour points = new LocalContour();
                    foreach (DxfLwPolylineVertex vert in poly.Vertices)
                    {
                        points.Points.Add(new PointF((float)vert.X, (float)vert.Y));
                    }
                    for (int i = 0; i < points.Points.Count; i++)
                    {
                        var p0 = points.Points[i];
                        var p1 = points.Points[(i + 1) % points.Points.Count];
                        elems.Add(new LineElement()
                            {
                                Start = p0, End = p1
                            });
                    }
                }
                break;

                case DxfEntityType.Arc:
                {
                    DxfArc        arc = (DxfArc)ent;
                    List <PointF> pp  = new List <PointF>();

                    if (arc.StartAngle > arc.EndAngle)
                    {
                        arc.StartAngle -= 360;
                    }

                    for (double i = arc.StartAngle; i < arc.EndAngle; i += 15)
                    {
                        var tt = arc.GetPointFromAngle(i);
                        pp.Add(new PointF((float)tt.X, (float)tt.Y));
                    }
                    var t = arc.GetPointFromAngle(arc.EndAngle);
                    pp.Add(new PointF((float)t.X, (float)t.Y));
                    for (int j = 1; j < pp.Count; j++)
                    {
                        var p1 = pp[j - 1];
                        var p2 = pp[j];
                        elems.Add(new LineElement()
                            {
                                Start = new PointF((float)p1.X, (float)p1.Y), End = new PointF((float)p2.X, (float)p2.Y)
                            });
                    }
                }
                break;

                case DxfEntityType.Circle:
                {
                    DxfCircle    cr = (DxfCircle)ent;
                    LocalContour cc = new LocalContour();

                    for (int i = 0; i <= 360; i += 15)
                    {
                        var ang = i * Math.PI / 180f;
                        var xx  = cr.Center.X + cr.Radius * Math.Cos(ang);
                        var yy  = cr.Center.Y + cr.Radius * Math.Sin(ang);
                        cc.Points.Add(new PointF((float)xx, (float)yy));
                    }
                    for (int i = 1; i < cc.Points.Count; i++)
                    {
                        var p1 = cc.Points[i - 1];
                        var p2 = cc.Points[i];
                        elems.Add(new LineElement()
                            {
                                Start = p1, End = p2
                            });
                    }
                }
                break;

                case DxfEntityType.Line:
                {
                    DxfLine poly = (DxfLine)ent;
                    elems.Add(new LineElement()
                        {
                            Start = new PointF((float)poly.P1.X, (float)poly.P1.Y), End = new PointF((float)poly.P2.X, (float)poly.P2.Y)
                        });
                    break;
                }

                case DxfEntityType.Polyline:
                {
                    DxfPolyline poly = (DxfPolyline)ent;
                    if (poly.Vertices.Count() < 2)
                    {
                        continue;
                    }
                    LocalContour points = new LocalContour();
                    for (int i = 0; i < poly.Vertices.Count; i++)
                    {
                        DxfVertex vert = poly.Vertices[i];
                        points.Points.Add(new PointF((float)vert.Location.X, (float)vert.Location.Y));
                    }
                    for (int i = 0; i < points.Points.Count; i++)
                    {
                        var p0 = points.Points[i];
                        var p1 = points.Points[(i + 1) % points.Points.Count];
                        elems.Add(new LineElement()
                            {
                                Start = p0, End = p1
                            });
                    }
                    break;
                }

                default:
                    throw new ArgumentException("unsupported entity type: " + ent);
                }
                ;
            }


            elems = elems.Where(z => z.Start.DistTo(z.End) > RemoveThreshold).ToList();
            var cntrs2 = ConnectElements(elems.ToArray());

            s.Outers.AddRange(cntrs2);
            if (s.Outers.Any(z => z.Points.Count < 3))
            {
                throw new Exception("few points");
            }

            return(s);
        }
Beispiel #15
0
        private static List <DxfEntity> OffsetToNest(IList <DxfEntity> dxfEntities, DxfPoint pivot, DxfPoint offset, double rotationAngle)
        {
            List <DxfEntity> dxfreturn = new List <DxfEntity>();
            List <DxfPoint>  tmpPts;

            foreach (DxfEntity entity in dxfEntities)
            {
                switch (entity.EntityType)
                {
                case DxfEntityType.Arc:
                    DxfArc dxfArc = (DxfArc)entity;
                    dxfArc.Center      = RotateLocation(rotationAngle, dxfArc.Center);
                    dxfArc.Center     += offset;
                    dxfArc.StartAngle += rotationAngle;
                    dxfArc.EndAngle   += rotationAngle;
                    dxfreturn.Add(dxfArc);
                    break;

                case DxfEntityType.ArcAlignedText:
                    DxfArcAlignedText dxfArcAligned = (DxfArcAlignedText)entity;
                    dxfArcAligned.CenterPoint  = RotateLocation(rotationAngle, dxfArcAligned.CenterPoint);
                    dxfArcAligned.CenterPoint += offset;
                    dxfArcAligned.StartAngle  += rotationAngle;
                    dxfArcAligned.EndAngle    += rotationAngle;
                    dxfreturn.Add(dxfArcAligned);
                    break;

                case DxfEntityType.Attribute:
                    DxfAttribute dxfAttribute = (DxfAttribute)entity;
                    dxfAttribute.Location  = RotateLocation(rotationAngle, dxfAttribute.Location);
                    dxfAttribute.Location += offset;
                    dxfreturn.Add(dxfAttribute);
                    break;

                case DxfEntityType.AttributeDefinition:
                    DxfAttributeDefinition dxfAttributecommon = (DxfAttributeDefinition)entity;
                    dxfAttributecommon.Location  = RotateLocation(rotationAngle, dxfAttributecommon.Location);
                    dxfAttributecommon.Location += offset;
                    dxfreturn.Add(dxfAttributecommon);
                    break;

                case DxfEntityType.Circle:
                    DxfCircle dxfCircle = (DxfCircle)entity;
                    dxfCircle.Center  = RotateLocation(rotationAngle, dxfCircle.Center);
                    dxfCircle.Center += offset;
                    dxfreturn.Add(dxfCircle);
                    break;

                case DxfEntityType.Ellipse:
                    DxfEllipse dxfEllipse = (DxfEllipse)entity;
                    dxfEllipse.Center  = RotateLocation(rotationAngle, dxfEllipse.Center);
                    dxfEllipse.Center += offset;
                    dxfreturn.Add(dxfEllipse);
                    break;

                case DxfEntityType.Image:
                    DxfImage dxfImage = (DxfImage)entity;
                    dxfImage.Location  = RotateLocation(rotationAngle, dxfImage.Location);
                    dxfImage.Location += offset;

                    dxfreturn.Add(dxfImage);
                    break;

                case DxfEntityType.Leader:
                    DxfLeader dxfLeader = (DxfLeader)entity;
                    tmpPts = new List <DxfPoint>();

                    foreach (DxfPoint vrt in dxfLeader.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    dxfLeader.Vertices.Clear();
                    dxfLeader.Vertices.Concat(tmpPts);
                    dxfreturn.Add(dxfLeader);
                    break;

                case DxfEntityType.Line:
                    DxfLine dxfLine = (DxfLine)entity;
                    dxfLine.P1  = RotateLocation(rotationAngle, dxfLine.P1);
                    dxfLine.P2  = RotateLocation(rotationAngle, dxfLine.P2);
                    dxfLine.P1 += offset;
                    dxfLine.P2 += offset;
                    dxfreturn.Add(dxfLine);
                    break;

                case DxfEntityType.LwPolyline:
                    DxfPolyline dxfPoly = (DxfPolyline)entity;
                    foreach (DxfVertex vrt in dxfPoly.Vertices)
                    {
                        vrt.Location  = RotateLocation(rotationAngle, vrt.Location);
                        vrt.Location += offset;
                    }

                    dxfreturn.Add(dxfPoly);
                    break;

                case DxfEntityType.MLine:
                    DxfMLine mLine = (DxfMLine)entity;
                    tmpPts            = new List <DxfPoint>();
                    mLine.StartPoint += offset;

                    mLine.StartPoint = RotateLocation(rotationAngle, mLine.StartPoint);

                    foreach (DxfPoint vrt in mLine.Vertices)
                    {
                        var tmppnt = RotateLocation(rotationAngle, vrt);
                        tmppnt += offset;
                        tmpPts.Add(tmppnt);
                    }

                    mLine.Vertices.Clear();
                    mLine.Vertices.Concat(tmpPts);
                    dxfreturn.Add(mLine);
                    break;

                case DxfEntityType.Polyline:
                    DxfPolyline polyline = (DxfPolyline)entity;

                    List <DxfVertex> verts = new List <DxfVertex>();
                    foreach (DxfVertex vrt in polyline.Vertices)
                    {
                        var tmppnt = vrt;
                        tmppnt.Location  = RotateLocation(rotationAngle, tmppnt.Location);
                        tmppnt.Location += offset;
                        verts.Add(tmppnt);
                    }

                    DxfPolyline polyout = new DxfPolyline(verts);
                    polyout.Location = polyline.Location + offset;
                    polyout.IsClosed = polyline.IsClosed;
                    polyout.Layer    = polyline.Layer;
                    dxfreturn.Add(polyout);

                    break;

                case DxfEntityType.Body:
                case DxfEntityType.DgnUnderlay:
                case DxfEntityType.Dimension:
                case DxfEntityType.DwfUnderlay:
                case DxfEntityType.Face:
                case DxfEntityType.Helix:
                case DxfEntityType.Insert:
                case DxfEntityType.Light:
                case DxfEntityType.ModelerGeometry:
                case DxfEntityType.MText:
                case DxfEntityType.OleFrame:
                case DxfEntityType.Ole2Frame:
                case DxfEntityType.PdfUnderlay:
                case DxfEntityType.Point:
                case DxfEntityType.ProxyEntity:
                case DxfEntityType.Ray:
                case DxfEntityType.Region:
                case DxfEntityType.RText:
                case DxfEntityType.Section:
                case DxfEntityType.Seqend:
                case DxfEntityType.Shape:
                case DxfEntityType.Solid:
                case DxfEntityType.Spline:
                case DxfEntityType.Text:
                case DxfEntityType.Tolerance:
                case DxfEntityType.Trace:
                case DxfEntityType.Underlay:
                case DxfEntityType.Vertex:
                case DxfEntityType.WipeOut:
                case DxfEntityType.XLine:
                    throw new ArgumentException("unsupported entity type: " + entity.EntityType);
                }
            }

            return(dxfreturn);
        }
Beispiel #16
0
        public float GetEntityLength(DxfCircle dxfCircle)
        {
            // We dont care about center

            return((float)(2 * Math.PI * dxfCircle.Radius));
        }
Beispiel #17
0
 public static Circle ToCircle(this DxfCircle circle)
 {
     return(new Circle(circle.Center.ToPoint(), circle.Radius, circle.Normal.ToVector(), circle.GetEntityColor(), circle, circle.Thickness));
 }
    /// <summary>
    /// Parse DXF into VectorShape list.
    /// </summary>
    public static List <VectorShape> ReadDXF(Stream dxfStream)
    {
        List <VectorShape> shapes = new List <VectorShape>();

        DxfFile dxfFile = DxfFile.Load(dxfStream);

        Dictionary <string, Color32> layerColors = new Dictionary <string, Color32>();

        foreach (DxfLayer layer in dxfFile.Layers)
        {
            layerColors.Add(layer.Name, ConvertColor(layer.Color));
        }

        foreach (DxfEntity entity in dxfFile.Entities)
        {
            VectorShape shape = null;

            switch (entity.EntityType)
            {
            case DxfEntityType.Point:
                DxfModelPoint point = entity as DxfModelPoint;
                shape = new PointShape(ConvertPoint(point.Location));
                break;

            case DxfEntityType.Line:
                DxfLine   line      = entity as DxfLine;
                Vector2[] endpoints = new Vector2[2];
                endpoints[0] = ConvertPoint(line.P1);
                endpoints[1] = ConvertPoint(line.P2);
                shape        = new PolyShape(endpoints);
                break;

            case DxfEntityType.Spline:
                DxfSpline spline = entity as DxfSpline;
                if ((spline.NumberOfControlPoints % spline.DegreeOfCurve) != 1)
                {
                    Debug.LogError("Invalid spline data! Wrong number of points. " + spline);
                    break;
                }

                Vector2[] controlPoints = new Vector2[spline.NumberOfControlPoints];
                for (int i = 0; i < controlPoints.Length; i++)
                {
                    controlPoints[i] = ConvertPoint(spline.ControlPoints[i]);
                }
                shape = new PolyShape(controlPoints[0]);
                PolyShape shapeSpline = shape as PolyShape;

                switch (spline.DegreeOfCurve)
                {
                case 1:

                    for (int i = 1; i < controlPoints.Length; i++)
                    {
                        shapeSpline.LineTo(controlPoints[i]);
                    }
                    break;

                case 2:
                    for (int i = 1; i < controlPoints.Length; i += 2)
                    {
                        shapeSpline.CurveTo(controlPoints[i + 1], controlPoints[i]);
                    }
                    break;

                case 3:
                    for (int i = 1; i < controlPoints.Length; i += 3)
                    {
                        shapeSpline.CurveTo(controlPoints[i + 2], controlPoints[i], controlPoints[i + 1]);
                    }
                    break;

                default:
                    Debug.LogWarning("Spline with unsupported curve of degree: " + spline.DegreeOfCurve);
                    break;
                }
                break;

            case DxfEntityType.Arc:
                DxfArc arc = entity as DxfArc;
                // If the arc is a complete circle just make one of those
                float startAngle = (float)arc.StartAngle;
                while (startAngle < 0f)
                {
                    startAngle += 360f;
                }
                float endAngle = (float)arc.EndAngle;
                while (endAngle < startAngle)
                {
                    endAngle += 360f;
                }

                float sweep = endAngle - startAngle;
                shape = new CircleShape(ConvertPoint(arc.Center), (float)arc.Radius, startAngle, sweep);
                break;

            case DxfEntityType.Circle:
                DxfCircle circle = entity as DxfCircle;
                shape = new CircleShape(ConvertPoint(circle.Center), (float)circle.Radius * dxfScale);
                break;

            case DxfEntityType.Ellipse:
                DxfEllipse ellipse = entity as DxfEllipse;
                // If the ellipse is actually a circle just make one of those
                if (Mathf.Approximately((float)ellipse.MinorAxisRatio, 1f))
                {
                    shape = new CircleShape(ConvertPoint(ellipse.Center), (float)ellipse.MajorAxis.Length * dxfScale);
                }
                else
                {
                    shape = new EllipseShape(ConvertPoint(ellipse.Center), ConvertVector(ellipse.MajorAxis), (float)ellipse.MinorAxisRatio);
                }
                break;

            case DxfEntityType.Polyline:
                DxfPolyline polyline = entity as DxfPolyline;
                if (polyline.ContainsVertices)
                {
                    Vector2[] vertices = new Vector2[polyline.Vertices.Count];
                    for (int i = 0; i < vertices.Length; i++)
                    {
                        vertices[i] = ConvertPoint(polyline.Vertices[i].Location);
                    }

                    shape = new PolyShape(vertices[0]);
                    PolyShape shapePolyline = shape as PolyShape;

                    for (int i = 1; i < vertices.Length; i++)
                    {
                        float bulge = (float)polyline.Vertices[i - 1].Bulge;
                        shapePolyline.ArcToDXF(vertices[i], bulge);
                    }

                    if (polyline.IsClosed)
                    {
                        float bulge = (float)polyline.Vertices[vertices.Length - 1].Bulge;
                        shapePolyline.ArcToDXF(vertices[0], bulge);
                        shape.Closed = true;
                    }
                }
                break;

            case DxfEntityType.LwPolyline:
            {
                DxfLwPolyline lwPolyline = entity as DxfLwPolyline;
                Vector2[]     vertices   = new Vector2[lwPolyline.Vertices.Count];
                for (int i = 0; i < vertices.Length; i++)
                {
                    DxfLwPolylineVertex lwpVertex = lwPolyline.Vertices[i];
                    vertices[i] = ConvertPoint(lwpVertex.X, lwpVertex.Y);
                }

                shape = new PolyShape(vertices[0]);
                PolyShape shapePolyline = shape as PolyShape;

                for (int i = 1; i < vertices.Length; i++)
                {
                    float bulge = (float)lwPolyline.Vertices[i - 1].Bulge;
                    shapePolyline.ArcToDXF(vertices[i], bulge);
                }

                if (lwPolyline.IsClosed)
                {
                    float bulge = (float)lwPolyline.Vertices[vertices.Length - 1].Bulge;
                    shapePolyline.ArcToDXF(vertices[0], bulge);
                    shape.Closed = true;
                }
            }
            break;

            default:
                Debug.Log("Unhandled entity of type: " + entity.EntityType);
                break;
            }

            if (shape != null)
            {
                if (entity.IsVisible)
                {
                    Color32 shapeColor = ConvertColor(entity.Color);
                    //layerColors.TryGetValue(entity.Layer, out shapeColor);

                    shape.colorOutline = shapeColor;
                    shapes.Add(shape);
                }
            }
        }

        return(shapes);
    }
Beispiel #19
0
        static void FindEntities(DxfEntityCollection Entities)
        {
            foreach (var entityGroups in Entities)
            {
                if (typeof(DxfLine) != entityGroups.GetType() && typeof(DxfLwPolyline) != entityGroups.GetType() && typeof(DxfMText) != entityGroups.GetType() && typeof(DxfText) != entityGroups.GetType() && typeof(DxfCircle) != entityGroups.GetType() && typeof(DxfHatch) != entityGroups.GetType() && typeof(DxfInsert) != entityGroups.GetType() && typeof(DxfSpline) != entityGroups.GetType())
                {
                    // Console.WriteLine(entityGroups.GetType());
                }

                dxfType.Add(entityGroups.GetType().Name);
                if (typeof(DxfLine) == entityGroups.GetType())
                {
                    dxfLine = entityGroups as DxfLine;

                    int color;

                    if (dxfLine.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfLine.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfLine.Color.Rgb;
                    }


                    CADLine cADLine = new CADLine
                    {
                        parentHandle = dxfLine.OwnerObjectSoftReference.Handle,
                        type         = dxfLine.GetType().Name,
                        color        = color,
                        transform    = dxfLine.Transform.DebugString,
                        startPoint   = dxfLine.Start.ToString(),
                        endPoint     = dxfLine.End.ToString(),
                        lineWeight   = dxfLine.LineWeight
                    };

                    cadEntities.Add(cADLine);
                }


                if (typeof(DxfLwPolyline) == entityGroups.GetType())
                {
                    //Console.WriteLine(dxfLwPolyline);

                    dxfLwPolyline = entityGroups as DxfLwPolyline;

                    string[] arrVertices = new string[dxfLwPolyline.Vertices.Count];
                    for (int i = 0; i < dxfLwPolyline.Vertices.Count; i++)
                    {
                        arrVertices[i] = dxfLwPolyline.Vertices[i].ToString();
                    }

                    int color;
                    if (dxfLwPolyline.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfLwPolyline.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfLwPolyline.Color.Rgb;
                    }


                    CADLwPolyLine cADLwPolyLine = new CADLwPolyLine
                    {
                        parentHandle = dxfLwPolyline.OwnerObjectSoftReference.Handle,
                        type         = dxfLwPolyline.GetType().Name,
                        color        = color,
                        transform    = dxfLwPolyline.Transform.DebugString,

                        vertices = arrVertices,
                        closed   = dxfLwPolyline.Closed.ToString(),
                    };

                    cadEntities.Add(cADLwPolyLine);
                }


                if (typeof(DxfXLine) == entityGroups.GetType())
                {
                    dxfXLine = entityGroups as DxfXLine;
                }

                if (typeof(DxfSpline) == entityGroups.GetType())
                {
                    dxfSpline = entityGroups as DxfSpline;

                    string[] arrFitPoints = new string[dxfSpline.FitPoints.Count];
                    for (int i = 0; i < dxfSpline.FitPoints.Count; i++)
                    {
                        arrFitPoints[i] = dxfSpline.FitPoints[i].ToString();
                    }

                    int color;
                    if (dxfSpline.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfSpline.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfSpline.Color.Rgb;
                    }


                    CADSpline cADSpline = new CADSpline
                    {
                        parentHandle = dxfSpline.OwnerObjectSoftReference.Handle,
                        type         = dxfSpline.GetType().Name,
                        color        = color,
                        transform    = dxfSpline.Transform.DebugString,

                        fitPoints = arrFitPoints,
                    };

                    cadEntities.Add(cADSpline);
                }


                if (typeof(DxfCircle) == entityGroups.GetType())
                {
                    dxfCircle = entityGroups as DxfCircle;

                    int color;
                    if (dxfCircle.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfCircle.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfCircle.Color.Rgb;
                    }


                    CADCircle cADCircle = new CADCircle
                    {
                        parentHandle = dxfCircle.OwnerObjectSoftReference.Handle,
                        type         = dxfCircle.GetType().Name,
                        color        = color,
                        transform    = dxfCircle.Transform.DebugString,

                        center = dxfCircle.Center.ToString(),
                        radius = dxfCircle.Radius
                    };

                    cadEntities.Add(cADCircle);

                    kcircle.Add(dxfCircle);
                }

                if (typeof(DxfArc) == entityGroups.GetType())
                {
                    dxfArc = entityGroups as DxfArc;

                    int color;
                    if (dxfArc.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfArc.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfArc.Color.Rgb;
                    }

                    CADArc cADArc = new CADArc
                    {
                        parentHandle = dxfArc.OwnerObjectSoftReference.Handle,
                        type         = dxfArc.GetType().Name,
                        color        = color,
                        transform    = dxfArc.Transform.DebugString,

                        center     = dxfArc.Center.ToString(),
                        startAngle = dxfArc.StartAngle,
                        endAngle   = dxfArc.EndAngle,
                        radius     = dxfArc.Radius
                    };

                    cadEntities.Add(cADArc);
                }

                if (typeof(DxfEllipse) == entityGroups.GetType())
                {
                    dxfEllipse = entityGroups as DxfEllipse;

                    int color;
                    if (dxfEllipse.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfEllipse.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfEllipse.Color.Rgb;
                    }

                    CADEllipse cADEllipse = new CADEllipse
                    {
                        parentHandle = dxfEllipse.OwnerObjectSoftReference.Handle,
                        type         = dxfEllipse.GetType().Name,
                        color        = color,
                        transform    = dxfEllipse.Transform.DebugString,

                        center            = dxfEllipse.Center.ToString(),
                        majorAxisEndPoint = dxfEllipse.MajorAxisEndPoint.ToString(),
                        minorAxisEndPoint = dxfEllipse.MinorAxisEndPoint.ToString(),
                        startParameter    = dxfEllipse.StartParameter,
                        endParameter      = dxfEllipse.EndParameter
                    };

                    cadEntities.Add(cADEllipse);
                }



                if (typeof(DxfMText) == entityGroups.GetType())
                {
                    dxfMText = entityGroups as DxfMText;

                    int color;
                    if (dxfMText.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfMText.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfMText.Color.Rgb;
                    }


                    if (dxfMText.SimplifiedText == "C座一层平面图")
                    {
                        ktls.Add(dxfMText);
                    }


                    CADMText cADMText = new CADMText
                    {
                        parentHandle = dxfMText.OwnerObjectSoftReference.Handle,
                        type         = dxfMText.GetType().Name,
                        color        = color,
                        transform    = dxfMText.Transform.DebugString,

                        simplifiedText = dxfMText.SimplifiedText.ToString(),
                        fontStyle      = dxfMText.Style.ToString(),
                        size           = dxfMText.Height,

                        attachmentPoint = dxfMText.AttachmentPoint.ToString(),
                        boxHeight       = dxfMText.BoxHeight,
                        boxWidth        = dxfMText.BoxWidth
                    };

                    cadEntities.Add(cADMText);

                    if (dxfMText.SimplifiedText.ToString() == "图 纸 目 录")
                    {
                        //Console.WriteLine(222222);
                        ktls.Add(dxfMText);
                    }
                    if (dxfMText.SimplifiedText.ToString() == "JS-T5-302")
                    {
                        //Console.WriteLine(222222);
                        ktls.Add(dxfMText);
                    }
                }


                if (typeof(DxfText) == entityGroups.GetType())
                {
                    dxfText = entityGroups as DxfText;

                    int color;
                    if (dxfText.Color.ColorType.ToString() == "ByLayer")
                    {
                        color = dxfText.Layer.Color.Rgb;
                    }
                    else
                    {
                        color = dxfText.Color.Rgb;
                    }

                    CADText cADText = new CADText
                    {
                        parentHandle = dxfText.OwnerObjectSoftReference.Handle,
                        type         = dxfText.GetType().Name,
                        color        = color,
                        transform    = dxfText.Transform.DebugString,

                        simplifiedText = dxfText.SimplifiedText.ToString(),
                        fontStyle      = dxfText.Style.ToString(),
                        size           = dxfText.Height,

                        alignMentPoint1 = dxfText.AlignmentPoint1.ToString(),
                        rotationAngle   = dxfText.Rotation,
                    };


                    if (dxfText.SimplifiedText == "JS-T5-001 ")
                    {
                        ktest.Add(dxfText);
                    }

                    cadEntities.Add(cADText);
                }

                if (typeof(DxfInsert) == entityGroups.GetType())
                {
                    dxfInsert = entityGroups as DxfInsert;
                    kins.Add(dxfInsert);


                    if (dxfInsert.Block != null)
                    {
                        ulong count;
                        if (dxfInsert.Block != null)
                        {
                            count = dxfInsert.Block.Handle;
                        }
                        else
                        {
                            count = 0;
                        }

                        CADInsert cADInsert = new CADInsert();


                        cADInsert.parentHandle = dxfInsert.OwnerObjectSoftReference.Handle;
                        cADInsert.type         = dxfInsert.GetType().Name;
                        cADInsert.transform    = dxfInsert.Transform.DebugString;

                        cADInsert.insertPoint   = dxfInsert.InsertionPoint.ToString();
                        cADInsert.rotationAngle = dxfInsert.Rotation;
                        cADInsert.insertName    = dxfInsert.Block.Name;
                        cADInsert.nowHandle     = count;
                        cADInsert.insertScale   = dxfInsert.ScaleFactor.ToString();

                        cadEntities.Add(cADInsert);

                        FindEntities(dxfInsert.Block.Entities);
                    }
                }



                if (typeof(DxfAttributeDefinition) == entityGroups.GetType())
                {
                    dxfAttributeDefinition = entityGroups as DxfAttributeDefinition;
                    //Console.WriteLine(dxfAttributeDefinition);
                }

                if (typeof(DxfDimension.Linear) == entityGroups.GetType())
                {
                    Console.WriteLine(11111);
                }
            }
        }
 /// <summary>
 /// Visits the specified entity.
 /// See the <see cref="IEntityVisitor"/> for more details.
 /// </summary>
 public override void Visit(DxfCircle circle)
 {
     HandleEntity(circle);
 }
Beispiel #21
0
        /// <summary>
        /// 门把手绘制
        /// </summary>
        /// <param name="dxf"></param>
        /// <param name="DLocation"></param>
        public static void Draw(DxfModel dxf, DLocation DLocation)
        {
            double factor = 0.05f;
             double distance = 30;
            //底部小圆的圆心
             Point3D sDxfCircle = new Point3D(DLocation.X + 10 * factor, DLocation.Y, DLocation.Z);
            //上部同心圆圆心
             Point3D bDxfCircle = new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance*factor, DLocation.Z);

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

             Point3D v1 = new Point3D(
                 DLocation.X + 10 * factor - double.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                 DLocation.Y + 5 * factor - double.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                 DLocation.Z);

             Point3D v2 = new Point3D(
                  DLocation.X + 10 * factor + double.Parse((5 * factor * Math.Cos(alpha)).ToString()),
                  DLocation.Y + 5 * factor - double.Parse((5 * factor * Math.Sin(alpha)).ToString()),
                  DLocation.Z);

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

             Point3D v5 = new Point3D(
             DLocation.X + 10 * factor  + double.Parse((8*factor*Math.Cos(alpha)).ToString()),
             DLocation.Y + 5 * factor + distance * factor - double.Parse((8 * factor * Math.Sin(alpha)).ToString()),
             DLocation.Z
             );
             DxfLine DxfLine14 = new DxfLine(v1, v4);
             dxf.Entities.Add(DxfLine14);

             DxfLine DxfLine25 = new DxfLine(v2, v5);
             dxf.Entities.Add(DxfLine25);

             //DxfArc
             DxfArc DxfArc = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor, DLocation.Z),
                 5 * factor, Convert.ToInt32(180 + alpha * 180 / Math.PI), Convert.ToInt32(360 - alpha * 180 / Math.PI));
             dxf.Entities.Add(DxfArc);

             //DxfArcup
             DxfArc DxfArcup = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance * factor, DLocation.Z),
                 8 * factor, Convert.ToInt32(-alpha * 180 / Math.PI), Convert.ToInt32(180 + alpha * 180 / Math.PI));
             dxf.Entities.Add(DxfArcup);

             //DxfArcround
             DxfArc DxfArcround = new DxfArc(
                 new Point3D(DLocation.X + 10 * factor, DLocation.Y + 5 * factor + distance * factor, DLocation.Z),
                 10 * factor,
                 Convert.ToInt32(-(alpha +beta) * 180 / Math.PI),
                 Convert.ToInt32(180 + (alpha +beta) * 180 / Math.PI));
             dxf.Entities.Add(DxfArcround);

             //DxfCircle
             Point3D centerWCS = new Point3D(DLocation.X+10*factor, DLocation.Y+5*factor+distance*factor, DLocation.Z);
             DxfCircle DxfCircle = new DxfCircle((Point3D)centerWCS, 7 * factor);
             dxf.Entities.Add(DxfCircle);

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

             //DxfText
             DxfText DxfText1 = new DxfText("A", t1, 0.2f);
             dxf.Entities.Add(DxfText1);

             //DxfText
             DxfText DxfText2 = new DxfText("A", t2, 0.2f);
             dxf.Entities.Add(DxfText2);

             //DxfText
             DxfText DxfText3 = new DxfText("O", t3, 0.2f);
             dxf.Entities.Add(DxfText3);

             //DxfText
             DxfText DxfText4 = new DxfText("N", t4, 0.2f);
             dxf.Entities.Add(DxfText4);
        }
Beispiel #22
0
        public void DrawArc(
            Pen pen,
            float x,
            float y,
            float width,
            float height,
            float startAngle,
            float sweepAngle)
        {
            double a    = -(double)startAngle * System.Math.PI / 180.0;
            double num1 = -(double)sweepAngle * System.Math.PI / 180.0;
            double b    = a + num1;

            if (num1 < 0.0)
            {
                MathUtil.Swap(ref a, ref b);
            }
            double radius = 0.5 * (double)width;

            WW.Math.Point3D center = new WW.Math.Point3D((double)x + radius, -(double)y - 0.5 * (double)height, 0.0);
            if ((double)width == (double)height)
            {
                if (MathUtil.AreApproxEqual(System.Math.Abs(num1), 2.0 * System.Math.PI))
                {
                    DxfCircle dxfCircle = new DxfCircle(center, radius);
                    dxfCircle.Color = EntityColor.CreateFrom((ArgbColor)pen.Color);
                    this.list_0.Add((DxfEntity)dxfCircle);
                }
                else
                {
                    DxfArc dxfArc = new DxfArc(center, radius, a, b);
                    dxfArc.Color = EntityColor.CreateFrom((ArgbColor)pen.Color);
                    this.list_0.Add((DxfEntity)dxfArc);
                }
            }
            else
            {
                double   num2 = (double)System.Math.Abs(width);
                double   num3 = (double)System.Math.Abs(height);
                double   minorToMajorRatio;
                Vector3D majorAxisEndPoint;
                double   num4;
                double   num5;
                if (num2 > num3)
                {
                    minorToMajorRatio = num3 / num2;
                    majorAxisEndPoint = new Vector3D(0.5 * num2, 0.0, 0.0);
                    num4 = a;
                    num5 = b;
                }
                else
                {
                    minorToMajorRatio = num2 / num3;
                    majorAxisEndPoint = new Vector3D(0.0, 0.5 * num3, 0.0);
                    if (MathUtil.AreApproxEqual(System.Math.Abs(num1), 2.0 * System.Math.PI))
                    {
                        num4 = 0.0;
                        num5 = 2.0 * System.Math.PI;
                    }
                    else
                    {
                        num4 = a - System.Math.PI / 2.0;
                        num5 = b - System.Math.PI / 2.0;
                    }
                }
                DxfEllipse dxfEllipse = new DxfEllipse(center, majorAxisEndPoint, minorToMajorRatio);
                dxfEllipse.Color          = EntityColor.CreateFrom((ArgbColor)pen.Color);
                dxfEllipse.StartParameter = num4;
                dxfEllipse.EndParameter   = num5;
                this.list_0.Add((DxfEntity)dxfEllipse);
            }
        }