|
//拷贝,移动,旋转 ,镜像,缩放
选择一个对象
static BOOL SelObj(ads_point& pt,AcDbObjectId& objId){
ads_name en;
if(acedEntSel(_T("\n选择对象"),en,pt) != RTNORM){
return false;
}
Acad::ErrorStatus es = acdbGetObjectId(objId,en);
return es == Acad::ErrorStatus::eOk ? true : false;
}
//选择一个点
static BOOL SelPoint(ads_point& ptEnd){
if(acedGetPoint(NULL,_T("\n选择一个点"),ptEnd) != RTNORM){
return false;
}
return true;
}
拷贝函数测试
static void TESTcopycmd(){
AcDbObjectId objId;
ads_point ptStart;
ads_point ptEnd;
if(!SelObj(ptStart,objId)){
acutPrintf(_T("选择对象失败"));
};
if(!SelPoint(ptEnd)){
acutPrintf(_T("选择点失败"));
}
CopyTo(objId,ptStart,ptEnd);
}
拷贝函数
static BOOL CopyTo(AcDbObjectId entId,const ads_point& ptFrom,
const ads_point& ptTo){
AcDbEntity* pEnt = NULL;
if(acdbOpenObject(pEnt,entId,AcDb::kForRead) != Acad::eOk){
return FALSE;
}
AcDbEntity* pCopyEnt = AcDbEntity::cast(pEnt->clone());
AcDbObjectId copyEntId;
if(pCopyEnt){
copyEntId = LoadEntity(pCopyEnt);
}
Move(copyEntId,ptFrom,ptTo);
}
移动函数测试============
static void TESTmovecmd(){
AcDbObjectId objId;
ads_point ptStart;
ads_point ptEnd;
if(!SelObj(ptStart,objId)){
acutPrintf(_T("选择对象失败"));
};
if(!SelPoint(ptEnd)){
acutPrintf(_T("选择点失败"));
}
Move(objId,ptStart,ptEnd);
}
移动函数
static Acad::ErrorStatus Move(AcDbObjectId entId,const ads_point& ptFrom,const ads_point& ptTo){
AcGeVector3d vec(ptTo[X] - ptFrom[X],ptTo[Y] - ptFrom[Y],
ptTo[Z] - ptFrom[Z]);
AcGeMatrix3d mat;
mat.setToTranslation(vec);
AcDbEntity* pEnt = NULL;
Acad::ErrorStatus es = acdbOpenObject(pEnt,entId,AcDb::kForWrite);
if(es!=Acad::eOk){
return es;
}
es=pEnt->transformBy(mat);
pEnt->close();
}
缩放
static void TESTsccmd()
{
ads_name name;
ads_point ptEnt;
AcDbObjectId id;
if(acedEntSel(_T("选择要扩大的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(_T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;
if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(_T("\n打开实体失败"));
return;
}
ads_real num;
if(acedGetReal(_T("\n输入扩展倍数"),&num) != RTNORM)
{
pEnt->close();
return;
}
ads_point pt;
if(acedGetPoint(NULL,_T("\n选择基点"),pt) != RTNORM)
{
pEnt->close();
return;
}
AcGePoint3d pt3d = asPnt3d(pt);
AcGeMatrix3d mat;
mat.setToScaling(num,pt3d);
pEnt->transformBy(mat);
pEnt->close();
}
旋转
static void TESTrtcmd()
{
ads_name name;
ads_point ptEnt;
AcDbObjectId id;
if(acedEntSel(_T("选择要旋转的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(_T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;
if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(_T("\n打开实体失败"));
return;
}
ads_point ptBase;
if(acedGetPoint(NULL,_T("\n选择旋转的基点"),ptBase) != RTNORM)
{
pEnt->close();如果不及时关闭,会导致内存泄漏
return;
}
ads_real angle;
if(acedGetAngle(ptBase,_T("\n输入旋转角度"),&angle) != RTNORM)
{
pEnt->close();
return;
}
AcDbCurve* pCurve;
pCurve = (AcDbCurve*)pEnt;
AcGePoint3d ptCenter;
pCurve->getStartPoint(ptCenter);
AcGeMatrix3d mat;
acutPrintf(_T("angle is %.2f"),angle);
mat.setToRotation(angle,AcGeVector3d::kZAxis,ptCenter);
//mat.rotation(angle,AcGeVector2d::kXAxis,ptCenter);
pEnt->transformBy(mat);
pEnt->close();
}
镜像
static void TESTmrcmd()
{
ads_name name;
ads_point ptEnt;
AcDbObjectId id;
if(acedEntSel(_T("选择要镜像的实体"),name,ptEnt) != RTNORM)
{
acutPrintf(_T("\nno obj select"));
return;
}
if(Acad::ErrorStatus::eOk != acdbGetObjectId(id,name))
{
return;
}
AcDbEntity* pEnt;
if(Acad::ErrorStatus::eOk != acdbOpenObject(pEnt,id,AcDb::OpenMode::kForWrite))
{
acutPrintf(_T("\n打开实体失败"));
return;
}
ads_point ptDis1;
if(acedGetPoint(NULL,_T("\n选择镜像点1"),ptDis1) !=RTNORM)
{
acutPrintf(_T("\nno point select"));
pEnt->close();
return;
}
ads_point ptDis2;
if(acedGetPoint(NULL,_T("\n选择镜像点2"),ptDis2) !=RTNORM)
{
acutPrintf(_T("\nno point select"));
pEnt->close();
return;
}
AcGePoint3d ptDis3d1 = asPnt3d(ptDis1);
AcGePoint3d ptDis3d2 = asPnt3d(ptDis2);
AcGeLine3d line(ptDis3d1,ptDis3d2);
AcGeMatrix3d mat ;
mat.setToMirroring(line);
acedInitGet(NULL,_T("Y N"));
CString strKW;
if(acedGetKword(_T("删除原对象?Y/N"),strKW.GetBuffer(1)) != RTNORM)
{
return;
}
strKW.ReleaseBuffer();
if(strKW.CompareNoCase(_T("N")) == 0)
{
AcDbEntity* pEnt2 = AcDbEntity::cast(pEnt->clone());
LoadEntity(pEnt2);
pEnt2->close();
}
pEnt->transformBy(mat);
pEnt->close();
}
} |
|