ObjectARX AcEdJig получение координат
| Правила | Регистрация | Пользователи | Сообщения за день |  Справка по форуму | Файлообменник |

Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > ObjectARX AcEdJig получение координат

ObjectARX AcEdJig получение координат

Ответ
Поиск в этой теме
Непрочитано 03.09.2013, 14:03 #1
ObjectARX AcEdJig получение координат
Константин Селикатов
 
Регистрация: 16.07.2013
Сообщений: 4

Делаю кастомный объект на ObjectARX, возникла необходимость сделать Jig. Попытался разобраться с примером (создание эллипса), но не понял в какой момент получаются координаты.

Вот в чём я разобрался:
Для создании объекта вызывается метод void createEllipse()
Код:
[Выделить все]
void
createEllipse()
{
    AcGePoint3d tempPt;
    struct resbuf rbFrom, rbTo;

    acedGetPoint(NULL, _T("\nEllipse center point: "),
        asDblArray(tempPt));

    rbFrom.restype = RTSHORT;
    rbFrom.resval.rint = 1; // from UCS
    rbTo.restype = RTSHORT;
    rbTo.resval.rint = 0; // to WCS

    acedTrans(asDblArray(tempPt), &rbFrom, &rbTo,
        Adesk::kFalse, asDblArray(tempPt));

    AcGeVector3d x = acdbHostApplicationServices()->workingDatabase()
                     ->ucsxdir();
    AcGeVector3d y = acdbHostApplicationServices()->workingDatabase()
                     ->ucsydir();
    AcGeVector3d normalVec = x.crossProduct(y);
    normalVec.normalize();

    AsdkEllipseJig *pJig
        = new AsdkEllipseJig(tempPt, normalVec);

    pJig->doIt();

    delete pJig;
}
Как видно из кода сначала создаётся объект класса AsdkEllipseJig, затем вызывается метод doIt(), затем объект удаляется.

Описание класса AsdkEllipseJig:
Код:
[Выделить все]
class AsdkEllipseJig : public AcEdJig
{
public:
    AsdkEllipseJig(const AcGePoint3d&, const AcGeVector3d&);
    void doIt();
    virtual DragStatus sampler();
    virtual Adesk::Boolean update();
    virtual AcDbEntity* entity() const;

private:
    AcDbEllipse *mpEllipse;
    AcGePoint3d mCenterPt, mAxisPt;
    AcGeVector3d mMajorAxis, mNormal;
    double mRadiusRatio;
    int mPromptCounter;
};
Метод doIt():
Код:
[Выделить все]
void
AsdkEllipseJig::doIt()
{
    mpEllipse = new AcDbEllipse();
	mpEllipse->set(mCenterPt, mNormal, mMajorAxis, mRadiusRatio); // Set default parameters for the ellipse.

    // Get the major axis vector from the user.
    //
    // At this time, mPromptCounter == 0
    //
    setDispPrompt(_T("\nEllipse major axis: "));
    AcEdJig::DragStatus stat = drag();

    // Get the ellipse's radius ratio.
    //
    mPromptCounter++;   // now == 1
    setDispPrompt(_T("\nEllipse minor axis: "));
    stat = drag();

    // Now add the ellipse to the database's current space.
    //
    append();
}
Как видно,в методе doIt() вызывается метод drag(), который в свою очередь вызывает sampler() и update():
Код:
[Выделить все]
AcEdJig::DragStatus
AsdkEllipseJig::sampler()
{
    DragStatus stat;

    setUserInputControls((UserInputControls)
        (AcEdJig::kAccept3dCoordinates
         | AcEdJig::kNoNegativeResponseAccepted
         | AcEdJig::kNoZeroResponseAccepted));

    if (mPromptCounter == 0) {

        // Aquire the major axis endpoint.
        //
        // If the newly acquired point is the same as it was
        // in the last sample, then we return kNoChange so the
        // AsdkEllipseJig::update() function will not be called and the
        // last update call will be able to finish, thus allowing
        // the ellipse to fully elaborate.
        //
        static AcGePoint3d axisPointTemp;
        stat = acquirePoint(mAxisPt, mCenterPt);
        if (axisPointTemp != mAxisPt)
            axisPointTemp = mAxisPt;
        else if (stat == AcEdJig::kNormal)
            return AcEdJig::kNoChange;
    }
    else if (mPromptCounter == 1) {

        // Aquire the distance from ellipse center to minor
        // axis endpoint. This will be used to calculate the
        // radius ratio.
        //
        // If the newly acquired distance is the same as it was
        // in the last sample, then we return kNoChange so the
        // AsdkEllipseJig::update() function will not be called and the
        // last update call will be able to finish, thus allowing
        // the ellipse to fully elaborate.
        //
        static double radiusRatioTemp = -1;
        stat = acquireDist(mRadiusRatio, mCenterPt);
        if (radiusRatioTemp != mRadiusRatio)
            radiusRatioTemp = mRadiusRatio;
        else if (stat == AcEdJig::kNormal)
            return AcEdJig::kNoChange;
    }
    return stat;
}

// This function is called to update the entity based on the
// input values.
//
Adesk::Boolean
AsdkEllipseJig::update()
{
    switch (mPromptCounter) {
    case 0:

        // At this time, mAxis contains the value of one
        // endpoint of the desired major axis.  The
        // AcDbEllipse class stores the major axis as the
        // vector from the center point to where the axis
        // intersects the ellipse path (such as half of the true
        // major axis), so we already have what we need.
        //
        mMajorAxis = mAxisPt - mCenterPt;
        break;
    case 1:

        // Calculate the radius ratio.  mRadiusRatio
        // currently contains the distance from the ellipse
        // center to the current pointer position.  This is
        // half of the actual minor axis length.  Since
        // AcDbEllipse stores the major axis vector as the
        // vector from the center point to the ellipse curve
        // (half the major axis), to get the radius ratio we
        // simply divide the value currently in mRadiusRatio
        // by the length of the stored major axis vector.
        //
        mRadiusRatio = mRadiusRatio / mMajorAxis.length();
        break;
    }

    // Now update the ellipse with the latest setting.
    //
    mpEllipse->set(mCenterPt, mNormal, mMajorAxis,
        mRadiusRatio);

    return Adesk::kTrue;
}
Метод sampler служит (как я понял) для получения и проверки координат, а метод update для обновления параметров объекта.
ВОПРОС: Где происходит получение вводимых координат?

Полный файл кода примера во вложении

Вложения
Тип файла: zip elipsjig.zip (3.7 Кб, 27 просмотров)

Просмотров: 4013
 
Непрочитано 03.09.2013, 15:12
#2
hwd

C, C++, C#
 
Регистрация: 07.10.2009
С-Пб.
Сообщений: 2,762
Отправить сообщение для hwd с помощью Skype™


Вопросы по ObjectARX лучше задавать здесь (больше шансов получить ответ).
__________________
Надеюсь, ты не социальный овощ? Это определяется делами! :welcome:
hwd вне форума  
 
Непрочитано 03.09.2013, 16:39
#3
Do$

AutoCAD/Civil3D LISP/C#
 
Регистрация: 15.08.2008
Санкт-Петербург
Сообщений: 1,701
Отправить сообщение для Do$ с помощью Skype™


Или здесь: http://adn-cis.org/forum/index.php?board=3.0
__________________
Толковый выбор приходит с опытом, а к нему приводит выбор бестолковый. (The Mechanic)
Do$ вне форума  
 
Непрочитано 04.09.2013, 02:20
#4
Александр Ривилис

программист, рыцарь ObjectARX
 
Регистрация: 09.05.2005
Киев
Сообщений: 2,413
Отправить сообщение для Александр Ривилис с помощью Skype™


Цитата:
Сообщение от Константин Селикатов Посмотреть сообщение
ВОПРОС: Где происходит получение вводимых координат?
Здесь:
Код:
[Выделить все]
 stat = acquirePoint(mAxisPt, mCenterPt);
и здесь:
Код:
[Выделить все]
 stat = acquireDist(mRadiusRatio, mCenterPt);
Александр Ривилис вне форума  
Ответ
Вернуться   Форум DWG.RU > Программное обеспечение > Программирование > ObjectARX AcEdJig получение координат



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Получение координат точки, лежащей на полилинии на расстоянии n от ее начала. Kirill_Ja Программирование 1 25.09.2012 10:15
Получение списка координат всех возможных прямоугольников из массива точек. swkx Программирование 6 22.04.2011 21:31
Получение координат выделенного объекта НовичOK Программирование 3 05.11.2010 14:26
Получение координат примитивов в Регионе (AcadRegion), C# AkaPaul Программирование 6 14.05.2010 22:22
Помощь по Лире Серега М Лира / Лира-САПР 52 28.05.2007 02:47