2020-10-16

项目场景:

提示:Jig配合acedGrread实现捕捉与坐标获取:
例如:acedGrread配合Jig在动态拖动中捕捉点并获取坐标


问题描述:

提示:基础的acedGrread在鼠标移动过程中没有捕捉功能,仅仅可获得鼠标信息,不能进行特殊点捕捉:
例如:基础的acedGrread在鼠标移动过程中没有捕捉功能,仅仅可获得鼠标信息,不能进行特殊点捕捉:

@Override public void run() { bytes = mmInStream.read(buffer); mHandler.obtainMessage(READ_DATA, bytes, -1, buffer).sendToTarget(); } 

原因分析:

提示:acedGrread是鼠标的响应,过程占用,有点模式状态的感觉:
例如:acedGrread是鼠标的响应,过程占用,有点模式状态的感觉,这种状态下,CAD的捕捉将失效。


解决方案:

提示:采用JIG:
例如:采用JIG的方式来进行捕捉,配合acedGrread来获得鼠标信息,可以很完美的解决问题。

以下上源码:

#pragma once
#include <dbjig.h>
class CDrawXPXJig :
    public AcEdJig
{
public:
    CDrawXPXJig();
    virtual ~CDrawXPXJig();
    //外部调用的函数,一般用于Jig的初始化
    bool doIt(const AcGePoint3d &centerPoint, AcDbObjectId& polyId, AcGePoint3d SPoint, AcGePoint3d EPoint);
    //此函数将被drag函数调用以获得用户输入
    virtual AcEdJig::DragStatus sampler();
    //对需要在拖动过程中发生变化的实体进行修改
    virtual Adesk::Boolean update();
    //指定了Jig所操作的对象
    virtual AcDbEntity* entity() const;
    AcGePoint2d ToPoint2d(const AcGePoint3d &point3d);
    void Erase(AcDbObjectId entId);
    void SetColor(AcDbObjectId entId, int colorIndex);
private:

    AcDbPolyline* m_pPoly; //拖动过程中动态变化的实体
    AcGePoint3d m_curPoint;  //储存用户光标移动时临时点的临时位置
    AcGePoint3d m_centerPoint; //正方形的中心点
};

 

#include "stdafx.h"
#include "CDrawXPXJig.h"
#include "BAS_DRAW_FUN1.h"
BAS_DRAW_FUN ob;
CDrawXPXJig::CDrawXPXJig()
{
    m_pPoly = NULL;
}


CDrawXPXJig::~CDrawXPXJig()
{
}
void CDrawXPXJig::SetColor(AcDbObjectId entId, int colorIndex)
{
    // 检测参数的有效性
    assert(colorIndex >= 0 && colorIndex <= 256);
    AcDbEntity *pEnt = NULL;
    if (acdbOpenObject(pEnt, entId, AcDb::kForWrite) == Acad::eOk)
    {
        pEnt->setColorIndex(colorIndex);
        pEnt->close();
    }
}

bool CDrawXPXJig::doIt(const AcGePoint3d &centerPoint,AcDbObjectId &polyId, AcGePoint3d SPoint, AcGePoint3d EPoint)
{
    m_centerPoint = centerPoint;
    //拖动之前:将多段线创建出来
    m_pPoly = new AcDbPolyline();
    m_pPoly->addVertexAt(0, ToPoint2d(SPoint));
    m_pPoly->addVertexAt(1, ToPoint2d(centerPoint));
    m_pPoly->addVertexAt(2, ToPoint2d(EPoint));

    
    //进入拖动流程
    
    AcEdJig::DragStatus stat = drag();
    //拖动结束:函数返回部分
    if (stat == kNormal)
    {
        polyId = ob.AddEntityToDbs(m_pPoly);
        return true;
    }
    else
    {
        delete m_pPoly;
        return false;
    }
}

AcGePoint2d CDrawXPXJig::ToPoint2d(const AcGePoint3d &point3d)
{
    return AcGePoint2d(point3d.x, point3d.y);
}

//此函数将被drag函数调用以获得用户输入

AcEdJig::DragStatus CDrawXPXJig::sampler()
{
    setUserInputControls((UserInputControls)
        (/*AcEdJig::kAccept3dCoordinates|*/ AcEdJig::kNoNegativeResponseAccepted| AcEdJig::kNullResponseAccepted));
    //一定要判断一下点是否发生了变化,否则update函数不停地被调用,实体反而不能被绘制出来
    static AcGePoint3d pointTemp;
    DragStatus stat = acquirePoint(m_curPoint);
    if (pointTemp != m_curPoint)
    {
        pointTemp = m_curPoint;
    }
    else if (stat == AcEdJig::kNormal)
    {
        return AcEdJig::kNoChange;
    }
    return stat;
}

Adesk::Boolean CDrawXPXJig::update()
{
    //实现你的更新操作,在这里更新的是m_pPoly
    double dist = ToPoint2d(m_centerPoint).distanceTo(ToPoint2d(m_curPoint));
    m_pPoly->setPointAt(1, ToPoint2d(m_curPoint));
    /*for (int i = 0; i < 4; i++)
    {
        double angle = i * PI* 0.5 + PI*0.25;
        AcGePoint2d pt = PolarPoint(ToPoint2d(m_centerPoint), angle, dist);
        m_pPoly->setPointAt(i, pt);
    }*/
    return Adesk::kTrue;
}

//指定了Jig所操作的对象
AcDbEntity* CDrawXPXJig::entity() const
{
    return m_pPoly;
}

void CDrawXPXJig::Erase(AcDbObjectId entId)

{
    AcDbEntity *pEnt = NULL;
    if (acdbOpenObject(pEnt, entId, AcDb::kForWrite) == Acad::eOk)
    {
        pEnt->erase();
        pEnt->close();
    }
}

 

 

CDrawXPXJig jig;
        AcDbObjectId polyID;
        if (acedGrRead(track, &type, result) == RTCAN)//读取输入设备,RTCAN即按下了ESC键
            return;                               //track=1:以拖曳方式
        if (jig.doIt(asPnt3d(result->resval.rpoint), polyID, asPnt3d(OriSpt), asPnt3d(OriEpt)))
        {
            if (acedGrRead(track, &type, result) == RTCAN)//读取输入设备,RTCAN即按下了ESC键
                return;                               //track=1:以拖曳方式
            //成功创建之后,可以进行其他的修改
            pt[X] = result->resval.rpoint[X];
            pt[Y] = result->resval.rpoint[Y];
        }
        else
        {
            return;
        }

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值