2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Fabrice Leray
4 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
5 * Copyright (C) 2012 - Scilab Enterprises - Bruno JOFRET
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
15 /*------------------------------------------------------------------------*/
16 /* file: sci_xset.c */
17 /* desc : interface for xset routine */
18 /*------------------------------------------------------------------------*/
20 #include "gw_graphics.h"
21 #include "api_scilab.h"
22 #include "GetProperty.h"
23 #include "SetProperty.h"
24 #include "DrawObjects.h"
25 #include "InitObjects.h"
26 #include "XsetXgetParameters.h"
29 #include "localization.h"
31 #include "HandleManagement.h"
33 #include "BuildObjects.h"
34 #include "graphicObjectProperties.h"
35 #include "setGraphicObjectProperty.h"
36 #include "FigureList.h"
37 #include "CurrentFigure.h"
38 #include "CurrentSubwin.h"
39 #include "AxesModel.h"
40 #include "getGraphicObjectProperty.h"
41 #include "deleteGraphicObject.h"
42 #include "warningmode.h"
45 /*--------------------------------------------------------------------------*/
46 int xsetg(char * str, char * str1, int lx0, int lx1);
47 /*--------------------------------------------------------------------------*/
48 int sci_xset(char *fname, unsigned long fname_len)
59 int m1 = 0, m2 = 0, xm[5], xn[5], x[5] = {0, 0, 0, 0, 0}, i = 0, v = 0;
60 double xx[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
61 char * subwinUID = NULL;
62 BOOL keyFound = FALSE;
64 if (nbInputArgument(pvApiCtx) <= 0)
66 sci_demo(fname, fname_len);
70 CheckInputArgument(pvApiCtx, 1, 6);
71 CheckOutputArgument(pvApiCtx, 0, 1);
73 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1);
76 printError(&sciErr, 0);
80 // Retrieve a matrix of double at position 1.
81 if (getAllocatedSingleString(pvApiCtx, piAddrl1, &l1))
83 Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 1);
88 for (i = 0 ; i < NUMSETFONC ; i++)
90 if (strcmp(l1, KeyTab_[i]) == 0)
99 Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1));
103 /* Allan CORNET Avril 2004 */
104 /* Bloque la commande xset('window') sans numero de fenetre */
105 if (nbInputArgument(pvApiCtx) == 1 && (strcmp((l1), "window") == 0))
107 Scierror(999, _("%s : '%s' must be set\n"), fname, "window-number");
111 if (nbInputArgument(pvApiCtx) == 2 && (!checkInputArgumentType(pvApiCtx, 2, sci_matrix)))
113 /* second argument is not a scalar it must be a string */
114 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrl2);
117 printError(&sciErr, 0);
121 // Retrieve a matrix of double at position 2.
122 if (getAllocatedSingleString(pvApiCtx, piAddrl2, &l2))
124 Scierror(202, _("%s: Wrong type for argument #%d: A string expected.\n"), fname, 2);
128 xsetg(l1, l2, m1, m2);
129 AssignOutputVariable(pvApiCtx, 1) = 0;
130 ReturnArguments(pvApiCtx);
134 if (nbInputArgument(pvApiCtx) == 1 && strcmp((l1), "default") == 0)
136 /* first treatment for xsetg : then we continue */
137 xsetg((l1), "void", m1, 4L);
140 for (i = 2 ; i <= nbInputArgument(pvApiCtx) ; i++)
142 sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrlr);
145 printError(&sciErr, 0);
149 // Retrieve a matrix of double at position i.
150 sciErr = getMatrixOfDouble(pvApiCtx, piAddrlr, &xm[i - 2], &xn[i - 2], &lr);
153 printError(&sciErr, 0);
154 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, i);
158 x[i - 2] = (int)lr[0];
162 if (strcmp((l1), "wdim") == 0 || strcmp((l1), "wpdim") == 0)
164 /* Xwindows limits dimensions to 2^16 */
165 if ((x[0] > 65535) || (x[1] > 65535))
167 x[0] = Min(x[0], 65535);
168 x[1] = Min(x[1], 65535);
175 if (strcmp((l1), "clipping") == 0)
178 if (nbInputArgument(pvApiCtx) != 5 && nbInputArgument(pvApiCtx) != 2)
180 Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 5);
184 if (nbInputArgument(pvApiCtx) == 2)
190 sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddrlr);
193 printError(&sciErr, 0);
197 // Retrieve a matrix of double at position 2.
198 sciErr = getMatrixOfDouble(pvApiCtx, piAddrlr, &iRows, &iCols, &lr);
201 printError(&sciErr, 0);
202 Scierror(202, _("%s: Wrong type for argument %d: A real expected.\n"), fname, 2);
207 if (iRows * iCols != 4)
209 Scierror(999, _("%s: Wrong size for input argument #%d: A %d-element vector expected.\n"), fname, 2, 4);
213 for (i = 0; i < 4 ; i++)
218 subwinUID = (char*)getOrCreateDefaultSubwin();
219 setGraphicObjectProperty(subwinUID, __GO_CLIP_BOX__, xx, jni_double_vector, 4);
220 setGraphicObjectProperty(subwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1);
222 else if (strcmp((l1), "colormap") == 0)
224 char *pFigureUID = NULL;
225 getOrCreateDefaultSubwin();
226 pFigureUID = (char*)getCurrentFigure();
227 setGraphicObjectProperty(pFigureUID, __GO_COLORMAP__, (lr), jni_double_vector, *xm * (*xn));
229 else if (strcmp((l1), "mark size") == 0)
231 int markSize = (int) xx[0];
232 int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */
233 char *subwinUID = (char*)getOrCreateDefaultSubwin();
235 setGraphicObjectProperty(subwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1);
236 setGraphicObjectProperty(subwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
238 else if (strcmp((l1), "mark") == 0)
240 int markStyle = (int) xx[0];
241 int markSize = (int) xx[1];
242 int markSizeUnit = 1; /* force switch to tabulated mode : old syntax / 0 : point, 1 : tabulated */
243 char *subwinUID = NULL;
244 if (nbInputArgument(pvApiCtx) != 3)
246 Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 3);
250 subwinUID = (char*)getOrCreateDefaultSubwin();
251 setGraphicObjectProperty(subwinUID, __GO_MARK_SIZE_UNIT__, &markSizeUnit, jni_int, 1); /* force switch to tabulated mode : old syntax */
252 setGraphicObjectProperty(subwinUID, __GO_MARK_STYLE__, &markStyle, jni_int, 1);
253 setGraphicObjectProperty(subwinUID, __GO_MARK_SIZE__, &markSize, jni_int, 1);
255 else if (strcmp((l1), "font size") == 0)
257 double fontSize = xx[0];
259 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
261 else if (strcmp((l1), "default") == 0)
264 unsigned short defcolors[] =
266 0, 0, 0, /* Black: DEFAULTBLACK */
267 0, 0, 255, /* Blue */
268 0, 255, 0, /* Green */
269 0, 255, 255, /* Cyan */
271 255, 0, 255, /* Magenta */
272 255, 255, 0, /* Yellow */
273 255, 255, 255, /* White: DEFAULTWHITE */
274 0, 0, 144, /* Blue4 */
275 0, 0, 176, /* Blue3 */
276 0, 0, 208, /* Blue2 */
277 135, 206, 255, /* LtBlue */
278 0, 144, 0, /* Green4 */
279 0, 176, 0, /* Green3 */
280 0, 208, 0, /* Green2 */
281 0, 144, 144, /* Cyan4 */
282 0, 176, 176, /* Cyan3 */
283 0, 208, 208, /* Cyan2 */
284 144, 0, 0, /* Red4 */
285 176, 0, 0, /* Red3 */
286 208, 0, 0, /* Red2 */
287 144, 0, 144, /* Magenta4 */
288 176, 0, 176, /* Magenta3 */
289 208, 0, 208, /* Magenta2 */
290 128, 48, 0, /* Brown4 */
291 160, 64, 0, /* Brown3 */
292 192, 96, 0, /* Brown2 */
293 255, 128, 128, /* Pink4 */
294 255, 160, 160, /* Pink3 */
295 255, 192, 192, /* Pink2 */
296 255, 224, 224, /* Pink */
297 255, 215, 0 /* Gold */
300 int piFigurePosition[2] = {200, 200};
301 int piFigureSize[2] = {500, 500};
302 int piAxesSize[2] = {498, 366};
303 int piViewPort[2] = {0, 0};
304 int piEmptyMatrix[4] = {1, 0, 0, 0};
306 // Create new axes and set it in current figure
307 char* pSubWinUID = (char*)getCurrentSubWin();
313 int m = NUMCOLORS_SCI;
317 int defaultBackground = -2;
318 char error_message[70];
320 double* pdblColorMap = (double*)malloc(m * 3 * sizeof(double));
322 // Create figure if it not exist.
323 char* pFigureUID = (char*)getCurrentFigure();
324 if (pFigureUID == NULL)
326 pFigureUID = createNewFigureWithAxes();
327 setCurrentFigure(pFigureUID);
328 AssignOutputVariable(pvApiCtx, 1) = 0;
329 ReturnArguments(pvApiCtx);
334 if (pdblColorMap == NULL)
336 sprintf(error_message, _("%s: No more memory.\n"), "xset");
340 if (pSubWinUID != NULL)
342 int iChildrenCount = 0;
343 int* childrencount = &iChildrenCount;
344 char** childrenUID = NULL;
346 int *piHidden = &iHidden;
348 getGraphicObjectProperty(pFigureUID, __GO_CHILDREN_COUNT__, jni_int, (void **)&childrencount);
349 getGraphicObjectProperty(pFigureUID, __GO_CHILDREN__, jni_string_vector, (void **)&childrenUID);
351 for (i = 0; i < childrencount[0]; ++i)
353 getGraphicObjectProperty(childrenUID[i], __GO_HIDDEN__, jni_bool, (void **)&piHidden);
356 deleteGraphicObject(childrenUID[i]);
361 cloneAxesModel(pFigureUID);
363 // Set default figure properties
364 setGraphicObjectProperty(pFigureUID, __GO_POSITION__, piFigurePosition, jni_int_vector, 2);
365 setGraphicObjectProperty(pFigureUID, __GO_SIZE__, piFigureSize, jni_int_vector, 2);
366 setGraphicObjectProperty(pFigureUID, __GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2);
367 setGraphicObjectProperty(pFigureUID, __GO_AUTORESIZE__, &bTrue, jni_bool, 1);
368 setGraphicObjectProperty(pFigureUID, __GO_VIEWPORT__, piViewPort, jni_int_vector, 2);
369 setGraphicObjectProperty(pFigureUID, __GO_NAME__, _("Figure n°%d"), jni_string, 1);
370 setGraphicObjectProperty(pFigureUID, __GO_INFO_MESSAGE__, "", jni_string, 1);
371 setGraphicObjectProperty(pFigureUID, __GO_PIXMAP__, &bFalse, jni_bool, 1);
372 setGraphicObjectProperty(pFigureUID, __GO_PIXEL_DRAWING_MODE__, &iCopy, jni_int, 1);
373 setGraphicObjectProperty(pFigureUID, __GO_ANTIALIASING__, &iZero, jni_int, 1);
374 setGraphicObjectProperty(pFigureUID, __GO_IMMEDIATE_DRAWING__, &bTrue, jni_bool, 1);
375 setGraphicObjectProperty(pFigureUID, __GO_BACKGROUND__, &defaultBackground, jni_int, 1);
376 setGraphicObjectProperty(pFigureUID, __GO_VISIBLE__, &bTrue, jni_bool, 1);
377 setGraphicObjectProperty(pFigureUID, __GO_ROTATION_TYPE__, &iZero, jni_int, 1);
378 setGraphicObjectProperty(pFigureUID, __GO_EVENTHANDLER__, "", jni_string, 1);
379 setGraphicObjectProperty(pFigureUID, __GO_EVENTHANDLER_ENABLE__, &bFalse, jni_bool, 1);
380 setGraphicObjectProperty(pFigureUID, __GO_USER_DATA__, piEmptyMatrix, jni_int_vector, 4);
381 setGraphicObjectProperty(pFigureUID, __GO_RESIZEFCN__, "", jni_string, 1);
382 setGraphicObjectProperty(pFigureUID, __GO_TAG__, "", jni_string, 1);
384 for (i = 0; i < m; i++)
386 pdblColorMap[i] = (double)(defcolors[3 * i] / 255.0);
387 pdblColorMap[i + m] = (double)(defcolors[3 * i + 1] / 255.0);
388 pdblColorMap[i + 2 * m] = (double)(defcolors[3 * i + 2] / 255.0);
391 setGraphicObjectProperty(pFigureUID, __GO_COLORMAP__, pdblColorMap, jni_double_vector, 3 * m);
392 setGraphicObjectProperty(pFigureUID, __GO_PARENT__, "", jni_string, 1);
395 else if (strcmp((l1), "clipgrf") == 0)
398 /* special treatement for xset("cligrf") */
399 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
401 else if (strcmp((l1), "clipoff") == 0)
404 /* special treatement for xset("clipoff") */
405 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, &clipState, jni_int, 1);
407 else if (strcmp((l1), "hidden3d") == 0)
409 /* special treatement for xset("hidden3d") */
410 int hiddenColor = (int) x[0];
412 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_HIDDEN_COLOR__, &hiddenColor, jni_int, 1);
414 else if (strcmp((l1), "font") == 0)
416 int fontStyle = (int) xx[0];
417 double fontSize = xx[1];
418 if (nbInputArgument(pvApiCtx) != 3)
420 Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 3);
424 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, &fontSize, jni_double, 1);
425 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_STYLE__, &fontStyle, jni_int, 1);
427 else if (strcmp((l1), "window") == 0 || strcmp((l1), "figure") == 0)
429 // Find if window already exists, if not create a new one
431 char *pFigureUID = (char*)getFigureFromIndex(iID);
432 if (pFigureUID == NULL)
434 pFigureUID = createNewFigureWithAxes();
435 setGraphicObjectProperty(pFigureUID, __GO_ID__, &iID, jni_int, 1);
436 setCurrentFigure(pFigureUID);
438 setCurrentFigure(pFigureUID);
440 else if ((strcmp((l1), "foreground") == 0) || (strcmp((l1), "color") == 0) || (strcmp((l1), "pattern") == 0))
442 int iColor = (int) x[0];
444 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_COLOR__, &iColor, jni_int, 1);
446 else if (strcmp((l1), "background") == 0)
448 int iColor = (int) x[0];
450 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_BACKGROUND__, &iColor, jni_int, 1);
452 else if (strcmp((l1), "thickness") == 0)
454 sciSetLineWidth((char*)getOrCreateDefaultSubwin(), x[0]);
456 else if (strcmp((l1), "line style") == 0)
458 int lineStyle = (int) x[0];
459 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
461 else if (strcmp((l1), "mark") == 0)
465 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_MARK_MODE__, &markMode, jni_bool, 1);
466 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_MARK_STYLE__, x, jni_int, 1);
468 else if (strcmp((l1), "colormap") == 0)
470 getOrCreateDefaultSubwin();
471 setGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP__, (lr), jni_double_vector, xm[0] * xn[0]);
473 else if (strcmp((l1), "dashes") == 0)
475 int lineStyle = (int) x[0];
476 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, &lineStyle, jni_int, 1);
478 else if (strcmp((l1), "wresize") == 0)
480 int iAutoResizeMode = x[0];
482 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTORESIZE__, &iAutoResizeMode, jni_bool, 1);
484 else if (strcmp((l1), "wpos") == 0)
486 int figurePosition[2];
487 if (nbInputArgument(pvApiCtx) != 2)
489 Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
492 getOrCreateDefaultSubwin();
494 figurePosition[0] = x[0];
495 figurePosition[1] = x[1];
496 setGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, figurePosition, jni_int_vector, 2);
498 else if (strcmp((l1), "wpdim") == 0 || strcmp((l1), "wdim") == 0)
501 if (nbInputArgument(pvApiCtx) != 2 && nbInputArgument(pvApiCtx) != 3)
503 Scierror(999, _("%s: Wrong number of input arguments: %d or %d expected.\n"), fname, 2, 3);
506 getOrCreateDefaultSubwin();
508 figureSize[0] = x[0];
509 figureSize[1] = x[1];
510 setGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, figureSize, jni_int_vector, 2);
511 } /*Ajout A.Djalel le 10/11/03 */
512 else if (strcmp((l1), "pixmap") == 0)
514 int iPixmapMode = x[0];
515 getOrCreateDefaultSubwin();
517 setGraphicObjectProperty(getCurrentFigure(), __GO_PIXMAP__, &iPixmapMode, jni_bool, 1);
519 else if (strcmp((l1), "wshow") == 0)
521 if (getWarningMode())
523 sciprint(_("WARNING: %s\n"), _("xset(\"wshow\") is obsolete."));
524 sciprint(_("WARNING: %s\n"), _("It will be removed after Scilab 5.4.0."));
525 sciprint(_("WARNING: %s\n"), _("Please use drawlater/drawnow instead."));
528 else if (strcmp((l1), "viewport") == 0)
530 int viewport[4] = {x[0], x[1], 0, 0};
531 getOrCreateDefaultSubwin();
532 setGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, viewport, jni_int_vector, 2);
534 else if (strcmp((l1), "wwpc") == 0)
536 if (getWarningMode())
538 sciprint(_("WARNING: %s\n"), _("xset(\"wwpc\") is obsolete."));
539 sciprint(_("WARNING: %s\n"), _("It will be removed after Scilab 5.4.0."));
540 sciprint(_("WARNING: %s\n"), _("Please use drawlater/drawnow instead."));
543 else if (strcmp((l1), "line mode") == 0)
545 char *pstSubwinUID = (char*)getOrCreateDefaultSubwin();
550 setGraphicObjectProperty(pstSubwinUID, __GO_LINE_MODE__, &iZero, jni_bool, 1);
554 setGraphicObjectProperty(pstSubwinUID, __GO_LINE_MODE__, &iOne, jni_bool, 1);
559 Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), fname, (l1));
563 AssignOutputVariable(pvApiCtx, 1) = 0;
564 ReturnArguments(pvApiCtx);
565 freeAllocatedSingleString(l1);
566 freeAllocatedSingleString(l2);
569 /*--------------------------------------------------------------------------*/
570 int xsetg(char * str, char * str1, int lx0, int lx1)
572 if (strcmp(str, "fpf") == 0)
574 strcpy(getFPF(), str1);
576 else if (strcmp(str, "auto clear") == 0)
578 int bAutoClear = (int) FALSE;
580 if (strcmp(str1, "on") == 0)
582 bAutoClear = (int) TRUE;
585 setGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, &bAutoClear, jni_bool, 1);
587 else if (strcmp(str, "default") == 0)
593 Scierror(999, _("%s: Unrecognized input argument '%s'.\n"), "xset(arg,<string>)", str);
598 /*--------------------------------------------------------------------------*/