/*----------------------------------------------------------- * Objsegs : *-----------------------------------------------------------*/ void Objsegs (int * style, int flag , int n1 , double * x , double * y , double * z , double arsize) { char *pobjUID = NULL; char *psubwinUID = NULL; int type = 0, colored = 0; double *fx = NULL, *fy = NULL; // No fx or fy int typeofchamp = -1; /* no champ here, only segs ; this info is useless */ checkRedrawing(); psubwinUID = (char*)getCurrentSubWin(); pobjUID = ConstructSegs(psubwinUID, type, x, y, z, n1, n1, (z == NULL ? 0 : n1), // x, y and z have the same size n1 fx, fy, flag, style, arsize, colored, typeofchamp); if (pobjUID == NULL) { Scierror(999, _("%s: No more memory.\n"), "Objsegs"); return; } setCurrentObject(pobjUID); releaseGraphicObjectProperty(__GO_SEGS__, pobjUID, jni_string, 1); }
int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int bufferLength, int x, int y, int width, int height) { double* value = NULL; getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &value); if (width * height * 4 == bufferLength) { char* parentFigure = NULL; double* colormap = NULL; int colormapSize = 0; int* piColormapSize = &colormapSize; getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure); getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); int textureHeight = getTextureHeight(id); int k = 0; for (int j = y ; j < y + height ; j++) { for (int i = x ; i < x + width ; i++) { ColorComputer::getDirectByteColor(value[j + i * textureHeight] - 1, colormap, colormapSize, &buffer[k]); buffer[k + 3] = 255; k += 4; } } releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); return bufferLength; } else { return 0; } }
static char *getPlot3d(char *pAxeUID, scicos_block * block) { char *pPlot3d; sco_data *sco = (sco_data *) * (block->work); // assert the sco is not NULL if (sco == NULL) { return NULL; } // fast path for an existing object if (sco->scope.cachedPlot3dUID != NULL) { return sco->scope.cachedPlot3dUID; } pPlot3d = findChildWithKindAt(pAxeUID, __GO_PLOT3D__, 0); /* * Allocate if necessary */ if (pPlot3d == NULL) { pPlot3d = createGraphicObject(__GO_PLOT3D__); if (pPlot3d != NULL) { createDataObject(pPlot3d, __GO_PLOT3D__); setGraphicObjectRelationship(pAxeUID, pPlot3d); } } /* * Setup on first access */ if (pPlot3d != NULL) { setBounds(block, pAxeUID, pPlot3d); setPlot3dSettings(pPlot3d); setDefaultValues(block, pPlot3d); { int iClipState = 1; //on setGraphicObjectProperty(pPlot3d, __GO_CLIP_STATE__, &iClipState, jni_int, 1); } } /* * then cache with a local storage */ if (pPlot3d != NULL && sco->scope.cachedPlot3dUID == NULL) { sco->scope.cachedPlot3dUID = strdup(pPlot3d); releaseGraphicObjectProperty(__GO_PARENT__, pPlot3d, jni_string, 1); } return sco->scope.cachedPlot3dUID; }
/* * To do: allowing either per-vertex or per-facet colors */ void NgonGridGrayplotDataDecomposer::fillColors(char* id, float* buffer, int bufferLength, int elementsSize) { char* parentFigure = NULL; char* parent = NULL; double* z = NULL; double* colormap = NULL; int numX = 0; int* piNumX = &numX; int numY = 0; int* piNumY = &numY; int colormapSize = 0; int* piColormapSize = &colormapSize; int dataMapping = 0; int* piDataMapping = &dataMapping; NgonGridGrayplotDataDecomposer* decomposer = get(); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY); getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &z); getGraphicObjectProperty(id, __GO_PARENT__, jni_string, (void**) &parent); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (strcmp(parent, "") == 0) { return; } getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure); if (parentFigure == NULL) { return; } getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); getGraphicObjectProperty(id, __GO_DATA_MAPPING__, jni_int, (void**) &piDataMapping); if (dataMapping == 0) { decomposer->fillNormalizedZGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY); } else if (dataMapping == 1) { decomposer->fillDirectGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY); } releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); }
void NgonGridMatplotDataDecomposer::fillVertices(char* id, float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask) { double* matplotScale = NULL; double* matplotTranslate = NULL; double zShift = 0.; double* pdZShift = &zShift; double xTrans[2]; double yTrans[2]; int numX = 0; int* piNumX = &numX; int numY = 0; int* piNumY = &numY; NgonGridMatplotDataDecomposer* decomposer = get(); getGraphicObjectProperty(id, __GO_MATPLOT_SCALE__, jni_double_vector, (void**) &matplotScale); getGraphicObjectProperty(id, __GO_MATPLOT_TRANSLATE__, jni_double_vector, (void**) &matplotTranslate); getGraphicObjectProperty(id, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, jni_double, (void**) &pdZShift); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY); /* The position of the lower-left corner and the distance between two adjacent vertices i and i+1 (respectively) along the x-axis */ xTrans[0] = matplotTranslate[0]; xTrans[1] = matplotScale[0]; /* The position of the lower-left corner and the distance between two adjacent vertices j and j+1 (respectively) along the y-axis */ yTrans[0] = matplotTranslate[1]; yTrans[1] = matplotScale[1]; /* * We pass the scale and translate values (for both the x and y axes) as the x and y coordinate arrays, * because Matplot vertex coordinates are directly computed from these values. */ decomposer->fillGridVertices(buffer, bufferLength, elementsSize, coordinateMask, scale, translation, logMask, (double*) xTrans, (double*) yTrans, &zShift, numX, numY); releaseGraphicObjectProperty(__GO_MATPLOT_SCALE__, matplotScale, jni_double_vector, 0); releaseGraphicObjectProperty(__GO_MATPLOT_TRANSLATE__, matplotTranslate, jni_double_vector, 0); }
static char *getAxe(char const* pFigureUID, scicos_block * block, int input) { char *pAxe; int i; sco_data *sco = (sco_data *) * (block->work); // assert the sco is not NULL if (sco == NULL) { return NULL; } // fast path for an existing object if (sco->scope.cachedAxeUID != NULL && sco->scope.cachedAxeUID[input] != NULL) { return sco->scope.cachedAxeUID[input]; } pAxe = findChildWithKindAt(pFigureUID, __GO_AXES__, input); /* * Allocate if necessary */ if (pAxe == NULL) { cloneAxesModel(pFigureUID); pAxe = findChildWithKindAt(pFigureUID, __GO_AXES__, input); } /* * Setup on first access */ if (pAxe != NULL) { // allocate the polylines through the getter for (i = 0; i < block->insz[input]; i++) { getPolyline(pAxe, block, input, i); } setAxesSettings(pAxe, block, input); } /* * then cache with local storage */ if (pAxe != NULL && sco->scope.cachedAxeUID != NULL && sco->scope.cachedAxeUID[input] == NULL) { sco->scope.cachedAxeUID[input] = strdup(pAxe); releaseGraphicObjectProperty(__GO_PARENT__, pAxe, jni_string, 1); } return sco->scope.cachedAxeUID[input]; }
/* * To do: compute and return color indices instead of directly looking * up colors from the colormap. */ void Plot3DDecomposer::fillColors(int id, float* buffer, int bufferLength, int elementsSize) { int parentFigure = 0; int* pparentFigure = &parentFigure; int parent = 0; int* pparent = &parent; double* z = NULL; double* colormap = NULL; int numX = 0; int* piNumX = &numX; int numY = 0; int* piNumY = &numY; int colormapSize = 0; int* piColormapSize = &colormapSize; Plot3DDecomposer* decomposer = get(); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY); getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &z); parent = getParentObject(id); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (parent == 0) { return; } getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &pparentFigure); if (parentFigure == 0) { return; } getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); decomposer->fillNormalizedZGridColors(buffer, bufferLength, elementsSize, colormap, colormapSize, z, numX, numY); releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); }
static char *getAxe(char const* pFigureUID, scicos_block * block) { char *pAxe; sco_data *sco = (sco_data *) * (block->work); // assert the sco is not NULL if (sco == NULL) { return NULL; } // fast path for an existing object if (sco->scope.cachedAxeUID != NULL) { return sco->scope.cachedAxeUID; } pAxe = findChildWithKindAt(pFigureUID, __GO_AXES__, 0); /* * Allocate if necessary */ if (pAxe == NULL) { cloneAxesModel(pFigureUID); pAxe = findChildWithKindAt(pFigureUID, __GO_AXES__, 0); } /* * Setup on first access */ if (pAxe != NULL) { getGrayplot(pAxe, block); } /* * then cache with local storage */ if (pAxe != NULL && sco->scope.cachedAxeUID == NULL) { sco->scope.cachedAxeUID = strdup(pAxe); releaseGraphicObjectProperty(__GO_PARENT__, pAxe, jni_string, 1); } return sco->scope.cachedAxeUID; }
void Objrect (double* x , double* y , double* width , double* height , int * foreground, int * background, BOOL isfilled , BOOL isline , long * hdl ) { char* newObjUID = NULL; char* psubwinUID = NULL; char* pFigureUID = NULL; pFigureUID = (char*)getCurrentFigure(); psubwinUID = (char*)getCurrentSubWin(); /* check if the auto_clear property is on and then erase everything */ checkRedrawing(); /*newObjUID = ConstructRectangle(psubwinUID , *x, *y, *height, *width, foreground, background, isfilled, isline);*/ newObjUID = constructRectangles(psubwinUID, *x, *y, *height, *width, foreground == NULL ? -1 : *foreground, background == NULL ? -1 : *background, (int)isfilled, (int)isline); if (newObjUID == NULL) { /* an error occurred */ *hdl = -1; return; } setCurrentObject(newObjUID); *hdl = getHandle(newObjUID); releaseGraphicObjectProperty(-1, newObjUID, jni_string, 0); }
BOOL update_specification_bounds(int iSubwinUID, double rect[6], int flag) { double *dataBounds = NULL; /* * 2D: keep the existing zmin and zmax * which is why they must be fetched */ if (flag != 3) { getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds); rect[4] = dataBounds[4]; rect[5] = dataBounds[5]; releaseGraphicObjectProperty(__GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6); } setGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, rect, jni_double_vector, 6); return TRUE; }
void Objpoly (double * x , double * y , int n , int closed, int mark , long * hdl) { char * pfigureUID = NULL; char * psubwinUID = NULL; char * pobjUID = NULL; psubwinUID = (char*)getCurrentSubWin(); checkRedrawing(); if (mark <= 0) { int absmark = abs(mark); pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, NULL, NULL, &absmark, NULL, NULL, FALSE, FALSE, TRUE, FALSE); } else { pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, &mark, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE); } if (pobjUID == NULL) { Scierror(999, _("%s: No more memory.\n"), "Objpoly"); return; } setCurrentObject(pobjUID); *hdl = getHandle(pobjUID); releaseGraphicObjectProperty(__GO_POLYLINE__, pobjUID, jni_string, 1); }
void Objdrawaxis (char dir , char tics , double* x , int * nx , double* y , int * ny , char * val[] , int subint , char * format , int font , int textcol, int ticscol, char flag , int seg , int nb_tics_labels) { char* pobjUID = NULL; char* psubwinUID = NULL; psubwinUID = (char*)getCurrentSubWin(); checkRedrawing(); pobjUID = ConstructAxis( psubwinUID, dir, tics, x, *nx, y, *ny, val, subint, format, font, textcol, ticscol, flag, seg, nb_tics_labels); if (pobjUID == NULL) { Scierror(999, _("%s: No more memory.\n"), "Objdrawaxis"); return; } setCurrentObject(pobjUID); releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1); }
void Objarc(double* angle1 , double* angle2 , double* x , double* y , double* width , double* height , int * foreground, int * background, BOOL isfilled , BOOL isline , long * hdl ) { char * psubwinUID = NULL; char * pobjUID = NULL; psubwinUID = (char*)getCurrentSubWin(); checkRedrawing(); pobjUID = ConstructArc(psubwinUID, *x, *y, *height, *width, *angle1, *angle2, foreground, background, isfilled, isline); setCurrentObject(pobjUID); *hdl = getHandle(pobjUID); releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1); }
int findChildWithKindAt(int parent, int type, const int position) { int child = 0; int childrenCount = 0; int*children = NULL; int i; int iChildType = -1; int *piChildType = &iChildType; int typeCount; int *pChildrenCount = &childrenCount; getGraphicObjectProperty(parent, __GO_CHILDREN_COUNT__, jni_int, (void **)&pChildrenCount); getGraphicObjectProperty(parent, __GO_CHILDREN__, jni_int_vector, (void **)&children); for (typeCount = 0, i = childrenCount - 1; i >= 0; i--) { getGraphicObjectProperty(children[i], __GO_TYPE__, jni_int, (void **)&piChildType); if (iChildType == type) { typeCount++; } if (typeCount == (position + 1)) { child = children[i]; LOG("%s: found %s at %d : %d\n", "findChildWithKindAt", type, position, child); break; } } releaseGraphicObjectProperty(__GO_CHILDREN__, children, jni_int_vector, childrenCount); return child; };
void MeshFecDataDecomposer::fillTextureCoordinates(int id, float* buffer, int bufferLength) { int parentFigure = 0; int * piParentFigure = &parentFigure; int colormapSize = 0; int* piColormapSize = &colormapSize; int* colorRange = NULL; double colorsNumber = 0.; double scale = 0.; double t = 0.; double* values = NULL; double* zBounds = NULL; double minValue = 0.; double maxValue = 0.; int numVertices = 0; int* piNumVertices = &numVertices; int bufferOffset = 0; getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &piParentFigure); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (parentFigure == 0) { return; } getGraphicObjectProperty(id, __GO_COLOR_RANGE__, jni_int_vector, (void**) &colorRange); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); if (colorRange[0] != 0 || colorRange[1] != 0) { colorsNumber = (double) (1 + colorRange[1] - colorRange[0]); } else { colorsNumber = (double) colormapSize; } releaseGraphicObjectProperty(__GO_COLOR_RANGE__, colorRange, jni_int_vector, 0); /** To take into account the presence of exterior colors: * - We add 2 to the number of colors. * - We skip the first color. */ t = 3. / (2. * (colorsNumber + 2.)); scale = (colorsNumber - 1.) / (colorsNumber + 2); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, (void**) &piNumVertices); getGraphicObjectProperty(id, __GO_DATA_MODEL_VALUES__, jni_double_vector, (void**) &values); getGraphicObjectProperty(id, __GO_Z_BOUNDS__, jni_double_vector, (void**) &zBounds); /* Z-bounds are not taken into account if either of them is invalid */ if ((zBounds[0] != 0.0 || zBounds[1] != 0.0) && (DecompositionUtils::isValid(zBounds[0]) && DecompositionUtils::isValid(zBounds[1])) && (zBounds[0] != zBounds[1])) { minValue = zBounds[0]; maxValue = zBounds[1]; } else { computeMinMaxValues(values, numVertices, &minValue, &maxValue); } releaseGraphicObjectProperty(__GO_Z_BOUNDS__, zBounds, jni_double_vector, 0); if (maxValue == minValue) { for (int i = 0; i < numVertices; i++) { buffer[bufferOffset++] = (float)minValue; buffer[bufferOffset++] = 0; buffer[bufferOffset++] = 0; buffer[bufferOffset++] = 1; } } else { for (int i = 0; i < numVertices; i++) { buffer[bufferOffset++] = (float)(t + scale * (values[i] - minValue) / (maxValue - minValue)); buffer[bufferOffset++] = 0; buffer[bufferOffset++] = 0; buffer[bufferOffset++] = 1; } } }
void Objfpoly (double * x , double * y , int n , int * style, long * hdl , int shading) { char* psubwinUID = NULL; char* pobjUID = NULL; int fillcolor = 0; int contourcolor = 0; int *piContourColor = &contourcolor; int closed = 1; /* we close the polyline by default */ psubwinUID = (char*)getOrCreateDefaultSubwin(); checkRedrawing(); if (shading == 2) { /* interpolated shading is "on" */ pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, NULL, style, NULL, NULL, NULL, FALSE, TRUE, FALSE, TRUE); } else { /* flat mode is "on" */ if (*style < 0) { fillcolor = abs(*style); pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, NULL, &fillcolor, NULL, NULL, NULL, FALSE, TRUE, FALSE, FALSE); } else if (*style == 0) { getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor); pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, &contourcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE); } else { /* *style > 0*/ fillcolor = *style; getGraphicObjectProperty(psubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piContourColor); pobjUID = ConstructPolyline(psubwinUID, x, y, PD0, closed, n, 1, &contourcolor, &fillcolor, NULL, NULL, NULL, TRUE, TRUE, FALSE, FALSE); } } if (pobjUID == NULL) { Scierror(999, _("%s: No more memory.\n"), "Objfpoly"); return; } setCurrentObject(pobjUID); *hdl = getHandle(pobjUID); releaseGraphicObjectProperty(__GO_PARENT__, pobjUID, jni_string, 1); }
static char *getPolyline(char *pAxeUID, scicos_block * block, int input, int row) { char *pPolyline; double d__0 = 0.0; BOOL b__true = TRUE; int color; sco_data *sco = (sco_data *) * (block->work); // assert the sco is not NULL if (sco == NULL) { return NULL; } // fast path for an existing object if (sco->scope.cachedPolylinesUIDs != NULL && sco->scope.cachedPolylinesUIDs[input] != NULL && sco->scope.cachedPolylinesUIDs[input][row] != NULL) { return sco->scope.cachedPolylinesUIDs[input][row]; } pPolyline = findChildWithKindAt(pAxeUID, __GO_POLYLINE__, row); /* * Allocate if necessary */ if (pPolyline == NULL) { pPolyline = createGraphicObject(__GO_POLYLINE__); if (pPolyline != NULL) { createDataObject(pPolyline, __GO_POLYLINE__); setGraphicObjectRelationship(pAxeUID, pPolyline); } } /* * Setup on first access */ if (pPolyline != NULL) { /* * Default setup (will crash if removed) */ { int polylineSize[2] = { 1, block->ipar[2] }; setGraphicObjectProperty(pPolyline, __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__, polylineSize, jni_int_vector, 2); } setGraphicObjectProperty(pPolyline, __GO_DATA_MODEL_X__, &d__0, jni_double_vector, 1); setGraphicObjectProperty(pPolyline, __GO_DATA_MODEL_Y__, &d__0, jni_double_vector, 1); // ipar=[win;size(in,'*');N;wpos(:);wdim(:);in(:);clrs(:);heritance] // 1 1 1 2 2 nin nin 1 color = block->ipar[7 + block->nin + input + row]; if (color > 0) { LOG("%s: %s at %d at %d to %d\n", "cmscope", "set lines mode", input, row, color); setGraphicObjectProperty(pPolyline, __GO_LINE_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(pPolyline, __GO_LINE_COLOR__, &color, jni_int, 1); } else { color = -color; LOG("%s: %s at %d at %d to %d\n", "cmscope", "set mark mode", input, row, -color); setGraphicObjectProperty(pPolyline, __GO_MARK_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(pPolyline, __GO_MARK_STYLE__, &color, jni_int, 1); } { int iClipState = 1; //on setGraphicObjectProperty(pPolyline, __GO_CLIP_STATE__, &iClipState, jni_int, 1); } } /* * then cache with local storage */ if (sco->scope.cachedPolylinesUIDs != NULL && sco->scope.cachedPolylinesUIDs[input] != NULL) { sco->scope.cachedPolylinesUIDs[input][row] = strdup(pPolyline); releaseGraphicObjectProperty(__GO_PARENT__, pPolyline, jni_string, 1); } return sco->scope.cachedPolylinesUIDs[input][row]; }
void Fac3DDecomposer::fillTextureCoordinates(int id, float* buffer, int bufferLength) { int parentFigure = 0; int* pparentFigure = &parentFigure; int parent = 0; int* pparent = &parent; double* colors = NULL; double* colormap = NULL; double* z = NULL; double color = 0.; int numVerticesPerGon = 0; int* piNumVerticesPerGon = &numVerticesPerGon; int numGons = 0; int* piNumGons = &numGons; int numColors = 0; int* piNumColors = &numColors; int colormapSize = 0; int* piColormapSize = &colormapSize; int colorFlag = 0; int* piColorFlag = &colorFlag; int dataMapping = 0; int* piDataMapping = &dataMapping; int perVertex = 0; getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, jni_int, (void**) &piNumVerticesPerGon); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_GONS__, jni_int, (void**) &piNumGons); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_COLORS__, jni_int, (void**) &piNumColors); getGraphicObjectProperty(id, __GO_DATA_MODEL_COLORS__, jni_double_vector, (void**) &colors); parent = getParentObject(id); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (parent == 0) { return; } getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &pparentFigure); if (parentFigure == 0) { return; } getGraphicObjectProperty(id, __GO_COLOR_FLAG__, jni_int, (void**) &piColorFlag); getGraphicObjectProperty(id, __GO_DATA_MAPPING__, jni_int, (void**) &piDataMapping); /* Do not fill */ if (colorFlag == 0) { return; } getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); if (numColors == numGons * numVerticesPerGon) { perVertex = 1; } else if (numColors == numGons) { perVertex = 0; } getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_int, (void**) &z); if (colorFlag == 1) { fillNormalizedZColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize, z, numGons, numVerticesPerGon); } else if (colorFlag > 1 && numColors == 0) { /* * The color buffer must be filled with the color_mode value. * To do: correctly take into account Nan and infinite values. */ int colorMode = 0; int* piColorMode = &colorMode; getGraphicObjectProperty(id, __GO_COLOR_MODE__, jni_int, (void**) &piColorMode); color = (double) colorMode; color = DecompositionUtils::getAbsoluteValue(color); fillConstantColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize, color, numGons, numVerticesPerGon); } else { fillDataColorsTextureCoordinates(buffer, bufferLength, colormap, colormapSize, colors, colorFlag, perVertex, dataMapping, numGons, numVerticesPerGon); } releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); }
/*------------------------------------------------ * 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; }
/* * To do: * -clean-up: replace explicitely computed z indices by getPointIndex calls * -remove the per-vertex color fill code */ void NgonGridMatplotDataDecomposer::fillColors(char* id, float* buffer, int bufferLength, int elementsSize) { char* parent = NULL; char* parentFigure = NULL; double* z = NULL; double* colormap = NULL; double currentZ = 0.; int numX = 0; int* piNumX = &numX; int numY = 0; int* piNumY = &numY; int colormapSize = 0; int* piColormapSize = &colormapSize; int bufferOffset = 0; getGraphicObjectProperty(id, __GO_PARENT__, jni_string, (void**) &parent); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (strcmp(parent, "") == 0) { return; } getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piNumX); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piNumY); getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &z); /* In order not to access invalid data when reading the last line's last element */ if (numX < 2) { return; } getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); #if PER_VERTEX_VALUES for (int j = 0; j < numY - 1; j++) { for (int i = 0; i < numX - 1; i++) { currentZ = z[i * (numY - 1) + (numY - 2 - j)]; ColorComputer::getDirectColor((double) currentZ - 1.0, colormap, colormapSize, &buffer[bufferOffset]); if (elementsSize == 4) { buffer[bufferOffset + 3] = 1.0; } bufferOffset += elementsSize; } /* Last element (same as the above loop's last) */ currentZ = z[(numX - 2) * (numY - 1) + (numY - 2 - j)]; ColorComputer::getDirectColor((double) currentZ - 1.0, colormap, colormapSize, &buffer[bufferOffset]); if (elementsSize == 4) { buffer[bufferOffset + 3] = 1.0; } bufferOffset += elementsSize; } /* Last line */ for (int i = 0; i < numX - 1; i++) { currentZ = z[(numY - 1) * i + 0]; ColorComputer::getDirectColor((double) currentZ - 1.0, colormap, colormapSize, &buffer[bufferOffset]); bufferOffset += elementsSize; if (elementsSize == 4) { buffer[bufferOffset + 3] = 1.0; } } /* Last element (same as the above loop's last) */ currentZ = z[(numX - 2) * (numY - 1) + 0]; ColorComputer::getDirectColor((double) currentZ - 1.0, colormap, colormapSize, &buffer[bufferOffset]); if (elementsSize == 4) { buffer[bufferOffset + 3] = 1.0; } #else for (int j = 0; j < numY - 1; j++) { for (int i = 0; i < numX - 1; i++) { float facetColor[3]; currentZ = z[i * (numY - 1) + (numY - 2 - j)]; ColorComputer::getDirectColor((double) currentZ - 1.0, colormap, colormapSize, facetColor); writeFacetColorToBuffer(buffer, bufferOffset, facetColor, elementsSize); bufferOffset += 4 * elementsSize; } } #endif releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); }
/*--------------------------------------------------------------------------*/ int sci_glue(char * fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; double* l2 = NULL; int* lind = NULL; long long* outindex = NULL; int numrow = 0, numcol = 0, n = 0, cx1 = 1; long *handelsvalue = NULL; int i = 0; char *pstCompoundUID = NULL; char *pstParentUID = NULL; char *pstCurrentParentUID = NULL; char *pobjUID = NULL; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); /* set or create a graphic window */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &numrow, &numcol, &l1); /* We get the scalar value if it is ones */ if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: Handle matrix expected.\n"), fname, 1); return 1; } n = numrow * numcol; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, numrow, numcol, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, nbInputArgument(pvApiCtx) + 2, numrow, numcol, &lind); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (n > 1) { C2F(dcopy)(&n, (double*)l1, &cx1, l2, &cx1); C2F(dsort)(l2, &n, (int*)(lind)); for (i = 1; i < n; i++) { long long i1 = ((long long*)l2)[i]; long long i2 = ((long long*)l2)[i - 1]; if (i1 == i2) { Scierror(999, _("%s: Each handle should not appear twice.\n"), fname); return 0; } } } /* we must change the pobj to the Compound type */ handelsvalue = MALLOC(n * sizeof(long)); for (i = 0 ; i < n ; i++) { handelsvalue[i] = (unsigned long) l1[i]; pobjUID = (char*)getObjectFromHandle(handelsvalue[i]); if (pobjUID == NULL) { FREE(handelsvalue); Scierror(999, _("%s: The handle is not or no more valid.\n"), fname); return 0; } getGraphicObjectProperty(pobjUID, __GO_PARENT__, jni_string, (void **)&pstCurrentParentUID); if (i == 0) { pstParentUID = pstCurrentParentUID; } if (strcmp(pstParentUID, pstCurrentParentUID) != 0) { FREE(handelsvalue); Scierror(999, _("%s: Objects must have the same parent.\n"), fname); return 0; } } //ret = CheckForCompound (handelsvalue, n); //if (ret>0) //{ // MEM LEAK // Scierror(999,_("%s: Handle %d cannot be glued (invalid parent).\n"),fname,ret); // return 0; //} //if (ret<0) //{ // MEM LEAK // Scierror(999,_("%s: Handle %d cannot be glued (invalid type).\n"),fname,-ret); // return 0; //} pstCompoundUID = ConstructCompound(handelsvalue, n); setCurrentObject(pstCompoundUID); numrow = 1; numcol = 1; sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 3, numrow, numcol, &outindex); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } outindex[0] = getHandle(pstCompoundUID); releaseGraphicObjectProperty(__GO_PARENT__, pstCompoundUID, jni_string, 1); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 3; ReturnArguments(pvApiCtx); FREE(handelsvalue); return 0; }
/*------------------------------------------------------------------------*/ void* get_position_property(void* _pvCtx, int iObjUID) { int iType = -1; int* piType = &iType; double* position = NULL; void* ret = NULL; getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **) &piType); if (piType == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "type"); return NULL; } /* Special figure case */ if (iType == __GO_FIGURE__) { int* figurePosition; int* figureSize; double position[4]; getGraphicObjectProperty(iObjUID, __GO_POSITION__, jni_int_vector, (void **) &figurePosition); getGraphicObjectProperty(iObjUID, __GO_AXES_SIZE__, jni_int_vector, (void **) &figureSize); if (figurePosition == NULL || figureSize == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "position"); return NULL; } position[0] = (double) figurePosition[0]; position[1] = (double) figurePosition[1]; position[2] = (double) figureSize[0]; position[3] = (double) figureSize[1]; ret = sciReturnRowVector(position, 4); releaseGraphicObjectProperty(__GO_POSITION__, figurePosition, jni_int_vector, 2); releaseGraphicObjectProperty(__GO_AXES_SIZE__, figureSize, jni_int_vector, 2); return ret; } /* Special label and legend case : only 2 values for position */ if (iType == __GO_LABEL__ || iType == __GO_LEGEND__) { double* position; getGraphicObjectProperty(iObjUID, __GO_POSITION__, jni_double_vector, (void **) &position); if (position == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "position"); return NULL; } ret = sciReturnRowVector(position, 2); releaseGraphicObjectProperty(__GO_POSITION__, position, jni_double_vector, 2); return ret; } if (iType == __GO_LIGHT__) { double* position = NULL; getGraphicObjectProperty(iObjUID, __GO_POSITION__, jni_double_vector, (void **)&position); if (position == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "position"); return NULL; } ret = sciReturnRowVector(position, 3); releaseGraphicObjectProperty(__GO_POSITION__, position, jni_double_vector, 3); return ret; } /* Generic case : position is a 4 row vector */ getGraphicObjectProperty(iObjUID, __GO_POSITION__, jni_double_vector, (void **) &position); if (position == NULL) { Scierror(999, _("'%s' property does not exist for this handle.\n"), "position"); return NULL; } ret = sciReturnRowVector(position, 4); releaseGraphicObjectProperty(__GO_POSITION__, position, jni_double_vector, 4); return ret; }
void champg(char *name, int colored, double *x, double *y, double *fx, double *fy, int *n1, int *n2, char *strflag, double *brect, double *arfact, int lstr) { int iSubwinUID = 0; int iNewSegsUID = 0; int clipState = 0; char textLogFlags[3]; double xx[2]; double yy[2]; double* boundingBox = NULL; double rotationAngles[2]; int nn1 = 1; int nn2 = 2; int autoScale = 0; int* piAutoScale = &autoScale; int firstPlot = 0; int* piFirstPlot = &firstPlot; int logFlags[3]; int flag, type = 1; double arsize1 = 0.; int *style = NULL; int iTmp = 0; int* piTmp = &iTmp; int i = 0; double drect[6]; BOOL bounds_changed = FALSE; BOOL axes_properties_changed = FALSE; /* champ with color inherited from subwin */ /* or champ1 (normed vector + color) is enabled */ int typeofchamp = (colored == 0 ? 0 : 1); /* First create champ object */ /* F.Leray Allocation de style[dim = Nbr1] */ if ((style = (int*)MALLOC ((*n1) * sizeof (int))) == NULL) { Scierror(999, _("%s: No more memory.\n"), "champg"); return; } flag = 1; /* je le mets � 1 pour voir F.Leray 19.02.04*/ arsize1 = *arfact; iSubwinUID = getCurrentSubWin(); /* then modify subwindow if needed */ checkRedrawing(); /* Force clipping to CLIPGRF (1) */ clipState = 1; setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); for (i = 0; i < (*n1); i++) { style[i] = i; } iNewSegsUID = createChamp(iSubwinUID, x, *n1, y, *n2, fx, *n1 * *n2, fy, *n1 * *n2, arsize1, typeofchamp != 0); if (iNewSegsUID == 0) { Scierror(999, _("%s: No more memory.\n"), "champg"); if (style != NULL) { FREE(style); } return; } setCurrentObject(iNewSegsUID); if (style != NULL) { FREE(style); style = NULL; } /* Get segs bounding box */ getGraphicObjectProperty(iNewSegsUID, __GO_BOUNDING_BOX__, jni_double_vector, (void **)&boundingBox); if (!boundingBox) { Scierror(999, _("%s: Could not retrive bounding box.\n"), "champg"); return; } xx[0] = boundingBox[0]; xx[1] = boundingBox[1]; yy[0] = boundingBox[2]; yy[1] = boundingBox[3]; releaseGraphicObjectProperty(__GO_BOUNDING_BOX__, boundingBox, jni_double_vector, 4); rotationAngles[0] = 0.0; rotationAngles[1] = 270.0; setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2); getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piAutoScale); getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piFirstPlot); if (autoScale) { /* compute and merge new specified bounds with the data bounds */ switch (strflag[1]) { case '0': /* do not change data bounds */ break; case '1' : case '3' : case '5' : case '7': /* Force data bounds=brect */ re_index_brect(brect, drect); break; case '2' : case '4' : case '6' : case '8': case '9': getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[0] = iTmp; getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[1] = iTmp; getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[2] = iTmp; /* Conversion required by compute_data_bounds2 */ textLogFlags[0] = getTextLogFlag(logFlags[0]); textLogFlags[1] = getTextLogFlag(logFlags[1]); textLogFlags[2] = getTextLogFlag(logFlags[2]); /* Force data bounds to the x and y bounds */ compute_data_bounds2(0, 'g', textLogFlags, xx, yy, nn1, nn2, drect); break; } /* merge data bounds and drect */ if (!firstPlot && (strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9')) { double* dataBounds; getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds); drect[0] = Min(dataBounds[0], drect[0]); /*xmin*/ drect[2] = Min(dataBounds[2], drect[2]); /*ymin*/ drect[1] = Max(dataBounds[1], drect[1]); /*xmax*/ drect[3] = Max(dataBounds[3], drect[3]); /*ymax*/ } if (strflag[1] != '0') { bounds_changed = update_specification_bounds(iSubwinUID, drect, 2); } } if (firstPlot) { bounds_changed = TRUE; } axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag); /* just after strflag2axes_properties */ firstPlot = 0; setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1); }
/*--------------------------------------------------------------------------*/ 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 MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int bufferLength) { // Indexed colors void * data = NULL; char * parentFigure = NULL; double * colormap = NULL; int colormapSize = 0; int * piColormapSize = &colormapSize; int datatype = -1; int * pidataType = &datatype; const int h = getTextureHeight(id); const int w = getTextureWidth(id); getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, &data); getGraphicObjectProperty(id, __GO_DATA_MODEL_MATPLOT_DATA_TYPE__, jni_int, (void**) &pidataType); getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure); getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); switch ((DataType)datatype) { case MATPLOT_HM1_Char : case MATPLOT_Char : { char * index = (char *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_HM1_UChar : case MATPLOT_UChar : { unsigned char * index = (unsigned char *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_Int : { int * index = (int *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_UInt : { unsigned int * index = (unsigned int *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_Short : { short * index = (short *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_UShort : { unsigned short * index = (unsigned short *)data; for (int i = 0 ; i < w * h; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } case MATPLOT_HM1_Double : case MATPLOT_Double : { double * index = (double *)data; for (int i = 0 ; i < w * h ; i++) { ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false); } break; } } releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); return bufferLength; }
/*--------------------------------------------------------------------------*/ int sci_xfarcs(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddr2 = NULL; int* l2 = NULL; int m1 = 0, n1 = 0; int m2 = 0, n2 = 0; long hdl = 0; int i = 0; double angle1 = 0.0; double angle2 = 0.0; CheckInputArgument(pvApiCtx, 1, 2); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 1. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl1, &m1, &n1, &l1); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 1); return 1; } if (m1 != 6) { Scierror(999, _("%s: Wrong size for input argument #%d: %s expected.\n"), fname, 1, "(6,n)"); return 0; } if (nbInputArgument(pvApiCtx) == 2) { sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 2. sciErr = getMatrixOfDoubleAsInteger(pvApiCtx, piAddr2, &m2, &n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2); return 1; } //CheckVector if (m2 != 1 && n2 != 1) { Scierror(999, _("%s: Wrong size for input argument #%d: Vector expected.\n"), fname, 2); return 1; } if (n1 != m2 * n2) { Scierror(999, _("%s: Wrong size for input arguments #%d and #%d.\n"), fname, 1, 2); return 0; } } else { m2 = 1; n2 = n1; sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, 2, m2, n2, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } for (i = 0; i < n2; ++i) { *((int*)(l2 + i)) = i + 1; } } getOrCreateDefaultSubwin(); for (i = 0; i < n1; ++i) { angle1 = DEG2RAD(*(l1 + (6 * i) + 4) / 64.0); angle2 = DEG2RAD(*(l1 + (6 * i) + 5) / 64.0); Objarc(&angle1, &angle2, (l1 + (6 * i)), (l1 + (6 * i) + 1), (l1 + (6 * i) + 2), (l1 + (6 * i) + 3), (int*)(l2 + i), (int*)(l2 + i), TRUE, FALSE, &hdl); } /** Construct Compound and make it current object **/ { char * o = ConstructCompoundSeq(n1); setCurrentObject(o); releaseGraphicObjectProperty(__GO_PARENT__, o, jni_string, 1); } AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }
void MeshFecDataDecomposer::fillColors(int id, float* buffer, int bufferLength, int elementsSize) { int parent = 0; int parentFigure = 0; int * piParentFigure = &parentFigure; double* values = NULL; double* zBounds = NULL; double* colormap = NULL; double minValue = 0.; double maxValue = 0.; double valueRange = 0.; float minColor[3]; float maxColor[3]; int colormapSize = 0; int* piColormapSize = &colormapSize; int numVertices = 0; int* piNumVertices = &numVertices; int minColorIndex = 0; int maxColorIndex = 0; int* colorRange = NULL; int useOutsideColors = 0; int bufferOffset = 0; parent = getParentObject(id); /* Temporary: to avoid getting a null parent_figure property when the object is built */ if (parent == 0) { return; } getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_int, (void**) &piParentFigure); getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap); getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize); getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, (void**) &piNumVertices); getGraphicObjectProperty(id, __GO_DATA_MODEL_VALUES__, jni_double_vector, (void**) &values); getGraphicObjectProperty(id, __GO_Z_BOUNDS__, jni_double_vector, (void**) &zBounds); getGraphicObjectProperty(id, __GO_COLOR_RANGE__, jni_int_vector, (void**) &colorRange); if (colorRange[0] != 0 || colorRange[1] != 0) { /* To do: use a scilab index to colormap index conversion function */ minColorIndex = colorRange[0] - 1; maxColorIndex = colorRange[1] - 1; if (minColorIndex < 0) { minColorIndex = 0; } if (maxColorIndex < 0) { maxColorIndex = 0; } if (maxColorIndex > colormapSize - 1) { maxColorIndex = colormapSize - 1; } if (minColorIndex > colormapSize - 1) { minColorIndex = colormapSize - 1; } } else { minColorIndex = 0; maxColorIndex = colormapSize - 1; } releaseGraphicObjectProperty(__GO_COLOR_RANGE__, colorRange, jni_int_vector, 0); computeMinMaxValues(values, numVertices, &minValue, &maxValue); /* Z-bounds are not taken into account if either of them is invalid */ if ((zBounds[0] != 0.0 || zBounds[1] != 0.0) && (DecompositionUtils::isValid(zBounds[0]) && DecompositionUtils::isValid(zBounds[1])) && (zBounds[0] != zBounds[1])) { int* outsideColors; minValue = zBounds[0]; maxValue = zBounds[1]; getGraphicObjectProperty(id, __GO_OUTSIDE_COLOR__, jni_int_vector, (void**) &outsideColors); if (outsideColors[0] != 0 || outsideColors[1] != 0) { useOutsideColors = 1; ColorComputer::getDirectColor((double) outsideColors[0] - 1.0, colormap, colormapSize, minColor); ColorComputer::getDirectColor((double) outsideColors[1] - 1.0, colormap, colormapSize, maxColor); } } releaseGraphicObjectProperty(__GO_Z_BOUNDS__, zBounds, jni_double_vector, 0); /* To be verified (when reverse z bounds are specified) */ if (DecompositionUtils::getAbsoluteValue(maxValue - minValue) < DecompositionUtils::getMinDoubleValue()) { valueRange = 1.0; } else { valueRange = maxValue - minValue; } for (int i = 0; i < numVertices; i++) { bufferOffset = elementsSize * i; if (useOutsideColors == 1) { if (values[i] < minValue) { buffer[bufferOffset] = minColor[0]; buffer[bufferOffset + 1] = minColor[1]; buffer[bufferOffset + 2] = minColor[2]; } else if (values[i] > maxValue) { buffer[bufferOffset] = maxColor[0]; buffer[bufferOffset + 1] = maxColor[1]; buffer[bufferOffset + 2] = maxColor[2]; } else { /* To do: replace 0.5 by a macro-definition */ ColorComputer::getColor(values[i], minValue, valueRange, 0.5, colormap, minColorIndex, maxColorIndex, colormapSize, &buffer[bufferOffset]); } } else { /* To do: replace 0.5 by a macro-definition */ ColorComputer::getColor(values[i], minValue, valueRange, 0.5, colormap, minColorIndex, maxColorIndex, colormapSize, &buffer[bufferOffset]); } if (elementsSize == 4) { buffer[bufferOffset + 3] = 1.0; } } releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize); }
/*--------------------------------------------------------------------------*/ 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; }
static char *getPolyline(char *pAxeUID, scicos_block * block, int row) { char *pPolyline; static double d__0 = 0.0; static BOOL b__true = TRUE; int color; int markSize; double lineThickness; sco_data *sco = (sco_data *) * (block->work); // assert the sco is not NULL if (sco == NULL) { return NULL; } // fast path for an existing object if (sco->scope.cachedPolylinesUIDs != NULL && sco->scope.cachedPolylinesUIDs[row] != NULL) { return sco->scope.cachedPolylinesUIDs[row]; } pPolyline = findChildWithKindAt(pAxeUID, __GO_POLYLINE__, row); /* * Allocate if necessary */ if (pPolyline == NULL) { pPolyline = createGraphicObject(__GO_POLYLINE__); if (pPolyline != NULL) { createDataObject(pPolyline, __GO_POLYLINE__); setGraphicObjectRelationship(pAxeUID, pPolyline); } } /* * Setup on first access */ if (pPolyline != NULL) { /* * Default setup of the nGons property */ { int nGons = 1; setGraphicObjectProperty(pPolyline, __GO_DATA_MODEL_NUM_GONS__, &nGons, jni_int, 1); } color = block->ipar[3 + row]; markSize = block->ipar[3 + block->ipar[1] + row]; lineThickness = (double)markSize; if (color > 0) { setGraphicObjectProperty(pPolyline, __GO_LINE_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(pPolyline, __GO_LINE_COLOR__, &color, jni_int, 1); setGraphicObjectProperty(pPolyline, __GO_LINE_THICKNESS__, &lineThickness, jni_double, 1); } else { color = -color; setGraphicObjectProperty(pPolyline, __GO_MARK_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(pPolyline, __GO_MARK_STYLE__, &color, jni_int, 1); setGraphicObjectProperty(pPolyline, __GO_MARK_SIZE__, &markSize, jni_int, 1); } { int iClipState = 1; //on setGraphicObjectProperty(pPolyline, __GO_CLIP_STATE__, &iClipState, jni_int, 1); } } /* * then cache with a local storage */ if (pPolyline != NULL && sco->scope.cachedPolylinesUIDs != NULL && sco->scope.cachedPolylinesUIDs[row] == NULL) { sco->scope.cachedPolylinesUIDs[row] = strdup(pPolyline); releaseGraphicObjectProperty(__GO_PARENT__, pPolyline, jni_string, 1); } return sco->scope.cachedPolylinesUIDs[row]; }
/*--------------------------------------------------------------------------*/ int sci_xstring(char *fname, unsigned long fname_len) { SciErr sciErr; int* piAddrStr = NULL; int* piAddrl1 = NULL; double* l1 = NULL; int* piAddrl2 = NULL; double* l2 = NULL; int* piAddrl4 = NULL; double* l4 = NULL; int* piAddrl5 = NULL; double* l5 = NULL; double rect[4]; double x = 0., y = 0., angle = 0.0; int m1 = 0, n1 = 0, m2 = 0, n2 = 0, m3 = 0, n3 = 0, m4 = 0, n4 = 0, m5 = 0, n5 = 0; char **Str = NULL; char **sendStr = NULL; int sendm3 = 0, sendn3 = 0; long hdlstr = 0; int nbElement = 0, i = 0; BOOL isboxed = FALSE; CheckInputArgument(pvApiCtx, 3, 5); sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddrStr); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of string at position 3. if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m3, &n3, &Str)) { Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 3); return 1; } if (m3 * n3 == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } 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; } if (m1 * n1 == 1 || m2 * n2 == 1) { nbElement = m1 * n1 * m2 * n2; } else if (m1 * n1 == m2 * n2) { nbElement = m1 * n1; } else { Scierror(999, _("%s: Incompatible input arguments #%d and #%d: Same element number expected.\n"), fname, 1, 2); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbElement == 0) { AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } if (nbInputArgument(pvApiCtx) >= 4) { sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddrl4); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 4. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl4, &m4, &n4, &l4); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 4); return 1; } if (m4 * n4 != 1 && m4 * n4 != nbElement) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 4, 1, nbElement); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } } if (nbInputArgument(pvApiCtx) >= 5) { sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddrl5); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of double at position 5. sciErr = getMatrixOfDouble(pvApiCtx, piAddrl5, &m5, &n5, &l5); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 5); return 1; } if (m5 * n5 != 1 && m5 * n5 != nbElement) { Scierror(999, _("%s: Wrong size for input argument #%d: %d or %d elements expected.\n"), fname, 5, 1, nbElement); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; } } x = *l1; y = *l2; sendStr = Str; sendm3 = m3; sendn3 = n3; if (nbInputArgument(pvApiCtx) >= 4) { angle = DEG2RAD(*l4); } if (nbInputArgument(pvApiCtx) >= 5) { isboxed = (*l5 != 0); } getOrCreateDefaultSubwin(); if (nbElement == 1) { Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed && (angle == 0), TRUE, FALSE, ALIGN_LEFT); } else { for (i = 0; i < nbElement; i++) { if (m1 * n1 == nbElement) { x = *((l1) + i); } if (m2 * n2 == nbElement) { y = *((l2) + i); } if (m3 * n3 == nbElement) { sendStr = Str + i; sendm3 = sendn3 = 1; } if (nbInputArgument(pvApiCtx) >= 4 && m4 * n4 == nbElement) { angle = DEG2RAD(*((l4) + i)); } if (nbInputArgument(pvApiCtx) >= 5 && m5 * n5 == nbElement) { isboxed = ((l5) != 0); } Objstring(sendStr, sendm3, sendn3, x, y, &angle, rect, TRUE, NULL, &hdlstr, 0, NULL, NULL, isboxed && (angle == 0), TRUE, FALSE, ALIGN_LEFT); } /* * If one of the string creation calls fails, * the compound build call will crash. * To be modified */ { char * o = ConstructCompoundSeq(nbElement); releaseGraphicObjectProperty(__GO_PARENT__, o, jni_string, 1); } } /* we must free Str memory */ freeArrayOfString(Str, m3 * n3); AssignOutputVariable(pvApiCtx, 1) = 0; ReturnArguments(pvApiCtx); return 0; }