public void ExportEntity(ExpBlock block, PicEntity entity)
        {
            PicTypedDrawable drawable = entity as PicTypedDrawable;
            ExpLayer         layer    = null;
            ExpPen           pen      = null;

            if (null != drawable)
            {
                pen   = _exporter.GetPenByAttribute(LineTypeToExpPen(drawable.LineType));
                layer = _exporter.GetLayerByName(string.Format("Layer {0}", drawable.Layer));
            }
            PicSegment seg = entity as PicSegment;

            if (null != seg)
            {
                _exporter.AddSegment(block, layer, pen, seg.Pt0.X, seg.Pt0.Y, seg.Pt1.X, seg.Pt1.Y);
            }
            PicArc arc = entity as PicArc;

            if (null != arc)
            {
                // using dxf conversions
                double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                if (ang < 0.0)
                {
                    angd += ang; ango = -ang;
                }
                else
                {
                    ango = ang;
                }
                _exporter.AddArc(block, layer, pen, arc.Center.X, arc.Center.Y, arc.Radius, angd, angd + ango);
            }
            PicCotationDistance cotation = drawable as PicCotationDistance;

            if (null != cotation)
            {
                List <Segment> segments = new List <Segment>();
                Vector2D       textPt   = Vector2D.Zero;
                double         textSize = 0.0;
                cotation.DrawSeg(ref segments, ref textPt, ref textSize);
                foreach (Segment cotSeg in segments)
                {
                    _exporter.AddSegment(block, layer, pen, cotSeg.P0.X, cotSeg.P0.Y, cotSeg.P1.X, cotSeg.P1.Y);
                }
                _exporter.AddText(block, layer, pen, textPt.X, textPt.Y, cotation.Text);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// ProcessEntity : write entity corresponding dxf description in line buffer
        /// </summary>
        /// <param name="entity">Entity</param>
        public override void ProcessEntity(PicEntity entity)
        {
            PicTypedDrawable drawable = (PicTypedDrawable)entity;

            if (null != drawable)
            {
                switch (drawable.Code)
                {
                case PicEntity.ECode.PE_POINT:
                    break;

                case PicEntity.ECode.PE_SEGMENT:
                {
                    PicSegment seg = (PicSegment)entity;
                    dxf.WriteLine(
                        dw
                        , new DL_LineData(
                            seg.Pt0.X                   // start point
                            , seg.Pt0.Y
                            , 0.0
                            , seg.Pt1.X         // end point
                            , seg.Pt1.Y
                            , 0.0
                            , InternalLineTypeToDxfColor(seg.LineType)
                            , "0"
                            )
                        , new DL_Attributes("0", InternalLineTypeToDxfColor(seg.LineType), -1, InternalLineTypeToDxfLineType(seg.LineType))
                        );
                }
                break;

                case PicEntity.ECode.PE_ARC:
                {
                    PicArc arc = (PicArc)entity;
                    double ang = arc.AngleEnd - arc.AngleBeg, angd = arc.AngleBeg, ango = arc.AngleEnd - arc.AngleBeg;
                    if (ang < 0.0)
                    {
                        angd += ang;
                        ango  = -ang;
                    }
                    else
                    {
                        ango = ang;
                    }

                    dxf.WriteArc(dw,
                                 new DL_ArcData(
                                     arc.Center.X, arc.Center.Y, 0.0,
                                     arc.Radius,
                                     angd, angd + ango,
                                     InternalLineTypeToDxfColor(arc.LineType),
                                     "0"
                                     ),
                                 new DL_Attributes("0", InternalLineTypeToDxfColor(arc.LineType), -1, InternalLineTypeToDxfLineType(arc.LineType))
                                 );
                }
                break;

                case PicEntity.ECode.PE_COTATIONDISTANCE:
                case PicEntity.ECode.PE_COTATIONHORIZONTAL:
                case PicEntity.ECode.PE_COTATIONVERTICAL:
                {
                    PicCotationDistance cotation = entity as PicCotationDistance;
                    List <Segment>      segments = new List <Segment>();
                    Vector2D            textPt   = Vector2D.Zero;
                    double textSize = 0.0;
                    cotation.DrawSeg(ref segments, ref textPt, ref textSize);
                    // draw segments
                    foreach (Segment seg in segments)
                    {
                        dxf.WriteLine(dw,
                                      new DL_LineData(
                                          seg.P0.X, seg.P0.Y, 0.0,
                                          seg.P1.X, seg.P1.Y, 0.0,
                                          InternalLineTypeToDxfColor(cotation.LineType),
                                          "0"
                                          ),
                                      new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType))
                                      );
                    }
                    // draw text
                    dxf.WriteText(dw,
                                  new DL_TextData(
                                      textPt.X, textPt.Y, 0.0,
                                      textPt.X, textPt.Y, 0.0,
                                      textSize, 1.0, 0,
                                      1, 2, cotation.Text, "STANDARD", 0.0),
                                  new DL_Attributes("0", InternalLineTypeToDxfColor(cotation.LineType), -1, InternalLineTypeToDxfLineType(cotation.LineType)));
                }
                break;

                case PicEntity.ECode.PE_ELLIPSE:
                    break;

                case PicEntity.ECode.PE_NURBS:
                    break;

                default:
                    throw new Exception("Can not export this kind of entity!");
                }
            }
        }