CADImport 控件实现查找文件中的文字和坐标定位。

 引用:

using CADImport;
using CADImportForm;
using HPGL2;
using RasterImage;
using ObjectsSelection;
using CADImportFaceModule;

 

存储图形元素

private ArrayList TextFile = new ArrayList();

 

#region 文本查找
        private void ReadAll(string aFileName)
        {
            if (FCADImage == null) return;
            TextFile.Clear();
            CADParams = new CADIterate();
            CADParams.matrix = new CADMatrix();
            CADParams.matrix.data[0, 0] = 1;
            CADParams.matrix.data[1, 1] = 1;
            CADParams.matrix.data[2, 2] = 1;
            FCADImage.Converter.AutoInsert = true; // to get all the elements inside of inserts
            FCADImage.Converter.Iterate(new CADEntityProc(ReadCADEntities), CADParams);
        }
        private void ReadCADEntities(CADEntity Entity)
        {
            if (Entity is CADText)
            {
                CADText Sender = (CADText)Entity;

                DPoint P;
             
                CADConst.DoScale2D(ref CADParams);
                if (Sender.Text == FineText)
                {
                    DPoint tmp_dp = Sender.StartPoint;
                    tmp_dp.Y += Sender.Height * 1.3; //for not shx
                    P = CADParams.matrix.PtXMat(tmp_dp);
                    FineTextPoint.X = float.Parse(P.X.ToString());
                    FineTextPoint.Y = float.Parse(P.Y.ToString());
                }
            }
        }
        private void CADMove(Point proPoint)
        {
            det1 = true;
            if (FCADImage == null) return;
            if (det1)
            {
                if (proPoint.X > cadPictBox.Width / 2)
                {
                    pos.X -= (proPoint.X - cadPictBox.Width / 2);
                }
                else
                {
                    pos.X += (cadPictBox.Width / 2 - proPoint.X);
                }
                if (proPoint.Y > cadPictBox.Height / 2)
                {
                    pos.Y -= (proPoint.Y - cadPictBox.Height / 2);
                }
                else
                {
                    if (cadPictBox.Height / 2 != proPoint.Y)
                    {
                        pos.Y += (cadPictBox.Height / 2 - proPoint.Y);
                    }
                }
                cadPictBox.Invalidate();
            }
            det1 = false;
        }
        #endregion

    private void button5_Click(object sender, EventArgs e)
        {
            if (FCADImage == null) return;
            FineText = textBox1.Text.Trim();
            ReadAll(FileName);
            if (FineTextPoint.X != 0 || FineTextPoint.Y != 0)
            {
                DPoint d_Pos = SetRealPointUsingsgImagePoint(FineTextPoint.X, FineTextPoint.Y);
                Point ProPoint = new Point(Convert.ToInt32(d_Pos.X), Convert.ToInt32(d_Pos.Y));
                CADMove(ProPoint);
            }
        }

评论 2 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

yangxjn

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值