コード例 #1
0
/*------------------------------------------------------------------------*/
int set_xtics_coord_property(void* _pvCtx, char* pobjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int N = 0;
    double* vector = NULL;
    char c_format[5];
    int iXNumberTicks = 0;
    int* piXNumberTicks = &iXNumberTicks;
    char** stringVector = NULL;
    int iTicksStyle = 0;
    int* piTicksStyle = &iTicksStyle;
    char ticksStyle = 0;

    if (valueType != sci_matrix)
    {
        Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "xtics_coord");
        return SET_PROPERTY_ERROR;
    }

    if (nbRow != 1)
    {
        Scierror(999, _("Wrong size for '%s' property: Row vector expected.\n"), "xtics_coord");
        return SET_PROPERTY_ERROR;
    }

    getGraphicObjectProperty(pobjUID, __GO_X_NUMBER_TICKS__, jni_int, (void**)&piXNumberTicks);

    if (piXNumberTicks == NULL)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "xtics_coord");
        return SET_PROPERTY_ERROR;
    }

    if (iXNumberTicks == 1 && nbCol != 1)
    {
        Scierror(999, _("Wrong size for '%s' property: Scalar expected.\n"), "xtics_coord");
        return SET_PROPERTY_ERROR;
    }

    if (iXNumberTicks != 1 && nbCol == 1)
    {
        Scierror(999, _("Wrong size for '%s' property: At least %d elements expected.\n"), "xtics_coord", 2);
        return SET_PROPERTY_ERROR;
    }

    /* what follows remains here as it was */
    status = setGraphicObjectProperty(pobjUID, __GO_X_TICKS_COORDS__, _pvData, jni_double_vector, nbCol);

    if (status == FALSE)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "xtics_coord");
        return SET_PROPERTY_ERROR;
    }

    getGraphicObjectProperty(pobjUID, __GO_TICKS_STYLE__, jni_int, (void**)&piTicksStyle);

    if (iTicksStyle == 0)
    {
        ticksStyle = 'v';
    }
    else if (iTicksStyle == 1)
    {
        ticksStyle = 'r';
    }
    else if (iTicksStyle == 2)
    {
        ticksStyle = 'i';
    }

    if (ComputeXIntervals(pobjUID, ticksStyle, &vector, &N, 0) != 0)
    {
        /* Something wrong happened */
        FREE(vector);
        return -1;
    }

    if (ComputeC_format(pobjUID, c_format) != 0)
    {
        /* Something wrong happened */
        FREE(vector);
        return -1;
    }

    stringVector = copyFormatedArray(vector, N, c_format, 256);

    status = setGraphicObjectProperty(pobjUID, __GO_TICKS_LABELS__, stringVector, jni_string_vector, N);

    FREE(vector);

    destroyStringArray(stringVector, N);

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        return SET_PROPERTY_ERROR;
    }

}
コード例 #2
0
ファイル: Format.c プロジェクト: ScilabOrg/scilab
/**
 * Compute the default labels of an axis from the positions of the ticks.
 * @param[in/out] pobjUID the axis object UID
 * @return a string matrix containing the labels.
 *         Actually it is a row vector.
 */
StringMatrix * computeDefaultTicsLabels(int iObjUID)
{
    StringMatrix * ticsLabels = NULL  ;
    int            nbTics     = 0     ;
    char           tempFormat[5]      ;
    char         * c_format   = NULL  ;
    double       * vector     = NULL   ; /* position of labels */
    char           curLabelBuffer[257];
    int            i = 0;

    int tmp = 0;
    int* piTmp = &tmp;
    char ticksStyle = 'v';

    getGraphicObjectProperty(iObjUID, __GO_FORMATN__, jni_string, (void **)&c_format);

    /*
     * If different from the empty string, the format is already specified,
     * if equal, it needs to be computed.
     */
    if (c_format && strcmp(c_format, "") == 0)
    {
        ComputeC_format(iObjUID, tempFormat);
        c_format = tempFormat;
    }

    getGraphicObjectProperty(iObjUID, __GO_TICKS_STYLE__, jni_int, (void **)&piTmp);

    if (tmp == 0)
    {
        ticksStyle = 'v';
    }
    else if (tmp == 1)
    {
        ticksStyle = 'r';
    }
    else if (tmp == 2)
    {
        ticksStyle = 'i';
    }

    /* vector is allocated here */
    if (ComputeXIntervals(iObjUID, ticksStyle, &vector, &nbTics, 1) != 0)
    {
        Scierror(999, _("Bad size in %s: you must first increase the size of the %s.\n"), "tics_coord", "tics_coord");
        return 0;
    }

    /* create a vector of strings */
    ticsLabels = newMatrix(1, nbTics);
    if (ticsLabels == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), "computeDefaultTicsLabels");
        return NULL;
    }

    for (i = 0 ; i < nbTics ; i++)
    {
        sprintf(curLabelBuffer, c_format, vector[i]) ; /* we can't know for sure the size of the label */
        /* That's why it is first stored in a big array */
        copyStrMatElement(ticsLabels, 0, i, curLabelBuffer);
    }

    FREE(vector);
    vector = NULL;

    return ticsLabels;

}