File: sci_delete.c

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (165 lines) | stat: -rw-r--r-- 4,927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2006 - ENPC - Jean-Philipe Chancelier
 * Copyright (C) 2006 - INRIA - Fabrice Leray
 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
 * 
 * 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
 *
 */

/*------------------------------------------------------------------------*/
/* file: sci_delete.c                                                     */
/* desc : interface for delete routine                                    */
/*------------------------------------------------------------------------*/

#include "gw_graphics.h"
#include "stack-c.h"
#include "DestroyObjects.h"
#include "SetProperty.h"
#include "GetProperty.h"
#include "DrawObjects.h"
#include "Interaction.h"
#include "CurrentObjectsManagement.h"
#include "ObjectSelection.h"
#include "DrawingBridge.h"
#include "localization.h"
#include "GraphicSynchronizerInterface.h"
#include "DestroyUimenu.h"
#include "DestroyUicontrol.h"
#include "DestroyWaitBar.h"
#include "Scierror.h"
#include "HandleManagement.h"
/*--------------------------------------------------------------------------*/
int sci_delete(char *fname,unsigned long fname_len)
{
  int m1,n1,l1,m2,n2,l2,num, lw;
  unsigned long hdl;
  sciPointObj * pobj;
  sciPointObj * parentFigure;

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

  switch(VarType(1))
  {
  case sci_handles: /* delete Entity given by a handle */
    GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&m1,&n1,&l1); /* Gets the Handle passed as argument */
    if (m1!=1||n1!=1) {
      lw = 1 + Top - Rhs;
      C2F(overload)(&lw,"delete",6);return 0;
    }
    if (Rhs == 2)
    {
      GetRhsVar(2,STRING_DATATYPE,&m2,&n2,&l2); /* Gets the command name */
    }
    hdl = (unsigned long)*hstk(l1); /* Puts the value of the Handle to hdl */
    break;
  case sci_strings: /* delete("all") */
    CheckRhs(1,1);
    GetRhsVar(1,STRING_DATATYPE,&m2,&n2,&l2);
    if (strcmp(cstk(l2),"all") == 0)
    {
			startGraphicDataWriting();
			sciClearFigure(sciGetCurrentFigure());
			endGraphicDataWriting();
			sciDrawObj(sciGetCurrentFigure()); /* redraw the figure to see the change */
			LhsVar(1) = 0;
			C2F(putlhsvar)();
      return 0;
    }
    else
    {
      Scierror(999,_("%s: Wrong value for input argument #%d: '%s' expected.\n"),fname,1,"all");
      return 0;
    }
    break;
  default:
    if (Rhs==0) /* Delete current object */
      {
        hdl = (unsigned long) sciGetHandle(sciGetCurrentObj());
      }
    else
      {
        Scierror(999,_("%s: Wrong type for input argument #%d: '%s' or handle expected.\n"),fname,1,"all");
        return 0;
      }
    break;
  }

  pobj = sciGetPointerFromHandle(hdl);

  if (pobj == NULL)
  {
    Scierror(999,_("%s: The handle is not valid.\n"),fname);
    return 0;
  }

  parentFigure = sciGetParentFigure(pobj);
      
  num = sciGetNumFigure( pobj ) ;

  if ((Rhs == 2) && (strcmp(cstk(l2),"callback") == 0))
  {
    startFigureDataWriting(parentFigure);
    sciDelCallback((sciPointObj *)pobj);
    endFigureDataWriting(parentFigure);
  }
  else
  {
    
    sciEntityType objType = sciGetEntityType( pobj ) ;

    if (objType == SCI_UIMENU)
      {
        DestroyUimenu(pobj);
      }
    else if(objType == SCI_UICONTROL)
      {
        DestroyUicontrol(pobj);
      }
    else if (objType == SCI_WAITBAR || objType == SCI_PROGRESSIONBAR)
      {
        DestroyWaitBar(pobj);
      }
    else if ( sciGetParentFigure(pobj) != NULL && objType != SCI_FIGURE)
      {
        BOOL selected = sciGetIsSelected( pobj ) ;
        sciPointObj * parentObj = sciGetParent(pobj);
        startFigureDataWriting(parentFigure);
				if (sciIsCurrentObject(pobj))
				{
					/* If the object is the current one, modify the current object pointer */
					sciSetCurrentObj(parentObj) ; /* A LAISSER F.Leray 25.03.04*/
				}
        sciDelGraphicObj( pobj ) ; /* don't use pobj after this point */
        pobj = NULL ;
        
        /* test here: we could have deleted the selected subwindow, we must choose an other */
        /* We must always have one selected subwindow (if at least one subwindow exists) */
        if ( objType == SCI_SUBWIN && selected )
        {
          /* we have to select antoher subwindow if one exists at least */
          sciSelectFirstSubwin( parentFigure ) ;
        }
        
        endFigureDataWriting(parentFigure);
        
        /* redraw the window */
        sciDrawObj( parentObj ) ;
      }
    else if( sciGetEntityType(pobj) == SCI_FIGURE ) /* F.Leray 13.04.04: We delete the special object Figure !!*/
      {
        sciDeleteWindow( num );
      }
    
  }
  
  LhsVar(1) = 0;
  C2F(putlhsvar)();
  return 0;
}