Exemplo n.º 1
0
 /// <summary>
 /// 判断Text是否已存在(重复的Text)
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 private bool TextExists(AcText text)
 {
     foreach (AcText t in _texts)
     {
         if (t.Value == text.Value && t.Position == text.Position && t.Height == text.Height)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 识别选中的对象,将其变为内部结构
        /// </summary>
        /// <param name="objects"></param>
        private void ParseObjects(IEnumerable objects, double baseX = 0, double baseY = 0, double xScale = 1, double yScale = 1)
        {
            foreach (ObjectId oid in objects)
            {
                switch (oid.ObjectClass.DxfName)
                {
                case "TEXT":
                    DBText  text         = (DBText)oid.GetObject(OpenMode.ForRead);
                    Point2d ptTextCenter = CommandUtils.GetCenterPoint(text);
                    AcText  at1          = new AcText(text.TextString, new Point2d(baseX + xScale * ptTextCenter.X, baseY + yScale * ptTextCenter.Y), yScale * text.Height);
                    if (!TextExists(at1))
                    {
                        _texts.Add(at1);
                    }
                    break;

                case "MTEXT":
                    MText   mText         = (MText)oid.GetObject(OpenMode.ForRead);
                    Point2d ptMTextCenter = CommandUtils.GetCenterPoint(mText);
                    AcText  at2           = new AcText(mText.Text, new Point2d(baseX + xScale * ptMTextCenter.X, baseY + yScale * ptMTextCenter.Y), yScale * mText.Height);
                    if (!TextExists(at2))
                    {
                        _texts.Add(at2);
                    }
                    break;

                case "LINE":
                    Line line = (Line)oid.GetObject(OpenMode.ForRead);
                    ParseLine(new Point2d(baseX + xScale * line.StartPoint.X, baseY + yScale * line.StartPoint.Y),
                              new Point2d(baseX + xScale * line.EndPoint.X, baseY + yScale * line.EndPoint.Y));
                    break;

                case "LWPOLYLINE":
                    Polyline pLine = (Polyline)oid.GetObject(OpenMode.ForRead);
                    ParsePolyLine(pLine, baseX, baseY, xScale, yScale);
                    break;

                case "INSERT":
                    DBObject obj = oid.GetObject(OpenMode.ForRead);
                    if (obj is BlockReference)
                    {
                        BlockReference   br  = obj as BlockReference;
                        BlockTableRecord btr = br.BlockTableRecord.GetObject(OpenMode.ForRead) as BlockTableRecord;
                        ParseObjects(btr, baseX + br.Position.X, baseY + br.Position.Y, xScale * br.ScaleFactors.X, yScale * br.ScaleFactors.Y);
                    }
                    break;

                default:
                    //System.Windows.Forms.MessageBox.Show(oid.ObjectClass.DxfName);
                    break;
                }
            }
        }