1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 1998-2001 - ENPC - Jean-Philipp Chancelier
4  * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
5  * Copyright (C) 2011 - DIGITEO - Manuel Juliachs
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15  *
16  */
17 
18 /*------------------------------------------------------------------------
19  *    Graphic library
20  --------------------------------------------------------------------------*/
21 
22 #include "math_graphics.h"
23 #include "PloEch.h"
24 
25 #include "GetProperty.h"
26 #include "SetProperty.h"
27 
28 
29 #include "BuildObjects.h"
30 #include "Axes.h"
31 #include "Champ.h"
32 
33 #include "sci_malloc.h" /* MALLOC */
34 #include "localization.h"
35 #include "Plot2d.h"
36 #include "Scierror.h"
37 
38 #include "createGraphicObject.h"
39 #include "getGraphicObjectProperty.h"
40 #include "setGraphicObjectProperty.h"
41 #include "graphicObjectProperties.h"
42 #include "CurrentSubwin.h"
43 #include "CurrentObject.h"
44 
45 /*-----------------------------------------------------------------
46  *  int C2F(champ)(x,y,fx,fy,n1,n2,strflag,brect,arfact,lstr)
47  *  int C2F(champ1)(x,y,fx,fy,n1,n2,strflag,brect,arfact,lstr)
48  *
49  * Used for Drawing 2 dimensional vector fields
50  * (fx[i+(*n1)*j], fy[i+(*n1)*j]) is the value of the vector field
51  * at point X=(x[i],y[j]);
52  *
53  * - fx and fy are (*n1)*(*n2) matrix of double
54  * - arfact : a factor by which to multiply the default arrow size
55  *          usr 1.0 by defaut
56  * - strflag : a string of length 3 (see plot2d)
57  * - brect=[xmin,ymin,xmax,ymax]    (see plot2d)
58  *
59  * - lstr : (used when called from Fortran code)
60  -------------------------------------------------------------------*/
61 
champg(char * name,int colored,double * x,double * y,double * fx,double * fy,int * n1,int * n2,char * strflag,double * brect,double * arfact,int lstr)62 void champg(char *name, int colored, double *x, double *y, double *fx, double *fy, int *n1,
63             int *n2, char *strflag, double *brect, double *arfact, int lstr)
64 {
65     int iSubwinUID = 0;
66     int iNewSegsUID = 0;
67 
68     int clipState = 0;
69     char textLogFlags[3];
70     double xx[2];
71     double yy[2];
72     double* boundingBox = NULL;
73     double rotationAngles[2];
74     int nn1 = 1;
75     int nn2 = 2;
76     int autoScale = 0;
77     int* piAutoScale = &autoScale;
78     int firstPlot = 0;
79     int* piFirstPlot = &firstPlot;
80     int logFlags[3];
81     int flag, type = 1;
82     double arsize1 = 0.;
83     int *style = NULL;
84 
85     int iTmp = 0;
86     int* piTmp = &iTmp;
87 
88     int i = 0;
89     double drect[6];
90     BOOL bounds_changed = FALSE;
91     BOOL axes_properties_changed = FALSE;
92 
93     /* champ with color inherited from subwin */
94     /* or champ1 (normed vector + color) is enabled */
95     int typeofchamp = (colored == 0 ? 0 : 1);
96 
97     /* First create champ object */
98     /* F.Leray Allocation de style[dim = Nbr1] */
99     if ((style = (int*)MALLOC ((*n1) * sizeof (int))) == NULL)
100     {
101         Scierror(999, _("%s: No more memory.\n"), "champg");
102         return;
103     }
104 
105     flag = 1; /* je le mets � 1 pour voir F.Leray 19.02.04*/
106     arsize1 = *arfact;
107 
108     iSubwinUID = getCurrentSubWin();
109 
110     /* then modify subwindow if needed */
111     checkRedrawing();
112 
113     /* Force clipping to CLIPGRF (1) */
114     clipState = 1;
115     setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);
116 
117     for (i = 0; i < (*n1); i++)
118     {
119         style[i] = i;
120     }
121 
122     iNewSegsUID = createChamp(iSubwinUID, x, *n1, y, *n2, fx, *n1 * *n2, fy, *n1 * *n2, arsize1, typeofchamp != 0);
123 
124     if (iNewSegsUID == 0)
125     {
126         Scierror(999, _("%s: No more memory.\n"), "champg");
127         if (style != NULL)
128         {
129             FREE(style);
130         }
131 
132         return;
133     }
134 
135     setCurrentObject(iNewSegsUID);
136 
137     if (style != NULL)
138     {
139         FREE(style);
140         style = NULL;
141     }
142 
143     /* Get segs bounding box */
144     getGraphicObjectProperty(iNewSegsUID, __GO_BOUNDING_BOX__, jni_double_vector, (void **)&boundingBox);
145     if (!boundingBox)
146     {
147         Scierror(999, _("%s: Could not retrieve bounding box.\n"), "champg");
148         return;
149     }
150 
151     xx[0] = boundingBox[0];
152     xx[1] = boundingBox[1];
153     yy[0] = boundingBox[2];
154     yy[1] = boundingBox[3];
155 
156     releaseGraphicObjectProperty(__GO_BOUNDING_BOX__, boundingBox, jni_double_vector, 4);
157 
158     rotationAngles[0] = 0.0;
159     rotationAngles[1] = 270.0;
160 
161     setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2);
162 
163     getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piAutoScale);
164 
165     getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piFirstPlot);
166 
167     if (autoScale)
168     {
169         /* compute and merge new specified bounds with the data bounds */
170         switch (strflag[1])
171         {
172             case '0':
173                 /* do not change data bounds */
174                 break;
175             case '1' :
176             case '3' :
177             case '5' :
178             case '7':
179                 /* Force data bounds=brect */
180                 re_index_brect(brect, drect);
181                 break;
182             case '2' :
183             case '4' :
184             case '6' :
185             case '8':
186             case '9':
187 
188                 getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
189                 logFlags[0] = iTmp;
190                 getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
191                 logFlags[1] = iTmp;
192                 getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp);
193                 logFlags[2] = iTmp;
194 
195                 /* Conversion required by compute_data_bounds2 */
196                 textLogFlags[0] = getTextLogFlag(logFlags[0]);
197                 textLogFlags[1] = getTextLogFlag(logFlags[1]);
198                 textLogFlags[2] = getTextLogFlag(logFlags[2]);
199 
200                 /* Force data bounds to the x and y bounds */
201                 compute_data_bounds2(0, 'g', textLogFlags, xx, yy, nn1, nn2, drect);
202                 break;
203         }
204 
205         /* merge data bounds and drect */
206         if (!firstPlot &&
207                 (strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9'))
208         {
209             double* dataBounds;
210 
211             getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds);
212 
213             drect[0] = Min(dataBounds[0], drect[0]); /*xmin*/
214             drect[2] = Min(dataBounds[2], drect[2]); /*ymin*/
215             drect[1] = Max(dataBounds[1], drect[1]); /*xmax*/
216             drect[3] = Max(dataBounds[3], drect[3]); /*ymax*/
217         }
218 
219         if (strflag[1] != '0')
220         {
221             bounds_changed = update_specification_bounds(iSubwinUID, drect, 2);
222         }
223 
224     }
225 
226     if (firstPlot)
227     {
228         bounds_changed = TRUE;
229     }
230 
231     axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag);
232 
233     /* just after strflag2axes_properties */
234     firstPlot = 0;
235     setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1);
236 }
237 
C2F(champ)238 int C2F(champ)(double *x, double *y, double *fx, double *fy, int *n1, int *n2, char *strflag, double *brect, double *arfact, int lstr)
239 {
240     champg("champ", 0, x, y, fx, fy, n1, n2, strflag, brect, arfact, lstr);
241     return (0);
242 }
243 
C2F(champ1)244 int C2F(champ1)(double *x, double *y, double *fx, double *fy, int *n1, int *n2, char *strflag, double *brect, double *arfact, int lstr)
245 {
246     champg("champ1", 1, x, y, fx, fy, n1, n2, strflag, brect, arfact, lstr);
247     return (0);
248 }
249 /*----------------------------------------------------------------------------------*/
250 
251