static BOOL pushData(scicos_block * block, int input, int row) { char const* pFigureUID; char *pAxeUID; char *pPolylineUID; double *data; sco_data *sco; BOOL result = TRUE; pFigureUID = getFigure(block); pAxeUID = getAxe(pFigureUID, block, input); pPolylineUID = getPolyline(pAxeUID, block, input, row); sco = getScoData(block); if (sco == NULL) return FALSE; // select the right input and row data = sco->internal.data[input][row]; result &= setGraphicObjectProperty(pPolylineUID, __GO_DATA_MODEL_X__, sco->internal.time[input], jni_double_vector, sco->internal.maxNumberOfPoints[input]); result &= setGraphicObjectProperty(pPolylineUID, __GO_DATA_MODEL_Y__, data, jni_double_vector, sco->internal.maxNumberOfPoints[input]); return result; }
/** \fn void cmscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void canimxy3d(scicos_block * block, scicos_flag flag) { char const* pFigureUID; sco_data *sco; int j; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); break; } pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } break; case StateUpdate: pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } appendData(block, block->inptr[0], block->inptr[1], block->inptr[2]); for (j = 0; j < block->insz[0]; j++) { result = pushData(block, j); if (result == FALSE) { Coserror("%s: unable to push some data.", "cscopxy3d"); break; } } break; case Ending: freeScoData(block); break; default: break; } }
/** \fn void cmscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cscopxy3d(scicos_block * block, scicos_flag flag) { int iFigureUID; sco_data *sco; int j; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); } iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); } break; case StateUpdate: iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } appendData(block, GetRealInPortPtrs(block, 1), GetRealInPortPtrs(block, 2), GetRealInPortPtrs(block, 3)); for (j = 0; j < block->insz[0]; j++) { result = pushData(block, j); if (result == FALSE) { Coserror("%s: unable to push some data.", "cscopxy3d"); break; } } break; case Ending: freeScoData(block); break; default: break; } }
/** \fn void cmatview(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cmatview(scicos_block * block, scicos_flag flag) { char const* pFigureUID; double *u; sco_data *sco; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); break; } pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } break; case StateUpdate: pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } u = GetRealInPortPtrs(block, 1); result = pushData(block, u); if (result == FALSE) { Coserror("%s: unable to push some data.", "cmatview"); break; } break; case Ending: freeScoData(block); break; default: break; } }
static int getAxe(int iFigureUID, scicos_block * block) { int iAxe; int i; int nclk = block->nipar - 6; sco_data *sco = getScoData(block); // assert the sco is not NULL if (sco == NULL) { return 0; } // fast path for an existing object if (sco->scope.cachedAxeUID) { return sco->scope.cachedAxeUID; } iAxe = findChildWithKindAt(iFigureUID, __GO_AXES__, 0); /* * Allocate if necessary */ if (iAxe == 0) { cloneAxesModel(iFigureUID); iAxe = findChildWithKindAt(iFigureUID, __GO_AXES__, 0); } /* * Setup on first access */ if (iAxe != 0) { // allocate the segs through the getter for (i = 0; i < nclk; i++) { getSegs(iAxe, block, i); } } else { return 0; } /* * then cache with a local storage */ sco->scope.cachedAxeUID = iAxe; return sco->scope.cachedAxeUID; }
static sco_data *reallocScoData(scicos_block * block, int input, int numberOfPoints) { sco_data *sco = getScoData(block); double *ptr; int setLen; int previousNumberOfPoints = sco->internal.maxNumberOfPoints[input]; /* * Realloc base pointer */ ptr = (double *)REALLOC(sco->internal.data[2 * input], 3 * numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[3 * (previousNumberOfPoints + setLen) + 0] = ptr[3 * (previousNumberOfPoints - 1) + 0]; ptr[3 * (previousNumberOfPoints + setLen) + 1] = ptr[3 * (previousNumberOfPoints - 1) + 1]; ptr[3 * (previousNumberOfPoints + setLen) + 2] = ptr[3 * (previousNumberOfPoints - 1) + 2]; } sco->internal.data[2 * input] = ptr; /* * Realloc direction pointer */ ptr = (double *)REALLOC(sco->internal.data[2 * input + 1], 3 * numberOfPoints * sizeof(double)); if (ptr == NULL) { goto error_handler; } for (setLen = numberOfPoints - previousNumberOfPoints - 1; setLen >= 0; setLen--) { ptr[3 * (previousNumberOfPoints + setLen) + 0] = ptr[3 * (previousNumberOfPoints - 1) + 0]; ptr[3 * (previousNumberOfPoints + setLen) + 1] = ptr[3 * (previousNumberOfPoints - 1) + 1]; ptr[3 * (previousNumberOfPoints + setLen) + 2] = ptr[3 * (previousNumberOfPoints - 1) + 2]; } sco->internal.data[2 * input + 1] = ptr; sco->internal.maxNumberOfPoints[input] = numberOfPoints; return sco; error_handler: freeScoData(block); // allocation error set_block_error(-5); return NULL; }
static void freeScoData(scicos_block * block) { sco_data *sco = getScoData(block); int i; int nclk = block->nipar - 6; if (sco != NULL) { for (i = 0; i < nclk; i++) { FREE(sco->internal.data[i]); } FREE(sco->internal.data); FREE(sco->internal.maxNumberOfPoints); FREE(sco->internal.numberOfPoints); FREE(sco->scope.cachedSegsUIDs); FREE(sco); *(block->work) = NULL; } }
static BOOL pushData(scicos_block * block, int input) { int iFigureUID; int iAxeUID; int iSegsUID; int dataLen; double *base; double *direction; sco_data *sco; BOOL result; iFigureUID = getFigure(block); iAxeUID = getAxe(iFigureUID, block); iSegsUID = getSegs(iAxeUID, block, input); sco = getScoData(block); if (sco == NULL) { return FALSE; } // select the right input and row base = sco->internal.data[2 * input]; direction = sco->internal.data[2 * input + 1]; dataLen = 3 * sco->internal.maxNumberOfPoints[input]; result = setGraphicObjectProperty(iSegsUID, __GO_BASE__, base, jni_double_vector, dataLen); if (result == FALSE) { return result; } result = setGraphicObjectProperty(iSegsUID, __GO_DIRECTION__, direction, jni_double_vector, dataLen); return result; }
static BOOL pushData(scicos_block * block, int row) { char const* pFigureUID; char *pAxeUID; char *pPolylineUID; double *coordinates; sco_data *sco; pFigureUID = getFigure(block); pAxeUID = getAxe(pFigureUID, block); pPolylineUID = getPolyline(pAxeUID, block, row); sco = getScoData(block); if (sco == NULL) { return FALSE; } // select the right input and row coordinates = sco->internal.coordinates[row]; return setGraphicObjectProperty(pPolylineUID, __GO_DATA_MODEL_COORDINATES__, coordinates, jni_double_vector, sco->internal.maxNumberOfPoints); }
static int getSegs(int iAxeUID, scicos_block * block, int input) { int iSegs; BOOL b__true = TRUE; double d__1 = 1.0; double d__0 = 0.0; int color; sco_data *sco = getScoData(block); // assert the sco is not NULL if (sco == NULL || sco->scope.cachedSegsUIDs == NULL) { return 0; } // fast path for an existing object if (sco->scope.cachedSegsUIDs[input]) { return sco->scope.cachedSegsUIDs[input]; } iSegs = findChildWithKindAt(iAxeUID, __GO_SEGS__, input); /* * Allocate if necessary */ if (iSegs == 0) { iSegs = createGraphicObject(__GO_SEGS__); if (iSegs != 0) { createDataObject(iSegs, __GO_SEGS__); setGraphicObjectRelationship(iAxeUID, iSegs); } else { return 0; } } /* * Setup on first access */ setGraphicObjectProperty(iSegs, __GO_NUMBER_ARROWS__, &sco->internal.maxNumberOfPoints[input], jni_int, 1); // Setup properties setGraphicObjectProperty(iSegs, __GO_LINE_THICKNESS__, &d__1, jni_double, 1); setGraphicObjectProperty(iSegs, __GO_ARROW_SIZE__, &d__0, jni_double, 1); color = block->ipar[2 + input]; if (color > 0) { setGraphicObjectProperty(iSegs, __GO_LINE_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(iSegs, __GO_SEGS_COLORS__, &color, jni_int_vector, 1); } else { int iMarkSize = 4; color = -color; setGraphicObjectProperty(iSegs, __GO_MARK_MODE__, &b__true, jni_bool, 1); setGraphicObjectProperty(iSegs, __GO_MARK_STYLE__, &color, jni_int, 1); setGraphicObjectProperty(iSegs, __GO_MARK_SIZE__, &iMarkSize, jni_int, 1); } { int iClipState = 1; //on setGraphicObjectProperty(iSegs, __GO_CLIP_STATE__, &iClipState, jni_int, 1); } /* * then cache with a local storage */ sco->scope.cachedSegsUIDs[input] = iSegs; return sco->scope.cachedSegsUIDs[input]; }
static int getFigure(scicos_block * block) { signed int figNum; int iFigureUID = 0; int iAxe = 0; int i__1 = 1; sco_data *sco = getScoData(block); // assert the sco is not NULL if (sco == NULL) { return 0; } // fast path for an existing object if (sco->scope.cachedFigureUID) { return sco->scope.cachedFigureUID; } figNum = block->ipar[0]; // with a negative id, use the block number indexed from a constant. if (figNum < 0) { figNum = 20000 + get_block_number(); } iFigureUID = getFigureFromIndex(figNum); // create on demand if (iFigureUID == 0) { iFigureUID = createNewFigureWithAxes(); setGraphicObjectProperty(iFigureUID, __GO_ID__, &figNum, jni_int, 1); // the stored uid is a reference to the figure map, not to the current figure iFigureUID = getFigureFromIndex(figNum); sco->scope.cachedFigureUID = iFigureUID; // set configured parameters setFigureSettings(iFigureUID, block); // allocate the axes through the getter iAxe = getAxe(iFigureUID, block); /* * Setup according to block settings */ setLabel(iAxe, __GO_X_AXIS_LABEL__, "t"); setLabel(iAxe, __GO_Y_AXIS_LABEL__, "y"); setGraphicObjectProperty(iAxe, __GO_X_AXIS_VISIBLE__, &i__1, jni_bool, 1); setGraphicObjectProperty(iAxe, __GO_Y_AXIS_VISIBLE__, &i__1, jni_bool, 1); setBounds(block, iAxe, 0); } if (sco->scope.cachedFigureUID == 0) { sco->scope.cachedFigureUID = iFigureUID; } return iFigureUID; }
static void appendData(scicos_block * block, int input, double t) { sco_data *sco = getScoData(block); int maxNumberOfPoints = sco->internal.maxNumberOfPoints[input]; int numberOfPoints = sco->internal.numberOfPoints[input]; int i; int nclk = block->nipar - 6; /* * Handle the case where the t is greater than the data_bounds */ if (t > ((sco->scope.periodCounter + 1) * block->rpar[0])) { sco->scope.periodCounter++; // reset the number of points for all the segs numberOfPoints = 0; for (i = 0; i < nclk; i++) { sco->internal.numberOfPoints[i] = 0; } if (setBounds(block, getAxe(getFigure(block), block), sco->scope.periodCounter) == FALSE) { set_block_error(-5); freeScoData(block); sco = NULL; } } /* * Handle the case where the scope has more points than maxNumberOfPoints */ if (sco != NULL && numberOfPoints >= maxNumberOfPoints) { // on a full scope, re-alloc maxNumberOfPoints = maxNumberOfPoints + DEFAULT_MAX_NUMBER_OF_POINTS; sco = reallocScoData(block, input, maxNumberOfPoints); // reconfigure related graphic objects if (setSegsBuffers(block, maxNumberOfPoints) == FALSE) { set_block_error(-5); freeScoData(block); sco = NULL; } } /* * Update data */ if (sco != NULL) { int setLen; /* * Base pointer */ for (setLen = maxNumberOfPoints - numberOfPoints - 1; setLen >= 0; setLen--) { sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 0] = t; // x sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 1] = 0; // y sco->internal.data[2 * input + 0][3 * (numberOfPoints + setLen) + 2] = (double) input; // z } /* * Direction pointer */ for (setLen = maxNumberOfPoints - numberOfPoints - 1; setLen >= 0; setLen--) { sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 0] = t; // x sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 1] = 0.8; // y sco->internal.data[2 * input + 1][3 * (numberOfPoints + setLen) + 2] = (double) input; // z } sco->internal.numberOfPoints[input]++; } }
/** \fn void cscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cevscpe(scicos_block * block, scicos_flag flag) { int iFigureUID; double t; int i; int mask; int nclk = block->nipar - 6; sco_data *sco; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); } iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } setSegsBuffers(block, DEFAULT_MAX_NUMBER_OF_POINTS); break; case StateUpdate: iFigureUID = getFigure(block); if (iFigureUID == 0) { // allocation error set_block_error(-5); break; } t = get_scicos_time(); // select only the masked indexes for (i = 0; i < nclk; i++) { mask = 1 << i; if ((block->nevprt & mask) == mask) { appendData(block, i, t); result = pushData(block, i); if (result == FALSE) { Coserror("%s: unable to push some data.", "cevscpe"); break; } } } break; case Ending: freeScoData(block); break; default: break; } }
/** \fn void cmscope(scicos_block * block,int flag) \brief the computational function \param block A pointer to a scicos_block \param flag An int which indicates the state of the block (init, update, ending) */ SCICOS_BLOCKS_IMPEXP void cmscope(scicos_block * block, scicos_flag flag) { char const* pFigureUID; double t; double *u; sco_data *sco; int i, j; BOOL result; switch (flag) { case Initialization: sco = getScoData(block); if (sco == NULL) { set_block_error(-5); break; } pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } break; case StateUpdate: pFigureUID = getFigure(block); if (pFigureUID == NULL) { // allocation error set_block_error(-5); break; } t = get_scicos_time(); for (i = 0; i < block->nin; i++) { u = (double *)block->inptr[i]; appendData(block, i, t, u); for (j = 0; j < block->insz[i]; j++) { result = pushData(block, i, j); if (result == FALSE) { Coserror("%s: unable to push some data.", "cmscope"); break; } } } break; case Ending: freeScoData(block); break; default: break; } }