⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmdutilities.cpp

📁 能在MDT5/6环境下对已经存在地曲面进行全部和局部区域展开
💻 CPP
字号:
#include "stdafx.h"
#include "StdArx.h"

#include "CmdUtilities.h"
#include "ChAppendedObjReactor.h"
#include "CreateDbObj.h"
#include "DbUtilities.h"
#include "dbxutil.h"
#include "geassign.h"
#include "ADSCODES.H"

//////////////////////////////////////////////////////////////////////////
// 当使用MCAD API库时使用
//
#ifdef AMI_H
#include "AmiUtilities.h"

// 从geomkeys转换到ss
AmiStatus getSSFromGeomKeys(AmiGeomKeyArray &keys,ads_name &ss)
{
	int num,i;
	AcDbObjectId *pArr;
	ads_name e1;
	AmiStatus as;
	
	acedSSAdd(NULL,NULL,ss);
	for(i=0;i<keys.length();i++) {		
		as = amiGetDbIdsFromKey(keys[i],num,pArr);
		if(num>0) {
			acdbGetAdsName(e1,pArr[0]);
			acedSSAdd(e1,ss,ss);
			delete pArr;
		}
		else {
			acedSSFree(ss);
			return as;
		}
	}
	
	return as;
}

// 调用命令amloftu生成单向放样曲面
AmiStatus createLoftUSurface(AmiGeomKeyArray& keys, AmiGeomKey *& pSurfkey)
{
	AmiStatus as=Ami::kOk;
	
	ads_name ss,ent;
	as = getSSFromGeomKeys(keys,ss);
	if(as != Ami::kOk) {
		if(ss) acedSSFree(ss);
		return as;
	}

	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);

	struct resbuf *list = acutBuildList(RTSTR, "_-amloftu", RTPICKS,ss,RTSTR,"",RTSTR,"",0);
	acedCmd(list);
	acutRelRb(list);
	acdbEntLast(ent);
	AcDbObjectId objId;
	acdbGetObjectId(objId,ent);
	as = amiGetKeyFromId(objId,Ami::surfKey,(AmiObjectKey*&)pSurfkey);
	acedSSFree(ss);
	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);

	return as;
}

// 调用命令amloftuv生成双向放样曲面
AmiStatus createLoftUVSurface(AmiGeomKeyArray & ukeys, AmiGeomKeyArray &vkeys, AmiGeomKey *& pSurfkey)
{
	AmiStatus as=Ami::kOk;
	
	ads_name ss1,ss2,ent;
	as = getSSFromGeomKeys(ukeys,ss1);
	if(as != Ami::kOk) {
		if(ss1) acedSSFree(ss1);
		return as;
	}
	as = getSSFromGeomKeys(vkeys,ss2);
	if(as != Ami::kOk) {
		if(ss1) acedSSFree(ss1);
		if(ss2) acedSSFree(ss2);
		return as;
	}
	
	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);
	
	struct resbuf *list = acutBuildList(RTSTR, "_amloftuv", RTPICKS,ss1,RTSTR,"",
		RTPICKS,ss2,RTSTR,"",0);
	acedCmd(list);
	acutRelRb(list);
	acdbEntLast(ent);
	AcDbObjectId objId;
	acdbGetObjectId(objId,ent);
	as = amiGetKeyFromId(objId,Ami::surfKey,(AmiObjectKey*&)pSurfkey);
	
	if(ss1) acedSSFree(ss1);
	if(ss2) acedSSFree(ss2);
	
	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);
	
	return as;
}

#endif // AMI_H
//
// 如果使用MCAD API库时使用
//////////////////////////////////////////////////////////////////////////


AcDbObjectId createLoftUSurface(const AcDbObjectIdArray& ids)
{
	Acad::ErrorStatus es;
	
	ads_name ss,ent;
	es = getSSFromDbIds(ids,ss);
	if(es != Acad::eOk) {
		return NULL;
	}

	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);

	struct resbuf *list = acutBuildList(RTSTR, "_-amloftu", RTPICKS,ss,RTSTR,"",RTSTR,"",0);
	acedCmd(list);
	acutRelRb(list);
	acdbEntLast(ent);
	AcDbObjectId objId;
	acdbGetObjectId(objId,ent);
	acedSSFree(ss);

	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);

	return objId;
}



AcDbObjectId createLoftUVSurface(const AcDbObjectIdArray& uids, const AcDbObjectIdArray& vids)
{
	Acad::ErrorStatus es;
	AcDbObjectId eId;
	
	ads_name ss1,ss2,ent;
	es = getSSFromDbIds(uids,ss1);
	if(es != Acad::eOk) {
		return NULL;
	}
	es = getSSFromDbIds(vids,ss2);
	if(es != Acad::eOk) {
		acedSSFree(ss1);
		return NULL;
	}

	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);

	struct resbuf *list = acutBuildList(RTSTR, "_amloftuv", RTPICKS,ss1,RTSTR,"",
		RTPICKS,ss2,RTSTR,"",0);
	acedCmd(list);
	acutRelRb(list);
	acdbEntLast(ent);
	acdbGetObjectId(eId,ent);

	if(ss1) acedSSFree(ss1);
	if(ss2) acedSSFree(ss2);

	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);

	return eId;
}

// 调用命令_amplane生成平面, 平面类名为AcAsSurface
AcDbObjectIdArray createPlane(const AcDbObjectIdArray& ids)
{
	Acad::ErrorStatus es;	
	ads_name ss;
	es = getSSFromDbIds(ids,ss);
	if (Acad::eOk != es) {
		return NULL;
	}

	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);

	struct resbuf *list = acutBuildList(RTSTR, "_amplane", RTSTR,"_wire",RTPICKS,ss,RTSTR,"",0);

	AcDbObjectIdArray retIds;
	ChAppendedObjDbReactor *pDbReactor;
	pDbReactor = new ChAppendedObjDbReactor();
	pDbReactor->setClassName("AcAsSurfBody");
	acedCmd(list);
	pDbReactor->getObjectIds(retIds);
	delete pDbReactor;

	acutRelRb(list);

	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);

	return retIds;
}

void
printList(struct resbuf* pRb)
{
    int rt, i;
    char buf[133];
	
    for (i = 0;pRb != NULL;i++, pRb = pRb->rbnext) {
        if (pRb->restype < 1010) {
            rt = RTSTR;
        } else if (pRb->restype < 1040) {
            rt = RT3DPOINT;
        } else if (pRb->restype < 1060) {
            rt = RTREAL;
        } else if (pRb->restype < 1071) {
            rt = RTSHORT;
        } else if (pRb->restype == 1071) {
            rt = RTLONG;
        } else {// restype is already RTSHORT, RTSTR,...
            rt = pRb->restype; // or else it is unknown.
        }
		
        switch (rt) {
        case RTSHORT:
            if (pRb->restype == RTSHORT) {
                acutPrintf(
                    "RTSHORT : %d\n", pRb->resval.rint);
            } else {
                acutPrintf("(%d . %d)\n", pRb->restype,
                    pRb->resval.rint);
            };
            break;
			
        case RTREAL:
            if (pRb->restype == RTREAL) {
                acutPrintf("RTREAL : %0.3f\n",
                    pRb->resval.rreal);
            } else {
                acutPrintf("(%d . %0.3f)\n", pRb->restype,
                    pRb->resval.rreal);
            };
            break;
			
        case RTSTR:
            if (pRb->restype == RTSTR) {
                acutPrintf("RTSTR : %s\n",
                    pRb->resval.rstring);
            } else {
                acutPrintf("(%d . \"%s\")\n", pRb->restype,
                    pRb->resval.rstring);
            };
            break;
			
        case RT3DPOINT:
            if (pRb->restype == RT3DPOINT) {
                acutPrintf(
                    "RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
                    pRb->resval.rpoint[X],
                    pRb->resval.rpoint[Y],
                    pRb->resval.rpoint[Z]);
            } else {
                acutPrintf("(%d %0.3f %0.3f %0.3f)\n",
                    pRb->restype,
                    pRb->resval.rpoint[X],
                    pRb->resval.rpoint[Y],
                    pRb->resval.rpoint[Z]);
            }
            break;
			
        case RTLONG:
            acutPrintf("RTLONG : %dl\n", pRb->resval.rlong);
            break;
        }
		
        if ((i == 23) && (pRb->rbnext != NULL)) {
            i = 0;
            acedGetString(0,
                "Press <ENTER> to continue...", buf);
        }
    }
}

Acad::ErrorStatus 
getSSFromDbIds(const AcDbObjectIdArray& ids,ads_name &ss)
{
	int num,i;
	ads_name e1;
	Acad::ErrorStatus es;
	
	num = ids.length();
	acedSSAdd(NULL,NULL,ss);
	for(i=0;i<num;i++) {		
		es = acdbGetAdsName(e1,ids[i]);
		if (Acad::eOk != es) {
			acedSSFree(ss);
			return es;
		}
		acedSSAdd(e1,ss,ss);
	}
	
	return es;
}


AcDbObjectId createRegionFromLoop(const ChGeLoop2d& loop, const AcGePoint2d& ptInLoop)
{
	Acad::ErrorStatus es;
	AcDbSpline * spl;
	AcDbObjectIdArray ids;
	int i,len;

	AcGePoint3dArray pnts;
	AcGePoint2d pt2d;
	AcGePoint3d pt;
	int j,jlen;

	len = loop.length();
	ids.setLogicalLength(len);
	for (i=0; i<len; i++) {
		jlen = loop[i].length();
		pnts.setLogicalLength(jlen);
		for (j=0; j<jlen; j++) {
			pt2d = (loop[i])[j];
			pt.set(pt2d.x,pt2d.y,0);
			acdbUcs2Wcs(asDblArray(pt),asDblArray(pt),false);
			pnts[j] = pt;
		}
		createSpline(pnts,spl);
		postToDb(spl,ids[i]);
		spl->close();
	}
	
	ads_name ss;
	es = getSSFromDbIds(ids,ss);
	if(es != Acad::eOk) {
		return NULL;
	}

	pt.set(ptInLoop.x,ptInLoop.y,0);
	
	struct resbuf val;
	val.restype = RTSHORT;
	val.resval.rint = 0;
	acedSetVar("cmdecho",&val);

	ChAppendedObjDbReactor *pRt;
	pRt = new ChAppendedObjDbReactor;
	pRt->setClassName("AcDbRegion");

	double angle=90;

	struct resbuf *list = acutBuildList(RTSTR, "_-boundary", RTSTR, "A", 
		RTSTR, "B", RTSTR, "N", RTPICKS,ss, RTSTR, "", 
		RTSTR, "O", RTSTR, "R", 
		RTSTR, "I", RTSTR, "N", RTSTR, "A", RTREAL, angle , 
		RTSTR, "",
		RT3DPOINT,asDblArray(pt),RTSTR,"",0);
	acedCmd(list);
	acutRelRb(list);
	acedSSFree(ss);

	AcDbObjectIdArray rgs;
	pRt->getObjectIds(rgs);
	delete pRt;
	
	val.resval.rint = 1;
	acedSetVar("cmdecho",&val);

	len = ids.length();
	for (i=0; i<len; i++) {
		acdbOpenObject(spl,ids[i],AcDb::kForWrite);
		spl->erase();
		spl->close();
	}


	if (rgs.length()) {
		len = rgs.length();
		AcDbRegion *pRg;
		for (i=1; i<len; i++) {	
			acdbOpenObject(pRg,rgs[i],AcDb::kForWrite);
			pRg->erase();
			pRg->close();
		}
		acdbOpenObject(pRg,rgs[0],AcDb::kForWrite);
		AcGeMatrix3d xform;
		acdbUcsMatrix(xform);
		xform.invert();
		pRg->transformBy(xform);
		pRg->close();

		return rgs[0];
	} else {
		return NULL;
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -