示例#1
0
/*--------------------------------------------------------------------------*/
int sci_xrects(char *fname, void *pvApiCtx)
{
    SciErr sciErr;

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

    int m1 = 0, n1 = 0, m2 = 0, n2 = 0;
    long  hdl = 0;
    int i = 0;
    int iSubwinUID = 0;

    int foreground = 0;
    int *piForeground = &foreground;
    int iCompoundUID = 0;

    CheckInputArgument(pvApiCtx, 1, 2);

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

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


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

        // Retrieve a matrix of double at position 2.
        sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &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;
        }

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

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

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

        for (i = 0; i < n2; ++i)
        {
            l2[i] = 0;
        }
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    // Create compound.
    iCompoundUID = createGraphicObject(__GO_COMPOUND__);
    /* Sets the parent-child relationship for the Compound */
    setGraphicObjectRelationship(iSubwinUID, iCompoundUID);

    /** Get Subwin line color */
    getGraphicObjectProperty(iSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeground);

    for (i = 0; i < n1; ++i)
    {
        /*       j = (i==0) ? 0 : 1; */
        if (l2[i] == 0)
        {
            /** fil(i) = 0 rectangle i is drawn using the current line style (or color).**/
            /* color setting is done now */

            Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                    &foreground, NULL, FALSE, TRUE, &hdl);
        }
        else
        {
            if (l2[i] < 0)
            {
                /** fil(i) < 0 rectangle i is drawn using the line style (or color) **/
                int tmp = - (*(int*)(l2 + i));
                Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                        &tmp, NULL, FALSE, TRUE, &hdl);
            }
            else
            {
                /** fil(i) > 0   rectangle i is filled using the pattern (or color) **/
                Objrect((l1 + (4 * i)), (l1 + (4 * i) + 1), (l1 + (4 * i) + 2), (l1 + (4 * i) + 3),
                        NULL, l2 + i, TRUE, FALSE, &hdl);
            }
        }
        // Add newly created object to Compound
        setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl));
    }

    /** make Compound current object **/
    setCurrentObject(iCompoundUID);
    AssignOutputVariable(pvApiCtx, 1) = 0;
    ReturnArguments(pvApiCtx);

    return 0;
}
示例#2
0
/*--------------------------------------------------------------------------*/
int sci_xrect( char *fname, unsigned long fname_len )
{
    long hdl = 0;
    int m1 = 0,n1 = 0,l1 = 0,m2 = 0,n2 = 0,l2 = 0,m3 = 0,n3 = 0,l3 = 0,m4 = 0,n4 = 0,l4 = 0;
    char* psubwinUID = NULL;

    int foreground = 0;
    int *piForeground = &foreground;

    CheckRhs(1,4);

    psubwinUID = (char*)getOrCreateDefaultSubwin();

    switch( Rhs )
    {
    case 1 :
        GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l1);
        CheckLength(1,m1*n1,4);

        getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeground);

        if (strcmp(fname,"xrect")==0)
        {
            Objrect (stk(l1),stk(l1+1),stk(l1+2),stk(l1+3),
                     &foreground,NULL,FALSE,TRUE,&hdl);
        }
        else
        { /* xfrect case */
            Objrect (stk(l1),stk(l1+1),stk(l1+2),stk(l1+3),
                     NULL,&foreground,TRUE,FALSE,&hdl);
        }

        if ( hdl < 0 )
        {
            break;
        }

        break;
    case 4 :
        getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piForeground);

        GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l1); CheckScalar(1,m1,n1);
        GetRhsVar(2,MATRIX_OF_DOUBLE_DATATYPE,&m2,&n2,&l2); CheckScalar(2,m2,n2);
        GetRhsVar(3,MATRIX_OF_DOUBLE_DATATYPE,&m3,&n3,&l3); CheckScalar(3,m3,n3);
        GetRhsVar(4,MATRIX_OF_DOUBLE_DATATYPE,&m4,&n4,&l4); CheckScalar(4,m4,n4);

        if (strcmp(fname,"xrect")==0)
        {
            Objrect (stk(l1),stk(l2),stk(l3),stk(l4),
                     &foreground,NULL,FALSE,TRUE,&hdl);
        }
        else
        {
            Objrect (stk(l1),stk(l2),stk(l3),stk(l4),
                     NULL,&foreground,TRUE,FALSE,&hdl);
        }

        if ( hdl < 0 )
        {
            break;
        }

        break;
    default :
        Scierror(999,_("%s: Wrong number of input argument(s): %d or %d expected.\n"),fname, 1,4);
        break ;
    }

    if ( hdl > 0 )
    {
        setGraphicObjectRelationship(psubwinUID, getObjectFromHandle(hdl));
        LhsVar(1)=0;
        PutLhsVar();
    }
    return 0;
}