主要用到函数说明:
IMxDrawEntity::GetBoundingBox
返回实体的最小矩形框外包。详细说明如下: 参数 | 说明 | [out] IMxDrawPoint** minPoint | 外包框的左下角点 | [out] IMxDrawPoint** maxPoint | 外包框的右上角 | c#中实现代码说明:
- //返回控件的数据库对象
- MxDrawDatabase databae = (MxDrawDatabase)axMxDrawX1.GetDatabase();
- //返回数据库中的块表对象
- MxDrawBlockTable blkTab = databae.GetBlockTable();
- //创建一个遍历块表中所有记录的遍历器
- MxDrawBlockTableIterator mBlockTableiter = blkTab.NewIterator();
- //移动当前遍历器位置
- for (; !mBlockTableiter.Done(); mBlockTableiter.Step())
-
- {
- //返回遍历器当前位置的记录
- MxDrawBlockTableRecord blkRec = mBlockTableiter.GetRecord();
- //创建一个遍历块表中所有记录的遍历器
- MxDrawBlockTableRecordIterator mBlockTableReciter = blkRec.NewIterator();
-
- MxDrawPoint mMaxPt = new MxDrawPoint();
- MxDrawPoint mMinPt = new MxDrawPoint();
-
- MxDrawPoint mMaxPtTemp = new MxDrawPoint();
- MxDrawPoint mMinPtTemp = new MxDrawPoint();
- //移动当前遍历器位置
- for (; !mBlockTableReciter.Done(); mBlockTableReciter.Step(true, false))
- {
- //与用户交互在图面上选择一个实体
- MxDrawEntity ent = mBlockTableReciter.GetEntity();
- //返回实体的最小矩形框外包
- ent.GetBoundingBox(out mMinPtTemp, out mMaxPtTemp);
-
- if ((mMinPtTemp == null) || (mMaxPtTemp == null))
- break;
-
- mMaxPt.x = Math.Max(mMaxPt.x, mMaxPtTemp.x);
- mMaxPt.y = Math.Max(mMaxPt.y, mMaxPtTemp.y);
-
- mMinPt.x = Math.Min(mMinPt.x, mMinPtTemp.x);
- mMinPt.y = Math.Min(mMinPt.y, mMinPtTemp.y);
-
- }
-
- if ((mMinPtTemp == null) || (mMaxPtTemp == null))
- continue;
-
- MxDrawPoint mNewBasePt = new MxDrawPoint();
-
- mNewBasePt.x = mMinPt.x + (mMaxPt.x - mMinPt.x) / 2;
- mNewBasePt.y = mMinPt.y + (mMaxPt.y - mMinPt.y) / 2;
- //块表记录的插入原点属性
- blkRec.Origin = mNewBasePt;
- //重新生成图,重新生成所有显示数据
- axMxDrawX1.Regen();
- }
复制代码
|