int sci_relocate_handle( char * fname, unsigned long fname_len )
{
  int handleCol ;
  int handleRow ;
  int nbHandle ;
  int handleStkIndex ;
  int parentCol ;
  int parentRow ;
  int parentStkIndex ;
  int outIndex ;
  int i ;
  unsigned long * handleArray = NULL ;

  /* the function should be called with relocate_handle( handle, parent_handle ) */
  CheckRhs(2,2) ;
  CheckLhs(0,1) ;


  GetRhsVar( 1,GRAPHICAL_HANDLE_DATATYPE, &handleRow, &handleCol, &handleStkIndex );
  nbHandle = handleRow * handleCol ;
  GetRhsVar( 2,GRAPHICAL_HANDLE_DATATYPE, &parentRow, &parentCol, &parentStkIndex );

  if ( parentCol * parentRow != 1 )
  {
    Scierror(999,_("%s: Handles must be relocated under a single parent.\n"),fname);
    return 0 ;
  }

  /* create an array of handles */
  handleArray = MALLOC( nbHandle * sizeof( unsigned long ) ) ;
  if ( handleArray == NULL )
  {
    Scierror(999,_("%s: No more memory.\n"),fname);
    return 0 ;
  }

  for ( i = 0 ; i < nbHandle ; i++ )
  {
    handleArray[i] = (unsigned long) *hstk( handleStkIndex + i ) ;
  }

// FIXME : loop on each handle and call MVC to enable new relationship.

//  if ( sciRelocateHandles( handleArray          ,
//                           handleRow * handleCol,
//                           (unsigned long) *hstk( parentStkIndex ) ) != 0 )
//  {
//		PutLhsVar();
//		return 0 ;
//  }
  FREE( handleArray ) ;
  CreateVar( Rhs + 1,GRAPHICAL_HANDLE_DATATYPE, &handleCol, &handleRow, &outIndex );
  *hstk(outIndex) = *hstk(handleStkIndex) ;
  LhsVar(1) = Rhs + 1 ;
  PutLhsVar();
  return 0 ;

}
Exemple #2
0
/*--------------------------------------------------------------------------*/
int sci_exportUI(char * fname, unsigned long fname_len)
{
    int iFigureId = 0; // id of the figure to export
    int iRows = 0;
    int iCols = 0;
    size_t stackPointer = 0;

    CheckLhs(0, 1);
    CheckRhs(1, 1);

    if (GetType(1) == sci_handles) // exportUI(figHandle)
    {
        const char *pstFigureUID = NULL;
        int iHandleType = -1;
        int *piHandleType = &iHandleType;
        int *piFigureId = &iFigureId;

        GetRhsVar(1, GRAPHICAL_HANDLE_DATATYPE, &iRows, &iCols, &stackPointer);
        if (iRows * iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
        }

        pstFigureUID = getObjectFromHandle((unsigned long) * (hstk(stackPointer)));

        getGraphicObjectProperty(pstFigureUID, __GO_TYPE__, jni_int, (void **)&piHandleType);
        if (iHandleType == __GO_FIGURE__)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
            return FALSE;
        }

        getGraphicObjectProperty(pstFigureUID, __GO_ID__, jni_int, (void **)&piFigureId);
    }
    else if (GetType(1) == sci_matrix) // exportUI(figId)
    {
        GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &iRows, &iCols, &stackPointer);
        if (iRows * iCols != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
            return FALSE;
        }

        iFigureId = (int) * (stk(stackPointer));
    }
    else
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A Real Scalar or a 'Figure' handle expected.\n"), fname, 1);
        return FALSE;
    }

    // call the export function
    exportUserInterface(iFigureId);

    LhsVar(1) = 0;

    PutLhsVar();

    return 0;
}
Exemple #3
0
/*--------------------------------------------------------------------------*/
int sciReturnHandle(void* _pvCtx, long handle)
{
  int numRow   = 1 ;
  int numCol   = 1 ;
  int outIndex = 0 ;
  CreateVar(Rhs+1,GRAPHICAL_HANDLE_DATATYPE,&numRow,&numCol,&outIndex);
  *hstk(outIndex) = handle ;
  return 0 ;
}
Exemple #4
0
/*--------------------------------------------------------------------------*/
int sciReturnColHandleVector(void* _pvCtx, const long handles[], int nbValues)
{
  int numCol   = 1 ;
  int outIndex = 0 ;
  int i ;
  CreateVar(Rhs+1, GRAPHICAL_HANDLE_DATATYPE, &nbValues, &numCol, &outIndex);
  for (i = 0 ; i < nbValues ; i++)
  {
    hstk(outIndex)[i] = handles[i] ;
  }
  return 0 ;
}
Exemple #5
0
/*--------------------------------------------------------------------------*/
int sci_glue( char * fname, unsigned long fname_len )
{
    int numrow,numcol,l1,l2,lind,n,cx1=1;
    unsigned long hdl = 0, parenthdl = 0 ;
    long *handelsvalue = NULL ;
    int outindex,i;

    char *pstCompoundUID = NULL;
    char *pstParentUID = NULL;
    char *pstCurrentParentUID = NULL;
    char *pobjUID = NULL;

    CheckRhs(1,1);
    CheckLhs(0,1);

    /*  set or create a graphic window */
    GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&numrow,&numcol,&l1); /* We get the scalar value if it is ones */
    n=numrow*numcol;
    CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,&numrow,&numcol,&l2);
    CreateVar(Rhs+2,MATRIX_OF_INTEGER_DATATYPE,&numrow,&numcol,&lind);

    if (n>1)
    {
        C2F(dcopy)(&n, stk(l1), &cx1, stk(l2), &cx1);
        C2F(dsort)(stk(l2),&n,istk(lind));
        for (i = 1; i < n;i++)
        {
            long long i1 = (long long)*hstk(l2+i);
            long long i2 = (long long)*hstk(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) (hstk(l1))[i];
        pobjUID = 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, &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;
    CreateVar(Rhs+3,GRAPHICAL_HANDLE_DATATYPE,&numrow,&numcol,&outindex);
    hstk(outindex)[0] = getHandle(pstCompoundUID);
    LhsVar(1) = Rhs+3;
    PutLhsVar();
    FREE(handelsvalue);

   return 0;
}
/*--------------------------------------------------------------------------*/
int sci_swap_handles( char * fname, unsigned long fname_len )
{
  int firstHdlCol  ;
  int firstHdlRow  ;
  int secondHdlCol ;
  int secondHdlRow ;
  int firstHdlStkIndex  ;
  int secondHdlStkIndex ;
  char *pstHandle_1;
  char *pstHandle_2;
  char *pstParent_1;
  char *pstParent_2;
  int iChildrenCount = 0;
  int *piChildrenCount = &iChildrenCount;
  char **pstChildrenUID;
  int i = 0;
  long h = 0;

  CheckRhs( 2, 2 ) ;
  CheckLhs( 0, 1 ) ;

  GetRhsVar( 1,GRAPHICAL_HANDLE_DATATYPE, &firstHdlRow, &firstHdlCol, &firstHdlStkIndex );
  GetRhsVar( 2,GRAPHICAL_HANDLE_DATATYPE, &secondHdlRow, &secondHdlCol, &secondHdlStkIndex );

  if ( firstHdlRow * firstHdlCol != 1 || secondHdlRow * secondHdlCol != 1 )
  {
    Scierror(999,_("%s: Routine can only swap two single handles.\n"),fname);
    return 0 ;
  }

  /* get the two handles and swap them */
  h = (long)*hstk(firstHdlStkIndex);
  pstHandle_1 = getObjectFromHandle(h);

  h = (long)*hstk(secondHdlStkIndex);
  pstHandle_2 = getObjectFromHandle(h);

  getGraphicObjectProperty(pstHandle_1, __GO_PARENT__, jni_string, &pstParent_1);
  getGraphicObjectProperty(pstHandle_2, __GO_PARENT__, jni_string, &pstParent_2);

  // Check if objects do not have the same parent
  if (strcmp(pstParent_1, pstParent_2) == 0)
  {
      getGraphicObjectProperty(pstParent_1, __GO_CHILDREN_COUNT__, jni_int, (void **)&piChildrenCount);
      getGraphicObjectProperty(pstParent_1, __GO_CHILDREN__, jni_string_vector, (void **)&pstChildrenUID);

      for (i = 0 ; i < iChildrenCount ; ++i)
      {
          if (strcmp(pstChildrenUID[i], pstHandle_1) == 0)
          {
              pstChildrenUID[i] = pstHandle_2;
          }
          else if (strcmp(pstChildrenUID[i], pstHandle_2) == 0)
          {
              pstChildrenUID[i] = pstHandle_1;
          }
      }

      setGraphicObjectProperty(pstParent_1, __GO_CHILDREN__, pstChildrenUID, jni_string_vector, iChildrenCount);

  }
  else
  {
      setGraphicObjectRelationship(pstParent_1, pstHandle_2);
      setGraphicObjectRelationship(pstParent_2, pstHandle_1);
  }
  LhsVar(1) = 0 ;
  PutLhsVar();
  return 0 ;
}