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-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 /*------------------------------------------------------------------------------*/
39 static void zoomSubwin(sciPointObj * pSubwin, int posX, int posY, int width, int height);
40 static void zoomFigure(sciPointObj * pFigure, int posX, int posY, int width, int height);
41 /*------------------------------------------------------------------------------*/
43 * Specify new zoom box for a subwin object.
44 * @param subwinUID the subwin's identifier.
45 * @param zoomRect vector [xMin, yMin, xMax, yMax].
47 int sciZoom2D(char * subwinUID, const double zoomRect[4])
51 // add Z scale to data bounds.
52 getGraphicObjectProperty(subwinUID, __GO_DATA_BOUNDS__, jni_double_vector, &zoomBox);
54 zoomBox[0] = zoomRect[0];
55 zoomBox[1] = zoomRect[1];
56 zoomBox[2] = zoomRect[2];
57 zoomBox[3] = zoomRect[3];
59 return sciZoom3D(subwinUID, zoomBox);
61 /*------------------------------------------------------------------------------*/
63 * Specify a new zoom box for a subwin object
64 * @param subwinUID the subwin's identifier.
65 * @param zoomBox vector [xMin, yMin, xMax, yMax, zMin, zMax].
67 int sciZoom3D(char * subwinUID, const double zoomBox[6])
72 // convert zoomBox to [xMin, xMax, yMin, yMax, zMin, zMax]
74 zoomBox3D[0] = zoomBox[0];
75 zoomBox3D[1] = zoomBox[2];
76 zoomBox3D[2] = zoomBox[1];
77 zoomBox3D[3] = zoomBox[3];
78 zoomBox3D[4] = zoomBox[4];
79 zoomBox3D[5] = zoomBox[5];
81 if (!checkDataBounds(subwinUID, zoomBox3D[0], zoomBox3D[1], zoomBox3D[2],
82 zoomBox3D[3], zoomBox3D[4], zoomBox3D[5]))
84 return SET_PROPERTY_ERROR;
87 status = setGraphicObjectProperty(subwinUID, __GO_ZOOM_BOX__, zoomBox3D, jni_double_vector, 6);
91 Scierror(999, _("'%s' property does not exist for this handle.\n"),"zoom_box");
92 return SET_PROPERTY_ERROR;
95 status = setGraphicObjectProperty(subwinUID, __GO_ZOOM_ENABLED__, &zoomEnabled, jni_bool, 1);
99 return SET_PROPERTY_SUCCEED;
103 return SET_PROPERTY_ERROR;
107 /*------------------------------------------------------------------------------*/
109 * get the zoom box to dispplay in Scilab for a sunwin object
110 * @param[out] zoomBox [xMin, yMin, xMax, yMax, zMin, zMax];
112 void sciGetZoom3D(sciPointObj * pObj, double zoomBox[6])
116 // here we get [xMin, xMax, yMin, yMax, zMin, zMax]
117 // we need to switch xMax and yMin
118 sciGetZoomBox(pObj, zoomBox);
120 zoomBox[1] = zoomBox[2];
123 /*------------------------------------------------------------------------------*/
124 int sciZoomRect(sciPointObj * pObj, const double zoomRect[4])
126 int status = SET_PROPERTY_ERROR;
127 if (sciGetEntityType(pObj) == SCI_FIGURE)
129 status = sciFigureZoom2D(pObj, zoomRect);
131 else if (sciGetEntityType(pObj) == SCI_SUBWIN)
133 status = sciZoom2D(pObj, zoomRect);
136 /* redraw everything */
137 if (status == SET_PROPERTY_SUCCEED)
144 /*------------------------------------------------------------------------------*/
145 int sciDefaultZoom2D(const double zoomRect[4])
147 sciPointObj * curFigure = NULL;
148 //startGraphicDataWriting();
149 curFigure = sciGetCurrentFigure();
150 //endGraphicDataWriting();
152 return sciZoomRect(curFigure, zoomRect);
154 /*------------------------------------------------------------------------------*/
155 int sciFigureZoom2D(sciPointObj * figure, const double zoomRect[4])
157 /* try to zoom on all the subwindows */
158 sciSons * pSons = sciGetSons(figure);
159 while (pSons != NULL)
161 sciPointObj * curObj = pSons->pointobj;
162 if (sciGetEntityType(curObj) == SCI_SUBWIN)
164 int status = sciZoom2D(curObj, zoomRect);
165 if (status == SET_PROPERTY_SUCCEED)
167 //forceRedraw(curObj);
171 return SET_PROPERTY_ERROR;
174 pSons = pSons->pnext;
177 return SET_PROPERTY_SUCCEED;
180 /*------------------------------------------------------------------------------*/
182 * Try to zoom on a single subwindow using a selection area
184 static void zoomSubwin(sciPointObj * pSubwin, int posX, int posY, int width, int height)
186 if (sciJavaZoomRect(pSubwin, posX, posY, width, height))
188 /* subwindow has been zoomed */
190 sciSetZooming(pSubwin, TRUE);
192 // window has changed
193 //forceRedraw(pSubwin);
196 /*------------------------------------------------------------------------------*/
198 * Zoom a figure using an already computed selection area
200 static void zoomFigure(sciPointObj * pFigure, int posX, int posY, int width, int height)
202 /* try to zoom on all the subwindows */
203 sciSons * pSons = sciGetSons(pFigure);
204 while (pSons != NULL)
206 sciPointObj * curObj = pSons->pointobj;
207 if (sciGetEntityType(curObj) == SCI_SUBWIN)
209 zoomSubwin(curObj, posX, posY, width, height);
211 pSons = pSons->pnext;
214 /*------------------------------------------------------------------------------*/
215 void sciZoomObject(sciPointObj * pObj, int x1, int y1, int x2, int y2)
217 /* convert found data to [x,y,w,h] */
220 int w = Abs(x1 - x2);
221 int h = Abs(y1 - y2);
223 if (w == 0 || h == 0)
225 /* Zoom is not possible */
229 if (sciGetEntityType(pObj) == SCI_FIGURE)
231 zoomFigure(pObj, x, y, w, h);
233 else if (sciGetEntityType(pObj) == SCI_SUBWIN)
235 zoomSubwin(pObj, x, y, w, h);
238 /*------------------------------------------------------------------------------*/
240 * Perform an interactive zoom (rectangular selection + zoom)
241 * @param pObj object on which the zoom will be applied.
242 * Might be a Figure or a Subwindow. If it is a figure the zoom
243 * is applied to the axes children of the figure
245 void sciInteractiveZoom(sciPointObj * pObj)
247 interactiveZoom(pObj);
249 /*------------------------------------------------------------------------------*/
251 * Perform a zoom rect (rectangular selection + zoom) on the current figure
253 void sciDefaultInteractiveZoom(void)
255 sciPointObj * curFigure;
257 // startGraphicDataWriting();
258 curFigure = sciGetCurrentFigure();
259 //endGraphicDataWriting();
262 /* zoom current figure */
263 interactiveZoom(curFigure);
265 /*------------------------------------------------------------------------------*/
267 * Check if the following data bounds can be used as new data bounds for the subwin object
268 * @param subwinUID the subwin's identifier.
269 * @param the lower x bound.
270 * @param the upper x bound.
271 * @param the lower y bound.
272 * @param the upper y bound.
273 * @param the lower z bound.
274 * @param the upper z bound.
275 * @return TRUE if values can be used, false otherwise
277 BOOL checkDataBounds(char * subwinUID, double xMin, double xMax,
278 double yMin, double yMax, double zMin, double zMax)
282 sciGetLogFlags(subwinUID, logFlags);
284 /* check if there is not an inf within the values */
285 /* since this has not any meaning */
286 if ( !finite(xMin) || !finite(xMax)
287 || !finite(yMin) || !finite(yMax)
288 || !finite(zMin) || !finite(zMax) )
290 Scierror(999, "Error : data bounds values must be finite.");
294 /* check if the bounds are correct */
295 /* allows equality with bounds since it is working */
296 if ( xMin > xMax || yMin > yMax || zMin > zMax )
298 Scierror(999, "Error : Min and Max values for one axis do not verify Min <= Max.\n");
302 /* check for logflags that values are greater than 0 */
303 if ( ( logFlags[0] == 'l' && xMin <= 0.0 )
304 || ( logFlags[1] == 'l' && yMin <= 0.0 )
305 || ( logFlags[2] == 'l' && zMin <= 0.0 ) )
307 Scierror(999, "Error: Bounds on axis must be strictly positive to use logarithmic mode.\n" );
313 /*------------------------------------------------------------------------------*/
315 * Unzoom a single subwindow
317 void sciUnzoomSubwin(char* subwinUID)
319 char* parentFigure = NULL;
322 getGraphicObjectProperty(subwinUID, __GO_PARENT_FIGURE__, jni_string, (void **) &parentFigure);
324 if( subwinUID == NULL || parentFigure == NULL )
329 setGraphicObjectProperty(subwinUID, __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
331 /*------------------------------------------------------------------------------*/
332 void unzoomSubwin(sciPointObj * pSubwin)
335 currentStatus = sciSetZooming(pSubwin, FALSE);
336 if (currentStatus == 0)
338 /* redraw only if needed */
339 //forceRedraw(pSubwin);
342 /*------------------------------------------------------------------------------*/
344 * Unzoom all the subwindows contained in a figure
346 void sciUnzoomFigure(char* figureUID)
349 char** pstChildrenUID;
354 int* piChildrenCount = &childrenCount;
356 getGraphicObjectProperty(figureUID, __GO_CHILDREN__, jni_string_vector, (void **) &pstChildrenUID);
357 getGraphicObjectProperty(figureUID, __GO_CHILDREN_COUNT__, jni_int, (void **) &piChildrenCount);
359 if (piChildrenCount != NULL)
362 for (i = 0; i < childrenCount; i++)
364 getGraphicObjectProperty(pstChildrenUID[i], __GO_TYPE__, jni_string, (void **) &pstType);
365 if (strcmp(pstType, __GO_AXES__) == 0)
366 setGraphicObjectProperty(pstChildrenUID[i], __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
370 /*------------------------------------------------------------------------------*/
372 * Unzoom a set of subwindows and figures
373 * @param objectsUID array of figure and subwindow objects id.
374 * @param nbObjects number of objects.
376 void sciUnzoomArray(char* objectsUID[], int nbObjects)
381 for (i = 0; i < nbObjects; i++)
383 getGraphicObjectProperty(objectsUID[i], __GO_TYPE__, jni_string, (void **) &pstType);
384 if (strcmp(pstType, __GO_FIGURE__) == 0)
386 /* Unzoom all subwindows of the figure */
387 sciUnzoomFigure(objectsUID[i]);
389 else if (strcmp(pstType, __GO_AXES__) == 0)
391 /* Unzoom the axes */
392 sciUnzoomSubwin(objectsUID[i]);
397 /*--------------------------------------------------------------------------------*/
398 void updateSubwinScale(char * pSubwinUID)
400 sciJavaUpdateSubwinScale(pSubwinUID);
402 /*------------------------------------------------------------------------------*/
403 void updateTextBounds(char * pTextUID)
405 char* parentAxes = NULL;
407 /* Update coordinate transformation if needed */
408 getGraphicObjectProperty(pTextUID, __GO_PARENT_AXES__, jni_string, &parentAxes);
409 updateSubwinScale(parentAxes);
411 /* Compute the bounding box of the text */
412 sciJavaUpdateTextBoundingBox(pTextUID);
414 /*------------------------------------------------------------------------------*/