hulei_accp
发表于 2005-11-7 22:57:00
<P>#include "adscodes.h"<BR>#include "rxregsvc.h"<BR>#include "assert.h"<BR>#include "math.h"<BR>#include "gepnt3d.h"<BR>#include "gevec3d.h"<BR>#include "gelnsg3d.h"<BR>#include "gearc3d.h"<BR>#include "dbents.h"<BR>#include "dbsymtb.h"<BR>#include "acgi.h"<BR>#include "acdb.h"<BR>#include "acdbabb.h"<BR>#include "aced.h"<BR>#include "acedads.h"<BR>#include "adesk.h"<BR>#include "dbapserv.h"<BR>#include "customEntity.h"</P>
<P><BR>Acad::ErrorStatus addToModelSpace(AcDbObjectId& , AcDbEntity*);<BR>void elevDim();<BR>void initApp();<BR>void unloadApp();</P>
<P>extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void * pkt);</P>
<P>static Acad::ErrorStatus drawDim(const CMyElevDim * elevDim,<BR> AcGiWorldDraw * woldDraw,<BR> AcGiViewportDraw * vportDraw);<BR>static Acad::ErrorStatus intLine(const CMyElevDim * elevDim,<BR> const AcGeLine3d line,<BR> AcGePoint3dArray & points);<BR>static Acad::ErrorStatus intLine(const CMyElevDim * elevDim,<BR> const AcGeLineSeg3d line,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points);<BR>static Acad::ErrorStatus intArc(const CMyElevDim * elevDim,<BR> const AcDbArc * arc,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points);<BR>static Acad::ErrorStatus intArc(const CMyElevDim * elevDim,<BR> const AcGeCircArc3d arc,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points);</P>
<P>static Acad::ErrorStatus intCircle(const CMyElevDim *elevDim,<BR> const AcDbCircle *circle,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points);</P>
<P>static Acad::ErrorStatus intCircle(const CMyElevDim * elevDim,<BR> const AcGeCircArc3d circle,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points);<BR>ACRX_DXF_DEFINE_MEMBERS(CMyElevDim,<BR> AcDbEntity,<BR> AcDb::kDHL_CURRENT,<BR> AcDb::kMReleaseCurrent,<BR> 0,<BR> CUSTOMENTITY,<BR> AUTOCAD);<BR>CMyElevDim::CMYElevDim()<BR>{<BR> assertWriteEnabled();<BR> mStartPoint.set(0,0,0);<BR> mInsertPoint.set(0,0,0);<BR> mSymbolPoint.set(0,0,0);<BR> mHeight=0;<BR> mLength=0;<BR> mElevation=0;<BR>}<BR>CMyElevDim::~CMyElevDim()<BR>{}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::getVertices3d(AcGePoint3dArray & vertexArray) const<BR>{<BR> assertReadEnabled();<BR> AcGePoint3dArray temparray;<BR> AcGePoint3d tempPoint;<BR> double height=getHeight();<BR> double length=getLength();<BR> vertexArray.append(mStartPoint);<BR> tempPoint=mStartPoint+AcGeVector3d(length,0,0);<BR> vertexArray.append(tempPoint);<BR> vertexArray.append(mSymbolPoint);<BR> tempPoint.set(mSymbolPoint.x-0.5*height,mSymbolPoint.y+height,mSymbolPoint.z);<BR> vertexArray.append(tempPoint);<BR> tempPoint.set(mSymbolPoint.x+0.5*height,mSymbolPoint.y+height,mSymbolPoint.z);<BR> vertexArray.append(tempPoint);<BR> return Acad::eOk;<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::getOsnapPoints(AcDb::OsnapMode osnapMode,<BR> int gsSelectionMark,<BR> const AcGePoint3d& pickPoint,<BR> const AcGePoint3d& lastPoint,<BR> const AcGeMatrix3d& viewXform,<BR> AcGePoint3dArray & snapPoints,<BR> AcDbIntArray & )const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> if(gsSelectionMark==0)<BR> {<BR> return Acad::eOk;<BR> }<BR> if(osnapMode!=AcDb::kOsModeEnd <BR> && osnapMode!=AcDb::kOsModeMid<BR> && osnapMode!=AcDb::kOsModeNear<BR> && osnapMode!=AcDb::kOsModePerp<BR> && osnapMode!=AcDb::kOsModeIns)<BR> {<BR> return Acad::eOk;<BR> }</P>
<P> AcGePoint3d startPoint;<BR> if(gsSelectionMark==5)<BR> {<BR> if(osnapMode==AcDb::kOsModeIns)<BR> {<BR> snapPoints.append(mInsertPoint);<BR> }<BR> return es;<BR> }<BR> int startIndex;<BR> if(gsSelectionMark==1)<BR> {<BR> startIndex=gsSelectionMark-1;<BR> }<BR> else<BR> {<BR> startIndex=gsSelectionMark;<BR> }<BR> AcGePoint3dArray vertexArray;<BR> if((es=getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGeLineSeg3d lnsg;<BR> if(startIndex==4)<BR> {<BR> lnsg=AcGeLineSeg3d(vertexArray,vertexArray);<BR> }<BR> else<BR> {<BR> lnsg=AcGeLineSeg3d(vertexArray,vertexArray);<BR> }<BR> AcGePoint3d pt;<BR> AcGeLine3d line,perpLine;<BR> AcGeVector3d vec;<BR> AcGeVector3d viewDir(viewXform(Z,0),viewXform(Z,1),viewXform(Z,2));<BR> switch(osnapMode)<BR> {<BR> case AcDb::kOsModeEnd:<BR> snapPoints.append(lnsg.startPoint());<BR> snapPoints.append(lnsg.endPoint());<BR> break;<BR> case AcDb::kOsModeMid:<BR> pt.set(((lnsg.startPoint())+(lnsg.endPoint()))*0.5,<BR> ((lnsg.startPoint())+(lnsg.endPoint()))*0.5,<BR> ((lnsg.startPoint())+(lnsg.endPoint()))*0.5);<BR> snapPoints.append(pt);<BR> break;<BR> case AcDb::kOsModeNear:<BR> pt=lnsg.projClosestPointTo(pickPoint,viewDir);<BR> snapPoints.append(pt);<BR> break;<BR> case AcDb::kOsModePerp:<BR> vec=lnsg.endPoint()-lnsg.startPoint();<BR> vec.normalize();<BR> line.set(lnsg.startPoint(),vec);<BR> pt=line.closestPointTo(lastPoint);<BR> snapPoints.append(pt);<BR> break;<BR> default:<BR> return Acad::eOk;<BR> }<BR> return es;</P>
<P>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::getGripPoints(AcGePoint3dArray & gripPoints,<BR> AcDbIntArray& osnapModes,<BR> AcDbIntArray& geomIds) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;<BR> if((es=getVertices3d(gripPoints))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> gripPoints.append(mInsertPoint);<BR> return es;<BR>}<BR>Acad::ErrorStatus<BR>CMyElevDim::moveGripPointsAt(const AcDbIntArray& indices,<BR> const AcGeVector3d& offset)<BR>{<BR> if(indices.length()==0||offset.isZeroLength())<BR> {<BR> return transformBy(AcGeMatrix3d::translation(offset));<BR> }<BR> AcGeVector3d off(offset);<BR> double dist;<BR> switch(indices)<BR> {<BR> case 1:<BR> mLength+=off.x;<BR> if(mLength<40.0)<BR> {<BR> mLength=40.0;<BR> } <BR> break;<BR> case 2:<BR> mSymbolPoint+=off;<BR> dist=mSymbolPoint.x-mStartPoint.x;<BR> if(dist<0)<BR> {<BR> mSymbolPoint.x=mStartPoint.x;<BR> }<BR> else if(dist>mLength)<BR> {<BR> mSymbolPoint.x=mStartPoint.x+mLength;<BR> }<BR> mSymbolPoint.y=mStartPoint.y;<BR> mSymbolPoint.z=mStartPoint.z;<BR> break;<BR> case 3:<BR> case 4:<BR> mHeight+=off.y;<BR> if(mHeight<10.0)<BR> {<BR> mHeight=10.0;<BR> }<BR> break;<BR> case 5:<BR> mInsertPoint+=off;<BR> if(((mInsertPoint.x=mSymbolPoint.x)<mHeight)||((mInsertPoint.y-mSymbolPoint.y)<0.2*mHeight))<BR> {<BR> mInsertPoint.x=mSymbolPoint.x+mHeight;<BR> mInsertPoint.y=mSymbolPoint.y+0.2*mHeight;<BR> mInsertPoint.z=mSymbolPoint.z;<BR> }<BR> break;<BR> }<BR> return Acad::eOk;<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::getStretchPoints(AcGePoint3dArray & stretchPoints) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;<BR> if((es=getVertices3d(stretchPoints))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> stretchPoints.removeAt(stretchPoints.length()-1);<BR> return es;<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::moveStretchPointsAt(const AcDbIntArray & indices,<BR> const AcGeVector3d& offset)<BR>{<BR> return moveGripPointsAt(indices,offset);<BR>}<BR>Acad::ErrorStatus<BR>CMyElevDim::getTransformerdCopy(const AcGeMatrix3d& mat,AcDbEntity * &ent)const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> for(int i=0; i<vertexArray.length()-1;i++)<BR> {<BR> vertexArray.transformBy(mat);<BR> }<BR> AcGePoint3dArray tempPtArray;<BR> tempPtArray.append(vertexArray);<BR> tempPtArray.append(vertexArray);<BR> tempPtArray.append(vertexArray);<BR> tempPtArray.append(vertexArray);<BR> tempPtArray.append(vertexArray);<BR> AcDb2dPolyline *pPolyline;<BR> pPolyline=new AcDb2dPolyline(k2dSimplePoly,vertexArray);<BR> assert(pPolyline!=NULL);<BR> pPolyline->setPropertiesFrom(this);<BR> ent=pPolyline;<BR> return es;</P>
<P>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::transformBy(const AcGeMatrix3d& xform)<BR>{<BR> assertWriteEnabled();<BR> mStartPoint.transformBy(xform);<BR> mSymbolPoint.transformBy(xform);<BR> mInsertPoint.transformBy(xform);<BR> mHeight=mHeight*xform.scale();<BR> mLength=mLength*xform.scale();<BR> mElevation=mStartPoint.y;<BR> return Acad::eOk;<BR>}<BR>Acad::ErrorStatus<BR>CMyElevDim::intersectWith(const AcDbEntity * ent,<BR> AcDb::Intersect intType,<BR> AcGePoint3dArray &points,<BR> int,<BR> int)const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> if(ent==NULL)<BR> {<BR> return Acad::eNullEntityPointer;<BR> }<BR> if(ent->isKindOf(AcDbLine::desc()))<BR> {<BR> if((es=intLine(this,AcDbLine::cast(ent),<BR> intType,NULL,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else if(ent->isKindOf(AcDbArc::desc()))<BR> {<BR> if((es=intArc(this,AcDbArc::cast(ent),intType,<BR> NULL,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else if(ent->isKindOf(AcDbCircle::desc()))<BR> {<BR> if((es=intCircle(this,AcDbCircle::cast(ent),<BR> intType,NULL,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else<BR> {<BR> AcGePoint3dArray vertexArray;<BR> if((es=getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> if(intType==AcDb::kExtendArg||intType==AcDb::kExtendBoth)<BR> {<BR> intType=AcDb::kExtendThis;<BR> }<BR> AcDbLine * pAcadLine;<BR> for(int i=0; i<vertexArray.length()-1;i++)<BR> {<BR> pAcadLine=new AcDbLine();<BR> if(i==1)<BR> {<BR> pAcadLine->setStartPoint(vertexArray);<BR> pAcadLine->setEndPoint(vertexArray);<BR> }<BR> else<BR> {<BR> pAcadLine->setStartPoint(vertexArray);<BR> pAcadLine->setEndPoint(vertexArray);<BR> }<BR> pAcadLine->setNormal(AcGeVector3d(0,0,1));<BR> if((es=ent->intersectWith(pAcadLine,intType,points))!=Acad::eOk)<BR> {<BR> delete pAcadLine;<BR> return es;<BR> }<BR> delete pAcadLine;<BR> }<BR> }<BR> return es;<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::intersectWith(const AcDbEntity * ent,<BR> AcDb::Intersect intType,<BR> const AcGePlane & projPlane,<BR> AcGePoint3dArray & points,<BR> int,<BR> int) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> if(ent=NULL)<BR> {<BR> return Acad::eNullEntityPointer;<BR> }<BR> if(ent->isKindOf(AcDbLine::desc()))<BR> {<BR> if((es=intLine(this,AcDbLine::cast(ent),<BR> intType,&projPlane,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else if(ent->isKindOf(AcDbArc::desc()))<BR> {<BR> if((es=intArc(this,AcDbArc::cast(ent),<BR> intType,&projPlane,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else if(ent->isKindOf(AcDbCircle::desc()))<BR> {<BR> if((es=intCircle(this,AcDbCircle::cast(ent),<BR> intType,&projPlane,points))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> }<BR> else<BR> {<BR> AcGePoint3dArray vertexArray;<BR> if((es=getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> if(intType==AcDb::kExtendArg||intType==AcDb::kExtendBoth)<BR> {<BR> intType=AcDb::kExtendThis;<BR> }<BR> AcDbLine *pLine;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> pLine=new AcDbLine();<BR> if(i==1)<BR> {<BR> pLine->setStartPoint(vertexArray);<BR> pLine->setEndPoint(vertexArray);<BR> pLine->setNormal(AcGeVector3d(0,0,1));<BR> }<BR> else<BR> {<BR> pLine->setStartPoint(vertexArray);<BR> pLine->setEndPoint(vertexArray);<BR> pLine->setNormal(AcGeVector3d(0,0,1));<BR> }<BR> if((es=ent->intersectWith(pLine,intType,<BR> projPlane,points))!=Acad::eOk)<BR> {<BR> delete pLine;<BR> return es;<BR> }<BR> delete pLine;<BR> }<BR> }<BR> return es;<BR>}</P>
<P>void CMyElevDim::list() const<BR>{<BR> assertReadEnabled();<BR> AcDbEntity::list();<BR> acutPrintf("%18s%16s%-9.16q0\n",<BR> "Elevation:",mElevation);<BR> AcGePoint3d sp=getStartPoint();<BR> acutPrintf("%18s%16s","","Start Point:");<BR> acutPrintf("x=%-9.16q0,y=%-9.16q0,z=%-9.16q0\n",<BR> sp.x,sp.y,sp.z);<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::explode(AcDbVoidPtrArray & entitySet) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcDbLine * line;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> line=new AcDbLine();<BR> if(i==1)<BR> {<BR> line->setStartPoint(vertexArray);<BR> line->setEndPoint(vertexArray);<BR> line->setNormal(AcGeVector3d(0,0,1));<BR> }<BR> else<BR> {<BR> line->setStartPoint(vertexArray);<BR> line->setEndPoint(vertexArray);<BR> line->setNormal(AcGeVector3d(0,0,1));</P>
<P> }<BR> entitySet.append(line);<BR> }<BR> AcDbText *pText;<BR> double elev;<BR> char str;<BR> elev=this->getElevation();<BR> acdbRToS(elev,2,2,str);<BR> pText=new AcDbText(mInsertPoint,str,AcDbObjectId::kNull,mHeight,0);<BR> entitySet.append(pText);<BR> return es;<BR>}<BR>Adesk::Boolean<BR>CMyElevDim::worldDraw(AcGiWorldDraw * worldDraw)<BR>{<BR> assertReadEnabled();<BR> if(worldDraw->regenAbort())<BR> {<BR> return Adesk::kTrue;<BR> }<BR> switch(worldDraw->regenType())<BR> {<BR> case kAcGiHideOrShadeCommand:<BR> case kAcGiRenderCommand:<BR> break;<BR> case kAcGiStandardDisplay:<BR> case kAcGiSaveWorldDrawForR12:<BR> case kAcGiSaveWorldDrawForProxy:<BR> AOK(drawDim(this,worldDraw,NULL));<BR> break;<BR> default:<BR> assert(Adesk::kFalse);<BR> }<BR> return Adesk::kTrue;<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::dwgInFields(AcDbDwgFiler * filer)<BR>{<BR> assertWriteEnabled();<BR> Acad::ErrorStatus es;<BR> if((es=AcDbEntity::dwgInFields(filer))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGePoint3d startPoint,symPoint,insPoint;<BR> filer->readPoint3d(&startPoint);<BR> filer->readPoint3d(&symPoint);<BR> filer->readPoint3d(&insPoint);<BR> filer->readDouble(&mHeight);<BR> filer->readDouble(&mLength);<BR> filer->readDouble(&mElevation);<BR> acdbWcs2Ecs(asDblArray(startPoint),asDblArray(startPoint),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mStartPoint.set(startPoint.x,startPoint.y,startPoint.z);<BR> acdbWcs2Ecs(asDblArray(symPoint),asDblArray(symPoint),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mSymbolPoint.set(symPoint.x,symPoint.y,symPoint.z);<BR> acdbWcs2Ecs(asDblArray(insPoint),asDblArray(insPoint),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mInsertPoint.set(insPoint.x,insPoint.y,insPoint.z);<BR> return filer->filerStatus();<BR>}</P>
<P>Acad::ErrorStatus<BR>CMyElevDim::dwgOutFields(AcDbDwgFiler * filer) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;<BR> if((es=AcDbEntity::dwgOutFields(filer))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> filer->writePoint3d(mStartPoint);<BR> filer->writePoint3d(mSymbolPoint);<BR> filer->writePoint3d(mInsertPoint);<BR> filer->writeDouble(mHeight);<BR> filer->writeDouble(mLength);<BR> filer->writeDouble(mElevation);<BR> return filer->filerStatus();<BR>}<BR>#ifdef ORDER_DEPENDENT<BR>Acad::ErrorStatus<BR>CMyElevDim::dxfInFields(AcDbDxfFiler * filer)<BR>{<BR> assertWriteEnabled();<BR> if((AcDbEntity::dxfInFields(filer)!=Acad::eOk)||!filer->atSubClassData("CMyElevDim"))<BR> {<BR> return filer->filerStatus();<BR> }<BR> try<BR> {<BR> AcGePoint3d sp,sympt,inspt;<BR> filer->readItem(&rb);<BR> if(rb.restype!=AcDb::kDxfXCoord)<BR> {<BR> throw AcDb::kDxfXCoord;<BR> }<BR> sp=asPnt3d(rb.resva.rpoint);<BR> filer->readItem(&rb);<BR> if(rb.restype!=AcDb::kDxfXCoord+1)<BR> {<BR> throw AcDb::kDxfXCoord+1;<BR> }<BR> sympt=asPnt3d(re.resval.rpoint);<BR> filer->readItem(&rb);<BR> if(rb.restype!=AcDb::kDxfXCoord+2)<BR> {<BR> throw AcDb::kDxfXCoord+2;<BR> }<BR> inspt=asPnt3d(rb.resval.rpoint);<BR> filer->readItem(&rb);<BR> if(rb.restype!=AcDb::kDxfReal)<BR> {<BR> thrwo AcDb::kDxfReal;<BR> }<BR> mHeight=rb.resval.rreal;<BR> filer->readItem(&rb);<BR> if(rb.restype!=AcDb::kDxfReal+1)<BR> {<BR> throw AcDb::kDxfReal+1;<BR> }<BR> mLength=rb.resva.rreal;<BR> filer->realItem(&rb);<BR> if(rb.restype!=AcDb::kDxfReal+2)<BR> {<BR> throw AcDb::kDxfReal+2;<BR> }<BR> mElevation=rb.resval.rreal;<BR> acDbWcs2Ecs(asDblArray(sp),asDblArray(sp),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mStartPoint.set(sp.x,sp.y,sp.z);<BR> acdbWcs2Ecs(asDblArray(sympt),asDblArray(sympt),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mSymbolPoint.set(sympt.x,sympt.y,sympt.z);<BR> acdbWcs2Ecs(asDblArray(inspt),asDblArray(inspt),<BR> asDblArray(AcGeVector3d(0,0,,1)),Adesk::kFalse);<BR> mInsertPoint.set(inspt.x,inspt.y,intpt.z);<BR> }<BR> catch(AcDb::DxfCode code)<BR> {<BR> filer->pushBackItem();<BR> filer->setError(Acad::EInvalidDxfCode,"\nError:expected group code %d",code);<BR> return filer->filerStatus();<BR> }<BR>}<BR>#else<BR>Acad::ErrorStatus<BR>CMyElevDim::dxfInFields(AcDbDxfFiler * filer)<BR>{<BR> assertWriteEnabled();<BR> Acad::ErrorStatus es=Acad::eOk;<BR> resbuf rb;<BR> if((AcDbEntity::dxfInFields(filer)!=Acad::eOk)||!filer->atSubclassData("CMyElevDim"))<BR> {<BR> return filer->filerStatus();<BR> }<BR> AcGePoint3d sp,sympt,inspt;<BR> Adesk::UInt32 fieldsFlags=0;<BR> while((es==Acad::eOk) && ((es=filer->readResBuf(&rb))==Acad::eOk))<BR> {<BR> switch(rb.restype)<BR> {<BR> case AcDb::kDxfXCoord:<BR> sp=asPnt3d(rb.resval.rpoint);<BR> fieldsFlags=0x1;<BR> break;<BR> case AcDb::kDxfXCoord+1:<BR> sympt=asPnt3d(rb.resval.rpoint);<BR> fieldsFlags=0x2;<BR> break;<BR> case AcDb::kDxfXCoord+2:<BR> inspt=asPnt3d(rb.resval.rpoint);<BR> fieldsFlags=0x3;<BR> break;<BR> case AcDb::kDxfReal:<BR> mHeight=rb.resval.rreal;<BR> fieldsFlags=0x4;<BR> break;<BR> case AcDb::kDxfReal+1:<BR> mLength=rb.resval.rreal;<BR> fieldsFlags=0x5;<BR> break;<BR> case AcDb::kDxfReal+2:<BR> mElevation=rb.resval.rreal;<BR> fieldsFlags=0x6;<BR> break;<BR> default:<BR> filer->pushBackItem();<BR> es=Acad::eEndOfFile;<BR> break;<BR> }<BR> }<BR> if(es!=Acad::eEndOfFile)<BR> {<BR> return Acad::eInvalidResBuf;<BR> }<BR> acdbWcs2Ecs(asDblArray(sp),asDblArray(sp),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mStartPoint.set(sp.x,sp.y,sp.z);<BR> acdbWcs2Ecs(asDblArray(sympt),asDblArray(sympt),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mSymbolPoint.set(sympt.x,sympt.y,sympt.z);<BR> acdbWcs2Ecs(asDblArray(inspt),asDblArray(inspt),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> mInsertPoint.set(inspt.x,inspt.y,inspt.z);<BR> return es;<BR>}<BR>#endif<BR>Acad::ErrorStatus<BR>CMyElevDim::dxfOutFields(AcDbDxfFiler * filer) const<BR>{<BR> assertReadEnabled();<BR> Acad::ErrorStatus es;<BR> if((es=AcDbEntity::dxfOutFields(filer))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> filer->writeItem(AcDb::kDxfSubclass,"CMyElevDim");<BR> filer->writePoint3d(AcDb::kDxfXCoord,mStartPoint);<BR> filer->writePoint3d(AcDb::kDxfXCoord+1,mSymbolPoint);<BR> filer->writePoint3d(AcDb::kDxfXCoord+2,mInsertPoint);<BR> filer->writeDouble(AcDb::kDxfReal,mHeight);<BR> filer->writeDouble(AcDb::kDxfReal+1,mLength);<BR> filer->writeDouble(AcDb::kDxfReal+2,mElevation);<BR> return filer->filerStatus();<BR>}</P>
<P>static Acad::ErrorStatus<BR>drawDim(const CMyElevDim * elevDim,<BR> AcGiWorldDraw * worldDraw,<BR> AcGiViewportDraw * vportDraw)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=elevDim->getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGePoint3d ptArray;<BR> for(int i=0;i<vertexArray.length()-1; i++)<BR> {<BR> if(i==1)<BR> {<BR> if(worldDraw!=NULL)<BR> {<BR> worldDraw->subEntityTraits().setSelectionMarker(4);<BR> ptArray=vertexArray;<BR> ptArray=vertexArray;<BR> worldDraw->geometry().polyline(2,ptArray);<BR> }<BR> else<BR> {<BR> assert(Adesk::kFalse);<BR> }<BR> continue;<BR> }<BR> if(worldDraw!=NULL)<BR> {<BR> if(i==0)<BR> {<BR> worldDraw->subEntityTraits().setSelectionMarker(i+1);<BR> }<BR> else<BR> {<BR> worldDraw->subEntityTraits().setSelectionMarker(i);<BR> }<BR> }<BR> else<BR> {<BR> assert(Adesk::kFalse);<BR> }<BR> ptArray=vertexArray;<BR> ptArray=vertexArray;<BR> if(worldDraw!=NULL)<BR> {<BR> worldDraw->geometry().polyline(2,ptArray);<BR> }<BR> else<BR> {<BR> assert(Adesk::kFalse);<BR> }<BR> }<BR> if(worldDraw!=NULL)<BR> {<BR> AcGePoint3d insPt;<BR> AcGeVector3d normal(0,0,1),direction(1,0,0);<BR> double height,elev;<BR> char str;<BR> insPt=elevDim->getInsertPoint();<BR> acdbEcs2Wcs(asDblArray(insPt),asDblArray(insPt),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> height=elevDim->getHeight();<BR> elev=elevDim->getElevation();<BR> acdbRToS(elev,2,2,str);<BR> worldDraw->subEntityTraits().setSelectionMarker(5);<BR> worldDraw->geometry().text(insPt,normal,direction,height,0.8,0,str);<BR> }<BR> else<BR> {<BR> assert(Adesk::kFalse);<BR> }<BR> return es;<BR>}<BR>static Acad::ErrorStatus<BR>intLine(const CMyElevDim * elevDim,<BR> const AcGeLine3d line,<BR> AcGePoint3dArray& points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=elevDim->getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGeLineSeg3d tlnsg;<BR> AcGePoint3d pt;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> if(i==1)<BR> {<BR> tlnsg.set(vertexArray,vertexArray);<BR> }<BR> else<BR> {<BR> tlnsg.set(vertexArray,vertexArray);<BR> }<BR> if(!tlnsg.intersectWith(line,pt))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> points.append(pt);<BR> }<BR> }<BR> return es;<BR>}</P>
<P>static Acad::ErrorStatus<BR>intLine(const CMyElevDim * elevDim,<BR> const AcDbLine * line,<BR> AcDb::Intersect intType,<BR> const AcGePlane *projPlane,<BR> AcGePoint3dArray &points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGeLineSeg3d lnsg(line->startPoint(),line->endPoint());<BR> es=intLine(elevDim,lnsg,intType,projPlane,points);<BR> return es;<BR>}</P>
<P>static Acad::ErrorStatus<BR>intLine(const CMyElevDim * elevDim,<BR> const AcGeLineSeg3d lnsg,<BR> AcDb::Intersect intType,<BR> const AcGePlane *projPlane,<BR> AcGePoint3dArray &points<BR> )<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=elevDim->getVertices3d(vertexArray) )!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGeLine3d aline(lnsg.startPoint(),lnsg.endPoint());<BR> AcGeLineSeg3d tlnsg;<BR> AcGePoint3d pt;<BR> AcGePoint3d dummy;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> if(i==1)<BR> {<BR> tlnsg.set(vertexArray,vertexArray);<BR> }<BR> else<BR> {<BR> tlnsg.set(vertexArray,vertexArray);<BR> }<BR> if(intType==AcDb::kExtendArg||intType==AcDb::kExtendBoth)<BR> {<BR> if(projPlane==NULL)<BR> {<BR> if(!tlnsg.intersectWith(aline,pt))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> points.append(pt);<BR> }<BR> }<BR> else<BR> {<BR> if(!tlnsg.projIntersectWith(aline,projPlane->normal(),pt,dummy))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> points.append(pt);<BR> }<BR> }<BR> }<BR> else<BR> {<BR> if(projPlane==NULL)<BR> {<BR> if(!tlnsg.intersectWith(lnsg,pt))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> points.append(pt);<BR> }<BR> }<BR> else<BR> {<BR> if(!tlnsg.projIntersectWith(lnsg,projPlane->normal(),pt,dummy))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> points.append(pt);<BR> }<BR> }<BR> }<BR> }<BR> return es;<BR> <BR>}</P>
<P><BR>static Acad::ErrorStatus<BR>intArc(const CMyElevDim * elevDim,<BR> const AcDbArc * arc,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGeCircArc3d aarc(arc->center(),arc->normal(),<BR> arc->normal().perpVector(),arc->radius(),<BR> arc->startAngle(),arc->endAngle());<BR> es=intArc(elevDim,aarc,intType,projPlane,points);<BR> return es;<BR>}<BR>static Acad::ErrorStatus<BR>intArc(const CMyElevDim * elevDim,<BR> const AcGeCircArc3d arc,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=elevDim->getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGeCircArc3d acircle(arc.center(),arc.normal(),arc.radius());<BR> AcGeLineSeg3d lnsg;<BR> AcGePoint3d pt1,pt2;<BR> AcGePoint3d dummy1 ,dummy2;<BR> int howMany;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> if(i==1)<BR> {<BR> lnsg.set(vertexArray,vertexArray);<BR> }<BR> else<BR> {<BR> lnsg.set(vertexArray,vertexArray);<BR> }<BR> if(intType==AcDb::kExtendArg||intType==AcDb::kExtendBoth)<BR> {<BR> if(projPlane==NULL)<BR> {<BR> if(!acircle.intersectWith(lnsg,howMany,pt1,pt2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> else<BR> {<BR> if(!acircle.projIntersectWith(lnsg,projPlane->normal(),<BR> howMany,pt1,pt2,dummy1,dummy2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> }<BR> else<BR> {<BR> if(projPlane==NULL)<BR> {<BR> if(!arc.intersectWith(lnsg,howMany,pt1,pt2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> else<BR> {<BR> if(!arc.projIntersectWith(lnsg,projPlane->normal(),<BR> howMany,pt1,pt2,dummy1,dummy2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> }</P>
<P> }<BR> return es;<BR>}</P>
<P>static Acad::ErrorStatus<BR>intCircle(const CMyElevDim * elevDim,<BR> const AcDbCircle * circle,<BR> AcDb::Intersect intType,<BR> AcGePlane * projPlane,<BR> AcGePoint3dArray & points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGeCircArc3d acircle(circle->center(),circle->normal(),circle->radius());<BR> es=intCircle(elevDim,acircle,intType,projPlane,points);<BR> return es;<BR>}</P>
<P>static Acad::ErrorStatus<BR>intCircle(const CMyElevDim * elevDim,<BR> const AcDbCircle * circle,<BR> AcDb::Intersect intType,<BR> const AcGePlane * projPlane,<BR> AcGePoint3dArray & points)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcGePoint3dArray vertexArray;<BR> if((es=elevDim->getVertices3d(vertexArray))!=Acad::eOk)<BR> {<BR> return es;<BR> }<BR> AcGeLineSeg3d lnsg;<BR> AcGePoint3d pt1,pt2;<BR> AcGePoint3d dummy1,dummy2;<BR> int howMany;<BR> for(int i=0; i<vertexArray.length()-1; i++)<BR> {<BR> if(i==1)<BR> {<BR> lnsg.set(vertexArray,vertexArray);<BR> }<BR> else<BR> {<BR> lnsg.set(vertexArray,vertexArray);<BR> }<BR> if(projPlane==NULL)<BR> {<BR> if(!circle.intersectWith(lnsg,howMany,pt1,pt2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> else<BR> {<BR> if(!circle.projIntersectWith(lnsg,projPlane->normal(),<BR> howMany,pt1,pt2,dummy1,dummy2))<BR> {<BR> continue;<BR> }<BR> else<BR> {<BR> if(howMany>1)<BR> {<BR> points.append(pt1);<BR> points.append(pt2);<BR> }<BR> else<BR> {<BR> points.append(pt1);<BR> }<BR> }<BR> }<BR> }<BR> return es;<BR>}</P>
<P>Acad::ErrorStatus<BR>addToModelSpace(AcDbObjectId & objId,AcDbEntity *pEntity)<BR>{<BR> Acad::ErrorStatus es=Acad::eOk;<BR> AcDbBlockTable * pBlockTable;<BR> AcDbBlockTableRecord *pSpaceRecord;<BR> acdbHostApplicationServices()->workingDatabase()<BR> ->getSymbolTable(pBlockTable,AcDb::kForRead);<BR> pBlockTable->getAt(ACDB_MODEL_SPACE,pSpaceRecord,AcDb::kForWrite);<BR> pSpaceRecord->appendAcDbEntity(objId,pEntity);<BR> pBlockTable->close();<BR> pEntity->close();<BR> pSpaceRecord->close();<BR> return es;<BR>}</P>
<P>void elevDim()<BR>{<BR> ads_name ename;<BR> AcGePoint3d pt;<BR> if(acedEntSel("\nPick a line:",ename,asDblArray(pt))!=RTNORM)<BR> {<BR> acutPrintf("\nPick entity fail!");<BR> return;<BR> }<BR> AcDbObjectId objId;<BR> AcDbLine * pLine;<BR> acdbGetObjectId(objId,ename);<BR> if(acdbOpenAcDbEntity((AcDbEntity * &)pLine,<BR> objId,AcDb::kForRead)!=Acad::eOk)<BR> {<BR> return;<BR> }<BR> AcGePoint3d startPt,endPt;<BR> if(pLine!=NULL)<BR> {<BR> startPt=pLine->startPoint();<BR> endPt=pLine->endPoint();<BR> pLine->close();<BR> }<BR> else<BR> {<BR> return;<BR> }<BR> if(fabs(startPt.y-endPt.y)>1e-10)<BR> {<BR> acutPrintf("\nThe line must be horizontal!");<BR> return;<BR> }<BR> double height=10.0;<BR> double length=50.0;<BR> AcGePoint3d startPoint;<BR> if(acedGetPoint(NULL,"\nPlease input start point:",asDblArray(startPoint))!=RTNORM)<BR> {<BR> return;<BR> }<BR> startPoint.set(startPoint.x,startPt.y,startPoint.z);<BR> acdbWcs2Ecs(asDblArray(startPoint),asDblArray(startPoint),<BR> asDblArray(AcGeVector3d(0,0,1)),Adesk::kFalse);<BR> CMyElevDim * pDim=new CMyElevDim;<BR> if(pDim==NULL)<BR> {<BR> ads_printf("\nOut of memory");<BR> return;<BR> }<BR> pDim->set(startPoint,height,length);<BR> pDim->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase());<BR> if(addToModelSpace(objId,pDim)!=Acad::eOk)<BR> {<BR> delete pDim;<BR> }<BR> return ;</P>
<P>}</P>
<P><BR>void initApp()<BR>{<BR> acedRegCmds->addCommand("ASDK_CUSTOMENTITY_COMMANDS",<BR> "ELEVDIM",<BR> "ELEVDIM",<BR> ACRX_CMD_MODAL,<BR> elevDim);<BR> CMyElevDim::rxInit();<BR> acrxBuildClassHierarchy();<BR>}<BR>void unloadApp()<BR>{<BR> acedRegCmds->removeGroup("ASDK_CUSTOMENTITY_COMMANDS");<BR> deleteAcRxClass(CMyElevDim::desc());<BR>}</P>
<P>AcRx::AppRetCode<BR>acrxEntryPoint(AcRx::AppMsgCode msg,void *pkt)<BR>{<BR> switch(msg)<BR> {<BR> case AcRx::kInitAppMsg:<BR> acrxUnlockApplication(pkt);<BR> acrxRegisterAppMDIAware(pkt);<BR> initApp();<BR> break;<BR> case AcRx::kUnloadAppMsg:<BR> unloadApp();<BR> break;<BR> }<BR> return AcRx::kRetOK;<BR>}</P>