gyboyzfm 发表于 2010-11-29 11:41:11

求助bojectarx高手关于jig类画固定长度的多段线

本帖最后由 gyboyzfm 于 2010-11-29 11:43 编辑

jig头文件:class CDrawESL_Jig : public AcEdJig
{
public:
CDrawESL_Jig();
CDrawESL_Jig(AcDbPolyline *pPLine);
virtual ~CDrawESL_Jig();

//设置匀坡线长度
void SetLength(double rLength){ m_rESLLength = rLength;} //开始拖动
DragStatus StartDrag(); //获取点坐标数组
void GetPoints(AcGePoint3dArray & arPoints) const; //采样函数
    virtual DragStatus sampler();//更新实体绘图
    virtual Adesk::Booleanupdate();    virtual AcDbEntity* entity() const{return m_pPLine;}
private:
//匀坡线长度
double m_rESLLength;
AcDbPolyline *m_pPLine;
AcGePoint3d m_CurPoint;
AcGePoint3dArray m_Points;

};jig类的代码:CDrawESL_Jig::CDrawESL_Jig()
{
m_pPLine = new AcDbPolyline(); m_rESLLength = 10;
}CDrawESL_Jig::CDrawESL_Jig(AcDbPolyline *pPLine)
{
m_pPLine = pPLine; //从AcDbPolyline *实体中提取点坐标, 写入m_Points
int i;
AcGePoint3d GPt;
for (i = 0; i < m_pPLine->numVerts(); i++)
{
m_pPLine->getPointAt(i, GPt);
m_Points.append(GPt);
}
// m_Points.append(AcGePoint3d(0.0,0.0,0.0));
}CDrawESL_Jig::~CDrawESL_Jig()
{
if (m_pPLine != NULL) delete m_pPLine;
m_pPLine = NULL;
}//获取点坐标数组
void CDrawESL_Jig::GetPoints(AcGePoint3dArray & arPoints) const
{
while (arPoints.length() != 0)
arPoints.removeFirst(); arPoints.append(m_Points); return;
}//***************开始拖动***************
AcEdJig::DragStatus CDrawESL_Jig::StartDrag()
{
if (m_Points.length() == 0)
{
setDispPrompt(_T("\n请指定第一个点:"));
}
else
{
setDispPrompt(_T("\n请指定下一个点:"));
} AcEdJig::DragStatus Sta = drag();
if (Sta == AcEdJig::kNormal)
{
m_Points.append(m_CurPoint);

}
return Sta;
}//***************采样函数***************
AcEdJig::DragStatus CDrawESL_Jig::sampler()
{
setUserInputControls( ( UserInputControls )
      ( kNullResponseAccepted | kAccept3dCoordinates | //kGovernedByOrthoMode|
kDontUpdateLastPoint | kNoZeroResponseAccepted));
DragStatus stat;

AcGePoint3d CurPoint;//if (m_Points.length() == 0)
//   stat = acquirePoint(CurPoint);
//else
//{
//stat = acquirePoint(CurPoint, m_Points);
//   }
stat = acquirePoint(CurPoint); //判断鼠标是否移动
if (stat == AcEdJig::kNormal)
{
if (m_CurPoint.distanceTo(CurPoint) < 1e-6)
{
   return AcEdJig::kNoChange;
}
else m_CurPoint = CurPoint;

}
return stat;
} //***************更新实体绘图*************************************
Adesk::BooleanCDrawESL_Jig::update()
{
/*AcDbObjectId EntId;*/
ads_point basePt, resultPt, RefPt; RefPt = m_CurPoint.x;
RefPt = m_CurPoint.y;
RefPt = m_CurPoint.z; ads_printf("\n点数:%d", m_Points.length());
if (m_Points.length() == 0)
{
return Adesk::kTrue;
}
else
{
basePt = m_Points.x;
basePt = m_Points.y;
basePt = m_Points.z;double rAngle = ads_angle(basePt, RefPt);
ads_polar(basePt, rAngle, m_rESLLength, resultPt);
m_CurPoint = AcGePoint3d(resultPt, resultPt, resultPt);
m_pPLine->setPointAt(m_Points.length(), AcGePoint2d(resultPt, resultPt));
} return Adesk::kTrue;
}
绘制图像的函数代码://消息处理函数---绘制按钮
void CDialog_DrawESL::OnButtonDraw()
{
// TODO: Add your control notification handler code here
BeginEditorCommand(); int i;
CDrawESL_Jig *pPLineJig = NULL;
AcEdJig::DragStatus ds;

AcDbObjectId EntId; do {
// pPline = NULL;
AcDbPolyline *pPline = NULL;if (pPLineJig == NULL)
{
   pPLineJig = new CDrawESL_Jig();
   pPLineJig->SetLength(m_rESLLength);
}
else
{
   AcGePoint3dArray arPoints;
   pPLineJig->GetPoints(arPoints);

   if (pPline != NULL) delete pPline;
   pPline = new AcDbPolyline(arPoints.length());   for (i = 0; i < arPoints.length(); i++)
   {
    pPline->addVertexAt(i, AcGePoint2d(arPoints.x, arPoints.y));
   }
   delete pPLineJig;
   pPLineJig = new CDrawESL_Jig(pPline);
   pPLineJig->SetLength(m_rESLLength);
}
ds = pPLineJig->StartDrag();
ads_printf("\nDragStatus = %d", ds);

if (ds != AcEdJig::kNormal)
{
   CompleteEditorCommand();
   delete pPLineJig;
   return;
}
}while (ds != AcEdJig::kCancel); delete pPLineJig; CompleteEditorCommand();
} 其中多段线的长度是由一个编辑框传入的数值。可是这个程序最后我发现不知道怎么把画出的多段线添加进数据库,无法显示出来。而且我想要的效果是鼠标点一个点,拖动的虚拟线并不是到鼠标当前点,只是到我求出来的resultPt请高手帮我看一下错在什么地方。附件中是我建立的工程
页: [1]
查看完整版本: 求助bojectarx高手关于jig类画固定长度的多段线