乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 11|回复: 0

[ARX]

[复制链接]

9

主题

13

帖子

4

银币

初来乍到

Rank: 1

铜币
49
发表于 2006-3-20 23:21:00 | 显示全部楼层 |阅读模式
本人刚在学习ObjectARX,出现如下问题望各位看看:
1:在AcDbEntity派生类中定义了getGripPoints()函数,但在CAD中看不到夹点,
是何原因(下附原程序).
2:在worldDraw()函数中采用AcDbText *pText=new AcDbText()与
mode->geometry().text()定义实体有何区别.
类定义:
class DLLIMPEXP dingteClass : public AcDbCurve
{
public:
ACRX_DECLARE_MEMBERS(dingteClass);
// Constructor / Destructor
dingteClass();
virtual ~dingteClass();
//{{AFX_ARX_METHODS(dingteClass)
virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler) const;
virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* pFiler);
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
virtual Acad::ErrorStatus getStartPoint(AcGePoint3d& x0) const;
virtual Acad::ErrorStatus getEndPoint(AcGePoint3d& x0) const;
virtual Acad::ErrorStatus getGripPoints(AcGePoint3dArray& gripPoints,
                                         AcDbIntArray& osnapModes,
                                         AcDbIntArray& geomIds) const;
virtual Acad::ErrorStatus moveGripPointsAt(const AcDbIntArray& indices,
                                            const AcGeVector3d& offset);

virtual Acad::ErrorStatus transformBy(const AcGeMatrix3d& xform);
virtual Adesk::Boolean worldDraw(AcGiWorldDraw* mode);
//}}AFX_ARX_METHODS

//{{AFX_ARX_DATA_ACCESS(dingteClass)
Acad::ErrorStatus setEntPoint(const AcGePoint3d entPoint);
Acad::ErrorStatus entPoint(AcGePoint3d& entPoint);
Acad::ErrorStatus setStartPoint(const AcGePoint3d startPoint);
Acad::ErrorStatus startPoint(AcGePoint3d& startPoint);
//}}AFX_ARX_DATA_ACCESS

private:
//{{AFX_ARX_DATA(dingteClass)
AcGePoint3d m_entPoint;
AcGePoint3d m_startPoint;
//}}AFX_ARX_DATA

private:
void *operator new[](unsigned nSize) { return 0; }
void operator delete[](void *p) {};
void *operator new[](unsigned nSize, const char *file, int line) { return 0; }
};
类实现:
Adesk::Boolean dingteClass::worldDraw(AcGiWorldDraw* mode)
{
assertReadEnabled();
// TODO: implement this function.
//AcGePoint3d startPoint,entPoint;
    //this->startPoint(startPoint);
    //this->entPoint(entPoint);
//AcGeVector3d normal(0.0, 0.0, 1.0);
//AcGeVector3d direction=m_startPoint-m_entPoint;
    //mode->geometry().text(m_startPoint,normal,direction,5,0.8,0,"toolTe");
//AcGePoint3d *pVerts=new AcGePoint3d[2];
    //pVerts[0]=m_startPoint;
    //pVerts[1]=m_entPoint;
//mode->geometry().polyline(2,pVerts);
AcDbText *pText=new AcDbText();
pText->setTextString("Hello");
pText->setPosition(m_startPoint);
pText->setHeight(5.0);
pText->worldDraw(mode);
AcDbLine *line;
line=new AcDbLine(m_startPoint,m_entPoint);
    line->worldDraw(mode);
return AcDbEntity::worldDraw(mode);
}
Acad::ErrorStatus dingteClass::startPoint(AcGePoint3d& startPoint)
{
assertReadEnabled();
startPoint = m_startPoint;
return Acad::eOk;
}
Acad::ErrorStatus dingteClass::setStartPoint(const AcGePoint3d startPoint)
{
assertWriteEnabled();
m_startPoint = startPoint;
return Acad::eOk;
}
Acad::ErrorStatus dingteClass::entPoint(AcGePoint3d& entPoint)
{
assertReadEnabled();
entPoint = m_entPoint;
return Acad::eOk;
}
Acad::ErrorStatus dingteClass::setEntPoint(const AcGePoint3d entPoint)
{
assertWriteEnabled();
m_entPoint = entPoint;
return Acad::eOk;
}

Acad::ErrorStatus dingteClass::transformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
// TODO: implement this function.
m_startPoint.transformBy(xform);
m_entPoint.transformBy(xform);
return AcDbEntity::transformBy(xform);
}

Acad::ErrorStatus dingteClass::moveGripPointsAt(const AcDbIntArray& indices,
                                                const AcGeVector3d& offset)
{
assertWriteEnabled();
// TODO: implement this function.
dingteClass* te=new dingteClass();
    AcGePoint3d entPoint,startPoint;
te->getEndPoint(entPoint);
te->getStartPoint(startPoint);
startPoint +=offset;
entPoint +=offset;
te->setEntPoint(entPoint);
te->setStartPoint(startPoint);
return AcDbEntity::moveGripPointsAt(indices, offset);
}
Acad::ErrorStatus dingteClass::getGripPoints(AcGePoint3dArray& gripPoints,
                                             AcDbIntArray& osnapModes,
                                             AcDbIntArray& geomIds) const
{
assertReadEnabled();
// TODO: implement this function.
AcGePoint3d entPoint,startPoint;
AcGeVector3d normal(0.0, 0.0, 1.0);   
startPoint=m_startPoint;
entPoint=m_entPoint;
acdbEcs2Wcs(asDblArray(startPoint),
  asDblArray(startPoint),asDblArray(normal),Adesk::kFalse);
acdbEcs2Wcs(asDblArray(entPoint),
  asDblArray(entPoint),asDblArray(normal),Adesk::kFalse);
gripPoints.append(startPoint);
gripPoints.append(entPoint);

return AcDbEntity::getGripPoints(gripPoints, osnapModes, geomIds);
}
Acad::ErrorStatus dingteClass::getEndPoint(AcGePoint3d& x0) const
{
assertReadEnabled();
// TODO: implement this function.
x0=m_entPoint;
return AcDbCurve::getEndPoint(x0);
}
Acad::ErrorStatus dingteClass::getStartPoint(AcGePoint3d& x0) const
{
assertReadEnabled();
// TODO: implement this function.
x0=m_startPoint;
return AcDbCurve::getStartPoint(x0);
}
Acad::ErrorStatus dingteClass::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es;
// Call dwgInFields from AcDbCurve
if ((es = AcDbCurve::dwgInFields(pFiler)) != Acad::eOk) {
  return es;
}
// Read version number.
Adesk::UInt16 version;
pFiler->readItem(&version);
if (version > VERSION_DINGTECLASS)
  return Acad::eMakeMeProxy;
// Read the data members.
switch (version)
{
case (1):
  pFiler->readItem(&m_startPoint);
  pFiler->readItem(&m_entPoint);
  // TODO: here you can file datamembers not
  //       created by the ObjectARX Add-In.
  break;
}

return pFiler->filerStatus();
}
Acad::ErrorStatus dingteClass::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es;
// Call dwgOutFields from AcDbCurve
if ((es = AcDbCurve::dwgOutFields(pFiler)) != Acad::eOk) {
  return es;
}
// Write version number.
pFiler->writeItem((Adesk::UInt16) VERSION_DINGTECLASS);
// Write the data members.
pFiler->writeItem(m_startPoint);
pFiler->writeItem(m_entPoint);
// TODO: here you can file datamembers not
//       created by the ObjectARX Add-In.

return pFiler->filerStatus();
}
Acad::ErrorStatus dingteClass::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
struct resbuf rb;
if ((AcDbCurve::dxfInFields(pFiler) != Acad::eOk) ||
     !pFiler->atSubclassData("dingteClass"))
  return pFiler->filerStatus();
// Read version number.
pFiler->readItem(&rb);
if (rb.restype != AcDb::kDxfInt16) {
  pFiler->pushBackItem();
  pFiler->setError(Acad::eInvalidDxfCode,
                  "nError: expected object version group code %d",
                   AcDb::kDxfInt16);
  return pFiler->filerStatus();
} else {
  Adesk::UInt16 version = rb.resval.rint;
  if (version > VERSION_DINGTECLASS)
   return Acad::eMakeMeProxy;
}
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfXCoord) {
  m_startPoint = asPnt3d(rb.resval.rpoint);
} else {
  pFiler->pushBackItem();
  pFiler->setError(Acad::eInvalidDxfCode,
                  "nError: expected group code %d",
                  AcDb::kDxfXCoord);
  return pFiler->filerStatus();
}
pFiler->readItem(&rb);
if (rb.restype == AcDb::kDxfXCoord + 1) {
  m_entPoint = asPnt3d(rb.resval.rpoint);
} else {
  pFiler->pushBackItem();
  pFiler->setError(Acad::eInvalidDxfCode,
                  "nError: expected group code %d",
                  AcDb::kDxfXCoord + 1);
  return pFiler->filerStatus();
}
// TODO: here you can file datamembers not
//       created by the ObjectARX Add-In.
return pFiler->filerStatus();
}
Acad::ErrorStatus dingteClass::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es;
if ((es = AcDbCurve::dxfOutFields(pFiler)) != Acad::eOk)
  return es;
// Write subclass marker.
pFiler->writeItem(AcDb::kDxfSubclass, "dingteClass");
// Write version number.
pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16) VERSION_DINGTECLASS);
pFiler->writeItem(AcDb::kDxfXCoord, m_startPoint);
pFiler->writeItem(AcDb::kDxfXCoord + 1, m_entPoint);
// TODO: here you can file datamembers not
//       created by the ObjectARX Add-In.
return es;
}
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 16:41 , Processed in 0.151186 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表