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) 2009 - DIGITEO - Pierre Lando
7  * Copyright (C) 2010 - DIGITEO - Manuel Juliachs
8  *
9  * Copyright (C) 2012 - 2016 - Scilab Enterprises
10  *
11  * This file is hereby licensed under the terms of the GNU GPL v2.0,
12  * pursuant to article 5.3.4 of the CeCILL v.2.1.
13  * This file was originally licensed under the terms of the CeCILL v2.1,
14  * and continues to be available under such terms.
15  * For more information, see the COPYING file which you should have received
16  * along with this program.
17  *
18  */
19 
20 /*------------------------------------------------------------------------*/
21 /* file: set_data_bounds_property.c                                       */
22 /* desc : function to modify in Scilab the data_bounds field of           */
23 /*        a handle                                                        */
24 /*------------------------------------------------------------------------*/
25 
26 #include "setHandleProperty.h"
27 #include "SetProperty.h"
28 #include "getPropertyAssignedValue.h"
29 #include "SetPropertyStatus.h"
30 #include "Scierror.h"
31 #include "localization.h"
32 #include "axesScale.h"
33 
34 #include "getGraphicObjectProperty.h"
35 #include "setGraphicObjectProperty.h"
36 #include "graphicObjectProperties.h"
37 
38 /*------------------------------------------------------------------------*/
39 int getdDataBoundsFromStack(double* pdblBounds, int nbRow, int nbCol,
40                             double* xMin, double* xMax,
41                             double* yMin, double* yMax,
42                             double* zMin, double* zMax);
43 /*------------------------------------------------------------------------*/
44 /**
45  * fill bounds (xMin, xMax, yMin,...) from the assigned value in the stack
46  * beacause it might have several possible size.
47  */
getdDataBoundsFromStack(double * pdblBounds,int nbRow,int nbCol,double * xMin,double * xMax,double * yMin,double * yMax,double * zMin,double * zMax)48 int getdDataBoundsFromStack(double* pdblBounds, int nbRow, int nbCol,
49                             double* xMin, double* xMax,
50                             double* yMin, double* yMax,
51                             double* zMin, double* zMax)
52 {
53     /* initialize zMin and zMax to avoid checking between 2D and 3D */
54     *zMin = 1.0;
55     *zMax = 2.0;
56 
57     if (nbRow == 3) /* Remove the 3x2 case */
58     {
59         Scierror(999, _("Wrong size for '%s' property: Must be in the set {%s}.\n"), "data_bounds", "1x4, 1x6, 2x2, 2x3, 4x1, 6x1");
60         return SET_PROPERTY_ERROR;
61     }
62 
63     switch (nbRow * nbCol)
64     {
65         case 4 : /* 2D case */
66             *xMin = pdblBounds[0];
67             *xMax = pdblBounds[1];
68             *yMin = pdblBounds[2];
69             *yMax = pdblBounds[3];
70             break;
71 
72         case 6 : /* 3D case */
73             *xMin = pdblBounds[0];
74             *xMax = pdblBounds[1];
75             *yMin = pdblBounds[2];
76             *yMax = pdblBounds[3];
77             *zMin = pdblBounds[4];
78             *zMax = pdblBounds[5];
79             break;
80         default:
81             Scierror(999, _("Wrong size for '%s' property: Must be in the set {%s}.\n"), "data_bounds", "1x4, 1x6, 2x2, 2x3, 4x1, 6x1");
82             return SET_PROPERTY_ERROR;
83     }
84 
85     return SET_PROPERTY_SUCCEED;
86 }
87 
88 /*------------------------------------------------------------------------*/
set_data_bounds_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)89 int set_data_bounds_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
90 {
91     BOOL status = FALSE;
92 
93     /* JB Silvy 09/11/05 */
94     double   xMin = 0.;
95     double   xMax = 0.;
96     double   yMin = 0.;
97     double   yMax = 0.;
98     double   zMin = 0.;
99     double   zMax = 0.;
100     int firstPlot = 0;
101 
102     if (valueType != sci_matrix)
103     {
104         Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "data_bounds");
105         return SET_PROPERTY_ERROR;
106     }
107 
108     /* get the bounds */
109     if (getdDataBoundsFromStack((double*)_pvData, nbRow, nbCol, &xMin, &xMax, &yMin, &yMax, &zMin, &zMax) == SET_PROPERTY_ERROR)
110     {
111         return SET_PROPERTY_ERROR;
112     }
113 
114     /* To be implemented within the MVC */
115     if (!checkDataBounds(iObjUID, xMin, xMax, yMin, yMax, zMin, zMax))
116     {
117         return SET_PROPERTY_ERROR;
118     }
119 
120     /* copy the values in the axis */
121     if (nbRow * nbCol == 4)
122     {
123         /* 2D */
124         double bounds[6];
125         double* tmpBounds;
126 
127         /* To get the Z coordinates */
128         getGraphicObjectProperty(iObjUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&tmpBounds);
129 
130         if (tmpBounds == NULL)
131         {
132             Scierror(999, _("'%s' property does not exist for this handle.\n"), "data_bounds");
133             return SET_PROPERTY_ERROR;
134         }
135 
136         bounds[0] = xMin;
137         bounds[1] = xMax;
138         bounds[2] = yMin;
139         bounds[3] = yMax;
140         bounds[4] = tmpBounds[4];
141         bounds[5] = tmpBounds[5];
142 
143         status = setGraphicObjectProperty(iObjUID, __GO_DATA_BOUNDS__, bounds, jni_double_vector, 6);
144     }
145     else
146     {
147         /* 3D */
148         double bounds[6] = {xMin, xMax, yMin, yMax, zMin, zMax};
149 
150         status = setGraphicObjectProperty(iObjUID, __GO_DATA_BOUNDS__, bounds, jni_double_vector, 6);
151     }
152 
153     setGraphicObjectProperty(iObjUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);
154 
155     if (status == TRUE)
156     {
157         return SET_PROPERTY_SUCCEED;
158     }
159     else
160     {
161         Scierror(999, _("'%s' property does not exist for this handle.\n"), "data_bounds");
162         return SET_PROPERTY_ERROR;
163     }
164 }
165 /*------------------------------------------------------------------------*/
166