当前位置: > 博天堂官网 >

这一段在 AutoCAD 2009 版本下使用 BlockView 例程预览自定义实

这一段在 AutoCAD 2009 版本下使用 BlockView 例程预览自定义实体时,发现 worldDraw 函数的某些代码会导致程序崩溃。重现步骤如下:
1.从 AcDbEntity 派生一个自定义实体 CMyEntity。
2.实现 worldDraw 函数,代码如下:

Adesk::Boolean CMyEntity::worldDraw(AcGiWorldDraw* mode)
{
 AcGePoint3d startPnt = AcGePoint3d::kOrigin;
 AcGePoint3d endPnt = startPnt + AcGeVector3d::kXAxis * 200;
 AcGePoint3d dimPnt = (startPnt + endPnt.asVector() / 2.0) + AcGeVector3d::kYAxis * 10;
 AcGePoint3d position = (startPnt + endPnt.asVector() / 2.0);

 {
  AcDbRotatedDimension dimension(0, startPnt, endPnt, dimPnt);

  dimension.worldDraw(mode);
 }

 {
  AcDbText text(position, _T("hello"), AcDbObjectId::kNull, 20);

  text.setHorizontalMode(AcDb::kTextCenter);
  text.setVerticalMode(AcDb::kTextVertMid),博天堂娱乐航母;
  text.setAlignmentPoint(position);
  text.worldDraw(mode);
 } 

 return Adesk::kTrue;
}

3.修改 void CBlockViewDlg::OnAddtempentity() 函数(添加的代码为红色),如下:

void CBlockViewDlg::OnAddtempentity()
{
  AcGePoint3d startPoint (rand()/100,rand()/100,rand()/100);
  AcGePoint3d endPoint (rand()/100,rand()/100,rand()/100);
  // create a new line with random coords
  AcDbLine *line = new AcDbLine (startPoint, endPoint);
  line->setDatabaseDefaults();

  // 测试代码开始
  CMyEntity* pMyEnt = new CMyEntity;
  pMyEnt->setDatabaseDefaults();
  // 测试代码结束

  // if we created it ok
  if (line != NULL)
  {
    // add the newly created line to the AcGsView
    mPreviewCtrl.mpView->add (line, mPreviewCtrl.model());
    // next record the temporary entity so we can free it later
    mPreviewCtrl.addTempEntity(line);

    // 测试代码开始
    mPreviewCtrl.mpView->add (pMyEnt, mPreviewCtrl.model());
    mPreviewCtrl.addTempEntity(pMyEnt);
    // 测试代码结束

    // now zoom extents to show where it was drawn
    //store the temporary lines
    m_tempExt.addPoint(startPoint);
    m_tempExt.addPoint(endPoint);
    if (mCurrentDwg->extmin().distanceTo(mCurrentDwg->extmax()) < 1e20)
 ,博天堂娱乐航母;   {
  ,博天堂娱乐航母;    m_tempExt.addPoint(mCurrentDwg->extmin()); 
      m_tempExt.addPoint(mCurrentDwg->extmax()); 
    }
    AcDbExtents viewExtents(m_tempExt);
    viewExtents.transformBy(m_viewMatrix);
    mPreviewCtrl.mpView->zoomExtents(viewExtents.minPoint(),viewExtents.maxPoint());

    // update the gsView
    refreshView(mPreviewCtrl.mpView);

 mPreviewCtrl.SetFocus();
  }
}

4.在 AutoCAD 2009 中加载 BlockView 程序,单击 Add Temp Entity,程序崩溃。

奇怪的是如果在 worldDraw 中将 AcDbRotatedDimension、AcDbText 实体的相关代码放在一起,则不会崩溃,代码如下:

Adesk::Boolean CMyEntity::worldDraw(AcGiWorldDraw* mode)
{
 AcGePoint3d startPnt = AcGePoint3d::kOrigin;
 AcGePoint3d endPnt = startPnt + AcGeVector3d::kXAxis * 200;
 AcGePoint3d dimPnt = (startPnt + endPnt.asVector() / 2.0) + AcGeVector3d::kYAxis * 10;
 AcGePoint3d position = (startPnt + endPnt.asVector() / 2.0);

 AcDbRotatedDimension dimension(0, startPnt, endPnt, dimPnt);

 dimension.worldDraw(mode);

 AcDbText text(position, _T("hello"), AcDbObjectId::kNull, 20);

 text.setHorizontalMode(AcDb::kTextCenter);
 text.setVerticalMode(AcDb::kTextVertMid);
 text.setAlignmentPoint(position);
 text.worldDraw(mode);

 return Adesk::kTrue;
}

后来经过测试发现,这个问题仅在 AutoCAD 2009 下出现,2002、2004、2005、2006、2007、2008、2010 均不会出现。

博天堂娱乐航母 | 博天堂娱乐航母 | 博天堂官网 | 博天堂官方网站 | www.918.com | 

返回顶部