- 积分
- 55
- 明经币
- 个
- 注册时间
- 2010-11-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 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::Boolean update(); 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[m_Points.length() - 1]);
// }
stat = acquirePoint(CurPoint); //判断鼠标是否移动
if (stat == AcEdJig::kNormal)
{
if (m_CurPoint.distanceTo(CurPoint) < 1e-6)
{
return AcEdJig::kNoChange;
}
else m_CurPoint = CurPoint;
}
return stat;
} //***************更新实体绘图*************************************
Adesk::Boolean CDrawESL_Jig::update()
{
/*AcDbObjectId EntId;*/
ads_point basePt, resultPt, RefPt; RefPt[X] = m_CurPoint.x;
RefPt[Y] = m_CurPoint.y;
RefPt[Z] = m_CurPoint.z; ads_printf("\n点数:%d", m_Points.length());
if (m_Points.length() == 0)
{
return Adesk::kTrue;
}
else
{
basePt[X] = m_Points[m_Points.length() - 1].x;
basePt[Y] = m_Points[m_Points.length() - 1].y;
basePt[Z] = m_Points[m_Points.length() - 1].z; double rAngle = ads_angle(basePt, RefPt);
ads_polar(basePt, rAngle, m_rESLLength, resultPt);
m_CurPoint = AcGePoint3d(resultPt[X], resultPt[Y], resultPt[Z]);
m_pPLine->setPointAt(m_Points.length(), AcGePoint2d(resultPt[X], resultPt[Y]));
} 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请高手帮我看一下错在什么地方。附件中是我建立的工程 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|