/*--------------------------------------------------------------------------*/ int sci_uimenu(char *fname, void *pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0; int setStatus = SET_PROPERTY_SUCCEED; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; int iParentUID = 0; unsigned long GraphicHandle = 0; int parentDefined = FALSE; int iCurrentFigure = 0; int iParentType = -1; int *piParentType = &iParentType; /* Create a new menu */ GraphicHandle = getHandle(CreateUimenu()); /* If no nbInputArgument(pvApiCtx) -> current figure is the parent (Ascendant compatibility) */ if (nbInputArgument(pvApiCtx) == 0) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } else /* Get parent ID */ { int *piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__ && iParentType != __GO_UIMENU__) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // Set the parent property callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), &hParent, sci_handles, 1, 1, "parent"); // Set the flag to avoid setting the parent two times parentDefined = TRUE; } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // First input parameter which is a property name beginIndex = 2; } } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Read and set all properties */ for (inputIndex = beginIndex; inputIndex < nbInputArgument(pvApiCtx); inputIndex = inputIndex + 2) { int* piAddrValue = NULL; int* piAddrProperty = NULL; int isUserDataProperty = 0; int iPropertyValuePositionIndex = inputIndex + 1; size_t posStackOrAdr = 0; /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); return FALSE; } else { sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddrProperty); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProperty, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); return 1; } if (stricmp(propertyName, "parent") == 0) { parentDefined = TRUE; } isUserDataProperty = (stricmp(propertyName, "user_data") == 0) || (stricmp(propertyName, "userdata") == 0); } sciErr = getVarAddressFromPosition(pvApiCtx, iPropertyValuePositionIndex, &piAddrValue); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isUserDataProperty) { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, 0, 0, 0, propertyName); } else { /* Read property value */ switch (getInputArgumentType(pvApiCtx, iPropertyValuePositionIndex)) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddrValue, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, iPropertyValuePositionIndex); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pdblValue, sci_matrix, nbRow, nbCol, propertyName); break; } case sci_strings: { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddrValue, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, iPropertyValuePositionIndex); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pstValue, sci_strings, nbRow, nbCol, propertyName); freeAllocatedSingleString(pstValue); break; } case sci_handles: { long long* phValues = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddrValue, &nbRow, &nbCol, &phValues); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, iPropertyValuePositionIndex); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), phValues, sci_handles, nbRow, nbCol, propertyName); break; } case sci_list: { getListItemNumber(pvApiCtx, piAddrValue, &nbRow); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, sci_list, nbRow, nbCol, propertyName); break; } default: { setStatus = SET_PROPERTY_ERROR; break; } } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); return FALSE; } freeAllocatedSingleString(propertyName); } /* If the parent is not given, the current figure is set as parent */ if (!parentDefined && (nbInputArgument(pvApiCtx) != 0)) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /* Create return variable */ nbRow = 1; nbCol = 1; // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_xget(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; char* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; char* l3 = NULL; int m1 = 0, m2 = 0, n2 = 0, i = 0; int one = 1; BOOL keyFound = FALSE; if (nbInputArgument(pvApiCtx) <= 0) { sci_demo(fname, fname_len); return 0; } CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, &l1)) { Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1); return 1; } /* check if key is valid */ for (i = 0; i < NUMSETFONC ; i++) { if (strcmp((l1), KeyTab_[i]) == 0) { keyFound = TRUE; break; } } if (!keyFound) { Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1)); freeAllocatedSingleString(l1); return -1; } if (nbInputArgument(pvApiCtx) == 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedSingleString(l1); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); freeAllocatedSingleString(l1); return 1; } //CheckScalar if (m2 != 1 || n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), fname, 2); freeAllocatedSingleString(l1); return 1; } } if (strcmp(l1, "fpf") == 0 || strcmp(l1, "auto clear") == 0) { int bufl; char buf[4096]; /* special case for global variables set */ xgetg((l1), buf, &bufl, m1, bsiz); if (allocSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, bufl * one, (const char **)&l3)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); freeAllocatedSingleString(l1); return 1; } strncpy((l3), buf, bufl); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "colormap") == 0) { int iObjUID = 0; // Force figure creation if none exists. getOrCreateDefaultSubwin(); iObjUID = getCurrentFigure(); get_color_map_property(pvApiCtx, iObjUID); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "mark") == 0) { int iObjUID = getOrCreateDefaultSubwin(); int iMarkStyle = 0; int* piMarkStyle = &iMarkStyle; int iMarkSize = 0; int* piMarkSize = &iMarkSize; double pdblResult[2]; getGraphicObjectProperty(iObjUID, __GO_MARK_STYLE__, jni_int, (void**)&piMarkStyle); getGraphicObjectProperty(iObjUID, __GO_MARK_SIZE__, jni_int, (void**)&piMarkSize); pdblResult[0] = iMarkStyle; pdblResult[1] = iMarkSize; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblResult); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "mark size") == 0) { int iObjUID = getOrCreateDefaultSubwin(); get_mark_size_property(pvApiCtx, iObjUID); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "line style") == 0) { get_line_style_property(pvApiCtx, getOrCreateDefaultSubwin()); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "clipping") == 0) { double *clipBox = NULL; int iObjUID = getOrCreateDefaultSubwin(); getGraphicObjectProperty(iObjUID, __GO_CLIP_BOX__, jni_double_vector, (void **)&clipBox); createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 4, clipBox); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "font") == 0) { int iObjUID = getOrCreateDefaultSubwin(); double dblFontSize = 0; double* pdblFontSize = &dblFontSize; int iFontStyle = 0; int* piFontStyle = &iFontStyle; double pdblResult[2]; getGraphicObjectProperty(iObjUID, __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize); getGraphicObjectProperty(iObjUID, __GO_FONT_STYLE__, jni_int, (void**)&piFontStyle); pdblResult[0] = iFontStyle; pdblResult[1] = dblFontSize; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblResult); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "font size") == 0) { double dblFontSize = 0; double* pdblFontSize = &dblFontSize; getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dblFontSize); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "dashes") == 0) { int iLineStyle = 0; int* piLineStyle = &iLineStyle; getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, jni_int, (void**)&piLineStyle); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iLineStyle); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "hidden3d") == 0) { get_hidden_color_property(pvApiCtx, getOrCreateDefaultSubwin()); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "window") == 0 || strcmp(l1, "figure") == 0) { int iFigureId = 0; int* piFigureId = &iFigureId; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_ID__, jni_int, (void**)&piFigureId); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iFigureId); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "thickness") == 0) { get_thickness_property(pvApiCtx, getOrCreateDefaultSubwin()); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "wdim") == 0 || strcmp(l1, "wpdim") == 0) { int *piFigureSize = NULL; double pdblFigureSize[2]; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, jni_int_vector, (void **) &piFigureSize); pdblFigureSize[0] = (double) piFigureSize[0]; pdblFigureSize[1] = (double) piFigureSize[1]; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblFigureSize); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "wpos") == 0) { int *piFigurePosition = NULL; double pdblFigurePosition[2]; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, jni_int_vector, (void **) &piFigurePosition); pdblFigurePosition[0] = piFigurePosition[0]; pdblFigurePosition[1] = piFigurePosition[1]; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblFigurePosition); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "viewport") == 0) { int* viewport = NULL; double pdblViewport[2]; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, jni_int_vector, (void **)&viewport); pdblViewport[0] = viewport[0]; pdblViewport[1] = viewport[1]; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 2, pdblViewport); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "background") == 0) { get_background_property(pvApiCtx, getOrCreateDefaultSubwin()); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if ( strcmp(l1, "color") == 0 || strcmp(l1, "foreground") == 0 || strcmp(l1, "pattern") == 0) { get_foreground_property(pvApiCtx, getOrCreateDefaultSubwin()); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "lastpattern") == 0) { int iNumColors = 0; int* piNumColors = &iNumColors; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNumColors); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "line mode") == 0) { int iLineMode = 0; int* lineMode = &iLineMode; getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_MODE__, jni_bool, (void **)&lineMode); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iLineMode); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "white") == 0) { int iNumColors = 0; int* piNumColors = &iNumColors; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors); /* White is lqst colormap index + 2 */ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iNumColors + 2); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "wresize") == 0) { // autoresize property int iAutoResize = 0; int* piAutoResize = &iAutoResize; getOrCreateDefaultSubwin(); getGraphicObjectProperty(getCurrentFigure(), __GO_AUTORESIZE__, jni_bool, (void **)&piAutoResize); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iAutoResize); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "clipgrf") == 0) { /* clip_state : 0 = off, 1 = on */ int iClipState = 0; int* piClipState = &iClipState; getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState); createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iClipState); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else if (strcmp(l1, "clipoff") == 0) { int iClipState = 0; int* piClipState = &iClipState; getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState); /* clip_state : 0 = off, 1 = on */ if (iClipState == 0) { createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1); } else { createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 0); } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } else { Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1)); freeAllocatedSingleString(l1); return -1; } freeAllocatedSingleString(l1); return 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; }
/*--------------------------------------------------------------------------*/ int sci_unzoom(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrstackPointer = NULL; long long* stackPointer = NULL; /* number of object to unzoom */ int nbObjects = 0; /* object type */ int iType = -1; int *piType = &iType; /* ids of object to unzoom */ int* iObjectsId = NULL; int iObjectUID = 0; CheckInputArgument(pvApiCtx, 0, 1); CheckOutputArgument(pvApiCtx, 0, 1); if (nbInputArgument(pvApiCtx) == 0) { iObjectUID = getCurrentFigure(); if (iObjectUID != 0) { sciUnzoomFigure(iObjectUID); } } else { int m = 0, n = 0, i = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrstackPointer); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrstackPointer, &m, &n, &stackPointer); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } nbObjects = m * n; iObjectsId = (int*)MALLOC(nbObjects * sizeof(int)); if (iObjectsId == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return -1; } /* first pass, check that all the handles are subwindows or figures */ /* and copy them into an array of objects */ for (i = 0; i < nbObjects; i++) { iObjectUID = getObjectFromHandle((long int)stackPointer[i]); getGraphicObjectProperty(iObjectUID, __GO_TYPE__, jni_int, (void **) &piType); if (iType != __GO_FIGURE__ && iType != __GO_AXES__) { FREE(iObjectsId); Scierror(999, _("%s: Wrong type for input argument: Vector of Axes and Figure handles expected.\n"), fname); return -1; } iObjectsId[i] = iObjectUID; } /* second pass un zoom the objects */ sciUnzoomArray(iObjectsId, nbObjects); FREE(iObjectsId); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_uicontrol(char *fname, void* pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0, k = 0; int setStatus = SET_PROPERTY_SUCCEED; int PARENT_NOT_FOUND = -2; int NOT_FOUND = -1; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; char *styleProperty = NULL; int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**); unsigned long GraphicHandle = 0; int found = 0; /* Does the property exists ? */ int *propertiesValuesIndices = NULL; int iParentType = -1; int *piParentType = &iParentType; int iParentStyle = -1; int *piParentStyle = &iParentStyle; int iParentUID = 0; int iUicontrol = 0; int iCurrentFigure = 0; CheckOutputArgument(pvApiCtx, 0, 1); //init properties index init_property_index(); if (nbInputArgument(pvApiCtx) == 0) { /* Create a pushbutton in current figure */ /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); /* Set current figure as parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } iUicontrol = getObjectFromHandle(GraphicHandle); setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (nbInputArgument(pvApiCtx) == 1) { /* Create a pushbutton in figure given as parameter */ /* Or give focus to the uicontrol given as parameter */ int* piAddr = NULL; int iType = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE) { OverLoad(1); return FALSE; } #if 0 // Allow XML loading else if (isStringType(pvApiCtx, piAddr)) { char* pstXmlfile = NULL; char* pstExpandedPath = NULL; if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile)) { freeAllocatedSingleString(pstXmlfile); Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } pstExpandedPath = expandPathVariable(pstXmlfile); freeAllocatedSingleString(pstXmlfile); iUicontrol = xmlload(pstExpandedPath); if (iUicontrol < 1) { Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath); FREE(pstExpandedPath); return 0; } FREE(pstExpandedPath); GraphicHandle = getHandle(iUicontrol); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } #endif // Allow XML loading else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType == __GO_UICONTROL__) /* Focus management */ { GraphicHandle = (unsigned long)hParent; requestFocus(iParentUID); } else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__) /* PushButton creation */ { /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); iUicontrol = getObjectFromHandle(GraphicHandle); /* First parameter is the parent */ setGraphicObjectRelationship(iParentUID, iUicontrol); setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]); if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } } else { if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings)) { OverLoad(1); return FALSE; } /* Allocate memory to store the position of properties in uicontrol call */ if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } /* Init all positions to NOT_FOUND */ for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++) { propertiesValuesIndices[inputIndex] = NOT_FOUND; /* Property initialized as not found */ } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { int* piAddr = NULL; double dblValue = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); FREE(propertiesValuesIndices); return FALSE; } if (getScalarDouble(pvApiCtx, piAddr, &dblValue)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); FREE(propertiesValuesIndices); return 1; } iParentUID = getFigureFromIndex((int)dblValue); } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); FREE(propertiesValuesIndices); return FALSE; } } else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); FREE(propertiesValuesIndices); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); FREE(propertiesValuesIndices); return 1; } iParentUID = getObjectFromHandle((long)hParent); } if (iParentUID == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); FREE(propertiesValuesIndices); return FALSE; } getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__) { getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle); if (iParentType != __GO_UICONTROL__ || (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__)) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); FREE(propertiesValuesIndices); return FALSE; } } /* First parameter is the parent */ propertiesValuesIndices[parent_property] = 1; // First input parameter which is a property name beginIndex = 2; } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Get all properties positions */ for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2) { /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); FREE(propertiesValuesIndices); return FALSE; } else { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); FREE(propertiesValuesIndices); return 1; } /* Bug 3031 */ /* We only want to compare propertyName along its length */ /* 'posi' must be matched to 'position' */ found = 0; for (k = 0; k < iPropertiesCount ; k++) { if (strlen(propertyName) <= strlen(propertiesNames[k])) { if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0) { propertiesValuesIndices[k] = inputIndex + 1; /* Position of value for property */ found = 1; break; } } } if (found == 0) { Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol"); freeAllocatedSingleString(propertyName); FREE(propertiesValuesIndices); return FALSE; } freeAllocatedSingleString(propertyName); } } if (propertiesValuesIndices[style_property] != NOT_FOUND) /* Style found */ { if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings))) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); FREE(propertiesValuesIndices); return 1; } if (strcmp(styleProperty, "frame") == 0) { //check scrollable property to create a scroll frame instead of normal frame if (propertiesValuesIndices[scrollable_property] != NOT_FOUND) { char* pstScroll = NULL; int iScroll = 0; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); freeAllocatedSingleString(styleProperty); return 1; } if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]); FREE(propertiesValuesIndices); freeAllocatedSingleString(styleProperty); return 1; } if (isStringType(pvApiCtx, piAddr)) { if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); FREE(propertiesValuesIndices); freeAllocatedSingleString(styleProperty); return 1; } if (strcmp(pstScroll, "on") == 0) { iScroll = 1; } freeAllocatedSingleString(pstScroll); } else { if (getScalarBoolean(pvApiCtx, piAddr, &iScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); freeAllocatedSingleString(styleProperty); FREE(propertiesValuesIndices); return 1; } } if (iScroll) { freeAllocatedSingleString(styleProperty); styleProperty = os_strdup("framescrollable"); } propertiesValuesIndices[scrollable_property] = NOT_FOUND; } } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); FREE(propertiesValuesIndices); return FALSE; } } /* Create a new uicontrol */ iUicontrol = CreateUIControl(styleProperty); freeAllocatedSingleString(styleProperty); if (iUicontrol == 0) /* Error in creation */ { Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname); FREE(propertiesValuesIndices); return FALSE; } GraphicHandle = getHandle(iUicontrol); /* If no parent given then the current figure is the parent */ if (propertiesValuesIndices[parent_property] == NOT_FOUND) { /* Set the parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND; } /* Read and set all properties */ for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++) /* Style has already been set */ { if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND) { //special case for not specified parent //but set relationship at the good moment. setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (propertiesValuesIndices[inputIndex] != NOT_FOUND) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); FREE(propertiesValuesIndices); return 1; } if (inputIndex == user_data_property || inputIndex == userdata_property) /* User data settings */ { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]); } else /* All other properties */ { /* Read property value */ switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex])) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]); FREE(propertiesValuesIndices); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_strings: /* Index for String & TooltipString properties: Can be more than one character string */ if ((inputIndex == string_property) || (inputIndex == tooltipstring_property)) { char** pstValue = NULL; if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); FREE(propertiesValuesIndices); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedMatrixOfString(nbRow, nbCol, pstValue); } else { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); FREE(propertiesValuesIndices); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedSingleString(pstValue); } break; case sci_handles: { long long* pHandles = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]); FREE(propertiesValuesIndices); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_tlist: //constraints and border { setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]); break; } default: setStatus = SET_PROPERTY_ERROR; break; } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]); FREE(propertiesValuesIndices); return FALSE; } } } } if (propertiesValuesIndices != NULL && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND && (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND))) /* SliderStep property not set */ { /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */ double maxValue = 0; double* pdblMaxValue = &maxValue; double minValue = 0; double* pdblMinValue = &minValue; double pdblStep[2]; getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue); getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue); pdblStep[0] = 0.01 * (maxValue - minValue); pdblStep[1] = 0.1 * (maxValue - minValue); setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND)) /* Position property not set */ { double* pdblPosition = NULL; getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition); setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4); releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND)) /* Visible property not set */ { /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */ int b = (int)TRUE; setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1); } FREE(propertiesValuesIndices); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*------------------------------------------------ * 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; }
/*--------------------------------------------------------------------------*/ int sci_unzoom(char *fname,unsigned long fname_len) { /* number of object to unzoom */ int nbObjects = 0; /* ids of object to unzoom */ char** objectsId = NULL; char* objectUID = NULL; /* object type */ int iType = -1; int *piType = &iType; CheckRhs(0,1) ; CheckLhs(0,1) ; if ( Rhs == 0 ) { objectUID = (char*)getCurrentFigure(); if (objectUID != NULL) { sciUnzoomFigure(objectUID); } } else { int m = 0,n = 0,i = 0; size_t stackPointer = 0; GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &m, &n, &stackPointer); nbObjects = m * n; objectsId = MALLOC(nbObjects * sizeof(char*)); if (objectsId == NULL) { Scierror(999, _("%s: No more memory.\n"),fname); return -1; } /* first pass, check that all the handles are subwindows or figures */ /* and copy them into an array of objects */ for (i = 0; i < nbObjects; i++ ) { objectUID = (char*)getObjectFromHandle(getHandleFromStack(stackPointer + i)); getGraphicObjectProperty(objectUID, __GO_TYPE__, jni_int, (void **) &piType); if (iType != __GO_FIGURE__ && iType != __GO_AXES__) { FREE(objectsId); Scierror(999, _("%s: Wrong type for input argument: Vector of Axes and Figure handles expected.\n"),fname); return -1; } objectsId[i] = objectUID; } /* second pass un zoom the objects */ sciUnzoomArray(objectsId, nbObjects); FREE(objectsId); } LhsVar(1)=0; PutLhsVar(); return 0; }
/*--------------------------------------------------------------------------*/ int sci_xpolys(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; int* piAddr3 = NULL; int* l3 = NULL; int m1 = 0, n1 = 0; int m2 = 0, n2 = 0; int m3 = 0, n3 = 0; int i = 0; long hdl = 0; int iFigureUID = 0; int iSubWinUID = 0; int iCompoundUID = 0; int iFalse = 0; int iVisible = 0; int *piVisible = &iVisible; CheckInputArgument(pvApiCtx, 2, 3); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 2); return 1; } //CheckSameDims if (m1 != m2 || n1 != n2) { Scierror(999, _("%s: Wrong size for input argument #%d: %d-by-%d matrix expected.\n"), fname, 1, m1, n1); return 1; } if (m1 * n1 == 0 || m2 * n2 == 0) { /* dimension 0, 0 polyline to draw */ AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } iSubWinUID = getOrCreateDefaultSubwin(); iFigureUID = getCurrentFigure(); // Create compound. iCompoundUID = createGraphicObject(__GO_COMPOUND__); setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iFalse, jni_bool, 1); /* Sets the parent-child relationship for the Compound */ setGraphicObjectRelationship(iSubWinUID, iCompoundUID); if (nbInputArgument(pvApiCtx) == 3) { sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 3. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr3, &m3, &n3, &l3); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3); return 1; } //CheckVector if (m3 != 1 && n3 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 3); return 1; } //CheckDimProp if (m3 * n3 < n1) { Scierror(999, _("%s: Wrong size for input arguments: Incompatible sizes.\n"), fname); return 1; } /* Construct the polylines */ for (i = 0; i < n1; ++i) { Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, *(int*)(l3 + i), &hdl); // Add newly created object to Compound setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl)); } } else { for (i = 0; i < n1; ++i) { Objpoly((l1 + (i * m1)), (l2 + (i * m2)), m1, 0, 1, &hdl); // Add newly created object to Compound setGraphicObjectRelationship(iCompoundUID, getObjectFromHandle(hdl)); } } getGraphicObjectProperty(iFigureUID, __GO_VISIBLE__, jni_bool, (void **)&piVisible); setGraphicObjectProperty(iCompoundUID, __GO_VISIBLE__, &iVisible, jni_bool, 1); setCurrentObject(iCompoundUID); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }