服務(wù)熱線
0755-26825352
首先我們要修改enttemp.h文件:
原文件如下:
class EntTemperature : public AcRxObject
{
public:
ACRX_DECLARE_MEMBERS(EntTemperature);
virtual double reflectedEnergy(AcDbEntity* pEnt) const = 0;
};
將斜體部分修改成如下:
virtual Adesk::Boolean HgyModify(AcDbEntity* pEnt)
const = 0;
因?yàn)槲覀円院笠訣ntTemperature作為基類,而且HgyModify函數(shù)在繼承類中要重寫并要求實(shí)現(xiàn)動(dòng)態(tài)調(diào)用,故此處必須聲明為虛擬函數(shù)。Virtual關(guān)健字即為C++面向?qū)ο蟮闹匾奶匦浴?/p>
第二、刪除tempapp.def文件中的energy文本。
第三、修改tempapp.cpp文件:
1、 刪除CircleTemperature、RigonTemperature及EllipseTemperature類的所有相關(guān)內(nèi)容。
2、 修改原文件中如下的內(nèi)容:
class DefaultTemperature : public EntTemperature
{
public:
virtual double reflectedEnergy(AcDbEntity* pEnt) const;
};
double DefaultTemperature::reflectedEnergy
(AcDbEntity* pEnt) const
{
ads_printf(" This entity has no area, and no reflection. ");
return -1.0;
}
修改后的內(nèi)容如下:
class DefaultTemperature : public EntTemperature
{
public:
virtual Adesk::Boolean HgyModify(AcDbEntity* pEnt) const;
};
Adesk::Boolean DefaultTemperature::
HgyModify(AcDbEntity* pEnt) const
{
ads_printf(" The entity hasn't defined,
and nothing to be modified. ");
return Acad::eOk;
}
為簡(jiǎn)單起見,我們只對(duì)直線和圓定義超級(jí)編輯命令,
在此定義有關(guān)line和circle類。在tempapp.cpp
文件中增加CircleTemperature和LineTemperature類,
定義如下:
class CircleTemperature : public EntTemperature
{
public:
virtual Adesk::Boolean HgyModify(AcDbEntity* pEnt) const;
};
Adesk::Boolean
CircleTemperature::HgyModify(AcDbEntity* pEnt) const
{
AcDbCircle *pCircle = AcDbCircle::cast(pEnt);
if (!pCircle) {
ads_printf("The entity selected is not a circle ");
pEnt- >close();
return Acad::eNotImplementedYet;
}
AcGePoint3d p,q;
double r;
p=P_TO_P(pCircle- >center());
if (getPoint((double*)(&p), "Center Point: ", p)== RTNORM
&& ads_getdist((double*)(&p), "Blob radius: ", &r) == RTNORM)
{
pCircle- >setCenter(p);
pCircle- >setRadius(r);
pCircle- >close();
}
return Acad::eOk;
}
class LineTemperature : public EntTemperature
{
public:
virtual Adesk::Boolean HgyModify(AcDbEntity* pEnt) const;
};
Adesk::Boolean
LineTemperature::HgyModify(AcDbEntity* pEnt) const
{
AcDbLine *pLine = AcDbLine::cast(pEnt);
if (!pLine) {
ads_printf("The entity selected is not a line. ");
pEnt- >close();
return eNotImplementedYet;
}
AcGePoint3d p,q;
p= P_TO_P (pLine- >startPoint());
if (getPoint ((double*)(&p), "From Point: ", p)== RTNORM
&& getPoint((double*)(&p), "To point: ", q) == RTNORM)
{
pLine- >setStartPoint(p);
pLine- >setEndPoint(q);
pLine- >close();
}
return Acad::eOk;
}
如您所見,HgyModify函數(shù)也要完全重寫。至此我們對(duì)CircleTemperature和LineTemperature的定義已經(jīng)完成。上面P_TO_P()只是一個(gè)點(diǎn)對(duì)點(diǎn)賦值,getPoint()是自定義的取點(diǎn)函數(shù)。增加全局變量:這樣我們?cè)诔跏蓟蚯宄齼?nèi)存過程中可以存取該類。
LineTemperature *pLineTemp;
CircleTemperature *pCircleTemp;
InitApp()函數(shù)中更改部分:
acedRegCmds- >addCommand("TEMPERATURE_APP",
"MODIFY", "MODIFY",
ACRX_CMD_TRANSPARENT, printEnergy);
更改程序中別的函數(shù)中的相應(yīng)的部分。
注意printEnergy()函數(shù)中selectEntity()
函數(shù)的第二個(gè)參數(shù)必須是AcDb::kForWrite;
編譯后在AutoCAD(如R14)中測(cè)試運(yùn)行,敲入modify后隨便選取直線或圓,您就會(huì)能體會(huì)到超級(jí)編輯命令的方便之處?;蛟S您會(huì)認(rèn)為此命令沒有什么特別之處,但若您仔細(xì)研究lab10子目錄中的內(nèi)容,定義自己的實(shí)體如門、窗或機(jī)械特征,特別是您自己才會(huì)用到的特殊對(duì)象,給對(duì)象增加此命令,您就會(huì)體會(huì)到ARX編程的魅力了。#p#分頁標(biāo)題#e#