/*--------------------------------------------------------------------------*/ int sci_uicontrol(char *fname, void* pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0, k = 0; int setStatus = SET_PROPERTY_SUCCEED; int PARENT_NOT_FOUND = -2; int NOT_FOUND = -1; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; char *styleProperty = NULL; int iPropertiesCount = sizeof(propertiesNames) / sizeof(char**); unsigned long GraphicHandle = 0; int found = 0; /* Does the property exists ? */ int *propertiesValuesIndices = NULL; int iParentType = -1; int *piParentType = &iParentType; int iParentStyle = -1; int *piParentStyle = &iParentStyle; int iParentUID = 0; int iUicontrol = 0; int iCurrentFigure = 0; CheckOutputArgument(pvApiCtx, 0, 1); //init properties index init_property_index(); if (nbInputArgument(pvApiCtx) == 0) { /* Create a pushbutton in current figure */ /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); /* Set current figure as parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } iUicontrol = getObjectFromHandle(GraphicHandle); setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (nbInputArgument(pvApiCtx) == 1) { /* Create a pushbutton in figure given as parameter */ /* Or give focus to the uicontrol given as parameter */ int* piAddr = NULL; int iType = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isHandleType(pvApiCtx, piAddr) == FALSE && isStringType(pvApiCtx, piAddr) == FALSE) { OverLoad(1); return FALSE; } #if 0 // Allow XML loading else if (isStringType(pvApiCtx, piAddr)) { char* pstXmlfile = NULL; char* pstExpandedPath = NULL; if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } if (getAllocatedSingleString(pvApiCtx, piAddr, &pstXmlfile)) { freeAllocatedSingleString(pstXmlfile); Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } pstExpandedPath = expandPathVariable(pstXmlfile); freeAllocatedSingleString(pstXmlfile); iUicontrol = xmlload(pstExpandedPath); if (iUicontrol < 1) { Scierror(999, _("%s: can not read file %s.\n"), fname, pstExpandedPath); FREE(pstExpandedPath); return 0; } FREE(pstExpandedPath); GraphicHandle = getHandle(iUicontrol); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; } #endif // Allow XML loading else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType == __GO_UICONTROL__) /* Focus management */ { GraphicHandle = (unsigned long)hParent; requestFocus(iParentUID); } else if (iParentType == __GO_FIGURE__ || iParentType == __GO_UIMENU__) /* PushButton creation */ { /* Create a new pushbutton */ GraphicHandle = getHandle(CreateUIControl(NULL)); iUicontrol = getObjectFromHandle(GraphicHandle); /* First parameter is the parent */ setGraphicObjectRelationship(iParentUID, iUicontrol); setStatus = callSetProperty(pvApiCtx, iUicontrol, &hParent, sci_handles, 1, 1, (char*)propertiesNames[parent_property]); if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s', '%s' or '%s' handle expected.\n"), fname, 1, "Uicontrol", "Figure", "Uimenu"); return FALSE; } } } else { if (!checkInputArgumentType(pvApiCtx, 1, sci_handles) && !checkInputArgumentType(pvApiCtx, 1, sci_strings)) { OverLoad(1); return FALSE; } /* Allocate memory to store the position of properties in uicontrol call */ if ((propertiesValuesIndices = (int*)MALLOC(sizeof(int) * iPropertiesCount)) == NULL) { Scierror(999, _("%s: No more memory.\n"), fname); return FALSE; } /* Init all positions to NOT_FOUND */ for (inputIndex = 0; inputIndex < iPropertiesCount; inputIndex++) { propertiesValuesIndices[inputIndex] = NOT_FOUND; /* Property initialized as not found */ } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { int* piAddr = NULL; double dblValue = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } if (getScalarDouble(pvApiCtx, piAddr, &dblValue)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } iParentUID = getFigureFromIndex((int)dblValue); } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } } else /* Get parent ID */ { int* piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong size for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); } if (iParentUID == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__) { getGraphicObjectProperty(iParentUID, __GO_STYLE__, jni_int, (void **)&piParentStyle); if (iParentType != __GO_UICONTROL__ || (iParentStyle != __GO_UI_FRAME__ && iParentStyle != __GO_UI_TAB__ && iParentStyle != __GO_UI_LAYER__)) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or a '%s' handle expected.\n"), fname, 1, "Figure", "Frame uicontrol"); return FALSE; } } /* First parameter is the parent */ propertiesValuesIndices[parent_property] = 1; // First input parameter which is a property name beginIndex = 2; } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Get all properties positions */ for (inputIndex = beginIndex; inputIndex < Rhs; inputIndex = inputIndex + 2) { /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); return FALSE; } else { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); return 1; } /* Bug 3031 */ /* We only want to compare propertyName along its length */ /* 'posi' must be matched to 'position' */ found = 0; for (k = 0; k < iPropertiesCount ; k++) { if (strlen(propertyName) <= strlen(propertiesNames[k])) { if (strnicmp(propertyName, propertiesNames[k], strlen(propertyName)) == 0) { propertiesValuesIndices[k] = inputIndex + 1; /* Position of value for property */ found = 1; break; } } } freeAllocatedSingleString(propertyName); if (found == 0) { Scierror(999, _("%s: Unknown property: %s for '%s' handles.\n"), fname, propertyName, "Uicontrol"); return FALSE; } } } if (propertiesValuesIndices[style_property] != NOT_FOUND) /* Style found */ { if ((checkInputArgumentType(pvApiCtx, propertiesValuesIndices[style_property], sci_strings))) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[style_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddr, &styleProperty)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); return 1; } if (strcmp(styleProperty, "frame") == 0) { //check scrollable property to create a scroll frame instead of normal frame if (propertiesValuesIndices[scrollable_property] != NOT_FOUND) { char* pstScroll = NULL; int iScroll = 0; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[scrollable_property], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isStringType(pvApiCtx, piAddr) == 0 && isBooleanType(pvApiCtx, piAddr) == 0 && isScalar(pvApiCtx, piAddr) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string or boolean expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } if (isStringType(pvApiCtx, piAddr)) { if (getAllocatedSingleString(pvApiCtx, piAddr, &pstScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } if (strcmp(pstScroll, "on") == 0) { iScroll = 1; } freeAllocatedSingleString(pstScroll); } else { if (getScalarBoolean(pvApiCtx, piAddr, &iScroll)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[scrollable_property]); return 1; } } if (iScroll) { freeAllocatedSingleString(styleProperty); styleProperty = os_strdup("framescrollable"); } propertiesValuesIndices[scrollable_property] = NOT_FOUND; } } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, propertiesValuesIndices[style_property]); return FALSE; } } /* Create a new uicontrol */ iUicontrol = CreateUIControl(styleProperty); freeAllocatedSingleString(styleProperty); if (iUicontrol == 0) /* Error in creation */ { Scierror(999, _("%s: Could not create 'Uicontrol' handle.\n"), fname); return FALSE; } GraphicHandle = getHandle(iUicontrol); /* If no parent given then the current figure is the parent */ if (propertiesValuesIndices[parent_property] == NOT_FOUND) { /* Set the parent */ iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } propertiesValuesIndices[parent_property] = PARENT_NOT_FOUND; } /* Read and set all properties */ for (inputIndex = 1; inputIndex < iPropertiesCount; inputIndex++) /* Style has already been set */ { if (propertiesValuesIndices[inputIndex] == PARENT_NOT_FOUND) { //special case for not specified parent //but set relationship at the good moment. setGraphicObjectRelationship(iCurrentFigure, iUicontrol); } else if (propertiesValuesIndices[inputIndex] != NOT_FOUND) { int* piAddr = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, propertiesValuesIndices[inputIndex], &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (inputIndex == user_data_property || inputIndex == userdata_property) /* User data settings */ { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, 0, 0, 0, (char*)propertiesNames[inputIndex]); } else /* All other properties */ { /* Read property value */ switch (getInputArgumentType(pvApiCtx, propertiesValuesIndices[inputIndex])) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pdblValue, sci_matrix, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_strings: /* Index for String & TooltipString properties: Can be more than one character string */ if ((inputIndex == string_property) || (inputIndex == tooltipstring_property)) { char** pstValue = NULL; if (getAllocatedMatrixOfString(pvApiCtx, piAddr, &nbRow, &nbCol, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedMatrixOfString(nbRow, nbCol, pstValue); } else { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddr, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, iUicontrol, pstValue, sci_strings, nbRow, nbCol, (char*)propertiesNames[inputIndex]); freeAllocatedSingleString(pstValue); } break; case sci_handles: { long long* pHandles = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddr, &nbRow, &nbCol, &pHandles); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, propertiesValuesIndices[inputIndex]); return 1; } setStatus = callSetProperty(pvApiCtx, iUicontrol, pHandles, sci_handles, nbRow, nbCol, (char*)propertiesNames[inputIndex]); break; } case sci_tlist: //constraints and border { setStatus = callSetProperty(pvApiCtx, iUicontrol, piAddr, sci_tlist, 1, 1, (char*)propertiesNames[inputIndex]); break; } default: setStatus = SET_PROPERTY_ERROR; break; } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, (char*)propertiesNames[inputIndex]); return FALSE; } } } } if (propertiesValuesIndices != NULL && (propertiesValuesIndices[sliderstep_property] == NOT_FOUND && (propertiesValuesIndices[min_property] != NOT_FOUND || propertiesValuesIndices[max_property] != NOT_FOUND))) /* SliderStep property not set */ { /* Set SliderStep property to [1/100*(Max-Min) 1/10*(Max-Min)] */ double maxValue = 0; double* pdblMaxValue = &maxValue; double minValue = 0; double* pdblMinValue = &minValue; double pdblStep[2]; getGraphicObjectProperty(iUicontrol, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue); getGraphicObjectProperty(iUicontrol, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue); pdblStep[0] = 0.01 * (maxValue - minValue); pdblStep[1] = 0.1 * (maxValue - minValue); setGraphicObjectProperty(iUicontrol, __GO_UI_SLIDERSTEP__, pdblStep, jni_double_vector, 2); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[position_property] == NOT_FOUND)) /* Position property not set */ { double* pdblPosition = NULL; getGraphicObjectProperty(iUicontrol, __GO_POSITION__, jni_double_vector, (void**) &pdblPosition); setGraphicObjectProperty(iUicontrol, __GO_POSITION__, pdblPosition, jni_double_vector, 4); releaseGraphicObjectProperty(__GO_POSITION__, pdblPosition, jni_double_vector, 4); } if ((nbInputArgument(pvApiCtx) < 2) || (propertiesValuesIndices[visible_property] == NOT_FOUND)) /* Visible property not set */ { /* Force the uicontrol to be visible because is invisible by default in the model (See bug #10346) */ int b = (int)TRUE; setGraphicObjectProperty(iUicontrol, __GO_VISIBLE__, &b, jni_bool, 1); } FREE(propertiesValuesIndices); /* Create return variable */ if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_uimenu(char *fname, void *pvApiCtx) { SciErr sciErr; int nbRow = 0, nbCol = 0; int setStatus = SET_PROPERTY_SUCCEED; int inputIndex = 0, beginIndex = 0; char *propertyName = NULL; int iParentUID = 0; unsigned long GraphicHandle = 0; int parentDefined = FALSE; int iCurrentFigure = 0; int iParentType = -1; int *piParentType = &iParentType; /* Create a new menu */ GraphicHandle = getHandle(CreateUimenu()); /* If no nbInputArgument(pvApiCtx) -> current figure is the parent (Ascendant compatibility) */ if (nbInputArgument(pvApiCtx) == 0) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /** * Odd number of input arguments * First input is the parent ID * All event inputs are property names * All odd (except first) inputs are property values */ if (nbInputArgument(pvApiCtx) % 2 == 1) { if ((!checkInputArgumentType(pvApiCtx, 1, sci_handles))) { Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1); return FALSE; } else /* Get parent ID */ { int *piAddr = NULL; long long hParent = 0; sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (getScalarHandle(pvApiCtx, piAddr, &hParent)) { Scierror(202, _("%s: Wrong type for input argument #%d: Handle expected.\n"), fname, 1); return 1; } iParentUID = getObjectFromHandle((long)hParent); if (iParentUID != 0) { getGraphicObjectProperty(iParentUID, __GO_TYPE__, jni_int, (void **)&piParentType); if (iParentType != __GO_FIGURE__ && iParentType != __GO_UIMENU__) { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // Set the parent property callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), &hParent, sci_handles, 1, 1, "parent"); // Set the flag to avoid setting the parent two times parentDefined = TRUE; } else { Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' or '%s' handle expected.\n"), fname, 1, "Figure", "Uimenu"); return FALSE; } // First input parameter which is a property name beginIndex = 2; } } /** * Even number of input arguments * All odd inputs are property names * All even inputs are property values */ else { // First input parameter which is a property name beginIndex = 1; } /* Read and set all properties */ for (inputIndex = beginIndex; inputIndex < nbInputArgument(pvApiCtx); inputIndex = inputIndex + 2) { int* piAddrValue = NULL; int* piAddrProperty = NULL; int isUserDataProperty = 0; int iPropertyValuePositionIndex = inputIndex + 1; size_t posStackOrAdr = 0; /* Read property name */ if ((!checkInputArgumentType(pvApiCtx, inputIndex, sci_strings))) { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, inputIndex); return FALSE; } else { sciErr = getVarAddressFromPosition(pvApiCtx, inputIndex, &piAddrProperty); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProperty, &propertyName)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, inputIndex); return 1; } if (stricmp(propertyName, "parent") == 0) { parentDefined = TRUE; } isUserDataProperty = (stricmp(propertyName, "user_data") == 0) || (stricmp(propertyName, "userdata") == 0); } sciErr = getVarAddressFromPosition(pvApiCtx, iPropertyValuePositionIndex, &piAddrValue); if (sciErr.iErr) { printError(&sciErr, 0); freeAllocatedSingleString(propertyName); return 1; } if (isUserDataProperty) { nbRow = -1; nbCol = -1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, 0, 0, 0, propertyName); } else { /* Read property value */ switch (getInputArgumentType(pvApiCtx, iPropertyValuePositionIndex)) { case sci_matrix: { double* pdblValue = NULL; sciErr = getMatrixOfDouble(pvApiCtx, piAddrValue, &nbRow, &nbCol, &pdblValue); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pdblValue, sci_matrix, nbRow, nbCol, propertyName); break; } case sci_strings: { char* pstValue = NULL; if (getAllocatedSingleString(pvApiCtx, piAddrValue, &pstValue)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } nbRow = (int)strlen(pstValue); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), pstValue, sci_strings, nbRow, nbCol, propertyName); freeAllocatedSingleString(pstValue); break; } case sci_handles: { long long* phValues = NULL; sciErr = getMatrixOfHandle(pvApiCtx, piAddrValue, &nbRow, &nbCol, &phValues); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, iPropertyValuePositionIndex); freeAllocatedSingleString(propertyName); return 1; } setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), phValues, sci_handles, nbRow, nbCol, propertyName); break; } case sci_list: { getListItemNumber(pvApiCtx, piAddrValue, &nbRow); nbCol = 1; setStatus = callSetProperty(pvApiCtx, getObjectFromHandle(GraphicHandle), piAddrValue, sci_list, nbRow, nbCol, propertyName); break; } default: { setStatus = SET_PROPERTY_ERROR; break; } } } if (setStatus == SET_PROPERTY_ERROR) { Scierror(999, _("%s: Could not set property '%s'.\n"), fname, propertyName); freeAllocatedSingleString(propertyName); return FALSE; } freeAllocatedSingleString(propertyName); } /* If the parent is not given, the current figure is set as parent */ if (!parentDefined && (nbInputArgument(pvApiCtx) != 0)) { // Set the parent property iCurrentFigure = getCurrentFigure(); if (iCurrentFigure == 0) { iCurrentFigure = createNewFigureWithAxes(); } setGraphicObjectRelationship(iCurrentFigure, getObjectFromHandle(GraphicHandle)); } /* Create return variable */ nbRow = 1; nbCol = 1; // YOU MUST REMOVE YOUR VARIABLE DECLARATION "int stkAdr". if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, GraphicHandle)) { Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ int sci_figure(char * fname, void* pvApiCtx) { SciErr sciErr; int* piAddr = NULL; int iFig = 0; int iRhs = nbInputArgument(pvApiCtx); int iId = 0; int iPos = 0; int i = 0; int iAxes = 0; int iPropertyOffset = 0; BOOL bDoCreation = TRUE; BOOL bVisible = TRUE; // Create a visible figure by default BOOL bDockable = TRUE; // Create a dockable figure by default BOOL bDefaultAxes = TRUE; // Create an Axes by default double* figureSize = NULL; double* axesSize = NULL; double* position = NULL; double val[4]; BOOL bMenuBar = TRUE; BOOL bToolBar = TRUE; BOOL bInfoBar = TRUE; BOOL bResize = TRUE; int iMenubarType = 1; // Create a 'figure' menubar by default int iToolbarType = 1; // Create a 'figure' toolbar by default double dblId = 0; BOOL status = FALSE; //figure(num) -> scf(num) //figure() -> scf() //figure(x, "...", ...) // figure() if (iRhs == 0) // Auto ID { iId = getValidDefaultFigureId(); iFig = createNewFigureWithAxes(); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, TRUE); initBar(iFig, bMenuBar, bToolBar, bInfoBar); createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; } if (iRhs == 1) { //figure(x); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isVarMatrixType(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } if (getScalarDouble(pvApiCtx, piAddr, &dblId)) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iId = (int)(dblId + 0.5); //avoid 1.999 -> 1 //get current fig from id iFig = getFigureFromIndex(iId); if (iFig == 0) // Figure does not exists, create a new one { iFig = createNewFigureWithAxes(); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, TRUE); } initBar(iFig, bMenuBar, bToolBar, bInfoBar); createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; } // Prepare property analysis if (iRhs % 2 == 0) { //get highest value of winsid to create the new windows @ + 1 iId = getValidDefaultFigureId(); iPos = 0; } else { iPos = 1; //figure(x, ...); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isVarMatrixType(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } if (getScalarDouble(pvApiCtx, piAddr, &dblId)) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iId = (int)(dblId + 0.5); //avoid 1.999 -> 1 //get current fig from id iFig = getFigureFromIndex(iId); if (iFig != 0) // Figure already exists { bDoCreation = FALSE; } } if (bDoCreation) { int* piAddrProp = NULL; char* pstProName = NULL; int* piAddrData = NULL; for (i = iPos + 1 ; i <= iRhs ; i += 2) { //get property name sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrProp); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProp, &pstProName)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); return 1; } if (stricmp(pstProName, "dockable") != 0 && stricmp(pstProName, "toolbar") != 0 && stricmp(pstProName, "menubar") != 0 && stricmp(pstProName, "default_axes") != 0 && stricmp(pstProName, "visible") != 0 && stricmp(pstProName, "figure_size") != 0 && stricmp(pstProName, "axes_size") != 0 && stricmp(pstProName, "position") != 0 && stricmp(pstProName, "menubar_visible") != 0 && stricmp(pstProName, "toolbar_visible") != 0 && stricmp(pstProName, "resize") != 0 && stricmp(pstProName, "infobar_visible") != 0) { freeAllocatedSingleString(pstProName); continue; } //get address of value on stack sciErr = getVarAddressFromPosition(pvApiCtx, i + 1, &piAddrData); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } //check property value to compatibility if (stricmp(pstProName, "dockable") == 0) { bDockable = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bDockable == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "dockable", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "toolbar") == 0) { char* pstVal = NULL; if (isStringType(pvApiCtx, piAddrData) == FALSE || isScalar(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); freeAllocatedSingleString(pstProName); } if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (stricmp(pstVal, "none") == 0) { iToolbarType = 0; } else if (stricmp(pstVal, "figure") == 0) { iToolbarType = 1; } else { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "toolbar", "none", "figure"); freeAllocatedSingleString(pstProName); freeAllocatedSingleString(pstVal); return 1; } freeAllocatedSingleString(pstVal); } else if (stricmp(pstProName, "menubar") == 0) { char* pstVal = NULL; if (isStringType(pvApiCtx, piAddrData) == FALSE || isScalar(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (stricmp(pstVal, "none") == 0) { iMenubarType = 0; } else if (stricmp(pstVal, "figure") == 0) { iMenubarType = 1; } else { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "menubar", "none", "figure"); freeAllocatedSingleString(pstProName); freeAllocatedSingleString(pstVal); return 1; } freeAllocatedSingleString(pstVal); } else if (stricmp(pstProName, "default_axes") == 0) { bDefaultAxes = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bDefaultAxes == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "default_axes", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "visible") == 0) { bVisible = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bVisible == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "figure_size") == 0) { int iRows = 0; int iCols = 0; if (isDoubleType(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong type for input argument #%d: A double vector expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &figureSize); if (iRows * iCols != 2) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "figure_size", 2); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "axes_size") == 0) { int iRows = 0; int iCols = 0; if (isDoubleType(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong type for input argument #%d: A double vector expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &axesSize); if (iRows * iCols != 2) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "axes_size", 2); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "position") == 0) { int iRows = 0; int iCols = 0; double* pdbl = NULL; if (isDoubleType(pvApiCtx, piAddrData)) { getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &pdbl); if (iRows * iCols != 4) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } position = pdbl; axesSize = (pdbl + 2); } else if (isStringType(pvApiCtx, piAddrData) && isScalar(pvApiCtx, piAddrData)) { char* pstVal = NULL; int iVal = 0; if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } iVal = sscanf(pstVal, "%lf|%lf|%lf|%lf", &val[0], &val[1], &val[2], &val[3]); freeAllocatedSingleString(pstVal); if (iVal != 4) { Scierror(999, _("Wrong value for '%s' property: string or 1 x %d real row vector expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } position = val; axesSize = (val + 2); } else { Scierror(999, _("Wrong value for '%s' property: string or 1 x %d real row vector expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "resize") == 0) { bResize = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bResize == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "resize", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "menubar_visible") == 0) { bMenuBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bMenuBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "menubar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "toolbar_visible") == 0) { bToolBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bToolBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "toolbar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "infobar_visible") == 0) { bInfoBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bInfoBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "infobar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } freeAllocatedSingleString(pstProName); } iFig = createFigure(bDockable, iMenubarType, iToolbarType, bDefaultAxes, bVisible); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, bDefaultAxes); } //set(iFig, iPos, iPos + 1) for (i = iPos + 1 ; i <= iRhs ; i += 2) { int isMatrixOfString = 0; int* piAddrProp = NULL; char* pstProName = NULL; int* piAddrData = NULL; int iRows = 0; int iCols = 0; void* _pvData = NULL; int iType = 0; //get property name sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrProp); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProp, &pstProName)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); return 1; } if (bDoCreation && ( stricmp(pstProName, "dockable") == 0 || stricmp(pstProName, "toolbar") == 0 || stricmp(pstProName, "menubar") == 0 || stricmp(pstProName, "default_axes") == 0 || stricmp(pstProName, "visible") == 0 || stricmp(pstProName, "figure_size") == 0 || stricmp(pstProName, "axes_size") == 0 || stricmp(pstProName, "position") == 0 || stricmp(pstProName, "resize") == 0 || stricmp(pstProName, "menubar_visible") == 0 || stricmp(pstProName, "toolbar_visible") == 0 || stricmp(pstProName, "infobar_visible") == 0)) { // Already set creating new figure // but let the set_ function fail if figure already exists freeAllocatedSingleString(pstProName); continue; } //get address of value on stack sciErr = getVarAddressFromPosition(pvApiCtx, i + 1, &piAddrData); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getVarType(pvApiCtx, piAddrData, &iType); if ((strcmp(pstProName, "user_data") == 0) || (stricmp(pstProName, "userdata") == 0)) { /* in this case set_user_data_property * directly uses the third position in the stack * to get the variable which is to be set in * the user_data property (any data type is allowed) S. Steer */ _pvData = (void*)piAddrData; /*position in the stack */ iRows = -1; /*unused */ iCols = -1; /*unused */ iType = -1; } else { switch (iType) { case sci_matrix : getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, (double**)&_pvData); break; case sci_boolean : getMatrixOfBoolean(pvApiCtx, piAddrData, &iRows, &iCols, (int**)&_pvData); break; case sci_handles : getMatrixOfHandle(pvApiCtx, piAddrData, &iRows, &iCols, (long long**)&_pvData); break; case sci_strings : if ( strcmp(pstProName, "tics_labels") != 0 && strcmp(pstProName, "auto_ticks") != 0 && strcmp(pstProName, "axes_visible") != 0 && strcmp(pstProName, "axes_reverse") != 0 && strcmp(pstProName, "text") != 0 && stricmp(pstProName, "string") != 0 && stricmp(pstProName, "tooltipstring") != 0) /* Added for uicontrols */ { if (getAllocatedSingleString(pvApiCtx, piAddrData, (char**)&_pvData)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, 3); freeAllocatedSingleString(pstProName); return 1; } iRows = (int)strlen((char*)_pvData); iCols = 1; } else { isMatrixOfString = 1; if (getAllocatedMatrixOfString(pvApiCtx, piAddrData, &iRows, &iCols, (char***)&_pvData)) { Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); freeAllocatedSingleString(pstProName); return 1; } } break; case sci_list : iCols = 1; getListItemNumber(pvApiCtx, piAddrData, &iRows); _pvData = (void*)piAddrData; /* In this case l3 is the list position in stack */ break; default : _pvData = (void*)piAddrData; /* In this case l3 is the list position in stack */ break; } } callSetProperty(pvApiCtx, iFig, _pvData, iType, iRows, iCols, pstProName); // If backgroundcolor is set : // * add it to colormap => performed by callSetProperty // * set background to index => performed by callSetProperty // * copy value into axes background property if (stricmp(pstProName, "backgroundcolor") == 0 && iAxes > 0) { int iBackground = 0; int *piBackground = &iBackground; getGraphicObjectProperty(iFig, __GO_BACKGROUND__, jni_int, (void **)&piBackground); setGraphicObjectProperty(iAxes, __GO_BACKGROUND__, piBackground, jni_int, 1); } freeAllocatedSingleString(pstProName); if (iType == sci_strings) { //free allacted data if (isMatrixOfString == 1) { freeAllocatedMatrixOfString(iRows, iCols, (char**)_pvData); } else { freeAllocatedSingleString((char*)_pvData); } } } if (position) { int pos[2]; pos[0] = (int)position[0]; pos[1] = (int)position[1]; setGraphicObjectProperty(iFig, __GO_POSITION__, pos, jni_int_vector, 2); } //axes_size if (axesSize) { int axes[2]; axes[0] = (int)axesSize[0]; axes[1] = (int)axesSize[1]; setGraphicObjectProperty(iFig, __GO_AXES_SIZE__, axes, jni_int_vector, 2); } else //no size, use default axes_size { int* piAxesSize = NULL; getGraphicObjectProperty(getFigureModel(), __GO_AXES_SIZE__, jni_int_vector, (void **)&piAxesSize); setGraphicObjectProperty(iFig, __GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2); releaseGraphicObjectProperty(__GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2); } initBar(iFig, bMenuBar, bToolBar, bInfoBar); if (axesSize == NULL && figureSize) //figure_size { int figure[2]; figure[0] = (int)figureSize[0]; figure[1] = (int)figureSize[1]; setGraphicObjectProperty(iFig, __GO_SIZE__, figure, jni_int_vector, 2); } setGraphicObjectProperty(iFig, __GO_RESIZE__, (void*)&bResize, jni_bool, 1); //return new created fig createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; }
/*--------------------------------------------------------------------------*/ int sci_getcallbackobject(char *fname, void* pvApiCtx) { SciErr sciErr; int* piAddrpObjUID = NULL; int nbRow = 0; int nbCol = 0; double ObjUID = 0; unsigned long graphicHandle = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); if ((checkInputArgumentType(pvApiCtx, 1, sci_matrix))) { sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrpObjUID); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 1. if (getScalarDouble(pvApiCtx, piAddrpObjUID, &ObjUID)) { Scierror(202, _("%s: Wrong type for argument #%d: Real expected.\n"), fname, 1); return 1; } } else { Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 1); return FALSE; } graphicHandle = getHandle((int)ObjUID); /* Create return variable */ if (graphicHandle == 0) /* Non-existing object --> return [] */ { if (createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1)) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } else /* Return the handle */ { if (createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, graphicHandle)) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return TRUE; }
/*--------------------------------------------------------------------------*/ 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; }
/*--------------------------------------------------------------------------*/ int sci_get(char *fname, void *pvApiCtx) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; int* piAddrl2 = NULL; char* l2 = NULL; int m1 = 0, n1 = 0; long hdl = 0; int lw = 0; int iObjUID = 0; int status = SET_PROPERTY_ERROR; CheckInputArgument(pvApiCtx, 1, 2); CheckOutputArgument(pvApiCtx, 0, 1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isMListType(pvApiCtx, piAddrl1) || isTListType(pvApiCtx, piAddrl1)) { OverLoad(1); return 0; } /* * The first input argument can be an ID or a marker (in this case, get returns the value of the current object */ switch (getInputArgumentType(pvApiCtx, 1)) { case sci_matrix: //console handle { double dbll1 = 0; if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getScalarDouble(pvApiCtx, piAddrl1, &dbll1)) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } if ((int)dbll1 == 0) /* Console property */ { int* piAddrstkAdr = NULL; char *stkAdr = NULL; if (nbInputArgument(pvApiCtx) == 1) { if (sciReturnHandle(getHandle(getConsoleIdentifier())) != 0) /* Get Console handle */ { ReturnArguments(pvApiCtx); return 0; } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } CheckInputArgument(pvApiCtx, 2, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrstkAdr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrstkAdr, &stkAdr)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (GetScreenProperty(pvApiCtx, stkAdr) != SET_PROPERTY_SUCCEED) { Scierror(999, _("%s: Could not read property '%s' for console object.\n"), "get", stkAdr[0]); freeAllocatedSingleString(stkAdr); return 1; } freeAllocatedSingleString(stkAdr); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); } return 0; break; } case sci_handles: /* scalar argument (hdl + string) */ CheckInputArgument(pvApiCtx, 1, 2); // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } if (m1 != 1 || n1 != 1) { //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; } if (nbInputArgument(pvApiCtx) == 1) { //get path from handle int uic = getObjectFromHandle((long) * l1); char* path = get_path(uic); if (path[0] == '\0') { Scierror(999, _("%s: Unable to get useful path from this handle.\n"), fname); return 1; } createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, path); FREE(path); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } // Retrieve a matrix of double at position 2. if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } hdl = (long) * l1; /* on recupere le pointeur d'objet par le handle */ break; case sci_strings: /* string argument (string) */ { char* pstFirst = NULL; CheckInputArgument(pvApiCtx, 1, 2); if (isScalar(pvApiCtx, piAddrl1) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 1); return 1; } // Retrieve a matrix of double at position 1. if (getAllocatedSingleString(pvApiCtx, piAddrl1, &pstFirst)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1); return 1; } if (strcmp(pstFirst, "default_figure") == 0 || strcmp(pstFirst, "default_axes") == 0 || strcmp(pstFirst, "current_figure") == 0 || strcmp(pstFirst, "current_axes") == 0 || strcmp(pstFirst, "current_entity") == 0 || strcmp(pstFirst, "hdl") == 0 || strcmp(pstFirst, "figures_id") == 0) { hdl = 0; l2 = pstFirst; } else { int uid = search_path(pstFirst); if (uid != 0) { freeAllocatedSingleString(pstFirst); hdl = getHandle(uid); if (nbInputArgument(pvApiCtx) == 1) { createScalarHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 1, hdl); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } if (isScalar(pvApiCtx, piAddrl2) == 0 || isStringType(pvApiCtx, piAddrl2) == 0) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2)) { Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 2); return 1; } } else { createEmptyMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; } } break; } default: //lw = 1 + nbArgumentOnStack(pvApiCtx) - nbInputArgument(pvApiCtx); OverLoad(1); return 0; break; } /* (l2) est la commande, l3 l'indice sur les parametres de la commande */ CheckOutputArgument(pvApiCtx, 0, 1); if (hdl == 0) { /* No handle specified */ if (callGetProperty(pvApiCtx, 0, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { iObjUID = getObjectFromHandle(hdl); if (iObjUID != 0) { if (callGetProperty(pvApiCtx, iObjUID, (l2)) != 0) { /* An error has occurred */ freeAllocatedSingleString(l2); ReturnArguments(pvApiCtx); return 0; } } else { Scierror(999, _("%s: The handle is not or no more valid.\n"), fname); freeAllocatedSingleString(l2); return 0; } } AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); freeAllocatedSingleString(l2); return 0; }