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
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
14 package org.scilab.modules.graphic_objects.builder;
16 import java.util.ArrayList;
17 import java.util.StringTokenizer;
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;
44 public final class Builder {
45 public final static int createRect(int parentSubwin, double x, double y, double height, double width, int foreground, int background, int isfilled, int isline) {
46 GraphicController controller = GraphicController.getController();
47 Axes axes = (Axes) controller.getObjectFromId(parentSubwin);
49 if (height < 0 || width < 0) {
53 Integer iRect = controller.askObject(Type.RECTANGLE, false);
56 * Sets the rectangle's parent in order to initialize the former's
57 * Contoured properties with the latter's values (cloneGraphicContext
61 Rectangle rect = (Rectangle) controller.getObjectFromId(iRect);
62 rect.setUpperLeftPoint(new Double[] { x, y, 0.0 });
63 rect.setHeight(height);
66 rect.setVisible(axes.getVisible());
68 /* Clip state and region */
69 /* To be checked for consistency */
71 rect.setClipBox(axes.getClipBox());
72 rect.setClipBoxSet(axes.getClipBoxSet());
73 rect.setClipState(axes.getClipState());
74 rect.setMarkMode(axes.getMarkMode());
77 * Initializes the contour properties (background, foreground, etc) to
78 * the default values (those of the parent Axes).
80 cloneGraphicContext(parentSubwin, iRect);
82 /* Contour settings */
83 rect.setLineMode(isline == 1);
84 rect.setFillMode(isfilled == 1);
86 if (foreground != -1) {
87 rect.setLineColor(foreground);
90 if (background != -1) {
91 rect.setBackground(background);
94 controller.objectCreated(iRect);
97 * Sets the Axes as the rectangle's parent and adds the rectangle to its
98 * parent's list of children.
100 //setGraphicObjectRelationship(pparentsubwinUID, pobjUID);
105 public static int cloneGraphicContext(int sourceIdentifier, int destIdentifier) {
106 GraphicController controller = GraphicController.getController();
107 Boolean lineMode = false;
108 Integer foreground = 0;
109 Integer lineStyle = 0;
110 Integer background = 0;
111 Integer markForeground = 0;
112 Integer markBackground = 0;
113 Integer markStyle = 0;
114 Integer markSize = 0;
115 Integer markSizeUnit = 0;
116 Double lineThickness = 0.;
119 * All these properties are passed by value thus do not care to release
120 * them and do not call releaseGraphicObjectProperty on purpose.
123 lineMode = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
124 foreground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
125 lineThickness = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
126 lineStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
128 background = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
130 markForeground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
132 markBackground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
134 markStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
136 markSize = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
138 markSizeUnit = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
140 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode);
141 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
142 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
143 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
145 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
147 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
148 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
149 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
150 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
151 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
156 public static int cloneFontContext(int sourceIdentifier, int destIdentifier) {
157 GraphicController controller = GraphicController.getController();
159 Integer fontColor = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__);
160 Integer fontStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__);
161 Double fontSize = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__);
162 Boolean fontFractional = (Boolean) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__);
164 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_COLOR__, fontColor);
165 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_STYLE__, fontStyle);
166 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_SIZE__, fontSize);
167 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_FONT_FRACTIONAL__, fontFractional);
172 public static int createHiddenLabel(int parent) {
174 GraphicController controller = GraphicController.getController();
176 Integer iLabel = controller.askObject(Type.LABEL, false);
177 Label label = (Label) controller.getObjectFromId(iLabel);
179 //Hide Label as they are non explicit children
180 label.setHidden(true);
181 label.setAutoPosition(true);
182 label.setAutoRotation(true);
184 cloneGraphicContext(parent, iLabel);
185 cloneFontContext(parent, iLabel);
186 controller.objectCreated(iLabel);
188 // Sets the label's parent
189 controller.setGraphicObjectRelationship(parent, iLabel);
194 public static void initSubWinBounds(int subWin) {
195 GraphicController controller = GraphicController.getController();
197 controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
198 controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
199 controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
202 public static void reinitSubWin(int subWin) {
203 GraphicController controller = GraphicController.getController();
206 for (Integer childId : (Integer[]) controller.getProperty(subWin, GraphicObjectProperties.__GO_CHILDREN__)) {
207 GraphicModel.getModel().deleteObject(childId);
210 label = createHiddenLabel(subWin);
211 controller.setProperty(subWin, GraphicObjectProperties.__GO_TITLE__, label);
213 label = createHiddenLabel(subWin);
214 controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LABEL__, label);
216 label = createHiddenLabel(subWin);
217 controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__, label);
219 label = createHiddenLabel(subWin);
220 controller.setProperty(subWin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__, label);
222 controller.setProperty(subWin, GraphicObjectProperties.__GO_X_AXIS_LOCATION__, 0);
223 controller.setProperty(subWin, GraphicObjectProperties.__GO_Y_AXIS_LOCATION__, 4);
224 controller.setProperty(subWin, GraphicObjectProperties.__GO_VISIBLE__, true);
225 controller.setProperty(subWin, GraphicObjectProperties.__GO_FIRST_PLOT__, true);
227 Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
228 Axes axes = (Axes) controller.getObjectFromId(axesModel);
230 controller.setProperty(subWin, GraphicObjectProperties.__GO_VIEW__, axes.getView());
231 controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, axes.getRotationAngles());
232 controller.setProperty(subWin, GraphicObjectProperties.__GO_ROTATION_ANGLES_3D__, axes.getRotationAngles3d());
235 public static boolean isAxesRedrawing(int subWin) {
236 GraphicController controller = GraphicController.getController();
237 Axes axes = (Axes) controller.getObjectFromId(subWin);
239 if (axes.getAutoClear()) {
240 reinitSubWin(subWin);
246 public static int createLabel(int parent, int type) {
247 GraphicController controller = GraphicController.getController();
248 Double[] position = new Double[3];
254 Integer parentType = (Integer) controller.getProperty(parent, GraphicObjectProperties.__GO_TYPE__);
255 if (parentType != GraphicObjectProperties.__GO_AXES__) {
260 Integer axesModel = GraphicModel.getAxesModel().getIdentifier();
262 //get type label from axes model
263 Integer labelSource = (Integer) controller.getProperty(axesModel, type);
266 Integer newLabel = controller.cloneObject(labelSource);
267 controller.setProperty(newLabel, GraphicObjectProperties.__GO_POSITION__, position);
268 // Auto position must be reset as setting the position has set it to false
269 Boolean autoPosition = (Boolean) controller.getProperty(labelSource, GraphicObjectProperties.__GO_AUTO_POSITION__);
270 controller.setProperty(newLabel, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition);
272 // Set relation between newLabel and parent
273 controller.setProperty(parent, type, newLabel);
274 controller.setGraphicObjectRelationship(parent, newLabel);
278 public final static int createFigureFromModel() {
279 GraphicController controller = GraphicController.getController();
280 return controller.cloneObject(GraphicModel.getFigureModel().getIdentifier());
283 public final static int cloneAxesModel(int parent) {
284 GraphicController controller = GraphicController.getController();
286 Integer newAxes = controller.cloneObject(GraphicModel.getAxesModel().getIdentifier());
287 createLabel(newAxes, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
288 createLabel(newAxes, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
289 createLabel(newAxes, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
290 createLabel(newAxes, GraphicObjectProperties.__GO_TITLE__);
292 controller.setGraphicObjectRelationship(parent, newAxes);
293 controller.setProperty(parent, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAxes);
295 ScilabNativeView.ScilabNativeView__setCurrentSubWin(newAxes);
296 ScilabNativeView.ScilabNativeView__setCurrentObject(newAxes);
300 public final static void cloneMenus(int iModel, int iParent) {
301 GraphicController controller = GraphicController.getController();
302 GraphicObject model = controller.getObjectFromId(iModel);
304 Integer[] children = model.getChildren();
306 for (int i = children.length - 1; i >= 0; i--) {
307 GraphicObject child = controller.getObjectFromId(children[i]);
308 if (child.getType() == GraphicObjectProperties.__GO_UIMENU__) {
309 Integer newMenu = controller.cloneObject(children[i]);
310 controller.setGraphicObjectRelationship(iParent, newMenu);
312 cloneMenus(children[i], newMenu);
317 public final static int createFigure(boolean dockable, int menubarType, int toolbarType, boolean defaultAxes, boolean visible, double[] figureSize, double[] axesSize, double[] position,
318 boolean menubar, boolean toolbar, boolean infobar) {
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 figure.setDefaultAxes(defaultAxes);
329 //set figure size only if axes size is not set too
330 if (figureSize != null && figureSize.length == 2 && (axesSize == null || axesSize.length == 0)) {
331 figure.setSize(new Integer[] { (int) figureSize[0], (int) figureSize[1] });
334 if (position != null && position.length == 2) {
335 figure.setPosition(new Integer[] { (int) position[0], (int) position[1] });
338 figure.setMenubarVisible(menubar);
339 figure.setToolbarVisible(toolbar);
340 figure.setInfobarVisible(infobar);
342 controller.objectCreated(figId);
344 ScilabNativeView.ScilabNativeView__setCurrentFigure(figId);
346 if (menubarType == BarType.FIGURE.ordinal()) {
347 cloneMenus(figModel, figId);
352 cloneAxesModel(figId);
355 if (axesSize != null && axesSize.length == 2) {
356 controller.setProperty(figId, GraphicObjectProperties.__GO_AXES_SIZE__, new Integer[] { (int) axesSize[0], (int) axesSize[1] });
362 public final static int createNewFigureWithAxes() {
363 GraphicController controller = GraphicController.getController();
364 Integer figModel = GraphicModel.getFigureModel().getIdentifier();
366 //clone default figure
367 Integer newFigure = createFigureFromModel();
369 //Clone the default menus
370 cloneMenus(figModel, newFigure);
373 controller.setProperty(newFigure, GraphicObjectProperties.__GO_ID__, 0);
376 cloneAxesModel(newFigure);
377 ScilabNativeView.ScilabNativeView__setCurrentFigure(newFigure);
379 //Force axes size after window creation
380 Integer[] axesSize = (Integer[]) controller.getProperty(figModel, GraphicObjectProperties.__GO_AXES_SIZE__);
381 controller.setProperty(newFigure, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
383 controller.setProperty(newFigure, GraphicObjectProperties.__GO_VALID__, true);
388 public final static int createSubWin(int parentFigure) {
389 //GraphicController controller = GraphicController.getController();
390 //GraphicObject parent = controller.getObjectFromId(parentFigure);
391 //if (parent.getType() != GraphicObjectProperties.__GO_FIGURE__) {
395 return cloneAxesModel(parentFigure);
398 public final static int createText(int iParentsubwinUID, String[] str, int nbRow, int nbCol, double x, double y, boolean autoSize, double[] userSize, int centerPos, int foreground,
399 boolean isForeground, int background, boolean isBackground, boolean isBoxed, boolean isLine, boolean isFilled, int align) {
401 GraphicController controller = GraphicController.getController();
402 int iText = controller.askObject(Type.TEXT, false);
404 Axes axes = (Axes) controller.getObjectFromId(iParentsubwinUID);
405 Text text = (Text) controller.getObjectFromId(iText);
408 text.setClipBox(axes.getClipBox());
409 text.setClipBoxSet(axes.getClipBoxSet());
410 text.setClipState(axes.getClipState());
413 Integer[] dimensions = new Integer[2];
414 dimensions[0] = nbRow;
415 dimensions[1] = nbCol;
416 text.setTextArrayDimensions(dimensions);
417 text.setTextStrings(str);
420 Double[] position = new Double[3];
424 text.setPosition(position);
427 Double[] setUserSize = new Double[2];
428 text.setTextBoxMode(centerPos);
429 text.setAutoDimensioning(autoSize);
431 if (autoSize == false || centerPos != 0) {
432 setUserSize[0] = userSize[0];
433 setUserSize[1] = userSize[1];
435 setUserSize[0] = 0.0;
436 setUserSize[1] = 0.0;
438 text.setTextBox(setUserSize);
440 int alignment = align - 1;
441 if (alignment < 0 || alignment > 2) {
445 text.setAlignment(alignment);
447 cloneGraphicContext(iParentsubwinUID, iText);
448 cloneFontContext(iParentsubwinUID, iText);
450 text.setBox(isBoxed);
451 text.setLineMode(isLine);
452 text.setFillMode(isFilled);
455 text.setLineColor(foreground);
459 text.setBackground(background);
462 text.setVisible(axes.getVisible());
463 controller.objectCreated(iText);
467 public final static int createArc(int parent, double x, double y, double h, double w, double startAngle, double endAngle, int foreground, boolean isForeground, int background,
468 boolean isBackground, boolean filled, boolean line) {
470 GraphicController controller = GraphicController.getController();
471 int iArc = controller.askObject(Type.ARC, false);
473 Axes axes = (Axes) controller.getObjectFromId(parent);
474 Arc arc = (Arc) controller.getObjectFromId(iArc);
476 //set visible false during construction
477 arc.setVisible(false);
479 Double[] upperLeftPoint = new Double[3];
480 upperLeftPoint[0] = x;
481 upperLeftPoint[1] = y;
482 upperLeftPoint[2] = 0.0;
484 arc.setUpperLeftPoint(upperLeftPoint);
487 arc.setStartAngle(startAngle);
488 arc.setEndAngle(endAngle);
489 arc.setArcDrawingMethod(axes.getArcDrawingMethod());
492 arc.setClipBox(axes.getClipBox());
493 arc.setClipBoxSet(axes.getClipBoxSet());
494 arc.setClipState(axes.getClipState());
496 cloneGraphicContext(parent, iArc);
498 arc.setLineMode(line);
499 arc.setFillMode(filled);
502 arc.setLineColor(foreground);
506 arc.setBackground(background);
509 arc.setVisible(axes.getVisible());
510 controller.objectCreated(iArc);
511 controller.setGraphicObjectRelationship(parent, iArc);
515 public final static int createAxis(int parent, int dir, int tics, double[] vx, double[] vy, int subint, String format, int fontSize, int textColor, int ticsColor, boolean seg) {
517 GraphicController controller = GraphicController.getController();
518 int iAxis = controller.askObject(Type.AXIS, false);
520 Axes axes = (Axes) controller.getObjectFromId(parent);
521 Axis axis = (Axis) controller.getObjectFromId(iAxis);
524 axis.setClipBox(axes.getClipBox());
525 axis.setClipBoxSet(false);
527 axis.setTicksDirection(dir);
528 axis.setTicksStyle(tics);
530 axis.setXTicksCoords(toDouble(vx));
531 axis.setYTicksCoords(toDouble(vy));
533 if (format != null && format.equals("") == false) {
534 axis.setFormatn(format);
537 axis.setSubticks(subint);
538 axis.setTicksSegment(seg);
539 cloneGraphicContext(parent, iAxis);
540 cloneFontContext(parent, iAxis);
542 Font font = axis.getFont();
543 font.setSize(new Double(fontSize));
544 font.setColor(textColor);
545 axis.setTicksColor(ticsColor);
547 controller.objectCreated(iAxis);
548 controller.setGraphicObjectRelationship(parent, iAxis);
552 public static int createCompound(int parent, int[] children) {
553 GraphicController controller = GraphicController.getController();
554 int iCompound = controller.askObject(Type.COMPOUND);
556 GraphicObject obj = controller.getObjectFromId(parent);
557 for (int i = 0; i < children.length; i++) {
558 controller.setGraphicObjectRelationship(iCompound, children[i]);
561 controller.setGraphicObjectRelationship(parent, iCompound);
562 controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, obj.getVisible());
566 public static int createCompoundSeq(int parent, int childrenCount) {
567 GraphicController controller = GraphicController.getController();
568 int iCompound = controller.askObject(Type.COMPOUND);
569 GraphicObject axes = controller.getObjectFromId(parent);
571 Integer[] children = axes.getChildren();
574 * Remove the last "number" created objects (located at the children
575 * list's head) and add them to the compound in the same order
577 for (int i = 0; i < childrenCount; i++) {
579 * Set the parent-child relationship between the Compound and each
580 * aggregated object. Children are added to the Compound from the
581 * least recent to the most recent, to preserve their former
584 controller.setGraphicObjectRelationship(iCompound, children[childrenCount - i - 1]);
587 controller.setGraphicObjectRelationship(parent, iCompound);
590 * visibility is obtained from the parent Figure, whereas it is
591 * retrieved from the parent Axes in ConstructCompound. To be made
594 Figure fig = (Figure) controller.getObjectFromId(axes.getParentFigure());
595 controller.setProperty(iCompound, GraphicObjectProperties.__GO_VISIBLE__, fig.getVisible());
599 public static int createFec(int parent, double[] zminmax, int[] colminmax, int[] colout, boolean with_mesh) {
601 GraphicController controller = GraphicController.getController();
602 int iFec = controller.askObject(Type.FEC, false);
603 Axes axes = (Axes) controller.getObjectFromId(parent);
604 Fec fec = (Fec) controller.getObjectFromId(iFec);
606 fec.setZBounds(toDouble(zminmax));
607 fec.setColorRange(toInteger(colminmax));
608 fec.setOutsideColor(toInteger(colout));
610 fec.setVisible(axes.getVisible());
613 fec.setClipBox(axes.getClipBox());
614 fec.setClipBoxSet(axes.getClipBoxSet());
615 fec.setClipState(axes.getClipState());
617 cloneGraphicContext(parent, iFec);
619 fec.setLineMode(with_mesh);
621 controller.objectCreated(iFec);
625 public static int createGrayplot(int parent, int type, double[] pvecx, int n1, int n2) {
627 int[] objectTypes = new int[] { GraphicObjectProperties.__GO_GRAYPLOT__, GraphicObjectProperties.__GO_MATPLOT__, GraphicObjectProperties.__GO_MATPLOT__ };
629 GraphicController controller = GraphicController.getController();
630 int iPlot = controller.askObject(GraphicObject.getTypeFromName(objectTypes[type]), false);
631 Axes axes = (Axes) controller.getObjectFromId(parent);
632 Imageplot plot = (Imageplot) controller.getObjectFromId(iPlot);
634 if (type == 2) { //Matplot1
635 Double[] data = new Double[pvecx.length];
636 for (int i = 0; i < pvecx.length; i++) {
639 plot.setTranslate(data);
641 Double[] scale = new Double[2];
642 scale[0] = (pvecx[2] - pvecx[0]) / (n2 - 1.0);
643 scale[1] = (pvecx[3] - pvecx[1]) / (n1 - 1.0);
644 plot.setScale(scale);
647 plot.setVisible(axes.getVisible());
650 plot.setClipBox(axes.getClipBox());
651 plot.setClipBoxSet(axes.getClipBoxSet());
652 plot.setClipState(axes.getClipState());
654 cloneGraphicContext(parent, iPlot);
655 controller.objectCreated(iPlot);
659 public static int createPolyline(int parent, boolean closed, int plot, int foreground, boolean isForeground, int[] background, int mark_style, boolean isMarkStyle, int mark_foreground,
660 boolean isMarkForeground, int mark_background, boolean isMarkBackground, boolean isline, boolean isfilled, boolean ismark, boolean isinterp) {
662 GraphicController controller = GraphicController.getController();
663 int iPoly = controller.askObject(Type.POLYLINE, false);
664 Axes axes = (Axes) controller.getObjectFromId(parent);
665 Polyline poly = (Polyline) controller.getObjectFromId(iPoly);
667 poly.setVisible(false);
670 poly.setClipBox(axes.getClipBox());
671 poly.setClipBoxSet(axes.getClipBoxSet());
672 poly.setClipState(axes.getClipState());
674 poly.setClosed(closed);
675 poly.setPolylineStyle(plot);
677 cloneGraphicContext(parent, iPoly);
679 poly.setMarkMode(ismark);
680 poly.setLineMode(isline);
681 poly.setFillMode(isfilled);
682 poly.setInterpColorMode(isinterp);
685 poly.setLineColor(foreground);
688 if (background.length != 0) {
690 /* 3 or 4 values to store */
691 Integer[] color = new Integer[background.length];
692 for (int i = 0; i < background.length; i++) {
693 color[i] = background[i];
696 poly.setInterpColorVector(color);
698 poly.setBackground(background[0]);
703 poly.setMarkStyle(mark_style);
706 if (isMarkForeground) {
707 poly.setMarkForeground(mark_foreground);
710 if (isMarkBackground) {
711 poly.setMarkBackground(mark_background);
714 poly.setVisible(true);
715 controller.objectCreated(iPoly);
719 public static int createLegend(int parent, String[] text, int[] handles) {
720 GraphicController controller = GraphicController.getController();
721 Axes axes = (Axes) controller.getObjectFromId(parent);
723 if (axes.getHasLegendChild()) {
724 controller.removeRelationShipAndDelete(axes.getLegendChild());
727 int iLeg = controller.askObject(Type.LEGEND, false);
728 Legend leg = (Legend) controller.getObjectFromId(iLeg);
730 leg.setParent(parent);
731 leg.setVisible(axes.getVisible());
733 int count = handles.length;
734 Integer[] textDims = new Integer[2];
738 leg.setTextArrayDimensions(textDims);
739 leg.setTextStrings(text);
742 * Links are ordered from most recent to least recent, as their
743 * referred-to Polylines in the latter's parent Compound object.
746 ArrayList<Integer> links = new ArrayList<Integer>();
747 for (int i = count - 1; i >= 0; i--) {
748 links.add(count - i - 1, handles[i]);
753 leg.setClipBoxSet(false);
754 leg.setClipState(0); //OFF
755 leg.setClipBox(axes.getClipBox());
757 cloneGraphicContext(parent, iLeg);
758 cloneFontContext(parent, iLeg);
760 leg.setFillMode(true);
762 controller.objectCreated(iLeg);
764 controller.setGraphicObjectRelationship(parent, iLeg);
768 public static int createSegs(int parent, double[] vx, double[] vy, double[] vz, boolean isVZ, int[] style, double arsize) {
769 GraphicController controller = GraphicController.getController();
770 Axes axes = (Axes) controller.getObjectFromId(parent);
771 int iSegs = controller.askObject(Type.SEGS, false);
772 Segs segs = (Segs) controller.getObjectFromId(iSegs);
774 segs.setVisible(axes.getVisible());
777 segs.setClipBox(axes.getClipBox());
778 segs.setClipBoxSet(axes.getClipBoxSet());
779 segs.setClipState(axes.getClipState());
781 /* Segs: Nbr1/2 arrows, Nbr1 is the number of endpoints */
782 int numberArrows = vx.length / 2;
784 segs.setNumberArrows(numberArrows);
785 segs.setArrowSize(arsize);
787 Double[] arrowCoords = new Double[3 * numberArrows];
788 for (int i = 0; i < numberArrows; i++) {
789 arrowCoords[3 * i] = vx[2 * i];
790 arrowCoords[3 * i + 1] = vy[2 * i];
792 arrowCoords[3 * i + 2] = vz[2 * i];
794 arrowCoords[3 * i + 2] = 0.0;
798 segs.setBase(arrowCoords);
800 for (int i = 0; i < numberArrows; i++) {
801 arrowCoords[3 * i] = vx[2 * i + 1];
802 arrowCoords[3 * i + 1] = vy[2 * i + 1];
804 arrowCoords[3 * i + 2] = vz[2 * i + 1];
806 arrowCoords[3 * i + 2] = 0.0;
810 segs.setDirection(arrowCoords);
811 segs.setColors(toInteger(style));
813 cloneGraphicContext(parent, iSegs);
814 controller.objectCreated(iSegs);
815 controller.setGraphicObjectRelationship(parent, iSegs);
819 public static int createChamp(int parent, double[] vx, double[] vy, double[] vfx, double[] vfy, double arsize, boolean typeofchamp) {
821 GraphicController controller = GraphicController.getController();
822 Axes axes = (Axes) controller.getObjectFromId(parent);
824 int iChamp = controller.askObject(Type.CHAMP, false);
825 Champ champ = (Champ) controller.getObjectFromId(iChamp);
827 champ.setVisible(axes.getVisible());
830 champ.setClipBox(axes.getClipBox());
831 champ.setClipBoxSet(axes.getClipBoxSet());
832 champ.setClipState(axes.getClipState());
834 int numberArrows = vx.length * vy.length;
835 champ.setNumberArrows(numberArrows);
837 Integer[] dimensions = new Integer[] { vx.length, vy.length };
838 champ.setDimensions(dimensions);
840 champ.setArrowSize(arsize);
842 Double[] arrowCoords = new Double[3 * numberArrows];
845 Double[] temp = new Double[vx.length];
846 for (int i = 0; i < vx.length; i++) {
849 champ.setBaseX(temp);
852 temp = new Double[vy.length];
853 for (int i = 0; i < vy.length; i++) {
856 champ.setBaseY(temp);
858 for (int i = 0; i < numberArrows; i++) {
859 arrowCoords[3 * i] = vfx[i];
860 arrowCoords[3 * i + 1] = vfy[i];
861 arrowCoords[3 * i + 2] = 0.0;
864 champ.setDirection(arrowCoords);
865 champ.setColored(typeofchamp);
867 cloneGraphicContext(parent, iChamp);
869 controller.objectCreated(iChamp);
870 controller.setGraphicObjectRelationship(parent, iChamp);
875 public static int createSurface(int parent, int typeof3d, int colorFlag, int colorMode) {
876 GraphicController controller = GraphicController.getController();
877 Axes axes = (Axes) controller.getObjectFromId(parent);
879 int iSurf = controller.askObject(GraphicObject.getTypeFromName(typeof3d), false);
880 Surface surf = (Surface) controller.getObjectFromId(iSurf);
882 surf.setVisible(axes.getVisible());
885 surf.setClipBox(axes.getClipBox());
886 surf.setClipBoxSet(axes.getClipBoxSet());
887 surf.setClipState(axes.getClipState());
889 surf.setColorFlag(colorFlag);
890 surf.setColorMode(colorMode);
892 surf.setHiddenColor(axes.getHiddenColor());
894 surf.setSurfaceMode(true);
895 cloneGraphicContext(parent, iSurf);
896 controller.objectCreated(iSurf);
897 controller.setGraphicObjectRelationship(parent, iSurf);
902 public static void initSubWinTo3d(int iSubwin, String legend, boolean isLegend, int[] flag, double alpha, double theta, double[] ebox, double[] x, double[] y, double[] z) {
903 GraphicController controller = GraphicController.getController();
906 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_VIEW__, 1);
909 StringTokenizer strTok = new StringTokenizer(legend, "@");
910 int iToken = strTok.countTokens();
913 String str[] = new String[] { strTok.nextToken() };
914 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
915 Integer[] dims = new Integer[] { 1, 1 };
916 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
917 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
922 String str[] = new String[] { strTok.nextToken() };
923 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
924 Integer[] dims = new Integer[] { 1, 1 };
925 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
926 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
931 String str[] = new String[] { strTok.nextToken() };
932 Integer label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
933 Integer[] dims = new Integer[] { 1, 1 };
934 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_ARRAY_DIMENSIONS__, dims);
935 controller.setProperty(label, GraphicObjectProperties.__GO_TEXT_STRINGS__, str);
939 // Force psubwin->logflags to linear
940 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__, false);
941 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__, false);
942 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__, false);
944 Boolean firstPlot = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_FIRST_PLOT__);
946 if (firstPlot && (flag[2] == 0 || flag[2] == 1)) {
949 if (flag[2] == 0 || flag[2] == 1) {
951 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
952 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
953 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
956 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 0);
959 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
960 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
961 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
962 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
963 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
964 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
966 } else if (flag[2] == 2) {
967 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
968 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
969 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
972 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 2);
975 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
976 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
977 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
978 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
979 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
980 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, false);
982 } else if (flag[2] == 3) {
983 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, false);
984 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, false);
985 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, false);
988 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
991 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
992 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
993 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
994 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
995 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
996 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
998 } else if (flag[2] == 4) {
999 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_VISIBLE__, true);
1000 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_VISIBLE__, true);
1001 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_VISIBLE__, true);
1004 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_BOX_TYPE__, 1);
1007 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_X_AXIS_LABEL__);
1008 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1009 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Y_AXIS_LABEL__);
1010 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1011 label = (Integer) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_Z_AXIS_LABEL__);
1012 controller.setProperty(label, GraphicObjectProperties.__GO_VISIBLE__, true);
1016 Double[] rotationAngles = new Double[] { alpha, theta };
1017 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ROTATION_ANGLES__, rotationAngles);
1019 Double[] dataBounds = (Double[]) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__);
1020 Boolean autoScale = (Boolean) controller.getProperty(iSubwin, GraphicObjectProperties.__GO_AUTO_SCALE__);
1022 Double rect[] = new Double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
1024 // compute and merge new specified bounds with data bounds
1032 rect[0] = ebox[0]; // xmin
1033 rect[1] = ebox[1]; // xmax
1034 rect[2] = ebox[2]; // ymin
1035 rect[3] = ebox[3]; // ymax
1036 rect[4] = ebox[4]; // zmin
1037 rect[5] = ebox[5]; // zmax
1043 double[] res = getDrect(x, rect[0], rect[1], dataBounds[0], dataBounds[1]);
1047 res = getDrect(y, rect[2], rect[3], dataBounds[2], dataBounds[3]);
1051 res = getDrect(z, rect[4], rect[5], dataBounds[4], dataBounds[5]);
1057 if (firstPlot == false) {
1058 rect[0] = Math.min(dataBounds[0], rect[0]); // xmin
1059 rect[1] = Math.max(dataBounds[1], rect[1]); // xmax
1060 rect[2] = Math.min(dataBounds[2], rect[2]); // ymin
1061 rect[3] = Math.max(dataBounds[3], rect[3]); // ymax
1062 rect[4] = Math.min(dataBounds[4], rect[4]); // zmin
1063 rect[5] = Math.max(dataBounds[5], rect[5]); // zmax
1067 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_DATA_BOUNDS__, rect);
1072 boolean isoview = (flag[1] == 3 || flag[1] == 4 || flag[1] == 5 || flag[1] == 6);
1073 controller.setProperty(iSubwin, GraphicObjectProperties.__GO_ISOVIEW__, isoview);
1077 private static double[] getDrect(double[] x, double min, double max, double defaultMin, double defaultMax) {
1078 double refMax = Double.NEGATIVE_INFINITY;
1079 double refMin = Double.POSITIVE_INFINITY;
1080 boolean isInfinite = true;
1082 for (int i = 0; i < x.length; i++) {
1084 if (tmp.isInfinite() == false && tmp.isNaN() == false) {
1085 refMin = Math.min(refMin, tmp);
1086 refMax = Math.max(refMax, tmp);
1092 refMin = defaultMin;
1093 refMax = defaultMax;
1096 return new double[] { refMin, refMax };
1099 private static boolean isValidType(int type) {
1100 return type >= 0 && type <= 1;
1103 private static boolean isValidColor(double[] color) {
1104 return (color[0] >= 0.0 && color[0] <= 1.0) && (color[1] >= 0.0 && color[1] <= 1.0) && (color[2] >= 0.0 && color[2] <= 1.0);
1107 public static int createLight(int parent, int type, boolean visible, double[] pos, double[] dir, double[] ambient, double[] diffuse, double[] specular) {
1108 GraphicController controller = GraphicController.getController();
1110 int iLight = controller.askObject(Type.LIGHT, false);
1111 Light light = (Light) controller.getObjectFromId(iLight);
1113 light.setVisible(visible);
1114 if (isValidType(type)) {
1115 light.setLightType(LightType.intToEnum(type));
1118 if (pos.length == 3) {
1119 light.setPosition(toDouble(pos));
1122 if (dir.length == 3) {
1123 light.setDirection(toDouble(dir));
1125 if (ambient.length == 3) {
1126 if (isValidColor(ambient)) {
1127 light.setAmbientColor(toDouble(ambient));
1130 if (diffuse.length == 3) {
1131 if (isValidColor(diffuse)) {
1132 light.setDiffuseColor(toDouble(diffuse));
1135 if (specular.length == 3) {
1136 if (isValidColor(specular)) {
1137 light.setSpecularColor(toDouble(specular));
1141 controller.objectCreated(iLight);
1142 // Set light's parent
1143 controller.setGraphicObjectRelationship(parent, iLight);
1147 private static Double[] toDouble(double[] var) {
1148 Double[] ret = new Double[var.length];
1149 for (int i = 0; i < var.length; i++) {
1156 private static Integer[] toInteger(int[] var) {
1157 Integer[] ret = new Integer[var.length];
1158 for (int i = 0; i < var.length; i++) {