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 - Jean-Baptiste Silvy
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
14 /*------------------------------------------------------------------------*/
15 /* file: axesScale.c */
16 /* desc : Contains functions to compute scale changes in a specific */
18 /*------------------------------------------------------------------------*/
22 #include "axesScale.h"
23 #include "math_graphics.h"
24 #include "GetProperty.h"
25 #include "SetProperty.h"
27 #include "localization.h"
28 #include "SetPropertyStatus.h"
29 #include "SetJavaProperty.h"
30 #include "Interaction.h"
31 #include "JavaInteraction.h"
32 #include "HandleManagement.h"
34 #include "setGraphicObjectProperty.h"
35 #include "getGraphicObjectProperty.h"
36 #include "graphicObjectProperties.h"
38 /*------------------------------------------------------------------------------*/
40 * Specify new zoom box for a subwin object.
41 * @param subwinUID the subwin's identifier.
42 * @param zoomRect vector [xMin, yMin, xMax, yMax].
44 int sciZoom2D(int iSubwinUID, const double zoomRect[4])
48 double* zoomBox = NULL;
49 // add Z scale to data bounds.
50 getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **) &zoomBox);
52 zoomBox[0] = zoomRect[0];
53 zoomBox[1] = zoomRect[1];
54 zoomBox[2] = zoomRect[2];
55 zoomBox[3] = zoomRect[3];
57 return sciZoom3D(iSubwinUID, zoomBox);
61 return SET_PROPERTY_ERROR;
64 /*------------------------------------------------------------------------------*/
66 * Specify a new zoom box for a subwin object
67 * @param subwinUID the subwin's identifier.
68 * @param zoomBox vector [xMin, yMin, xMax, yMax, zMin, zMax].
70 int sciZoom3D(int iSubwinUID, const double zoomBox[6])
75 // convert zoomBox to [xMin, xMax, yMin, yMax, zMin, zMax]
77 zoomBox3D[0] = zoomBox[0];
78 zoomBox3D[1] = zoomBox[2];
79 zoomBox3D[2] = zoomBox[1];
80 zoomBox3D[3] = zoomBox[3];
81 zoomBox3D[4] = zoomBox[4];
82 zoomBox3D[5] = zoomBox[5];
84 if (!checkDataBounds(iSubwinUID, zoomBox3D[0], zoomBox3D[1], zoomBox3D[2],
85 zoomBox3D[3], zoomBox3D[4], zoomBox3D[5]))
87 return SET_PROPERTY_ERROR;
90 status = setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_BOX__, zoomBox3D, jni_double_vector, 6);
94 Scierror(999, _("'%s' property does not exist for this handle.\n"), "zoom_box");
95 return SET_PROPERTY_ERROR;
98 status = setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_ENABLED__, &zoomEnabled, jni_bool, 1);
102 return SET_PROPERTY_SUCCEED;
106 return SET_PROPERTY_ERROR;
110 /*------------------------------------------------------------------------------*/
111 int sciZoomRect(int iObjUID, const double zoomRect[4])
114 int *piType = &iType;
115 getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **) &piType);
116 if (iType == __GO_FIGURE__)
118 return sciFigureZoom2D(iObjUID, zoomRect);
120 else if (iType == __GO_AXES__)
122 return sciZoom2D(iObjUID, zoomRect);
126 return SET_PROPERTY_ERROR;
129 /*------------------------------------------------------------------------------*/
130 int sciFigureZoom2D(int iFigureUID, const double zoomRect[4])
133 int childrenCount = 0;
134 int* pChildrenCount = &childrenCount;
136 int* piChildren = NULL;
138 getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **) &pChildrenCount);
140 if ((pChildrenCount != NULL) && (childrenCount > 0))
142 getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **) &piChildren);
143 for (i = 0; i < childrenCount; i++)
145 sciZoomRect(piChildren[i], zoomRect);
149 return SET_PROPERTY_SUCCEED;
151 /*------------------------------------------------------------------------------*/
153 * Check if the following data bounds can be used as new data bounds for the subwin object
154 * @param subwinUID the subwin's identifier.
155 * @param the lower x bound.
156 * @param the upper x bound.
157 * @param the lower y bound.
158 * @param the upper y bound.
159 * @param the lower z bound.
160 * @param the upper z bound.
161 * @return TRUE if values can be used, false otherwise
163 BOOL checkDataBounds(int iSubwinUID, double xMin, double xMax,
164 double yMin, double yMax, double zMin, double zMax)
168 sciGetLogFlags(iSubwinUID, logFlags);
170 /* check if there is not an inf within the values */
171 /* since this has not any meaning */
172 if ( !finite(xMin) || !finite(xMax)
173 || !finite(yMin) || !finite(yMax)
174 || !finite(zMin) || !finite(zMax))
176 Scierror(999, "Error : data bounds values must be finite.");
180 /* check if the bounds are correct */
181 /* allows equality with bounds since it is working */
182 if (xMin > xMax || yMin > yMax || zMin > zMax)
184 Scierror(999, "Error : Min and Max values for one axis do not verify Min <= Max.\n");
188 /* check for logflags that values are greater than 0 */
189 if ( (logFlags[0] == 'l' && xMin <= 0.0)
190 || (logFlags[1] == 'l' && yMin <= 0.0)
191 || (logFlags[2] == 'l' && zMin <= 0.0))
193 Scierror(999, "Error: Bounds on axis must be strictly positive to use logarithmic mode.\n");
199 /*------------------------------------------------------------------------------*/
201 * Unzoom a single subwindow
203 void sciUnzoomSubwin(int iSubwinUID)
205 int iParentFigure = 0;
206 int* piParent = &iParentFigure;
209 getGraphicObjectProperty(iSubwinUID, __GO_PARENT_FIGURE__, jni_int, (void **) &piParent);
211 if (iSubwinUID == 0 || iParentFigure == 0)
216 setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
218 /*------------------------------------------------------------------------------*/
220 * Unzoom all the subwindows contained in a figure
222 void sciUnzoomFigure(int iFigureUID)
225 int *piType = &iType;
226 int* piChildrenUID = NULL;
230 int childrenCount = 0;
231 int* piChildrenCount = &childrenCount;
233 getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **) &piChildrenUID);
234 getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **) &piChildrenCount);
236 if (piChildrenCount != NULL)
239 for (i = 0; i < childrenCount; i++)
241 getGraphicObjectProperty(piChildrenUID[i], __GO_TYPE__, jni_int, (void **) &piType);
242 if (iType == __GO_AXES__)
244 setGraphicObjectProperty(piChildrenUID[i], __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
249 /*------------------------------------------------------------------------------*/
251 * Unzoom a set of subwindows and figures
252 * @param objectsUID array of figure and subwindow objects id.
253 * @param nbObjects number of objects.
255 void sciUnzoomArray(int* piObjUID, int nbObjects)
259 int *piType = &iType;
261 for (i = 0; i < nbObjects; i++)
263 getGraphicObjectProperty(piObjUID[i], __GO_TYPE__, jni_int, (void **) &piType);
264 if (iType == __GO_FIGURE__)
266 /* Unzoom all subwindows of the figure */
267 sciUnzoomFigure(piObjUID[i]);
269 else if (iType == __GO_AXES__)
271 /* Unzoom the axes */
272 sciUnzoomSubwin(piObjUID[i]);
277 /*--------------------------------------------------------------------------------*/
278 void updateSubwinScale(int iSubwinUID)
280 sciJavaUpdateSubwinScale(iSubwinUID);
282 /*------------------------------------------------------------------------------*/
283 void updateTextBounds(int iTextUID)
286 int* piParent = &iParentAxes;
288 /* Update coordinate transformation if needed */
289 getGraphicObjectProperty(iTextUID, __GO_PARENT_AXES__, jni_int, (void **) &piParent);
290 updateSubwinScale(iParentAxes);
292 /* Compute the bounding box of the text */
293 sciJavaUpdateTextBoundingBox(iTextUID);
295 /*------------------------------------------------------------------------------*/