Beispiel #1
0
/*--------------------------------------------------------------------------*/
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;
}
Beispiel #2
0
/*--------------------------------------------------------------------------*/
int sci_xstring(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

    int* piAddrStr = NULL;
    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddrl4 = NULL;
    double* l4 = NULL;
    int* piAddrl5 = NULL;
    double* l5 = NULL;

    double rect[4];
    double x = 0., y = 0., angle = 0.0;
    int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0, m5 = 0, n5 = 0;
    char **Str = NULL;
    char **sendStr = NULL;
    int sendm3 = 0, sendn3 = 0;
    long hdlstr = 0;
    int nbElement = 0, i = 0;
    BOOL isboxed = FALSE;

    CheckInputArgument(pvApiCtx, 3, 5);

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

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

    if (m3 * n3 == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

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

    // Retrieve a matrix of double at position 1.
    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);
        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 (m1 * n1 == 1 || m2 * n2 == 1)
    {
        nbElement = m1 * n1 * m2 * n2;
    }
    else if (m1 * n1 == m2 * n2)
    {
        nbElement = m1 * n1;
    }
    else
    {
        Scierror(999, _("%s: Incompatible input arguments #%d and #%d: Same element number expected.\n"), fname, 1, 2);
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (nbElement == 0)
    {
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    if (nbInputArgument(pvApiCtx) >= 4)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrl4);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

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

        if (m4 * n4 != 1 && m4 * n4 != nbElement)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 4, 1, nbElement);
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }
    }
    if (nbInputArgument(pvApiCtx) >= 5)
    {
        sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrl5);
        if (sciErr.iErr)
        {
            printError(&sciErr, 0);
            return 1;
        }

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

        if (m5 * n5 != 1 && m5 * n5 != nbElement)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 5, 1, nbElement);
            AssignOutputVariable(pvApiCtx, 1) = 0;
            ReturnArguments(pvApiCtx);
            return 0;
        }
    }

    x = *l1;
    y = *l2;
    sendStr = Str;
    sendm3 = m3;
    sendn3 = n3;
    if (nbInputArgument(pvApiCtx) >= 4)
    {
        angle = DEG2RAD(*l4);
    }
    if (nbInputArgument(pvApiCtx) >= 5)
    {
        isboxed = (*l5 != 0);
    }

    getOrCreateDefaultSubwin();

    if (nbElement == 1)
    {
        Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed
                  && (angle == 0), TRUE, FALSE, ALIGN_LEFT);
    }
    else
    {
        for (i = 0; i < nbElement; i++)
        {
            if (m1 * n1 == nbElement)
            {
                x = *((l1) + i);
            }
            if (m2 * n2 == nbElement)
            {
                y = *((l2) + i);
            }
            if (m3 * n3 == nbElement)
            {
                sendStr = Str + i;
                sendm3 = sendn3 = 1;
            }
            if (nbInputArgument(pvApiCtx) >= 4 && m4 * n4 == nbElement)
            {
                angle = DEG2RAD(*((l4) + i));
            }
            if (nbInputArgument(pvApiCtx) >= 5 && m5 * n5 == nbElement)
            {
                isboxed = ((l5) != 0);
            }

            Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed
                      && (angle == 0), TRUE, FALSE, ALIGN_LEFT);
        }

        /*
         * If one of the string creation calls fails,
         * the compound build call will crash.
         * To be modified
         */
        {
            char * o = ConstructCompoundSeq(nbElement);
            releaseGraphicObjectProperty(__GO_PARENT__, o, jni_string, 1);
        }
    }

    /* we must free Str memory */

    freeArrayOfString(Str, m3 * n3);

    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);
    return 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;
}
Beispiel #4
0
int sci_umfpack(char* fname, void* pvApiCtx)
{
    SciErr sciErr;

    int mb      = 0;
    int nb      = 0;
    int i       = 0;
    int num_A   = 0;
    int num_b   = 0;
    int mW      = 0;
    int Case    = 0;
    int stat    = 0;

    SciSparse AA;
    CcsSparse A;

    int* piAddrA = NULL;
    int* piAddr2 = NULL;
    int* piAddrB = NULL;

    double* pdblBR = NULL;
    double* pdblBI = NULL;
    double* pdblXR = NULL;
    double* pdblXI = NULL;

    int iComplex = 0;

    int mA              = 0; // rows
    int nA              = 0; // cols
    int iNbItem         = 0;
    int* piNbItemRow    = NULL;
    int* piColPos       = NULL;
    double* pdblSpReal  = NULL;
    double* pdblSpImg   = NULL;

    /* umfpack stuff */
    double Info[UMFPACK_INFO];
    double* Control = NULL;
    void* Symbolic  = NULL;
    void* Numeric   = NULL;
    int* Wi         = NULL;
    double* W       = NULL;
    char* pStr      = NULL;
    int iType2      = 0;
    int iTypeA      = 0;
    int iTypeB      = 0;

    /* Check numbers of input/output arguments */
    CheckInputArgument(pvApiCtx, 3, 3);
    CheckOutputArgument(pvApiCtx, 1, 1);

    /* First get arg #2 : a string of length 1 */
    sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddr2, &iType2);
    if (sciErr.iErr || iType2 != sci_strings)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 2);
        return 1;
    }

    getAllocatedSingleString(pvApiCtx, piAddr2, &pStr);

    /* select Case 1 or 2 depending (of the first char of) the string ... */
    if (pStr[0] == '\\') // compare pStr[0] with '\'
    {
        Case  = 1;
        num_A = 1;
        num_b = 3;
    }
    else if (pStr[0] == '/')
    {
        Case  = 2;
        num_A = 3;
        num_b = 1;
    }
    else
    {
        Scierror(999, _("%s: Wrong input argument #%d: '%s' or '%s' expected.\n"), fname, 2, "\\", "/");
        FREE(pStr);
        return 1;
    }
    FREE(pStr);

    /* get A */
    sciErr = getVarAddressFromPosition(pvApiCtx, num_A, &piAddrA);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddrA, &iTypeA);
    if (sciErr.iErr || iTypeA != sci_sparse)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: A sparse matrix expected.\n"), fname, 1);
        return 1;
    }

    if (isVarComplex(pvApiCtx, piAddrA))
    {
        AA.it = 1;
        iComplex = 1;
        sciErr = getComplexSparseMatrix(pvApiCtx, piAddrA, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal, &pdblSpImg);
    }
    else
    {
        AA.it = 0;
        sciErr = getSparseMatrix(pvApiCtx, piAddrA, &mA, &nA, &iNbItem, &piNbItemRow, &piColPos, &pdblSpReal);
    }

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

    // fill struct sparse
    AA.m     = mA;
    AA.n     = nA;
    AA.nel   = iNbItem;
    AA.mnel  = piNbItemRow;
    AA.icol  = piColPos;
    AA.R     = pdblSpReal;
    AA.I     = pdblSpImg;

    if ( mA != nA || mA < 1 )
    {
        Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, num_A);
        return 1;
    }

    /* get B*/
    sciErr = getVarAddressFromPosition(pvApiCtx, num_b, &piAddrB);
    if (sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 1;
    }

    sciErr = getVarType(pvApiCtx, piAddrB, &iTypeB);
    if (sciErr.iErr || iTypeB != sci_matrix)
    {
        printError(&sciErr, 0);
        Scierror(999, _("%s: Wrong type for input argument #%d: A matrix expected.\n"), fname, 3);
        return 1;
    }

    if (isVarComplex(pvApiCtx, piAddrB))
    {
        iComplex = 1;
        sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddrB, &mb, &nb, &pdblBR, &pdblBI);
    }
    else
    {
        sciErr = getMatrixOfDouble(pvApiCtx, piAddrB, &mb, &nb, &pdblBR);
    }

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

    if ( (Case == 1 && ( mb != mA || nb < 1 )) || (Case == 2 && ( nb != mA || mb < 1 )) )
    {
        Scierror(999, _("%s: Wrong size for input argument #%d.\n"), fname, num_b);
        return 1;
    }

    SciSparseToCcsSparse(&AA, &A);

    /* allocate memory for the solution x */
    if (iComplex)
    {
        sciErr = allocComplexMatrixOfDouble(pvApiCtx, 4, mb, nb, &pdblXR, &pdblXI);
    }
    else
    {
        sciErr = allocMatrixOfDouble(pvApiCtx, 4, mb, nb, &pdblXR);
    }

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

    /* allocate memory for umfpack_di_wsolve usage or umfpack_zi_wsolve usage*/
    Wi = (int*)MALLOC(mA * sizeof(int));

    if (A.it == 1)
    {
        mW = 10 * mA;
    }
    else
    {
        mW = 5 * mA;
    }

    W = (double*)MALLOC(mW * sizeof(double));

    if (A.it == 1  &&  pdblBI == NULL)
    {
        int iSize = mb * nb * sizeof(double);
        pdblBI = (double*)MALLOC(iSize);
        memset(pdblBI, 0x00, iSize);
    }

    /* Now calling umfpack routines */
    if (A.it == 1)
    {
        stat = umfpack_zi_symbolic(mA, nA, A.p, A.irow, A.R, A.I, &Symbolic, Control, Info);
    }
    else
    {
        stat = umfpack_di_symbolic(mA, nA, A.p, A.irow, A.R, &Symbolic, Control, Info);
    }

    if ( stat  != UMFPACK_OK )
    {
        freeCcsSparse(A);
        Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("symbolic factorization"), UmfErrorMes(stat));
        return 1;
    }

    if (A.it == 1)
    {
        stat = umfpack_zi_numeric(A.p, A.irow, A.R, A.I, Symbolic, &Numeric, Control, Info);
    }
    else
    {
        stat = umfpack_di_numeric(A.p, A.irow, A.R, Symbolic, &Numeric, Control, Info);
    }

    if (A.it == 1)
    {
        umfpack_zi_free_symbolic(&Symbolic);
    }
    else
    {
        umfpack_di_free_symbolic(&Symbolic);
    }

    if ( stat  != UMFPACK_OK )
    {
        if (A.it == 1)
        {
            umfpack_zi_free_numeric(&Numeric);
        }
        else
        {
            umfpack_di_free_numeric(&Numeric);
        }
        freeCcsSparse(A);
        Scierror(999, _("%s: An error occurred: %s: %s\n"), fname, _("numeric factorization"), UmfErrorMes(stat));
        return 1;
    }


    if ( Case == 1 )   /*  x = A\b  <=> Ax = b */
    {
        if (A.it == 0)
        {
            for ( i = 0 ; i < nb ; i++ )
            {
                umfpack_di_wsolve(UMFPACK_A, A.p, A.irow, A.R, &pdblXR[i * mb], &pdblBR[i * mb],
                                  Numeric, Control, Info, Wi, W);
            }

            if (isVarComplex(pvApiCtx, piAddrB))
            {
                for ( i = 0 ; i < nb ; i++ )
                {
                    umfpack_di_wsolve(UMFPACK_A, A.p, A.irow, A.R, &pdblXI[i * mb], &pdblBI[i * mb],
                                      Numeric, Control, Info, Wi, W);
                }
            }
        }
        else /*  A.it == 1  */
        {
            for ( i = 0 ; i < nb ; i++ )
            {
                umfpack_zi_wsolve(UMFPACK_A, A.p, A.irow, A.R, A.I, &pdblXR[i * mb], &pdblXI[i * mb],
                                  &pdblBR[i * mb], &pdblBI[i * mb], Numeric, Control, Info, Wi, W);
            }
        }
    }
    else  /* Case == 2,   x = b/A  <=> x A = b <=> A.'x.' = b.' */
    {
        if (A.it == 0)
        {
            TransposeMatrix(pdblBR, mb, nb, pdblXR);    /* put b in x (with transposition) */
            for ( i = 0 ; i < mb ; i++ )
            {
                umfpack_di_wsolve(UMFPACK_At, A.p, A.irow, A.R, &pdblBR[i * nb], &pdblXR[i * nb],
                                  Numeric, Control, Info, Wi, W);      /* the solutions are in br */
            }

            TransposeMatrix(pdblBR, nb, mb, pdblXR);         /* put now br in xr with transposition */

            if (isVarComplex(pvApiCtx, piAddrB))
            {
                TransposeMatrix(pdblBI, mb, nb, pdblXI);    /* put b in x (with transposition) */
                for ( i = 0 ; i < mb ; i++ )
                {
                    umfpack_di_wsolve(UMFPACK_At, A.p, A.irow, A.R, &pdblBI[i * nb], &pdblXI[i * nb],
                                      Numeric, Control, Info, Wi, W);      /* the solutions are in bi */
                }
                TransposeMatrix(pdblBI, nb, mb, pdblXI);         /* put now bi in xi with transposition */
            }
        }
        else /*  A.it==1  */
        {
            TransposeMatrix(pdblBR, mb, nb, pdblXR);
            TransposeMatrix(pdblBI, mb, nb, pdblXI);
            for ( i = 0 ; i < mb ; i++ )
            {
                umfpack_zi_wsolve(UMFPACK_Aat, A.p, A.irow, A.R, A.I, &pdblBR[i * nb], &pdblBI[i * nb],
                                  &pdblXR[i * nb], &pdblXI[i * nb], Numeric, Control, Info, Wi, W);
            }
            TransposeMatrix(pdblBR, nb, mb, pdblXR);
            TransposeMatrix(pdblBI, nb, mb, pdblXI);
        }
    }

    if (A.it == 1)
    {
        umfpack_zi_free_numeric(&Numeric);
    }
    else
    {
        umfpack_di_free_numeric(&Numeric);
    }

    if (piNbItemRow != NULL)
    {
        FREE(piNbItemRow);
    }
    if (piColPos != NULL)
    {
        FREE(piColPos);
    }
    if (pdblSpReal != NULL)
    {
        FREE(pdblSpReal);
    }
    if (pdblSpImg != NULL)
    {
        FREE(pdblSpImg);
    }
    FREE(W);
    FREE(Wi);
    freeCcsSparse(A);

    AssignOutputVariable(pvApiCtx, 1) = 4;
    ReturnArguments(pvApiCtx);
    return 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;
}
Beispiel #6
0
/*--------------------------------------------------------------------------*/
int sci_stringbox(char * fname, unsigned long fname_len)
{

    SciErr sciErr;

    int* piAddrstackPointer = NULL;
    long long* stackPointer = NULL;
    char** strStackPointer   = NULL;
    double* pdblStackPointer = NULL;

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

    char* parentAxes = NULL;
    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 */

        char * pTextUID = NULL;
        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: Handle matrix expected.\n"), fname,  1);
            return 1;
        }

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

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

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

        getGraphicObjectProperty(pTextUID, __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(pTextUID, __GO_PARENT_AXES__, jni_string, (void **)&parentAxes);

        updateTextBounds(pTextUID);

        /*
         * 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(pTextUID, __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
    {
        char * parentSubwinUID = (char*)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(parentSubwinUID, __GO_FONT_STYLE__, jni_int, (void**)&pfontId);
        getGraphicObjectProperty(parentSubwinUID, __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 matrix expected.\n"), fname,  1);
            return 1;
        }

        /* retrieve it */
        text = strStackPointer;

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

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

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

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

        if (nbInputArgument(pvApiCtx) >= 6)
        {
            /* font size is defined */
            if (getScalarFromStack(6, fname, &fontSize) < 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;
}
    /*--------------------------------------------------------------------------*/
    int sci_getinstalledlookandfeels(char *fname, unsigned long fname_len)
    {
        SciErr sciErr;
        CheckInputArgument(pvApiCtx, 0, 0);
        CheckOutputArgument(pvApiCtx, 1, 1);

        org_scilab_modules_gui_utils::LookAndFeelManager * lnf = 0;
        try
        {
            lnf = new org_scilab_modules_gui_utils::LookAndFeelManager(getScilabJavaVM());
        }
        catch (const GiwsException::JniException & e)
        {
            Scierror(999, _("%s: A Java exception arisen:\n%s"), fname, e.whatStr().c_str());
            return 1;
        }

        if (lnf)
        {
            char **lookandfeels = NULL;
            int nbElems = 0;
            int nbCol = 0;

            lookandfeels = lnf->getInstalledLookAndFeels();
            nbElems = lnf->numbersOfInstalledLookAndFeels();

            nbCol = 1;

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

            if (lookandfeels)
            {
                int i = 0;

                for (i = 0; i < nbElems; i++)
                {
                    if (lookandfeels[i])
                    {
                        delete[]lookandfeels[i];
                    }
                }
                delete[]lookandfeels;
                lookandfeels = NULL;
            }
            delete lnf;

            AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
            returnArguments(pvApiCtx);
        }
        else
        {
            Scierror(999, _("%s: No more memory.\n"), fname);
        }
        return 0;
    }
Beispiel #8
0
/*--------------------------------------------------------------------------*/
int sci_xpolys(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

    int* piAddrl1 = NULL;
    double* l1 = NULL;
    int* piAddrl2 = NULL;
    double* l2 = NULL;
    int* piAddr3 = NULL;
    int* l3 = NULL;

    int m1 = 0, n1 = 0;
    int m2 = 0, n2 = 0;
    int m3 = 0, n3 = 0;

    int i = 0;
    long hdl = 0;

    int iFigureUID = 0;
    int iSubWinUID = 0;
    int iCompoundUID = 0;
    int iFalse = 0;

    int iVisible = 0;
    int *piVisible = &iVisible;

    CheckInputArgument(pvApiCtx, 2, 3);

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

    // Retrieve a matrix of double at position 1.
    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);
        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;
    }

    //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;
    }


    if (m1 * n1 == 0 || m2 * n2 == 0)
    {
        /* dimension 0, 0 polyline to draw */
        AssignOutputVariable(pvApiCtx, 1) = 0;
        ReturnArguments(pvApiCtx);
        return 0;
    }

    iSubWinUID = getOrCreateDefaultSubwin();
    iFigureUID = getCurrentFigure();
    // Create compound.
    iCompoundUID = createGraphicObject(__GO_COMPOUND__);
    setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1);
    /* Sets the parent-child relationship for the Compound */
    setGraphicObjectRelationship(iSubWinUID, iCompoundUID);

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

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

        //CheckVector
        if (m3 != 1 && n3 != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 3);
            return 1;
        }

        //CheckDimProp
        if (m3 * n3 < n1)
        {
            Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname);
            return 1;
        }

        /* Construct the polylines */
        for (i = 0; i < n1; ++i)
        {
            Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, *(int*)(l3 + i), &hdl);
            // Add newly created object to Compound
            setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl));
        }
    }
    else
    {
        for (i = 0; i < n1; ++i)
        {
            Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, 1, &hdl);
            // Add newly created object to Compound
            setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl));
        }
    }

    getGraphicObjectProperty(iFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible);

    setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1);

    setCurrentObject(iCompoundUID);

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