明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1984|回复: 0

紧急求救:关于AcDbEntity派生类无法实现夹点问题

[复制链接]
发表于 2006-3-20 23:23: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;
}

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

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 01:23 , Processed in 0.170913 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表