1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 /*------------------------------------------------------------------------*/
17 /* file: set_rect_property.c                                         */
18 /* desc : function to modify in Scilab the rect field of             */
19 /*        a matplot handle                                                        */
20 /*------------------------------------------------------------------------*/
21 
22 #include "setHandleProperty.h"
23 #include "SetProperty.h"
24 #include "getPropertyAssignedValue.h"
25 #include "Scierror.h"
26 #include "localization.h"
27 #include "SetPropertyStatus.h"
28 #include "getGraphicObjectProperty.h"
29 
30 #include "setGraphicObjectProperty.h"
31 #include "graphicObjectProperties.h"
32 
33 /*------------------------------------------------------------------------*/
set_rect_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)34 int set_rect_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
35 {
36     BOOL status = FALSE;
37     double * rect = (double*)_pvData;
38     double pdblScale[2];
39     int numX;
40     int * piNumX = &numX;
41     int numY;
42     int * piNumY = &numY;
43 
44     if (valueType != sci_matrix)
45     {
46         Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "rect");
47         return SET_PROPERTY_ERROR;
48     }
49 
50     if (nbRow * nbCol != 4)
51     {
52         Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "rect", 4);
53         return SET_PROPERTY_ERROR;
54     }
55 
56     status = setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_MATPLOT_BOUNDS__, _pvData, jni_double_vector, 4);
57     if (status == TRUE)
58     {
59         getGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_NUM_X__, jni_int, (void **)&piNumX);
60         getGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_NUM_Y__, jni_int, (void **)&piNumY);
61         setGraphicObjectProperty(iObjUID, __GO_MATPLOT_TRANSLATE__, _pvData, jni_double_vector, 2);
62         pdblScale[0] = (rect[2] - rect[0]) / (numX - 1.0);
63         pdblScale[1] = (rect[3] - rect[1]) / (numY - 1.0);
64         setGraphicObjectProperty(iObjUID, __GO_MATPLOT_SCALE__, pdblScale, jni_double_vector, 2);
65 
66         return SET_PROPERTY_SUCCEED;
67     }
68     else
69     {
70         Scierror(999, _("'%s' property does not exist for this handle.\n"), "margins");
71         return SET_PROPERTY_ERROR;
72     }
73 }
74 /*------------------------------------------------------------------------*/
75