Plug rubberbox function :
[scilab.git] / scilab / modules / graphics / src / c / Interaction.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2001-2002 - INRIA - Mathieu Philipe
4  * Copyright (C) 2002-2004 - INRIA - Djalel Abdemouche
5  * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
6  * Copyright (C) 2005 - INRIA - Jean-Baptiste Silvy
7  * Copyright (C) 2012 - DIGITEO - Manuel Juliachs
8  *
9  * This file must be used under the terms of the CeCILL.
10  * This source file is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution.  The terms
12  * are also available at
13  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14  *
15  */
16
17 /*------------------------------------------------------------------------
18  *    Graphic library
19  *    Comment:
20  *    This file contains all functions used to INTERACT with the graphic
21  *    window (zoom by pressing button, callbacks...)
22  --------------------------------------------------------------------------*/
23 #include <string.h>
24 #include "Interaction.h"
25 #include "SetProperty.h"
26 #include "GetProperty.h"
27 #include "Scierror.h"
28 #include "MALLOC.h" /* MALLOC */
29 #include "localization.h"
30 #include "JavaInteraction.h"
31 #include "axesScale.h"
32 #include "math_graphics.h"
33 #include "HandleManagement.h"
34
35 #include "graphicObjectProperties.h"
36 #include "setGraphicObjectProperty.h"
37 #include "getGraphicObjectProperty.h"
38
39
40 /*-------------------------------------------------------------------------------------*/
41 static int moveObj(char* pobjUID, double displacement[], int displacementSize);
42 /*-------------------------------------------------------------------------------------*/
43
44 /**sciAddCallback
45  * exec the callback associated with pthis
46  */
47 int
48 sciAddCallback (sciPointObj * pthis, char *code, int len, int mevent )
49 {
50     /* Destruction de l'ancienne callback si elle existait */
51     sciDelCallback (pthis);
52
53     switch (sciGetEntityType (pthis))
54     {
55         case SCI_SUBWIN:
56             if ((pSUBWIN_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
57             {
58                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
59                 return -1;
60             }
61             else
62             {
63                 strncpy(pSUBWIN_FEATURE (pthis)->callback, code, len);
64                 pSUBWIN_FEATURE (pthis)->callbacklen = len;
65                 pSUBWIN_FEATURE (pthis)->callbackevent = mevent;
66             }
67             break;
68         case SCI_ARC:
69             if ((pARC_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
70             {
71                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
72                 return -1;
73             }
74             else
75             {
76                 strncpy(pARC_FEATURE (pthis)->callback, code, len);
77                 pARC_FEATURE (pthis)->callbacklen = len;
78                 pARC_FEATURE (pthis)->callbackevent = mevent;
79
80             }
81             break;
82         case SCI_RECTANGLE:
83             if ((pRECTANGLE_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
84             {
85                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
86                 return -1;
87             }
88             else
89             {
90                 strncpy(pRECTANGLE_FEATURE (pthis)->callback, code, len);
91                 pRECTANGLE_FEATURE (pthis)->callbacklen = len;
92                 pRECTANGLE_FEATURE (pthis)->callbackevent = mevent;
93
94             }
95             break;
96         case SCI_SEGS:
97             if ((pSEGS_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
98             {
99                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
100                 return -1;
101             }
102             else
103             {
104                 strncpy(pSEGS_FEATURE (pthis)->callback, code, len);
105                 pPOLYLINE_FEATURE (pthis)->callbacklen = len;
106                 pPOLYLINE_FEATURE (pthis)->callbackevent = mevent;
107
108             }
109             break;
110         case SCI_FEC:
111             if ((pFEC_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
112             {
113                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
114                 return -1;
115             }
116             else
117             {
118                 strncpy(pFEC_FEATURE (pthis)->callback, code, len);
119                 pPOLYLINE_FEATURE (pthis)->callbacklen = len;
120                 pPOLYLINE_FEATURE (pthis)->callbackevent = mevent;
121
122             }
123             break;
124         case SCI_GRAYPLOT:
125             if ((pGRAYPLOT_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
126             {
127                 Scierror(999, _("%s: No more memory.\n"), "sciAddCallback");
128                 return -1;
129             }
130             else
131             {
132                 strncpy(pGRAYPLOT_FEATURE (pthis)->callback, code, len);
133                 pPOLYLINE_FEATURE (pthis)->callbacklen = len;
134                 pPOLYLINE_FEATURE (pthis)->callbackevent = mevent;
135
136             }
137             break;
138         case SCI_POLYLINE:
139             if ((pPOLYLINE_FEATURE (pthis)->callback = CALLOC (len + 1, sizeof (char))) == NULL)
140             {
141                 Scierror(9999, _("%s: No more memory.\n"), "sciAddCallback");
142                 return -1;
143             }
144             else
145             {
146                 strncpy(pPOLYLINE_FEATURE (pthis)->callback, code, len);
147                 pPOLYLINE_FEATURE (pthis)->callbacklen = len;
148                 pPOLYLINE_FEATURE (pthis)->callbackevent = mevent;
149
150             }
151             break;
152         case SCI_UICONTROL:
153         case SCI_UIMENU:
154             break;
155         case SCI_TEXT:
156         case SCI_LEGEND:
157         case SCI_SURFACE:
158         case SCI_AXES:
159         case SCI_FIGURE:
160         case SCI_AGREG:
161         case SCI_LABEL: /* F.Leray 28.05.04 */
162
163         default:
164             Scierror(999, _("No Callback is associated with this Entity.\n"));
165             return -1;
166             break;
167     }
168     return -1;
169 }
170
171
172
173
174 /**sciGetCallback
175  * returns the scilab callback code
176  */
177 char *sciGetCallback(sciPointObj * pthis)
178 {
179     switch (sciGetEntityType (pthis))
180     {
181         case SCI_SUBWIN:
182             return (char *)(pSUBWIN_FEATURE(pthis)->callback);
183             break;
184         case SCI_ARC:
185             return (char *)(pARC_FEATURE(pthis)->callback);
186             break;
187         case SCI_SEGS:
188             return (char *)(pSEGS_FEATURE(pthis)->callback);
189             break;
190         case SCI_FEC:
191             return (char *)(pFEC_FEATURE(pthis)->callback);
192             break;
193         case SCI_GRAYPLOT:
194             return (char *)(pGRAYPLOT_FEATURE(pthis)->callback);
195             break;
196         case SCI_POLYLINE:
197             return (char *)(pPOLYLINE_FEATURE(pthis)->callback);
198             break;
199         case SCI_RECTANGLE:
200             return (char *)(pRECTANGLE_FEATURE(pthis)->callback);
201             break;
202         case SCI_TEXT:
203             return (char *)(pTEXT_FEATURE(pthis)->callback);
204             break;
205         case SCI_SURFACE:
206             return (char *)(pSURFACE_FEATURE(pthis)->callback);
207             break;
208         case SCI_AXES:
209             return (char *)(pAXES_FEATURE(pthis)->callback);
210             break;
211         case SCI_UIMENU:
212             return (char *)(pUIMENU_FEATURE(pthis)->callback);
213             break;
214         case SCI_UICONTROL:
215             return (char *)(pUICONTROL_FEATURE(pthis)->callback);
216             break;
217         case SCI_LEGEND:
218         case SCI_FIGURE:
219         case SCI_AGREG:
220         case SCI_LABEL: /* F.Leray 28.05.04 */
221         default:
222             Scierror(999, _("No Callback is associated with this Entity.\n"));
223             return (char *)NULL;
224             break;
225     }
226 }
227
228 /* 07/11/2002*/
229 /**sciGetCallbackMouseEvent
230  * @author Djalel Abdemouche
231  */
232 int sciGetCallbackMouseEvent(sciPointObj * pthis)
233 {
234     switch (sciGetEntityType (pthis))
235     {
236         case SCI_SUBWIN:
237             return pSUBWIN_FEATURE(pthis)->callbackevent;
238             break;
239         case SCI_ARC:
240             return pARC_FEATURE(pthis)->callbackevent;
241             break;
242         case SCI_SEGS:
243             return pSEGS_FEATURE(pthis)->callbackevent;
244             break;
245         case SCI_FEC:
246             return pFEC_FEATURE(pthis)->callbackevent;
247             break;
248         case SCI_GRAYPLOT:
249             return pGRAYPLOT_FEATURE(pthis)->callbackevent;
250             break;
251         case SCI_POLYLINE:
252             return pPOLYLINE_FEATURE(pthis)->callbackevent;
253             break;
254         case SCI_RECTANGLE:
255             return pRECTANGLE_FEATURE(pthis)->callbackevent;
256             break;
257         case SCI_TEXT:
258             return pTEXT_FEATURE(pthis)->callbackevent;
259             break;
260         case SCI_SURFACE:
261             return pSURFACE_FEATURE(pthis)->callbackevent;
262             break;
263         case SCI_AXES:
264             return pAXES_FEATURE(pthis)->callbackevent;
265             break;
266         case SCI_UIMENU:
267         case SCI_LEGEND:
268         case SCI_FIGURE:
269         case SCI_AGREG:
270         case SCI_LABEL: /* F.Leray 28.05.04 */
271         default:
272             Scierror(999, _("No Callback is associated with this Entity.\n"));
273             return 100;
274             break;
275     }
276
277 }
278
279 /**sciSetCallbackMouseEvent
280  * @author Djalel Abdemouche
281  */
282 int sciSetCallbackMouseEvent(sciPointObj * pthis, int mevent)
283 {
284     switch (sciGetEntityType (pthis))
285     {
286         case SCI_SUBWIN:
287             pSUBWIN_FEATURE(pthis)->callbackevent = mevent;
288             break;
289         case SCI_ARC:
290             pARC_FEATURE(pthis)->callbackevent = mevent;
291             break;
292         case SCI_SEGS:
293             pSEGS_FEATURE(pthis)->callbackevent = mevent;
294             break;
295         case SCI_FEC:
296             pFEC_FEATURE(pthis)->callbackevent = mevent;
297             break;
298         case SCI_GRAYPLOT:
299             pGRAYPLOT_FEATURE(pthis)->callbackevent = mevent;
300             break;
301         case SCI_POLYLINE:
302             pPOLYLINE_FEATURE(pthis)->callbackevent = mevent;
303             break;
304         case SCI_RECTANGLE:
305             pRECTANGLE_FEATURE(pthis)->callbackevent = mevent;
306             break;
307         case SCI_TEXT:
308             pTEXT_FEATURE(pthis)->callbackevent = mevent;
309             break;
310         case SCI_SURFACE:
311             pSURFACE_FEATURE(pthis)->callbackevent = mevent;
312             break;
313         case SCI_AXES:
314             pAXES_FEATURE(pthis)->callbackevent = mevent;
315             break;
316         case SCI_LEGEND:
317         case SCI_FIGURE:
318         case SCI_AGREG:
319         case SCI_UIMENU:
320         case SCI_LABEL: /* F.Leray 28.05.04 */
321         default:
322             Scierror (999, _("No Callback is associated with this Entity.\n"));
323             return 100;
324             break;
325     }
326     return 100;
327 }
328
329
330
331 /**sciDelCallback
332  * returns the length of the scilab callback code
333  */
334 int
335 sciDelCallback (sciPointObj * pthis)
336 {
337     switch (sciGetEntityType (pthis))
338     {
339         case SCI_SUBWIN:
340             pSUBWIN_FEATURE (pthis)->callbacklen = 0;
341             pSUBWIN_FEATURE (pthis)->callbackevent = 100;
342             FREE(pSUBWIN_FEATURE (pthis)->callback);
343             pSUBWIN_FEATURE (pthis)->callback = NULL;
344             break;
345         case SCI_ARC:
346             pARC_FEATURE (pthis)->callbacklen = 0;
347             pARC_FEATURE (pthis)->callbackevent = 100;
348             FREE(pARC_FEATURE (pthis)->callback);
349             pARC_FEATURE (pthis)->callback = NULL;
350             break;
351         case SCI_RECTANGLE:
352             pRECTANGLE_FEATURE (pthis)->callbacklen = 0;
353             pRECTANGLE_FEATURE (pthis)->callbackevent = 100;
354             FREE(pRECTANGLE_FEATURE (pthis)->callback);
355             pRECTANGLE_FEATURE (pthis)->callback = NULL;
356             break;
357         case SCI_SEGS:
358             pSEGS_FEATURE (pthis)->callbacklen = 0;
359             pSEGS_FEATURE (pthis)->callbackevent = 100;
360             FREE(pSEGS_FEATURE (pthis)->callback);
361             pSEGS_FEATURE (pthis)->callback = NULL;
362             break;
363         case SCI_FEC:
364             pFEC_FEATURE (pthis)->callbacklen = 0;
365             pFEC_FEATURE (pthis)->callbackevent = 100;
366             FREE(pFEC_FEATURE (pthis)->callback);
367             pFEC_FEATURE (pthis)->callback = NULL;
368             break;
369         case SCI_GRAYPLOT:
370             pGRAYPLOT_FEATURE (pthis)->callbacklen = 0;
371             pGRAYPLOT_FEATURE (pthis)->callbackevent = 100;
372             FREE(pGRAYPLOT_FEATURE (pthis)->callback);
373             pGRAYPLOT_FEATURE (pthis)->callback = NULL;
374             break;
375         case SCI_POLYLINE:
376             pPOLYLINE_FEATURE (pthis)->callbacklen = 0;
377             pPOLYLINE_FEATURE (pthis)->callbackevent = 100;
378             FREE(pPOLYLINE_FEATURE (pthis)->callback);
379             pPOLYLINE_FEATURE (pthis)->callback = NULL;
380             break;
381         case SCI_UIMENU:
382         case SCI_TEXT:
383         case SCI_LEGEND:
384         case SCI_SURFACE:
385         case SCI_AXES:
386         case SCI_FIGURE:
387         case SCI_AGREG:
388         case SCI_LABEL: /* F.Leray 28.05.04 */
389         default:
390             Scierror(999, _("No Callback is associated with this Entity.\n"));
391             return -1;
392             break;
393     }
394     return 0;
395 }
396
397
398 /************************************ End of callback Functions ************************************/
399
400
401 /*----------------------------------------------------------------------------------------*/
402 /* Objmove                                                                                         */
403 /* move a handle in the graphic window                                                             */
404 /*----------------------------------------------------------------------------------------*/
405
406 static int moveObj(char* pobjUID, double displacement[], int displacementSize)
407 {
408     int i;
409     double x = displacement[0];
410     double y = displacement[1];
411     double z = (displacementSize == 3 ? displacement[2] : 0.0);
412
413     int iNum;
414     int *piNum = &iNum;
415     double* pdblData;
416     double* pdblDataY;
417     double* pdblDataZ;
418     char* pstType;
419
420     double* dataX = NULL;
421     double* dataY = NULL;
422     double* dataZ = NULL;
423
424     int iNumX = 0;
425     int iNumY = 0;
426     int iNumZ = 0;
427     int *piNumX = &iNumX;
428     int *piNumY = &iNumY;
429     int *piNumZ = &iNumZ;
430
431     int iChildrenCount = 0;
432     int *piChildrenCount = &iChildrenCount;
433     char **pstChildrenUID;
434
435     // Get type
436     getGraphicObjectProperty(pobjUID, __GO_TYPE__, jni_string, &pstType);
437
438     // If a Figure, neither the object nor its children are moved.
439     if ((strcmp(pstType, __GO_FIGURE__) == 0))
440     {
441         Scierror(999, _("This object can not be moved.\n"));
442         return -1;
443     }
444
445     // Iterate on children.
446     getGraphicObjectProperty(pobjUID, __GO_CHILDREN_COUNT__, jni_int, &piChildrenCount);
447
448     if (iChildrenCount != 0)
449     {
450         getGraphicObjectProperty(pobjUID, __GO_CHILDREN__, jni_string_vector, (void **) &pstChildrenUID);
451         for (i = 0 ; i < iChildrenCount ; ++i)
452         {
453             moveObj(pstChildrenUID[i], displacement, displacementSize);
454         }
455     }
456
457     // Arc.
458     if (strcmp(pstType, __GO_ARC__) == 0)
459     {
460         getGraphicObjectProperty(pobjUID, __GO_UPPER_LEFT_POINT__, jni_double_vector, &pdblData);
461         pdblData[0] += x;
462         pdblData[1] += y;
463         pdblData[2] += z;
464         setGraphicObjectProperty(pobjUID, __GO_UPPER_LEFT_POINT__, pdblData, jni_double_vector, 3);
465
466         return 0;
467     }
468     // Fac3d.
469     else if (strcmp(pstType, __GO_FAC3D__) == 0)
470     {
471         int iNumVPG = 0;
472         int* piNumVPG = &iNumVPG;
473
474         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, jni_int, &piNumVPG);
475         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_GONS__, jni_int, &piNum);
476
477         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
478         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
479         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, jni_double_vector, &dataZ);
480
481         for (i = 0; i < iNumVPG * iNum; i++)
482         {
483             dataX[i] += x;
484             dataY[i] += y;
485             dataZ[i] += z;
486         }
487
488         /* Model data has been updated by direct pointer access, trigger update within the renderer. */
489         setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, iNumVPG * iNum);
490
491         return 0;
492     }
493     // Fec.
494     else if (strcmp(pstType, __GO_FEC__) == 0)
495     {
496         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_VERTICES__, jni_int, &piNum);
497         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_COORDINATES__, jni_double_vector, &pdblData);
498
499         for (i = 0; i < iNum; i++)
500         {
501             pdblData[3 * i] += x;
502             pdblData[3 * i + 1] += y;
503             pdblData[3 * i + 2] += z;
504         }
505
506         setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_COORDINATES__, pdblData, jni_double_vector, 3 * iNum);
507
508         return 0;
509     }
510     // Grayplot.
511     else if (strcmp(pstType, __GO_GRAYPLOT__) == 0)
512     {
513         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_X__, jni_int, &piNumX);
514         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Y__, jni_int, &piNumY);
515
516         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
517         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
518
519         for (i = 0; i < iNumX; i++)
520         {
521             dataX[i] += x;
522         }
523
524         for (i = 0; i < iNumY; i++)
525         {
526             dataY[i] += y;
527         }
528
529         if (displacementSize == 3)
530         {
531             double zShift = 0.0;
532             double* pdZshift = &zShift;
533
534             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, jni_int, &pdZshift);
535             zShift += z;
536             setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, &zShift, jni_double, 1);
537         }
538         else
539         {
540             setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, iNumY);
541         }
542
543         return 0;
544     }
545     // Matplot.
546     else if (strcmp(pstType, __GO_MATPLOT__) == 0)
547     {
548         double zShift = 0.0;
549         double* pdZShift = &zShift;
550         //double* bounds = NULL;
551         int type;
552         int* itype = &type;
553
554         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_MATPLOT_TYPE__, jni_int, &itype);
555
556         /* Only type 1 Matplot objects can be moved. */
557         if (type == 1)
558         {
559             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_X__, jni_int, &piNumX);
560             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Y__, jni_int, &piNumY);
561
562             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
563             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
564
565             for (i = 0; i < iNumX; i++)
566             {
567                 dataX[i] += x;
568             }
569
570             for (i = 0; i < iNumY; i++)
571             {
572                 dataY[i] += y;
573             }
574
575             /* Bounds must be updated. */
576             //getGraphicObjectProperty(pobjUID, __GO_MATPLOT_BOUNDS__, jni_double_vector, &bounds);
577
578             //bounds[0] += x;
579             //bounds[1] += x;
580             //bounds[2] += y;
581             //bounds[3] += y;
582
583             if (displacementSize == 3)
584             {
585                 getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, jni_int, &pdZShift);
586                 zShift += z;
587                 setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, &zShift, jni_double, 1);
588             }
589             else
590             {
591                 setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, iNumY);
592             }
593
594             return 0;
595         }
596     }
597     // Polyline.
598     else if (strcmp(pstType, __GO_POLYLINE__) == 0)
599     {
600         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, jni_int, &piNum);
601
602         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
603         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
604
605         for (i = 0; i < iNum; i++)
606         {
607             dataX[i] += x;
608             dataY[i] += y;
609         }
610
611         if (displacementSize == 3)
612         {
613             int zCoordinatesSet = 1;
614
615             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, jni_double_vector, &dataZ);
616
617             for (i = 0; i < iNum; i++)
618             {
619                 dataZ[i] += z;
620             }
621
622             /* The z coordinates flag must be set explicitely for now. */
623             setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z_COORDINATES_SET__, &zCoordinatesSet, jni_int, 1);
624
625             /* Model data has been updated by direct pointer access, trigger update within the renderer. */
626             setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, iNum);
627         }
628         else
629         {
630             /* Trigger update, see above. */
631             setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, iNum);
632         }
633
634         return 0;
635     }
636     // Plot3d.
637     else if (strcmp(pstType, __GO_PLOT3D__) == 0)
638     {
639         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_X__, jni_int, &piNumX);
640         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Y__, jni_int, &piNumY);
641         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Z__, jni_int, &piNumZ);
642
643         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
644         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
645         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, jni_double_vector, &dataZ);
646
647         for (i = 0; i < iNumX; i++)
648         {
649             dataX[i] += x;
650         }
651
652         for (i = 0; i < iNumY; i++)
653         {
654             dataY[i] += y;
655         }
656
657         for (i = 0; i < iNumZ; i++)
658         {
659             dataZ[i] += z;
660         }
661
662         /*
663          * Perform only one set call to trigger geometry data update within the renderer module.
664          * Model data has been updated above by direct pointer access.
665          */
666         setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, dataZ, jni_double_vector, iNumZ);
667         return 0;
668     }
669     // Champ.
670     else if (strcmp(pstType, __GO_CHAMP__) == 0)
671     {
672         int *champDimensions = NULL;
673
674         getGraphicObjectProperty(pobjUID, __GO_CHAMP_DIMENSIONS__, jni_int_vector, &champDimensions);
675
676         getGraphicObjectProperty(pobjUID, __GO_BASE_X__, jni_double_vector, &pdblData);
677         getGraphicObjectProperty(pobjUID, __GO_BASE_Y__, jni_double_vector, &pdblDataY);
678
679         for (i = 0; i < champDimensions[0]; i++)
680         {
681             pdblData[i] += x;
682         }
683
684         for (i = 0; i < champDimensions[1]; i++)
685         {
686             pdblDataY[i] += y;
687         }
688
689         setGraphicObjectProperty(pobjUID, __GO_BASE_X__, pdblData, jni_double_vector, champDimensions[0]);
690         setGraphicObjectProperty(pobjUID, __GO_BASE_Y__, pdblDataY, jni_double_vector, champDimensions[1]);
691
692         if (displacementSize == 3)
693         {
694             getGraphicObjectProperty(pobjUID, __GO_BASE_Z__, jni_double_vector, &pdblDataZ);
695
696             for (i = 0; i < champDimensions[0]*champDimensions[1]; i++)
697             {
698                 pdblDataZ[i] += z;
699             }
700
701             setGraphicObjectProperty(pobjUID, __GO_BASE_Z__, pdblDataZ, jni_double_vector, champDimensions[0]*champDimensions[1]);
702         }
703         return 0;
704     }
705     // Label.
706     else if (strcmp(pstType, __GO_LABEL__) == 0)
707     {
708         getGraphicObjectProperty(pobjUID, __GO_POSITION__, jni_double_vector, &pdblData);
709         pdblData[0] += x;
710         pdblData[1] += y;
711         pdblData[2] += z;
712         setGraphicObjectProperty(pobjUID, __GO_POSITION__, pdblData, jni_double_vector, 3);
713
714         return 0;
715     }
716     // Rectangle.
717     else if (strcmp(pstType, __GO_RECTANGLE__) == 0)
718     {
719         getGraphicObjectProperty(pobjUID, __GO_UPPER_LEFT_POINT__, jni_double_vector, &pdblData);
720         pdblData[0] += x;
721         pdblData[1] += y;
722         pdblData[2] += z;
723         setGraphicObjectProperty(pobjUID, __GO_UPPER_LEFT_POINT__, pdblData, jni_double_vector, 3);
724
725         return 0;
726     }
727     // Segs.
728     else if (strcmp(pstType, __GO_SEGS__) == 0)
729     {
730         double* pdblDirection;
731
732         getGraphicObjectProperty(pobjUID, __GO_NUMBER_ARROWS__, jni_int, &piNum);
733         getGraphicObjectProperty(pobjUID, __GO_BASE__, jni_double_vector, &pdblData);
734         getGraphicObjectProperty(pobjUID, __GO_DIRECTION__, jni_double_vector, &pdblDirection);
735
736         for (i = 0; i < iNum; i++)
737         {
738             pdblData[3 * i] += x;
739             pdblData[3 * i + 1] += y;
740             pdblData[3 * i + 2] += z;
741         }
742
743         for (i = 0; i < iNum; i++)
744         {
745             pdblDirection[3 * i] += x;
746             pdblDirection[3 * i + 1] += y;
747             pdblDirection[3 * i + 2] += z;
748         }
749
750         setGraphicObjectProperty(pobjUID, __GO_BASE__, pdblData, jni_double_vector, 3 * iNum);
751         setGraphicObjectProperty(pobjUID, __GO_DIRECTION__, pdblDirection, jni_double_vector, 3 * iNum);
752
753         return 0;
754     }
755     // Text.
756     else if (strcmp(pstType, __GO_TEXT__) == 0)
757     {
758         getGraphicObjectProperty(pobjUID, __GO_POSITION__, jni_double_vector, &pdblData);
759         pdblData[0] += x;
760         pdblData[1] += y;
761         pdblData[2] += z;
762         setGraphicObjectProperty(pobjUID, __GO_POSITION__, pdblData, jni_double_vector, 3);
763
764         return 0;
765     }
766
767     if ((strcmp(pstType, __GO_AXES__) == 0) || (strcmp(pstType, __GO_COMPOUND__) == 0))
768     {
769         // Children already moved: Done.
770         return 0;
771     }
772
773     // Default error.
774     Scierror(999, _("This object can not be moved.\n"));
775     return -1;
776     /*
777         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_X__, jni_int, &piNumX);
778         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Y__, jni_int, &piNumY);
779
780         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, jni_double_vector, &dataX);
781         getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, jni_double_vector, &dataY);
782
783         // X
784         for (i = 0 ; i < iNumX ; ++i)
785         {
786             dataX[i] += x;
787         }
788         setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_X__, dataX, jni_double_vector, iNumX);
789
790         // Y
791         for (i = 0 ; i < iNumY ; ++i)
792         {
793             dataY[i] += y;
794         }
795         setGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Y__, dataY, jni_double_vector, iNumY);
796
797         // Z if needed
798         if (displacementSize == 3)
799         {
800             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_NUM_Z__, jni_int, &piNumZ);
801             getGraphicObjectProperty(pobjUID, __GO_DATA_MODEL_Z__, jni_double_vector, &dataZ);
802             for (i = 0 ; i < iNumZ ; ++i)
803             {
804                 dataZ[i] += z;
805             }
806         }
807
808         return 0;
809     */
810
811 #if 0
812     switch (sciGetEntityType (pobj))
813     {
814         case SCI_SUBWIN:
815         {
816             sciSons * psonstmp = sciGetSons(pobj);
817             while ((psonstmp != NULL) && (psonstmp->pointobj != NULL))
818             {
819                 moveObj(psonstmp->pointobj, displacement, displacementSize);
820                 psonstmp = psonstmp->pnext;
821             }
822         }
823         break;
824         case SCI_ARC:
825             pARC_FEATURE(pobj)->x += x;
826             pARC_FEATURE(pobj)->y += y;
827             if (displacementSize == 3) pARC_FEATURE(pobj)->z += z;
828             break;
829         case SCI_RECTANGLE:
830             pRECTANGLE_FEATURE(pobj)->x += x;
831             pRECTANGLE_FEATURE(pobj)->y += y;
832             if (displacementSize == 3) pRECTANGLE_FEATURE(pobj)->z += z;
833             break;
834         case SCI_AGREG:
835         {
836             sciSons * psonstmp = sciGetSons(pobj);
837             while ((psonstmp != NULL) && (psonstmp->pointobj != NULL))
838             {
839                 moveObj(psonstmp->pointobj, displacement, displacementSize);
840                 psonstmp = psonstmp->pnext;
841             }
842         }
843         break;
844         case SCI_TEXT:
845             pTEXT_FEATURE(pobj)->x += x;
846             pTEXT_FEATURE(pobj)->y += y;
847             if (displacementSize == 3) pTEXT_FEATURE(pobj)->z += z;
848             break;
849         case SCI_SEGS:
850             n = pSEGS_FEATURE(pobj)->Nbr1;
851             for (i = 0; i < n; i++)
852             {
853                 pSEGS_FEATURE(pobj)->vx[i] += x;
854                 pSEGS_FEATURE(pobj)->vy[i] += y;
855             }
856             if (displacementSize == 3)
857             {
858                 if  (pSEGS_FEATURE(pobj)->vz == (double *)NULL)
859                 {
860                     if ((pSEGS_FEATURE(pobj)->vz = MALLOC (n * sizeof (double))) == NULL)
861                     {
862                         return -1;
863                     }
864                     for (i = 0; i < n; i++)
865                     {
866                         pSEGS_FEATURE(pobj)->vz[i] = z;
867                     }
868                 }
869                 else
870                     for (i = 0; i < n; i++)
871                     {
872                         pSEGS_FEATURE(pobj)->vz[i] += z;
873                     }
874             }
875             break;
876         case SCI_POLYLINE:
877             n = pPOLYLINE_FEATURE(pobj)->n1;
878             for (i = 0; i < n; i++)
879             {
880                 pPOLYLINE_FEATURE(pobj)->pvx[i] += x;
881                 pPOLYLINE_FEATURE(pobj)->pvy[i] += y;
882             }
883             if (displacementSize == 3)
884             {
885                 if  (pPOLYLINE_FEATURE(pobj)->pvz == (double *)NULL)
886                 {
887                     if ((pPOLYLINE_FEATURE(pobj)->pvz = MALLOC (n * sizeof (double))) == NULL)
888                     {
889                         return -1;
890                     }
891                     for (i = 0; i < n; i++)
892                     {
893                         pPOLYLINE_FEATURE(pobj)->pvz[i] = z;
894                     }
895                 }
896                 else
897                 {
898                     for (i = 0; i < n; i++)
899                     {
900                         pPOLYLINE_FEATURE(pobj)->pvz[i] += z;
901                     }
902                 }
903             }
904             break;
905         case SCI_FEC:
906             for (i = 0; i < pFEC_FEATURE(pobj)->Nnode; i++)
907             {
908                 pFEC_FEATURE(pobj)->pvecx[i] += x;
909                 pFEC_FEATURE(pobj)->pvecy[i] += y;
910             }
911             break;
912         case SCI_GRAYPLOT:
913             if (pGRAYPLOT_FEATURE(pobj)->type == 2)
914             {
915                 /* Matplot 1, it is not possible to move a Matplot*/
916                 pGRAYPLOT_FEATURE(pobj)->pvecx[0] += x;
917                 pGRAYPLOT_FEATURE(pobj)->pvecx[2] += x;
918                 pGRAYPLOT_FEATURE(pobj)->pvecx[1] += y;
919                 pGRAYPLOT_FEATURE(pobj)->pvecx[3] += y;
920             }
921             else if (pGRAYPLOT_FEATURE(pobj)->type == 0)
922             {
923                 /* Grayplot */
924                 for (i = 0; i < pGRAYPLOT_FEATURE(pobj)->nx; i++)
925                 {
926                     pGRAYPLOT_FEATURE(pobj)->pvecx[i] += x;
927                 }
928                 for (i = 0; i < pGRAYPLOT_FEATURE(pobj)->ny; i++)
929                 {
930                     pGRAYPLOT_FEATURE(pobj)->pvecy[i] += y;
931                 }
932             }
933             else
934             {
935                 Scierror(999, _("This object can not be moved.\n"));
936                 return -1;
937             }
938
939             break;
940         case SCI_SURFACE:
941             switch (pSURFACE_FEATURE (pobj)->typeof3d)
942             {
943                 case SCI_FAC3D:
944                     n = pSURFACE_FEATURE (pobj)->dimzx * pSURFACE_FEATURE (pobj)->dimzy;
945                     for (i = 0; i < n; i++)
946                     {
947                         pSURFACE_FEATURE(pobj)->pvecx[i] += x;
948                         pSURFACE_FEATURE(pobj)->pvecy[i] += y;
949                     }
950                     if (displacementSize == 3)
951                     {
952                         if  (pSURFACE_FEATURE(pobj)->pvecz == (double *)NULL)
953                         {
954                             if ((pSURFACE_FEATURE(pobj)->pvecz = MALLOC (n * sizeof (double))) == NULL) return -1;
955                             for (i = 0; i < n; i++)
956                                 pSURFACE_FEATURE(pobj)->pvecz[i] = z;
957                         }
958                         else
959                             for (i = 0; i < n; i++)
960                                 pSURFACE_FEATURE(pobj)->pvecz[i] += z;
961                     }
962                     break;
963                 case SCI_PLOT3D:
964                     for (i = 0; i < pSURFACE_FEATURE (pobj)->dimzx; i++)
965                         pSURFACE_FEATURE(pobj)->pvecx[i] += x;
966                     for (i = 0; i < pSURFACE_FEATURE (pobj)->dimzy; i++)
967                         pGRAYPLOT_FEATURE(pobj)->pvecy[i] += y;
968                     if (displacementSize == 3)
969                     {
970                         n = pSURFACE_FEATURE (pobj)->dimzx * pSURFACE_FEATURE (pobj)->dimzy;
971                         if  (pSURFACE_FEATURE(pobj)->pvecz == (double *)NULL)
972                         {
973                             if ((pSURFACE_FEATURE(pobj)->pvecz = MALLOC (n * sizeof (double))) == NULL) return -1;
974                             for (i = 0; i < n; i++)
975                                 pSURFACE_FEATURE(pobj)->pvecz[i] = z;
976                         }
977                         else
978                             for (i = 0; i < n; i++)
979                                 pSURFACE_FEATURE(pobj)->pvecz[i] += z;
980                     }
981                     break;
982                 case SCI_CONTOUR:
983                 case SCI_PARAM3D:
984                 case SCI_PARAM3D1: /* Nothing to be done */
985                     break;
986             }
987             break;
988         case SCI_LABEL:
989         {
990             double pos[3];
991             sciGetTextPos(pobj, pos) ;
992             sciSetTextPos(pobj, pos[0] + x, pos[1] + y, pos[2] + z) ;
993             pLABEL_FEATURE(pobj)->auto_position = FALSE;
994             break;
995         }
996         case SCI_FIGURE:
997         case SCI_AXES:
998         case SCI_LEGEND:
999         case SCI_UIMENU:
1000         default:
1001             Scierror(999, _("This object can not be moved.\n"));
1002             return -1;
1003             break;
1004     }
1005
1006     /* update the object */
1007     forceMove(pobjUID, x, y, z);
1008 #endif
1009     return 0;
1010 }
1011
1012 int Objmove (char *pobjUID, double d[], int m, BOOL opt)
1013 {
1014     int status = moveObj(pobjUID, d, m);
1015 #if 0
1016     if (status < 0)
1017     {
1018         return status;
1019     }
1020
1021     if (opt)
1022     {
1023         /* should be sci draw single obj */
1024         sciDrawSingleObj(pobj);
1025     }
1026     else
1027     {
1028         sciDrawObj(sciGetParentFigure(pobj));
1029     }
1030 #endif
1031     return status;
1032 }
1033
1034 /*---------------------------------------------------------------------------------*/
1035 void interactiveZoom(sciPointObj * pObj)
1036 {
1037     if (sciGetEntityType(pObj) == SCI_FIGURE)
1038     {
1039         interactiveJavaZoom(pObj);
1040     }
1041     else if (sciGetEntityType(pObj) == SCI_SUBWIN)
1042     {
1043         interactiveJavaSubwinZoom(pObj);
1044     }
1045 }
1046 /*---------------------------------------------------------------------------------*/
1047 void interactiveRotation(sciPointObj * pFigure)
1048 {
1049     interactiveJavaRotation(pFigure);
1050 }
1051 /*---------------------------------------------------------------------------------*/
1052 void interactiveSubwinRotation(sciPointObj * pSubwin)
1053 {
1054     /* get coordinates of first mouse click */
1055     interactiveJavaSubwinRotation(pSubwin);
1056 }
1057 /*---------------------------------------------------------------------------------*/
1058 void showWindow(char * pFigureUID)
1059 {
1060     // @TODO: Call SwingView to raise window.
1061 }
1062