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