/*--------------------------------------------------------------------------*/ void* get_default_figure_property(void* _pvCtx, int iObjUID) { if (iObjUID != 0) { /* This property should not be called on an handle */ Scierror(999, _("'%s' property does not exist for this handle.\n"), "default_figure"); return NULL; } return sciReturnHandle(getHandle(getFigureModel())); }
int InitAxesModel() { int cubeScaling = 0; int logFlag = 0; int ticksColor = 0; int axisLocation = 0; int boxType = 0; int filled = 0; int gridColor = 0; int gridPosition = 0; int view = 0; int axisReverse = 0; int axisVisible = 0; int defaultNumberTicks = 0; int autoTicks = 0; int autoSubticks = 0; int nbSubticks = 0; int hiddenAxisColor = 0; int hiddenColor = 0; int isoview = 0; int visible = 0; int *piVisible = &visible; int clipState = 0; int tightLimits = 0; int arcDrawingMethod = 0; int labelsFontStyle = 6; int labelsFontColor = -1; int i = 0; double labelsFontSize = 1; double axesBounds[4]; double dataBounds[6]; double rotationAngles[2]; double tab[] = { 0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. }; /* graduations init. tmptab */ /* z-axis initial ticks locations */ double tabZTicksLocations[] = { -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 }; char labelBuffer[LABEL_BUFFER_LENGTH]; char **stringVector = NULL; int lineColor = -1; int background = -2; int foreground = -1; double lineWidth = 1.0; /* 0: solid */ int lineStyle = 0; int markMode = 0; int lineMode = 1; int fillMode = 1; int markStyle = 0; int markSize = 0; /* 0: point, 1: tabulated */ int markSizeUnit = 1; int iLabelUID = 0; int iFiguremdlUID = getFigureModel(); int iAxesmdlUID = getAxesModel(); sciInitGraphicMode(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_BACKGROUND__, &background, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_COLOR__, &foreground, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_SIZE__, &labelsFontSize, jni_double, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_COLOR__, &labelsFontColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FONT_STYLE__, &labelsFontStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_THICKNESS__, &lineWidth, jni_double, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_STYLE__, &lineStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_MODE__, &markMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_MODE__, &lineMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_FILL_MODE__, &fillMode, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_STYLE__, &markStyle, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_SIZE__, &markSize, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_BACKGROUND__, &background, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_MARK_FOREGROUND__, &foreground, jni_int, 1); cubeScaling = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_CUBE_SCALING__, &cubeScaling, jni_bool, 1); /* Log flags set to linear for the 3 axes */ logFlag = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_LOG_FLAG__, &logFlag, jni_bool, 1); ticksColor = -1; setGraphicObjectProperty(iAxesmdlUID, __GO_TICKS_COLOR__, &ticksColor, jni_int, 1); nbSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); /* 0 corresponds to bottom position */ axisLocation = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LOCATION__, &axisLocation, jni_int, 1); /* 4 corresponds to left position */ axisLocation = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LOCATION__, &axisLocation, jni_int, 1); /* 0 corresponds to OFF */ boxType = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_BOX_TYPE__, &boxType, jni_int, 1); filled = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_FILLED__, &filled, jni_bool, 1); gridColor = -1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_GRID_COLOR__, &gridColor, jni_int, 1); /* 0: background */ setGraphicObjectProperty(iAxesmdlUID, __GO_LINE_COLOR__, &lineColor, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_BACKGROUND__, &background, jni_int, 1); gridPosition = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_GRID_POSITION__, &gridPosition, jni_int, 1); rotationAngles[0] = 0.0; rotationAngles[1] = 270.0; setGraphicObjectProperty(iAxesmdlUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2); /* 0: 2D view */ view = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_VIEW__, &view, jni_int, 1); /* Must be set after VIEW, since setting VIEW to 2D overwrites the 3D rotation angles */ rotationAngles[0] = 45.0; rotationAngles[1] = 215.0; setGraphicObjectProperty(iAxesmdlUID, __GO_ROTATION_ANGLES_3D__, rotationAngles, jni_double_vector, 2); axisVisible = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_VISIBLE__, &axisVisible, jni_bool, 1); axisReverse = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_REVERSE__, &axisReverse, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_REVERSE__, &axisReverse, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_REVERSE__, &axisReverse, jni_bool, 1); /* Corresponds to the MVC AUTO_SUBTICKS property (!flagNax is equivalent to AUTO_SUBTICKS) */ #if 0 ppaxesmdl->flagNax = FALSE; #endif autoSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1); /* To be corrected when the equivalent of flagnax is implemented within the MVC */ nbSubticks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_SUBTICKS__, &nbSubticks, jni_int, 1); /* * The code creating default ticks labels and positions should be put * into the Model. Ticks positions and locations should be computed using the default data bounds * instead of using pre-defined values. * Note that the pre-MVC ticks labels creation code is implemented in the C++ Renderer module * and should be moved to the Java Model's relevant parts (TicksProperty). */ /* * Automatic ticks computation must be activated for the 3 axes before setting ticks values to * ensure that the ticks values set are the automatic ticks' ones. */ autoTicks = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); defaultNumberTicks = 11; setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_TICKS_LOCATIONS__, tab, jni_double_vector, defaultNumberTicks); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_TICKS_LOCATIONS__, tab, jni_double_vector, defaultNumberTicks); stringVector = createStringArray(defaultNumberTicks); if (stringVector == NULL) { return -1; } /* * A proper format should be used (ChoixFormatE function) */ for (i = 0; i < defaultNumberTicks; i++) { sprintf(labelBuffer, "%.1f", tab[i]); stringVector[i] = os_strdup(labelBuffer); if (stringVector[i] == NULL) { return -1; } } setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); /* * The same number of ticks is used now for the x,y and z axes. * Previously, the z-axis contained only 3 ticks (-1, 0, 1). However, the renderer module was * overriding this default number (3) by creating an 11-tick z-axis when required (3D view). * Ticks locations and labels are however different for the z-axis (from -1 to +1 instead of 0 to 1). */ setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_TICKS_LOCATIONS__, tabZTicksLocations, jni_double_vector, defaultNumberTicks); /* ChoixFormatE should be used */ for (i = 0; i < defaultNumberTicks; i++) { FREE(stringVector[i]); sprintf(labelBuffer, "%.1f", tabZTicksLocations[i]); stringVector[i] = os_strdup(labelBuffer); if (stringVector[i] == NULL) { return -1; } } setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, defaultNumberTicks); destroyStringArray(stringVector, defaultNumberTicks); /* * Indicates the direction of projection (0 for the axis corresponding to the direction, * 1 for the others). * To be implemented within the MVC if determined to be useful. */ #if 0 ppaxesmdl->project[0] = 1; ppaxesmdl->project[1] = 1; ppaxesmdl->project[2] = 0; #endif hiddenAxisColor = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_HIDDEN_AXIS_COLOR__, &hiddenAxisColor, jni_int, 1); hiddenColor = 4; setGraphicObjectProperty(iAxesmdlUID, __GO_HIDDEN_COLOR__, &hiddenColor, jni_int, 1); isoview = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_ISOVIEW__, &isoview, jni_bool, 1); /* Axes bounds set to fill the whole drawing area */ axesBounds[0] = 0.0; axesBounds[1] = 0.0; axesBounds[2] = 1.0; axesBounds[3] = 1.0; setGraphicObjectProperty(iAxesmdlUID, __GO_AXES_BOUNDS__, axesBounds, jni_double_vector, 4); /* xmin, xmax */ dataBounds[0] = 0.0; dataBounds[1] = 1.0; /* ymin, ymax */ dataBounds[2] = 0.0; dataBounds[3] = 1.0; /* zmin, zmax */ dataBounds[4] = -1.0; dataBounds[5] = 1.0; setGraphicObjectProperty(iAxesmdlUID, __GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6); /* visible */ getGraphicObjectProperty(iFiguremdlUID, __GO_VISIBLE__, jni_bool, (void**)&piVisible); setGraphicObjectProperty(iAxesmdlUID, __GO_VISIBLE__, &visible, jni_bool, 1); /* 0: clipping off */ clipState = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); /* "real data bounds" and "data bounds" are initially the same */ setGraphicObjectProperty(iAxesmdlUID, __GO_REAL_DATA_BOUNDS__, dataBounds, jni_double_vector, 6); tightLimits = 0; setGraphicObjectProperty(iAxesmdlUID, __GO_X_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_TIGHT_LIMITS__, &tightLimits, jni_bool, 1); /* Sets the default arc drawing method to lines (1), which is faster */ arcDrawingMethod = 1; setGraphicObjectProperty(iAxesmdlUID, __GO_ARC_DRAWING_METHOD__, &arcDrawingMethod, jni_int, 1); /* Creates the Axes model's labels and sets the model as their parent */ iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_TITLE__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_X_AXIS_LABEL__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_Y_AXIS_LABEL__, &iLabelUID, jni_int, 1); iLabelUID = initLabel(iAxesmdlUID); setGraphicObjectProperty(iAxesmdlUID, __GO_Z_AXIS_LABEL__, &iLabelUID, jni_int, 1); return 0; }
/*--------------------------------------------------------------------------*/ 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; }