Scicos blocks: use the new MVC graphic for scopes
[scilab.git] / scilab / modules / scicos_blocks / src / c / canimxy.c
index c15ee2b..664afc9 100755 (executable)
-/*  Scicos
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2011 - Scilab Enterprises - ClĂ©ment DAVID
  *
- *  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
+ *  This file must be used under the terms of the CeCILL.
+ *  This source file is licensed as described in the file COPYING, which
+ *  you should have received as part of this distribution.  The terms
+ *  are also available at
+ *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ */
+
+#include "dynlib_scicos_blocks.h"
+#include "scoUtils.h"
+
+#include "MALLOC.h"
+#include "elementary_functions.h"
+
+#include "getGraphicObjectProperty.h"
+#include "setGraphicObjectProperty.h"
+#include "graphicObjectProperties.h"
+#include "createGraphicObject.h"
+
+#include "CurrentFigure.h"
+
+#include "scicos_block4.h"
+#include "scicos.h"
+
+#include "localization.h"
+
+#include "FigureList.h"
+#include "BuildObjects.h"
+#include "AxesModel.h"
+
+#include <string.h>
+
+/*****************************************************************************
+ * Internal container structure
+ ****************************************************************************/
+
+/**
+ * Container structure
+ */
+typedef struct
+{
+    struct
+    {
+        int numberOfPoints;
+        int maxNumberOfPoints;
+        double ***data;
+    } internal;
+
+    struct
+    {
+        char *cachedFigureUID;
+        char *cachedAxeUID;
+        char **cachedPolylinesUIDs;
+    } scope;
+} sco_data;
+
+/**
+ * Get (and allocate on demand) the internal data used on this scope
+ * \param block the block
+ * \return the scope data
+ */
+static sco_data *getScoData(scicos_block * block);
+
+/**
+ * Release any internal data
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * \param block the block
+ */
+static void freeScoData(scicos_block * block);
+
+/**
+ * Append the data to the current data
+ *
+ * \param block the block
+ * \param x x data
+ * \param y y data
+ */
+static void appendData(scicos_block * block, double *x, double *y);
+
+/**
+ * Push the block data to the polyline
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * \param block the block
+ * \param row the selected row
  *
- * See the file ./license.txt
  */
-/*--------------------------------------------------------------------------*/
+static BOOL pushData(scicos_block * block, int row);
+
+/*****************************************************************************
+ * Graphics utils
+ ****************************************************************************/
+
 /**
-   \file canimxy.c
-   \author Benoit Bayol
-   \version 1.0
-   \date September 2006 - January 2007
-   \brief CANIMXY is a scope in 2D which draw its input as a XY scope, there is animation.
-   \see CANIMXY.sci in macros/scicos_blocks/Sinks/
-*/
-/*--------------------------------------------------------------------------*/
-#include "scoMemoryScope.h"
-#include "scoWindowScope.h"
-#include "scoMisc.h"
-#include "scoGetProperty.h"
-#include "scoSetProperty.h"
-#include "scicos_block4.h"
-#include "DrawingBridge.h"
-#include "MALLOC.h"
-#include "dynlib_scicos_blocks.h"
-/*--------------------------------------------------------------------------*/
-/** \fn canimxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
-    \brief Function to draw or redraw the window
+ * Get (and allocate on demand) the figure associated with the block
+ * \param block the block
+ * \return a valid figure UID or NULL on error
+ */
+static char *getFigure(scicos_block * block);
+
+/**
+ * Get (and allocate on demand) the axe associated with the input
+ *
+ * \param pFigureUID the parent figure UID
+ * \param block the block
+ * \param input the current input index (0-indexed)
+ * \return a valid axe UID or NULL on error
+ */
+static char *getAxe(char *pFigureUID, scicos_block * block);
+
+/**
+ * Get (and allocate on demand) the polyline associated with the row
+ *
+ * \param pAxeUID the parent axe UID
+ * \param block the block
+ * \param row the current row index (0-indexed)
+ * \return a valid polyline UID or NULL on error
+ */
+static char *getPolyline(char *pAxeUID, scicos_block * block, int row);
+
+/**
+ * Set the polylines bounds
+ *
+ * \param block the block
+ */
+static BOOL setPolylinesBounds(scicos_block * block);
+
+/*****************************************************************************
+ * Simulation function
+ ****************************************************************************/
+
+/** \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 canimxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
+SCICOS_BLOCKS_IMPEXP void canimxy(scicos_block * block, scicos_flag flag)
+{
+    char *pFigureUID;
+    sco_data *sco;
+
+    int j;
+    BOOL result;
+
+    switch (flag)
+    {
+
+    case Initialization:
+        sco = getScoData(block);
+        if (sco == NULL)
+        {
+            set_block_error(-5);
+        }
+        pFigureUID = getFigure(block);
+        if (pFigureUID == NULL)
+        {
+            // allocation error
+            set_block_error(-5);
+        }
+        break;
+
+    case StateUpdate:
+        pFigureUID = getFigure(block);
+
+        appendData(block, (double *)block->inptr[0], (double *)block->inptr[1]);
+        for (j = 0; j < block->insz[0]; j++)
+        {
+            result = pushData(block, j);
+            if (result == FALSE)
+            {
+                Coserror("%s: unable to push some data.", "cscopxy");
+                break;
+            }
+        }
+        break;
+
+    case Ending:
+        freeScoData(block);
+        break;
+
+    default:
+        break;
+    }
+}
+
+/*-------------------------------------------------------------------------*/
+
+/*****************************************************************************
+ *
+ * Container management
+ *
+ ****************************************************************************/
+
+static sco_data *getScoData(scicos_block * block)
 {
-  /* Declarations*/
-  int i = 0;
-  int gomme_color = 0; //As usual
-  int * ipar = NULL; //Integer Parameters
-  int color_flag = 0; //Flag on Color
-  int color[2];
-  int line_size = 0;
-  int animed = 0;
-  int win = 0; //Windows ID : To give a name to the window
-  int buffer_size = 0; //Buffer Size
-  int win_pos[2]; //Position of the Window
-  int win_dim[2]; //Dimension of the Window
-  int nipar = 0;
-  double * rpar = NULL; //Reals parameters
-  double xmin = 0., xmax = 0., ymin = 0., ymax = 0.; //Ymin and Ymax are vectors here
-  scoGraphicalObject Pinceau; //Pointer to each polyline of each axes
-  scoGraphicalObject Gomme; //Pointer to each polyline of each axes
-  scoGraphicalObject Trait; //Pointer to each trache of each axes
-  int number_of_subwin = 0;
-  int number_of_curves_by_subwin = 0;
-  int dimension = 2;
-  int nbr_curves = 0;
-  char *label = NULL;
-
-  /*Retrieving Parameters*/
-  ipar = GetIparPtrs(block);
-  nipar = GetNipar(block);
-  rpar = GetRparPtrs(block);
-  win = ipar[0];
-  color_flag = ipar[1];
-  buffer_size = ipar[2];
-  color[0] = ipar[3];
-  color[1] = ipar[3];
-  line_size = ipar[4];
-  animed = ipar[5];
-  win_pos[0] = ipar[6];
-  win_pos[1] = ipar[7];
-  win_dim[0] = ipar[8];
-  win_dim[1] = ipar[9];
-  nbr_curves = ipar[10];
-  xmin = rpar[0];
-  xmax = rpar[1];
-  ymin = rpar[2];
-  ymax = rpar[3];
-  label = GetLabelPtrs(block);
-  number_of_subwin = 1;
-  /* If only one element to draw*/
-  if (buffer_size == 1)
+    sco_data *sco = (sco_data *) * (block->work);
+    int i, j, k, l;
+
+    if (sco == NULL)
     {
-      number_of_curves_by_subwin = nbr_curves;
-      if(firstdraw == 1)
-       {
-         scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
-         scoSetShortDrawSize(*pScopeMemory,0,1);
-         scoSetLongDrawSize(*pScopeMemory,0,0);
-       }
-      scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
-      if(scoGetScopeActivation(*pScopeMemory) == 1)
-       {
-
-         //sciSetPixmapMode(scoGetPointerScopeWindow(*pScopeMemory),TRUE);
-
-         for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(*pScopeMemory, 0) ; i++)
-           {
-             scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
-             Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
-             pPOLYLINE_FEATURE(Pinceau)->n1 = 1;
-             sciSetMarkSize(Pinceau, line_size);
-
-           }
-       }
+        /*
+         * Data allocation
+         */
+
+        sco = (sco_data *) MALLOC(sizeof(sco_data));
+        if (sco == NULL)
+            goto error_handler_sco;
+
+        sco->internal.numberOfPoints = 0;
+        sco->internal.maxNumberOfPoints = block->ipar[2];
+
+        sco->internal.data = (double ***)CALLOC(block->nin, sizeof(double **));
+        if (sco->internal.data == NULL)
+            goto error_handler_data;
+
+        for (i = 0; i < block->nin; i++)
+        {
+            sco->internal.data[i] = (double **)CALLOC(block->insz[i], sizeof(double *));
+            if (sco->internal.data[i] == NULL)
+                goto error_handler_data_i;
+        }
+        for (i = 0; i < block->nin; i++)
+        {
+            for (j = 0; j < block->insz[i]; j++)
+            {
+                sco->internal.data[i][j] = (double *)CALLOC(block->ipar[2], sizeof(double));
+
+                if (sco->internal.data[i][j] == NULL)
+                    goto error_handler_data_ij;
+            }
+        }
+
+        sco->scope.cachedFigureUID = NULL;
+        sco->scope.cachedAxeUID = NULL;
+
+        sco->scope.cachedPolylinesUIDs = (char **)CALLOC(block->insz[0], sizeof(char **));
+
+        *(block->work) = sco;
     }
-  /*else if 2 or more elements*/
-  else
+
+    return sco;
+
+    /*
+     * Error management (out of normal flow)
+     */
+
+error_handler_data_ij:
+    for (k = 0; k < i; k++)
     {
-      number_of_curves_by_subwin = 2*nbr_curves; //it is a trick to recognize the type of scope, not sure it is a good way because normally a curve is the combination of a short and a longdraw
-      if(firstdraw == 1)
-       {
-         scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
-       }
-
-      scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
-      if(scoGetScopeActivation(*pScopeMemory) == 1)
-       {
-         gomme_color = sciGetBackground(scoGetPointerAxes(*pScopeMemory,0));
-
-
-         if(color[0] <= 0)  /*if mark style*/
-           {
-             if(firstdraw == 1)
-               {
-                 scoSetShortDrawSize(*pScopeMemory,0,1);
-                 scoSetLongDrawSize(*pScopeMemory,0,buffer_size-1);
-               }
-             for(i = 0 ; i < nbr_curves ; i++)
-               {
-                 //because of color[0] is negative it will add a black mark with style number color[0]
-                 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
-                 scoAddPolylineForShortDraw(*pScopeMemory,0,i+nbr_curves,color[0]); //same type of mark and black for the rubber
-                 scoAddPolylineForLongDraw(*pScopeMemory,0,i,color[0]);
-
-                 Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
-                 Gomme = scoGetPointerShortDraw(*pScopeMemory,0,i+nbr_curves);
-                 Trait = scoGetPointerLongDraw(*pScopeMemory,0,i);
-
-                 pPOLYLINE_FEATURE(Pinceau)->n1 = 1;
-                 pPOLYLINE_FEATURE(Gomme)->n1 = 1;
-                 sciSetMarkForeground(Gomme, gomme_color); //here the rubber becomes colored like the background of the axes
-                 pPOLYLINE_FEATURE(Trait)->n1 = buffer_size-1;
-
-                 sciSetMarkSize(Pinceau, line_size);
-                 sciSetMarkSize(Gomme, line_size);
-                 sciSetMarkSize(Trait, line_size);
-               }
-           }
-         /*if line style*/
-         else
-           {
-             if(firstdraw == 1)
-               {
-                 scoSetShortDrawSize(*pScopeMemory,0,2);
-                 scoSetLongDrawSize(*pScopeMemory,0,buffer_size-1);
-               }
-             for(i = 0 ; i < nbr_curves ; i++)
-               {
-                 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
-                 scoAddPolylineForShortDraw(*pScopeMemory,0,i+nbr_curves,gomme_color);
-                 scoAddPolylineForLongDraw(*pScopeMemory,0,i,color[0]);
-
-                 Pinceau = scoGetPointerShortDraw(*pScopeMemory,0,i);
-                 Gomme = scoGetPointerShortDraw(*pScopeMemory,0,i+nbr_curves);
-                 Trait = scoGetPointerLongDraw(*pScopeMemory,0,i);
-
-                 pPOLYLINE_FEATURE(Pinceau)->n1 = 2;
-                 pPOLYLINE_FEATURE(Gomme)->n1 = 2;
-                 pPOLYLINE_FEATURE(Trait)->n1 = buffer_size-1;
-
-                 sciSetLineWidth(Pinceau, line_size);
-                 sciSetLineWidth(Gomme, line_size);
-                 sciSetLineWidth(Trait, line_size);
-               }
-           }
-       }
+        for (l = 0; l < j; l++)
+        {
+            FREE(sco->internal.data[k][l]);
+        }
     }
-  if(scoGetScopeActivation(*pScopeMemory) == 1)
+    i = block->nin - 1;
+error_handler_data_i:
+    for (j = 0; j < i; j++)
     {
-      scoAddTitlesScope(*pScopeMemory,label,"x","y",NULL);
+        FREE(sco->internal.data[i]);
     }
+    FREE(sco->internal.data);
+error_handler_data:
+    FREE(sco);
+error_handler_sco:
+    // allocation error
+    set_block_error(-5);
+    return NULL;
 }
-/*--------------------------------------------------------------------------*/
-/** \fn void canimxy(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 canimxy(scicos_block * block, int flag)
+
+static void freeScoData(scicos_block * block)
 {
-  /*Declarations*/
-  ScopeMemory * pScopeMemory = NULL;
-  double *u1 = NULL,*u2 = NULL;
-  scoGraphicalObject pLongDraw;
-  int i = 0;
-  /* State Machine Control */
-  switch(flag)
+    sco_data *sco = (sco_data *) * (block->work);
+    int i, j;
+
+    if (sco != NULL)
     {
-    case Initialization:
-      {
-       canimxy_draw(block,&pScopeMemory,1);
-       break; //Break of the switch condition don t forget it
-      } //End of Initialization
+        for (i = 0; i < block->nin; i++)
+        {
+            for (j = 0; j < block->insz[i]; j++)
+            {
+                FREE(sco->internal.data[i][j]);
+            }
+            FREE(sco->internal.data[i]);
+        }
 
-    case StateUpdate:
-      {
-       scoRetrieveScopeMemory(block->work,&pScopeMemory);
-       if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-
-           /* Charging Elements */
-           if (scoGetPointerScopeWindow(pScopeMemory) == NULL) // If the window has been destroyed we recreate it
-             {
-               canimxy_draw(block,&pScopeMemory,0);
-             }
-
-           /*Retrieve Elements*/
-           u1 = GetRealInPortPtrs(block,1);
-           u2 = GetRealInPortPtrs(block,2);
-
-           scoDrawScopeAnimXYStyle(pScopeMemory,u1,u2,NULL);
-         }
-       break; //Break of the switch don t forget it !
-      }//End of stateupdate
-
-      //This case is activated when the simulation is done or when we close scicos
-    case Ending:
-      {
-       scoRetrieveScopeMemory(block->work, &pScopeMemory);
-       if(scoGetScopeActivation(pScopeMemory) == 1)
-         {
-           /* Check if figure is still opened, otherwise, don't try to destroy it again. */
-           scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
-           if (figure != NULL)
-             {
-               if(scoGetLongDrawSize(pScopeMemory,0) == 0)
-                 {
-                   for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
-                     {
-                       pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
-                       forceRedraw(pLongDraw);
-                     }
-                 }
-               else
-                 {
-                   for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0)/2 ; i++)
-                     {
-                       pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
-                       forceRedraw(pLongDraw);
-                     }
-                 }
-               clearUserData(figure);
-             }
-         }
-       scoFreeScopeMemory(block->work, &pScopeMemory);
-       break; //Break of the switch
-      }
-      //free the memory which is allocated at each turn by some variables
+        FREE(sco->internal.data);
+
+//      Commented due to the C++ allocation
+//      see http://bugzilla.scilab.org/show_bug.cgi?id=9747
+//      FREE(sco->scope.cachedFigureUID);
+//      sco->scope.cachedFigureUID = NULL;
+//      for (i=0; i<block->nin; i++) {
+//          for (j=0; j<block->insz[i]; j++) {
+//              FREE(sco->scope.cachedPolylinesUIDs[i][j]);
+//              sco->scope.cachedPolylinesUIDs[i][j] = NULL;
+//          }
+//          FREE(sco->scope.cachedAxeUID[i]);
+//          sco->scope.cachedAxeUID[i] = NULL;
+//      }
+
+        FREE(sco);
+    }
+}
 
+static void appendData(scicos_block * block, double *x, double *y)
+{
+    int i;
+
+    sco_data *sco = (sco_data *) * (block->work);
+    int maxNumberOfPoints = sco->internal.maxNumberOfPoints;
+    int numberOfPoints = sco->internal.numberOfPoints;
+
+    /*
+     * Handle the case where the scope has more points than maxNumberOfPoints
+     */
+    if (sco != NULL && numberOfPoints >= maxNumberOfPoints)
+    {
+        unsigned int setLen = (unsigned int)maxNumberOfPoints - 1;
+
+        // on a full scope, push data
+        for (i = 0; i < block->insz[0]; i++)
+        {
+            sco->internal.data[0][i][setLen] = x[i];
+            memmove(sco->internal.data[0][i], &sco->internal.data[0][i][1], setLen * sizeof(double));
+
+            sco->internal.data[1][i][setLen] = y[i];
+            memmove(sco->internal.data[1][i], &sco->internal.data[1][i][1], setLen * sizeof(double));
+        }
+
+        // then return
+        return;
+    }
+
+    /*
+     * Update data
+     */
+    if (sco != NULL)
+    {
+        int setLen;
+
+        for (i = 0; i < block->insz[0]; i++)
+        {
+            for (setLen = maxNumberOfPoints - numberOfPoints; setLen >= 0; setLen--)
+            {
+                sco->internal.data[0][i][numberOfPoints + setLen] = x[i];
+                sco->internal.data[1][i][numberOfPoints + setLen] = y[i];
+            }
+        }
+
+        sco->internal.numberOfPoints++;
+    }
+}
+
+static BOOL pushData(scicos_block * block, int row)
+{
+    char *pFigureUID;
+    char *pAxeUID;
+    char *pPolylineUID;
+
+    double *x;
+    double *y;
+    sco_data *sco;
+
+    BOOL result = TRUE;
+
+    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
+    x = sco->internal.data[0][row];
+    y = sco->internal.data[1][row];
+
+    result &= setGraphicObjectProperty(pPolylineUID, __GO_DATA_MODEL_X__, x, jni_double_vector, sco->internal.maxNumberOfPoints);
+    result &= setGraphicObjectProperty(pPolylineUID, __GO_DATA_MODEL_Y__, y, jni_double_vector, sco->internal.maxNumberOfPoints);
+
+    return result;
+}
+
+/*****************************************************************************
+ *
+ * Graphic utils
+ *
+ ****************************************************************************/
+
+/**
+ * Set properties on the figure.
+ *
+ * \param pFigureUID the figure uid
+ * \param block the current block
+ */
+static void setFigureSettings(char *pFigureUID, scicos_block * block)
+{
+    int win_pos[2];
+    int win_dim[2];
+
+    int *ipar = block->ipar;
+
+    win_pos[0] = ipar[6];
+    win_pos[1] = ipar[7];
+    win_dim[0] = ipar[8];
+    win_dim[1] = ipar[9];
+
+    setGraphicObjectProperty(pFigureUID, __GO_POSITION__, &win_pos, jni_int_vector, 2);
+    setGraphicObjectProperty(pFigureUID, __GO_SIZE__, &win_dim, jni_int_vector, 2);
+};
+
+/*****************************************************************************
+ *
+ * Graphic
+ *
+ ****************************************************************************/
+
+static char *getFigure(scicos_block * block)
+{
+    signed int figNum;
+    char *pFigureUID = NULL;
+    char *pAxe = NULL;
+    static const int i__1 = 1;
+    sco_data *sco = (sco_data *) * (block->work);
+
+    // fast path for an existing object
+    if (sco->scope.cachedFigureUID != NULL)
+    {
+        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();
+    }
+
+    pFigureUID = getFigureFromIndex(figNum);
+    // create on demand
+    if (pFigureUID == NULL)
+    {
+        pFigureUID = createNewFigureWithAxes();
+        setGraphicObjectProperty(pFigureUID, __GO_ID__, &figNum, jni_int, 1);
+
+        // set configured parameters
+        setFigureSettings(pFigureUID, block);
+        sco->scope.cachedFigureUID = pFigureUID;
+
+        // allocate the axes through the getter
+        pAxe = getAxe(pFigureUID, block);
+
+        /*
+         * Setup according to block settings
+         */
+        setLabel(pAxe, __GO_X_AXIS_LABEL__, "x");
+        setLabel(pAxe, __GO_Y_AXIS_LABEL__, "y");
+
+        setGraphicObjectProperty(pAxe, __GO_X_AXIS_VISIBLE__, &i__1, jni_bool, 1);
+        setGraphicObjectProperty(pAxe, __GO_Y_AXIS_VISIBLE__, &i__1, jni_bool, 1);
+
+        setPolylinesBounds(block);
+    }
+
+    if (sco->scope.cachedFigureUID == NULL)
+    {
+        sco->scope.cachedFigureUID = pFigureUID;
+    }
+    return pFigureUID;
+}
+
+static char *getAxe(char *pFigureUID, scicos_block * block)
+{
+    char *pAxe;
+    int i;
+    sco_data *sco = (sco_data *) * (block->work);
+
+    // 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)
+    {
+        pAxe = cloneGraphicObject(getAxesModel());
+
+        if (pAxe != NULL)
+        {
+            setGraphicObjectRelationship(pFigureUID, pAxe);
+
+            // allocate the polylines through the getter
+            for (i = 0; i < block->insz[0]; i++)
+            {
+                getPolyline(pAxe, block, i);
+            }
+        }
+    }
+
+    if (sco->scope.cachedAxeUID == NULL)
+    {
+        sco->scope.cachedAxeUID = pAxe;
+    }
+    return pAxe;
+}
+
+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);
+
+    // 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);
+
+            /*
+             * 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);
+
+            color = block->ipar[3];
+            markSize = block->ipar[4];
+            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);
+            }
+        }
+    }
+
+    if (sco->scope.cachedPolylinesUIDs != NULL)
+    {
+        sco->scope.cachedPolylinesUIDs[row] = pPolyline;
+    }
+    return pPolyline;
+}
+
+static BOOL setPolylinesBounds(scicos_block * block)
+{
+    char *pFigureUID;
+    char *pAxeUID;
+
+    double dataBounds[6];
+
+    dataBounds[0] = block->rpar[0]; // xMin
+    dataBounds[1] = block->rpar[1]; // xMax
+    dataBounds[2] = block->rpar[2]; // yMin
+    dataBounds[3] = block->rpar[3]; // yMax
+    dataBounds[4] = -1.0;       // zMin
+    dataBounds[5] = 1.0;        // zMax
+
+    pFigureUID = getFigure(block);
+    pAxeUID = getAxe(pFigureUID, block);
+
+    return setGraphicObjectProperty(pAxeUID, __GO_DATA_BOUNDS__, dataBounds, jni_double_vector, 6);
 }
-/*--------------------------------------------------------------------------*/