2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2012 - Gustavo Barbosa Libotte
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
13 package org.scilab.modules.gui.datatip;
15 import static org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties.__GO_VIEW__;
17 import org.scilab.modules.graphic_objects.PolylineData;
18 import org.scilab.modules.graphic_objects.graphicController.GraphicController;
19 import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
20 import org.scilab.modules.graphic_objects.graphicObject.GraphicObjectProperties;
21 import org.scilab.modules.gui.editor.CommonHandler;
22 import org.scilab.modules.gui.editor.EntityPicker;
23 import org.scilab.modules.renderer.CallRenderer;
26 * Create a datatip and set its properties
27 * @author Gustavo Barbosa Libotte
29 public class DatatipCreate {
31 static EntityPicker ep = new EntityPicker();
34 * Given a mouse coordinate point x, y in pixels
37 * @param figureUid Figure unique identifier.
38 * @param coordIntX Integer with pixel mouse position x.
39 * @param coordIntY Integer with pixel mouse position y.
40 * @return Datatip handler string.
42 public static Integer createDatatip(int figureUid, Integer coordIntX, Integer coordIntY) {
44 Integer polylineUid = ep.pick(figureUid, coordIntX, coordIntY);
45 double[] graphicCoord = DatatipCommon.getTransformedPosition(figureUid, new Integer[] {coordIntX, coordIntY});
46 EntityPicker.PickedPoint picked = ep.pickPoint(polylineUid, coordIntX, coordIntY);
47 double[] point = CommonHandler.computeIntersection(polylineUid, picked.point, graphicCoord);
48 Integer newDatatip = datatipProperties(point, polylineUid);
53 * Given a double graphic coordinate point x, y
56 * @param polylineUid Polyline unique identifier.
57 * @param coordDoubleXY double array with graphic position x and y.
58 * @return Datatip handler string.
60 public static int createDatatipProgramCoord(int polylineUid, double[] coordDoubleXY) {
62 if (polylineUid != 0) {
64 if (PolylineData.isZCoordSet(polylineUid) == 0) {
66 DatatipCommon.Segment seg = DatatipCommon.getSegment(coordDoubleXY[0], polylineUid);
69 Double[] pos = DatatipCommon.Interpolate(coordDoubleXY[0], seg);
70 double[] position = new double[] {pos[0], pos[1], 0.0};
72 Integer newDatatip = datatipProperties(position, polylineUid);
77 DatatipCommon.Segment seg3d = DatatipCommon.getSegment3dView(coordDoubleXY[0], coordDoubleXY[1], polylineUid);
79 Double[] pos = DatatipCommon.Interpolate3dViewProgCoord(coordDoubleXY[0], coordDoubleXY[1], seg3d, polylineUid);
80 double[] position = new double[] {pos[0], pos[1], pos[2]};
82 Integer newDatatip = datatipProperties(position, polylineUid);
94 * Given an integer index that belongs to the polyline create a datatip.
96 * @param polylineUid Polyline unique identifier.
97 * @param indexPoint integer related to one of the indexed points of the polyline
98 * @return Datatip handler string.
100 public static int createDatatipProgramIndex(int polylineUid, int indexPoint) {
102 double[] DataX = (double[]) PolylineData.getDataX(polylineUid);
103 double[] DataY = (double[]) PolylineData.getDataY(polylineUid);
105 if (indexPoint > DataX.length) {
106 indexPoint = DataX.length;
107 } else if (indexPoint <= 0) {
111 double[] coordDoubleXY = new double[3];
112 if (PolylineData.isZCoordSet(polylineUid) == 1) {
113 double[] DataZ = (double[]) PolylineData.getDataZ(polylineUid);
114 coordDoubleXY[0] = DataX[indexPoint - 1];
115 coordDoubleXY[1] = DataY[indexPoint - 1];
116 coordDoubleXY[2] = DataZ[indexPoint - 1];
118 coordDoubleXY[0] = DataX[indexPoint - 1];
119 coordDoubleXY[1] = DataY[indexPoint - 1];
122 Integer newDatatip = datatipProperties(coordDoubleXY, polylineUid);
127 * Get the datatip position in pixels on a specific axes
129 * @param coordinates Datatip coordinates x, y in double precision
130 * @param axesUid Axes unique identifier
131 * @return datatip position in pixels
133 public static int[] getDatatipPositionInteger(double[] coordinates, int axesUid) {
135 double[] graphCoordDouble = new double[] {0.0, 0.0, 0.0};
136 graphCoordDouble[0] = coordinates[0];
137 graphCoordDouble[1] = coordinates[1];
138 graphCoordDouble[2] = 0.0;
140 double[] pixelCoordinates = new double[] {0.0, 0.0};
141 pixelCoordinates = CallRenderer.getPixelFrom2dViewCoordinates(axesUid, graphCoordDouble);
143 int xInt = (int) pixelCoordinates[0];
144 int yInt = (int) pixelCoordinates[1];
146 int[] coordInteger = new int[2];
147 coordInteger[0] = xInt;
148 coordInteger[1] = yInt;
155 * Creates and setup the datatip.
157 * @param coord double array with graphic position x and y.
158 * @param polyline the polyline uid string.
159 * @return Datatip uid string.
161 private static int datatipProperties(double[] coord, Integer polyline) {
163 Integer newDatatip = GraphicController.getController().askObject(GraphicObject.getTypeFromName(GraphicObjectProperties.__GO_DATATIP__));
164 Double[] datatipPosition = new Double[] {coord[0], coord[1], coord[2]};
166 GraphicController.getController().setProperty(newDatatip, GraphicObjectProperties.__GO_DATATIP_DATA__, datatipPosition);
168 Integer axesUid = (Integer)GraphicController.getController().getProperty(polyline, GraphicObjectProperties.__GO_PARENT_AXES__);
169 Integer viewInfo = (Integer) GraphicController.getController().getProperty(axesUid, __GO_VIEW__);
170 if (viewInfo == 1 && PolylineData.isZCoordSet(polyline) == 1) {
171 GraphicController.getController().setProperty(newDatatip, GraphicObjectProperties.__GO_DATATIP_3COMPONENT__, true);
172 GraphicController.getController().setProperty(newDatatip, GraphicObjectProperties.__GO_CLIP_STATE__, 0);
175 GraphicController.getController().setGraphicObjectRelationship(polyline, newDatatip);
180 * Set the datatip interpolation mode.
182 * @param datatipUid datatip unique identifier.
183 * @param interpMode boolean for the interpolation mode.
185 private static void datatipSetInterp(int datatipUid, boolean interpMode) {
186 GraphicController.getController().setProperty(datatipUid, GraphicObjectProperties.__GO_DATATIP_INTERP_MODE__, interpMode);