/*------------------------------------------------------------------------*/
int set_format_n_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    char* format = NULL;
    char * oldFormat = NULL;
    StringMatrix * labels = NULL;

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

    format = (char*)_pvData;

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

    if (strcmp(format, oldFormat) == 0)
    {
        return SET_PROPERTY_SUCCEED;
    }

    status = setGraphicObjectProperty(iObjUID, __GO_FORMATN__, format, jni_string, 1);
    if (status == TRUE)
    {
        labels = computeDefaultTicsLabels(iObjUID);
        if (labels != NULL)
        {
            char ** data = getStrMatData(labels);
            setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, data, jni_string_vector, labels->nbCol * labels->nbRow);
            deleteMatrix(labels);
        }

        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "format_n");
        return SET_PROPERTY_ERROR;
    }
}
Esempio n. 2
0
void Objdrawaxis (char     dir    ,
                  char     tics   ,
                  double* x      ,
                  int    * nx     ,
                  double* y      ,
                  int    * ny     ,
                  char   * val[]  ,
                  int      subint ,
                  char   * format ,
                  int      font   ,
                  int      textcol,
                  int      ticscol,
                  char     flag   ,
                  int      seg    ,
                  int      nb_tics_labels)
{
    int iObjUID = 0;
    int iSubwinUID = 0;
    int ticksDirection = 0;
    int ticksStyle = 0;

    iSubwinUID = getCurrentSubWin();

    checkRedrawing();

    switch (dir)
    {
        default :
        case 'u' :
            ticksDirection = 0;
            break;
        case 'd' :
            ticksDirection = 1;
            break;
        case 'l' :
            ticksDirection = 2;
            break;
        case 'r' :
            ticksDirection = 3;
            break;
    }

    switch (tics)
    {
        default:
        case 'v':
            ticksStyle = 0;
            break;
        case 'r':
            ticksStyle = 1;
            break;
        case 'i':
            ticksStyle = 2;
            break;
    }

    iObjUID = createAxis(iSubwinUID, ticksDirection, ticksStyle, x, *nx, y, *ny, subint, format, font, textcol, ticscol, seg);

    if (iObjUID == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), "Objdrawaxis");
        return;
    }

    if (val == NULL)
    {
        char **matData;
        StringMatrix *tics_labels;

        tics_labels = computeDefaultTicsLabels(iObjUID);

        if (tics_labels == NULL)
        {
            deleteGraphicObject(iObjUID);
            return;
        }

        matData = getStrMatData(tics_labels);

        /*
        * The labels vector size must be computed using the matrix's dimensions.
        * To be modified when the labels computation is moved to the Model.
        */
        setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, matData, jni_string_vector, tics_labels->nbCol * tics_labels->nbRow);

        deleteMatrix(tics_labels);
    }
    else
    {
        int i = 0;
        /*
        * Labels are set using the str argument; the previous code tested whether each element of the
        * str array was null and set the corresponding Axis' element to NULL, though there was no
        * apparent reason to do so. This is still checked, but now aborts building the Axis.
        */

        if (nb_tics_labels == -1)
        {
            Scierror(999, _("Impossible case when building axis\n"));
            deleteGraphicObject(iObjUID);
            return;
        }

        for (i = 0; i < nb_tics_labels; i++)
        {
            if (val[i] == NULL)
            {
                deleteGraphicObject(iObjUID);
                return;
            }
        }

        setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, val, jni_string_vector, nb_tics_labels);
    }

    setCurrentObject(iObjUID);
}