summaryrefslogtreecommitdiff
path: root/modules/graphics/src/c/axesScale.c
blob: 938ae303ed67f3a7b32ea4a59f562f6164d919e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
 *
 * This file must be used under the terms of the CeCILL.
 * This source file is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at
 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 *
 */

/*------------------------------------------------------------------------*/
/* file: axesScale.c                                                      */
/* desc : Contains functions to compute scale changes in a specific       */
/*        subwindow.                                                      */
/*------------------------------------------------------------------------*/

#include <string.h>

#include "axesScale.h"
#include "math_graphics.h"
#include "GetProperty.h"
#include "SetProperty.h"
#include "Scierror.h"
#include "localization.h"
#include "SetPropertyStatus.h"
#include "SetJavaProperty.h"
#include "Interaction.h"
#include "JavaInteraction.h"
#include "HandleManagement.h"

#include "setGraphicObjectProperty.h"
#include "getGraphicObjectProperty.h"
#include "graphicObjectProperties.h"

/*------------------------------------------------------------------------------*/
/**
 * Specify new zoom box for a subwin object.
 * @param subwinUID the subwin's identifier.
 * @param zoomRect vector [xMin, yMin, xMax, yMax].
 */
int sciZoom2D(int iSubwinUID, const double zoomRect[4])
{
    if (iSubwinUID != 0)
    {
        double* zoomBox = NULL;
        // add Z scale to data bounds.
        getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **) &zoomBox);

        zoomBox[0] = zoomRect[0];
        zoomBox[1] = zoomRect[1];
        zoomBox[2] = zoomRect[2];
        zoomBox[3] = zoomRect[3];

        return sciZoom3D(iSubwinUID, zoomBox);
    }
    else
    {
        return SET_PROPERTY_ERROR;
    }
}
/*------------------------------------------------------------------------------*/
/**
 * Specify a new zoom box for a subwin object
 * @param subwinUID the subwin's identifier.
 * @param zoomBox vector [xMin, yMin, xMax, yMax, zMin, zMax].
 */
int sciZoom3D(int iSubwinUID, const double zoomBox[6])
{
    BOOL status = FALSE;
    int zoomEnabled = 1;

    // convert zoomBox to [xMin, xMax, yMin, yMax, zMin, zMax]
    double zoomBox3D[6];
    zoomBox3D[0] = zoomBox[0];
    zoomBox3D[1] = zoomBox[2];
    zoomBox3D[2] = zoomBox[1];
    zoomBox3D[3] = zoomBox[3];
    zoomBox3D[4] = zoomBox[4];
    zoomBox3D[5] = zoomBox[5];

    if (!checkDataBounds(iSubwinUID, zoomBox3D[0], zoomBox3D[1], zoomBox3D[2],
                         zoomBox3D[3], zoomBox3D[4], zoomBox3D[5]))
    {
        return SET_PROPERTY_ERROR;
    }

    status = setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_BOX__, zoomBox3D, jni_double_vector, 6);

    if (status != TRUE)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "zoom_box");
        return SET_PROPERTY_ERROR;
    }

    status = setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_ENABLED__, &zoomEnabled, jni_bool, 1);

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        return SET_PROPERTY_ERROR;
    }

}
/*------------------------------------------------------------------------------*/
int sciZoomRect(int iObjUID, const double zoomRect[4])
{
    int iType = -1;
    int *piType = &iType;
    getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void **) &piType);
    if (iType == __GO_FIGURE__)
    {
        return sciFigureZoom2D(iObjUID, zoomRect);
    }
    else if (iType == __GO_AXES__)
    {
        return sciZoom2D(iObjUID, zoomRect);
    }
    else
    {
        return SET_PROPERTY_ERROR;
    }
}
/*------------------------------------------------------------------------------*/
int sciFigureZoom2D(int iFigureUID, const double zoomRect[4])
{
    int i = 0;
    int childrenCount = 0;
    int* pChildrenCount = &childrenCount;

    int* piChildren = NULL;

    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **) &pChildrenCount);

    if ((pChildrenCount != NULL) && (childrenCount > 0))
    {
        getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **) &piChildren);
        for (i = 0; i < childrenCount; i++)
        {
            sciZoomRect(piChildren[i], zoomRect);
        }
    }

    return SET_PROPERTY_SUCCEED;
}
/*------------------------------------------------------------------------------*/
/**
 * Check if the following data bounds can be used as new data bounds for the subwin object
 * @param subwinUID the subwin's identifier.
 * @param the lower x bound.
 * @param the upper x bound.
 * @param the lower y bound.
 * @param the upper y bound.
 * @param the lower z bound.
 * @param the upper z bound.
 * @return TRUE if values can be used, false otherwise
 */
BOOL checkDataBounds(int iSubwinUID, double xMin, double xMax,
                     double yMin, double yMax, double zMin, double zMax)
{
    char logFlags[3];

    sciGetLogFlags(iSubwinUID, logFlags);

    /* check if there is not an inf within the values */
    /* since this has not any meaning */
    if (   !finite(xMin) || !finite(xMax)
            || !finite(yMin) || !finite(yMax)
            || !finite(zMin) || !finite(zMax))
    {
        Scierror(999, "Error : data bounds values must be finite.");
        return FALSE;
    }

    /* check if the bounds are correct */
    /* allows equality with bounds since it is working */
    if (xMin > xMax || yMin > yMax || zMin > zMax)
    {
        Scierror(999, "Error : Min and Max values for one axis do not verify Min <= Max.\n");
        return FALSE;
    }

    /* check for logflags that values are greater than 0 */
    if (  (logFlags[0] == 'l' && xMin <= 0.0)
            || (logFlags[1] == 'l' && yMin <= 0.0)
            || (logFlags[2] == 'l' && zMin <= 0.0))
    {
        Scierror(999, "Error: Bounds on axis must be strictly positive to use logarithmic mode.\n");
        return FALSE;
    }

    return TRUE;
}
/*------------------------------------------------------------------------------*/
/**
 * Unzoom a single subwindow
 */
void sciUnzoomSubwin(int iSubwinUID)
{
    int iParentFigure = 0;
    int* piParent = &iParentFigure;
    int zoomEnabled = 0;

    getGraphicObjectProperty(iSubwinUID, __GO_PARENT_FIGURE__, jni_int, (void **) &piParent);

    if (iSubwinUID == 0 || iParentFigure == 0)
    {
        return;
    }

    setGraphicObjectProperty(iSubwinUID, __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
}
/*------------------------------------------------------------------------------*/
/**
 * Unzoom all the subwindows contained in a figure
 */
void sciUnzoomFigure(int iFigureUID)
{
    int iType = -1;
    int *piType = &iType;
    int* piChildrenUID = NULL;

    int i = 0;
    int zoomEnabled = 0;
    int childrenCount = 0;
    int* piChildrenCount = &childrenCount;

    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN__, jni_int_vector, (void **) &piChildrenUID);
    getGraphicObjectProperty(iFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **) &piChildrenCount);

    if (piChildrenCount != NULL)
    {

        for (i = 0; i < childrenCount; i++)
        {
            getGraphicObjectProperty(piChildrenUID[i], __GO_TYPE__, jni_int, (void **) &piType);
            if (iType == __GO_AXES__)
            {
                setGraphicObjectProperty(piChildrenUID[i], __GO_ZOOM_ENABLED__, (void **) &zoomEnabled, jni_bool, 1);
            }
        }
    }
}
/*------------------------------------------------------------------------------*/
/**
 * Unzoom a set of subwindows and figures
 * @param objectsUID array of figure and subwindow objects id.
 * @param nbObjects number of objects.
 */
void sciUnzoomArray(int* piObjUID, int nbObjects)
{
    /* object type */
    int iType = -1;
    int *piType = &iType;
    int i = 0;
    for (i = 0; i < nbObjects; i++)
    {
        getGraphicObjectProperty(piObjUID[i], __GO_TYPE__, jni_int, (void **) &piType);
        if (iType == __GO_FIGURE__)
        {
            /* Unzoom all subwindows of the figure */
            sciUnzoomFigure(piObjUID[i]);
        }
        else if (iType == __GO_AXES__)
        {
            /* Unzoom the axes */
            sciUnzoomSubwin(piObjUID[i]);
        }

    }
}
/*--------------------------------------------------------------------------------*/
void updateSubwinScale(int iSubwinUID)
{
    sciJavaUpdateSubwinScale(iSubwinUID);
}
/*------------------------------------------------------------------------------*/
void updateTextBounds(int iTextUID)
{
    int iParentAxes = 0;
    int* piParent = &iParentAxes;

    /* Update coordinate transformation if needed */
    getGraphicObjectProperty(iTextUID, __GO_PARENT_AXES__, jni_int, (void **) &piParent);
    updateSubwinScale(iParentAxes);

    /* Compute the bounding box of the text */
    sciJavaUpdateTextBoundingBox(iTextUID);
}
/*------------------------------------------------------------------------------*/