- UID
- 737382
- 积分
- 386
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2014-9-13
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
各位大师,我看了帮助文档里面的例子,这个实在搞不懂,这里的addDimData,setDimValue干啥用的,有啥效果,哪位大师帮看下
extern int gCircleDynDimSetting;
AcCircleJig::AcCircleJig(AcDbDatabase *pDb,
AcCircle *pCircle):
mpCircle(pCircle),
mpdb(pDb)
{
mElevation = 0.0;
mNormal.set(0,0,1);
mpDimDataArray = new AcDbDimDataPtrArray;
mpDimDataArray->setLogicalLength(0);
}
AcCircleJig::~AcCircleJig()
{
if (mpDimDataArray)
{
for (int i = 0; i < mpDimDataArray->length(); i++)
{
AcDbDimData *pData = (*mpDimDataArray)[i];
delete pData;
}
delete mpDimDataArray;
}
}
Acad::ErrorStatus
AcCircleJig::setPlane()
{
// Acquire current UCS transformation matrix.
// We save the matrix for later use.
//
acdbUcsMatrix(mUcsToWcsMat);
mWcsToUcsMat = mUcsToWcsMat.inverse();
// Get data from user coordinate system.
//
AcGePoint3d orgPt;
AcGeVector3d xAxis, yAxis, zAxis;
mUcsToWcsMat.getCoordSystem(orgPt, xAxis, yAxis, zAxis);
// Get the current elevation w.r.t current UCS, w.r.t the current space.
//
struct resbuf rb;
ads_getvar(/*MSG0*/"CVPORT", &rb);
double elev;
if (rb.resval.rint == 1)
elev = mpdb->pelevation(); // Paper space
else
elev = mpdb->elevation(); // Model space
// Convert elevation from UCS to WCS.
//
orgPt += elev * zAxis;
mElevation = zAxis.dotProduct(orgPt.asVector());
mNormal = zAxis;
mHorizDir = xAxis;
return Acad::eOk;
}
//Purpose: This is the fist function that that command is
// expected to call. This would call the other drag()
// method classes.
void
AcCircleJig::dragIt(void)
{
AcEdJig::DragStatus stat;
const TCHAR* pszPrompt = _T("Enter the center for the Circle");
setDispPrompt(pszPrompt);
stat =acquireDefPt();
setCircleProperties();
do
{
const TCHAR*pszPrompt2 = _T("Enter the Radius point for the circle");
setDispPrompt(pszPrompt2);
addDimData();
stat = drag();
} while (stat != AcEdJig::kNormal && stat != AcEdJig::kCancel &&
stat != AcEdJig::kNull);
if (stat == AcEdJig::kNormal)
append();
}
AcEdJig::DragStatus
AcCircleJig::acquireDefPt()
{
DragStatus stat;
setUserInputControls( (UserInputControls)
(AcEdJig::kAccept3dCoordinates |
AcEdJig::kNoNegativeResponseAccepted)
);
AcGePoint3d pt;
stat =acquirePoint(pt);
if(mCenterPt != pt)
mCenterPt=pt;
if(stat == AcEdJig::kNormal )
return AcEdJig::kNoChange;
else
return stat;
}
AcEdJig::DragStatus
AcCircleJig::sampler(void)
{
DragStatus stat;
setUserInputControls((UserInputControls)
(AcEdJig::kAccept3dCoordinates
| AcEdJig::kGovernedByOrthoMode
| AcEdJig::kAcceptOtherInputString
| AcEdJig::kNoNegativeResponseAccepted
| AcEdJig::kNullResponseAccepted
| AcEdJig::kNoZeroResponseAccepted));
AcGePoint3d pnt;
stat = acquirePoint(pnt);
if (stat == kNormal) {
if (pnt == mRadVec){
return AcEdJig::kNoChange;
}
else{
mRadVec = pnt;
}
}
return stat;
}
Adesk::Boolean
AcCircleJig::update()
{
AcGeVector3d radVec = mRadVec - mCenterPt;
double radius = radVec.length();
mpCircle->setRadius(radius);
//update the Dynamic Dimension
updateDimension();
return Adesk::kTrue;
}
void
AcCircleJig::setCircleProperties()
{
mpCircle->setDatabaseDefaults();
mpCircle->setCenter(mCenterPt);
mpCircle->setNormal(mNormal);
}
bool
AcCircleJig::updateDimension()
{
if (!mpCircle || !mpDimDataArray ||
(mpDimDataArray->length() <= 0))
return false;
double radius = mpCircle->radius();
AcGePoint3d cenPt = mpCircle->Center();
AcGeVector3d radVec = mRadVec - cenPt;
if (!radVec.isZeroLength())
{
radVec.normalize();
radVec = radius * radVec;
}
AcGePoint3d chordPt = cenPt + radVec;
AcGePoint3d farChordPt = cenPt - radVec;
for (int i = 0; i < mpDimDataArray->length(); i++)
{
AcDbDimData *pData = (*mpDimDataArray)[i];
int iAppData = *( static_cast<int *>(pData->appData()) );
AcDbDimension *pDim = (AcDbDimension*)pData->dimension();
AcDbAlignedDimension *pAlnDim = AcDbAlignedDimension::cast(pDim);
if (pAlnDim == NULL)
continue;
pAlnDim->setXLine1Point(cenPt);
pAlnDim->setXLine2Point(chordPt);
pAlnDim->setDimLinePoint(chordPt);
}
return true;
}
AcDbDimDataPtrArray*
AcCircleJig::dimData(const double dimScale)
{
return mpDimDataArray;
}
Acad::ErrorStatus
AcCircleJig::setDimValue(const AcDbDimData *pdimData,
const double dimValue)
{
mpCircle->setRadius(dimValue);
return Acad::eOk;
}
bool
AcCircleJig::addDimData()
{
if (mpCircle == NULL)
return false;
if (mpDimDataArray == NULL) {
mpDimDataArray = new AcDbDimDataPtrArray();
} else {
for (int i = 0; i < mpDimDataArray->length(); i++) {
AcDbDimData *pData = (*mpDimDataArray)[i];
delete pData;
}
mpDimDataArray->setLogicalLength(0);
}
double radius = mpCircle->radius();
AcGePoint3d cenPt = mpCircle->Center();
AcGeVector3d normal = mpCircle->normal();
AcGeVector3d vertDir = normal.crossProduct(mHorizDir);
AcDbAlignedDimension *pAlnDim1 = new AcDbAlignedDimension();
pAlnDim1->setDatabaseDefaults();
pAlnDim1->setNormal(normal);
pAlnDim1->setElevation(mElevation);
pAlnDim1->setDimsah(true);
pAlnDim1->setDimse1(true);
pAlnDim1->setDimblk1(_T("None"));
pAlnDim1->setXLine1Point(mCenterPt);
pAlnDim1->setXLine2Point(mRadVec);
pAlnDim1->setDimLinePoint(mRadVec);
AcDbDimData *dimData1 = new AcDbDimData(pAlnDim1);
int DimIndex(1);
dimData1->setAppData(&DimIndex);
// check what the setting is for this dimension
// this is configured using the SETDYNDIMMODES command
getDynDimSettings(dimData1, (AcDbDimData::DimDataFlags)gCircleDynDimSetting);
mpDimDataArray->append(dimData1);
return true;
}
|
|