Graphics: Move constructRectangle on Java side
[scilab.git] / scilab / modules / graphic_objects / src / java / org / scilab / modules / graphic_objects / GraphicObjectBuilder.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2010 - DIGITEO - Bruno JOFRET
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12
13 package org.scilab.modules.graphic_objects;
14
15 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
16
17 /**
18  * This is a static class to access all controller capabilities
19  * from C/C++ code through JNI
20  * See SCI/modules/graphic_objects/src/jni/graphic_objects.giws.xml for other details.
21  **/
22 public final class GraphicObjectBuilder {
23
24     public static String constructRectangles(String pparentsubwinUID, double x, double y, double height, double width, int foreground, int background, int isfilled, int isline) {
25         double[] clipRegion;
26         int visible = 0;
27         int clipRegionSet = 0;
28         int clipState = 0;
29         int iMarkMode = 0;
30
31         if (height < 0 || width < 0)
32         {
33             return null;
34         }
35
36         String pobjUID = CallGraphicController.askGraphicObject(GraphicObjectProperties.__GO_RECTANGLE__);
37
38         /*
39          * Sets the rectangle's parent in order to initialize the former's Contoured properties
40          * with the latter's values (cloneGraphicContext call below)
41          */
42         //setGraphicObjectProperty(pobjUID, __GO_PARENT__, pparentsubwinUID, jni_string, 1);
43
44         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_UPPER_LEFT_POINT__, new double[]{x, y, 0});
45         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_HEIGHT__, height);
46         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_WIDTH__, width);
47
48         visible = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_VISIBLE__);
49         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_VISIBLE__, visible == 1);
50
51         /* Clip state and region */
52         /* To be checked for consistency */
53
54         clipRegion = CallGraphicController.getGraphicObjectPropertyAsDoubleVector(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX__);
55         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX__, clipRegion);
56
57         clipRegionSet = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__);
58         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_BOX_SET__,  clipRegionSet == 1);
59
60         clipState = CallGraphicController.getGraphicObjectPropertyAsInteger(pparentsubwinUID, GraphicObjectProperties.__GO_CLIP_STATE__);
61         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_CLIP_STATE__, clipState);
62
63         iMarkMode = CallGraphicController.getGraphicObjectPropertyAsBoolean(pparentsubwinUID, GraphicObjectProperties.__GO_MARK_MODE__);
64         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_MARK_MODE__, iMarkMode == 1);
65
66         /*
67          * Initializes the contour properties (background, foreground, etc)
68          * to the default values (those of the parent Axes).
69          */
70         cloneGraphicContext(pparentsubwinUID, pobjUID);
71
72         /* Contour settings */
73         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_LINE_MODE__, isline == 1);
74         CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_FILL_MODE__, isfilled == 1);
75
76         if (foreground != -1)
77         {
78             CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
79         }
80
81         if (background != -1)
82         {
83             CallGraphicController.setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_BACKGROUND__, background);
84         }
85
86         /* Parent reset to the null object */
87         //setGraphicObjectProperty(pobjUID, GraphicObjectProperties.__GO_PARENT__, "", jni_string, 1);
88
89         /*
90          * Sets the Axes as the rectangle's parent and adds the rectangle to
91          * its parent's list of children.
92          */
93         //setGraphicObjectRelationship(pparentsubwinUID, pobjUID);
94
95         return pobjUID;
96     }
97
98     public static int cloneGraphicContext(String sourceIdentifier, String destIdentifier) {
99         int lineMode = 0;
100         int foreground = 0;
101         int lineStyle = 0;
102         int background = 0;
103         int markForeground = 0;
104         int markBackground = 0;
105         int markStyle = 0;
106         int markSize = 0;
107         int markSizeUnit = 0;
108         double lineThickness = 0.;
109
110         /*
111          * All these properties are passed by value thus do not care to release them
112          * and do not call releaseGraphicObjectProperty on purpose.
113          */
114
115         lineMode = CallGraphicController.getGraphicObjectPropertyAsBoolean(sourceIdentifier, GraphicObjectProperties.__GO_LINE_MODE__);
116         foreground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__);
117         lineThickness = CallGraphicController.getGraphicObjectPropertyAsDouble(sourceIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__);
118         lineStyle = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__);
119
120         background = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_BACKGROUND__);
121
122         markForeground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__);
123
124         markBackground = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__);
125
126         markStyle = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__);
127
128         markSize = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__);
129
130         markSizeUnit = CallGraphicController.getGraphicObjectPropertyAsInteger(sourceIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__);
131
132         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_MODE__, lineMode == 1);
133         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_COLOR__, foreground);
134         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_THICKNESS__, lineThickness);
135         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_LINE_STYLE__, lineStyle);
136
137         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_BACKGROUND__, background);
138
139         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_FOREGROUND__, markForeground);
140         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_BACKGROUND__, markBackground);
141         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_STYLE__, markStyle);
142         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE__, markSize);
143         CallGraphicController.setGraphicObjectProperty(destIdentifier, GraphicObjectProperties.__GO_MARK_SIZE_UNIT__, markSizeUnit);
144
145         return 0;
146     }
147 }