Add full options management to figure
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / builder / Builder.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  * Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
5  *
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
11  *
12  */
13
14 package org.scilab.modules.graphic_objects.builder;
15
16 import java.util.ArrayList;
17 import java.util.StringTokenizer;
18
19 import org.scilab.modules.graphic_objects.ScilabNativeView;
20 import org.scilab.modules.graphic_objects.arc.Arc;
21 import org.scilab.modules.graphic_objects.axes.Axes;
22 import org.scilab.modules.graphic_objects.axis.Axis;
23 import org.scilab.modules.graphic_objects.fec.Fec;
24 import org.scilab.modules.graphic_objects.figure.Figure;
25 import org.scilab.modules.graphic_objects.figure.Figure.BarType;
26 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
27 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
28 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
29 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject.Type;
30 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
31 import org.scilab.modules.graphic_objects.imageplot.Imageplot;
32 import org.scilab.modules.graphic_objects.label.Label;
33 import org.scilab.modules.graphic_objects.legend.Legend;
34 import org.scilab.modules.graphic_objects.lighting.Light;
35 import org.scilab.modules.graphic_objects.lighting.Light.LightType;
36 import org.scilab.modules.graphic_objects.polyline.Polyline;
37 import org.scilab.modules.graphic_objects.rectangle.Rectangle;
38 import org.scilab.modules.graphic_objects.surface.Surface;
39 import org.scilab.modules.graphic_objects.textObject.Font;
40 import org.scilab.modules.graphic_objects.textObject.Text;
41 import org.scilab.modules.graphic_objects.vectfield.Champ;
42 import org.scilab.modules.graphic_objects.vectfield.Segs;
43
44 public final class Builder {
45     public final static int createRect(int parentSubwin, double x, double y,
46                                        double height, double width, int foreground,
47                                        int background, int isfilled, int isline) {
48         GraphicController controller = GraphicController.getController();
49         Axes axes = (Axes)controller.getObjectFromId(parentSubwin);
50
51         if (height < 0 || width < 0) {
52             return 0;
53         }
54
55         Integer iRect = controller.askObject(Type.RECTANGLE);
56
57         /*
58          * Sets the rectangle's parent in order to initialize the former's Contoured properties
59          * with the latter's values (cloneGraphicContext call below)
60          */
61
62         Rectangle rect = (Rectangle) controller.getObjectFromId(iRect);
63         rect.setUpperLeftPoint(new Double[] {x, y, 0.0});
64         rect.setHeight(height);
65         rect.setWidth(width);
66
67         rect.setVisible(axes.getVisible());
68
69         /* Clip state and region */
70         /* To be checked for consistency */
71
72         rect.setClipBox(axes.getClipBox());
73         rect.setClipBoxSet(axes.getClipBoxSet());
74         rect.setClipState(axes.getClipState());
75         rect.setMarkMode(axes.getMarkMode());
76
77         /*
78          * Initializes the contour properties (background, foreground, etc)
79          * to the default values (those of the parent Axes).
80          */
81         cloneGraphicContext(parentSubwin, iRect);
82
83         /* Contour settings */
84         rect.setLineMode(isline == 1);
85         rect.setFillMode(isfilled == 1);
86
87         if (foreground != -1) {
88             rect.setLineColor(foreground);
89         }
90
91         if (background != -1) {
92             rect.setBackground(background);
93         }
94
95         controller.objectCreated(iRect);
96
97         /*
98          * Sets the Axes as the rectangle's parent and adds the rectangle to
99          * its parent's list of children.
100          */
101         //setGraphicObjectRelationship(pparentsubwinUID, pobjUID);
102
103         return iRect;
104     }
105
106     public static int cloneGraphicContext(int sourceIdentifier, int destIdentifier) {
107         GraphicController controller = GraphicController.getController();
108         Boolean lineMode = false;
109         Integer foreground = 0;
110         Integer lineStyle = 0;
111         Integer background = 0;
112         Integer markForeground = 0;
113         Integer markBackground = 0;
114         Integer markStyle = 0;
115         Integer markSize = 0;
116         Integer markSizeUnit = 0;
117         Double lineThickness = 0.;
118
119         /*
120          * All these properties are passed by value thus do not care to release them
121          * and do not call releaseGraphicObjectProperty on purpose.
122          */
123
124         lineMode = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
125         foreground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
126         lineThickness = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
127         lineStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
128
129         background = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
130
131         markForeground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
132
133         markBackground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
134
135         markStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
136
137         markSize = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
138
139         markSizeUnit = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
140
141         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode);
142         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
143         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
144         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
145
146         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
147
148         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
149         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
150         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
151         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
152         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
153
154         return 0;
155     }
156
157     public static int cloneFontContext(int sourceIdentifier, int destIdentifier) {
158         GraphicController controller = GraphicController.getController();
159
160         Integer fontColor = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__);
161         Integer fontStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__);
162         Double fontSize = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__);
163         Boolean fontFractional = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__);
164
165         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__, fontColor);
166         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__, fontStyle);
167         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__, fontSize);
168         controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__, fontFractional);
169
170         return 0;
171     }
172
173     public static int createHiddenLabel(int parent) {
174
175         GraphicController controller = GraphicController.getController();
176
177         Integer iLabel = controller.askObject(Type.LABEL);
178         Label label = (Label) controller.getObjectFromId(iLabel);
179
180         //Hide Label as they are non explicit children
181         label.setHidden(true);
182         label.setAutoPosition(true);
183         label.setAutoRotation(true);
184
185         cloneGraphicContext(parent, iLabel);
186         cloneFontContext(parent, iLabel);
187         controller.objectCreated(iLabel);
188
189         // Sets the label's parent
190         controller.setGraphicObjectRelationship(parent, iLabel);
191
192         return iLabel;
193     }
194
195     public static void initSubWinBounds(int subWin) {
196         GraphicController controller = GraphicController.getController();
197
198         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
199         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
200         controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
201     }
202
203     public static void reinitSubWin(int subWin) {
204         GraphicController controller = GraphicController.getController();
205         Integer label = 0;
206
207         for (Integer childId : (Integer[]) controller.getProperty(subWin, GraphicObjectProperties.__GO_CHILDREN__)) {
208             GraphicModel.getModel().deleteObject(childId);
209         }
210
211         label = createHiddenLabel(subWin);
212         controller.setProperty(subWin, GraphicObjectProperties.__GO_TITLE__, label);
213
214         label = createHiddenLabel(subWin);
215         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LABEL__, label);
216
217         label = createHiddenLabel(subWin);
218         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__, label);
219
220         label = createHiddenLabel(subWin);
221         controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__, label);
222
223         controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOCATION__, 0);
224         controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOCATION__, 4);
225         controller.setProperty(subWin, GraphicObjectProperties.__GO_VISIBLE__, true);
226         controller.setProperty(subWin, GraphicObjectProperties.__GO_FIRST_PLOT__, true);
227
228         Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
229         Axes axes = (Axes) controller.getObjectFromId(axesModel);
230
231         controller.setProperty(subWin, GraphicObjectProperties.__GO_VIEW__, axes.getView());
232         controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, axes.getRotationAngles());
233         controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES_3D__, axes.getRotationAngles3d());
234     }
235
236     public static boolean isAxesRedrawing(int subWin) {
237         GraphicController controller = GraphicController.getController();
238         Axes axes = (Axes)controller.getObjectFromId(subWin);
239
240         if (axes.getAutoClear()) {
241             reinitSubWin(subWin);
242             return true;
243         }
244         return false;
245     }
246
247     public static int createLabel(int parent, int type) {
248         GraphicController controller = GraphicController.getController();
249         Double[] position = new Double[3];
250         position[0] = 1.0;
251         position[1] = 1.0;
252         position[2] = 1.0;
253
254         //check parent type
255         Integer parentType = (Integer) controller.getProperty(parent, GraphicObjectProperties.__GO_TYPE__);
256         if (parentType != GraphicObjectProperties.__GO_AXES__) {
257             return 1;
258         }
259
260         //get axes model
261         Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
262
263         //get type label from axes model
264         Integer labelSource = (Integer) controller.getProperty(axesModel, type);
265
266         //clone label
267         Integer newLabel = controller.cloneObject(labelSource);
268         controller.setProperty(newLabel, GraphicObjectProperties.__GO_POSITION__, position);
269         // Auto position must be reset as setting the position has set it to false
270         Boolean autoPosition = (Boolean ) controller.getProperty(labelSource, GraphicObjectProperties.__GO_AUTO_POSITION__);
271         controller.setProperty(newLabel, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition);
272
273         // Set relation between newLabel and parent
274         controller.setProperty(parent, type, newLabel);
275         controller.setGraphicObjectRelationship(parent, newLabel);
276         return 0;
277     }
278
279     public final static int createFigureFromModel() {
280         GraphicController controller = GraphicController.getController();
281         return controller.cloneObject(GraphicModel.getFigureModel().getIdentifier());
282     }
283
284     public final static int cloneAxesModel(int parent) {
285         GraphicController controller = GraphicController.getController();
286
287         Integer newAxes = controller.cloneObject(GraphicModel.getAxesModel().getIdentifier());
288         createLabel(newAxes, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
289         createLabel(newAxes, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
290         createLabel(newAxes, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
291         createLabel(newAxes, GraphicObjectProperties.__GO_TITLE__);
292
293         controller.setGraphicObjectRelationship(parent, newAxes);
294         controller.setProperty(parent, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAxes);
295
296         ScilabNativeView.ScilabNativeView__setCurrentSubWin(newAxes);
297         ScilabNativeView.ScilabNativeView__setCurrentObject(newAxes);
298         return newAxes;
299     }
300
301     public final static void cloneMenus(int iModel, int iParent) {
302         GraphicController controller = GraphicController.getController();
303         GraphicObject model = controller.getObjectFromId(iModel);
304
305         Integer[] children = model.getChildren();
306
307         for (int i = children.length - 1 ; i >= 0 ; i--) {
308             GraphicObject child = controller.getObjectFromId(children[i]);
309             if (child.getType() == GraphicObjectProperties.__GO_UIMENU__) {
310                 Integer newMenu = controller.cloneObject(children[i]);
311                 controller.setGraphicObjectRelationship(iParent, newMenu);
312
313                 cloneMenus(children[i], newMenu);
314             }
315         }
316     }
317         
318     public final static int createFigure(boolean dockable, int menubarType, int toolbarType, boolean defaultAxes, boolean visible) {
319         GraphicController controller =  GraphicController.getController();
320         Integer figModel = GraphicModel.getFigureModel().getIdentifier();
321         Integer figId = controller.cloneObject(figModel, false);
322         Figure figure = (Figure) controller.getObjectFromId(figId);
323         figure.setDockable(dockable);
324         figure.setMenubar(menubarType);
325         figure.setToolbar(toolbarType);
326         figure.setVisible(visible);
327         
328         controller.objectCreated(figId);
329         ScilabNativeView.ScilabNativeView__setCurrentFigure(figId);
330         
331         if (menubarType == BarType.FIGURE.ordinal()) {
332             cloneMenus(figModel, figId);
333         }
334         
335         if (defaultAxes) {
336             //clone default axes
337             cloneAxesModel(figId);
338         }
339
340         return figId;
341     }
342     
343     public final static int createNewFigureWithAxes() {
344         GraphicController controller = GraphicController.getController();
345         Integer figModel  = GraphicModel.getFigureModel().getIdentifier();
346
347         //clone default figure
348         Integer newFigure = createFigureFromModel();
349
350         //Clone the default menus
351         cloneMenus(figModel, newFigure);
352
353         //set ID to 0
354         controller.setProperty(newFigure, GraphicObjectProperties.__GO_ID__, 0);
355
356         //clone default axes
357         cloneAxesModel(newFigure);
358         ScilabNativeView.ScilabNativeView__setCurrentFigure(newFigure);
359
360         //Force axes size after window creation
361         Integer[] figureSize = (Integer[]) controller.getProperty(figModel, GraphicObjectProperties.__GO_SIZE__);
362         controller.setProperty(newFigure, GraphicObjectProperties.__GO_SIZE__, figureSize);
363         Integer[] axesSize = (Integer[]) controller.getProperty(figModel, GraphicObjectProperties.__GO_AXES_SIZE__);
364         controller.setProperty(newFigure, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
365
366         controller.setProperty(newFigure, GraphicObjectProperties.__GO_VALID__, true);
367
368
369         return newFigure;
370     }
371
372     public final static int createSubWin(int parentFigure) {
373         GraphicController controller = GraphicController.getController();
374         GraphicObject parent = controller.getObjectFromId(parentFigure);
375         if (parent.getType() != GraphicObjectProperties.__GO_FIGURE__) {
376             return 0;
377         }
378
379         return cloneAxesModel(parentFigure);
380     }
381
382     public final static int createText(int iParentsubwinUID, String[] str, int nbRow, int nbCol,
383                                        double x, double y, boolean autoSize, double[] userSize, int centerPos,
384                                        int foreground, boolean isForeground, int background, boolean isBackground,
385                                        boolean isBoxed, boolean isLine,
386                                        boolean isFilled, int align) {
387
388         GraphicController controller = GraphicController.getController();
389         int iText = controller.askObject(Type.TEXT);
390
391         Axes axes = (Axes) controller.getObjectFromId(iParentsubwinUID);
392         Text text = (Text) controller.getObjectFromId(iText);
393
394         //clip
395         text.setClipBox(axes.getClipBox());
396         text.setClipBoxSet(axes.getClipBoxSet());
397         text.setClipState(axes.getClipState());
398
399         //text
400         Integer[] dimensions = new Integer[2];
401         dimensions[0] = nbRow;
402         dimensions[1] = nbCol;
403         text.setTextArrayDimensions(dimensions);
404         text.setTextStrings(str);
405
406         //position
407         Double[] position = new Double[3];
408         position[0] = x;
409         position[1] = y;
410         position[2] = 0.0;
411         text.setPosition(position);
412
413         //test box
414         Double[] setUserSize = new Double[2];
415         text.setTextBoxMode(centerPos);
416         text.setAutoDimensioning(autoSize);
417
418         if (autoSize == false || centerPos != 0) {
419             setUserSize[0] = userSize[0];
420             setUserSize[1] = userSize[1];
421         } else {
422             setUserSize[0] = 0.0;
423             setUserSize[1] = 0.0;
424         }
425         text.setTextBox(setUserSize);
426
427         int alignment = align - 1;
428         if (alignment < 0 || alignment > 2) {
429             alignment = 0;
430         }
431
432         text.setAlignment(alignment);
433
434         cloneGraphicContext(iParentsubwinUID, iText);
435         cloneFontContext(iParentsubwinUID, iText);
436
437         text.setBox(isBoxed);
438         text.setLineMode(isLine);
439         text.setFillMode(isFilled);
440
441         if (isForeground) {
442             text.setLineColor(foreground);
443         }
444
445         if (isBackground) {
446             text.setBackground(background);
447         }
448
449         text.setVisible(axes.getVisible());
450         controller.objectCreated(iText);
451         return iText;
452     }
453
454     public final static int createArc(int parent, double x, double y, double h, double w,
455                                       double startAngle, double endAngle,
456                                       int foreground, boolean isForeground, int background, boolean isBackground,
457                                       boolean filled, boolean line) {
458
459         GraphicController controller = GraphicController.getController();
460         int iArc = controller.askObject(Type.ARC);
461
462         Axes axes = (Axes) controller.getObjectFromId(parent);
463         Arc arc = (Arc) controller.getObjectFromId(iArc);
464
465         //set visible false during construction
466         arc.setVisible(false);
467
468         Double[] upperLeftPoint = new Double[3];
469         upperLeftPoint[0] = x;
470         upperLeftPoint[1] = y;
471         upperLeftPoint[2] = 0.0;
472
473         arc.setUpperLeftPoint(upperLeftPoint);
474         arc.setHeight(h);
475         arc.setWidth(w);
476         arc.setStartAngle(startAngle);
477         arc.setEndAngle(endAngle);
478         arc.setArcDrawingMethod(axes.getArcDrawingMethod());
479
480         //clip
481         arc.setClipBox(axes.getClipBox());
482         arc.setClipBoxSet(axes.getClipBoxSet());
483         arc.setClipState(axes.getClipState());
484
485         cloneGraphicContext(parent, iArc);
486
487         arc.setLineMode(line);
488         arc.setFillMode(filled);
489
490         if (isForeground) {
491             arc.setLineColor(foreground);
492         }
493
494         if (isBackground) {
495             arc.setBackground(background);
496         }
497
498         arc.setVisible(axes.getVisible());
499         controller.objectCreated(iArc);
500         controller.setGraphicObjectRelationship(parent, iArc);
501         return iArc;
502     }
503
504     public final static int createAxis(int parent, int dir, int tics, double[] vx, double[] vy, int subint, String format,
505                                        int fontSize, int textColor, int ticsColor, boolean seg) {
506
507         GraphicController controller = GraphicController.getController();
508         int iAxis = controller.askObject(Type.AXIS);
509
510         Axes axes = (Axes) controller.getObjectFromId(parent);
511         Axis axis = (Axis) controller.getObjectFromId(iAxis);
512
513         //clip box
514         axis.setClipBox(axes.getClipBox());
515         axis.setClipBoxSet(false);
516
517         axis.setTicksDirection(dir);
518         axis.setTicksStyle(tics);
519
520         axis.setXTicksCoords(toDouble(vx));
521         axis.setYTicksCoords(toDouble(vy));
522
523         if (format != null && format.equals("") == false) {
524             axis.setFormatn(format);
525         }
526
527         axis.setSubticks(subint);
528         axis.setTicksSegment(seg);
529         cloneGraphicContext(parent, iAxis);
530         cloneFontContext(parent, iAxis);
531
532         Font font = axis.getFont();
533         font.setSize(new Double(fontSize));
534         font.setColor(textColor);
535         axis.setTicksColor(ticsColor);
536
537         controller.objectCreated(iAxis);
538         controller.setGraphicObjectRelationship(parent, iAxis);
539         return iAxis;
540     }
541
542     public static int createCompound(int parent, int[] children) {
543         GraphicController controller = GraphicController.getController();
544         int iCompound = controller.askObject(Type.COMPOUND);
545         controller.objectCreated(iCompound);
546
547         GraphicObject obj = controller.getObjectFromId(parent);
548         for (int i = 0 ; i < children.length ; i++) {
549             controller.setGraphicObjectRelationship(iCompound, children[i]);
550         }
551
552         controller.setGraphicObjectRelationship(parent, iCompound);
553         controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, obj.getVisible());
554         return iCompound;
555     }
556
557     public static int createCompoundSeq(int parent, int childrenCount) {
558         GraphicController controller = GraphicController.getController();
559         int iCompound = controller.askObject(Type.COMPOUND);
560         controller.objectCreated(iCompound);
561         GraphicObject axes = controller.getObjectFromId(parent);
562
563         Integer[] children = axes.getChildren();
564
565         /*
566          * Remove the last "number" created objects (located at the children list's head)
567          * and add them to the compound in the same order
568          */
569         for (int i = 0 ; i < childrenCount ; i++) {
570             /*
571              * Set the parent-child relationship between the Compound and each aggregated object.
572              * Children are added to the Compound from the least recent to the most recent, to
573              * preserve their former ordering.
574              */
575             controller.setGraphicObjectRelationship(iCompound, children[childrenCount - i - 1]);
576         }
577
578         controller.setGraphicObjectRelationship(parent, iCompound);
579
580         /*
581          * visibility is obtained from the parent Figure, whereas it is retrieved from the
582          * parent Axes in ConstructCompound.
583          * To be made consistent.
584          */
585         Figure fig = (Figure)controller.getObjectFromId(axes.getParentFigure());
586         controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, fig.getVisible());
587         return iCompound;
588     }
589
590     public static int createFec(int parent, double[] zminmax, int[] colminmax, int[] colout, boolean with_mesh) {
591
592         GraphicController controller = GraphicController.getController();
593         int iFec = controller.askObject(Type.FEC);
594         Axes axes = (Axes) controller.getObjectFromId(parent);
595         Fec fec = (Fec) controller.getObjectFromId(iFec);
596
597
598         fec.setZBounds(toDouble(zminmax));
599         fec.setColorRange(toInteger(colminmax));
600         fec.setOutsideColor(toInteger(colout));
601
602         fec.setVisible(axes.getVisible());
603
604         //clip box
605         fec.setClipBox(axes.getClipBox());
606         fec.setClipBoxSet(axes.getClipBoxSet());
607         fec.setClipState(axes.getClipState());
608
609         cloneGraphicContext(parent, iFec);
610
611         fec.setLineMode(with_mesh);
612
613         controller.objectCreated(iFec);
614         return iFec;
615     }
616
617     public static int createGrayplot(int parent, int type, double[] pvecx, int n1, int n2) {
618
619         int[] objectTypes = new int[] {GraphicObjectProperties.__GO_GRAYPLOT__, GraphicObjectProperties.__GO_MATPLOT__, GraphicObjectProperties.__GO_MATPLOT__};
620
621         GraphicController controller = GraphicController.getController();
622         int iPlot = controller.askObject(GraphicObject.getTypeFromName(objectTypes[type]));
623         Axes axes = (Axes) controller.getObjectFromId(parent);
624         Imageplot plot = (Imageplot) controller.getObjectFromId(iPlot);
625
626         if (type == 2) { //Matplot1
627             Double[] data = new Double[pvecx.length];
628             for (int i = 0 ; i < pvecx.length ; i++) {
629                 data[i] = pvecx[i];
630             }
631             plot.setTranslate(data);
632
633             Double[] scale = new Double[2];
634             scale[0] = (pvecx[2] - pvecx[0]) / (n2 - 1.0);
635             scale[1] = (pvecx[3] - pvecx[1]) / (n1 - 1.0);
636             plot.setScale(scale);
637         }
638
639         plot.setVisible(axes.getVisible());
640
641         //clip box
642         plot.setClipBox(axes.getClipBox());
643         plot.setClipBoxSet(axes.getClipBoxSet());
644         plot.setClipState(axes.getClipState());
645
646         cloneGraphicContext(parent, iPlot);
647         controller.objectCreated(iPlot);
648         return iPlot;
649     }
650
651
652     public static int createPolyline(int parent, boolean closed, int plot,
653                                      int foreground, boolean isForeground, int[] background, int mark_style, boolean isMarkStyle,
654                                      int mark_foreground, boolean isMarkForeground,
655                                      int mark_background, boolean isMarkBackground,
656                                      boolean isline, boolean isfilled, boolean ismark, boolean isinterp) {
657
658         GraphicController controller = GraphicController.getController();
659         int iPoly = controller.askObject(Type.POLYLINE);
660         Axes axes = (Axes) controller.getObjectFromId(parent);
661         Polyline poly = (Polyline) controller.getObjectFromId(iPoly);
662
663         poly.setVisible(false);
664
665         //clip box
666         poly.setClipBox(axes.getClipBox());
667         poly.setClipBoxSet(axes.getClipBoxSet());
668         poly.setClipState(axes.getClipState());
669
670         poly.setClosed(closed);
671         poly.setPolylineStyle(plot);
672
673         cloneGraphicContext(parent, iPoly);
674
675         poly.setMarkMode(ismark);
676         poly.setLineMode(isline);
677         poly.setFillMode(isfilled);
678         poly.setInterpColorMode(isinterp);
679
680         if (isForeground) {
681             poly.setLineColor(foreground);
682         }
683
684         if (background.length != 0) {
685             if (isinterp) {
686                 /* 3 or 4 values to store */
687                 Integer[] color = new Integer[background.length];
688                 for (int i = 0 ; i < background.length ; i++) {
689                     color[i] = background[i];
690                 }
691
692                 poly.setInterpColorVector(color);
693             } else {
694                 poly.setBackground(background[0]);
695             }
696         }
697
698         if (isMarkStyle) {
699             poly.setMarkStyle(mark_style);
700         }
701
702         if (isMarkForeground) {
703             poly.setMarkForeground(mark_foreground);
704         }
705
706         if (isMarkBackground) {
707             poly.setMarkBackground(mark_background);
708         }
709
710         poly.setVisible(true);
711         controller.objectCreated(iPoly);
712         return iPoly;
713     }
714
715     public static int createLegend(int parent, String[] text, int[] handles) {
716         GraphicController controller = GraphicController.getController();
717         Axes axes = (Axes) controller.getObjectFromId(parent);
718
719         if (axes.getHasLegendChild()) {
720             controller.removeRelationShipAndDelete(axes.getLegendChild());
721         }
722
723
724         int iLeg = controller.askObject(Type.LEGEND);
725         Legend leg = (Legend)controller.getObjectFromId(iLeg);
726
727         leg.setParent(parent);
728         leg.setVisible(axes.getVisible());
729
730         int count = handles.length;
731         Integer[] textDims = new Integer[2];
732         textDims[0] = count;
733         textDims[1] = 1;
734
735         leg.setTextArrayDimensions(textDims);
736         leg.setTextStrings(text);
737
738         /*
739          * Links are ordered from most recent to least recent,
740          * as their referred-to Polylines in the latter's parent Compound object.
741          */
742
743         ArrayList<Integer> links = new ArrayList<Integer>();
744         for (int i = count - 1 ; i >= 0 ; i--) {
745             links.add(count - i - 1, handles[i]);
746         }
747
748         leg.setLinks(links);
749
750         leg.setClipBoxSet(false);
751         leg.setClipState(0); //OFF
752         leg.setClipBox(axes.getClipBox());
753
754         cloneGraphicContext(parent,  iLeg);
755         cloneFontContext(parent, iLeg);
756
757         leg.setFillMode(true);
758
759         controller.objectCreated(iLeg);
760         leg.setParent(0);
761         controller.setGraphicObjectRelationship(parent, iLeg);
762         return iLeg;
763     }
764
765     public static int createSegs(int parent, double[] vx, double[] vy, double[] vz, boolean isVZ,
766                                  int[] style, double arsize) {
767         GraphicController controller = GraphicController.getController();
768         Axes axes = (Axes) controller.getObjectFromId(parent);
769         int iSegs = controller.askObject(Type.SEGS);
770         Segs segs = (Segs)controller.getObjectFromId(iSegs);
771
772         segs.setVisible(axes.getVisible());
773
774         //clip box
775         segs.setClipBox(axes.getClipBox());
776         segs.setClipBoxSet(axes.getClipBoxSet());
777         segs.setClipState(axes.getClipState());
778
779         /* Segs: Nbr1/2 arrows, Nbr1 is the number of endpoints */
780         int numberArrows = vx.length / 2;
781
782         segs.setNumberArrows(numberArrows);
783         segs.setArrowSize(arsize);
784
785         Double[] arrowCoords = new Double[3 * numberArrows];
786         for (int i = 0 ; i < numberArrows ; i++) {
787             arrowCoords[3 * i] = vx[2 * i];
788             arrowCoords[3 * i + 1] = vy[2 * i];
789             if (isVZ) {
790                 arrowCoords[3 * i + 2] = vz[2 * i];
791             } else {
792                 arrowCoords[3 * i + 2] = 0.0;
793             }
794         }
795
796         segs.setBase(arrowCoords);
797
798         for (int i = 0 ; i < numberArrows ; i++) {
799             arrowCoords[3 * i] = vx[2 * i + 1];
800             arrowCoords[3 * i + 1] = vy[2 * i + 1];
801             if (isVZ) {
802                 arrowCoords[3 * i + 2] = vz[2 * i + 1];
803             } else {
804                 arrowCoords[3 * i + 2] = 0.0;
805             }
806         }
807
808         segs.setDirection(arrowCoords);
809         segs.setColors(toInteger(style));
810
811         cloneGraphicContext(parent, iSegs);
812         controller.objectCreated(iSegs);
813         controller.setGraphicObjectRelationship(parent, iSegs);
814         return iSegs;
815     }
816
817     public static int createChamp(int parent, double[] vx, double[] vy,
818                                   double[] vfx, double[] vfy, double arsize, boolean typeofchamp) {
819
820         GraphicController controller = GraphicController.getController();
821         Axes axes = (Axes) controller.getObjectFromId(parent);
822
823         int iChamp = controller.askObject(Type.CHAMP);
824         Champ champ = (Champ)controller.getObjectFromId(iChamp);
825
826         champ.setVisible(axes.getVisible());
827
828         //clip box
829         champ.setClipBox(axes.getClipBox());
830         champ.setClipBoxSet(axes.getClipBoxSet());
831         champ.setClipState(axes.getClipState());
832
833         int numberArrows = vx.length * vy.length;
834         champ.setNumberArrows(numberArrows);
835
836         Integer[] dimensions = new Integer[] {vx.length, vy.length};
837         champ.setDimensions(dimensions);
838
839         champ.setArrowSize(arsize);
840
841         Double[] arrowCoords = new Double[3 * numberArrows];
842
843         //convert vx Double
844         Double[] temp = new Double[vx.length];
845         for (int i =  0 ; i < vx.length ; i++) {
846             temp[i] = vx[i];
847         }
848         champ.setBaseX(temp);
849
850         //convert vy Double
851         temp = new Double[vy.length];
852         for (int i =  0 ; i < vy.length ; i++) {
853             temp[i] = vy[i];
854         }
855         champ.setBaseY(temp);
856
857         for (int i = 0 ; i < numberArrows ; i++) {
858             arrowCoords[3 * i] = vfx[i];
859             arrowCoords[3 * i + 1] = vfy[i];
860             arrowCoords[3 * i + 2] = 0.0;
861         }
862
863         champ.setDirection(arrowCoords);
864         champ.setColored(typeofchamp);
865
866         cloneGraphicContext(parent, iChamp);
867
868         controller.objectCreated(iChamp);
869         controller.setGraphicObjectRelationship(parent, iChamp);
870
871         return iChamp;
872     }
873
874     public static int createSurface(int parent, int typeof3d, int colorFlag, int colorMode) {
875         GraphicController controller = GraphicController.getController();
876         Axes axes = (Axes) controller.getObjectFromId(parent);
877
878         int iSurf = controller.askObject(GraphicObject.getTypeFromName(typeof3d));
879         Surface surf = (Surface) controller.getObjectFromId(iSurf);
880
881         surf.setVisible(axes.getVisible());
882
883         //clip box
884         surf.setClipBox(axes.getClipBox());
885         surf.setClipBoxSet(axes.getClipBoxSet());
886         surf.setClipState(axes.getClipState());
887
888         surf.setColorFlag(colorFlag);
889         surf.setColorMode(colorMode);
890
891         surf.setHiddenColor(axes.getHiddenColor());
892
893         surf.setSurfaceMode(true);
894         cloneGraphicContext(parent, iSurf);
895         controller.objectCreated(iSurf);
896         controller.setGraphicObjectRelationship(parent, iSurf);
897
898         return iSurf;
899     }
900
901     public static void initSubWinTo3d(int iSubwin, String legend, boolean isLegend,
902                                       int[] flag, double alpha, double theta,
903                                       double[] ebox, double[] x, double[] y, double[] z) {
904         GraphicController controller = GraphicController.getController();
905
906         // Force 3d view
907         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_VIEW__, 1);
908
909         if (isLegend) {
910             StringTokenizer strTok =  new StringTokenizer(legend, "@");
911             int iToken = strTok.countTokens();
912             if (iToken > 0) {
913                 //X
914                 String str[] = new String[] {strTok.nextToken()};
915                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
916                 Integer[] dims = new Integer[] {1, 1};
917                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
918                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
919             }
920
921             if (iToken > 1) {
922                 //Y
923                 String str[] = new String[] {strTok.nextToken()};
924                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
925                 Integer[] dims = new Integer[] {1, 1};
926                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
927                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
928             }
929
930             if (iToken > 2) {
931                 //Z
932                 String str[] = new String[] {strTok.nextToken()};
933                 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
934                 Integer[] dims = new Integer[] {1, 1};
935                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
936                 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
937             }
938         }
939
940         // Force psubwin->logflags to linear
941         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
942         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
943         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
944
945         Boolean firstPlot = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_FIRST_PLOT__);
946
947         if (firstPlot && (flag[2] == 0 || flag[2] == 1)) {
948             /* Nothing to do */
949         } else {
950             if (flag[2] == 0 || flag[2] == 1) {
951                 if (firstPlot) {
952                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
953                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
954                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
955
956                     // 0: OFF
957                     controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 0);
958
959                     Integer label = 0;
960                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
961                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
962                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
963                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
964                     label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
965                     controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
966                 }
967             } else if (flag[2] == 2) {
968                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
969                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
970                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
971
972                 //2: HIDDEN_AXES
973                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 2);
974
975                 Integer label = 0;
976                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
977                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
978                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
979                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
980                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
981                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
982
983             } else if (flag[2] == 3) {
984                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
985                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
986                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
987
988                 //1: ON
989                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
990
991                 Integer label = 0;
992                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
993                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
994                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
995                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
996                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
997                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
998
999             } else if (flag[2] == 4) {
1000                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, true);
1001                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, true);
1002                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, true);
1003
1004                 //1: ON
1005                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
1006
1007                 Integer label = 0;
1008                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
1009                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1010                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
1011                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1012                 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
1013                 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1014             }
1015         }
1016
1017         Double[] rotationAngles = new Double[] {alpha, theta};
1018         controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, rotationAngles);
1019
1020         Double[] dataBounds = (Double[]) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__);
1021         Boolean autoScale = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_AUTO_SCALE__);
1022
1023         Double rect[] = new Double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
1024         if (autoScale) {
1025             // compute and merge new specified bounds with data bounds
1026             switch (flag[1]) {
1027                 case 0 :
1028                     break;
1029                 case 1 :
1030                 case 3 :
1031                 case 5 :
1032                 case 7 :
1033                     rect[0] = ebox[0]; // xmin
1034                     rect[1] = ebox[1]; // xmax
1035                     rect[2] = ebox[2]; // ymin
1036                     rect[3] = ebox[3]; // ymax
1037                     rect[4] = ebox[4]; // zmin
1038                     rect[5] = ebox[5]; // zmax
1039                     break;
1040                 case 2 :
1041                 case 4 :
1042                 case 6 :
1043                 case 8 :
1044                     double[] res = getDrect(x, rect[0], rect[1], dataBounds[0], dataBounds[1]);
1045                     rect[0] = res[0];
1046                     rect[1] = res[1];
1047
1048                     res = getDrect(y, rect[2], rect[3], dataBounds[2], dataBounds[3]);
1049                     rect[2] = res[0];
1050                     rect[3] = res[1];
1051
1052                     res = getDrect(z, rect[4], rect[5], dataBounds[4], dataBounds[5]);
1053                     rect[4] = res[0];
1054                     rect[5] = res[1];
1055                     break;
1056             }
1057
1058             if (firstPlot == false) {
1059                 rect[0] = Math.min(dataBounds[0], rect[0]); // xmin
1060                 rect[1] = Math.max(dataBounds[1], rect[1]); // xmax
1061                 rect[2] = Math.min(dataBounds[2], rect[2]); // ymin
1062                 rect[3] = Math.max(dataBounds[3], rect[3]); // ymax
1063                 rect[4] = Math.min(dataBounds[4], rect[4]); // zmin
1064                 rect[5] = Math.max(dataBounds[5], rect[5]); // zmax
1065             }
1066
1067             if (flag[1] != 0) {
1068                 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__, rect);
1069             }
1070         }
1071
1072         if (flag[1] != 0) {
1073             boolean isoview = (flag[1] == 3 || flag[1] == 4 || flag[1] == 5 || flag[1] == 6);
1074             controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ISOVIEW__, isoview);
1075         }
1076     }
1077
1078     private static double[] getDrect(double[] x, double min, double max, double defaultMin, double defaultMax) {
1079         double refMax = Double.NEGATIVE_INFINITY;
1080         double refMin = Double.POSITIVE_INFINITY;
1081         boolean isInfinite = true;
1082
1083         for (int i = 0 ; i < x.length ; i++) {
1084             Double tmp = x[i];
1085             if (tmp.isInfinite() == false && tmp.isNaN() == false) {
1086                 refMin = Math.min(refMin, tmp);
1087                 refMax = Math.max(refMax, tmp);
1088                 isInfinite = false;
1089             }
1090         }
1091
1092         if (isInfinite) {
1093             refMin = defaultMin;
1094             refMax = defaultMax;
1095         }
1096
1097         return new double[] {refMin, refMax};
1098     }
1099
1100     private static boolean  isValidType(int type) {
1101         return type >= 0 && type <= 1;
1102     }
1103
1104     private static boolean isValidColor(double[] color) {
1105         return (color[0] >= 0.0 && color[0] <= 1.0)
1106                && (color[1] >= 0.0 && color[1] <= 1.0)
1107                && (color[2] >= 0.0 && color[2] <= 1.0);
1108     }
1109
1110     public static int createLight(int parent, int type, boolean visible, double[] pos,
1111                                   double[] dir, double[] ambient, double[] diffuse, double[] specular) {
1112         GraphicController controller = GraphicController.getController();
1113
1114         int iLight = controller.askObject(Type.LIGHT);
1115         Light light = (Light) controller.getObjectFromId(iLight);
1116
1117         light.setVisible(visible);
1118         if (isValidType(type)) {
1119             light.setLightType(LightType.intToEnum(type));
1120         }
1121
1122         if (pos.length == 3) {
1123             light.setPosition(toDouble(pos));
1124         }
1125
1126         if (dir.length == 3) {
1127             light.setDirection(toDouble(dir));
1128         }
1129         if (ambient.length == 3) {
1130             if (isValidColor(ambient)) {
1131                 light.setAmbientColor(toDouble(ambient));
1132             }
1133         }
1134         if (diffuse.length == 3) {
1135             if (isValidColor(diffuse)) {
1136                 light.setDiffuseColor(toDouble(diffuse));
1137             }
1138         }
1139         if (specular.length == 3) {
1140             if (isValidColor(specular)) {
1141                 light.setSpecularColor(toDouble(specular));
1142             }
1143         }
1144
1145         controller.objectCreated(iLight);
1146         // Set light's parent
1147         controller.setGraphicObjectRelationship(parent, iLight);
1148         return iLight;
1149     }
1150
1151     private static Double[] toDouble(double[] var) {
1152         Double[] ret = new Double[var.length];
1153         for (int i = 0 ; i < var.length ; i++) {
1154             ret[i] = var[i];
1155         }
1156
1157         return ret;
1158     }
1159
1160     private static Integer[] toInteger(int[] var) {
1161         Integer[] ret = new Integer[var.length];
1162         for (int i = 0 ; i < var.length ; i++) {
1163             ret[i] = var[i];
1164         }
1165
1166         return ret;
1167     }
1168 }
1169