- UID
- 770541
- 积分
- 410
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2017-8-19
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本帖最后由 1121443108qaz 于 2018-11-12 22:46 编辑
1,首先是一次WMFOUT,import
- void CEntityUtil::wmfoutIn(ads_name& ssname)
- {
- acedCommandS(RTSTR, L"_.wmfout", RTSTR, L"D:\\temp.wmf", RTENAME, ssname, RTSTR, L"", RTNONE);
- acedCommandS(RTSTR, L"_.import", RTSTR, L"D:\\temp.wmf", RTNONE);
- acdbEntLast(ssname);
- AcDbObjectId entId;
- acdbGetObjectId(entId, ssname);
- AcDbBlockReference* pBlk = NULL;
- AcGePoint3d ptBase;
- AcGeMatrix3d mat;
- if (acdbOpenObject(pBlk,entId,AcDb::kForWrite)==Acad::eOk)
- {
- ptBase = pBlk->position();
- mat.setToScaling(2.0, ptBase);
- pBlk->transformBy(mat);
- pBlk->close();
- }
- }
0.2,然后是对每个文字缩放至一定范围,保证转化后轮廓线的精度
- AcGePoint3d CTextUtil::zoome(const AcDbText* pText)
- {
- CString string;
- ads_name ename;
- AcGePoint3d ptCen,ptMin,ptMax;
- string = pText->textString();
- if (acutWcMatch(string,L".")==RTNORM)
- {
- //acutPrintf(L"\n是特殊字符");
- acdbGetAdsName(ename, pText->objectId());
- AcGePoint2d ptcen2d= CDwgDatabaseUtil::zoomObject(ename); //直接用zoom object方法
- ptCen = CConvertUtil::ToPoint3d(ptcen2d);
- return ptCen;
- }
- double height,width;
- double xfa, yfa;
- AcDbExtents ext;
- pText->bounds(ext);
- ptMin = ext.minPoint();
- ptMax = ext.maxPoint();
- height = ptMax.y - ptMin.y;
- width = ptMax.x - ptMin.x;
- ptCen = CGePointUtil::GetMiddllePoint(ptMin, ptMax);
- AcDbViewTableRecord view;
- if (height>width)
- {
- yfa = 1;
- xfa = height / width;
- }
- else
- {
- xfa = 1;
- yfa = width / height;
- }
- height = height * (yfa+0.2);
- width = width * (xfa+0.2);
- view.setCenterPoint(CConvertUtil::ToPoint2d(ptCen));
- view.setWidth(width);
- view.setHeight(height);
- acedSetCurrentView(&view, NULL);
- return ptCen;
- }
3,对于已经颠倒或反向的文字来说WMFOUT,导入一次后就行,否则需要镜像后WMFOUT,import,再镜像回来。然而如果对一个多行文字镜像再打破,此时这个文字事实上是镜像的,但是特性上显示不颠倒且不反向,所以需要判断。
- bool CTextUtil::isMirror(const AcDbText* pText)
- {
- bool ismirror = true;
- if (pText->isMirroredInX() || pText->isMirroredInY())
- {
- return ismirror;
- }
- AcDbExtents ext;
- pText->getGeomExtents(ext);
- AcGePoint3d position, minPt, maxPt,leftUpPt,rightDownPt;
- minPt = ext.minPoint();
- maxPt = ext.maxPoint();
- rightDownPt = AcGePoint3d(maxPt.x, minPt.y, 0);
- leftUpPt = AcGePoint3d(minPt.x, maxPt.y, 0);
- position = pText->position();
- double dis1, dis2, dis3;
- dis1 = position.distanceTo(minPt);
- dis2 = position.distanceTo(leftUpPt);
- dis3 = position.distanceTo(rightDownPt);
- if (dis1<dis2 && dis1<dis3)
- {
- ismirror = false;
- }
- return ismirror;
- }
4,最后是整体代码。
- void MyUtil::t2lb(AcDbObjectIdArray& entIds)
- {
- AcDbObjectIdArray tempIds;
- AcDbObjectId entId,tempId,layId,recordId;
- AcGePoint2d pt,ptCen;
- ads_name ename;
- AcDbDatabase* pData = acdbHostApplicationServices()->workingDatabase();
- pData->setMirrtext(true);
- resbuf cmdstart, cmdend, wmf1, VTDURATION;;
- acedGetVar(L"wmfforegnd", &wmf1);
- wmf1.resval.rint = 1;
- acedSetVar(L"wmfforegnd", &wmf1);
- wmf1.resval.rint = 0;
- acedSetVar(L"wmfbkgnd", &wmf1);
- acedGetVar(L"cmdecho", &cmdstart);
- cmdend = cmdstart;
- cmdend.resval.rint = 0;
- acedSetVar(L"cmdecho", &cmdend);
- acedGetVar(L"VTDURATION", &VTDURATION);
- VTDURATION.resval.rint = 0;
- acedSetVar(L"VTDURATION", &VTDURATION);
- AcDbEntity* pEnt = NULL,*pTempEnt= NULL;
- AcDbVoidPtrArray pts;
- AcDbText* pText = NULL;
- AcDbBlockReference* pBlock = NULL;
- AcDbBlockTableRecord* pBlkRcd = NULL;
- for (int i=0;i<entIds.length();i++)
- {
- entId = entIds.at(i);
- acdbGetAdsName(ename, entId);
- if (acdbOpenAcDbEntity(pEnt,entId,AcDb::kForWrite)==Acad ::eOk)
- {
- if (pEnt->isKindOf(AcDbText::desc()))
- {
- layId = pEnt->layerId();
- pText = AcDbText::cast(pEnt);
- if (CTextUtil::isMirror(pText))
- {
- pEnt->close();
- ptCen = CConvertUtil::ToPoint2d(CTextUtil::zoome(pText));
- //CDwgDatabaseUtil::zoomObject(ename);
- pData->setClayer(layId);
- CEntityUtil::wmfoutIn(ename);
- CEntityUtil::erase(entId);
- acdbGetObjectId(entId, ename);
- if (acdbOpenObject(pBlock,entId,AcDb::kForWrite)==Acad ::eOk)
- {
- recordId=pBlock->blockTableRecord();
- pBlock->explode(pts);
- for (int k=0;k<pts.length();k++)
- {
- AcDbPolyline* pPoly = new AcDbPolyline();
- pTempEnt = (AcDbEntity*)pts.at(k);
- tempId = CDwgDatabaseUtil::postToMOdelSpace(pTempEnt);
- tempIds.append(tempId);
- if (acdbOpenAcDbEntity(pTempEnt, tempId, AcDb::kForWrite) == Acad::eOk)
- {
- pPoly->convertFrom(pTempEnt, true); //转化为普通多段线
- CPolylineUtil::normal(pPoly);
- pPoly->close();
- }
- }
- pts.removeAll();
- pBlock->erase();
- pBlock->close();
- if (acdbOpenObject(pBlkRcd,recordId,AcDb::kForWrite)==Acad ::eOk)
- {
- pBlkRcd->erase();
- pBlkRcd->close();
- }
- }
- }
- else
- {
- pEnt->close();
- ptCen = CConvertUtil::ToPoint2d(CTextUtil::zoome(pText));
- pData->setClayer(layId); //设置为当前层
- CEntityUtil::mirror(entId, CConvertUtil::ToPoint3d(ptCen), CConvertUtil::ToPoint3d(ptCen) + AcGeVector3d(0, 10, 0)); //以视图中心点镜像
- acdbGetAdsName(ename, entId);
- CEntityUtil::wmfoutIn(ename); //wmfout wmfin一次
- CEntityUtil::erase(entId); //删除文字
- acdbGetObjectId(entId, ename);
- CEntityUtil::mirror(entId, CConvertUtil::ToPoint3d(ptCen), CConvertUtil::ToPoint3d(ptCen) + AcGeVector3d(0, 10, 0));//镜像回去
- if (acdbOpenObject(pBlock, entId, AcDb::kForWrite) == Acad::eOk)
- {
- recordId = pBlock->blockTableRecord();
- pBlock->explode(pts);
- for (int k = 0; k < pts.length(); k++)
- {
- AcDbPolyline* pPoly = new AcDbPolyline();
- pTempEnt = (AcDbEntity*)pts.at(k);
- tempId = CDwgDatabaseUtil::postToMOdelSpace(pTempEnt);
- tempIds.append(tempId);
- if (acdbOpenAcDbEntity(pTempEnt, tempId, AcDb::kForWrite) == Acad::eOk)
- {
- pPoly->convertFrom(pTempEnt, true); //转化为普通多段线
- CPolylineUtil::normal(pPoly);
- pPoly->close();
- }
- }
- pBlock->erase();
- pBlock->close();
- pts.removeAll();
- if (acdbOpenObject(pBlkRcd, recordId, AcDb::kForWrite) == Acad::eOk)
- {
- pBlkRcd->erase();
- pBlkRcd->close();
- }
- }
- }
- }else if (pEnt->isKindOf(AcDbMText::desc()))
- {
- //acutPrintf(L"\n是多行文字");
- pEnt->explode(pts);
- pEnt->erase();
- pEnt->close();
- for (int j = 0; j < pts.length(); j++)
- {
- pTempEnt =(AcDbEntity*)(pts.at(j));
- tempId=CDwgDatabaseUtil::postToMOdelSpace(pTempEnt);
- entIds.append(tempId);
- }
- pts.removeAll();
- }
- else
- {
- pEnt->close();
- }
- }
- }
- acedSetVar(L"cmdecho", &cmdstart);
- pData->setMirrtext(false);
- }
|
评分
-
查看全部评分
|