/*------------------------------------------------------------------------*/
int set_outside_colors_property(char* pobjUID, size_t stackPointer, int valueType, int nbRow, int nbCol )
{
    BOOL status;
    int  values[2];
    int nbColors = 0;

    if ( !isParameterDoubleMatrix( valueType ) )
    {
        Scierror(999, _("Wrong type for '%s' property: Integer expected.\n"), "outside_colors");
        return SET_PROPERTY_ERROR;
    }

#if 0
    if ( sciGetEntityType(pobj) != SCI_FEC )
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"),"outside_colors");
        return SET_PROPERTY_ERROR;
    }
#endif

    if ( nbRow * nbCol != 2 )
    {
        Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "outside_colors", 2);
        return SET_PROPERTY_ERROR;
    }

    copyDoubleVectorToIntFromStack(stackPointer, values, 2);

    /* Returns the number of colors of pobj's parent Figure */
    nbColors = sciGetNumColors(pobjUID);

    if (   values[0] > nbColors || values[0] < -1
      || values[1] > nbColors || values[1] < -1)
    {
        /* It is possible to set color_range outside the colormap, however it won't be used.*/
        sciprint(_("WARNING: Wrong value for '%s' property: indices outside the colormap will be clamped.\n"), "outside_colors");
    }

    status = setGraphicObjectProperty(pobjUID, __GO_OUTSIDE_COLOR__, values, jni_int_vector, 2);

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

}
/*------------------------------------------------------------------------*/
int set_interp_color_vector_property(void* _pvCtx, char* pobjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int iNumElements = 0;
    int* piNumElements = &iNumElements;

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

    getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void **) &piNumElements);

    /*
     * A way to display a more explicit message would be to first get the
     * interpolation vector set flag and test it for NULL.
     */
    if (piNumElements == NULL)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "data");
        return SET_PROPERTY_ERROR;
    }

    if ((nbCol == 3 && iNumElements == 3) ||
            (nbCol == 4 && iNumElements == 4))
    {
        int tmp[4];
        copyDoubleVectorToIntFromStack(_pvData, tmp, nbCol);

        status = setGraphicObjectProperty(pobjUID, __GO_INTERP_COLOR_VECTOR__, tmp, jni_int_vector, nbCol);

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

    }
    else
    {
        Scierror(999, _("The number of column of the color vector must match the number of points defining the line (which must be %d or %d).\n"), 3, 4);
        return SET_PROPERTY_ERROR;
    }
}
/*------------------------------------------------------------------------*/
int set_mark_foreground_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int markForeground = 0;
	int *tmp = NULL;
    int colorSet = 0;

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

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

	if ( nbCol == 1 )
	{
		markForeground = (int)((double*)_pvData)[0];
		status = setGraphicObjectProperty(iObjUID, __GO_MARK_FOREGROUND__, &markForeground, jni_int, 1);
	}
	else
	{
		tmp = MALLOC(nbCol * sizeof(int));
		copyDoubleVectorToIntFromStack(_pvData, tmp, nbCol);
		status = setGraphicObjectProperty(iObjUID, __GO_MARK_FOREGROUNDS__, tmp, jni_int_vector, nbCol);
		FREE(tmp);
        colorSet = 1;
        setGraphicObjectProperty(iObjUID, __GO_COLOR_SET__, &colorSet, jni_bool, 1);
	}

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "mark_foreground");
        return SET_PROPERTY_ERROR;
    }
}
/*------------------------------------------------------------------------*/
int set_color_range_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int values[2];
    int nbColors = 0;

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

    if (nbRow * nbCol != 2)
    {
        Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "color_range", 2);
        return SET_PROPERTY_ERROR;
    }

    copyDoubleVectorToIntFromStack(_pvData, values, 2);
    /* Returns the number of colors of pobj's parent Figure */
    nbColors = sciGetNumColors(iObjUID);

    if (  values[0] > nbColors || values[0] < 0
            || values[1] > nbColors || values[1] < 0)
    {
        /* It is possible to set color_range outside the colormap, however it won't be used.*/
        sciprint(_("WARNING: Wrong value for '%s' property: indices outside the colormap will be clamped.\n"), "color_range");
    }

    status = setGraphicObjectProperty(iObjUID, __GO_COLOR_RANGE__, values, jni_int_vector, 2);

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "color_range");
        return SET_PROPERTY_ERROR;
    }
}
/*------------------------------------------------------------------------*/
int set_mark_size_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
	int status = -1;
    int *tmp = NULL;

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

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

	tmp = MALLOC(nbCol * sizeof(int));
    copyDoubleVectorToIntFromStack(_pvData, tmp, nbCol);
	status = sciSetMarkSize(iObjUID, tmp, nbCol);
	FREE(tmp);

    return status;
}
/*------------------------------------------------------------------------*/
int set_segs_color_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    BOOL status = FALSE;
    int iNbSegs = 0;
    int* piNbSegs = &iNbSegs;
    int* segsColors = NULL;

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

    getGraphicObjectProperty(iObjUID, __GO_NUMBER_ARROWS__, jni_int, (void**)&piNbSegs);

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

    if (nbRow * nbCol != 1 && nbRow * nbCol != iNbSegs)
    {
        Scierror(999, _("Wrong size for '%s' property: %d or %d elements expected.\n"), "segs_color", 1, iNbSegs);
        return SET_PROPERTY_ERROR;
    }

    if (nbRow * nbCol == 1)
    {
        int value = (int) ((double*)_pvData)[0];

        /* 1-element array which is internally duplicated */
        status = setGraphicObjectProperty(iObjUID, __GO_SEGS_COLORS__, &value, jni_int_vector, 1);
    }
    else if (nbRow * nbCol == iNbSegs)
    {
        segsColors = (int*) MALLOC(iNbSegs * sizeof(int));

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

        copyDoubleVectorToIntFromStack(_pvData, segsColors, iNbSegs);
        status = setGraphicObjectProperty(iObjUID, __GO_SEGS_COLORS__, segsColors, jni_int_vector, iNbSegs);

        FREE(segsColors);
    }

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

    return SET_PROPERTY_SUCCEED;
}
/*------------------------------------------------------------------------*/
int set_colors_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol )
{
    BOOL status = FALSE;
    int iNumElements = 0;
    int* piNumElements = &iNumElements;

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

    getGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void **) &piNumElements);

    /*
     * A way to display a more explicit message would be to first get the
     * interpolation vector set flag and test it for NULL.
     */
    if (piNumElements == NULL)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "data");
        return SET_PROPERTY_ERROR;
    }

    if (nbCol == 0)
    {
        int colorSet = 0;
        status = setGraphicObjectProperty(iObjUID, __GO_COLOR_SET__, &colorSet, jni_bool, 1);
        if (status == FALSE)
        {
            Scierror(999, _("'%s' property does not exist for this handle.\n"), "colors");
            return SET_PROPERTY_ERROR;
        }
        setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_COLORS__, NULL, jni_int_vector, 0);

        return SET_PROPERTY_SUCCEED;
    }

    if (nbCol == iNumElements)
    {
        int * tmp = MALLOC(nbCol * sizeof(int));
        copyDoubleVectorToIntFromStack(_pvData, tmp, nbCol);

        status = setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_COLORS__, tmp, jni_int_vector, nbCol);
        if (status == TRUE)
        {
            int colorSet = 1;
            setGraphicObjectProperty(iObjUID, __GO_COLOR_SET__, &colorSet, jni_bool, 1);
            FREE(tmp);
            return SET_PROPERTY_SUCCEED;
        }
        else
        {
            FREE(tmp);
            Scierror(999, _("'%s' property does not exist for this handle.\n"), "colors");
            return SET_PROPERTY_ERROR;
        }
    }
    else
    {
        Scierror(999, _("The number of column of the color vector must match the number of points defining the line.\n"));
        return SET_PROPERTY_ERROR;
    }
}