2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Bruno JOFRET
4 * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
5 * Copyright (C) 2013 - 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 package org.scilab.modules.graphic_objects;
17 import org.scilab.modules.graphic_objects.figure.Figure;
18 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
19 import org.scilab.modules.graphic_objects.graphicModel.GraphicModel;
20 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
23 * This is a static class to access all controller capabilities
24 * from C/C++ code through JNI
25 * See SCI/modules/graphic_objects/src/jni/graphic_objects.giws.xml for other details.
27 public final class GraphicObjectBuilder {
29 public static Figure createNewFigureWithAxes(Integer id) {
30 GraphicController controller = GraphicController.getController();
32 final int[] props = new int[] {GraphicObjectProperties.__GO_X_AXIS_LABEL__, GraphicObjectProperties.__GO_Y_AXIS_LABEL__, GraphicObjectProperties.__GO_Z_AXIS_LABEL__, GraphicObjectProperties.__GO_TITLE__};
33 String figureModelUID = GraphicModel.getModel().getFigureModel().getIdentifier();
34 String axesModelUID = GraphicModel.getModel().getAxesModel().getIdentifier();
35 String newFID = controller.createUID().toString();
36 String newAID = controller.createUID().toString();
37 GraphicModel.getModel().cloneObject(figureModelUID, newFID);
38 GraphicModel.getModel().cloneObject(axesModelUID, newAID);
40 controller.setProperty(newFID, GraphicObjectProperties.__GO_ID__, id);
41 controller.setGraphicObjectRelationship(newFID, newAID);
42 controller.setProperty(newFID, GraphicObjectProperties.__GO_SELECTED_CHILD__, newAID);
44 for (Integer type : props) {
45 final double[] position = new double[] {1, 1, 1};
46 String modelLabelUID = (String) controller.getProperty(axesModelUID, type);
47 String pobjUID = controller.createUID().toString();
48 GraphicModel.getModel().cloneObject(modelLabelUID, pobjUID);
49 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_POSITION__, position);
51 Boolean autoPosition = (Boolean ) controller.getProperty(modelLabelUID, GraphicObjectProperties.__GO_AUTO_POSITION__);
52 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_AUTO_POSITION__, autoPosition);
54 controller.setProperty(newAID, type, pobjUID);
55 CallGraphicController.setGraphicObjectRelationship(newAID, pobjUID);
58 ScilabNativeView.ScilabNativeView__createObject(newFID);
59 ScilabNativeView.ScilabNativeView__updateObject(newFID, GraphicObjectProperties.__GO_ID__);
60 ScilabNativeView.ScilabNativeView__setCurrentObject(newAID);
61 ScilabNativeView.ScilabNativeView__setCurrentSubWin(newAID);
62 ScilabNativeView.ScilabNativeView__setCurrentFigure(newFID);
64 Integer[] axesSize = (Integer[]) controller.getProperty(figureModelUID, GraphicObjectProperties.__GO_AXES_SIZE__);
65 controller.setProperty(newFID, GraphicObjectProperties.__GO_AXES_SIZE__, axesSize);
67 return (Figure) controller.getObjectFromId(newFID);
70 public static String constructRectangles(String pparentsubwinUID, double x, double y, double height, double width, int foreground, int background, int isfilled, int isline) {
71 GraphicController controller = GraphicController.getController();
74 Boolean visible = false;
75 Boolean clipRegionSet = false;
76 Integer clipState = 0;
77 Boolean iMarkMode = false;
79 if (height < 0 || width < 0) {
83 String pobjUID = CallGraphicController.askGraphicObject(GraphicObjectProperties.__GO_RECTANGLE__);
86 * Sets the rectangle's parent in order to initialize the former's Contoured properties
87 * with the latter's values (cloneGraphicContext call below)
89 //setGraphicObjectProperty(pobjUID, __GO_PARENT__, pparentsubwinUID, jni_string, 1);
91 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__, new Double[] {x, y, 0.0});
92 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_HEIGHT__, height);
93 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_WIDTH__, width);
95 visible = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_VISIBLE__);
96 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_VISIBLE__, visible);
98 /* Clip state and region */
99 /* To be checked for consistency */
101 clipRegion = (Double[]) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX__);
102 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX__, clipRegion);
104 clipRegionSet = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__);
105 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__, clipRegionSet);
107 clipState = (Integer) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_STATE__);
108 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_STATE__, clipState);
110 iMarkMode = (Boolean) controller.getProperty(pparentsubwinUID, GraphicObjectProperties.__GO_MARK_MODE__);
111 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_MARK_MODE__, iMarkMode);
114 * Initializes the contour properties (background, foreground, etc)
115 * to the default values (those of the parent Axes).
117 cloneGraphicContext(pparentsubwinUID, pobjUID);
119 /* Contour settings */
120 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_LINE_MODE__, isline == 1);
121 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_FILL_MODE__, isfilled == 1);
123 if (foreground != -1) {
124 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
127 if (background != -1) {
128 controller.setProperty(pobjUID, GraphicObjectProperties.__GO_BACKGROUND__, background);
131 /* Parent reset to the null object */
132 //setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_PARENT__, "", jni_string, 1);
135 * Sets the Axes as the rectangle's parent and adds the rectangle to
136 * its parent's list of children.
138 //setGraphicObjectRelationship(pparentsubwinUID, pobjUID);
143 public static int cloneGraphicContext(String sourceIdentifier, String destIdentifier) {
144 GraphicController controller = GraphicController.getController();
145 Integer lineMode = 0;
146 Integer foreground = 0;
147 Integer lineStyle = 0;
148 Integer background = 0;
149 Integer markForeground = 0;
150 Integer markBackground = 0;
151 Integer markStyle = 0;
152 Integer markSize = 0;
153 Integer markSizeUnit = 0;
154 Double lineThickness = 0.;
157 * All these properties are passed by value thus do not care to release them
158 * and do not call releaseGraphicObjectProperty on purpose.
161 lineMode = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
162 foreground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
163 lineThickness = (Double) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
164 lineStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
166 background = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
168 markForeground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
170 markBackground = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
172 markStyle = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
174 markSize = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
176 markSizeUnit = (Integer) controller.getProperty(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
178 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode == 1);
179 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
180 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
181 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
183 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
185 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
186 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
187 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
188 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
189 controller.setProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);