コード例 #1
0
/*--------------------------------------------------------------------------*/
static int getScalarFromStack(int paramIndex, char * funcName, double* res, void* pvApiCtx)
{
    SciErr sciErr;
    int m = 0;
    int n = 0;
    int* piAddrstackPointer = NULL;
    double* stackPointer = NULL;
    if ((!checkInputArgumentType(pvApiCtx, paramIndex, sci_matrix)))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Real scalar expected.\n"), funcName, paramIndex);
        return -1;
    }

    /* get the handle */
    sciErr = getVarAddressFromPosition(pvApiCtx,  paramIndex, &piAddrstackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return -1;
    }

    // Retrieve a matrix of double at position  paramIndex.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), funcName,  paramIndex);
        return -1;
    }


    if (m * n != 1)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: Real scalar expected.\n"), funcName, paramIndex);
        return -1;
    }

    *res = *stackPointer;
    return 0;
}
コード例 #2
0
/*--------------------------------------------------------------------------*/
int sci_getcallbackobject(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrpObjUID = NULL;
    int nbRow = 0;
    int nbCol = 0;
    char** pObjUID = NULL;
    unsigned long graphicHandle = 0;

    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpObjUID);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrpObjUID, &nbRow, &nbCol, &pObjUID))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }

        if (nbCol != 1 || nbRow == 0)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 1);
            return FALSE;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return FALSE;
    }

    graphicHandle = getHandle(pObjUID[0]);
    freeAllocatedMatrixOfString(nbRow, nbCol, pObjUID);

    /* Create return variable */
    if (graphicHandle == 0)     /* Non-existing object --> return [] */
    {
        double* stkAdr = NULL;
        nbRow = 0;
        nbCol = 0;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }
    }
    else                        /* Return the handle */
    {
        long long* stkAdr = NULL;
        nbRow = 1;
        nbCol = 1;

        sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        *stkAdr = (long long)graphicHandle;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #3
0
/*--------------------------------------------------------------------------*/
int sci_uicontrol(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int nbRow = 0, nbCol = 0, k = 0;
    int setStatus = SET_PROPERTY_SUCCEED;
    int PARENT_NOT_FOUND = -2;
    int NOT_FOUND = -1;
    int inputIndex = 0, beginIndex = 0;
    char *propertyName = NULL;
    char *styleProperty = NULL;

    int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**);
    unsigned long GraphicHandle = 0;

    int found = 0;              /* Does the property exists ? */

    int *propertiesValuesIndices = NULL;

    int iParentType = -1;
    int *piParentType = &iParentType;
    int iParentStyle = -1;
    int *piParentStyle = &iParentStyle;

    int iParentUID      = 0;
    int iUicontrol      = 0;
    int iCurrentFigure  = 0;

    CheckOutputArgument(pvApiCtx, 0, 1);

    //init properties index
    init_property_index();

    if (nbInputArgument(pvApiCtx) == 0)
    {
        /* Create a pushbutton in current figure */

        /* Create a new pushbutton */
        GraphicHandle = getHandle(CreateUIControl(NULL));

        /* Set current figure as parent */
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }

        iUicontrol = getObjectFromHandle(GraphicHandle);
        setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
    }
    else if (nbInputArgument(pvApiCtx) == 1)
    {
        /* Create a pushbutton in figure given as parameter */
        /* Or give focus to the uicontrol given as parameter */
        int* piAddr = NULL;
        int iType = 0;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
        if (sciErr.iErr)
        {
            Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
            return 0;
        }

        if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE)
        {
            OverLoad(1);
            return FALSE;
        }
#if 0 // Allow XML loading
        else if (isStringType(pvApiCtx, piAddr))
        {
            char* pstXmlfile = NULL;
            char* pstExpandedPath = NULL;

            if (isScalar(pvApiCtx, piAddr) == 0)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
                return FALSE;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile))
            {
                freeAllocatedSingleString(pstXmlfile);
                Scierror(999, _("%s: No more memory.\n"), fname);
                return FALSE;
            }

            pstExpandedPath = expandPathVariable(pstXmlfile);
            freeAllocatedSingleString(pstXmlfile);
            iUicontrol = xmlload(pstExpandedPath);
            if (iUicontrol < 1)
            {
                Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath);
                FREE(pstExpandedPath);
                return 0;
            }
            FREE(pstExpandedPath);
            GraphicHandle = getHandle(iUicontrol);

            /* Create return variable */
            if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
            return TRUE;
        }
#endif // Allow XML loading
        else /* Get parent ID */
        {
            int* piAddr = NULL;
            long long hParent = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (isScalar(pvApiCtx, piAddr) == 0)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                return FALSE;
            }

            if (getScalarHandle(pvApiCtx, piAddr, &hParent))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                return 1;
            }

            iParentUID = getObjectFromHandle((long)hParent);
            if (iParentUID != 0)
            {
                getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
                if (iParentType == __GO_UICONTROL__)  /* Focus management */
                {
                    GraphicHandle = (unsigned long)hParent;
                    requestFocus(iParentUID);
                }
                else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__)  /* PushButton creation */
                {
                    /* Create a new pushbutton */
                    GraphicHandle = getHandle(CreateUIControl(NULL));
                    iUicontrol = getObjectFromHandle(GraphicHandle);

                    /* First parameter is the parent */
                    setGraphicObjectRelationship(iParentUID, iUicontrol);
                    setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]);
                    if (setStatus == SET_PROPERTY_ERROR)
                    {
                        Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName);
                        return FALSE;
                    }
                }
                else
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol",
                             "Figure", "Uimenu");
                    return FALSE;
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure",
                         "Uimenu");
                return FALSE;
            }
        }
    }
    else
    {
        if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings))
        {
            OverLoad(1);
            return FALSE;
        }

        /* Allocate memory to store the position of properties in uicontrol call */
        if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
            return FALSE;
        }

        /* Init all positions to NOT_FOUND */
        for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++)
        {
            propertiesValuesIndices[inputIndex] = NOT_FOUND;    /* Property initialized as not found */
        }

        /**
         * Odd number of input arguments
         * First input is the parent ID
         * All event inputs are property names
         * All odd (except first) inputs are property values
         */
        if (nbInputArgument(pvApiCtx) % 2 == 1)
        {
            if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
            {
                if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
                {
                    int* piAddr = NULL;
                    double dblValue = 0;

                    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    if (isScalar(pvApiCtx, piAddr) == 0)
                    {
                        Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                        return FALSE;
                    }

                    if (getScalarDouble(pvApiCtx, piAddr, &dblValue))
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                        return 1;
                    }

                    iParentUID = getFigureFromIndex((int)dblValue);
                }
                else
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }
            }
            else /* Get parent ID */
            {
                int* piAddr = NULL;
                long long hParent = 0;
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (isScalar(pvApiCtx, piAddr) == 0)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }

                if (getScalarHandle(pvApiCtx, piAddr, &hParent))
                {
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }

                iParentUID = getObjectFromHandle((long)hParent);
            }

            if (iParentUID == 0)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                         "Frame uicontrol");
                return FALSE;
            }

            getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
            if (iParentType != __GO_FIGURE__)
            {
                getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle);
                if (iParentType != __GO_UICONTROL__ ||
                        (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__))
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure",
                             "Frame uicontrol");
                    return FALSE;
                }
            }
            /* First parameter is the parent */
            propertiesValuesIndices[parent_property] = 1;
            // First input parameter which is a property name
            beginIndex = 2;
        }
        /**
         * Even number of input arguments
         * All odd inputs are property names
         * All even inputs are property values
         */
        else
        {
            // First input parameter which is a property name
            beginIndex = 1;
        }

        /* Get all properties positions */
        for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2)
        {
            /* Read property name */
            if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings)))
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex);
                return FALSE;
            }
            else
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex);
                    return 1;
                }


                /* Bug 3031 */
                /* We only want to compare propertyName along its length */
                /* 'posi' must be matched to 'position' */
                found = 0;
                for (k = 0; k < iPropertiesCount ; k++)
                {
                    if (strlen(propertyName) <= strlen(propertiesNames[k]))
                    {
                        if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0)
                        {
                            propertiesValuesIndices[k] = inputIndex + 1;    /* Position of value for property */
                            found = 1;
                            break;
                        }
                    }
                }

                freeAllocatedSingleString(propertyName);

                if (found == 0)
                {
                    Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol");
                    return FALSE;
                }
            }
        }

        if (propertiesValuesIndices[style_property] != NOT_FOUND)    /* Style found */
        {
            if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings)))
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
                    return 1;
                }

                if (strcmp(styleProperty, "frame") == 0)
                {
                    //check scrollable property to create a scroll frame instead of normal frame
                    if (propertiesValuesIndices[scrollable_property] != NOT_FOUND)
                    {
                        char* pstScroll = NULL;
                        int iScroll = 0;
                        sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            return 1;
                        }

                        if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0)
                        {
                            Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                            return 1;
                        }

                        if (isStringType(pvApiCtx, piAddr))
                        {
                            if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll))
                            {
                                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                                return 1;
                            }

                            if (strcmp(pstScroll, "on") == 0)
                            {
                                iScroll = 1;
                            }

                            freeAllocatedSingleString(pstScroll);
                        }
                        else
                        {
                            if (getScalarBoolean(pvApiCtx, piAddr, &iScroll))
                            {
                                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]);
                                return 1;
                            }
                        }

                        if (iScroll)
                        {
                            freeAllocatedSingleString(styleProperty);
                            styleProperty = os_strdup("framescrollable");
                        }

                        propertiesValuesIndices[scrollable_property] = NOT_FOUND;
                    }
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]);
                return FALSE;
            }
        }

        /* Create a new uicontrol */
        iUicontrol = CreateUIControl(styleProperty);
        freeAllocatedSingleString(styleProperty);
        if (iUicontrol == 0) /* Error in creation */
        {
            Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname);
            return FALSE;
        }
        GraphicHandle = getHandle(iUicontrol);

        /* If no parent given then the current figure is the parent */
        if (propertiesValuesIndices[parent_property] == NOT_FOUND)
        {
            /* Set the parent */
            iCurrentFigure = getCurrentFigure();

            if (iCurrentFigure == 0)
            {
                iCurrentFigure = createNewFigureWithAxes();
            }

            propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND;
        }

        /* Read and set all properties */
        for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++)   /* Style has already been set */
        {
            if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND)
            {
                //special case for not specified parent
                //but set relationship at the good moment.
                setGraphicObjectRelationship(iCurrentFigure, iUicontrol);
            }
            else if (propertiesValuesIndices[inputIndex] != NOT_FOUND)
            {
                int* piAddr = NULL;
                sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                if (inputIndex == user_data_property || inputIndex == userdata_property)   /* User data settings */
                {
                    nbRow = -1;
                    nbCol = -1;
                    setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]);
                }
                else            /* All other properties */
                {
                    /* Read property value */
                    switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex]))
                    {
                        case sci_matrix:
                        {
                            double* pdblValue = NULL;
                            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue);
                            if (sciErr.iErr)
                            {
                                printError(&sciErr, 0);
                                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                return 1;
                            }

                            setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        case sci_strings:
                            /* Index for String & TooltipString properties: Can be more than one character string */
                            if ((inputIndex == string_property) || (inputIndex == tooltipstring_property))
                            {
                                char** pstValue = NULL;
                                if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue))
                                {
                                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                    return 1;
                                }

                                setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                                freeAllocatedMatrixOfString(nbRow, nbCol, pstValue);
                            }
                            else
                            {
                                char* pstValue = NULL;
                                if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue))
                                {
                                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                    return 1;
                                }

                                nbRow = (int)strlen(pstValue);
                                nbCol = 1;
                                setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                                freeAllocatedSingleString(pstValue);
                            }
                            break;
                        case sci_handles:
                        {
                            long long* pHandles = NULL;
                            sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles);
                            if (sciErr.iErr)
                            {
                                printError(&sciErr, 0);
                                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]);
                                return 1;
                            }

                            setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        case sci_tlist: //constraints and border
                        {
                            setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]);
                            break;
                        }
                        default:
                            setStatus = SET_PROPERTY_ERROR;
                            break;
                    }
                }
                if (setStatus == SET_PROPERTY_ERROR)
                {
                    Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]);
                    return FALSE;
                }
            }
        }
    }

    if (propertiesValuesIndices != NULL
            && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND &&
                (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND)))    /* SliderStep property not set */
    {
        /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */
        double maxValue = 0;
        double* pdblMaxValue = &maxValue;
        double minValue = 0;
        double* pdblMinValue = &minValue;
        double pdblStep[2];

        getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue);
        getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue);

        pdblStep[0] = 0.01 * (maxValue - minValue);
        pdblStep[1] = 0.1 * (maxValue - minValue);

        setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2);
    }

    if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND))    /* Position property not set */
    {
        double* pdblPosition = NULL;

        getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition);
        setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4);
        releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4);
    }

    if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND))    /* Visible property not set */
    {
        /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */
        int b = (int)TRUE;
        setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1);
    }

    FREE(propertiesValuesIndices);

    /* Create return variable */
    if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #4
0
ファイル: sci_toolbar.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
int sci_toolbar(char *fname, unsigned long l)
{
    SciErr sciErr;

    int* piAddr1 = NULL;
    int* piStkAdr = NULL;
    int* piAddrstkAdr = NULL;
    long long* stkAdr = NULL;
    int* piAddrparam = NULL;

    int nbCol = 0;
    int nbRow = 0;

    char *Output = NULL;
    char **param = NULL;
    int figNum = -2;

    int iIsVisible = 0;
    int *piIsVisible = NULL;

    int iParentUID = 0;
    int iParentType = -1;
    int *piParentType = &iParentType;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* Figure number */
    if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &nbRow, &nbCol, &piStkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1);
            return 1;
        }

        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
            return FALSE;
        }
        figNum = *piStkAdr;

        if (figNum < -1)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: Must be > %d expected.\n"), fname, 1, -1);
            return FALSE;
        }

        if (figNum != -1)       /* Check that the figure exists */
        {
            if (getFigureFromIndex(figNum) == 0)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: 'Graphic Window Number %d' does not exist.\n"), fname, 1, figNum);
                return FALSE;
            }
        }

        if (figNum == -1)
        {
            iParentUID = getConsoleIdentifier();
        }
        else
        {
            iParentUID = getFigureFromIndex(figNum);
        }
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position 1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstkAdr, &nbRow, &nbCol, &stkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }

        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
            return FALSE;
        }

        iParentUID = getObjectFromHandle((long) * stkAdr);

        if (iParentUID == 0)
        {
            Scierror(999, _("%s: Wrong value for input argument #%d: this handle does not exist.\n"), fname, 1);
            return FALSE;
        }

        getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
        if (iParentType != __GO_FIGURE__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1);
            return FALSE;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A real or a Figure handle expected.\n"), fname, 1);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 2)               /* New status */
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrparam);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrparam, &nbRow, &nbCol, &param))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }

            if ((strcmp(param[0], "off") == 0) || (strcmp(param[0], "on") == 0))
            {
                iIsVisible = strcmp(param[0], "on") == 0;
                if (iParentUID != getConsoleIdentifier() || getScilabMode() == SCILAB_STD)
                {
                    setGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, &iIsVisible, jni_bool, 1);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
            }
            else
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, param);
                Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "on", "off");
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Returned value */
    piIsVisible = &iIsVisible;
    getGraphicObjectProperty(iParentUID, __GO_TOOLBAR_VISIBLE__, jni_bool, (void **)&piIsVisible);
    if (iIsVisible)
    {
        Output = strdup("on");
    }
    else
    {
        Output = strdup("off");
    }

    nbCol = 1;
    nbRow = (int)strlen(Output);
    if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, Output))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;

    if (Output)
    {
        FREE(Output);
        Output = NULL;
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #5
0
/*--------------------------------------------------------------------------*/
int sci_TCL_UnsetVar(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    int* piAddrl2 = NULL;
    char* l2 = NULL;

    static int n1, m1;
    static int n2, m2;

    Tcl_Interp *TCLinterpreter = NULL;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 1, 1);

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        int paramoutINT = 0;
        char *VarName = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &VarName))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        if (!existsGlobalInterp())
        {
            freeAllocatedSingleString(VarName);
            Scierror(999, _("%s: Error main TCL interpreter not initialized.\n"), fname);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) == 2)
        {
            // two arguments given - get a pointer on the slave interpreter
            if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
            {
                sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
                if (sciErr.iErr)
                {
                    freeAllocatedSingleString(VarName);
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 2.
                if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
                {
                    freeAllocatedSingleString(VarName);
                    Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
                    return 1;
                }

                TCLinterpreter = Tcl_GetSlave(getTclInterp(), (l2));
                freeAllocatedSingleString(l2);
                releaseTclInterp();
                if (TCLinterpreter == NULL)
                {
                    freeAllocatedSingleString(VarName);
                    Scierror(999, _("%s: No such slave interpreter.\n"), fname);
                    return 0;
                }
            }
            else
            {
                freeAllocatedSingleString(VarName);
                Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 2);
                return 0;
            }
        }
        else
        {
            // only one argument given - use the main interpreter
            TCLinterpreter = getTclInterp();
        }

        paramoutINT = (int)(Tcl_UnsetVar(TCLinterpreter, VarName, TCL_GLOBAL_ONLY) != TCL_ERROR);
        freeAllocatedSingleString(VarName);

        if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, paramoutINT))
        {
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        ReturnArguments(pvApiCtx);
    }
    else
    {
        releaseTclInterp();
        Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
        return 0;
    }
    releaseTclInterp();

    return 0;
}
コード例 #6
0
/*--------------------------------------------------------------------------*/
int sci_rotate_axes(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;

    int nbRow = 0;
    int nbCol = 0;

    int iUID = 0;
    int* piUID = &iUID;
    int iType = -1;
    int *piType = &iType;

    /* check size of input and output */
    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (nbInputArgument(pvApiCtx) == 0)
    {
        iUID = getCurrentFigure();
    }
    else
    {
        /* Get figure or subwin handle */
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Single Figure or Axes handle expected.\n"), fname, 1);
            return -1;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position 1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &nbRow, &nbCol, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }


        if (nbRow * nbCol != 1)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Single Figure or Axes handle expected.\n"), fname, 1);
            return -1;
        }

        iUID = getObjectFromHandle((long int) * stackPointer);

        getGraphicObjectProperty(iUID, __GO_TYPE__, jni_int, (void **)&piType);
        if (iType == __GO_AXES__)
        {
            iUID = getParentObject(iUID);
        }
    }

    if (iUID == 0)
    {
        Scierror(999, _("%s: The handle is not or no more valid.\n"), fname);
        return -1;
    }

    setGraphicObjectProperty(iUID, __GO_INFO_MESSAGE__, "Right click and drag to rotate.", jni_string, 1);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
コード例 #7
0
/*--------------------------------------------------------------------------*/
int sci_helpbrowser(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrhelpAdr      = NULL;
    int* piAddrkeywordAdr   = NULL;
    int* piAddrfullTextAdr  = NULL;
    int* fullTextAdr        = NULL;

    int nbRow = 0;
    int nbCol = 0;
    char** keywordAdr = NULL;

    int nbRowHelp       = 0;
    int nbColHelp       = 0;
    char** helpAdr      = NULL;
    char** languageAdr  = NULL;
    int ret = 1;

    CheckInputArgument(pvApiCtx, 2, 4);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* We load SciNotes when calling javahelp because we have no way to know
     * to load it when using Javahelp because it can call SciNotes directly */
    if (!loadedDep)
    {
        loadOnUseClassPath("SciNotes");
        loadedDep = TRUE;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrhelpAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrhelpAdr, &nbRowHelp, &nbColHelp, &helpAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        helpAdr = NULL; /* No toolboxes installed */
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 1);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        ret = launchHelpBrowser(helpAdr, nbRowHelp * nbColHelp, languageAdr[0]);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }
        freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
    }
    else if (nbInputArgument(pvApiCtx) == 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrkeywordAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrkeywordAdr, &nbRow, &nbCol, &keywordAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }

                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedMatrixOfString(nbRow, nbCol, keywordAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 2);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 3, sci_strings)))
        {
            int* piAddrlanguageAdr = NULL;
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrlanguageAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrlanguageAdr, &nbRow, &nbCol, &languageAdr))
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedMatrixOfString(nbRow, nbCol, languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrfullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrfullTextAdr, &nbRow, &nbCol, &fullTextAdr);
            if (sciErr.iErr)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                if (helpAdr)
                {
                    freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
                }
                freeAllocatedSingleString(*keywordAdr);
                freeAllocatedSingleString(*languageAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 4);
                return FALSE;
            }
        }
        else
        {
            if (helpAdr)
            {
                freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
            }
            freeAllocatedSingleString(*keywordAdr);
            freeAllocatedSingleString(*languageAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }

        ret = searchKeyword(helpAdr, nbRowHelp * nbColHelp, keywordAdr[0], languageAdr[0], *fullTextAdr == 1);

        if (helpAdr)
        {
            freeAllocatedMatrixOfString(nbRowHelp, nbColHelp, helpAdr);
        }

        freeAllocatedSingleString(*keywordAdr);
        freeAllocatedSingleString(*languageAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 4);
        return FALSE;
    }

    if (ret == 0)
    {
        return FALSE;
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #8
0
ファイル: sci_xlfont.c プロジェクト: quanpan302/scilab
/*--------------------------------------------------------------------------*/
static int xlfont_one_rhs(char * fname)
{
    SciErr sciErr;
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        int* piAddrl1 = NULL;
        int* l1 = NULL;
        char* strl1 = NULL;
        int m1 = 0, n1 = 0;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &strl1))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        if (strcmp(strl1, "AVAILABLE_FONTS") == 0)
        {
            int nbElements = 0;
            char **fontsname = getAvailableFontsName(&nbElements);

            m1 = nbElements;
            n1 = 1;

            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, (const char * const*)fontsname);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            freeArrayOfString(fontsname, nbElements);
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else if (strcmp(strl1, "reset") == 0)
        {
            resetFontManager();
            freeAllocatedSingleString(strl1);
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }
        else
        {
            if (isAvailableFontsName(strl1))
            {
                int fontID = addFont(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else if (FileExist(strl1))
            {
                int fontID = addFontFromFilename(strl1);

                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = fontID;

                freeAllocatedSingleString(strl1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: A valid fontname expected.\n"), fname, 1);
            }
        }

        freeAllocatedSingleString(strl1);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
        return 0;
    }

    return 0;
}
コード例 #9
0
/*--------------------------------------------------------------------------*/
int sci_getcallbackobject(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrpObjUID = NULL;
    int nbRow = 0;
    int nbCol = 0;
    double ObjUID = 0;
    unsigned long graphicHandle = 0;

    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpObjUID);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getScalarDouble(pvApiCtx, piAddrpObjUID, &ObjUID))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: Real expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return FALSE;
    }

    graphicHandle = getHandle((int)ObjUID);

    /* Create return variable */
    if (graphicHandle == 0)     /* Non-existing object --> return [] */
    {
        if (createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1))
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }
    }
    else                        /* Return the handle */
    {
        if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, graphicHandle))
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #10
0
ファイル: sci_qp_solve.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
int sci_qp_solve(char *fname, unsigned long fname_len)
{
    SciErr sciErr;
    static int un = 1, deux = 2;
    // n : first dimension of Q
    // nbis : second dimension of Q (nbis is expected to be equal to n)
    static int n = 0, nbis = 0;
    static int unbis = 0;
    static int m = 0, next = 0;
    static int mbis = 0;
    static int pipo = 0;
    static int nact = 0;
    int r = 0;
    static int lw = 0,  k = 0;
    static SciSparse Sp;
    static int issparse = 0;
    double *work = NULL;

    int* piAddr1 = NULL;
    int* piAddr2 = NULL;
    int* piAddr3 = NULL;
    int* piAddr4 = NULL;
    int* piAddr5 = NULL;

    double* Q = NULL;
    double* C = NULL;
    double* p = NULL;
    double* b = NULL;
    int* me   = NULL;

    double* x = NULL;
    int* iact = NULL;
    int* iter = NULL;
    double* crval = NULL;
    int *ierr = NULL;


    /*   Check rhs and lhs   */
    CheckInputArgument(pvApiCtx, 5, 5) ;
    CheckOutputArgument(pvApiCtx, 1, 5) ;

    /*Warning this interface does not support arguments passed by reference */

    /* RhsVar: qp_solve(Q,p,C,b,me) */
    /*                1,2,3,4,5   */

    next = nbInputArgument(pvApiCtx) + 1;
    /*   Variable 1 (Q)   */
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 1.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &n, &nbis, &Q);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
        printError(&sciErr, 0);
        return 1;
    }

    //CheckSquare
    if (n != nbis)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A square matrix expected.\n"), fname, 1);
        return 1;
    }

    /*   Variable 2 (p)   */
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 2.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &nbis, &unbis, &p);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
        printError(&sciErr, 0);
        return 1;
    }

    //CheckLength
    if (nbis * unbis != n)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, 2, nbis * unbis);
        return 1;
    }


    /*   Variable 3 (C)   */
    issparse =  (checkInputArgumentType(pvApiCtx, 3, 5));
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (!issparse)
    {
        // Retrieve a matrix of double at position 3.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &nbis, &m, &C);
        if (sciErr.iErr)
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
            printError(&sciErr, 0);
            return 1;
        }
    }
    else
    {
        if (isVarComplex(pvApiCtx, piAddr3))
        {
            Sp.it = 1;
            sciErr = getComplexSparseMatrix(pvApiCtx, piAddr3, &(Sp.m), &(Sp.n), &(Sp.nel), &(Sp.mnel), &(Sp.icol), &(Sp.R), &(Sp.I));
        }
        else
        {
            Sp.it = 0;
            sciErr = getSparseMatrix(pvApiCtx, piAddr3, &(Sp.m), &(Sp.n), &(Sp.nel), &(Sp.mnel), &(Sp.icol), &(Sp.R));
        }

        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        nbis = Sp.m;
        m = Sp.n;
    }

    if ( nbis != n ) // car C est passee en transposee dans la macro qpsolve
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d column(s) expected for matrix %s.\n"), fname, 3, n, "C");
        return 0;
    }

    /*   Variable 4 (b)   */
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 4.
    sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &mbis, &unbis, &b);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 4);
        printError(&sciErr, 0);
        return 1;
    }

    //CheckLength
    if (mbis * unbis != m)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, 4, mbis * unbis);
        return 1;
    }


    /*   Variable 5 (me)   */
    //get variable address
    sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr5);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    // Retrieve a matrix of double at position 5.
    sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr5, &pipo, &unbis, &me);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 5);
        printError(&sciErr, 0);
        return 1;
    }

    //CheckScalar
    if (pipo != 1 || unbis != 1)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 5);
        return 1;
    }

    if ((*(me) < 0) || (*(me) > n))
    {
        Scierror(999, _("%s: Wrong value for input argument #%d: %s must be an integer in the range 0 to %d.\n"), fname, 5, "me", n);
        return 0;
    }

    /* nbOutputArgument(pvApiCtx) variables: x, iact, iter, crval */
    next = Rhs;
    sciErr = allocMatrixOfDouble(pvApiCtx, next + 1, n, un, &x);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, next + 2, m, un, &iact);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, next + 3, deux, un, &iter);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    sciErr = allocMatrixOfDouble(pvApiCtx, next + 4, un, un, &crval);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, next + 5, un, un, &ierr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }


    r = Min(n, m);
    lw =  2 * n + r * (r + 5) / 2 + 2 * m + 1;
    if ((work = (double *)MALLOC(lw * sizeof(double))) == NULL)
    {
        Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
        return 1;
    }
    /* change the sign of  C and b.*/
    *ierr = 0;
    if (!issparse)
    {
        /* linear constraints matrix is stored full */
        C2F(qpgen2)((Q), (p), &n, &n,  (x), (crval), (C),
                    (b), &n, &m, (me), (iact), &nact, (iter), work,
                    (ierr));
    }
    else
    {
        /* linear constraints matrix is a sparse matrix */
        /* Change the linear constraints matrix representation:
        qpgen1sci requires column-compressed sparse matrix internal
        representation while Scilab sparse matrices are row-compressed */
        double *R = NULL, *I = NULL;
        int *ind = NULL;

        if ((R = (double *)MALLOC(Sp.nel * sizeof(double))) == NULL)
        {
            FREE(work);
            work = NULL;
            Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
            return 1;
        }
        if ((ind = (int *)MALLOC((m + Sp.nel) * sizeof(int))) == NULL)
        {
            FREE(work);
            work = NULL;
            FREE(R);
            R = NULL;
            Scierror(999, _("%s: Cannot allocate more memory.\n"), fname);
            return 1;
        }

        // Transpose the sparse matrix A
        C2F(spt)(&n, &m, &(Sp.nel) ,  &(Sp.it), (int *)work,
                 Sp.R,  Sp.I,  Sp.mnel,  Sp.icol, R, I, ind, ind + m);

        C2F(qpgen1sci)((Q), (p), &n, &n,  (x), (crval),
                       ind, ind + m,  R,
                       (b), &m, (me), (iact), &nact, (iter),
                       work, (ierr));
        FREE(work);
        work = NULL;
        FREE(R);
        R = NULL;
        FREE(ind);
        ind = NULL;
    }

    for (k = nact; k < m; k++)
    {
        (iact)[k] = 0;
    }
    /* LhsVar: [x, iact, iter, f] = qp_solve(...) */
    if (Lhs != 5)
    {
        if (*ierr == 0)
        {
            for (k = 0; k < Lhs; k++)
            {
                AssignOutputVariable(pvApiCtx, 1 + k) = next + 1 + k;
            }
            ReturnArguments(pvApiCtx);
        }
        else if (*ierr == 1)
        {
            Scierror(999, _("%s: The minimization problem has no solution.\n"), fname);
        }
        else if (*ierr == 2)
        {
            Scierror(999, _("%s: Q is not symmetric positive definite.\n"), fname);
        }
    }
    else
    {
        for (k = 0; k < Lhs; k++)
        {
            AssignOutputVariable(pvApiCtx, 1 + k) = next + 1 + k;
        }
        if (*ierr == 1)
        {
            if (getWarningMode())
            {
                sciprint(_("\n%s: Warning: The minimization problem has no solution. The results may be inaccurate.\n\n"), fname);
            }
        }
        else if (*ierr == 2)
        {
            if (getWarningMode())
            {
                sciprint(_("\n%s: Warning: Q is not symmetric positive definite. The results may be inaccurate.\n\n"), fname);
            }
        }
        ReturnArguments(pvApiCtx);
    }
    return 0;
}
コード例 #11
0
/*--------------------------------------------------------------------------*/
int sci_stringbox(char * fname, void *pvApiCtx)
{
    SciErr sciErr;
    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;
    char** strStackPointer   = NULL;
    double* pdblStackPointer = NULL;

    int type = -1;
    int *piType = &type;

    int iParentAxes = 0;
    int* piParentAxes = &iParentAxes;
    double* textCorners = NULL;
    int two   = 2;
    int four  = 4;
    double corners[4][2]; /* the four edges of the boundingRect */

    /* The function should be called with stringbox(handle) */
    CheckInputArgument(pvApiCtx,  1, 6);
    CheckOutputArgument(pvApiCtx,  0, 1);

    if (nbInputArgument(pvApiCtx) == 1)
    {
        int m;
        int n;
        /* A text handle should be specified */

        int iTextUID = 0;
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        /* get the handle */
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of handle at position  1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"), fname,  1, "Text");
            return 1;
        }

        if (m * n != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A ''%s'' handle expected.\n"), fname, 1, "Text");
            return 0;
        }

        /* Get the handle and check that this is a text handle */
        iTextUID = getObjectFromHandle((long int) * stackPointer);

        if (iTextUID == 0)
        {
            Scierror(999, _("%s: The handle is not valid.\n"), fname);
            return 0;
        }

        getGraphicObjectProperty(iTextUID, __GO_TYPE__, jni_int, (void **)&piType);

        if (type != __GO_LABEL__ && type != __GO_TEXT__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 'Text' handle expected.\n"), fname, 1);
            return 0;
        }

        getGraphicObjectProperty(iTextUID, __GO_PARENT_AXES__, jni_int, (void **)&piParentAxes);

        updateTextBounds(iTextUID);

        /*
         * To do: performs a projection/unprojection to obtain the bounding box in object coordinates
         * but using a rotation matrix corresponding to the default rotation angles (view == 2d)
         */

        getGraphicObjectProperty(iTextUID, __GO_CORNERS__, jni_double_vector, (void **)&textCorners);

        corners[1][0] = textCorners[0];
        corners[1][1] = textCorners[1];

        corners[0][0] = textCorners[3];
        corners[0][1] = textCorners[4];

        corners[3][0] = textCorners[6];
        corners[3][1] = textCorners[7];

        corners[2][0] = textCorners[9];
        corners[2][1] = textCorners[10];
    }
    else if (nbInputArgument(pvApiCtx) == 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d or %d to %d expected.\n"), fname, 1, 3, 6);
        return 0;
    }
    else
    {
        int iParentSubwinUID = getOrCreateDefaultSubwin();
        char ** text = NULL;
        int textNbRow;
        int textNbCol;
        double xPos;
        double yPos;
        double angle = DEFAULT_ANGLE;
        int fontId;
        int *pfontId = &fontId;
        double fontSize;
        double *pfontSize = &fontSize;

        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_STYLE__, jni_int, (void**)&pfontId);
        getGraphicObjectProperty(iParentSubwinUID, __GO_FONT_SIZE__, jni_double, (void **)&pfontSize);

        /* Check that first argument is a string */
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: 2D array of strings expected.\n"), fname, 1);
            return 0;
        }
        sciErr = getVarAddressFromPosition(pvApiCtx,  1, &piAddrstackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position  1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrstackPointer, &textNbRow, &textNbCol, &strStackPointer))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname,  1);
            return 1;
        }

        /* retrieve it */
        text = strStackPointer;

        /* Second and third arguments should be scalars */
        if (getScalarFromStack(2, fname, &xPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (getScalarFromStack(3, fname, &yPos, pvApiCtx) < 0)
        {
            freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) >= 4)
        {
            /* angle is defined */
            if (getScalarFromStack(4, fname, &angle, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        if (nbInputArgument(pvApiCtx) >= 5)
        {
            double fontIdD;
            /* font style is defined */
            if (getScalarFromStack(5, fname, &fontIdD, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
            fontId = (int) fontIdD;
        }

        if (nbInputArgument(pvApiCtx) >= 6)
        {
            /* font size is defined */
            if (getScalarFromStack(6, fname, &fontSize, pvApiCtx) < 0)
            {
                freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
                return 0;
            }
        }

        /* compute the box */
        getTextBoundingBox(text, textNbRow, textNbCol, xPos, yPos, angle, fontId, fontSize, corners);
        freeAllocatedMatrixOfString(textNbRow, textNbCol, strStackPointer);
    }


    /* copy everything into the lhs */
    sciErr = allocMatrixOfDouble(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, two, four, &pdblStackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    pdblStackPointer[0] = corners[1][0];
    pdblStackPointer[1] = corners[1][1];
    pdblStackPointer[2] = corners[0][0];
    pdblStackPointer[3] = corners[0][1];
    pdblStackPointer[4] = corners[3][0];
    pdblStackPointer[5] = corners[3][1];
    pdblStackPointer[6] = corners[2][0];
    pdblStackPointer[7] = corners[2][1];

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
コード例 #12
0
/*--------------------------------------------------------------------------*/
int sci_TCL_DeleteInterp(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl2 = NULL;
    char* l2 = NULL;

    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 1, 1);

    if (nbInputArgument(pvApiCtx) == 1)
    {

        if (!existsGlobalInterp())
        {
            Scierror(999, _("%s: Error main TCL interpreter not initialized.\n"), fname);
            return 0;
        }

        if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
        {
            static int n2, m2;
            Tcl_Interp *TCLinterpreter = NULL;

            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
            TCLinterpreter = Tcl_GetSlave(getTclInterp(), (l2));
            freeAllocatedSingleString(l2);
            releaseTclInterp();
            if (TCLinterpreter == NULL)
            {
                Scierror(999, _("%s: No such slave interpreter.\n"), fname);
                return 0;
            }
            else
            {
                Tcl_DeleteInterp(TCLinterpreter);
                TCLinterpreter = NULL;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 1);
            return 0;
        }
    }
    else // nbInputArgument(pvApiCtx) == 0
    {
        releaseTclInterp();

        CloseTCLsci();
        InitializeTclTk();
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
コード例 #13
0
ファイル: sci_x_mdialog.cpp プロジェクト: ScilabOrg/scilab
/*--------------------------------------------------------------------------*/
int sci_x_mdialog(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrlabelsAdr = NULL;
    int* piAddrlineLabelsAdr = NULL;
    int* piAddrdefaultValuesAdr = NULL;
    int* piAddrcolumnLabelsAdr = NULL;
    double* emptyMatrixAdr = NULL;

    int nbRow = 0, nbCol = 0;
    int nbRowDefaultValues = 0, nbColDefaultValues = 0;
    int nbRowLineLabels = 0, nbColLineLabels = 0;
    int nbRowColumnLabels = 0, nbColColumnLabels = 0;

    int messageBoxID = 0;

    char **labelsAdr = NULL;
    char **lineLabelsAdr = NULL;
    char **columnLabelsAdr = NULL;
    char **defaultValuesAdr = NULL;

    int userValueSize = 0;
    char **userValue = NULL;

    CheckInputArgument(pvApiCtx, 3, 4);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* READ THE LABELS */
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrlabelsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrlabelsAdr, &nbRow, &nbCol, &labelsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 1);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Multiple Values Request"));
    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, labelsAdr, nbCol * nbRow);
    freeAllocatedMatrixOfString(nbRow, nbCol, labelsAdr);

    /* READ THE LINE LABELS */
    if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlineLabelsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrlineLabelsAdr, &nbRowLineLabels, &nbColLineLabels, &lineLabelsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
            return 1;
        }

        if (nbRowLineLabels != 1 && nbColLineLabels != 1)
        {
            freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr);
            Scierror(999, _("%s: Wrong size for input argument #%d: Vector of strings expected.\n"), fname, 2);
            return FALSE;
        }
        setMessageBoxLineLabels(messageBoxID, lineLabelsAdr, nbColLineLabels * nbRowLineLabels);
        freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
        return FALSE;
    }

    /* READ THE COLUMN LABELS or DEFAULT VALUES */
    if (checkInputArgumentType(pvApiCtx, 3, sci_strings))
    {
        if (nbInputArgument(pvApiCtx) == 3)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrdefaultValuesAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrdefaultValuesAdr, &nbRowDefaultValues, &nbColDefaultValues, &defaultValuesAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
                return 1;
            }

            if ((nbRowDefaultValues != nbRowLineLabels) || (nbColDefaultValues != nbColLineLabels))
            {
                freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: It must have same dimensions as argument #%d.\n"), fname, 3, 2);
                return FALSE;
            }

            setMessageBoxDefaultInput(messageBoxID, defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues);
            freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr);
        }
        else
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrcolumnLabelsAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrcolumnLabelsAdr, &nbRowColumnLabels, &nbColColumnLabels, &columnLabelsAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
                return 1;
            }

            if (nbRowColumnLabels != 1 && nbColColumnLabels != 1)
            {
                freeAllocatedMatrixOfString(nbRowColumnLabels, nbColColumnLabels, columnLabelsAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: Vector of strings expected.\n"), fname, 3);
                return FALSE;
            }
            setMessageBoxColumnLabels(messageBoxID, columnLabelsAdr, nbColColumnLabels * nbRowColumnLabels);
            freeAllocatedMatrixOfString(nbRowColumnLabels, nbColColumnLabels, columnLabelsAdr);
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 3);
        return FALSE;
    }

    if (nbInputArgument(pvApiCtx) == 4)
    {
        /* READ  DEFAULT VALUES */
        if (checkInputArgumentType(pvApiCtx, 4, sci_strings))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrdefaultValuesAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 4.
            // DO NOT FORGET TO RELEASE MEMORY via freeAllocatedMatrixOfString(nbRowDefaultValues, nbColDefaultValues, defaultValuesAdr).
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrdefaultValuesAdr, &nbRowDefaultValues, &nbColDefaultValues, &defaultValuesAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4);
                return 1;
            }

            if ((nbRowDefaultValues != nbRowLineLabels * nbColLineLabels) || (nbColDefaultValues != nbRowColumnLabels * nbColColumnLabels))
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: %d x %d matrix of strings expected.\n"), fname, 4, nbRowLineLabels * nbColLineLabels, nbRowColumnLabels * nbColColumnLabels);
                freeArrayOfString(defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues);
                return FALSE;
            }
            setMessageBoxDefaultInput(messageBoxID, defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues);
            freeArrayOfString(defaultValuesAdr, nbColDefaultValues * nbRowDefaultValues);
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings expected.\n"), fname, 4);
            return FALSE;
        }
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValueSize = getMessageBoxValueSize(messageBoxID);
    if (userValueSize == 0)
    {
        nbRow = 0;
        nbCol = 0;
        // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int emptyMatrixAdr".
        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &emptyMatrixAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

    }
    else
    {
        userValue = getMessageBoxValue(messageBoxID);
        nbCol = 1;
        nbRowDefaultValues = nbColLineLabels * nbRowLineLabels;
        nbColDefaultValues = 1;
        if (nbInputArgument(pvApiCtx) == 4)
        {
            nbColDefaultValues = nbColColumnLabels * nbRowColumnLabels;
        }

        createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRowDefaultValues, nbColDefaultValues, userValue);
        delete[] userValue;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #14
0
ファイル: sci_xgetmouse.c プロジェクト: ASP1234/Scilabv5.5.2
/*--------------------------------------------------------------------------*/
int sci_xgetmouse(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    double* l2 = NULL;

    int  m1 = 1, n1 = 3;
    int mouseButtonNumber = 0;
    int windowsID = 0;
    int sel[2], m = 0, n = 0;

    int pixelCoords[2];
    double userCoords2D[2] = {0.0, 0.0};

    int selPosition = 0;

    CheckInputArgument(pvApiCtx, 0, 1);
    CheckOutputArgument(pvApiCtx, 1, 2);

    switch (nbInputArgument(pvApiCtx))
    {
        case 1:
            if (checkInputArgumentType(pvApiCtx, 1, sci_boolean))
            {
                selPosition = 1;
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: Boolean vector expected.\n"), fname, 1);
                return FALSE;
            }
            break;
        default:
            // Call Java xgetmouse
            // No need to set any option.
            break;
    }

    // Select current figure or create it
    getOrCreateDefaultSubwin();

    // Call Java to get mouse information
    if (selPosition != 0)
    {
        int* l1Sel = NULL;
        sciErr = getVarAddressFromPosition(pvApiCtx, selPosition, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of boolean at position selPosition.
        sciErr = getMatrixOfBoolean(pvApiCtx, piAddrl1, &m, &n, &l1Sel);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, selPosition);
            return 1;
        }

        //CheckDims
        if (m * n != 2 || 1 != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, selPosition, 2, 1);
            return 1;
        }

        sel[0] = (int)l1Sel[0];
        sel[1] = (int)l1Sel[1];

        // Call Java xgetmouse
        CallJxgetmouseWithOptions(sel[0], sel[1]);
    }
    else
    {
        CallJxgetmouse();
    }

    // Get return values
    mouseButtonNumber = getJxgetmouseMouseButtonNumber();
    pixelCoords[0] = (int) getJxgetmouseXCoordinate();
    pixelCoords[1] = (int) getJxgetmouseYCoordinate();

    sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    // No need to calculate coordinates if callback or close is trapped
    if (mouseButtonNumber == -1000 || mouseButtonNumber == -2)
    {
        l1[0] = -1;
        l1[1] = -1;
        l1[2] = (double) mouseButtonNumber;
    }
    else
    {
        // Convert pixel coordinates to user coordinates
        int iClickedSubwinUID = getCurrentSubWin();
        updateSubwinScale(iClickedSubwinUID);
        sciGet2dViewCoordFromPixel(iClickedSubwinUID, pixelCoords, userCoords2D);

        l1[0] = userCoords2D[0];
        l1[1] = userCoords2D[1];
        l1[2] = (double) mouseButtonNumber;
    }
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;

    switch (Lhs)
    {
        case 1:
            ReturnArguments(pvApiCtx);
            return 0;
        case 2:
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, m1, m1, &l2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            l2[0] = windowsID; /* this is the window number */
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            ReturnArguments(pvApiCtx);
            return 0;
    }
    ReturnArguments(pvApiCtx);
    return -1;
}
コード例 #15
0
ファイル: sci_exportUI.c プロジェクト: rossdrummond/scilab
/*--------------------------------------------------------------------------*/
int sci_exportUI(char * fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrstackPointer = NULL;

    int iFigureId   = 0; // id of the figure to export
    int *piFigureId = &iFigureId;
    int iRows       = 0;
    int iCols       = 0;
    int iHandleType = -1;
    int *piHandleType = &iHandleType;

    CheckOutputArgument(pvApiCtx, 0, 1);
    CheckInputArgument(pvApiCtx, 1, 1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_handles)) // exportUI(figHandle)
    {
        char *pstFigureUID      = NULL;
        char *pstHandleType     = NULL;
        long long* stackPointer = NULL;
        // Retrieve a matrix of handle at position 1.
        sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &iRows, &iCols, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }

        if (iRows * iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
        }

        pstFigureUID = getObjectFromHandle((unsigned long) * stackPointer);

        getGraphicObjectProperty(pstFigureUID, __GO_TYPE__, jni_int, (void **)&piHandleType);
        if (iHandleType == __GO_FIGURE__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
            return FALSE;
        }

        getGraphicObjectProperty(pstFigureUID, __GO_ID__, jni_int, (void **)&piFigureId);
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix)) // exportUI(figId)
    {
        double* stackPointer = NULL;

        // Retrieve a matrix of double at position 1.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrstackPointer, &iRows, &iCols, &stackPointer);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1);
            return 1;
        }

        if (iRows * iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
            return FALSE;
        }

        iFigureId = (int) * stackPointer;
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
        return FALSE;
    }

    // call the export function
    exportUserInterface(iFigureId);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
コード例 #16
0
ファイル: sci_xlfont.c プロジェクト: quanpan302/scilab
/*--------------------------------------------------------------------------*/
static int xlfont_n_rhs(char * fname)
{
    SciErr sciErr;
    BOOL isBold = FALSE;
    BOOL isItalic = FALSE;

    if (nbInputArgument(pvApiCtx) == 3)
    {
        int m3 = 0, n3 = 0;
        int* piAddrl3 = NULL;
        int* l3 = NULL;
        if ((!checkInputArgumentType(pvApiCtx, 3, sci_boolean)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return 0;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrl3);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of boolean at position 3.
        sciErr = getMatrixOfBoolean(pvApiCtx, piAddrl3, &m3, &n3, &l3);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: Boolean matrix expected.\n"), fname, 3);
            return 1;
        }

        isBold = (BOOL) * l3;
    }

    if (nbInputArgument(pvApiCtx) == 4)
    {
        int m4 = 0, n4 = 0;
        int* piAddrl4 = NULL;
        int* l4 = NULL;
        if ((!checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return 0;
        }
        sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrl4);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of boolean at position 4.
        sciErr = getMatrixOfBoolean(pvApiCtx, piAddrl4, &m4, &n4, &l4);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: Boolean matrix expected.\n"), fname, 4);
            return 1;
        }

        isItalic = (BOOL) * l4;
    }

    if (((checkInputArgumentType(pvApiCtx, 1, sci_strings))) && ((checkInputArgumentType(pvApiCtx, 2, sci_matrix))))
    {
        int m1 = 0, n1 = 0;
        int m2 = 0, n2 = 0;
        char* strl1 = NULL;
        double* l2 = NULL;
        int* l1 = NULL;

        int* piAddrl1 = NULL;
        int* piAddrl2 = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &strl1))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
            return 1;
        }

        if ((m2 == 1) && (n2 == 1))
        {
            int fontIndex = (int)l2[0];
            char *fontname = strl1;
            if (fontIndex < 0)
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: Non-negative int expected.\n"), fname, 2);
                return 0;
            }

            if ((nbInputArgument(pvApiCtx) == 2) && FileExist(fontname))
            {
                int Id = changeFontFromFilename(fontIndex, fontname);
                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = Id;

                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
            }
            else if (isAvailableFontsName(fontname))
            {
                int Id = changeFontWithProperty(fontIndex, fontname, isBold, isItalic);
                m1 = 1;
                n1 = 1;

                sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx,  nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(999, _("%s: Memory allocation error.\n"), fname);
                    return 1;
                }

                l1[0] = Id;

                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: A valid fontname expected.\n"), fname, 1);
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 2);
        }

        freeAllocatedSingleString(strl1);
    }
    else
    {
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
            return 0;
        }

        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Non-negative int expected.\n"), fname, 2);
            return 0;
        }
    }
    return 0;
}
コード例 #17
0
/*--------------------------------------------------------------------------*/
int sci_unsetmenu(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrmenuNameAdr      = NULL;
    char* menuNameAdr           = NULL;
    int* piAddrfigureNumberAdr  = NULL;
    double* figureNumberAdr     = NULL;
    int* piAddrsubMenuIndexAdr  = NULL;
    double* subMenuIndexAdr     = NULL;

    int nbRow = 0;
    int nbCol = 0;

    // Check parameter number
    CheckInputArgument(pvApiCtx, 1, 3);
    CheckOutputArgument(pvApiCtx, 1, 1);

    if (nbInputArgument(pvApiCtx) == 1)
    {
        // Error message in not in standard mode (we need figure number)
        if (getScilabMode() != SCILAB_STD)
        {
            Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD");
            return FALSE;
        }

        // Unset a Menu of Scilab Main Window
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
            return FALSE;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
            return 1;
        }

        EnableMenu(getConsoleIdentifier(), menuNameAdr, FALSE);
        freeAllocatedSingleString(menuNameAdr);
    }
    else if (nbInputArgument(pvApiCtx) == 2)
    {
        // Unset a Menu a Scilab Graphic Window
        if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)) && (checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                return 1;
            }


            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
                return FALSE;
            }

            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                return 1;
            }

            EnableMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, FALSE);
            freeAllocatedSingleString(menuNameAdr);
        }
        else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)) && (checkInputArgumentType(pvApiCtx, 2, sci_matrix))) // Unset a submenu in main window
        {
            // Error message in not in standard mode (we need figure number)
            if (getScilabMode() != SCILAB_STD)
            {
                Scierror(999, _("%s: Figure number must be given when not in '%s' mode.\n"), fname, "STD");
                return FALSE;
            }

            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmenuNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                return 1;
            }

            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrsubMenuIndexAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                freeAllocatedSingleString(menuNameAdr);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
                freeAllocatedSingleString(menuNameAdr);
                return 1;
            }


            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 2);
                freeAllocatedSingleString(menuNameAdr);
                return FALSE;
            }

            EnableSubMenu(getConsoleIdentifier(), menuNameAdr, (int)*subMenuIndexAdr, FALSE);
            freeAllocatedSingleString(menuNameAdr);
        }
        else
        {
            Scierror(999, _("%s: Wrong input arguments: '%s' or '%s' expected.\n"), fname, "(button, nsub)", "(gwin, button)");
            return FALSE;
        }
    }
    else                        // Unset a submenu in graphics window
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfigureNumberAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrfigureNumberAdr, &nbRow, &nbCol, &figureNumberAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                return 1;
            }


            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 1);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmenuNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            if (getAllocatedSingleString(pvApiCtx, piAddrmenuNameAdr, &menuNameAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
            return FALSE;
        }

        if ((checkInputArgumentType(pvApiCtx, 3, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrsubMenuIndexAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                freeAllocatedSingleString(menuNameAdr);
                return 1;
            }

            // Retrieve a matrix of double at position 3.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrsubMenuIndexAdr, &nbRow, &nbCol, &subMenuIndexAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                freeAllocatedSingleString(menuNameAdr);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 3);
                freeAllocatedSingleString(menuNameAdr);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 3);
            freeAllocatedSingleString(menuNameAdr);
            return FALSE;
        }

        EnableSubMenu(getFigureFromIndex((int)*figureNumberAdr), menuNameAdr, (int)*subMenuIndexAdr, FALSE);
        freeAllocatedSingleString(menuNameAdr);
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
コード例 #18
0
/*--------------------------------------------------------------------------*/
int sci_progressionbar(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrhandleAdr = NULL;
    long long* handleAdr = NULL;
    int* piAddrmessageAdr = NULL;
    long long* stkAdr = NULL;

    int iProgressionbarUID = 0;

    int nbRow = 0, nbCol = 0;
    int nbRowMessage = 0, nbColMessage = 0;

    char **messageAdr = NULL;
    int iValue = 0;
    unsigned long GraphicHandle = 0;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 1, 1);

    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrhandleAdr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    if (nbInputArgument(pvApiCtx) == 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_handles)))  /* ProgressionBar to update */
        {
            // Retrieve a matrix of handle at position 1.
            sciErr = getMatrixOfHandle(pvApiCtx, piAddrhandleAdr, &nbRow, &nbCol, &handleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                return FALSE;
            }
        }
        else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings))) /* Message to display */
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmessageAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 1.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle or a string expected.\n"), fname, 1);
            return FALSE;
        }

        if (handleAdr == 0)
        {
            /* Create a new ProgressionBar */
            iProgressionbarUID = createGraphicObject(__GO_PROGRESSIONBAR__);
            GraphicHandle = getHandle(iProgressionbarUID);
            setGraphicObjectProperty(iProgressionbarUID, __GO_UI_MESSAGE__, messageAdr, jni_string_vector, nbColMessage * nbRowMessage);
            freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);
        }
        else
        {
            GraphicHandle = (unsigned long) * (handleAdr);
            iProgressionbarUID = getObjectFromHandle(GraphicHandle);
            setGraphicObjectProperty(iProgressionbarUID, __GO_UI_VALUE__, &iValue, jni_int, 1);
        }
    }
    else if (nbInputArgument(pvApiCtx) == 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_handles)) && (checkInputArgumentType(pvApiCtx, 2, sci_strings))) /* progressionbar(id,mes) */
        {
            // Retrieve a matrix of handle at position 1.
            sciErr = getMatrixOfHandle(pvApiCtx, piAddrhandleAdr, &nbRow, &nbCol, &handleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                return FALSE;
            }
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmessageAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                return 1;
            }

            GraphicHandle = (unsigned long) * handleAdr;
            iProgressionbarUID = getObjectFromHandle(GraphicHandle);

            setGraphicObjectProperty(iProgressionbarUID, __GO_UI_VALUE__, &iValue, jni_int, 1);
            setGraphicObjectProperty(iProgressionbarUID, __GO_UI_MESSAGE__, messageAdr, jni_string_vector, nbColMessage * nbRowMessage);
            freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);
        }
        else
        {
            Scierror(999, _("%s: Wrong input arguments: '%s' expected.\n"), fname, "(id, mes)");
            return FALSE;
        }
    }

    if (nbOutputArgument(pvApiCtx) == 1)
    {
        nbRow = 1;
        nbCol = 1;

        sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &stkAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        *stkAdr = (long long)GraphicHandle;
        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #19
0
/*--------------------------------------------------------------------------*/
int sci_x_choose_modeless(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddritemsAdr = NULL;
    int* piAddrmessageAdr = NULL;
    int* piAddrbuttonLabelAdr = NULL;
    double* userValueAdr = NULL;

    int nbRow = 0, nbCol = 0;
    int nbRowItems = 0, nbColItems = 0;

    int messageBoxID = 0;

    char **itemsAdr = NULL;
    char **buttonLabelAdr = NULL;

    char **messageAdr = NULL;

    int userValue = 0;

    CheckInputArgument(pvApiCtx, 2, 3);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddritemsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddritemsAdr, &nbRowItems, &nbColItems, &itemsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 1);
        return FALSE;
    }

    if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrmessageAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRow, &nbCol, &messageAdr))
        {
            freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
            return 1;
        }

    }
    else
    {
        freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Choose Message"));
    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbCol * nbRow);
    /* ListBox Items */
    setMessageBoxListBoxItems(messageBoxID, itemsAdr, nbColItems * nbRowItems);
    /* Modality */
    setMessageBoxModal(messageBoxID, FALSE);

    freeAllocatedMatrixOfString(nbRowItems, nbColItems, itemsAdr);
    freeAllocatedMatrixOfString(nbRow, nbCol, messageAdr);

    if (nbInputArgument(pvApiCtx) == 3)
    {
        if (VarType(3) ==  sci_strings)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrbuttonLabelAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrbuttonLabelAdr, &nbRow, &nbCol, &buttonLabelAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, buttonLabelAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A string expected.\n"), fname, 3);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 3);
            return FALSE;
        }

        setMessageBoxButtonsLabels(messageBoxID, buttonLabelAdr, nbCol * nbRow);
        freeAllocatedMatrixOfString(nbRow, nbCol, buttonLabelAdr);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValue = getMessageBoxSelectedItem(messageBoxID);

    nbRow = 1;
    nbCol = 1;

    sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &userValueAdr);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    *userValueAdr = userValue;

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #20
0
ファイル: sci_x_choice.c プロジェクト: scitao/scilab
/*--------------------------------------------------------------------------*/
int sci_x_choice(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrdefaultValuesAdr = NULL;
    int* piAddrlabelsAdr = NULL;
    int* piAddrlineLabelsAdr = NULL;
    double* emptyMatrixAdr = NULL;

    int nbRow = 0, nbCol = 0;
    int nbRowDefaultValues = 0, nbColDefaultValues = 0;
    int nbRowLineLabels = 0, nbColLineLabels = 0;

    int messageBoxID = 0;

    char **labelsAdr = NULL;
    char **lineLabelsAdr = NULL;
    double *defaultValues = NULL;
    int *defaultValuesInt = NULL;

    int userValueSize = 0;
    int *userValue = NULL;
    double *userValueDouble = NULL;

    int K = 0;

    CheckInputArgument(pvApiCtx, 3, 3);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* READ THE DEFAULT VALUES */
    if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrdefaultValuesAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrdefaultValuesAdr, &nbRowDefaultValues, &nbColDefaultValues, &defaultValues);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
            return 1;
        }

        defaultValuesInt = (int *)MALLOC(nbRowDefaultValues * nbColDefaultValues * sizeof(int));
        for (K = 0; K < nbRowDefaultValues * nbColDefaultValues; K++)
        {
            defaultValuesInt[K] = (int)defaultValues[K];
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"), fname, 1);
        return FALSE;
    }

    /* READ THE MESSAGE */
    if ((checkInputArgumentType(pvApiCtx, 2, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlabelsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrlabelsAdr, &nbRow, &nbCol, &labelsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
            return 1;
        }

    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
        FREE(defaultValuesInt);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Choices Request"));

    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, labelsAdr, nbCol * nbRow);
    freeAllocatedMatrixOfString(nbRow, nbCol, labelsAdr);

    /* READ THE LABELS */
    if (checkInputArgumentType(pvApiCtx, 3, sci_strings))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrlineLabelsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 3.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrlineLabelsAdr, &nbRowLineLabels, &nbColLineLabels, &lineLabelsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
            return 1;
        }

        if (nbRow != 1 && nbCol != 1)
        {
            freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr);
            Scierror(999, _("%s: Wrong size for input argument #%d: Vector of strings expected.\n"), fname, 3);
            return FALSE;
        }
        setMessageBoxLineLabels(messageBoxID, lineLabelsAdr, nbColLineLabels * nbRowLineLabels);
        freeAllocatedMatrixOfString(nbRowLineLabels, nbColLineLabels, lineLabelsAdr);
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 3);
        return FALSE;
    }

    /* Default selected buttons */
    setMessageBoxDefaultSelectedButtons(messageBoxID, defaultValuesInt, nbRowDefaultValues * nbColDefaultValues);

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValueSize = getMessageBoxValueSize(messageBoxID);
    if (userValueSize == 0)
    {
        nbRow = 0;
        nbCol = 0;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &emptyMatrixAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }
    }
    else
    {
        userValue = (int*)getMessageBoxUserSelectedButtons(messageBoxID);

        userValueDouble = (double *)MALLOC(nbRowDefaultValues * nbColDefaultValues * sizeof(double));
        for (K = 0; K < nbRowDefaultValues * nbColDefaultValues; K++)
        {
            userValueDouble[K] = userValue[K];
        }

        sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRowDefaultValues, nbColDefaultValues, userValueDouble);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        /* TO DO : do a delete []  getMessageBoxUserSelectedButtons */
    }

    FREE(defaultValuesInt);

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #21
0
ファイル: sci_messagebox.c プロジェクト: adrianafs/scilab
/*--------------------------------------------------------------------------*/
int sci_messagebox(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrmessageAdr       = NULL;
    int* piAddrtitleAdr         = NULL;
    int* piAddriconAdr          = NULL;
    int* piAddrbuttonsTextAdr   = NULL;
    int* piAddrmodalOptionAdr   = NULL;
    double* buttonNumberAdr     = NULL;

    int messageBoxID = 0;

    /* Used to read input arguments */
    int nbRow = 0, nbCol = 0;
    int nbRowButtons = 0, nbColButtons = 0;
    int nbRowMessage = 0, nbColMessage = 0;

    char **buttonsTextAdr   = 0;
    char **messageAdr       = 0;
    char **titleAdr         = 0;
    char **modalOptionAdr   = 0;
    char **iconAdr          = 0;

    /* Used to write output argument */
    int buttonNumber = 0;

    CheckInputArgument(pvApiCtx, 1, 5);
    CheckOutputArgument(pvApiCtx, 0, 1);

    /* Message to be displayed */
    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrmessageAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrmessageAdr, &nbRowMessage, &nbColMessage, &messageAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
        return FALSE;
    }

    /* Title to be displayed */
    if (nbInputArgument(pvApiCtx) >= 2)
    {
        if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrtitleAdr, &nbRow, &nbCol, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 2);
                return FALSE;
            }
            /* The title argument can be used to give the modal option */
            if (isModalOption(titleAdr[0]))
            {
                modalOptionAdr = titleAdr;
                titleAdr = NULL;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Icon to be displayed */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        if ((checkInputArgumentType(pvApiCtx, 3, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddriconAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 3.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddriconAdr, &nbRow, &nbCol, &iconAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow * nbCol == 1)
            {
                /* The icon argument can be used to give the modal option or the buttons names */
                if (isModalOption(iconAdr[0]))
                {
                    modalOptionAdr = (char **)iconAdr;
                    iconAdr = NULL;
                }
                else if (!isIconName(iconAdr[0]))
                {
                    buttonsTextAdr = (char **)iconAdr;
                    nbRowButtons = nbRow;
                    nbColButtons = nbCol;
                    iconAdr = NULL;
                }
            }
            else  /* More than one string --> buttons names */
            {
                buttonsTextAdr = (char **)iconAdr;
                nbRowButtons = nbRow;
                nbColButtons = nbCol;
                iconAdr = NULL;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string or string vector expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Buttons names */
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 4, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrbuttonsTextAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 4.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrbuttonsTextAdr, &nbRowButtons, &nbColButtons, &buttonsTextAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow * nbCol == 1)
            {
                /* The buttons names argument can be used to give the modal option */
                if (isModalOption(buttonsTextAdr[0]))
                {
                    modalOptionAdr = buttonsTextAdr;
                    buttonsTextAdr = NULL;
                }
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string or string vector expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Modal option */
    if (nbInputArgument(pvApiCtx) == 5)
    {
        if ((checkInputArgumentType(pvApiCtx, 5, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrmodalOptionAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 5.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrmodalOptionAdr, &nbRow, &nbCol, &modalOptionAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 5);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 5);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 5);
            return FALSE;
        }
    }
    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, messageAdr, nbColMessage * nbRowMessage);
    freeAllocatedMatrixOfString(nbRowMessage, nbColMessage, messageAdr);

    /* Title */
    if (titleAdr != NULL)
    {
        setMessageBoxTitle(messageBoxID, titleAdr[0]);
        freeAllocatedMatrixOfString(nbRow, nbCol, titleAdr);
    }
    else
    {
        setMessageBoxTitle(messageBoxID, _("Scilab Message"));
    }

    /* Icon */
    if (iconAdr != NULL)
    {
        setMessageBoxIcon(messageBoxID, iconAdr[0]);
        freeAllocatedMatrixOfString(nbRow, nbCol, iconAdr);
    }

    /* Buttons */
    if (buttonsTextAdr != NULL)
    {
        setMessageBoxButtonsLabels(messageBoxID, buttonsTextAdr, nbColButtons * nbRowButtons);
        freeAllocatedMatrixOfString(nbRowButtons, nbColButtons, buttonsTextAdr);
    }

    /* Modal ? */
    if (modalOptionAdr != NULL)
    {
        setMessageBoxModal(messageBoxID, !stricmp(modalOptionAdr[0], "modal"));
        freeAllocatedMatrixOfString(nbRow, nbCol, modalOptionAdr);
    }
    else
    {
        setMessageBoxModal(messageBoxID, FALSE);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Return the index of the button selected */
    if (nbOutputArgument(pvApiCtx) == 1)
    {
        /* Read the user answer */
        buttonNumber = getMessageBoxSelectedButton(messageBoxID);

        nbRow = 1;
        nbCol = 1;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &buttonNumberAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        buttonNumberAdr[0] = buttonNumber;

        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #22
0
ファイル: sci_uimenu.c プロジェクト: FOSSEE-Internship/scilab
/*--------------------------------------------------------------------------*/
int sci_uimenu(char *fname, void *pvApiCtx)
{
    SciErr sciErr;
    int nbRow = 0, nbCol = 0;
    int setStatus = SET_PROPERTY_SUCCEED;
    int inputIndex = 0, beginIndex = 0;
    char *propertyName = NULL;
    int iParentUID = 0;
    unsigned long GraphicHandle = 0;
    int parentDefined = FALSE;
    int iCurrentFigure = 0;
    int iParentType = -1;
    int *piParentType = &iParentType;

    /* Create a new menu */
    GraphicHandle = getHandle(CreateUimenu());

    /* If no nbInputArgument(pvApiCtx) -> current figure is the parent (Ascendant compatibility) */
    if (nbInputArgument(pvApiCtx) == 0)
    {
        // Set the parent property
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }
        setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle));
    }

    /**
    * Odd number of input arguments
    * First input is the parent ID
    * All event inputs are property names
    * All odd (except first) inputs are property values
    */
    if (nbInputArgument(pvApiCtx) % 2 == 1)
    {
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1);
            return FALSE;
        }
        else                    /* Get parent ID */
        {
            int *piAddr = NULL;
            long long hParent = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of handle at position 1.
            // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr".
            if (getScalarHandle(pvApiCtx, piAddr, &hParent))
            {
                Scierror(202, _("%s: Wrong type for input argument #%d: Handle expected.\n"), fname, 1);
                return 1;
            }

            iParentUID = getObjectFromHandle((long)hParent);
            if (iParentUID != 0)
            {
                getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
                if (iParentType != __GO_FIGURE__ && iParentType != __GO_UIMENU__)
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu");
                    return FALSE;
                }

                // Set the parent property
                callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), &hParent, sci_handles, 1, 1, "parent");

                // Set the flag to avoid setting the parent two times
                parentDefined = TRUE;
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu");
                return FALSE;
            }

            // First input parameter which is a property name
            beginIndex = 2;
        }
    }
    /**
    * Even number of input arguments
    * All odd inputs are property names
    * All even inputs are property values
    */
    else
    {
        // First input parameter which is a property name
        beginIndex = 1;
    }

    /* Read and set all properties */
    for (inputIndex = beginIndex; inputIndex < nbInputArgument(pvApiCtx); inputIndex = inputIndex + 2)
    {
        int* piAddrValue = NULL;
        int* piAddrProperty = NULL;

        int isUserDataProperty = 0;
        int iPropertyValuePositionIndex = inputIndex + 1;
        size_t posStackOrAdr = 0;

        /* Read property name */
        if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex);
            return FALSE;
        }
        else
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddrProperty);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            if (getAllocatedSingleString(pvApiCtx, piAddrProperty, &propertyName))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex);
                return 1;
            }

            if (stricmp(propertyName, "parent") == 0)
            {
                parentDefined = TRUE;
            }

            isUserDataProperty = (stricmp(propertyName, "user_data") == 0) || (stricmp(propertyName, "userdata") == 0);
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, iPropertyValuePositionIndex, &piAddrValue);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            freeAllocatedSingleString(propertyName);
            return 1;
        }

        if (isUserDataProperty)
        {
            nbRow = -1;
            nbCol = -1;
            setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, 0, 0, 0, propertyName);
        }
        else
        {
            /* Read property value */
            switch (getInputArgumentType(pvApiCtx, iPropertyValuePositionIndex))
            {
                case sci_matrix:
                {
                    double* pdblValue = NULL;
                    sciErr = getMatrixOfDouble(pvApiCtx, piAddrValue, &nbRow, &nbCol, &pdblValue);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }

                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pdblValue, sci_matrix, nbRow, nbCol, propertyName);
                    break;
                }
                case sci_strings:
                {
                    char* pstValue = NULL;
                    if (getAllocatedSingleString(pvApiCtx, piAddrValue, &pstValue))
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }

                    nbRow = (int)strlen(pstValue);
                    nbCol = 1;
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pstValue, sci_strings, nbRow, nbCol, propertyName);
                    freeAllocatedSingleString(pstValue);
                    break;
                }
                case sci_handles:
                {
                    long long* phValues = NULL;
                    sciErr = getMatrixOfHandle(pvApiCtx, piAddrValue, &nbRow, &nbCol, &phValues);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, iPropertyValuePositionIndex);
                        freeAllocatedSingleString(propertyName);
                        return 1;
                    }
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), phValues, sci_handles, nbRow, nbCol, propertyName);
                    break;
                }
                case sci_list:
                {
                    getListItemNumber(pvApiCtx, piAddrValue, &nbRow);
                    nbCol = 1;
                    setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, sci_list, nbRow, nbCol, propertyName);
                    break;
                }
                default:
                {
                    setStatus = SET_PROPERTY_ERROR;
                    break;
                }
            }
        }

        if (setStatus == SET_PROPERTY_ERROR)
        {
            Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName);
            freeAllocatedSingleString(propertyName);
            return FALSE;
        }

        freeAllocatedSingleString(propertyName);
    }

    /* If the parent is not given, the current figure is set as parent */
    if (!parentDefined && (nbInputArgument(pvApiCtx) != 0))
    {
        // Set the parent property
        iCurrentFigure = getCurrentFigure();
        if (iCurrentFigure == 0)
        {
            iCurrentFigure = createNewFigureWithAxes();
        }
        setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle));
    }

    /* Create return variable */
    nbRow = 1;
    nbCol = 1;
    // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr".
    if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #23
0
ファイル: sci_TCL_SetVar.c プロジェクト: kingdwd/scilab
/*--------------------------------------------------------------------------*/
int sci_TCL_SetVar(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl2 = NULL;
    char* l2 = NULL;

    int* piAddrl1 = NULL;
    int* piAddrStr = NULL;
    char *VarName = NULL;

    static int n1, m1;
    static int n2, m2;

    int paramoutINT = 0;
    Tcl_Interp *TCLinterpreter = NULL;

    CheckInputArgument(pvApiCtx, 2, 3);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (getTclInterp() == NULL)
    {
        releaseTclInterp();
        Scierror(999, _("%s: Error main TCL interpreter not initialized.\n"), fname);
        return 0;
    }
    releaseTclInterp();

    if (nbInputArgument(pvApiCtx) == 3)
    {
        // three arguments given - get a pointer on the slave interpreter
        if (checkInputArgumentType(pvApiCtx, 3, sci_strings))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrl2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 3.
            if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 3);
                return 1;
            }

            TCLinterpreter = Tcl_GetSlave(getTclInterp(), (l2));
            freeAllocatedSingleString(l2);
            if (TCLinterpreter == NULL)
            {
                releaseTclInterp();
                Scierror(999, _("%s: No such slave interpreter.\n"), fname);
                return 0;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname, 3);
            return 0;
        }
    }
    else
    {
        // only two arguments given - use the main interpreter
        TCLinterpreter = getTclInterp();
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings) && checkInputArgumentType(pvApiCtx, 2, sci_strings))
    {
        char **Str = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &VarName))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrStr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m1, &n1, &Str))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
            return 1;
        }


        // Efface valeur precedente
        Tcl_UnsetVar(TCLinterpreter, VarName, TCL_GLOBAL_ONLY);

        if ( (m1 == 1) && (n1 == 1) )
        {
            paramoutINT = SetVarAString(TCLinterpreter, VarName, Str);
        }
        else
        {
            paramoutINT = SetVarStrings(TCLinterpreter, VarName, Str, m1, n1);
        }

        freeAllocatedSingleString(VarName);
        freeAllocatedMatrixOfString(m1, n1, Str);
    }
    else if (checkInputArgumentType(pvApiCtx, 1, sci_strings) && checkInputArgumentType(pvApiCtx, 2, sci_matrix))
    {
#define COMPLEX 1
        int *header = NULL;
        int Cmplx;
        double* l1 = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of double at position 1.
        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &VarName))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
            return 1;
        }

        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            freeAllocatedSingleString(VarName);
            return 1;
        }

        if (isVarComplex(pvApiCtx, piAddrl1))
        {
            Scierror(999, _("This function doesn't work with Complex.\n"));
            freeAllocatedSingleString(VarName);
            releaseTclInterp();
            return 0;
        }

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
            freeAllocatedSingleString(VarName);
            return 1;
        }

        if ( (m1 == 0) && (n1 == 0) )
        {
            Scierror(999, _("[] doesn't work with Tcl/Tk.\n"));
            freeAllocatedSingleString(VarName);
            releaseTclInterp();
            return 0;
        }

        if ( (m1 == 1) && (n1 == 1) )
        {
            paramoutINT = SetVarScalar(TCLinterpreter, VarName, *l1);
        }
        else
        {
            paramoutINT = SetVarMatrix(TCLinterpreter, VarName, l1, m1, n1);
        }

        freeAllocatedSingleString(VarName);
    }
    else
    {
        if ((!checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), fname , 1);
        }
        if ((!checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Matrix expected.\n"), fname , 2);
        }
        releaseTclInterp();
        return 0;
    }

    if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, paramoutINT))
    {
        Scierror(999, _("%s: Memory allocation error.\n"), fname);
        return 1;
    }

    releaseTclInterp();

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);

    return 0;
}
コード例 #24
0
ファイル: sci_uigetcolor.c プロジェクト: scitao/scilab
/*--------------------------------------------------------------------------*/
int sci_uigetcolor(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    //WARNING ALL NEW DECALRATIONS ARE HERE IF YOUR HAVE MANY FUNCTIONS
    //IN THE FILE YOU HAVE PROBABLY TO MOVE DECLARATIONS IN GOOD FUNCTIONS
    int* piAddrredAdr = NULL;
    double* redAdr = NULL;
    int* piAddrtitleAdr = NULL;
    char* titleAdr = NULL;
    int* piAddrgreenAdr = NULL;
    double* greenAdr = NULL;
    int* piAddrblueAdr = NULL;
    double* blueAdr = NULL;

    int colorChooserID = 0;
    int firstColorIndex = 0;

    int nbRow = 0, nbCol = 0;

    double *selectedRGB = NULL;

    CheckInputArgument(pvApiCtx, 0, 4);

    if ((nbOutputArgument(pvApiCtx) != 1) && (nbOutputArgument(pvApiCtx) != 3)) /* Bad use */
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d or %d expected.\n"), fname, 1, 3);
        return FALSE;
    }

    /* Rhs==1: title or [R, G, B] given */
    if (nbInputArgument(pvApiCtx) == 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                return 1;
            }

            if ((nbRow != 1) || (nbCol != 3))
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 1, 3);
                return FALSE;
            }
        }
        else if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* Title and [R, G, B] given */
    if (nbInputArgument(pvApiCtx) == 2)
    {
        /* Title */
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname, 1);
            return FALSE;
        }

        /* [R, G, B] */
        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow*nbCol != 3)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A 1 x %d real row vector expected.\n"), fname, 2, 3);
            return FALSE;
        }
    }

    /* No title given but colors given with separate values */
    if (nbInputArgument(pvApiCtx) == 3)
    {
        firstColorIndex = 1;
    }

    /* Title and colors given with separate values */
    if (nbInputArgument(pvApiCtx) == 4)
    {
        firstColorIndex = 2;

        /* Title */
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrtitleAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 1.
            if (getAllocatedSingleString(pvApiCtx, piAddrtitleAdr, &titleAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real or a string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* R, G, B given */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        /* Default red value */
        if ((checkInputArgumentType(pvApiCtx, firstColorIndex, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex, &piAddrredAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrredAdr, &nbRow, &nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex);
            return FALSE;
        }

        /* Default green value */
        if (checkInputArgumentType(pvApiCtx, firstColorIndex + 1, sci_matrix))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 1, &piAddrgreenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex + 1.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrgreenAdr, &nbRow, &nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 1);
            return FALSE;
        }

        /* Default blue value */
        if (checkInputArgumentType(pvApiCtx, firstColorIndex + 2, sci_matrix))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, firstColorIndex + 2, &piAddrblueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position firstColorIndex + 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrblueAdr, &nbRow, &nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
                return 1;
            }

            if (nbRow*nbCol != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, firstColorIndex + 2);
            return FALSE;
        }
    }

    /* Create the Java Object */
    colorChooserID = createColorChooser();

    /* Title */
    if (titleAdr != 0)
    {
        setColorChooserTitle(colorChooserID, titleAdr);
        freeAllocatedSingleString(titleAdr);
    }

    /* Default red value */
    if (redAdr != 0)
    {
        if (greenAdr != 0 ) /* All values given in first input argument */
        {
            setColorChooserDefaultRGBSeparateValues(colorChooserID, (int)redAdr[0], (int)greenAdr[0], (int)blueAdr[0]);
        }
        else
        {
            setColorChooserDefaultRGB(colorChooserID, redAdr);
        }
    }

    /* Display it and wait for a user input */
    colorChooserDisplayAndWait(colorChooserID);

    /* Return the selected color */
    /* Read the user answer */
    selectedRGB = getColorChooserSelectedRGB(colorChooserID);

    if (selectedRGB[0] >= 0) /* The user selected a color */
    {

        nbRow = 1;
        if (nbOutputArgument(pvApiCtx) == 1)
        {
            nbCol = 3;
            sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, selectedRGB);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            nbCol = 1;

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            redAdr[0] = selectedRGB[0];

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            greenAdr[0] = selectedRGB[1];

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            blueAdr[0] = selectedRGB[2];

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
        }
    }
    else /* The user canceled */
    {
        nbRow = 0;
        nbCol = 0;
        if (nbOutputArgument(pvApiCtx) == 1)
        {
            /* Return [] */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }


            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &redAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &greenAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &blueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }


            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
        }
    }

    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #25
0
ファイル: sci_x_dialog.c プロジェクト: ZhanlinWang/scilab
/*--------------------------------------------------------------------------*/
int sci_x_dialog(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrlabelsAdr = NULL;
    int* piAddrinitialValueAdr = NULL;
    double* emptyMatrixAdr = NULL;

    int nbRow = 0, nbCol = 0;

    int messageBoxID = 0;

    char **initialValueAdr = 0;

    char **labelsAdr = 0;

    int userValueSize = 0;
    char **userValue = NULL;

    CheckInputArgument(pvApiCtx, 1, 2);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrlabelsAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 1.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrlabelsAdr, &nbRow, &nbCol, &labelsAdr))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 1);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 1);
        return FALSE;
    }

    /* Create the Java Object */
    messageBoxID = createMessageBox();

    /* Title is a default title */
    setMessageBoxTitle(messageBoxID, _("Scilab Input Value Request"));
    /* Message */
    setMessageBoxMultiLineMessage(messageBoxID, labelsAdr, nbCol * nbRow);
    freeAllocatedMatrixOfString(nbRow, nbCol, labelsAdr);

    if (nbInputArgument(pvApiCtx) == 2)
    {
        if (VarType(2) ==  sci_strings)
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrinitialValueAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 2.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrinitialValueAdr, &nbRow, &nbCol, &initialValueAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: Vector of strings expected.\n"), fname, 2);
            return FALSE;
        }

        setMessageBoxInitialValue(messageBoxID, initialValueAdr, nbCol * nbRow);
        freeAllocatedMatrixOfString(nbRow, nbCol, initialValueAdr);
    }

    /* Display it and wait for a user input */
    messageBoxDisplayAndWait(messageBoxID);

    /* Read the user answer */
    userValueSize = getMessageBoxValueSize(messageBoxID);
    if (userValueSize == 0)
    {
        nbRow = 0;
        nbCol = 0;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, &emptyMatrixAdr);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }
    }
    else
    {
        userValue = getMessageBoxValue(messageBoxID);

        nbCol = 1;
        CreateVarFromPtr(nbInputArgument(pvApiCtx) + 1, MATRIX_OF_STRING_DATATYPE, &userValueSize, &nbCol, userValue);
        /* TO DO : delete of userValue */
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #26
0
/*--------------------------------------------------------------------------*/
int sci_uigetfont(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddrfontNameAdr  = NULL;
    int* piAddrfontSizeAdr  = NULL;
    int* piAddrboldAdr      = NULL;
    int* boldAdr            = NULL;
    int* piAddritalicAdr    = NULL;
    int* italicAdr          = NULL;
    double* fontSizeAdr     = NULL;

    int fontChooserID = 0;
    int nbRow = 0;
    int nbCol = 0;

    char **fontNameAdr = NULL;
    int fontNameSize   = 0;

    char *selectedFontName  = NULL;
    int selectedFontSize    = 0;
    BOOL selectedBold       = FALSE;
    BOOL selectedItalic     = FALSE;

    CheckInputArgument(pvApiCtx, 0, 4);
    CheckOutputArgument(pvApiCtx, 1, 4);

    /* Default font name */
    if (nbInputArgument(pvApiCtx) >= 1)
    {
        if ((checkInputArgumentType(pvApiCtx, 1, sci_strings)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrfontNameAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of string at position 1.
            if (getAllocatedMatrixOfString(pvApiCtx, piAddrfontNameAdr, &nbRow, &nbCol, &fontNameAdr))
            {
                Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                return 1;
            }

            fontNameSize = nbRow * nbCol;
            if (fontNameSize != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
                return FALSE;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
            return FALSE;
        }
    }

    /* Default font size */
    if (nbInputArgument(pvApiCtx) >= 2)
    {
        if ((checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrfontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of double at position 2.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrfontSizeAdr, &nbRow, &nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 2);
                return FALSE;
            }
        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A real expected.\n"), fname, 2);
            return FALSE;
        }
    }

    /* Is the default font bold ? */
    if (nbInputArgument(pvApiCtx) >= 3)
    {
        if ((checkInputArgumentType(pvApiCtx, 3, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrboldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 3.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddrboldAdr, &nbRow, &nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 3);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
                return FALSE;
            }

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
            return FALSE;
        }
    }

    /* Is the default font italic ? */
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        if ((checkInputArgumentType(pvApiCtx, 4, sci_boolean)))
        {
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddritalicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            // Retrieve a matrix of boolean at position 4.
            sciErr = getMatrixOfBoolean(pvApiCtx, piAddritalicAdr, &nbRow, &nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: Boolean matrix expected.\n"), fname, 4);
                return 1;
            }

            if (nbRow * nbCol != 1)
            {
                freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
                Scierror(999, _("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 4);
                return FALSE;
            }

        }
        else
        {
            freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
            return FALSE;
        }
    }

    /* Create the Java Object */
    fontChooserID = createFontChooser();

    /* Default font */
    if (fontNameAdr != NULL)
    {
        setFontChooserFontName(fontChooserID, fontNameAdr[0]);
    }

    /* Default size */
    if (fontSizeAdr != 0)
    {
        setFontChooserFontSize(fontChooserID, (int)fontSizeAdr[0]);
    }

    /* Default bold */
    if (boldAdr != 0)
    {
        setFontChooserBold(fontChooserID, booltoBOOL(boldAdr[0]));
    }

    /* Default italic */
    if (italicAdr != 0)
    {
        setFontChooserItalic(fontChooserID, booltoBOOL(italicAdr[0]));
    }

    /* Display it and wait for a user input */
    fontChooserDisplayAndWait(fontChooserID);

    /* Return the selected font */

    /* Read the user answer */
    selectedFontName = getFontChooserFontName(fontChooserID);


    if (strcmp(selectedFontName, "")) /* The user selected a font */
    {
        selectedFontSize = getFontChooserFontSize(fontChooserID);
        selectedBold = getFontChooserBold(fontChooserID);
        selectedItalic = getFontChooserItalic(fontChooserID);

        nbRow = 1;
        nbCol = 1;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow, nbCol, (const char * const*) &selectedFontName);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *fontSizeAdr = selectedFontSize;
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *boldAdr = selectedBold;
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            *italicAdr = selectedItalic;
        }
    }
    else /* The user canceled */
    {
        if (selectedFontName)
        {
            freeAllocatedSingleString(selectedFontName);
        }
        nbRow = 0;
        nbCol = 0;
        if (nbOutputArgument(pvApiCtx) >= 1)
        {
            /* Return "" as font name */
            char* fontNameEmpty = NULL;
            if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, nbRow * nbCol, (const char**) &fontNameEmpty))
            {
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 2)
        {
            /* Return [] as font size */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, nbRow, nbCol, &fontSizeAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 3)
        {
            /* Return [] as bold value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 3, nbRow, nbCol, &boldAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }

        if (nbOutputArgument(pvApiCtx) >= 4)
        {
            /* Return [] as italic value */
            sciErr = allocMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 4, nbRow, nbCol, &italicAdr);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
    AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
    AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;

    if (fontNameSize)
    {
        freeAllocatedMatrixOfString(nbRow, nbCol, fontNameAdr);
    }
    ReturnArguments(pvApiCtx);
    return TRUE;
}
コード例 #27
0
ファイル: xs2file.c プロジェクト: quanpan302/scilab
/*--------------------------------------------------------------------------*/
int xs2file(char * fname, ExportFileType fileType )
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    int* piAddrfileName = NULL;
    int* piAddrsciOrientation = NULL;
    int* piAddrquality = NULL;
    double* quality = NULL;

    /* Check input and output sizes */
    CheckOutputArgument(pvApiCtx, 0, 1);
    if (isVectorialExport(fileType) || fileType == JPG_EXPORT)
    {
        CheckInputArgument(pvApiCtx, 2, 3);
    }
    else
    {
        CheckInputArgument(pvApiCtx, 2, 2);
    }

    if ((!checkInputArgumentType(pvApiCtx, 1, sci_matrix)) && (!checkInputArgumentType(pvApiCtx, 1, sci_handles)))
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: An integer or a handle expected.\n"), fname, 1);
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 1;
    }

    if ( (checkInputArgumentType(pvApiCtx, 2, sci_strings)) )
    {
        char **fileName = NULL;
        char *real_filename = NULL;
        float jpegCompressionQuality = 0.95f;
        ExportOrientation orientation = EXPORT_PORTRAIT; /* default orientation */
        int m1 = 0, n1 = 0;
        int figurenum = -1;
        char* figureUID = NULL;
        char *status = NULL;

        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        /* get handle by figure number */
        if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
        {
            // Retrieve a matrix of double at position 1.
            int* l1 = NULL;
            sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddrl1, &m1, &n1, &l1);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1);
                return 1;
            }

            if (m1 * n1 != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1);
                return 1;
            }

            figurenum = *l1;
            if (!sciIsExistingFigure(figurenum))
            {
                Scierror(999, "%s: Input argument #%d must be a valid figure_id.\n", fname, 1);
                return 1;
            }
            figureUID = (char*)getFigureFromIndex(figurenum);
        }
        /* check given handle */
        else if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
        {
            int iHandleType = -1;
            int* piHandleType = &iHandleType;
            long long* l1 = NULL;

            // Retrieve a matrix of handle at position 1.
            sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument %d: Handle matrix expected.\n"), fname, 1);
                return 1;
            }

            if (m1 * n1 != 1)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1);
                return 1;
            }

            figureUID = (char*)getObjectFromHandle((unsigned long) * l1);
            if (figureUID == NULL)
            {
                Scierror(999, _("%s: Input argument #%d must be a valid handle.\n"), fname, 1);
                return 1;
            }

            getGraphicObjectProperty(figureUID, __GO_TYPE__, jni_int, (void**)&piHandleType);

            if (iHandleType != __GO_FIGURE__)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A ''%s'' handle expected.\n"), fname, 1, "Figure");
                return 1;
            }
        }
        else
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A scalar or figure handle expected.\n"), fname, 1);
            return 1;
        }

        /* get file name */
        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrfileName);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // Retrieve a matrix of string at position 2.
        if (getAllocatedMatrixOfString(pvApiCtx, piAddrfileName, &m1, &n1, &fileName))
        {
            Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
            return 1;
        }

        if (m1 * n1 == 1)
        {
            if (nbInputArgument(pvApiCtx) == 3)
            {
                int nbCol = 0;
                int nbRow = 0;

                if (isVectorialExport(fileType))
                {

                    char **sciOrientation = NULL;

                    if ((!checkInputArgumentType(pvApiCtx, 3, sci_strings)))
                    {
                        freeAllocatedMatrixOfString(m1, n1, fileName);
                        Scierror(999, _("%s: Wrong type for input argument #%d: Single character string expected.\n"), fname, 3);
                        return 1;
                    }

                    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrsciOrientation);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    // Retrieve a matrix of string at position 3.
                    if (getAllocatedMatrixOfString(pvApiCtx, piAddrsciOrientation, &nbRow, &nbCol, &sciOrientation))
                    {
                        freeAllocatedMatrixOfString(m1, n1, fileName);
                        Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3);
                        return 1;
                    }

                    if (nbRow * nbCol == 1)
                    {
                        /* Value should be 'landscape' or 'portrait' but check only the first character */
                        /* for compatibility with Scilab 4*/
                        if (strcmp(sciOrientation[0], "landscape") == 0 || strcmp(sciOrientation[0], "l") == 0)
                        {
                            freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
                            orientation = EXPORT_LANDSCAPE;
                        }
                        else if (strcmp(sciOrientation[0], "portrait") == 0 || strcmp(sciOrientation[0], "p") == 0)
                        {
                            freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
                            orientation = EXPORT_PORTRAIT;
                        }
                        else
                        {
                            freeAllocatedMatrixOfString(m1, n1, fileName);
                            freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
                            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 3, "portrait", "landscape");
                            return 1;
                        }
                    }
                    else
                    {
                        freeAllocatedMatrixOfString(m1, n1, fileName);
                        freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
                        Scierror(999, _("%s: Wrong size for input argument #%d: Single character string expected.\n"), fname, 3);
                        return 1;
                    }
                }
                else
                {
                    sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrquality);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    // Retrieve a matrix of double at position 3.
                    sciErr = getMatrixOfDouble(pvApiCtx, piAddrquality, &nbRow, &nbCol, &quality);
                    if (sciErr.iErr)
                    {
                        freeAllocatedMatrixOfString(m1, n1, fileName);
                        printError(&sciErr, 0);
                        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                        return 1;
                    }

                    if (nbRow != 1 || nbCol != 1 || *quality < 0 || *quality > 1)
                    {
                        freeAllocatedMatrixOfString(m1, n1, fileName);
                        Scierror(999, _("%s: Wrong type for input argument #%d: A real between 0 and 1 expected.\n"), fname, 3);
                        return 1;
                    }
                    jpegCompressionQuality = (float) * quality;
                }
            }

            /* Replaces SCI, ~, HOME, TMPDIR by the real path */
            real_filename = expandPathVariable(fileName[0]);

            /* Call the function for exporting file */
            status = exportToFile(figureUID, real_filename, fileType, jpegCompressionQuality, orientation);

            /* free pointers no more used */
            if (real_filename)
            {
                FREE(real_filename);
                real_filename = NULL;
            }
            freeAllocatedMatrixOfString(m1, n1, fileName);

            /* treat errors */
            if (strlen(status) != 0)
            {
                Scierror(999, _("%s: %s\n"), fname, status);
                return 1;
            }
        }
        else
        {
            freeAllocatedMatrixOfString(m1, n1, fileName);
            Scierror(999, _("%s: Wrong size for input argument #%d: Single character string expected.\n"), fname, 2);
            return 1;
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: Single character string expected.\n"), fname, 2);
        return 1;
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
コード例 #28
0
ファイル: sci_plot2d.c プロジェクト: FOSSEE-Internship/scilab
/*------------------------------------------------------------------------*/
int sci_plot2d(char* fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    double* lt = NULL;
    int iTypel1 = 0;
    int iTypel2 = 0;
    int lw = 0;

    int m1 = 0, n1 = 0, m2 = 0, n2 = 0;
    int test = 0, i = 0, j = 0, iskip = 0;
    int frame_def = 8;
    int *frame = &frame_def;
    int axes_def = 1;
    int *axes = &axes_def;

    /* F.Leray 18.05.04 : log. case test*/
    int size_x = 0, size_y = 0;
    char dataflag = 0;

    char* logFlags = NULL;
    int* style = NULL;
    double* rect = NULL;
    char* strf = NULL;
    char* legend = NULL;
    int* nax = NULL;
    BOOL flagNax = FALSE;
    char strfl[4];
    BOOL freeStrf = FALSE;

    rhs_opts opts[] =
    {
        { -1, "axesflag", -1, 0, 0, NULL},
        { -1, "frameflag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "logflag", -1, 0, 0, NULL},
        { -1, "nax", -1, 0, 0, NULL},
        { -1, "rect", -1, 0, 0, NULL},
        { -1, "strf", -1, 0, 0, NULL},
        { -1, "style", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    if (nbInputArgument(pvApiCtx) == 0)
    {
        sci_demo(fname, pvApiCtx);
        return 0;
    }

    CheckInputArgument(pvApiCtx, 1, 9);

    iskip = 0;
    if (getOptionals(pvApiCtx, fname, opts) == 0)
    {
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
    {
        /* logflags */
        GetLogflags(pvApiCtx, fname, 1, opts, &logFlags);
        iskip = 1;
    }

    if (FirstOpt(pvApiCtx) == 2 + iskip)                                /** plot2d([loglags,] y, <opt_args>); **/
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // the argument can be a matrix of doubles or other
        // If it is not a matrix of doubles, call overload
        if (iTypel2 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(1);
            return 0;
        }

        if (m2 == 1 && n2 > 1)
        {
            m2 = n2;
            n2 = 1;
        }

        m1 = m2;
        n1 = n2;

        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &l1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            Scierror(999, _("%s: Memory allocation error.\n"), fname);
            return 1;
        }

        for (i = 0; i < m2 ; ++i)
        {
            for (j = 0 ; j < n2 ;  ++j)
            {
                *(l1 + i + m2 * j) = (double) i + 1;
            }
        }
    }
    else if (FirstOpt(pvApiCtx) >= 3 + iskip)     /** plot2d([loglags,] x, y[, style [,...]]); **/
    {
        /* x */
        sciErr = getVarAddressFromPosition(pvApiCtx, 1 + iskip, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl1, &iTypel1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // x can be a matrix of doubles or other
        // If x is not a matrix of doubles, call overload
        if (iTypel1 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(1);
            return 0;
        }

        /* y */
        sciErr = getVarAddressFromPosition(pvApiCtx, 2 + iskip, &piAddrl2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        sciErr = getVarType(pvApiCtx, piAddrl2, &iTypel2);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        // y can be a matrix of doubles or other
        // If y is not a matrix of doubles, call overload
        if (iTypel2 == sci_matrix)
        {

            // Retrieve a matrix of double at position 1 + iskip.
            sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2 + iskip);
                return 1;
            }
        }
        else
        {
            OverLoad(2);
            return 0;
        }

        test = (m1 * n1 == 0) ||
               ((m1 == 1 || n1 == 1) && (m2 == 1 || n2 == 1) && (m1 * n1 == m2 * n2))  ||
               ((m1 == m2) && (n1 == n2)) ||
               ((m1 == 1 && n1 == m2) || (n1 == 1 && m1 == m2));
        //CheckDimProp
        if (!test)
        {
            Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
            return 1;
        }

        if (m1 * n1 == 0)
        {
            /* default x=1:n */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            if (m2 == 1 && n2 > 1)
            {
                m2 = n2;
                n2 = 1;
            }
            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *(lt + i + m2 * j) = (double) i + 1;
                }
            }
            m1 = m2;
            n1 = n2;
            l1 = lt;
        }
        else if ((m1 == 1 || n1 == 1) && (m2 != 1 && n2 != 1))
        {
            /* a single x vector for mutiple columns for y */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m2, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            for (i = 0; i < m2 ; ++i)
            {
                for (j = 0 ; j < n2 ;  ++j)
                {
                    *(lt + i + m2 * j) = *(l1 + i);
                }
            }
            m1 = m2;
            n1 = n2;
            l1 = lt;
        }
        else if ((m1 == 1 && n1 == 1) && (n2 != 1))
        {
            /* a single y row vector  for a single x */
            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n2, &lt);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                return 1;
            }

            for (j = 0 ; j < n2 ;  ++j)
            {
                lt[j] = *l1;
            }
            n1 = n2;
            l1 = lt;
        }
        else
        {
            if (m2 == 1 && n2 > 1)
            {
                m2 = n2;
                n2 = 1;
            }
            if (m1 == 1 && n1 > 1)
            {
                m1 = n1;
                n1 = 1;
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Wrong number of mandatory input arguments. At least %d expected.\n"), fname, 1);
        return 0;
    }

    if (n1 == -1 || n2 == -1 || m1 == -1 || m2 == -1)
    {
        Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); /* @TODO : detail error */
        return 0;
    }

    sciGetStyle(pvApiCtx, fname, 3 + iskip, n1, opts, &style);
    GetStrf(pvApiCtx, fname, 4 + iskip, opts, &strf);
    GetLegend(pvApiCtx, fname, 5 + iskip, opts, &legend);
    GetRect(pvApiCtx, fname, 6 + iskip, opts, &rect);
    GetNax(pvApiCtx, 7 + iskip, opts, &nax, &flagNax);

    if (iskip == 0)
    {
        GetLogflags(pvApiCtx, fname, 8, opts, &logFlags);
    }

    freeStrf = !isDefStrf(strf);

    // Check strf [0-1][0-8][0-5]
    if (!isDefStrf(strf) && (strlen(strf) != 3 || strf[0] < '0' || strf[0] > '1' || strf[1] < '0' || strf[1] > '8' || strf[2] < '0' || strf[2] > '5'))
    {
        Scierror(999, _("%s: Wrong value for strf option: %s.\n"), fname, strf);
        if (freeStrf)
        {
            freeAllocatedSingleString(strf);
        }
        return -1;
    }

    if (isDefStrf(strf))
    {
        strcpy(strfl, DEFSTRFN);

        strf = strfl;
        if (!isDefRect(rect))
        {
            strfl[1] = '7';
        }
        if (!isDefLegend(legend))
        {
            strfl[0] = '1';
        }

        GetOptionalIntArg(pvApiCtx, fname, 9, "frameflag", &frame, 1, opts);
        if (frame != &frame_def)
        {
            if (*frame >= 0 && *frame <= 8)
            {
                strfl[1] = (char)(*frame + 48);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for frameflag option.\n"), fname);
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                return -1;
            }
        }

        GetOptionalIntArg(pvApiCtx, fname, 9, "axesflag", &axes, 1, opts);
        if (axes != &axes_def)
        {
            if ((*axes >= 0 && *axes <= 5) || *axes == 9)
            {
                strfl[2] = (char)(*axes + 48);
            }
            else
            {
                Scierror(999, _("%s: Wrong value for axesflag option.\n"), fname);
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                return -1;
            }
        }
    }

    /* Make a test on log. mode : available or not depending on the bounds set by Rect arg. or xmin/xmax :
       Rect case :
       - if the min bound is strictly posivite, we can use log. mode
       - if not, send error message
       x/y min/max case:
       - we find the first strictly positive min bound in Plo2dn.c ?? */

    switch (strf[1])
    {
        case '0':
            /* no computation, the plot use the previous (or default) scale */
            break;
        case '1' :
        case '3' :
        case '5' :
        case '7':
            /* based on Rect arg */
            if (rect[0] > rect[2] || rect[1] > rect[3])
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Impossible status min > max in x or y rect data.\n"), fname);
                return -1;
            }

            if (rect[0] <= 0. && logFlags[1] == 'l') /* xmin */
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Bounds on x axis must be strictly positive to use logarithmic mode.\n"), fname);
                return -1;
            }

            if (rect[1] <= 0. && logFlags[2] == 'l') /* ymin */
            {
                if (freeStrf)
                {
                    freeAllocatedSingleString(strf);
                }
                Scierror(999, _("%s: Bounds on y axis must be strictly positive to use logarithmic mode.\n"), fname);
                return -1;
            }

            break;
        case '2' :
        case '4' :
        case '6' :
        case '8':
        case '9':
            /* computed from the x/y min/max */
            if ((int)strlen(logFlags) < 1)
            {
                dataflag = 'g';
            }
            else
            {
                dataflag = logFlags[0];
            }

            switch (dataflag)
            {
                case 'e' :
                    size_x = (m1 != 0) ? 2 : 0;
                    break;
                case 'o' :
                    size_x = m1;
                    break;
                case 'g' :
                default  :
                    size_x = (n1 * m1);
                    break;
            }

            if (size_x != 0)
            {
                if (logFlags[1] == 'l' && sciFindStPosMin((l1), size_x) <= 0.0)
                {
                    if (freeStrf)
                    {
                        freeAllocatedSingleString(strf);
                    }
                    Scierror(999, _("%s: At least one x data must be strictly positive to compute the bounds and use logarithmic mode.\n"), fname);
                    return -1;
                }
            }

            size_y = (n1 * m1);

            if (size_y != 0)
            {
                if (logFlags[2] == 'l' && sciFindStPosMin((l2), size_y) <= 0.0)
                {
                    if (freeStrf)
                    {
                        freeAllocatedSingleString(strf);
                    }
                    Scierror(999, _("%s: At least one y data must be strictly positive to compute the bounds and use logarithmic mode\n"), fname);
                    return -1;
                }
            }

            break;
    }

    // open a figure if none already exists
    getOrCreateDefaultSubwin();

    Objplot2d (1, logFlags, (l1), (l2), &n1, &m1, style, strf, legend, rect, nax, flagNax);

    // Allocated by sciGetStyle (get_style_arg function in GetCommandArg.c)
    FREE(style);

    if (freeStrf)
    {
        freeAllocatedSingleString(strf);
    }

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
コード例 #29
0
/*--------------------------------------------------------------------------*/
int sci_ClipBoard(char *fname, void* pvApiCtx)
{
    SciErr sciErr;

    int* piAddr1   = NULL;
    int* piAddrl1   = NULL;
    int* piAddrStr  = NULL;
    double* pdbll1  = NULL;
    int* pil1       = NULL;

    static int n1 = 0, m1 = 0;
    char* param1 = NULL;
    char* param2 = NULL;

    nbInputArgument(pvApiCtx) = Max(0, nbInputArgument(pvApiCtx));
    CheckInputArgument(pvApiCtx, 0, 2);
    CheckOutputArgument(pvApiCtx, 0, 1);

    if ( getScilabMode() != SCILAB_NWNI )
    {
        /*--------------------*/
        /* clipboard("paste") */
        /*--------------------*/
        if (nbInputArgument(pvApiCtx) == 1)
        {
            if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
            {
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 1.
                if (getAllocatedSingleString(pvApiCtx, piAddrl1, &param1))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                    return 1;
                }

                if ( ( strcmp(param1, "paste") == 0 ) || ( strcmp(param1, "pastespecial") == 0 ) )
                {
                    /* Use the Java clipboard (CallScilabBridge.java returns "" if clipboard could not be read) */
                    char *output = getClipboardContents();


                    m1 = (int)strlen(output);
                    n1 = 1;

                    if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, output))
                    {
                        freeAllocatedSingleString(param1);
                        Scierror(999, _("%s: Memory allocation error.\n"), fname);
                        return 1;
                    }

                    /* TO DO a delete [] and not a FREE */
                    FREE(output);
                    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;

                    freeAllocatedSingleString(param1);
                    ReturnArguments(pvApiCtx);
                    return TRUE;
                }
                else
                {
                    freeAllocatedSingleString(param1);

                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "paste", "pastespecial");
                    return FALSE;
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1);
                return FALSE;
            }
        }
        else if (nbInputArgument(pvApiCtx) == 2)
        {
            if (checkInputArgumentType(pvApiCtx, 1, sci_strings))
            {
                /* Get the first argument: should be "copy" or "do" */
                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 1.
                if (getAllocatedSingleString(pvApiCtx, piAddrl1, &param1))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
                    return 1;
                }

                if (( strcmp(param1, "do") != 0 ) && ( strcmp(param1, "copy") != 0 ))
                {
                    freeAllocatedSingleString(param1);
                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 1, "do", "copy");
                    return FALSE;
                }

                if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
                {

                    /*-------------------------------------------*/
                    /* clipboard("do", {"paste","copy","empty"}) */
                    /*-------------------------------------------*/

                    /* @TODO : should be remplaced by an enum */
                    if ( strcmp(param1, "do") == 0 )
                    {
                        freeAllocatedSingleString(param1);

                        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            return 1;
                        }

                        // Retrieve a matrix of double at position 2.
                        if (getAllocatedSingleString(pvApiCtx, piAddrl1, &param2))
                        {
                            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                            return 1;
                        }

                        if ( strcmp(param2, "paste") == 0 )
                        {
                            /* Call Java to do the job */
                            pasteClipboardIntoConsole();
                        }
                        else if ( strcmp(param2, "copy") == 0 )
                        {
                            /* Call Java to do the job */
                            copyConsoleSelection();
                        }
                        else if ( strcmp(param2, "empty") == 0 )
                        {
                            /* Call Java to do the job */
                            emptyClipboard();
                        }
                        else
                        {
                            freeAllocatedSingleString(param2);
                            Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s' or '%s' expected.\n"), fname, 2, "copy", "paste", "empty");
                            return FALSE;
                        }

                        m1 = 0;
                        n1 = 0;

                        freeAllocatedSingleString(param2);

                        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
                            return 1;
                        }

                        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                        ReturnArguments(pvApiCtx);
                        return TRUE;
                    }

                    /*-------------------------*/
                    /* clipboard("copy", data) */
                    /*-------------------------*/

                    else if ( strcmp(param1, "copy") == 0 )
                    {
                        char *TextToPutInClipboard = NULL;
                        char **Str = NULL;
                        int m2 = 0, n2 = 0;

                        freeAllocatedSingleString(param1);

                        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrStr);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            return 1;
                        }

                        // Retrieve a matrix of string at position 2.
                        if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m2, &n2, &Str))
                        {
                            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                            return 1;
                        }

                        if (m2 * n2 == 1) /* Single line copy */
                        {
                            TextToPutInClipboard = Str[0];
                            /* Call Java to do the job */
                            setClipboardContents(TextToPutInClipboard);
                        }
                        else /* Multi-line copy */
                        {
                            int i = 0, j = 0, l2 = 0;
                            char *TextToSendInClipboard = NULL;
                            int SizeofTextToSendInClipboard = 0;
                            char **buffer = (char**)MALLOC( (m2 * n2) * sizeof(char *) );
                            if (buffer == NULL)
                            {

                                freeAllocatedMatrixOfString(m2, n2, Str);
                                Scierror(999, _("%s: No more memory.\n"), fname);
                                return FALSE;
                            }

                            for (i = 0; i < m2; i++)
                            {
                                for (j = 0; j < n2; j++)
                                {
                                    SizeofTextToSendInClipboard = SizeofTextToSendInClipboard + (int)strlen(Str[j * m2 + i]) + (int)strlen("\n") + (int)strlen(" ");
                                    buffer[i * n2 + j] = os_strdup(Str[j * m2 + i]);
                                }
                            }

                            TextToSendInClipboard = (char*)MALLOC( (SizeofTextToSendInClipboard) * sizeof(char) );
                            if (TextToSendInClipboard == NULL)
                            {
                                freeAllocatedMatrixOfString(m2, n2, Str);
                                Scierror(999, _("%s: No more memory.\n"), fname);
                                freeArrayOfString(buffer, m2 * n2);

                                return FALSE;
                            }

                            strcpy(TextToSendInClipboard, "");

                            for (i = 0; i < m2; i++)
                            {
                                for (j = 0; j < n2; j++)
                                {
                                    strcat(TextToSendInClipboard, buffer[l2++]);
                                    strcat(TextToSendInClipboard, " ");
                                }
                                if ( i != (m2 - 1) )
                                {
                                    strcat(TextToSendInClipboard, "\n");
                                }
                            }

                            /* Call Java to do the job */
                            setClipboardContents(TextToSendInClipboard);

                            FREE(buffer);
                            buffer = NULL;
                            freeArrayOfString(buffer, m2 * n2);
                            FREE(TextToSendInClipboard);
                            TextToSendInClipboard = NULL;
                        }

                        freeAllocatedMatrixOfString(m2, n2, Str);
                        m1 = 0;
                        n1 = 0;

                        sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1);
                        if (sciErr.iErr)
                        {
                            printError(&sciErr, 0);
                            Scierror(999, _("%s: Memory allocation error.\n"), fname);
                            return 1;
                        }

                        AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                        ReturnArguments(pvApiCtx);
                        return TRUE;
                    }
                }
                else
                {
                    freeAllocatedSingleString(param1);
                    Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
                    return FALSE;
                }
            }

            /*----------------------------------*/
            /* clipboard(fignum, {"EMF","DIB"}) */
            /*----------------------------------*/

            else if (checkInputArgumentType(pvApiCtx, 1, sci_matrix))
            {

                int num_win = -2;

                sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                // Retrieve a matrix of double at position 1.
                sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr1, &m1, &n1, &pil1);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
                    return 1;
                }

                num_win = pil1[0];

                if (m1 * n1 != 1)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: A real expected.\n"), fname, 1);
                    return FALSE;
                }

                if (checkInputArgumentType(pvApiCtx, 2, sci_strings))
                {
                    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl1);
                    if (sciErr.iErr)
                    {
                        printError(&sciErr, 0);
                        return 1;
                    }

                    // Retrieve a matrix of double at position 2.
                    if (getAllocatedSingleString(pvApiCtx, piAddrl1, &param2))
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                        return 1;
                    }

                    if ( ( strcmp(param2, "EMF") == 0 ) || ( strcmp(param2, "DIB") == 0 ) )
                    {
                        if (num_win >= 0)
                        {
                            /* Call Java */
                            if ( strcmp(param2, "EMF") == 0)
                            {
                                /* @TODO create EMF */
                                copyFigureToClipBoard(getFigureFromIndex(num_win));
                            }
                            else
                            {
                                /* @TODO create DIB */
                                copyFigureToClipBoard(getFigureFromIndex(num_win));
                            }

                            m1 = 0;
                            n1 = 0;

                            freeAllocatedSingleString(param2);

                            sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m1, n1, &pdbll1);
                            if (sciErr.iErr)
                            {
                                printError(&sciErr, 0);
                                Scierror(999, _("%s: Memory allocation error.\n"), fname);
                                return 1;
                            }
                            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                            ReturnArguments(pvApiCtx);
                            return TRUE;
                        }
                        else
                        {
                            freeAllocatedSingleString(param2);
                            Scierror(999, _("%s: Wrong value for input argument #%d: Must be >= %d expected.\n"), fname, 1, 0);
                            return FALSE;
                        }

                    }
                    else
                    {
                        freeAllocatedSingleString(param2);
                        Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "EMF", "DIB");
                        return FALSE;
                    }

                }
                else
                {
                    Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
                    return FALSE;
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: string or real expected.\n"), fname, 1);
                return FALSE;
            }
        }
    }
    else
    {
        Scierror(999, _("%s: Function not available in NWNI mode.\n"), fname);
        return FALSE;
    }

    return FALSE;
}