Пример #1
0
/*-----------------------------------------------------------
 *   Objsegs :
 *-----------------------------------------------------------*/
void Objsegs (int * style,
              int   flag ,
              int   n1   ,
              double  * x    ,
              double  * y    ,
              double  * z    ,
              double    arsize)
{
    char *pobjUID = NULL;
    char *psubwinUID = NULL;
    int type = 0, colored = 0;
    double *fx = NULL, *fy = NULL; // No fx or fy
    int typeofchamp = -1; /* no champ here, only segs ; this info is useless */

    checkRedrawing();
    psubwinUID = (char*)getCurrentSubWin();

    pobjUID = ConstructSegs(psubwinUID, type,
                            x, y, z, n1, n1, (z == NULL ? 0 : n1), // x, y and z have the same size n1
                            fx, fy, flag, style, arsize, colored, typeofchamp);

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

    setCurrentObject(pobjUID);
    releaseGraphicObjectProperty(__GO_SEGS__, pobjUID, jni_string, 1);
}
Пример #2
0
void Objarc(double* angle1    ,
            double* angle2    ,
            double* x         ,
            double* y         ,
            double* width     ,
            double* height    ,
            int    * foreground,
            int    * background,
            BOOL     isfilled  ,
            BOOL     isline    ,
            long   * hdl  )
{
    int iSubwinUID = 0;
    int iObjUID = 0;
    double rect[6];

    iSubwinUID = getCurrentSubWin();
    checkRedrawing();

    rect[0] = *x;
    rect[1] = *x + *width;
    rect[2] = *y - *height;
    rect[3] = *y;

    updateXYDataBounds(iSubwinUID, rect);

    iObjUID = createArc(iSubwinUID, *x, *y,
                        *height, *width, *angle1, *angle2, foreground, background, isfilled, isline);

    setCurrentObject(iObjUID);
    *hdl = getHandle(iObjUID);
}
Пример #3
0
/*
  For matplot1
*/
int C2F(implot1)(unsigned char *z, int *n1, int *n2, double *xrect, int plottype)
{
    int iSubwinUID = 0;
    int iGrayplotUID = 0;
    BOOL isRedrawn = FALSE;
    double y = 0; /* void for ConstructGrayplot */
    int clipState = 0;
    int firstPlot = 0;

    isRedrawn = checkRedrawing();

    /*---- Boundaries of the frame ----*/
    iSubwinUID = getCurrentSubWin();

    /* Force "cligrf" clipping (1) */
    clipState = 1;
    setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

    iGrayplotUID = ConstructImplot(iSubwinUID, xrect, z, *n1 + 1, *n2 + 1, plottype);
    if (iGrayplotUID == 0)
    {
        // allocation error
        Scierror(999, _("%s: No more memory.\n"), "grayplot");
        return -1;
    }

    setCurrentObject(iGrayplotUID);
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);

    return (0);
}
Пример #4
0
/* box is an OUTPUT re-used inside matdes.c in scixstring */
void Objstring(char            ** fname      ,
               int                nbRow      ,
               int                nbCol      ,
               double             x          ,
               double             y          ,
               double           * angle      ,
               double             box[4]     ,
               BOOL               autoSize   ,
               double             userSize[2],
               long             * hdl        ,
               int                centerPos  ,
               int              * foreground ,
               int              * background ,
               BOOL               isboxed    ,
               BOOL               isline     ,
               BOOL               isfilled   ,
               sciTextAlignment   alignment)
{
    char * psubwinUID = NULL;
    char * pobjUID = NULL;
    char * pfigureUID = NULL;

    pfigureUID = (char*)getCurrentFigure();
    psubwinUID = (char*)getCurrentSubWin();

    checkRedrawing();

    pobjUID = ConstructText(psubwinUID   ,
                            fname     ,
                            nbRow     ,
                            nbCol     ,
                            x         ,
                            y         ,
                            autoSize  ,
                            userSize  ,
                            centerPos ,
                            foreground,
                            background,
                            isboxed   ,
                            isline    ,
                            isfilled  ,
                            alignment);

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

    *hdl = getHandle(pobjUID);

    setGraphicObjectProperty(pobjUID, __GO_FONT_ANGLE__, angle, jni_double, 1);
}
Пример #5
0
void Objrect (double* x         ,
              double* y         ,
              double* width     ,
              double* height    ,
              int    * foreground,
              int    * background,
              BOOL     isfilled  ,
              BOOL     isline    ,
              long   * hdl )
{
    int iNewObjUID = 0;
    int iSubwinUID = 0;
    double rect[6];

    iSubwinUID = getCurrentSubWin();

    /* check if the auto_clear property is on and then erase everything */
    checkRedrawing();

    rect[0] = *x;
    rect[1] = *x + *width;
    rect[2] = *y - *height;
    rect[3] = *y;

    updateXYDataBounds(iSubwinUID, rect);

    /*newObjUID = ConstructRectangle(iSubwinUID , *x, *y, *height, *width,
      foreground, background, isfilled, isline);*/

    iNewObjUID = createRect(iSubwinUID, *x, *y, *height, *width,
                            foreground == NULL ? -1 : *foreground,
                            background == NULL ? -1 : *background,
                            (int)isfilled, (int)isline);

    if (iNewObjUID == 0)
    {
        /* an error occurred */
        *hdl = -1;
        return;
    }

    setCurrentObject(iNewObjUID);
    *hdl = getHandle(iNewObjUID);
}
Пример #6
0
/*-----------------------------------------------------------
 *   Objsegs :
 *-----------------------------------------------------------*/
void Objsegs (int * style,
              int   flag ,
              int   n1   ,
              double  * x    ,
              double  * y    ,
              double  * z    ,
              double    arsize)
{
    int iObjUID = 0;
    int iSubwinUID = 0;
    int type = 0, colored = 0;
    double *fx = NULL, *fy = NULL; // No fx or fy
    int typeofchamp = -1; /* no champ here, only segs ; this info is useless */
    double rect[6];

    checkRedrawing();
    iSubwinUID = getCurrentSubWin();

    if (n1)
    {
        MiniMaxi(x, n1, rect, rect + 1);
        MiniMaxi(y, n1, rect + 2, rect + 3);

        if (z)
        {
            MiniMaxi(z, n1, rect + 4, rect + 5);
            updateXYZDataBounds(iSubwinUID, rect);
        }
        else
        {
            updateXYDataBounds(iSubwinUID, rect);
        }
    }

    iObjUID = createSegs(iSubwinUID, x, n1, y, n1, z, (z == NULL ? 0 : n1), style, flag == 0 ? 1 : n1, arsize);

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

    setCurrentObject(iObjUID);
}
Пример #7
0
void Objpoly (double  * x     ,
              double  * y     ,
              int   n     ,
              int   closed,
              int       mark  ,
              long    * hdl)
{
    int iSubwinUID = 0;
    int iObjUID = 0;
    double rect[6];

    iSubwinUID = getCurrentSubWin();

    checkRedrawing();

    if (n)
    {
        MiniMaxi(x, n, rect, rect + 1);
        MiniMaxi(y, n, rect + 2, rect + 3);

        updateXYDataBounds(iSubwinUID, rect);
    }

    if (mark <= 0)
    {
        int absmark = abs(mark);
        iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n, 1,
                                    NULL, NULL, &absmark, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
    }
    else
    {
        iObjUID = ConstructPolyline(iSubwinUID, x, y, PD0, closed, n, 1,
                                    &mark, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
    }

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

    setCurrentObject(iObjUID);
    *hdl = getHandle(iObjUID);
}
Пример #8
0
/* return TRUE if the window has been redrawn */
BOOL checkRedrawing(void)
{
    int iAutoClear = 0;
    int* piAutoClear = &iAutoClear;

    //  nbCheckRedraw++;
    //  fprintf(stderr, "[DEBUG] checkRedrawing : %d\n", nbCheckRedraw);
    int iSubWinID = getCurrentSubWin();

    getGraphicObjectProperty(iSubWinID, __GO_AUTO_CLEAR__, jni_bool, (void **)&piAutoClear);

    if (iAutoClear)
    {
        reinitSubWin(iSubWinID);
        return TRUE;
    }

    return FALSE;
}
Пример #9
0
void Objrect (double* x         ,
              double* y         ,
              double* width     ,
              double* height    ,
              int    * foreground,
              int    * background,
              BOOL     isfilled  ,
              BOOL     isline    ,
              long   * hdl )
{
    char* newObjUID = NULL;
    char* psubwinUID = NULL;
    char* pFigureUID = NULL;

    pFigureUID = (char*)getCurrentFigure();
    psubwinUID = (char*)getCurrentSubWin();

    /* check if the auto_clear property is on and then erase everything */
    checkRedrawing();
    /*newObjUID = ConstructRectangle(psubwinUID , *x, *y, *height, *width,
      foreground, background, isfilled, isline);*/

    newObjUID = constructRectangles(psubwinUID, *x, *y, *height, *width,
                                    foreground == NULL ? -1 : *foreground,
                                    background == NULL ? -1 : *background,
                                    (int)isfilled, (int)isline);

    if (newObjUID == NULL)
    {
        /* an error occurred */
        *hdl = -1;
        return;
    }

    setCurrentObject(newObjUID);
    *hdl = getHandle(newObjUID);

    releaseGraphicObjectProperty(-1, newObjUID, jni_string, 0);
}
Пример #10
0
void Objpoly (double  * x     ,
              double  * y     ,
              int   n     ,
              int   closed,
              int       mark  ,
              long    * hdl)
{
    char * pfigureUID = NULL;
    char * psubwinUID = NULL;
    char * pobjUID = NULL;

    psubwinUID = (char*)getCurrentSubWin();

    checkRedrawing();

    if (mark <= 0)
    {
        int absmark = abs(mark);
        pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1,
                                    NULL, NULL, &absmark, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
    }
    else
    {
        pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1,
                                    &mark, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
    }

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

    setCurrentObject(pobjUID);
    *hdl = getHandle(pobjUID);

    releaseGraphicObjectProperty(__GO_POLYLINE__, pobjUID, jni_string, 1);
}
Пример #11
0
void Objarc(double* angle1    ,
            double* angle2    ,
            double* x         ,
            double* y         ,
            double* width     ,
            double* height    ,
            int    * foreground,
            int    * background,
            BOOL     isfilled  ,
            BOOL     isline    ,
            long   * hdl  )
{
    char * psubwinUID = NULL;
    char * pobjUID = NULL;

    psubwinUID = (char*)getCurrentSubWin();
    checkRedrawing();
    pobjUID = ConstructArc(psubwinUID, *x, *y,
                           *height, *width, *angle1, *angle2, foreground, background, isfilled, isline);
    setCurrentObject(pobjUID);

    *hdl = getHandle(pobjUID);
    releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1);
}
Пример #12
0
void Objdrawaxis (char     dir    ,
                  char     tics   ,
                  double* x      ,
                  int    * nx     ,
                  double* y      ,
                  int    * ny     ,
                  char   * val[]  ,
                  int      subint ,
                  char   * format ,
                  int      font   ,
                  int      textcol,
                  int      ticscol,
                  char     flag   ,
                  int      seg    ,
                  int      nb_tics_labels)
{
    char* pobjUID = NULL;
    char* psubwinUID = NULL;

    psubwinUID = (char*)getCurrentSubWin();

    checkRedrawing();

    pobjUID = ConstructAxis(
                  psubwinUID,
                  dir, tics, x, *nx, y, *ny, val, subint, format, font, textcol, ticscol, flag, seg, nb_tics_labels);

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

    setCurrentObject(pobjUID);
    releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1);
}
Пример #13
0
/*--------------------------------------------------------------------------*/
types::Function::ReturnValue sci_xset(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    wchar_t* pwcsWhat = NULL;
    std::list<types::Double*> lpDblInputs;
    int iSubwinUID = 0;

    if (in.size() == 0)
    {
        return Overload::call(L"%_xset", in, _iRetCount, out);
    }

    if (in.size() > 6)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "xset", 1, 6);
        return types::Function::Error;
    }

    if (_iRetCount > 1)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "xset", 1);
        return types::Function::Error;
    }

    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 1);
        return types::Function::Error;
    }

    types::String* pStr = in[0]->getAs<types::String>();

    if (pStr->isScalar() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 1);
        return types::Function::Error;
    }

    pwcsWhat = pStr->get(0);

    if (ConfigGraphicVariable::bPropertyFound(pwcsWhat) == false)
    {
        char* pstWhat = wide_string_to_UTF8(pwcsWhat);
        Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xset", pstWhat);
        FREE(pstWhat);
        return types::Function::Error;
    }

    // Only in case of "fpf" and "auto clear", the second argument is a string
    // Only "default" case have one input argument
    if (ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 15 && // fpf
            ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 2  && // auto clear
            ConfigGraphicVariable::getPropertyValue(pwcsWhat) != 10)   // default
    {
        for (unsigned int i = 1 ; i < in.size() ; i++)
        {
            if (in[i]->isDouble() == false)
            {
                Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), "xset", i + 1);
            }
        }
    }

    switch (ConfigGraphicVariable::getPropertyValue(pwcsWhat))
    {
        case 15 : // fpf
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            if (in[1]->isString() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            types::String* pStrValue = in[1]->getAs<types::String>();
            if (pStrValue->isScalar() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            ConfigGraphicVariable::setFPF(pStrValue->get(0));
        }
        break;
        case 2 : // auto clear
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            if (in[1]->isString() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            types::String* pStrValue = in[1]->getAs<types::String>();
            if (pStrValue->isScalar() == false)
            {
                Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int bAutoClear = 0;
            if (wcscmp(pStrValue->get(0), L"on") == 0)
            {
                bAutoClear = 1;
            }

            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, &bAutoClear, jni_bool, 1);
        }
        break;
        case 5 : // clipping
        {
            int clipState = 2;
            double dvalues[4];
            if (in.size() == 2)
            {
                types::Double* pDblArg = in[1]->getAs<types::Double>();
                if (pDblArg->getSize() != 4)
                {
                    Scierror(999, _("%s: Wrong size for input argument #%d: A %d-element vector expected.\n"), "xset", 2, 4);
                    return types::Function::Error;
                }

                memcpy(dvalues, pDblArg->get(), 4 * sizeof(double));
            }
            else if (in.size() != 5)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d or %d expected.\n"), "xset", 2, 5);
                return types::Function::Error;
            }
            else
            {
                for (int i = 0; i < 4 ; i++)
                {
                    dvalues[i] = in[i + 1]->getAs<types::Double>()->get(0);
                }
            }

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_CLIP_BOX__, dvalues, jni_double_vector, 4);
            setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 8 : // colormap
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            types::Double* pDblArg = in[1]->getAs<types::Double>();
            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP__, pDblArg->get(), jni_double_vector, pDblArg->getSize());
        }
        break;
        case 21 : // mark size
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int markSize = (int)in[1]->getAs<types::Double>()->get(0);
            int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
        }
        break;
        case 20 : // mark
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int markStyle = (int) in[1]->getAs<types::Double>()->get(0);
            int markSize = (int) in[2]->getAs<types::Double>()->get(0);
            int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */
            int markMode = 1;

            iSubwinUID = getOrCreateDefaultSubwin();
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_MODE__, &markMode, jni_bool, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1); /* force switch to tabulated mode : old syntax */
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_STYLE__, &markStyle, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
        }
        break;
        case 13 : // font size
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }
            double fontSize = in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
        }
        break;
        case 10 : // default
        {
            if (in.size() != 1)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 1);
                return types::Function::Error;
            }

            unsigned short* defcolors = ConfigGraphicVariable::getDefaultColormap();

            int piFigurePosition[2] = {200, 200};
            int piFigureSize[2]     = {500, 500};
            int piAxesSize[2]       = {498, 366};
            int piViewPort[2]       = {0, 0};
            int piEmptyMatrix[4]    = {1, 0, 0, 0};

            // init variables
            int iZero   = 0;
            BOOL bTrue  = TRUE;
            BOOL bFalse = FALSE;
            int m       = NUMCOLORS_SCI;
            int i       = 0;
            int iCopy   = 3;
            int defaultBackground = -2;

            // reset format
            ConfigGraphicVariable::setFPF(L"");

            double* pdblColorMap = new double[m * 3];
            if (pdblColorMap == NULL)
            {
                Scierror(999, _("%s: No more memory.\n"), "xset");
                return types::Function::Error;
            }

            // Create figure if it not exist.
            int iFigureUID = getCurrentFigure();
            if (iFigureUID == 0)
            {
                iFigureUID = createNewFigureWithAxes();
                setCurrentFigure(iFigureUID);
                delete[] pdblColorMap;
                return types::Function::OK;
            }

            // Create new axes and set it in current figure
            int iSubWinUID = getCurrentSubWin();
            if (iSubWinUID != 0)
            {
                int iChildrenCount  = 0;
                int* childrencount  = &iChildrenCount;
                int* childrenUID    = 0;
                int iHidden         = 0;
                int *piHidden       = &iHidden;

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

                for (i = 0; i < childrencount[0]; ++i)
                {
                    getGraphicObjectProperty(childrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
                    if (iHidden == 0)
                    {
                        deleteGraphicObject(childrenUID[i]);
                    }
                }
            }

            cloneAxesModel(iFigureUID);

            // Set default figure properties
            setGraphicObjectProperty(iFigureUID, __GO_POSITION__, piFigurePosition, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_SIZE__, piFigureSize, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_AUTORESIZE__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_VIEWPORT__, piViewPort, jni_int_vector, 2);
            setGraphicObjectProperty(iFigureUID, __GO_NAME__, _("Figure n°%d"), jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_INFO_MESSAGE__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_PIXEL_DRAWING_MODE__, &iCopy, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_ANTIALIASING__, &iZero, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_IMMEDIATE_DRAWING__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_BACKGROUND__, &defaultBackground, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_VISIBLE__, &bTrue, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_ROTATION_TYPE__, &iZero, jni_int, 1);
            setGraphicObjectProperty(iFigureUID, __GO_EVENTHANDLER__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_EVENTHANDLER_ENABLE__, &bFalse, jni_bool, 1);
            setGraphicObjectProperty(iFigureUID, __GO_USER_DATA__, piEmptyMatrix, jni_int_vector, 4);
            setGraphicObjectProperty(iFigureUID, __GO_RESIZEFCN__, "", jni_string, 1);
            setGraphicObjectProperty(iFigureUID, __GO_TAG__, "", jni_string, 1);

            for (i = 0; i < m; i++)
            {
                pdblColorMap[i]         = (double)(defcolors[3 * i] / 255.0);
                pdblColorMap[i + m]     = (double)(defcolors[3 * i + 1] / 255.0);
                pdblColorMap[i + 2 * m] = (double)(defcolors[3 * i + 2] / 255.0);
            }

            setGraphicObjectProperty(iFigureUID, __GO_COLORMAP__, pdblColorMap, jni_double_vector, 3 * m);
            setGraphicObjectProperty(iFigureUID, __GO_PARENT__, "", jni_string, 1);
            delete[] pdblColorMap;
        }
        break;
        case 6 : // clipgrf
        {
            int clipState = 1;
            /* special treatement for xset("cligrf") */
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 4 : // clipoff
        {
            int clipState = 0;
            /* special treatement for xset("clipoff") */
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
        }
        break;
        case 16 : // hidden3d
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int hiddenColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_HIDDEN_COLOR__, &hiddenColor, jni_int, 1);
        }
        break;
        case 12 : // font
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int fontStyle = (int) in[1]->getAs<types::Double>()->get(0);
            double fontSize = in[2]->getAs<types::Double>()->get(0);

            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_STYLE__, &fontStyle, jni_int, 1);
        }
        break;
        case 11 : // window
        case 30 : // figure
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            // Find if window already exists, if not create a new one
            int iID = (int)in[1]->getAs<types::Double>()->get(0);
            int iFigureUID = getFigureFromIndex(iID);
            int iAxesUID = 0;
            int* piAxesUID = &iAxesUID;

            if (iFigureUID == 0)
            {
                iFigureUID = createNewFigureWithAxes();
                setGraphicObjectProperty(iFigureUID, __GO_ID__, &iID, jni_int, 1);
            }

            setCurrentFigure(iFigureUID);
            getGraphicObjectProperty(iFigureUID, __GO_SELECTED_CHILD__, jni_int, (void**)&piAxesUID);
            setCurrentSubWin(iAxesUID);
        }
        break;
        case 14 : // foreground
        case 7 : // color
        case 23 : // pattern
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_COLOR__, &iColor, jni_int, 1);
        }
        break;
        case 3 : // background
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iColor = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_BACKGROUND__, &iColor, jni_int, 1);
        }
        break;
        case 25 : // thickness
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            sciSetLineWidth(getOrCreateDefaultSubwin(), (int)in[1]->getAs<types::Double>()->get(0));
        }
        break;
        case 19 : // line style
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int lineStyle = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
        }
        break;
        case 9 : // dashes
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int lineStyle = (int) in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
        }
        break;
        case 33 : // wresize
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iAutoResizeMode = (int)in[1]->getAs<types::Double>()->get(0);
            setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTORESIZE__, &iAutoResizeMode, jni_bool, 1);
        }
        break;
        case 32 : // wpos
        {
            int figurePosition[2];
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            getOrCreateDefaultSubwin();

            figurePosition[0] = (int)in[1]->getAs<types::Double>()->get(0);
            figurePosition[1] = (int)in[1]->getAs<types::Double>()->get(1);
            setGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, figurePosition, jni_int_vector, 2);
        }
        break;
        case 31 : // wpdim
        case 28 : // wdim
        {
            int figureSize[2] = {0, 0};
            if (in.size() != 2 && in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d or %d expected.\n"), "xset", 2, 3);
                return types::Function::Error;
            }

            figureSize[0] = (int)in[1]->getAs<types::Double>()->get(0);
            if (in.size() == 3)
            {
                figureSize[1] = (int)in[2]->getAs<types::Double>()->get(0);
            }

            /* Xwindows limits dimensions to 2^16 */
            if ((figureSize[0] > 65535) || (figureSize[1] > 65535))
            {
                figureSize[0] = std::min(figureSize[0], 65535);
                figureSize[1] = std::min(figureSize[1], 65535);
                if (ConfigVariable::getWarningMode())
                {
                    sciprint(_("%s: window dimensions have been set less than 2^16.\n"), "xset");
                }
            }

            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, figureSize, jni_int_vector, 2);
        }
        break;
        case 27 : // viewport
        {
            if (in.size() != 3)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 3);
                return types::Function::Error;
            }

            int viewport[4] = {0, 0, 0, 0};
            viewport[0] = (int)in[1]->getAs<types::Double>()->get(0);
            viewport[1] = (int)in[2]->getAs<types::Double>()->get(0);

            getOrCreateDefaultSubwin();
            setGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, viewport, jni_int_vector, 2);
        }
        break;
        case 18 : // line mode
        {
            if (in.size() != 2)
            {
                Scierror(77, _("%s: Wrong number of input arguments: %d expected.\n"), "xset", 2);
                return types::Function::Error;
            }

            int iSubwinUID = getOrCreateDefaultSubwin();
            int iZero = 0;
            int iOne = 1;

            if (in[1]->getAs<types::Double>()->get(0) == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_LINE_MODE__, &iZero, jni_bool, 1);
            }
            else
            {
                setGraphicObjectProperty(iSubwinUID, __GO_LINE_MODE__, &iOne, jni_bool, 1);
            }
        }
        break;
        default :
        {
            char* pstWhat = wide_string_to_UTF8(pwcsWhat);
            Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xset", pstWhat);
            FREE(pstWhat);
            return types::Function::Error;
        }
    }

    return types::Function::OK;
}
Пример #14
0
int plot2dn(int ptype, char *logflags, double *x, double *y, int *n1, int *n2, int *style, char *strflag, char *legend, double *brect, int *aaint,
            BOOL flagNax, int lstr1, int lstr2)
{
    int iSubwinUID = 0;
    int iCurFigureUID = 0;
    int closeflag = 0;
    int jj = 0;
    long hdl = 0;
    int *pObj = NULL;
    int cmpt = 0;
    int with_leg = 0;
    double drect[6];
    char dataflag = 0;

    BOOL bounds_changed = FALSE;
    BOOL axes_properties_changed = FALSE;

    double rotationAngles[2];
    int clipState = 0;
    int autoScale = 0;
    int logFlags[3];
    int iTmp = 0;
    int *piTmp = &iTmp;
    char textLogFlags[3];
    int firstPlot = 0;
    int newFirstPlot = 0;
    int autoSubticks = 0;

    iSubwinUID = getOrCreateDefaultSubwin();

    /*
     * Check if the auto_clear property is on and then erase everything
     * To be implemented
     */
    checkRedrawing();

    rotationAngles[0] = 0.0;
    rotationAngles[1] = 270.0;

    setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);

    /* Force logflags to those given by argument */

    getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piTmp);
    firstPlot = iTmp;

    /* Reset x and y logflags */
    if (firstPlot)
    {
        logFlags[0] = getBooleanLogFlag(logflags[1]);
        logFlags[1] = getBooleanLogFlag(logflags[2]);

        setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, &logFlags[0], jni_bool, 1);
        setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, &logFlags[1], jni_bool, 1);
    }

    /* Forces "clipgrf" clipping (1) */
    clipState = 1;
    setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

    getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piTmp);
    autoScale = iTmp;

    if (autoScale)
    {
        /* compute and merge new specified bounds with the data bounds */
        switch (strflag[1])
        {
            case '0':
                /* do not change data bounds */
                break;
            case '1':
            case '3':
            case '5':
            case '7':
                /* Force data bounds=brect */
                re_index_brect(brect, drect);
                break;
            case '2':
            case '4':
            case '6':
            case '8':
            case '9':
                /* Force data bounds to the x and y bounds */
                if ((int)strlen(logflags) < 1)
                {
                    dataflag = 'g';
                }
                else
                {
                    dataflag = logflags[0];
                }

                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[0] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[1] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[2] = iTmp;

                /* Conversion required by compute_data_bounds2 */
                textLogFlags[0] = getTextLogFlag(logFlags[0]);
                textLogFlags[1] = getTextLogFlag(logFlags[1]);
                textLogFlags[2] = getTextLogFlag(logFlags[2]);

                compute_data_bounds2(0, dataflag, textLogFlags, x, y, *n1, *n2, drect);

                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot && (strflag[1] == '5' || strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9'))
        {
            double *dataBounds;

            getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);

            drect[0] = Min(dataBounds[0], drect[0]);    /*xmin */
            drect[2] = Min(dataBounds[2], drect[2]);    /*ymin */
            drect[1] = Max(dataBounds[1], drect[1]);    /*xmax */
            drect[3] = Max(dataBounds[3], drect[3]);    /*ymax */
        }

        if (strflag[1] != '0')
        {
            bounds_changed = update_specification_bounds(iSubwinUID, drect, 2);
        }
    }

    if (firstPlot)
    {
        bounds_changed = TRUE;
    }

    /* Adapted to the MVC */
    axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);

    /* just after strflag2axes_properties */
    newFirstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &newFirstPlot, jni_bool, 1);

    with_leg = (strflag[0] == '1');

    /* F.Leray 07.10.04 : trigger algo to init. manual graduation u_xgrads and
     * u_ygrads if nax (in matdes.c which is == aaint HERE) was specified */

    /* The MVC AUTO_SUBTICKS property corresponds to !flagNax */
    autoSubticks = !flagNax;
    setGraphicObjectProperty(iSubwinUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1);

    if (flagNax == TRUE)
    {
        getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
        logFlags[0] = iTmp;
        getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
        logFlags[1] = iTmp;

        if (logFlags[0] == 0 && logFlags[1] == 0)
        {
            int autoTicks = 0;
            int i = 0;
            int iSize = 0;
            double dblFabs = 0;
            char** stringVector = NULL;

            if (aaint[1] == -1)
            {
                autoTicks = 1;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else if (aaint[1] == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else
            {
                double* dXGrads = (double*) MALLOC(aaint[1] * sizeof(double));

                // Compute X grads
                dXGrads[0] = drect[0];
                if (aaint[1] > 1)
                {
                    double pas = (drect[1] - drect[0]) / (aaint[1] - 1);
                    for (i = 0; i < aaint[1]; i++)
                    {
                        dXGrads[i] = drect[0] + pas * i;
                    }
                }

                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, dXGrads, jni_double_vector, aaint[1]);
                // Create X Labels
                stringVector = (char **) MALLOC(aaint[1] * sizeof(char*));
                for (i = 0; i < aaint[1]; i++)
                {
                    iSize = 6;
                    if (dXGrads[i] < 0)
                    {
                        iSize += 2;
                    }
                    dblFabs = fabs(dXGrads[i]);
                    if (dblFabs >= 10)
                    {
                        iSize = iSize + (int)floor(log10(dblFabs));
                    }

                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
                    sprintf(stringVector[i], "%.3f", dXGrads[i]);
                    stringVector[i][iSize - 1] = '\0';
                }

                setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[1]);

                for (i = 0; i < aaint[1]; i++)
                {
                    FREE(stringVector[i]);
                }

                FREE(stringVector);
                FREE(dXGrads);
                stringVector = NULL;
            }

            if (aaint[3] == -1)
            {
                autoTicks = 1;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else if (aaint[3] == 0)
            {
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0);
                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            }
            else
            {
                double* dYGrads = (double*) MALLOC(aaint[3] * sizeof(double));

                // Compute Y grads
                dYGrads[0] = drect[2];
                if (aaint[3] > 1)
                {
                    double pas = (drect[3] - drect[2]) / (aaint[3] - 1);
                    for (i = 0; i < aaint[3]; i++)
                    {
                        dYGrads[i] = drect[2] + pas * i;
                    }
                }

                autoTicks = 0;
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, dYGrads, jni_double_vector, aaint[3]);

                // Create Y Labels
                stringVector = (char**) MALLOC(aaint[3] * sizeof(char*));
                for (i = 0; i < aaint[3]; i++)
                {
                    iSize = 6;
                    if (dYGrads[i] < 0)
                    {
                        iSize += 2;
                    }
                    dblFabs = fabs(dYGrads[i]);
                    if (dblFabs >= 10)
                    {
                        iSize = iSize + (int)floor(log10(dblFabs));
                    }
                    stringVector[i] = (char*) MALLOC(iSize * sizeof(char));
                    sprintf(stringVector[i], "%.3f", dYGrads[i]);
                    stringVector[i][iSize - 1] = '\0';
                }

                setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[3]);

                for (i = 0; i < aaint[3]; i++)
                {
                    FREE(stringVector[i]);
                }

                FREE(stringVector);
                FREE(dYGrads);
                stringVector = NULL;
            }

            // X and Y subticks
            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_SUBTICKS__, aaint, jni_int, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_SUBTICKS__, &aaint[2], jni_int, 1);
        }
        else
        {
            sciprint(_("Warning: Nax does not work with logarithmic scaling.\n"));
        }

    }

    /*---- Drawing the curves and the legends ----*/
    if (*n1 != 0)
    {
        if ((pObj = (int*)MALLOC((*n1 + 1) * sizeof(int))) == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "plot2d");
            return -1;
        }

        /*A.Djalel 3D axes */
        for (jj = 0; jj < *n1; jj++)
        {
            int iObjUID = 0;

            if (style[jj] > 0)
            {
                BOOL isline = TRUE;

                if (ptype == 3)
                {
                    isline = FALSE;
                }
                iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]),
                                            &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype,
                                            &style[jj], NULL, NULL, NULL, NULL, isline, FALSE, FALSE, FALSE);
            }
            else
            {
                int minusstyle = -style[jj];

                iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]),
                                            &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype,
                                            NULL, NULL, &minusstyle, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
            }
            if (iObjUID == 0)
            {
                // skip
                Scierror(999, _("%s: No more memory.\n"), "plot2d");
            }
            else
            {
                setCurrentObject(iObjUID);

                pObj[cmpt] = iObjUID;
                cmpt++;
            }

        }

        /*---- Drawing the Legends ----*/
        if (with_leg)
        {
            int iLegUID = 0;
            char **Str;
            int nleg;

            if (scitokenize(legend, &Str, &nleg))
            {
                FREE(pObj);
                Scierror(999, _("%s: No more memory.\n"), "plot2d");
                return 0;
            }

            iLegUID = ConstructLegend(getCurrentSubWin(), Str, pObj, Min(nleg, cmpt));

            if (iLegUID != 0)
            {
                int legendLocation;
                int contourMode;

                /* 9: LOWER_CAPTION */
                legendLocation = 9;
                setGraphicObjectProperty(iLegUID, __GO_LEGEND_LOCATION__, &legendLocation, jni_int, 1);

                contourMode = 0;

                setGraphicObjectProperty(iLegUID, __GO_FILL_MODE__, &contourMode, jni_bool, 1);
                setGraphicObjectProperty(iLegUID, __GO_LINE_MODE__, &contourMode, jni_bool, 1);
            }

            freeArrayOfString(Str, nleg);
        }

        /*---- construct Compound ----*/
        if (cmpt > 0)
        {
            int parentVisible = 0;
            int *piParentVisible = &parentVisible;
            int iCompoundUID = createCompound(iSubwinUID, pObj, cmpt);
            setCurrentObject(iCompoundUID);
        }
        FREE(pObj);

    }
    /* End of the curves and legend block */

    return 0;
}
Пример #15
0
/*--------------------------------------------------------------------------*/
int sci_drawaxis(char *fname, void* pvApiCtx)
{
    /** XXXXX : un point en suspens c'est le "S" ou une adresse est
     *  stockees ds un unsigned long : est ce sufisant ?
     */
    static rhs_opts opts[] =
    {
        { -1, "dir", -1, 0, 0, NULL},
        { -1, "fontsize", -1, 0, 0, NULL},
        { -1, "format_n", -1, 0, 0, NULL},
        { -1, "seg", -1, 0, 0, NULL},
        { -1, "sub_int", -1, 0, 0, NULL},
        { -1, "textcolor", -1, 0, 0, NULL},
        { -1, "tics", -1, 0, 0, NULL},
        { -1, "ticscolor", -1, 0, 0, NULL},
        { -1, "val", -1, 0, 0, NULL},
        { -1, "x", -1, 0, 0, NULL},
        { -1, "y", -1, 0, 0, NULL},
        { -1, NULL, -1, 0, 0, NULL}
    };

    int iSubwinUID = 0;
    int minrhs = -1, maxrhs = 0, minlhs = 0, maxlhs = 1, nopt = 0;
    char dir = 'l', *format = NULL, tics = 'v', **val = NULL;
    int fontsize = -1, sub_int = 2, seg_flag = 1, textcolor = -1, ticscolor = -1;
    double *x = NULL, *y = NULL;
    int nx = 0, ny = 0, ntics;
    int nb_tics_labels = -1;
    int iRhs = nbInputArgument(pvApiCtx);

    nopt = NumOpt(pvApiCtx);

    CheckInputArgument(pvApiCtx, minrhs, maxrhs + nopt);
    CheckOutputArgument(pvApiCtx, minlhs, maxlhs);

    if (getOptionals(pvApiCtx, fname, opts) == 0)
    {
        /* error */
        return 0;
    }

    iSubwinUID = getOrCreateDefaultSubwin();

    if (opts[0].iPos != -1)
    {
        char* pstDir = NULL;
        //CheckLength
        if (opts[0].iRows != 1 || opts[0].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[0].iPos, opts[0].iRows);
            return 1;
        }

        if (getAllocatedSingleString(pvApiCtx, opts[0].piAddr, &pstDir))
        {
            return 1;
        }
        dir = pstDir[0];
        freeAllocatedSingleString(pstDir);
    }
    if (opts[1].iPos != -1)
    {
        double dblSize = 0;
        //CheckScalar
        if (opts[1].iRows != 1 || opts[1].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[1].iPos);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[1].piAddr, &dblSize);
        fontsize = (int)dblSize;
    }
    if (opts[2].iPos != -1)
    {
        /* verfier ce que l'on recoit avec "" XXX */
        if (getAllocatedSingleString(pvApiCtx, opts[2].piAddr, &format))
        {
            return 1;
        }
    }

    if (opts[3].iPos != -1)
    {
        double dblSeq = 0;
        //CheckScalar
        if (opts[3].iRows != 1 || opts[3].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[3].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }


        getScalarDouble(pvApiCtx, opts[3].piAddr, &dblSeq);
        seg_flag = (int)dblSeq;
    }

    if (opts[4].iPos != -1)
    {
        double dblSub = 0;
        //CheckScalar
        if (opts[4].iRows != 1 || opts[4].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[4].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[4].piAddr, &dblSub);
        sub_int = (int)dblSub;
    }

    if (opts[5].iPos != -1)
    {
        double dblColor = 0;
        //CheckScalar
        if (opts[5].iRows != 1 || opts[5].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[5].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[5].piAddr, &dblColor);
        textcolor = (int)dblColor;
    }

    if (opts[6].iPos != -1)
    {
        char* pstTics = NULL;
        //CheckLength
        if (opts[6].iRows != 1 || opts[6].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[6].iPos, opts[6].iRows);
            freeAllocatedSingleString(format);
            return 1;
        }

        if (getAllocatedSingleString(pvApiCtx, opts[6].piAddr, &pstTics))
        {
            return 1;
        }
        tics = pstTics[0];
        freeAllocatedSingleString(pstTics);
    }

    if (opts[7].iPos != -1)
    {
        double dblColor = 0;
        //CheckScalar
        if (opts[7].iRows != 1 || opts[7].iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, opts[7].iPos);
            freeAllocatedSingleString(format);
            return 1;
        }

        getScalarDouble(pvApiCtx, opts[7].piAddr, &dblColor);
        ticscolor = (int)dblColor;
    }

    if (opts[8].iPos != -1)
    {
        if (getAllocatedMatrixOfString(pvApiCtx, opts[8].piAddr, &opts[8].iRows, &opts[8].iCols, &val))
        {
            return 1;
        }
    }

    if (opts[9].iPos != -1)
    {
        getMatrixOfDouble(pvApiCtx, opts[9].piAddr, &opts[9].iRows, &opts[9].iCols, &x);
        nx = opts[9].iRows * opts[9].iCols; /* F.Leray OK here opts[9].iRows and opts[9].iCols are integers. */
    }
    else
    {
        static double x_def[1];
        double *bounds;
        int iCurrentSubwinUID = getCurrentSubWin();

        getGraphicObjectProperty(iCurrentSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
        nx = 1;
        x = x_def;
        if (dir == 'l')
        {
            x_def[0] = bounds[0];    /* xMin */
        }
        else if (dir == 'r')
        {
            x_def[0] = bounds[1];    /* xMax */
        }
    }

    if (opts[10].iPos != -1)
    {
        getMatrixOfDouble(pvApiCtx, opts[10].piAddr, &opts[10].iRows, &opts[10].iCols, &y);
        ny = opts[10].iRows * opts[10].iCols;
    }
    else
    {
        static double y_def[1];
        double *bounds;
        int iCurrentSubwinUID = getCurrentSubWin();

        getGraphicObjectProperty(iCurrentSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&bounds);
        ny = 1;
        y = y_def;
        if (dir == 'd')
        {
            y_def[0] = bounds[2];    /* yMin */
        }
        else if (dir == 'u')
        {
            y_def[0] = bounds[3];    /* yMax */
        }
    }

    /* compatibility test */
    switch (tics)
    {
        case 'r':
            if (check_xy(fname, dir, 3, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        case 'i':
            if (check_xy(fname, dir, 4, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        case 'v':
            if (check_xy(fname, dir, -1, opts[9].iPos, opts[9].iRows, opts[9].iCols, x,
                         opts[10].iPos, opts[10].iRows, opts[10].iCols, y, &ntics) == 0)
            {
                ReturnArguments(pvApiCtx);
                freeAllocatedSingleString(format);
                freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
                return 0;
            }
            break;
        default:
            Scierror(999, _("%: Wrong value for %s '%c': '%s', '%s' and '%s' expected.\n"), fname, "tics", dir, "r", "v", "i");
            freeAllocatedSingleString(format);
            freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
            return 0;
    }

    if (val != NULL)
    {
        //CheckLength
        if (opts[8].iRows * opts[8].iCols != ntics)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: %d expected.\n"), fname, opts[8].iPos, opts[8].iRows * opts[8].iCols);
            freeAllocatedSingleString(format);
            freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
            return 1;
        }

        nb_tics_labels = opts[8].iRows * opts[8].iCols;
    }

    Objdrawaxis(dir, tics, x, &nx, y, &ny, val, sub_int, format, fontsize, textcolor, ticscolor, 'n', seg_flag, nb_tics_labels);

    freeAllocatedSingleString(format);
    if (val != NULL)
    {
        freeAllocatedMatrixOfString(opts[8].iRows, opts[8].iCols, val);
    }
    createScalarHandle(pvApiCtx, iRhs + 1, getHandle(getCurrentObject()));
    AssignOutputVariable(pvApiCtx, 1) = iRhs + 1;
    ReturnArguments(pvApiCtx);
    return 0;
}
Пример #16
0
void champg(char *name, int colored, double *x, double *y, double *fx, double *fy, int *n1,
            int *n2, char *strflag, double *brect, double *arfact, int lstr)
{
    int iSubwinUID = 0;
    int iNewSegsUID = 0;

    int clipState = 0;
    char textLogFlags[3];
    double xx[2];
    double yy[2];
    double* boundingBox = NULL;
    double rotationAngles[2];
    int nn1 = 1;
    int nn2 = 2;
    int autoScale = 0;
    int* piAutoScale = &autoScale;
    int firstPlot = 0;
    int* piFirstPlot = &firstPlot;
    int logFlags[3];
    int flag, type = 1;
    double arsize1 = 0.;
    int *style = NULL;

    int iTmp = 0;
    int* piTmp = &iTmp;

    int i = 0;
    double drect[6];
    BOOL bounds_changed = FALSE;
    BOOL axes_properties_changed = FALSE;

    /* champ with color inherited from subwin */
    /* or champ1 (normed vector + color) is enabled */
    int typeofchamp = (colored == 0 ? 0 : 1);

    /* First create champ object */
    /* F.Leray Allocation de style[dim = Nbr1] */
    if ((style = (int*)MALLOC ((*n1) * sizeof (int))) == NULL)
    {
        Scierror(999, _("%s: No more memory.\n"), "champg");
        return;
    }

    flag = 1; /* je le mets � 1 pour voir F.Leray 19.02.04*/
    arsize1 = *arfact;

    iSubwinUID = getCurrentSubWin();

    /* then modify subwindow if needed */
    checkRedrawing();

    /* Force clipping to CLIPGRF (1) */
    clipState = 1;
    setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

    for (i = 0; i < (*n1); i++)
    {
        style[i] = i;
    }

    iNewSegsUID = createChamp(iSubwinUID, x, *n1, y, *n2, fx, *n1 * *n2, fy, *n1 * *n2, arsize1, typeofchamp != 0);

    if (iNewSegsUID == 0)
    {
        Scierror(999, _("%s: No more memory.\n"), "champg");
        if (style != NULL)
        {
            FREE(style);
        }

        return;
    }

    setCurrentObject(iNewSegsUID);

    if (style != NULL)
    {
        FREE(style);
        style = NULL;
    }

    /* Get segs bounding box */
    getGraphicObjectProperty(iNewSegsUID, __GO_BOUNDING_BOX__, jni_double_vector, (void **)&boundingBox);
    if (!boundingBox)
    {
        Scierror(999, _("%s: Could not retrive bounding box.\n"), "champg");
        return;
    }

    xx[0] = boundingBox[0];
    xx[1] = boundingBox[1];
    yy[0] = boundingBox[2];
    yy[1] = boundingBox[3];

    releaseGraphicObjectProperty(__GO_BOUNDING_BOX__, boundingBox, jni_double_vector, 4);

    rotationAngles[0] = 0.0;
    rotationAngles[1] = 270.0;

    setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);

    getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piAutoScale);

    getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piFirstPlot);

    if (autoScale)
    {
        /* compute and merge new specified bounds with the data bounds */
        switch (strflag[1])
        {
            case '0':
                /* do not change data bounds */
                break;
            case '1' :
            case '3' :
            case '5' :
            case '7':
                /* Force data bounds=brect */
                re_index_brect(brect, drect);
                break;
            case '2' :
            case '4' :
            case '6' :
            case '8':
            case '9':

                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[0] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[1] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[2] = iTmp;

                /* Conversion required by compute_data_bounds2 */
                textLogFlags[0] = getTextLogFlag(logFlags[0]);
                textLogFlags[1] = getTextLogFlag(logFlags[1]);
                textLogFlags[2] = getTextLogFlag(logFlags[2]);

                /* Force data bounds to the x and y bounds */
                compute_data_bounds2(0, 'g', textLogFlags, xx, yy, nn1, nn2, drect);
                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot &&
                (strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9'))
        {
            double* dataBounds;

            getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);

            drect[0] = Min(dataBounds[0], drect[0]); /*xmin*/
            drect[2] = Min(dataBounds[2], drect[2]); /*ymin*/
            drect[1] = Max(dataBounds[1], drect[1]); /*xmax*/
            drect[3] = Max(dataBounds[3], drect[3]); /*ymax*/
        }

        if (strflag[1] != '0')
        {
            bounds_changed = update_specification_bounds(iSubwinUID, drect, 2);
        }

    }

    if (firstPlot)
    {
        bounds_changed = TRUE;
    }

    axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);

    /* just after strflag2axes_properties */
    firstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);
}
Пример #17
0
/*------------------------------------------------
 *  plot3d
 *-----------------------------------------------*/
void Objplot3d (char    * fname ,
                int * isfac ,
                int * izcol ,
                double    x[]   ,
                double    y[]   ,
                double    z[]   ,
                double  * zcol  ,
                int * m     ,
                int * n     ,
                double  * theta ,
                double  * alpha ,
                char    * legend,
                int * iflag ,
                double  * ebox  ,
                int * m1    , /*Adding F.Leray 12.03.04 and 19.03.04*/
                int * n1    ,
                int * m2    ,
                int * n2    ,
                int * m3    ,
                int * n3    ,
                int * m3n   ,
                int * n3n)
/* F.Leray 25.04.05 : warning here legends means "X@Y@Z": it is labels writings!! */
/* legends has not the same meaning than inside plot2dn (there, it is really the legends of the plotted curves)*/
{
    sciTypeOf3D typeof3d;
    int flagcolor = 0;
    long *hdltab = NULL;
    int i = 0;

    char *psubwinUID = NULL;
    char *pobjUID = NULL;
    char *parentFigureUID = NULL;

    double drect[6];
    double rotationAngles[2];
    double* dataBounds = NULL;
    char * loc = NULL;
    char * legx = NULL;
    char * legy = NULL;
    char * legz = NULL;
    char* labelId = NULL;
    /*   char * buff = NULL; */
    int flag_x = 1;
    int flag_y = 1;
    int dimvectx = -1;
    int dimvecty = -1;
    int view = 0;
    int linLogFlag;
    int firstPlot = 0;
    int *piFirstPlot = &firstPlot;

    int box = 0;
    int axisVisible = 0;
    int autoScale = 0;
    int *piAutoScale = &autoScale;

    int isoview = 0;
    int clipState = 0;

    char *pNewSurfaceUID = NULL;


    /* Initialisation drect A.C pour debuggueur */
    drect[0] = 0.0;
    drect[1] = 0.0;
    drect[2] = 0.0;
    drect[3] = 0.0;
    drect[4] = 0.0;
    drect[5] = 0.0;

    /* =================================================
     * Force SubWindow properties according to arguments
     * ================================================= */

    parentFigureUID = (char*)getCurrentFigure();
    psubwinUID = (char*)getCurrentSubWin();

    checkRedrawing();

    /* Force 3D view */
    view = 1;
    setGraphicObjectProperty(psubwinUID, __GO_VIEW__, &view, jni_int, 1);

    if (legend != NULL)
    {
        int textDimensions[2] = {1, 1};
        /* F.Leray 25.04.05 replace the default labels by the user labels if specified */
        loc = (char *) MALLOC((strlen(legend) + 1) * sizeof(char));
        if (loc == NULL)
        {
            Scierror(999, _("%s: No more memory.\n"), "Objplot3d");
        }

        strcpy(loc, legend);

        /*   legx=strtok_r(loc,"@",&buff); */
        legx = strtok(loc, "@");

        if (legx != NULL)
        {
            getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, (void **)&labelId);

            setGraphicObjectProperty(labelId, __GO_TEXT_ARRAY_DIMENSIONS__, textDimensions, jni_int_vector, 2);
            setGraphicObjectProperty(labelId, __GO_TEXT_STRINGS__, &legx, jni_string_vector, textDimensions[0]*textDimensions[1]);
        }

        /*   legy=strtok_r((char *)0,"@",&buff); */
        legy = strtok((char *)NULL, "@"); /* NULL to begin at the last read character */
        if (legy != NULL)
        {
            getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, (void **)&labelId);

            setGraphicObjectProperty(labelId, __GO_TEXT_ARRAY_DIMENSIONS__, textDimensions, jni_int_vector, 2);
            setGraphicObjectProperty(labelId, __GO_TEXT_STRINGS__, &legy, jni_string_vector, textDimensions[0]*textDimensions[1]);
        }

        /*   legz=strtok_r((char *)0,"@",&buff); */
        legz = strtok((char *)NULL, "@");
        if (legz != NULL)
        {
            getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, (void **)&labelId);

            setGraphicObjectProperty(labelId, __GO_TEXT_ARRAY_DIMENSIONS__, textDimensions, jni_int_vector, 2);
            setGraphicObjectProperty(labelId, __GO_TEXT_STRINGS__, &legz, jni_string_vector, textDimensions[0]*textDimensions[1]);
        }
    }

    /* Force psubwin->logflags to linear */
    linLogFlag = 0;

    setGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LOG_FLAG__, &linLogFlag, jni_bool, 1);
    setGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LOG_FLAG__, &linLogFlag, jni_bool, 1);
    setGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LOG_FLAG__, &linLogFlag, jni_bool, 1);


    getGraphicObjectProperty(psubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piFirstPlot);

    if (firstPlot == 0 && (iflag[2] == 0 || iflag[2] == 1))
    {
        /* Nothing to do: we leave as before */
    }
    else
    {
        int labelVisible;

        if (iflag[2] == 0 || iflag[2] == 1)
        {
            if (firstPlot)
            {
                /* 0: OFF */
                box = 0;

                axisVisible = 0;
                setGraphicObjectProperty(psubwinUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
                setGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
                setGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);

                setGraphicObjectProperty(psubwinUID, __GO_BOX_TYPE__, &box, jni_int, 1);

                labelVisible = 0;
                getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, (void **)&labelId);
                setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
                getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, (void **)&labelId);
                setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
                getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, (void **)&labelId);
                setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            }
            /*else no changes : the axes visible properties are driven by the previous plot */
        }
        else if (iflag[2] == 2)
        {
            /* 2: HIDDEN_AXES */
            box = 2;

            /* for 2d use only (when switching to 2d mode) */
            setGraphicObjectProperty(psubwinUID, __GO_BOX_TYPE__, &box, jni_int, 1);

            axisVisible = 0;
            setGraphicObjectProperty(psubwinUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);

            labelVisible = 0;
            getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
        }
        else if (iflag[2] == 3)
        {
            /* 1: ON */
            box = 1;

            /* for 2d use only (when switching to 2d mode) */
            setGraphicObjectProperty(psubwinUID, __GO_BOX_TYPE__, &box, jni_int, 1);

            axisVisible = 0;
            setGraphicObjectProperty(psubwinUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);

            labelVisible = 1;
            getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
        }
        else if (iflag[2] == 4)
        {
            /* 1: ON */
            box = 1;
            setGraphicObjectProperty(psubwinUID, __GO_BOX_TYPE__, &box, jni_int, 1);

            axisVisible = 1;
            setGraphicObjectProperty(psubwinUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);
            setGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1);

            labelVisible = 1;
            getGraphicObjectProperty(psubwinUID, __GO_X_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Y_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
            getGraphicObjectProperty(psubwinUID, __GO_Z_AXIS_LABEL__, jni_string, (void **)&labelId);
            setGraphicObjectProperty(labelId, __GO_VISIBLE__, &labelVisible, jni_bool, 1);
        }
    }

    rotationAngles[0] = *alpha;
    rotationAngles[1] = *theta;

    setGraphicObjectProperty(psubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);

    getGraphicObjectProperty(psubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);

    getGraphicObjectProperty(psubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piAutoScale);

    if (autoScale)
    {
        /* compute and merge new specified bounds with data bounds */
        switch (iflag[1])
        {
            case 0:  /* do not change data bounds */
                break;
            case 1 :
            case 3 :
            case 5 :
            case 7 : /* Force data bounds=ebox */
                drect[0] = ebox[0]; /*xmin*/
                drect[2] = ebox[2]; /*ymin*/
                drect[1] = ebox[1]; /*xmax*/
                drect[3] = ebox[3]; /*ymax*/
                drect[4] = ebox[4]; /*zmin*/
                drect[5] = ebox[5]; /*zmax*/
                break;
            case 2 :
            case 4 :
            case 6 :
            case 8:/* Force data bounds to the x and y bounds */
                getDrect(x, (*m1) * (*n1), &drect[0], &drect[1], dataBounds[0], dataBounds[1]);
                getDrect(y, (*m2) * (*n2), &drect[2], &drect[3], dataBounds[2], dataBounds[3]);
                getDrect(z, (*m3) * (*n3), &drect[4], &drect[5], dataBounds[4], dataBounds[5]);
                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot)
        {
            drect[0] = Min(dataBounds[0], drect[0]); /* xmin */
            drect[1] = Max(dataBounds[1], drect[1]); /* xmax */
            drect[2] = Min(dataBounds[2], drect[2]); /* ymin */
            drect[3] = Max(dataBounds[3], drect[3]); /* ymax */
            drect[4] = Min(dataBounds[4], drect[4]); /* zmin */
            drect[5] = Max(dataBounds[5], drect[5]); /* zmax */
        }

        if (iflag[1] != 0)
        {
            setGraphicObjectProperty(psubwinUID, __GO_DATA_BOUNDS__, drect, jni_double_vector, 6);
        }
    }

    if (iflag[1] != 0)
    {
        isoview = (iflag[1] == 3 || iflag[1] == 4 || iflag[1] == 5 || iflag[1] == 6);

        setGraphicObjectProperty(psubwinUID, __GO_ISOVIEW__, &isoview, jni_bool, 1);
    }

    /* =================================================
     * Analyze arguments to find entity type
     * ================================================= */

    if (*isfac == 1)
    {
        if (*izcol == 0)
        {
            if (strcmp(fname, "plot3d1") == 0)
            {
                typeof3d = SCI_FAC3D;
                flagcolor = 1;
            }
            else
            {
                typeof3d = SCI_FAC3D;
                flagcolor = 0;
            }
        }
        else if (*izcol == 2)
        {
            typeof3d = SCI_FAC3D;
            flagcolor = 3;
        }
        else
        {
            typeof3d = SCI_FAC3D;
            flagcolor = 2;
        }
    }
    else if (*isfac == 0)
    {
        if (strcmp(fname, "plot3d1") == 0)
        {
            typeof3d = SCI_PLOT3D;
            flagcolor = 1;
        }
        else
        {
            typeof3d = SCI_PLOT3D;
            flagcolor = 0;
        }
    }
    else
    {
        typeof3d = SCI_PARAM3D1;
        flagcolor = 1;
    }

    /* =================================================
     * Construct the Entities
     * ================================================= */

    /*Distinction here between SCI_PARAM3D1 and others*/
    if (typeof3d != SCI_PARAM3D1)
    {
        if (*isfac == 1)
        {
            /* x is considered as a matrix */
            dimvectx = -1;
        }
        else if (*m1 == 1) /* x is a row vector */
        {
            dimvectx = *n1;
        }
        else if (*n1 == 1) /* x is a column vector */
        {
            dimvectx = *m1;
        }
        else /* x is a matrix */
        {
            dimvectx = -1;
        }

        if (dimvectx > 1)
        {
            int monotony = checkMonotony(x, dimvectx);
            if (monotony == 0)
            {
                Scierror(999, _("%s: x vector is not monotonous.\n"), "Objplot3d");
                return;
            }

            flag_x = monotony;
        }

        if (*isfac == 1)
        {
            /* y is considered as a matrix */
            dimvecty = -1;
        }
        else if (*m2 == 1) /* y is a row vector */
        {
            dimvecty = *n2;
        }
        else if (*n2 == 1) /* y is a column vector */
        {
            dimvecty = *m2;
        }
        else /* y is a matrix */
        {
            dimvecty = -1;
        }

        if (dimvecty > 1)
        {
            /* test the monotony on y*/
            int monotony = checkMonotony(y, dimvecty);
            if (monotony == 0)
            {
                Scierror(999, _("%s: y vector is not monotonous.\n"), "Objplot3d");
                return;
            }

            flag_y = monotony;
        }

        pNewSurfaceUID = ConstructSurface(psubwinUID, typeof3d,
                                          x, y, z, zcol, *izcol, *m, *n, iflag, ebox, flagcolor,
                                          isfac, m1, n1, m2, n2, m3, n3, m3n, n3n);

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

        setCurrentObject(pNewSurfaceUID);

        /* Force clipping, 1: CLIPGRF */
        clipState = 1;
        setGraphicObjectProperty(pNewSurfaceUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

        releaseGraphicObjectProperty(__GO_PARENT__, pNewSurfaceUID, jni_string, 1);
    }
    else
    {
        char* pNewPolylineUID = NULL;
        char* currentSubwinUID = NULL;

        if ((hdltab = MALLOC (*n * sizeof (long))) == NULL)
        {
            Scierror(999, "%s: No more memory.\n", fname);
            return;
        }

        currentSubwinUID = (char*)getCurrentSubWin();

        for (i = 0; i < *n; ++i)
        {
            /* F.Leray Pb here: In fact we do not create a Surface but one or several 3D Polylines
               Pb comes when wanting to access the fields "surface_color" or "flag" for example
               in function sciSet (cf. matdes.c).
               Question 1: Are these properties accessible from a SCI_PARAM3D1 ?
               Question 2: Is "flag" obsolete and replaced by "color_mode"?*/

            if ((*n > 0) && (zcol != (double *)NULL))
            {
                if ((int) zcol[i] > 0)
                {
                    int intzcol = (int) zcol[i];
                    pNewPolylineUID = ConstructPolyline
                                      (currentSubwinUID,
                                       &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                       &intzcol, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
                }
                else
                {
                    int intzcol = (int) - zcol[i];
                    pNewPolylineUID = ConstructPolyline
                                      (currentSubwinUID,
                                       &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                       NULL, NULL, &intzcol, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
                }
            }
            else
            {
                /* default case, nothing is given */
                int curcolor = 0;
                int *piCurColor = &curcolor;

                getGraphicObjectProperty(currentSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piCurColor);

                pNewPolylineUID = ConstructPolyline(currentSubwinUID,
                                                    &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                                    &curcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
            }

            if (pNewPolylineUID == NULL)
            {
                Scierror(999, _("%s: No more memory.\n"), fname);
                FREE(hdltab);
                return;
            }

            setCurrentObject(pNewPolylineUID);
            setGraphicObjectRelationship(currentSubwinUID, pNewPolylineUID);
            releaseGraphicObjectProperty(__GO_PARENT__, pNewPolylineUID, jni_string, 1);
            pNewPolylineUID = NULL;

            pobjUID = (char*)getCurrentObject();

            /* Force clipping, 1: CLIPGRF */
            clipState = 1;
            setGraphicObjectProperty(pobjUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

            hdltab[i] = getHandle(pobjUID);
        }

        /** construct Compound and make it current object**/
        if (*n > 1)
        {
            char* o = ConstructCompound (hdltab, *n);
            setCurrentObject(o);
            releaseGraphicObjectProperty(__GO_PARENT__, o, jni_string, 1);
        }
        FREE(hdltab);
    }

    /* =================================================
     * Redraw Figure
     * ================================================= */

    // subwin has been modified

    firstPlot = 0;
    setGraphicObjectProperty(psubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);

    FREE(loc);
    loc = NULL;

}
Пример #18
0
/*------------------------------------------------
 *  plot3d
 *-----------------------------------------------*/
void Objplot3d (char    * fname ,
                int * isfac ,
                int * izcol ,
                double    x[]   ,
                double    y[]   ,
                double    z[]   ,
                double  * zcol  ,
                int * m     ,
                int * n     ,
                double  * theta ,
                double  * alpha ,
                char    * legend,
                int * iflag ,
                double  * ebox  ,
                int * m1    , /*Adding F.Leray 12.03.04 and 19.03.04*/
                int * n1    ,
                int * m2    ,
                int * n2    ,
                int * m3    ,
                int * n3    ,
                int * m3n   ,
                int * n3n)
/* F.Leray 25.04.05 : warning here legends means "X@Y@Z": it is labels writings!! */
/* legends has not the same meaning than inside plot2dn (there, it is really the legends of the plotted curves)*/
{
    sciTypeOf3D typeof3d;
    int flagcolor = 0;
    int* pObj = NULL;
    int i = 0;

    int iSubwinUID = 0;

    int firstPlot = 0;

    int clipState = 0;

    int iNewSurfaceUID = 0;


    /* =================================================
     * Force SubWindow properties according to arguments
     * ================================================= */

    iSubwinUID = getCurrentSubWin();
    checkRedrawing();
    initSubWinTo3d(iSubwinUID, legend, iflag, *alpha, *theta, ebox, x, *m1 **n1, y, *m2 **n2, z, *m3 **n3);

    /* =================================================
     * Analyze arguments to find entity type
     * ================================================= */

    if (*isfac == 1)
    {
        if (*izcol == 0)
        {
            if (strcmp(fname, "plot3d1") == 0)
            {
                typeof3d = SCI_FAC3D;
                flagcolor = 1;
            }
            else
            {
                typeof3d = SCI_FAC3D;
                flagcolor = 0;
            }
        }
        else if (*izcol == 2)
        {
            typeof3d = SCI_FAC3D;
            flagcolor = 3;
        }
        else
        {
            typeof3d = SCI_FAC3D;
            flagcolor = 2;
        }
    }
    else if (*isfac == 0)
    {
        if (strcmp(fname, "plot3d1") == 0)
        {
            typeof3d = SCI_PLOT3D;
            flagcolor = 1;
        }
        else
        {
            typeof3d = SCI_PLOT3D;
            flagcolor = 0;
        }
    }
    else
    {
        typeof3d = SCI_PARAM3D1;
        flagcolor = 1;
    }

    /* =================================================
     * Construct the Entities
     * ================================================= */

    /*Distinction here between SCI_PARAM3D1 and others*/
    if (typeof3d != SCI_PARAM3D1)
    {
        int dimvectx = -1;
        int dimvecty = -1;
        if (*isfac == 1)
        {
            /* x is considered as a matrix */
            dimvectx = -1;
        }
        else if (*m1 == 1) /* x is a row vector */
        {
            dimvectx = *n1;
        }
        else if (*n1 == 1) /* x is a column vector */
        {
            dimvectx = *m1;
        }
        else /* x is a matrix */
        {
            dimvectx = -1;
        }

        if (dimvectx > 1)
        {
            int monotony = checkMonotony(x, dimvectx);
            if (monotony == 0)
            {
                Scierror(999, _("%s: x vector is not monotonous.\n"), "Objplot3d");
                return;
            }

        }

        if (*isfac == 1)
        {
            /* y is considered as a matrix */
            dimvecty = -1;
        }
        else if (*m2 == 1) /* y is a row vector */
        {
            dimvecty = *n2;
        }
        else if (*n2 == 1) /* y is a column vector */
        {
            dimvecty = *m2;
        }
        else /* y is a matrix */
        {
            dimvecty = -1;
        }

        if (dimvecty > 1)
        {
            /* test the monotony on y*/
            int monotony = checkMonotony(y, dimvecty);
            if (monotony == 0)
            {
                Scierror(999, _("%s: y vector is not monotonous.\n"), "Objplot3d");
                return;
            }
        }

        iNewSurfaceUID = ConstructSurface(iSubwinUID, typeof3d,
                                          x, y, z, zcol, *izcol, *m, *n, iflag, ebox, flagcolor,
                                          isfac, m1, n1, m2, n2, m3, n3, m3n, n3n);

        if (iNewSurfaceUID == 0)
        {
            Scierror(999, _("%s: No more memory.\n"), "Objplot3d");
            return;
        }

        setCurrentObject(iNewSurfaceUID);

        /* Force clipping, 1: CLIPGRF */
        clipState = 1;
        setGraphicObjectProperty(iNewSurfaceUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);
    }
    else
    {
        int iNewPolylineUID = 0;
        int iCurrentSubwinUID = 0;

        if ((pObj = (int*)MALLOC (*n * sizeof (int))) == NULL)
        {
            Scierror(999, "%s: No more memory.\n", fname);
            return;
        }

        iCurrentSubwinUID = getCurrentSubWin();

        for (i = 0; i < *n; ++i)
        {
            if ((*n > 0) && (zcol != (double *)NULL))
            {
                if ((int) zcol[i] > 0)
                {
                    int intzcol = (int) zcol[i];
                    iNewPolylineUID = ConstructPolyline
                                      (iCurrentSubwinUID,
                                       &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                       &intzcol, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
                }
                else
                {
                    int intzcol = (int) - zcol[i];
                    iNewPolylineUID = ConstructPolyline
                                      (iCurrentSubwinUID,
                                       &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                       NULL, NULL, &intzcol, NULL, NULL, FALSE, FALSE, TRUE, FALSE);
                }
            }
            else
            {
                /* default case, nothing is given */
                int curcolor = 0;
                int *piCurColor = &curcolor;

                getGraphicObjectProperty(iCurrentSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piCurColor);

                iNewPolylineUID = ConstructPolyline(iCurrentSubwinUID,
                                                    &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1,
                                                    &curcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE);
            }

            if (iNewPolylineUID == 0)
            {
                Scierror(999, _("%s: No more memory.\n"), fname);
                FREE(pObj);
                return;
            }

            setCurrentObject(iNewPolylineUID);
            setGraphicObjectRelationship(iCurrentSubwinUID, iNewPolylineUID);

            /* Force clipping, 1: CLIPGRF */
            clipState = 1;
            setGraphicObjectProperty(iNewPolylineUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

            pObj[i] = iNewPolylineUID;
        }

        /** construct Compound and make it current object**/
        if (*n > 1)
        {
            int o = createCompound (iCurrentSubwinUID, pObj, *n);
            setCurrentObject(o);
        }
        FREE(pObj);
    }

    /* =================================================
     * Redraw Figure
     * ================================================= */

    // subwin has been modified

    firstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);
}
Пример #19
0
void Objdrawaxis (char     dir    ,
                  char     tics   ,
                  double* x      ,
                  int    * nx     ,
                  double* y      ,
                  int    * ny     ,
                  char   * val[]  ,
                  int      subint ,
                  char   * format ,
                  int      font   ,
                  int      textcol,
                  int      ticscol,
                  char     flag   ,
                  int      seg    ,
                  int      nb_tics_labels)
{
    int iObjUID = 0;
    int iSubwinUID = 0;
    int ticksDirection = 0;
    int ticksStyle = 0;

    iSubwinUID = getCurrentSubWin();

    checkRedrawing();

    switch (dir)
    {
        default :
        case 'u' :
            ticksDirection = 0;
            break;
        case 'd' :
            ticksDirection = 1;
            break;
        case 'l' :
            ticksDirection = 2;
            break;
        case 'r' :
            ticksDirection = 3;
            break;
    }

    switch (tics)
    {
        default:
        case 'v':
            ticksStyle = 0;
            break;
        case 'r':
            ticksStyle = 1;
            break;
        case 'i':
            ticksStyle = 2;
            break;
    }

    iObjUID = createAxis(iSubwinUID, ticksDirection, ticksStyle, x, *nx, y, *ny, subint, format, font, textcol, ticscol, seg);

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

    if (val == NULL)
    {
        char **matData;
        StringMatrix *tics_labels;

        tics_labels = computeDefaultTicsLabels(iObjUID);

        if (tics_labels == NULL)
        {
            deleteGraphicObject(iObjUID);
            return;
        }

        matData = getStrMatData(tics_labels);

        /*
        * The labels vector size must be computed using the matrix's dimensions.
        * To be modified when the labels computation is moved to the Model.
        */
        setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, matData, jni_string_vector, tics_labels->nbCol * tics_labels->nbRow);

        deleteMatrix(tics_labels);
    }
    else
    {
        int i = 0;
        /*
        * Labels are set using the str argument; the previous code tested whether each element of the
        * str array was null and set the corresponding Axis' element to NULL, though there was no
        * apparent reason to do so. This is still checked, but now aborts building the Axis.
        */

        if (nb_tics_labels == -1)
        {
            Scierror(999, _("Impossible case when building axis\n"));
            deleteGraphicObject(iObjUID);
            return;
        }

        for (i = 0; i < nb_tics_labels; i++)
        {
            if (val[i] == NULL)
            {
                deleteGraphicObject(iObjUID);
                return;
            }
        }

        setGraphicObjectProperty(iObjUID, __GO_TICKS_LABELS__, val, jni_string_vector, nb_tics_labels);
    }

    setCurrentObject(iObjUID);
}
Пример #20
0
/*--------------------------------------------------------------------------*/
int sci_xgetmouse(char *fname, unsigned long fname_len)
{
    SciErr sciErr;

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

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

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

    int selPosition = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

            l2[0] = windowsID; /* this is the window number */
            AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
            ReturnArguments(pvApiCtx);
            return 0;
    }
    ReturnArguments(pvApiCtx);
    return -1;
}
Пример #21
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;
}
Пример #22
0
int C2F(xgray)(double *x, double *y, double *z, int *n1, int *n2, char *strflag, double *brect, int *aaint, BOOL flagNax, char *logflags, long int l1)
{
    int iSubwinUID = 0;
    int iGrayplotUID = 0;
    double xx[2], yy[2];
    int nn1 = 1, nn2 = 2;
    double drect[6];
    BOOL bounds_changed = FALSE;
    BOOL isRedrawn = FALSE;
    BOOL axes_properties_changed = FALSE;

    char textLogFlags[3];
    double rotationAngles[2];
    int clipState = 0;
    int autoScale = 0;
    int firstPlot = 0;
    int logFlags[3];
    char dataflag = 0;
    int autoSubticks = 0;

    int iTmp = 0;
    int* piTmp = &iTmp;

    xx[0] = Mini(x, *n1);
    xx[1] = Maxi(x, *n1);
    yy[0] = Mini(y, *n2);
    yy[1] = Maxi(y, *n2);

    /* Adding F.Leray 22.04.04 */
    iSubwinUID = getCurrentSubWin();

    isRedrawn = checkRedrawing();

    rotationAngles[0] = 0.0;
    rotationAngles[1] = 270.0;

    setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);

    /* Force "cligrf" clipping (1) */
    clipState = 1;
    setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);

    getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piTmp);
    firstPlot = iTmp;

    getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piTmp);
    autoScale = iTmp;

    /* Reset x and y logflags */
    if (firstPlot)
    {
        logFlags[0] = getBooleanLogFlag(logflags[1]);
        logFlags[1] = getBooleanLogFlag(logflags[2]);

        setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, &logFlags[0], jni_bool, 1);
        setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, &logFlags[1], jni_bool, 1);
    }

    if (autoScale)
    {
        /* compute and merge new specified bounds with the data bounds */
        switch (strflag[1])
        {
            case '0':
                /* do not change data bounds */
                break;
            case '1' :
            case '3' :
            case '5' :
            case '7':
                /* Force data bounds=brect */
                re_index_brect(brect, drect);
                break;
            case '2' :
            case '4' :
            case '6' :
            case '8':
            case '9':
                /* Force data bounds to the x and y bounds */
                if ((int)strlen(logflags) < 1)
                {
                    dataflag = 'g';
                }
                else
                {
                    dataflag = logflags[0];
                }

                getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[0] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[1] = iTmp;
                getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
                logFlags[2] = iTmp;

                /* Conversion required by compute_data_bounds2 */
                textLogFlags[0] = getTextLogFlag(logFlags[0]);
                textLogFlags[1] = getTextLogFlag(logFlags[1]);
                textLogFlags[2] = getTextLogFlag(logFlags[2]);

                /* Force data bounds to the x and y bounds */
                compute_data_bounds2(0, dataflag, textLogFlags, xx, yy, nn1, nn2, drect);
                break;
        }

        /* merge data bounds and drect */
        if (!firstPlot && (strflag[1] == '7' || strflag[1] == '8'))
        {
            double* dataBounds;
            getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);

            drect[0] = Min(dataBounds[0], drect[0]); /*xmin*/
            drect[2] = Min(dataBounds[2], drect[2]); /*ymin*/
            drect[1] = Max(dataBounds[1], drect[1]); /*xmax*/
            drect[3] = Max(dataBounds[3], drect[3]); /*ymax*/
        }

        if (strflag[1] != '0')
        {
            bounds_changed = update_specification_bounds(iSubwinUID, drect, 2);
        }
    }

    if (firstPlot)
    {
        bounds_changed = TRUE;
    }

    axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);

    firstPlot = 0;
    setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);

    /* F.Leray 07.10.04 : trigger algo to init. manual graduation u_xgrads and
    u_ygrads if nax (in matdes.c which is == aaint HERE) was specified */

    /* The MVC AUTO_SUBTICKS property corresponds to !flagNax */
    autoSubticks = !flagNax;
    setGraphicObjectProperty(iSubwinUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1);

    if (flagNax == TRUE)
    {
        if (logFlags[0] == 0 && logFlags[1] == 0)
        {
            int autoTicks;

            autoTicks = 0;
            setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
            setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1);
        }
        else
        {
            Sciwarning(_("Warning: Nax does not work with logarithmic scaling.\n"));
        }
    }

    /* Constructs the object */
    iGrayplotUID = ConstructGrayplot(getCurrentSubWin(), x, y, z, *n1, *n2, 0);

    /* Failed allocation */
    if (iGrayplotUID == 0)
    {
        Scierror(999, _("%s: No more memory.\n"), "grayplot");
        return -1;
    }

    /* Sets the grayplot as current */
    setCurrentObject(iGrayplotUID);

    return (0);
}