1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
4  * Copyright (C) 2006 - INRIA - Allan Cornet
5  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
6  * Copyright (C) 2010 - DIGITEO - Manuel Juliachs
7  *
8  * Copyright (C) 2012 - 2016 - Scilab Enterprises
9  *
10  * This file is hereby licensed under the terms of the GNU GPL v2.0,
11  * pursuant to article 5.3.4 of the CeCILL v.2.1.
12  * This file was originally licensed under the terms of the CeCILL v2.1,
13  * and continues to be available under such terms.
14  * For more information, see the COPYING file which you should have received
15  * along with this program.
16  *
17  */
18 
19 /*------------------------------------------------------------------------*/
20 /* file: set_z_shift_property.c                                           */
21 /* desc : function to modify in Scilab the z_shift field of               */
22 /*        a handle                                                        */
23 /*------------------------------------------------------------------------*/
24 
25 #include "setHandleProperty.h"
26 #include "SetProperty.h"
27 #include "getPropertyAssignedValue.h"
28 #include "Scierror.h"
29 #include "localization.h"
30 #include "GetProperty.h"
31 #include "sci_malloc.h"
32 #include "SetPropertyStatus.h"
33 
34 #include "getGraphicObjectProperty.h"
35 #include "setGraphicObjectProperty.h"
36 #include "graphicObjectProperties.h"
37 
38 /*------------------------------------------------------------------------*/
set_z_shift_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)39 int set_z_shift_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
40 {
41     BOOL result = FALSE;
42     double* shiftCoordinates = NULL;
43     int nbElement = nbRow * nbCol;
44     int iNumElements = 0;
45     int* piNumElements = &iNumElements;
46 
47     if (valueType != sci_matrix)
48     {
49         Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "z_shift");
50         return SET_PROPERTY_ERROR;
51     }
52 
53     if (nbRow > 1 && nbCol > 1)
54     {
55         Scierror(999, _("Wrong size for '%s' property: Must be in the set {%s}.\n"), "z_shift", "0x0, 1xn, nx1");
56         return SET_PROPERTY_ERROR;
57     }
58 
59     getGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void**)&piNumElements);
60 
61     if (piNumElements == NULL)
62     {
63         Scierror(999, _("'%s' property does not exist for this handle.\n"), "z_shift");
64         return SET_PROPERTY_ERROR;
65     }
66 
67     if (nbElement != 0 && nbElement != iNumElements) /* we can specify [] (null vector) to reset to default */
68     {
69         Scierror(999, _("Wrong size for '%s' property: %d or %d elements expected.\n"), "z_shift", 0, iNumElements);
70         return SET_PROPERTY_ERROR;
71     }
72 
73     if (nbElement != 0)
74     {
75         shiftCoordinates = (double*)_pvData;
76 
77         result = setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT__, shiftCoordinates, jni_double_vector, iNumElements);
78 
79         /* The FALSE value is used for now to identify a failed memory allocation */
80         if (result == FALSE)
81         {
82             Scierror(999, _("%s: No more memory.\n"), "set_z_shift_property");
83             return SET_PROPERTY_ERROR;
84         }
85     }
86     else
87     {
88         /*
89          * Setting the shift flag to 0 directly in the model
90          * when filling the shift coordinates array (0-element case)
91          * would probably be better.
92          */
93         int shiftSet = 0;
94         setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_Z_COORDINATES_SHIFT_SET__, &shiftSet, jni_double_vector, 1);
95     }
96 
97     return SET_PROPERTY_SUCCEED;
98 }
99 /*------------------------------------------------------------------------*/
100