Sample Code for dxfInFields() with Order Dependence

This code sample shows how you could write a dxfInFields() function that is order-dependent.

Acad::ErrorStatus
AsdkPoly::dxfInFields(AcDbDxfFiler* filer)
{
    assertWriteEnabled();
    if ((AcDbCurve::dxfInFields(filer) != Acad::eOk) ||
        !filer->atSubclassData("AsdkPoly") )
    {
        return filer->filerStatus();
    }
    try
    {
        struct resbuf rb;
        // Object Version
        Adesk::Int16 version;
        filer->readItem(&rb);
        if (rb.restype != AcDb::kDxfInt16) 
            throw AcDb::kDxfInt16;
        version = rb.resval.rint;
        if (version > VERSION)
            return Acad::eMakeMeProxy;
        if (version == 1)
        {
            AcGePoint3d cent,sp;
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfXCoord) 
                throw AcDb::kDxfXCoord
                cent = asPnt3d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfXCoord + 1) 
                throw AcDb::kDxfXCoord + 1;
            sp = asPnt3d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfInt32) 
                throw AcDb::kDxfInt32;
            mNumSides = rb.resval.rlong;
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfNormalX) 
                throw AcDb::kDxfNormalX
                mPlaneNormal = asVec3d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfText) 
                throw AcDb::kDxfText;
            setName(rb.resval.rstring);
            filer->readItem(&rb);
            if (rb.restype != kDxfHardPointerId) 
                throw AcDb::kDxfHardPointerId;
            acdbGetObjectId(mTextStyle, rb.resval.rlname);
            // Convert data from old format.
            acdbWcs2Ecs(asDblArray(cent),asDblArray(cent),
                asDblArray(mPlaneNormal),Adesk::kFalse);
            mCenter.set(cent.x,cent.y);
            mElevation = cent.z;
            acdbWcs2Ecs(asDblArray(sp),asDblArray(sp),
                asDblArray(mPlaneNormal),Adesk::kFalse);
            mStartPoint.set(sp.x,sp.y);
            assert(mElevation == sp.z);
        } 
        else if (version == 2)
        {
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfXCoord) 
                throw AcDb::kDxfXCoord;
            mCenter = asPnt2d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfXCoord + 1) 
                throw AcDb::kDxfXCoord + 1;
            mStartPoint = asPnt2d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfInt32) 
                throw AcDb::kDxfInt32
                mNumSides = rb.resval.rlong;
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfNormalX)
                throw AcDb::kDxfNormalX;
            mPlaneNormal = asVec3d(rb.resval.rpoint);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfText) 
                throw AcDb::kDxfText
                setName(rb.resval.rstring);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfHardPointerId) 
                throw AcDb::kDxfHardPointerId;
            acdbGetObjectId(mTextStyle, rb.resval.rlname);
            filer->readItem(&rb);
            if (rb.restype != AcDb::kDxfReal) 
                throw AcDb::kDxfReal;
            mElevation = rb.resval.rreal;
        } 
        else assert(false);
    }
    catch (AcDb::DxfCode code)
    {
        filer->pushBackItem();
        filer->setError(Acad::eInvalidDxfCode,
            "\nError: expected group code %d", code);
        return filer->filerStatus();
    }
}