2.2.4.24.31 Layer::UnitsConvert

Description

Layer position coordinates convert

Syntax

BOOL UnitsConvert( int nUnitsTo, double * pVals, int nUnitsFrom = -1 )

Parameters

nUnitsTo
[input] one of M_PERCENT, M_INCH, .. M_LINK
pVals
[input/output] 4 values that are the width, height, left and top of the layer area
nUnitsFrom
[input] one of M_PERCENT, M_INCH, .. M_LINK

Return

return true for success

Examples

EX1

//Output layer position after coverting the layer position coordinates to other units.
void Layer_UnitsConvert_ex1()
{
    double xx[4];
    GraphLayer gl = Project.ActiveLayer();
    int nCurrent = gl.GetPosition(xx);
    int nLast;
    printf("Current Settings\n%d:LeftTop=%4.2f,%4.2f\tW,H=%4.2f,%4.2f\n", nCurrent, xx[2], xx[3], xx[0], xx[1]);
    // do convertion with a diff value then actual
    xx[0] /=2; // width to be half
    xx[2] += 1; // left to be moved a little
    printf("Modified Settings\n%d:LeftTop=%4.2f,%4.2f\tW,H=%4.2f,%4.2f\n", nCurrent, xx[2], xx[3], xx[0], xx[1]);
    
    out_str("Results of converting to other units");
    nLast = nCurrent;
    for(int ii = M_PERCENT; ii <= M_LINK; ii++)
    {
        gl.UnitsConvert(ii, xx, nLast);
        printf("From %d to %d, new LeftTop=%4.2f,%4.2f\tW,H=%4.2f,%4.2f\n", nLast, ii, xx[2], xx[3], xx[0], xx[1]); 
        nLast = ii;
    }
    //check and make sure the codes above didnt change the layer itself
    nCurrent = gl.GetPosition(xx);
    printf("after %d: LeftTop=%4.2f,%4.2f\tW,H=%4.2f,%4.2f\n", nCurrent, xx[2], xx[3], xx[0], xx[1]);  
}

Remark

See Also

Layer::SetPosition, Layer::GetPosition

Header to Include

origin.h