Ejemplo n.º 1
0
/* interface for the previous function Table */
int gw_graphics(void)
{
    nbInputArgument(pvApiCtx) = Max(0, nbInputArgument(pvApiCtx));

    if (pvApiCtx == NULL)
    {
        pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
    }

    pvApiCtx->pstName = (char*)Tab[Fin - 1].name;
    if (getScilabMode() != SCILAB_NWNI)
    {
        if (!loadedDep)
        {
            loadOnUseClassPath("graphics");
            loadedDep = TRUE;
        }
        callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
    }
    else
    {
        if ((strcmp(Tab[Fin - 1].name, "set") == 0 ||
                strcmp(Tab[Fin - 1].name, "delete") == 0 ||
                strcmp(Tab[Fin - 1].name, "get") == 0) &&
                (getInputArgumentType(pvApiCtx, 1) == sci_tlist || getInputArgumentType(pvApiCtx, 1) == sci_mlist))
        {
            callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab));
            return 0;
        }
        else
        {
            Scierror(999, _("Scilab '%s' module disabled in -nogui or -nwni mode.\n"), "graphics");
        }
    }

    return 0;
}
Ejemplo n.º 2
0
/*--------------------------------------------------------------------------*/
int sci_delete(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

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

    int m1 = 0, n1 = 0, lw = 0;
    unsigned long hdl = 0;
    int nb_handles = 0, i = 0, dont_overload = 0;
    int iObjUID = 0;
    int iFigureUID = 0;
    int* piChildrenUID = NULL;
    int iChildrenCount = 0;
    int* childrencount = &iChildrenCount;
    int iHidden = 0;
    int *piHidden = &iHidden;

    int iParentUID = 0;
    int* piParentUID = &iParentUID;
    int iParentType = -1;
    int *piParentType = &iParentType;
    int iObjType = -1;
    int *piObjType = &iObjType;

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

    if (nbInputArgument(pvApiCtx) == 0)               /* Delete current object */
    {
        iObjUID = getCurrentObject();
        if (iObjUID == 0)
        {
            //No current object, we can leave
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }

        hdl = (unsigned long)getHandle(iObjUID);
        dont_overload = 1;
        nb_handles = 1;
    }
    else
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        switch (getInputArgumentType(pvApiCtx, 1))
        {
            case sci_matrix:
            {
                if (isEmptyMatrix(pvApiCtx, piAddrl1))
                {
                    AssignOutputVariable(pvApiCtx, 1) = 0;
                    ReturnArguments(pvApiCtx);
                    return 1;
                }
                else
                {
                    Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1);
                    return 1;
                }
                break;
            }
            case sci_handles:      /* delete Entity given by a handle */

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

                nb_handles = m1 * n1;

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

                    // Retrieve a matrix of double at position 2.
                    if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))   /* Gets the command name */
                    {
                        Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
                        return 1;
                    }
                }
                hdl = (unsigned long) * (l1); /* Puts the value of the Handle to hdl */
                break;
            case sci_strings:      /* delete("all") */
                CheckInputArgument(pvApiCtx, 1, 1);
                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;
                }

                if (strcmp((l2), "all") == 0)
                {
                    int i = 0;
                    int iFigureNumber = sciGetNbFigure();

                    if (iFigureNumber == 0)
                    {
                        //no graphic windows, we can leave
                        AssignOutputVariable(pvApiCtx, 1) = 0;
                        ReturnArguments(pvApiCtx);
                        return 0;
                    }

                    iFigureUID = getCurrentFigure();

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&childrencount);

                    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);

                    for (i = 0; i < childrencount[0]; ++i)
                    {
                        getGraphicObjectProperty(piChildrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
                        if (iHidden == 0)
                        {
                            deleteGraphicObject(piChildrenUID[i]);
                        }
                    }
                    /*
                     * Clone a new Axes object using the Axes model which is then
                     * attached to the 'cleaned' Figure.
                     */
                    cloneAxesModel(iFigureUID);

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

                    return 0;
                }
                else
                {
                    Scierror(999, _("%s: Wrong value for input argument #%d: '%s' expected.\n"), fname, 1, "all");
                    return 0;
                }
                break;
            default:
                // Overload
                lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
                C2F(overload) (&lw, "delete", 6);
                return 0;
        }
    }

    for (i = 0; i < nb_handles; i++)
    {
        int iTemp = 0;
        if (nbInputArgument(pvApiCtx) != 0)
        {
            hdl = (unsigned long) * (l1 + i); /* Puts the value of the Handle to hdl */
        }

        iObjUID = getObjectFromHandle(hdl);

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

        if (isFigureModel(iObjUID) || isAxesModel(iObjUID))
        {
            Scierror(999, _("This object cannot be deleted.\n"));
            return 0;
        }

        /* Object type */
        getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **)&piObjType);
        if (iObjType == __GO_AXES__)
        {
            /* Parent object */
            iParentUID = getParentObject(iObjUID);
            /* Parent type */
            getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType);
        }

        if (iObjType == __GO_LABEL__)
        {
            Scierror(999, _("A Label object cannot be deleted.\n"));
            return 0;
        }

        //bug #11485 : duplicate pobjUID before delete it.
        iTemp = iObjUID;
        deleteGraphicObject(iObjUID);

        /*
         ** All figure must have at least one axe child.
         ** If the last one is removed, add a new default one.
         */
        if (iObjType == __GO_AXES__ && iParentType == __GO_FIGURE__)
        {
            int iChild = 0;
            int iChildCount = 0;
            int *piChildCount = &iChildCount;
            char **pstChildren = NULL;
            int iChildType = -1;
            int *piChildType = &iChildType;
            int iAxesFound = 0;
            int iDefaultAxes = -1;
            int *piDefaultAxes = &iDefaultAxes;

            getGraphicObjectProperty(iParentUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildCount);
            getGraphicObjectProperty(iParentUID, __GO_CHILDREN__, jni_int_vector, (void **)&piChildrenUID);
            getGraphicObjectProperty(iParentUID, __GO_DEFAULT_AXES__, jni_bool, (void **)&piDefaultAxes);

            for (iChild = 0; iChild < iChildCount; iChild++)
            {
                getGraphicObjectProperty(piChildrenUID[iChild], __GO_TYPE__, jni_int, (void **)&piChildType);
                if (iChildType == __GO_AXES__)
                {
                    if (getCurrentSubWin() == iTemp) // Current axes has been deleted
                    {
                        setCurrentSubWin(piChildrenUID[iChild]);
                    }
                    iAxesFound = 1;
                    break;
                }
            }
            if (!iAxesFound && iDefaultAxes != 0)
            {

                /*
                 * Clone a new Axes object using the Axes model which is then
                 * attached to the newly created Figure.
                 */
                cloneAxesModel(iParentUID);
            }
        }
    }

    if (!dont_overload)
    {
        // Overload
        lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
        C2F(overload) (&lw, "delete", 6);
    }
    else
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
    }

    if (l2)
    {
        freeAllocatedSingleString(l2);
    }

    return 0;
}
Ejemplo n.º 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;
}
Ejemplo n.º 4
0
/*--------------------------------------------------------------------------*/
int get_logflags_arg(void* _pvCtx, char *fname, int pos, rhs_opts opts[], char ** logFlags)
{
    int kopt = 0;
    int* piAddr = NULL;

    int iLog = 0;
    char* pstLog = NULL;
    if (pos < FirstOpt(_pvCtx)) //input argument  */
    {
        //no idea of the real goal of this, how input var can have type == 0 Oo
        if (getInputArgumentType(_pvCtx, pos) == 0)
        {
            *logFlags = getDefLogFlags();
            return 1;
        }

        getVarAddressFromPosition(_pvCtx, pos, &piAddr);
    }
    else if ((kopt = FindOpt(_pvCtx, "logflag", opts)) >= 0)//optional argument
    {
        piAddr = opts[kopt].piAddr;
    }
    else
    {
        //take default value
        *logFlags = getDefLogFlags();
        return 1;
    }

    getAllocatedSingleString(_pvCtx, piAddr, &pstLog);
    iLog = (int)strlen(pstLog);
    if (iLog != 2 && iLog != 3)
    {
        Scierror(999, "%s: Wrong size for input argument #%d: %d or %d expected\n", fname, pos, 2, 3);
        return 0;
    }

    if (iLog == 2)
    {
        if ((pstLog[0] != 'l' && pstLog[0] != 'n') || (pstLog[1] != 'l' && pstLog[1] != 'n'))
        {
            //Err = pos;
            SciError(116);
            return 0;
        }

        logFlagsCpy[0] = 'g';
        logFlagsCpy[1] = pstLog[0];
        logFlagsCpy[2] = pstLog[1];
        *logFlags = logFlagsCpy;
    }
    else //iLog == 3
    {
        if (((pstLog[0] != 'g') && (pstLog[0] != 'e') && (pstLog[0] != 'o')) ||
                (pstLog[1] != 'l' && pstLog[1] != 'n') ||
                (pstLog[2] != 'l' && pstLog[2] != 'n'))
        {
            //Err = pos;
            SciError(116);
            return 0;
        }

        *logFlags = pstLog;
    }

    return 1;
}
Ejemplo n.º 5
0
/*--------------------------------------------------------------------------*/
int sci_param3d1(char *fname, void *pvApiCtx)
{
    SciErr sciErr;
    int izcol = 0, isfac = 0;
    double *zcol = NULL;
    static double  ebox_def [6] = { 0, 1, 0, 1, 0, 1};
    double *ebox = ebox_def;
    static int iflag_def[3] = {1, 2, 4};
    int iflag[3] , *ifl = NULL;
    double  alpha_def = 35.0 , theta_def = 45.0;
    double *alpha = &alpha_def, *theta = &theta_def;
    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0;
    int m3n = 0, n3n = 0, m3l = 0;
    static rhs_opts opts[] =
    {
        { -1, "alpha", -1, 0, 0, NULL},
        { -1, "ebox", -1, 0, 0, NULL},
        { -1, "flag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "theta", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char * labels = NULL;

    int* piAddr1  = NULL;
    int* piAddr2  = NULL;
    int* piAddr3  = NULL;
    int* piAddr31 = NULL;
    int* piAddr32 = NULL;

    double* l1  = NULL;
    double* l2  = NULL;
    double* l3  = NULL;
    double* l3n = NULL;

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

    CheckInputArgument(pvApiCtx, 3, 8);

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

    if (FirstOpt(pvApiCtx) < 4)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4);
        return (0);
    }

    //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, &m1, &n1, &l1); /* x */
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
        printError(&sciErr, 0);
        return 1;
    }

    if (m1 == 1 && n1 > 1)
    {
        m1 = n1;
        n1 = 1;
    }

    //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, &m2, &n2, &l2); /* y */
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2);
        printError(&sciErr, 0);
        return 1;
    }

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

    if (m1 * n1 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }
    //CheckSameDims
    if (m1 != m2 || n1 != n2)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }

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

    switch (getInputArgumentType(pvApiCtx, 3))
    {
        case 1 :
            izcol = 0;

            // Retrieve a matrix of double at position 3.
            // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int l3".
            sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &m3, &n3, &l3); /* z */
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            break;
        case 15 :
            izcol = 1;
            /* z = list(z,colors) */
            sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l);
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            if (m3l != 2)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"),
                         fname, 2, m3l, 2);
                return 0;
            }

            sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

            sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */
            if (sciErr.iErr)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
                printError(&sciErr, 0);
                return 1;
            }

            zcol  = (l3n);
            if (m3n * n3n != n3)
            {
                Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, 3, n3);
                return 0;
            }
            break;
        default :
            OverLoad(3);
            return 0;
    }

    if (m3 == 1 && n3 > 1)
    {
        m3 = n3;
        n3 = 1;
    }
    //CheckSameDims
    if (m1 != m3 || n1 != n3)
    {
        Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1);
        return 1;
    }


    GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts);
    GetLabels(pvApiCtx, fname, 6, opts, &labels);
    iflag_def[1] = 8;
    ifl = &(iflag_def[1]);
    GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &ifl, 2, opts);
    iflag[0] = iflag_def[0];
    iflag[1] = ifl[0];
    iflag[2] = ifl[1];

    GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts);

    if (m1 == 1 && n1 > 1)
    {
        m1 = n1;
        n1 = 1;
    }

    getOrCreateDefaultSubwin();

    /* NG beg */
    isfac = -1;

    Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m1, &n1, theta, alpha, labels, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04*/

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Ejemplo n.º 6
0
/*--------------------------------------------------------------------------*/
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;
}
Ejemplo n.º 7
0
/*--------------------------------------------------------------------------*/
int sci_xtitle(char * fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddr4 = NULL;
    int* boxPtr = NULL;
    int* piAddrStr = NULL;

    int  narg = 0;
    int  nbLabels = 0; /* number of modified labels */
    int  box = 0;
    BOOL isBoxSpecified = FALSE;
    int iSubwinUID = 0;
    static rhs_opts opts[] =
    {
        { -1, "boxed", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

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

    CheckInputArgument(pvApiCtx, 1, 5);


    nbLabels = nbInputArgument(pvApiCtx);

    /* get the given options from the name in opts */
    if (!getOptionals(pvApiCtx, fname, opts))
    {
        /* error */
        return 0;
    }

    /* compatibility with previous version in which box was put */
    /* at the fourth position */

    if (nbInputArgument(pvApiCtx) == 4)
    {
        int type = getInputArgumentType(pvApiCtx, 4);
        if (type == 1 || type == 8)/* double or int */
        {
            int n = 0, m = 0;
            sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
            if (sciErr.iErr)
            {
                printError(&sciErr, 0);
                return 1;
            }

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

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

            box = *boxPtr;
            nbLabels--; /* it is not a label text */
            isBoxSpecified = TRUE;
        }
    }

    if (opts[0].iPos != -1 && !isBoxSpecified)
    {
        /* check if "box" is in the options */
        getScalarBoolean(pvApiCtx, opts[0].piAddr, &box);
        if (opts[0].iRows != 1 || opts[0].iCols != 1)
        {
            /* check size */
            Scierror(999, _("%s: Wrong type for input argument: Scalar expected.\n"), fname);
            return 1;
        }
        nbLabels--; /* it is not a label text */
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    for (narg = 1 ; narg <= nbLabels ; narg++)
    {
        int m = 0, n = 0;
        char **Str = NULL;
        int iModifiedLabel = 0;
        int* piModifiedLabel = &iModifiedLabel;

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

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

        if (m * n == 0)
        {
            continue;
        }

        switch (narg)
        {
            case 1:
                getGraphicObjectProperty(iSubwinUID, __GO_TITLE__, jni_int, (void **)&piModifiedLabel);
                break;
            case 2:
                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            case 3:
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            case 4:
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LABEL__, jni_int, (void **)&piModifiedLabel);
                break;
            default:
                break;
        }

#if 0
        startFigureDataWriting(pFigure);
#endif

        sciSetText(iModifiedLabel, Str, m, n);

        setGraphicObjectProperty(iModifiedLabel, __GO_FILL_MODE__, &box, jni_bool, 1);

#if 0
        endFigureDataWriting(pFigure);
#endif

        freeArrayOfString(Str, m * n);
    }

    setCurrentObject(iSubwinUID);
#if 0
    sciDrawObj(pFigure);
#endif

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 0;
}
Ejemplo n.º 8
0
/*--------------------------------------------------------------------------*/
int checkInputArgumentType(void* _pvCtx, int _iVar, int _iType)
{
    return getInputArgumentType(_pvCtx, _iVar) == _iType;
}
Ejemplo n.º 9
0
/*--------------------------------------------------------------------------*/
int sci_plot3d(char * fname, unsigned long fname_len)
{
    SciErr sciErr;
    static double  ebox_def [6] = { 0, 1, 0, 1, 0, 1};
    double *ebox = ebox_def;
    static int iflag_def[3] = {2, 2, 4};
    int *iflag = iflag_def;
    double  alpha_def = 35.0 , theta_def = 45.0;
    double *alpha = &alpha_def, *theta = &theta_def;
    int m1 = 0, n1 = 0,  m2 = 0, n2 = 0, m3 = 0, n3 = 0;
    int m3n = 0, n3n = 0, m3l = 0;

    int izcol = 0,  isfac = 0;
    double *zcol = NULL;

    static rhs_opts opts[] =
    {
        { -1, "alpha", -1, 0, 0, NULL},
        { -1, "ebox", -1, 0, 0, NULL},
        { -1, "flag", -1, 0, 0, NULL},
        { -1, "leg", -1, 0, 0, NULL},
        { -1, "theta", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    char * legend = NULL;

    int* piAddr1  = NULL;
    int* piAddr2  = NULL;
    int* piAddr3  = NULL;
    int* piAddr31 = NULL;
    int* piAddr32 = NULL;

    double* l1  = NULL;
    double* l2  = NULL;
    double* l3  = NULL;
    double* l3n = NULL;

    /*
    ** This overload the function to call demo script
    ** the demo script is called %_<fname>
    */
    if (nbInputArgument(pvApiCtx) <= 0)
    {
        sci_demo(fname, fname_len);
        return 0;
    }

    CheckInputArgument(pvApiCtx, 3, 8);

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

    if (FirstOpt() < 4)
    {
        Scierror(999, _("%s: Misplaced optional argument: #%d must be at position %d.\n"), fname, 1, 4);
        return -1;
    }

    //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, &m1, &n1, &l1);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1);
        printError(&sciErr, 0);
        return 1;
    }

    //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, &m2, &n2, &l2);
    if (sciErr.iErr)
    {
        Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
        printError(&sciErr, 0);
        return 1;
    }

    if (m1 * n1 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (nbInputArgument(pvApiCtx) >= 3)
    {
        /*     third argument can be a matrix z or a list list(z,zcol) */
        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

        switch (getInputArgumentType(pvApiCtx, 3))
        {
            case sci_matrix :
                //get variable address
                sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

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

                izcol = 0;
                break;
            case sci_list :
                izcol = 1;
                /* z = list(z,colors) */
                sciErr = getListItemNumber(pvApiCtx, piAddr3, &m3l);
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                if (m3l != 2)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: List of size %d expected.\n"),
                             fname, 2, m3l, 2);
                    return 1;
                }

                sciErr = getListItemAddress(pvApiCtx, piAddr3, 1, &piAddr31);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getMatrixOfDouble(pvApiCtx, piAddr31, &m3, &n3, &l3); /* z */
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getListItemAddress(pvApiCtx, piAddr3, 2, &piAddr32);
                if (sciErr.iErr)
                {
                    printError(&sciErr, 0);
                    return 1;
                }

                sciErr = getMatrixOfDouble(pvApiCtx, piAddr32, &m3n, &n3n, &l3n); /* z */
                if (sciErr.iErr)
                {
                    Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 3);
                    printError(&sciErr, 0);
                    return 1;
                }

                zcol  = (l3n);
                if (m3n * n3n != n3 &&  m3n * n3n != m3 * n3)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d expected.\n"), fname, 3, n3, m3 * n3);
                    return 1;
                }
                /*
                *   Added by E Segre 4/5/2000. In the case where zcol is a
                *   matrix of the same size as z, we set izcol to 2. This
                *   value is later transmitted to the C2F(fac3dg) routine,
                *   which has been modified to do the interpolated shading
                *    (see the file SCI/modules/graphics/src/c/Plo3d.c
                */
                if (m3n * n3n == m3 * n3)
                {
                    izcol = 2 ;
                }
                break;
            default :
                OverLoad(3);
                return 0;
        }
    }
    iflag_def[1] = 8;

    GetOptionalDoubleArg(pvApiCtx, fname, 4, "theta", &theta, 1, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 5, "alpha", &alpha, 1, opts);
    GetLabels(pvApiCtx, fname, 6, opts, &legend);
    GetOptionalIntArg(pvApiCtx, fname, 7, "flag", &iflag, 3, opts);
    GetOptionalDoubleArg(pvApiCtx, fname, 8, "ebox", &ebox, 6, opts);

    if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1)
    {
        if (! (m1 == m2 && m2 == m3 && n1 == n2 && n2 == n3))
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d, #%d and #%d: Incompatible length.\n"), fname, 1, 2, 3);
            return 1;
        }
    }
    else
    {
        if (m2 * n2 != n3)
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 2, 3);
            return 1;
        }

        if (m1 * n1 != m3)
        {
            Scierror(999, _("%s: Wrong value for input arguments #%d and #%d: Incompatible length.\n"), fname, 1, 3);
            return 1;
        }

        if (m1 * n1 <= 1 || m2 * n2 <= 1)
        {
            Scierror(999, _("%s: Wrong size for input arguments #%d and #%d: %s expected.\n"), fname, 2, 3, ">= 2");
            return 1;
        }
    }

    if (m1 * n1 == 0 || m2 * n2 == 0 || m3 * n3 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    getOrCreateDefaultSubwin();

    /******************** 24/05/2002 ********************/
    if (m1 * n1 == m3 * n3 && m1 * n1 == m2 * n2 && m1 * n1 != 1) /* NG beg */
    {
        isfac = 1;
    }
    else
    {
        isfac = 0;
    }


    Objplot3d (fname, &isfac, &izcol, (l1), (l2), (l3), zcol, &m3, &n3, theta, alpha, legend, iflag, ebox, &m1, &n1, &m2, &n2, &m3, &n3, &m3n, &n3n); /*Adding F.Leray 12.03.04 and 19.03.04*/

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

}
Ejemplo n.º 10
0
/*--------------------------------------------------------------------------
 * sciset(choice-name,x1,x2,x3,x4,x5)
 * or   xset()
 *-----------------------------------------------------------*/
int sci_set(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddr1 = NULL;
    int* piAddr2 = NULL;
    int* piAddr3 = NULL;
    int lw = 0;
    int isMatrixOfString = 0;

    char* pstProperty = NULL;
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
    if (sciErr.iErr)
    {
        //error
        return 1;
    }

    if (isMListType(pvApiCtx, piAddr1) || isTListType(pvApiCtx, piAddr1))
    {
        OverLoad(1);
        return 0;
    }

    CheckRhs(2, 3);
    CheckLhs(0, 1);

    if (isDoubleType(pvApiCtx, piAddr1))   /* tclsci handle */
    {
        /* call "set" for tcl/tk see tclsci/sci_gateway/c/sci_set.c */
        OverLoad(1);
        return 0;
    }
    else                        /* others types */
    {
        int iRows1 = 0, iCols1 = 0;
        int iRows2 = 0, iCols2 = 0;
        int iRows3 = 0, iCols3 = 0;
        void* _pvData = NULL;
        unsigned long hdl;
        char *pobjUID = NULL;

        int iType1 = 0;

        int valueType = 0;      /* type of the rhs */

        int setStatus = 0;

        /* after the call to sciSet get the status : 0 <=> OK,          */
        /*                                          -1 <=> Error,       */
        /*                                           1 <=> nothing done */

        /*  set or create a graphic window */
        sciErr = getVarType(pvApiCtx, piAddr1, &iType1);
        if (sciErr.iErr)
        {
            //error
            return 1;
        }
        switch (iType1)
        {
            case sci_handles:
                /* first is a scalar argument so it's a gset(hdl,"command",[param]) */
                /* F.Leray; INFO: case 9 is considered for a matrix of graphic handles */
                CheckRhs(3, 3);

                if (isScalar(pvApiCtx, piAddr1) == FALSE)
                {
                    OverLoad(1);
                    return 0;
                }

                getScalarHandle(pvApiCtx, piAddr1, (long long*)&hdl);
                pobjUID = (char*)getObjectFromHandle(hdl);

                getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
                getAllocatedSingleString(pvApiCtx, piAddr2, &pstProperty);
                valueType = getInputArgumentType(pvApiCtx, 3);

                getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
                if ((strcmp(pstProperty, "user_data") == 0) || (stricmp(pstProperty, "userdata") == 0))
                {
                    /* in this case set_user_data_property
                     * directly uses the  third position in the stack
                     * to get the variable which is to be set in
                     * the user_data property (any data type is allowed) S. Steer */
                    _pvData = (void*)piAddr3;         /*position in the stack */
                    iRows3 = -1;   /*unused */
                    iCols3 = -1;   /*unused */
                    valueType = -1;
                }
                else if (valueType == sci_matrix)
                {
                    getMatrixOfDouble(pvApiCtx, piAddr3, &iRows3, &iCols3, (double**)&_pvData);
                }
                else if (valueType == sci_boolean)
                {
                    getMatrixOfBoolean(pvApiCtx, piAddr3, &iRows3, &iCols3, (int**)&_pvData);
                }
                else if (valueType == sci_handles)
                {
                    getMatrixOfHandle(pvApiCtx, piAddr3, &iRows3, &iCols3, (long long**)&_pvData);
                }
                else if (valueType == sci_strings)
                {
                    if (   strcmp(pstProperty, "tics_labels") != 0 && strcmp(pstProperty, "auto_ticks") != 0 &&
                            strcmp(pstProperty, "axes_visible") != 0 && strcmp(pstProperty, "axes_reverse") != 0 &&
                            strcmp(pstProperty, "text") != 0 && stricmp(pstProperty, "string") != 0 &&
                            stricmp(pstProperty, "tooltipstring") != 0) /* Added for uicontrols */
                    {
                        getAllocatedSingleString(pvApiCtx, piAddr3, (char**)&_pvData);
                        iRows3 = (int)strlen((char*)_pvData);
                        iCols3 = 1;
                    }
                    else
                    {
                        isMatrixOfString = 1;
                        getAllocatedMatrixOfString(pvApiCtx, piAddr3, &iRows3, &iCols3, (char***)&_pvData);
                    }
                }
                else if (valueType == sci_list) /* Added for callbacks */
                {
                    iCols3 = 1;
                    getListItemNumber(pvApiCtx, piAddr3, &iRows3);
                    _pvData = (void*)piAddr3;         /* In this case l3 is the list position in stack */
                }
                break;

            case sci_strings:      /* first is a string argument so it's a set("command",[param]) */
                CheckRhs(2, 2);
                getAllocatedSingleString(pvApiCtx, piAddr1, &pstProperty);
                hdl = 0;
                pobjUID = NULL;
                valueType = getInputArgumentType(pvApiCtx, 2);
                getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);

                if (valueType == sci_matrix)
                {
                    getMatrixOfDouble(pvApiCtx, piAddr2, &iRows3, &iCols3, (double**)&_pvData);
                }
                else if (valueType == sci_handles)
                {
                    getMatrixOfHandle(pvApiCtx, piAddr2, &iRows3, &iCols3, (long long**)&_pvData);
                }
                else if (valueType == sci_strings)
                {
                    if (strcmp(pstProperty, "tics_labels") == 0 || strcmp(pstProperty, "auto_ticks") == 0 ||
                            strcmp(pstProperty, "axes_visible") == 0 || strcmp(pstProperty, "axes_reverse") == 0 ||
                            strcmp(pstProperty, "text") == 0)
                    {
                        isMatrixOfString = 1;
                        getAllocatedMatrixOfString(pvApiCtx, piAddr2, &iRows3, &iCols3, (char***)&_pvData);
                    }
                    else
                    {
                        getAllocatedSingleString(pvApiCtx, piAddr2, (char**)&_pvData);
                        iRows3 = (int)strlen((char*)_pvData);
                        iCols3 = 1;
                    }
                }
                break;

            default:
                Scierror(999, _("%s: Wrong type for input argument #%d: String or handle expected.\n"), fname, 1);
                return 0;
                break;
        }

        if (hdl != 0)
        {
            pobjUID = (char*)getObjectFromHandle(hdl);

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

            // Only set the property whitout doing anythig else.
            //static int sciSet(void* _pvCtx, char *pobjUID, char *marker, void* value, int valueType, int *numrow, int *numcol)
            setStatus = callSetProperty(pvApiCtx, pobjUID, _pvData, valueType, iRows3, iCols3, pstProperty);
            if (valueType == sci_strings)
            {
                //free allacted data
                if (isMatrixOfString == 1)
                {
                    freeAllocatedMatrixOfString(iRows3, iCols3, (char**)_pvData);
                }
                else
                {
                    freeAllocatedSingleString((char*)_pvData);
                }
            }
        }
        else
        {
#define NB_PROPERTIES_SUPPORTED 7
            /* No object specified */
            /* ONLY supported properties are */
            /* 'current_entity' */
            /* 'hdl' */
            /* 'current_figure' */
            /* 'current_axes' */
            /* 'default_values' */
            /* 'figure_style' for compatibility but do nothing */
            /* others values must return a error */
            char *propertiesSupported[NB_PROPERTIES_SUPPORTED] = { "current_entity",
                    "hdl",
                    "current_figure",
                    "current_axes",
                    "figure_style",
                    "default_values",
                    "auto_clear"
                                                                 };

            int i = 0;
            int iPropertyFound = 0;

            for (i = 0; i < NB_PROPERTIES_SUPPORTED; i++)
            {

                if (strcmp(propertiesSupported[i], pstProperty) == 0)
                {
                    iPropertyFound = 1;
                }
            }

            if (iPropertyFound)
            {
                // we do nothing with "figure_style" "new" (to remove in 5.4)
                int bDoSet = ((isMatrixOfString) && (strcmp(pstProperty, "figure_style") == 0) && (strcmp(((char**)_pvData)[0], "new") == 0)) != 1;

                if (bDoSet)
                {
                    setStatus = callSetProperty(pvApiCtx, NULL, _pvData, valueType, iRows3, iCols3, pstProperty);
                    if (valueType == sci_strings)
                    {
                        //free allocated data
                        if (isMatrixOfString == 1)
                        {
                            freeAllocatedMatrixOfString(iRows3, iCols3, (char**)_pvData);
                        }
                        else
                        {
                            freeAllocatedSingleString((char*)_pvData);
                        }
                    }
                }
            }
            else
            {
                Scierror(999, _("%s: Wrong value for input argument #%d: a valid property expected.\n"), fname, 1);
                if (isMatrixOfString)
                {
                    freeArrayOfString((char **)_pvData, iRows3 * iCols3);
                }
                return 0;
            }
        }

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

    return 0;
}
Ejemplo n.º 11
0
/*--------------------------------------------------------------------------*/
int sci_get(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

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

    int m1 = 0, n1 = 0;
    long hdl = 0;

    int lw = 0;
    int iObjUID = 0;

    int status = SET_PROPERTY_ERROR;

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

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

    if (isMListType(pvApiCtx, piAddrl1) || isTListType(pvApiCtx, piAddrl1))
    {
        OverLoad(1);
        return 0;
    }

    /*
     * The first input argument can be an ID or a marker (in this case, get returns the value of the current object */
    switch (getInputArgumentType(pvApiCtx, 1))
    {
    case sci_matrix: //console handle
    {
        double dbll1 = 0;

        if (isScalar(pvApiCtx, piAddrl1) == 0)
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
            return 1;
        }

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

        if ((int)dbll1 == 0) /* Console property */
        {
            int* piAddrstkAdr = NULL;
            char *stkAdr = NULL;
            if (nbInputArgument(pvApiCtx) == 1)
            {
                if (sciReturnHandle(getHandle(getConsoleIdentifier())) != 0)    /* Get Console handle */
                {
                    ReturnArguments(pvApiCtx);
                    return 0;
                }
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }

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

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

            if (GetScreenProperty(pvApiCtx, stkAdr) != SET_PROPERTY_SUCCEED)
            {
                Scierror(999, _("%s: Could not read property '%s' for console object.\n"), "get", stkAdr[0]);
                freeAllocatedSingleString(stkAdr);
                return 1;
            }
            freeAllocatedSingleString(stkAdr);
            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            ReturnArguments(pvApiCtx);
        }

        return 0;
        break;
    }
    case sci_handles:          /* scalar argument (hdl + string) */
        CheckInputArgument(pvApiCtx, 1, 2);

        // 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 input argument #%d: Handle matrix expected.\n"), fname, 1);
            return 1;
        }

        if (m1 != 1 || n1 != 1)
        {
            //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
            OverLoad(1);
            return 0;
        }

        if (nbInputArgument(pvApiCtx) == 1)
        {
            //get path from handle
            int uic = getObjectFromHandle((long) * l1);
            char* path = get_path(uic);
            if (path[0] == '\0')
            {
                Scierror(999, _("%s: Unable to get useful path from this handle.\n"), fname);
                return 1;
            }

            createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, path);
            FREE(path);

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

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

        if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0)
        {
            Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
            return 1;
        }

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

        hdl = (long) * l1; /* on recupere le pointeur d'objet par le handle */
        break;
    case sci_strings:          /* string argument (string) */
    {
        char* pstFirst = NULL;
        CheckInputArgument(pvApiCtx, 1, 2);

        if (isScalar(pvApiCtx, piAddrl1) == 0)
        {
            Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1);
            return 1;
        }

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

        if (strcmp(pstFirst, "default_figure") == 0 ||
                strcmp(pstFirst, "default_axes") == 0 ||
                strcmp(pstFirst, "current_figure") == 0 ||
                strcmp(pstFirst, "current_axes") == 0 ||
                strcmp(pstFirst, "current_entity") == 0 ||
                strcmp(pstFirst, "hdl") == 0 ||
                strcmp(pstFirst, "figures_id") == 0)
        {
            hdl = 0;
            l2 = pstFirst;
        }
        else
        {
            int uid = search_path(pstFirst);
            if (uid != 0)
            {
                freeAllocatedSingleString(pstFirst);
                hdl = getHandle(uid);

                if (nbInputArgument(pvApiCtx) == 1)
                {
                    createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, hdl);
                    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                    ReturnArguments(pvApiCtx);
                    return 0;
                }

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

                if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0)
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                    return 1;
                }

                if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
                {
                    Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2);
                    return 1;
                }
            }
            else
            {
                createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1);
                AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                ReturnArguments(pvApiCtx);
                return 0;
            }
        }
        break;
    }
    default:
        //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx);
        OverLoad(1);
        return 0;
        break;
    }
    /* (l2) est la commande, l3 l'indice sur les parametres de la commande */
    CheckOutputArgument(pvApiCtx, 0, 1);

    if (hdl == 0)
    {
        /* No handle specified */
        if (callGetProperty(pvApiCtx, 0, (l2)) != 0)
        {
            /* An error has occurred */
            freeAllocatedSingleString(l2);
            ReturnArguments(pvApiCtx);
            return 0;
        }
    }
    else
    {
        iObjUID = getObjectFromHandle(hdl);
        if (iObjUID != 0)
        {

            if (callGetProperty(pvApiCtx, iObjUID, (l2)) != 0)
            {
                /* An error has occurred */
                freeAllocatedSingleString(l2);
                ReturnArguments(pvApiCtx);
                return 0;
            }
        }
        else
        {
            Scierror(999, _("%s: The handle is not or no more valid.\n"), fname);
            freeAllocatedSingleString(l2);
            return 0;
        }
    }

    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    ReturnArguments(pvApiCtx);
    freeAllocatedSingleString(l2);
    return 0;
}