Bug 11982 fixed: ticks computation were made when drawing 01/10701/4
Calixte DENIZET [Tue, 5 Mar 2013 16:10:44 +0000 (17:10 +0100)]
Change-Id: I900a8d0acda1a8e0fb842a0b78dcdcf01597690a

scilab/CHANGES_5.4.X
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/AxesDrawer.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/ruler/AxesRulerDrawer.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/ruler/AxesRulerSpriteFactory.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/axes/ruler/RulerDrawerManager.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/label/LabelManager.java
scilab/modules/renderer/tests/nonreg_tests/bug_11982.dia.ref [new file with mode: 0644]
scilab/modules/renderer/tests/nonreg_tests/bug_11982.tst [new file with mode: 0644]

index 50cb513..8f6a3ae 100644 (file)
@@ -379,6 +379,8 @@ Bug fixes
 * Bug #11980 fixed - csim returned an error message in some cases: "Submatrix
                      incorrectly defined".
 
+* Bug #11982 fixed - Ticks computations were made when drawing.
+
 * Bug #11971 fixed - Canceling "Open File" action launched from icon in the
                     toolbar opened SciNotes anyway.
 
index 8d4aebf..f8dbdfe 100644 (file)
@@ -246,7 +246,6 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
         return colorMap;
     }
 
-
     /**
      * Returns the visitor corresponding to the Figure identifier.
      * @param figureId the figure identifier.
@@ -896,6 +895,7 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
 
             if (object instanceof Axes) {
                 Axes axes = (Axes) object;
+
                 if (axes.getXAxisAutoTicks() && X_AXIS_TICKS_PROPERTIES.contains(property)) {
                     return false;
                 }
@@ -907,9 +907,23 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
                 if (axes.getZAxisAutoTicks() && Z_AXIS_TICKS_PROPERTIES.contains(property)) {
                     return false;
                 }
+
+                if (property != GraphicObjectProperties.__GO_CHILDREN__) {
+                    axesDrawer.computeRulers(axes);
+                }
             }
 
             if (object instanceof Figure) {
+                if (property == GraphicObjectProperties.__GO_SIZE__ || property == GraphicObjectProperties.__GO_AXES_SIZE__ || property == GraphicObjectProperties.__GO_CHILDREN__) {
+                    Figure fig = (Figure) object;
+                    for (String gid : fig.getChildren()) {
+                        GraphicObject go = GraphicController.getController().getObjectFromId(gid);
+                        if (go instanceof Axes) {
+                            axesDrawer.computeRulers((Axes) go);
+                        }
+                    }
+                }
+
                 if (SILENT_FIGURE_PROPERTIES.contains(property)) {
                     return false;
                 }
index 7a39aff..82079ee 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2009-2010 - DIGITEO - Pierre Lando
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -26,6 +27,8 @@ import org.scilab.forge.scirenderer.tranformations.Vector4d;
 import org.scilab.modules.graphic_objects.axes.Axes;
 import org.scilab.modules.graphic_objects.axes.Box;
 import org.scilab.modules.graphic_objects.contouredObject.Line;
+import org.scilab.modules.graphic_objects.graphicController.GraphicController;
+import org.scilab.modules.graphic_objects.graphicObject.GraphicObject;
 import org.scilab.modules.graphic_objects.graphicObject.ClippableProperty;
 import org.scilab.modules.graphic_objects.graphicObject.ClippableProperty.ClipStateType;
 import org.scilab.modules.graphic_objects.figure.ColorMap;
@@ -70,16 +73,16 @@ public class AxesDrawer {
     private final LabelManager labelManager;
 
     /** The x-axis label positioner. */
-    private AxisLabelPositioner xAxisLabelPositioner;
+    private final Map<String, AxisLabelPositioner> xAxisLabelPositioner = new HashMap<String, AxisLabelPositioner>();
 
     /** The y-axis label positioner. */
-    private AxisLabelPositioner yAxisLabelPositioner;
+    private final Map<String, AxisLabelPositioner> yAxisLabelPositioner = new HashMap<String, AxisLabelPositioner>();
 
     /** The z-axis label positioner. */
-    private AxisLabelPositioner zAxisLabelPositioner;
+    private final Map<String, AxisLabelPositioner> zAxisLabelPositioner = new HashMap<String, AxisLabelPositioner>();
 
     /** The title positioner. */
-    private TitlePositioner titlePositioner;
+    private final Map<String, TitlePositioner> titlePositioner = new HashMap<String, TitlePositioner>();
 
     /**
      * The current reversed bounds. Used by the functions converting
@@ -115,11 +118,6 @@ public class AxesDrawer {
         this.geometries = new Geometries(visitor.getCanvas());
         this.rulerDrawer = new AxesRulerDrawer(visitor.getCanvas());
 
-        this.xAxisLabelPositioner = new AxisLabelPositioner();
-        this.yAxisLabelPositioner = new YAxisLabelPositioner();
-        this.zAxisLabelPositioner = new AxisLabelPositioner();
-        this.titlePositioner = new TitlePositioner();
-
         reversedBounds = new double[6];
         reversedBoundsIntervals = new double[3];
     }
@@ -138,6 +136,29 @@ public class AxesDrawer {
     }
 
     /**
+     * Compute the graduations on the axes
+     * @param axes the axes
+     */
+    public void computeRulers(Axes axes) {
+        DrawingTools drawingTools = visitor.getDrawingTools();
+        Canvas canvas = visitor.getCanvas();
+        ColorMap colorMap = visitor.getColorMap();
+        try {
+            Integer[] size = visitor.getFigure().getAxesSize();
+            double w = ((double) (int) size[0]) / 2;
+            double h = ((double) (int) size[1]) / 2;
+            Transformation windowTrans = TransformationFactory.getAffineTransformation(new Vector3d(w, h, 1), new Vector3d(w, h, 0));
+            Transformation zoneProjection = computeZoneProjection(axes);
+            Transformation transformation = computeBoxTransformation(axes, canvas, false);
+            Transformation canvasTrans = windowTrans.rightTimes(zoneProjection).rightTimes(transformation);
+
+            rulerDrawer.computeRulers(axes, this, colorMap, drawingTools, transformation, canvasTrans);
+        } catch (DegenerateMatrixException e) {
+
+        }
+    }
+
+    /**
      * Draw the given {@see Axes}.
      * @param axes {@see Axes} to draw.
      * @throws org.scilab.forge.scirenderer.SciRendererException if the draw fail.
@@ -149,16 +170,12 @@ public class AxesDrawer {
         TransformationStack modelViewStack = drawingTools.getTransformationManager().getModelViewStack();
         TransformationStack projectionStack = drawingTools.getTransformationManager().getProjectionStack();
 
-        // Axes are drawn on top of everything.
-        drawingTools.clearDepthBuffer();
-
         // Set axes zone.
         Transformation zoneProjection = computeZoneProjection(axes);
         projectionStack.push(zoneProjection);
 
         // Set box projection.
         Transformation transformation = computeBoxTransformation(axes, canvas, false);
-        Transformation transformation2dView = computeBoxTransformation(axes, canvas, true);
         modelViewStack.pushRightMultiply(transformation);
 
         /* Compute the data scale and translate transformation. */
@@ -171,16 +188,20 @@ public class AxesDrawer {
         currentProjection = currentProjection.rightTimes(dataTransformation);
 
         sceneProjectionMap.put(axes.getIdentifier(), currentProjection);
-        Transformation windowTrans = drawingTools.getTransformationManager().getWindowTransformation().getInverseTransformation();
+
+        Transformation windowTrans = drawingTools.getTransformationManager().getInverseWindowTransformation();
         currentProjection = windowTrans.rightTimes(currentProjection);
 
         /* Update the projection maps with the resulting projections. */
         addProjection(axes.getIdentifier(), currentProjection);
 
         /* 2d view projection, to do: optimize computation */
-        currentProjection = zoneProjection.rightTimes(transformation2dView);
-        currentProjection = currentProjection.rightTimes(dataTransformation);
-        currentProjection = windowTrans.rightTimes(currentProjection);
+        if (axes.getRotationAngles()[0] != 0 || axes.getRotationAngles()[1] != DEFAULT_THETA) {
+            Transformation transformation2dView = computeBoxTransformation(axes, canvas, true);
+            currentProjection = zoneProjection.rightTimes(transformation2dView);
+            currentProjection = currentProjection.rightTimes(dataTransformation);
+            currentProjection = windowTrans.rightTimes(currentProjection);
+        }
 
         addProjection2dView(axes.getIdentifier(), currentProjection);
 
@@ -280,7 +301,6 @@ public class AxesDrawer {
         }
     }
 
-
     /**
      * Compute the mirroring matrix needed to have the [-1; -1; -1] point projected with the maximal Z value.
      * @param transformation the current transformation.
@@ -300,7 +320,6 @@ public class AxesDrawer {
         }
     }
 
-
     /**
      * Compute zone where the axes is draw. In normalised window coordinate.
      * @param axes the given {@see axes}.
@@ -329,7 +348,6 @@ public class AxesDrawer {
         return new Rectangle2D.Double(x, y, w, h);
     }
 
-
     /**
      * Compute the projection for the given axes.
      * @param axes the given axes.
@@ -399,8 +417,6 @@ public class AxesDrawer {
     private Transformation computeBoxTransformation(Axes axes, Canvas canvas, boolean use2dView) throws DegenerateMatrixException {
         Double[] bounds = axes.getDisplayedBounds();
 
-
-        double alpha;
         double theta;
 
         double tmpX;
@@ -416,15 +432,16 @@ public class AxesDrawer {
 
         // Rotate.
         if (use2dView) {
-            alpha = 0.0;
             theta = 2 * DEFAULT_THETA;
         } else {
-            alpha = -axes.getRotationAngles()[0];
+            double alpha = -axes.getRotationAngles()[0];
             theta = DEFAULT_THETA + axes.getRotationAngles()[1];
+            if (alpha != 0) {
+                Transformation alphaRotation = TransformationFactory.getRotationTransformation(alpha, 1.0, 0.0, 0.0);
+                transformation = transformation.rightTimes(alphaRotation);
+            }
         }
 
-        Transformation alphaRotation = TransformationFactory.getRotationTransformation(alpha, 1.0, 0.0, 0.0);
-        transformation = transformation.rightTimes(alphaRotation);
         Transformation thetaRotation = TransformationFactory.getRotationTransformation(theta, 0.0, 0.0, 1.0);
         transformation = transformation.rightTimes(thetaRotation);
 
@@ -438,8 +455,10 @@ public class AxesDrawer {
              * Here, we should divide the values by their maximum.
              * But the next operation will automatically.
              */
-            Transformation cubeScale = TransformationFactory.getScaleTransformation(tmpX, tmpY, tmpZ);
-            transformation = transformation.rightTimes(cubeScale);
+            if (tmpX != 1 || tmpY != 1 || tmpZ != 1) {
+                Transformation cubeScale = TransformationFactory.getScaleTransformation(tmpX, tmpY, tmpZ);
+                transformation = transformation.rightTimes(cubeScale);
+            }
         }
 
         // Compute bounds of projected data.
@@ -1026,32 +1045,56 @@ public class AxesDrawer {
      * Returns the x-axis label positioner.
      * @return the x-axis label positioner.
      */
-    public AxisLabelPositioner getXAxisLabelPositioner() {
-        return this.xAxisLabelPositioner;
+    public AxisLabelPositioner getXAxisLabelPositioner(Axes axes) {
+        AxisLabelPositioner positioner = this.xAxisLabelPositioner.get(axes.getIdentifier());
+        if (positioner == null) {
+            positioner = new AxisLabelPositioner();
+            this.xAxisLabelPositioner.put(axes.getIdentifier(), positioner);
+        }
+
+        return positioner;
     }
 
     /**
      * Returns the y-axis label positioner.
      * @return the y-axis label positioner.
      */
-    public AxisLabelPositioner getYAxisLabelPositioner() {
-        return this.yAxisLabelPositioner;
+    public AxisLabelPositioner getYAxisLabelPositioner(Axes axes) {
+        AxisLabelPositioner positioner = this.yAxisLabelPositioner.get(axes.getIdentifier());
+        if (positioner == null) {
+            positioner = new YAxisLabelPositioner();
+            this.yAxisLabelPositioner.put(axes.getIdentifier(), positioner);
+        }
+
+        return positioner;
     }
 
     /**
      * Returns the z-axis label positioner.
      * @return the z-axis label positioner.
      */
-    public AxisLabelPositioner getZAxisLabelPositioner() {
-        return this.zAxisLabelPositioner;
+    public AxisLabelPositioner getZAxisLabelPositioner(Axes axes) {
+        AxisLabelPositioner positioner = this.zAxisLabelPositioner.get(axes.getIdentifier());
+        if (positioner == null) {
+            positioner = new AxisLabelPositioner();
+            this.zAxisLabelPositioner.put(axes.getIdentifier(), positioner);
+        }
+
+        return positioner;
     }
 
     /**
      * Returns the title positioner.
      * @return the title positioner.
      */
-    public LabelPositioner getTitlePositioner() {
-        return this.titlePositioner;
+    public LabelPositioner getTitlePositioner(Axes axes) {
+        TitlePositioner positioner = this.titlePositioner.get(axes.getIdentifier());
+        if (positioner == null) {
+            positioner = new TitlePositioner();
+            this.titlePositioner.put(axes.getIdentifier(), positioner);
+        }
+
+        return positioner;
     }
 
     public void disposeAll() {
@@ -1059,10 +1102,19 @@ public class AxesDrawer {
         this.projectionMap.clear();
         this.projection2dViewMap.clear();
         this.sceneProjectionMap.clear();
+        this.xAxisLabelPositioner.clear();
+        this.yAxisLabelPositioner.clear();
+        this.zAxisLabelPositioner.clear();
+        this.titlePositioner.clear();
     }
 
     public void update(String id, int property) {
-        this.rulerDrawer.update(id, property);
+        if (this.rulerDrawer.update(id, property)) {
+            GraphicObject object = GraphicController.getController().getObjectFromId(id);
+            if (object instanceof Axes) {
+                computeRulers((Axes) object);
+            }
+        }
     }
 
     public void dispose(String id) {
@@ -1070,5 +1122,9 @@ public class AxesDrawer {
         projectionMap.remove(id);
         projection2dViewMap.remove(id);
         sceneProjectionMap.remove(id);
+        this.xAxisLabelPositioner.remove(id);
+        this.yAxisLabelPositioner.remove(id);
+        this.zAxisLabelPositioner.remove(id);
+        this.titlePositioner.remove(id);
     }
 }
index 6cbfe8b..8c12194 100644 (file)
@@ -2,6 +2,7 @@
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2009-2010 - DIGITEO - Pierre Lando
  * Copyright (C) 2011 - DIGITEO - Manuel Juliachs
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -41,6 +42,7 @@ import java.awt.Color;
 import java.nio.FloatBuffer;
 import java.text.DecimalFormat;
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * @author Pierre Lando
@@ -72,29 +74,41 @@ public class AxesRulerDrawer {
     }
 
     /**
-     * Draw the ruler.
+     * Get default ruler model
+     * @param axes the axes
+     * @param colorMap the colorMap
+     * @return a DefaultRulerModel
+     */
+    private final DefaultRulerModel getDefaultRulerModel(Axes axes, ColorMap colorMap) {
+        DefaultRulerModel rulerModel = new DefaultRulerModel();
+        rulerModel.setTicksLength(TICKS_LENGTH);
+        rulerModel.setSubTicksLength(SUB_TICKS_LENGTH);
+        rulerModel.setLineWidth(axes.getLineThickness());
+        rulerModel.setSpriteDistance(SPRITE_DISTANCE);
+        rulerModel.setColor(ColorFactory.createColor(colorMap, axes.getLineColor()));
+
+        return rulerModel;
+    }
+
+    /**
+     * Compute ticks and subticks on the rulers
      * @param axes the current {@see Axes}
      * @param axesDrawer the drawer used to draw the current {@see Axes}
      * @param colorMap current {@see ColorMap}
      * @param drawingTools the used {@see DrawingTools}
+     * @param transformation the current modelView projection
+     * @param canvasProjection the canvas projection
      * @throws org.scilab.forge.scirenderer.SciRendererException if draw fail.
      */
-    public void drawRuler(Axes axes, AxesDrawer axesDrawer, ColorMap colorMap, DrawingTools drawingTools) throws SciRendererException {
+    public void computeRulers(Axes axes, AxesDrawer axesDrawer, ColorMap colorMap, DrawingTools drawingTools, Transformation transformation, Transformation canvasProjection) {
         Double[] bounds = axes.getDisplayedBounds();
-        double[] matrix = drawingTools.getTransformationManager().getModelViewStack().peek().getMatrix();
+        double[] matrix = transformation.getMatrix();
 
         RulerDrawingResult rulerDrawingResult;
         double[] values;
 
         RulerDrawer[] rulerDrawers = rulerDrawerManager.get(axes);
-        DefaultRulerModel rulerModel = new DefaultRulerModel();
-        rulerModel.setTicksLength(TICKS_LENGTH);
-        rulerModel.setSubTicksLength(SUB_TICKS_LENGTH);
-        rulerModel.setLineWidth(axes.getLineThickness());
-        rulerModel.setSpriteDistance(SPRITE_DISTANCE);
-        rulerModel.setColor(ColorFactory.createColor(colorMap, axes.getLineColor()));
-
-        Transformation canvasProjection = drawingTools.getTransformationManager().getCanvasProjection();
+        DefaultRulerModel rulerModel = getDefaultRulerModel(axes, colorMap);
 
         Vector3d xAxisPosition = computeXAxisPosition(matrix, bounds, axes.getXAxis().getAxisLocation());
         Vector3d yAxisPosition = computeYAxisPosition(matrix, bounds, axes.getYAxis().getAxisLocation());
@@ -116,21 +130,7 @@ public class AxesRulerDrawer {
             yTicksDirection = new Vector3d(0, 0, getNonZeroSignum(yAxisPosition.getZ()));
         }
 
-        int gridPosition;
-        if (axes.getGridPositionAsEnum().equals(Axes.GridPosition.FOREGROUND)) {
-            gridPosition = 1;
-        } else {
-            gridPosition = -1;
-        }
-
         // Draw X ruler
-
-        ElementsBuffer vertexBuffer = drawingTools.getCanvas().getBuffersManager().createElementsBuffer();
-
-        Appearance gridAppearance = new Appearance();
-        gridAppearance.setLinePattern(GRID_LINE_PATTERN);
-        gridAppearance.setLineWidth(axes.getLineThickness().floatValue());
-
         rulerModel.setTicksDirection(xTicksDirection);
         rulerModel.setFirstPoint(xAxisPosition.setX(-1));
         rulerModel.setSecondPoint(xAxisPosition.setX(1));
@@ -148,12 +148,13 @@ public class AxesRulerDrawer {
         }
 
         double distanceRatio;
-        AxisLabelPositioner xAxisLabelPositioner = axesDrawer.getXAxisLabelPositioner();
+        AxisLabelPositioner xAxisLabelPositioner = axesDrawer.getXAxisLabelPositioner(axes);
         xAxisLabelPositioner.setLabelPosition(xAxisPosition);
 
         if (axes.getXAxisVisible()) {
-            rulerDrawingResult = rulerDrawers[0].draw(drawingTools, rulerModel);
+            rulerDrawingResult = rulerDrawers[0].computeRuler(drawingTools, rulerModel, canvasProjection);
             values = rulerDrawingResult.getTicksValues();
+
             if (axes.getXAxisAutoTicks()) {
                 Arrays.sort(values);
                 GraphicController.getController().setProperty(axes.getIdentifier(), GraphicObjectProperties.__GO_X_AXIS_TICKS_LOCATIONS__, toDoubleArray(values));
@@ -161,48 +162,12 @@ public class AxesRulerDrawer {
                 GraphicController.getController().setProperty(axes.getIdentifier(), GraphicObjectProperties.__GO_X_AXIS_SUBTICKS__, rulerDrawingResult.getSubTicksDensity() - 1);
             }
 
-            distanceRatio  = rulerDrawingResult.getMaxDistToTicksDirNorm();
+            distanceRatio = rulerDrawingResult.getMaxDistToTicksDirNorm();
 
             xAxisLabelPositioner.setTicksDirection(xTicksDirection);
             xAxisLabelPositioner.setDistanceRatio(distanceRatio);
             xAxisLabelPositioner.setProjectedTicksDirection(rulerDrawingResult.getNormalizedTicksDirection().setZ(0));
-
-            if (axes.getXAxisGridColor() != -1) {
-                FloatBuffer vertexData;
-                if (axes.getXAxisLogFlag()) {
-                    vertexData = getXGridData(rulerDrawingResult.getSubTicksValues(), rulerModel);
-                } else {
-                    vertexData = getXGridData(values, rulerModel);
-                }
-                vertexBuffer.setData(vertexData, 4);
-
-                Transformation mirror;
-                try {
-                    mirror = TransformationFactory.getScaleTransformation(
-                                 1,
-                                 matrix[6] < 0 ? gridPosition : -gridPosition,
-                                 matrix[10] < 0 ? gridPosition : -gridPosition
-                             );
-                } catch (DegenerateMatrixException ignored) {
-                    // Should never happens as long as gridPosition the value 1 or -1
-                    mirror = TransformationFactory.getIdentity();
-                }
-
-                gridAppearance.setLineColor(ColorFactory.createColor(colorMap, axes.getXAxisGridColor()));
-                drawingTools.getTransformationManager().getModelViewStack().pushRightMultiply(mirror);
-                DefaultGeometry gridGeometry = new DefaultGeometry();
-                gridGeometry.setFillDrawingMode(Geometry.FillDrawingMode.NONE);
-                gridGeometry.setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
-                gridGeometry.setVertices(vertexBuffer);
-                drawingTools.draw(gridGeometry, gridAppearance);
-                drawingTools.getTransformationManager().getModelViewStack().pop();
-            }
-
         } else {
-            /*
-             * x-axis not visible: the projected ticks direction must be computed, as well as
-             * the distance ratio using the default ticks length as numerator.
-             */
             xAxisLabelPositioner.setTicksDirection(xTicksDirection);
             Vector3d projTicksDir = canvasProjection.projectDirection(xTicksDirection);
             xAxisLabelPositioner.setDistanceRatio((double) TICKS_LENGTH / projTicksDir.getNorm());
@@ -210,6 +175,7 @@ public class AxesRulerDrawer {
         }
 
         // Draw Y ruler
+        rulerModel = getDefaultRulerModel(axes, colorMap);
         rulerModel.setTicksDirection(yTicksDirection);
         rulerModel.setFirstPoint(yAxisPosition.setY(-1));
         rulerModel.setSecondPoint(yAxisPosition.setY(1));
@@ -225,11 +191,11 @@ public class AxesRulerDrawer {
             rulerModel.setAutoTicks(true);
         }
 
-        AxisLabelPositioner yAxisLabelPositioner = axesDrawer.getYAxisLabelPositioner();
+        AxisLabelPositioner yAxisLabelPositioner = axesDrawer.getYAxisLabelPositioner(axes);
         yAxisLabelPositioner.setLabelPosition(yAxisPosition);
 
         if (axes.getYAxisVisible()) {
-            rulerDrawingResult = rulerDrawers[1].draw(drawingTools, rulerModel);
+            rulerDrawingResult = rulerDrawers[1].computeRuler(drawingTools, rulerModel, canvasProjection);
             values = rulerDrawingResult.getTicksValues();
             if (axes.getYAxisAutoTicks()) {
                 Arrays.sort(values);
@@ -243,37 +209,6 @@ public class AxesRulerDrawer {
             yAxisLabelPositioner.setTicksDirection(yTicksDirection);
             yAxisLabelPositioner.setDistanceRatio(distanceRatio);
             yAxisLabelPositioner.setProjectedTicksDirection(rulerDrawingResult.getNormalizedTicksDirection().setZ(0));
-
-            if (axes.getYAxisGridColor() != -1) {
-                FloatBuffer vertexData;
-                if (axes.getYAxisLogFlag()) {
-                    vertexData = getYGridData(rulerDrawingResult.getSubTicksValues(), rulerModel);
-                } else {
-                    vertexData = getYGridData(values, rulerModel);
-                }
-                vertexBuffer.setData(vertexData, 4);
-
-                Transformation mirror;
-                try {
-                    mirror = TransformationFactory.getScaleTransformation(
-                                 matrix[2] < 0 ? gridPosition : -gridPosition,
-                                 1,
-                                 matrix[10] < 0 ? gridPosition : -gridPosition
-                             );
-                } catch (DegenerateMatrixException ignored) {
-                    // Should never happens as long as gridPosition the value 1 or -1
-                    mirror = TransformationFactory.getIdentity();
-                }
-
-                gridAppearance.setLineColor(ColorFactory.createColor(colorMap, axes.getYAxisGridColor()));
-                drawingTools.getTransformationManager().getModelViewStack().pushRightMultiply(mirror);
-                DefaultGeometry gridGeometry = new DefaultGeometry();
-                gridGeometry.setFillDrawingMode(Geometry.FillDrawingMode.NONE);
-                gridGeometry.setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
-                gridGeometry.setVertices(vertexBuffer);
-                drawingTools.draw(gridGeometry, gridAppearance);
-                drawingTools.getTransformationManager().getModelViewStack().pop();
-            }
         } else {
             /* y-axis not visible: compute the projected ticks direction and distance ratio (see the x-axis case). */
             yAxisLabelPositioner.setTicksDirection(yTicksDirection);
@@ -298,11 +233,12 @@ public class AxesRulerDrawer {
                 tys = ys;
             }
 
+            rulerModel = getDefaultRulerModel(axes, colorMap);
+
             rulerModel.setFirstPoint(new Vector3d(xs, ys, -1));
             rulerModel.setSecondPoint(new Vector3d(xs, ys, 1));
             rulerModel.setTicksDirection(new Vector3d(txs, tys, 0));
 
-
             setRulerBounds(axes.getZAxis(), rulerModel, bounds[4], bounds[5]);
             rulerModel.setLogarithmic(axes.getZAxis().getLogFlag());
             rulerModel.setMinimalSubTicksDistance(axes.getZAxis().getLogFlag() ? LOG_MINIMAL_SUB_TICKS_DISTANCE : LINEAR_MINIMAL_SUB_TICKS_DISTANCE);
@@ -314,11 +250,11 @@ public class AxesRulerDrawer {
                 rulerModel.setAutoTicks(true);
             }
 
-            AxisLabelPositioner zAxisLabelPositioner = axesDrawer.getZAxisLabelPositioner();
+            AxisLabelPositioner zAxisLabelPositioner = axesDrawer.getZAxisLabelPositioner(axes);
             zAxisLabelPositioner.setLabelPosition(new Vector3d(xs, ys, 0));
 
             if (axes.getZAxisVisible()) {
-                rulerDrawingResult = rulerDrawers[2].draw(drawingTools, rulerModel);
+                rulerDrawingResult = rulerDrawers[2].computeRuler(drawingTools, rulerModel, canvasProjection);
                 values = rulerDrawingResult.getTicksValues();
                 if (axes.getZAxisAutoTicks()) {
                     Arrays.sort(values);
@@ -332,13 +268,131 @@ public class AxesRulerDrawer {
                 zAxisLabelPositioner.setTicksDirection(new Vector3d(txs, tys, 0.0));
                 zAxisLabelPositioner.setDistanceRatio(distanceRatio);
                 zAxisLabelPositioner.setProjectedTicksDirection(rulerDrawingResult.getNormalizedTicksDirection().setZ(0));
+            } else {
+                /* z-axis not visible: compute the projected ticks direction and distance ratio (see the x-axis case). */
+                Vector3d zTicksDirection = new Vector3d(txs, tys, 0);
+
+                zAxisLabelPositioner.setTicksDirection(zTicksDirection);
+                Vector3d projTicksDir = canvasProjection.projectDirection(zTicksDirection);
+                zAxisLabelPositioner.setDistanceRatio((double) TICKS_LENGTH / projTicksDir.getNorm());
+                zAxisLabelPositioner.setProjectedTicksDirection(projTicksDir.getNormalized().setZ(0));
+            }
+        }
+    }
+
+    /**
+     * Draw the ruler.
+     * @param axes the current {@see Axes}
+     * @param axesDrawer the drawer used to draw the current {@see Axes}
+     * @param colorMap current {@see ColorMap}
+     * @param drawingTools the used {@see DrawingTools}
+     * @throws org.scilab.forge.scirenderer.SciRendererException if draw fail.
+     */
+    public void drawRuler(Axes axes, AxesDrawer axesDrawer, ColorMap colorMap, DrawingTools drawingTools) throws SciRendererException {
+        Appearance gridAppearance = new Appearance();
+        gridAppearance.setLinePattern(GRID_LINE_PATTERN);
+        gridAppearance.setLineWidth(axes.getLineThickness().floatValue());
+
+        Double[] bounds = axes.getDisplayedBounds();
+        double[] matrix = drawingTools.getTransformationManager().getModelViewStack().peek().getMatrix();
+
+        RulerDrawer[] rulerDrawers = rulerDrawerManager.get(axes);
+        ElementsBuffer vertexBuffer = drawingTools.getCanvas().getBuffersManager().createElementsBuffer();
+
+        if (rulerDrawers[0].getModel() == null) {
+            computeRulers(axes, axesDrawer, colorMap, drawingTools, drawingTools.getTransformationManager().getModelViewStack().peek(), drawingTools.getTransformationManager().getCanvasProjection());
+        }
+
+        int gridPosition;
+        if (axes.getGridPositionAsEnum().equals(Axes.GridPosition.FOREGROUND)) {
+            gridPosition = 1;
+        } else {
+            gridPosition = -1;
+        }
+
+        // Draw X ruler
+        if (axes.getXAxisVisible()) {
+            rulerDrawers[0].draw(drawingTools);
+
+            if (axes.getXAxisGridColor() != -1) {
+                FloatBuffer vertexData;
+                if (axes.getXAxisLogFlag()) {
+                    vertexData = getXGridData(rulerDrawers[0].getSubTicksValue(), rulerDrawers[0].getModel());
+                } else {
+                    vertexData = getXGridData(rulerDrawers[0].getTicksValue(), rulerDrawers[0].getModel());
+                }
+                vertexBuffer.setData(vertexData, 4);
+
+                Transformation mirror;
+                try {
+                    mirror = TransformationFactory.getScaleTransformation(
+                                 1,
+                                 matrix[6] < 0 ? gridPosition : -gridPosition,
+                                 matrix[10] < 0 ? gridPosition : -gridPosition
+                             );
+                } catch (DegenerateMatrixException ignored) {
+                    // Should never happens as long as gridPosition the value 1 or -1
+                    mirror = TransformationFactory.getIdentity();
+                }
+
+                gridAppearance.setLineColor(ColorFactory.createColor(colorMap, axes.getXAxisGridColor()));
+                drawingTools.getTransformationManager().getModelViewStack().pushRightMultiply(mirror);
+                DefaultGeometry gridGeometry = new DefaultGeometry();
+                gridGeometry.setFillDrawingMode(Geometry.FillDrawingMode.NONE);
+                gridGeometry.setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
+                gridGeometry.setVertices(vertexBuffer);
+                drawingTools.draw(gridGeometry, gridAppearance);
+                drawingTools.getTransformationManager().getModelViewStack().pop();
+            }
+        }
+
+        // Draw Y ruler
+        if (axes.getYAxisVisible()) {
+            rulerDrawers[1].draw(drawingTools);
+
+            if (axes.getYAxisGridColor() != -1) {
+                FloatBuffer vertexData;
+                if (axes.getYAxisLogFlag()) {
+                    vertexData = getYGridData(rulerDrawers[1].getSubTicksValue(), rulerDrawers[1].getModel());
+                } else {
+                    vertexData = getYGridData(rulerDrawers[1].getTicksValue(), rulerDrawers[1].getModel());
+                }
+                vertexBuffer.setData(vertexData, 4);
+
+                Transformation mirror;
+                try {
+                    mirror = TransformationFactory.getScaleTransformation(
+                                 matrix[2] < 0 ? gridPosition : -gridPosition,
+                                 1,
+                                 matrix[10] < 0 ? gridPosition : -gridPosition
+                             );
+                } catch (DegenerateMatrixException ignored) {
+                    // Should never happens as long as gridPosition the value 1 or -1
+                    mirror = TransformationFactory.getIdentity();
+                }
+
+                gridAppearance.setLineColor(ColorFactory.createColor(colorMap, axes.getYAxisGridColor()));
+                drawingTools.getTransformationManager().getModelViewStack().pushRightMultiply(mirror);
+                DefaultGeometry gridGeometry = new DefaultGeometry();
+                gridGeometry.setFillDrawingMode(Geometry.FillDrawingMode.NONE);
+                gridGeometry.setLineDrawingMode(Geometry.LineDrawingMode.SEGMENTS);
+                gridGeometry.setVertices(vertexBuffer);
+                drawingTools.draw(gridGeometry, gridAppearance);
+                drawingTools.getTransformationManager().getModelViewStack().pop();
+            }
+        }
+
+        // Draw Z ruler
+        if (axes.getViewAsEnum() == Camera.ViewType.VIEW_3D && axes.getRotationAngles()[1] != 90.0) {
+            if (axes.getZAxisVisible()) {
+                rulerDrawers[2].draw(drawingTools);
 
                 if (axes.getZAxisGridColor() != -1 || !axes.getZAxisVisible()) {
                     FloatBuffer vertexData;
                     if (axes.getZAxisLogFlag()) {
-                        vertexData = getZGridData(rulerDrawingResult.getSubTicksValues(), rulerModel);
+                        vertexData = getZGridData(rulerDrawers[2].getSubTicksValue(), rulerDrawers[2].getModel());
                     } else {
-                        vertexData = getZGridData(values, rulerModel);
+                        vertexData = getZGridData(rulerDrawers[2].getTicksValue(), rulerDrawers[2].getModel());
                     }
                     vertexBuffer.setData(vertexData, 4);
 
@@ -363,14 +417,6 @@ public class AxesRulerDrawer {
                     drawingTools.draw(gridGeometry, gridAppearance);
                     drawingTools.getTransformationManager().getModelViewStack().pop();
                 }
-            } else {
-                /* z-axis not visible: compute the projected ticks direction and distance ratio (see the x-axis case). */
-                Vector3d zTicksDirection = new Vector3d(txs, tys, 0);
-
-                zAxisLabelPositioner.setTicksDirection(zTicksDirection);
-                Vector3d projTicksDir = canvasProjection.projectDirection(zTicksDirection);
-                zAxisLabelPositioner.setDistanceRatio((double) TICKS_LENGTH / projTicksDir.getNorm());
-                zAxisLabelPositioner.setProjectedTicksDirection(projTicksDir.getNormalized().setZ(0));
             }
         }
 
@@ -491,8 +537,8 @@ public class AxesRulerDrawer {
      * @param rulerModel used rulerModel to compute grid world position.
      * @return X grid data.
      */
-    private FloatBuffer getXGridData(double[] values, RulerModel rulerModel) {
-        FloatBuffer vertexData = FloatBuffer.allocate(values.length * 16);
+    private FloatBuffer getXGridData(List<Double> values, RulerModel rulerModel) {
+        FloatBuffer vertexData = FloatBuffer.allocate(values.size() * 16);
         for (double value : values) {
             float p = (float) rulerModel.getPosition(value).getX();
             vertexData.put(p);
@@ -522,8 +568,8 @@ public class AxesRulerDrawer {
      * @param rulerModel used rulerModel to compute grid world position.
      * @return Y grid data.
      */
-    private FloatBuffer getYGridData(double[] values, RulerModel rulerModel) {
-        FloatBuffer vertexData = FloatBuffer.allocate(values.length * 16);
+    private FloatBuffer getYGridData(List<Double> values, RulerModel rulerModel) {
+        FloatBuffer vertexData = FloatBuffer.allocate(values.size() * 16);
         for (double value : values) {
             float p = (float) rulerModel.getPosition(value).getY();
             vertexData.put(+1);
@@ -553,8 +599,8 @@ public class AxesRulerDrawer {
      * @param rulerModel used rulerModel to compute grid world position.
      * @return Z grid data.
      */
-    private FloatBuffer getZGridData(double[] values, RulerModel rulerModel) {
-        FloatBuffer vertexData = FloatBuffer.allocate(values.length * 16);
+    private FloatBuffer getZGridData(List<Double> values, RulerModel rulerModel) {
+        FloatBuffer vertexData = FloatBuffer.allocate(values.size() * 16);
         int limit = 0;
         for (double value : values) {
             float p = (float) rulerModel.getPosition(value).getZ();
@@ -584,8 +630,8 @@ public class AxesRulerDrawer {
         this.rulerDrawerManager.disposeAll();
     }
 
-    public void update(String id, int property) {
-        this.rulerDrawerManager.update(id, property);
+    public boolean update(String id, int property) {
+        return this.rulerDrawerManager.update(id, property);
     }
 
     public void dispose(String id) {
index ffc2600..7e4bd13 100644 (file)
@@ -92,13 +92,17 @@ class AxesRulerSpriteFactory implements RulerSpriteFactory {
             }
         } else {
             FormattedText formattedText = getTextAtValue(value);
-            FormattedTextSpriteDrawer textObjectSpriteDrawer = new FormattedTextSpriteDrawer(colorMap, formattedText);
-            Texture texture = textureManager.createTexture();
-            texture.setMagnificationFilter(Texture.Filter.LINEAR);
-            texture.setMinifyingFilter(Texture.Filter.LINEAR);
-            texture.setDrawer(textObjectSpriteDrawer);
+            if (formattedText != null && formattedText.getText() != null && !formattedText.getText().isEmpty()) {
+                FormattedTextSpriteDrawer textObjectSpriteDrawer = new FormattedTextSpriteDrawer(colorMap, formattedText);
+                Texture texture = textureManager.createTexture();
+                texture.setMagnificationFilter(Texture.Filter.LINEAR);
+                texture.setMinifyingFilter(Texture.Filter.LINEAR);
+                texture.setDrawer(textObjectSpriteDrawer);
+
+                return texture;
+            }
 
-            return texture;
+            return null;
         }
     }
 
index 8f72656..ddb326d 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2009-2010 - DIGITEO - Pierre Lando
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -34,17 +35,17 @@ class RulerDrawerManager {
      * Set of properties that affect ruler sprites.
      */
     private static final Set<Integer> SPRITE_PROPERTIES = new HashSet<Integer>(Arrays.asList(
-            GraphicObjectProperties.__GO_FONT_SIZE__,
-            GraphicObjectProperties.__GO_FONT_COLOR__,
-            GraphicObjectProperties.__GO_FONT_STYLE__,
-            GraphicObjectProperties.__GO_FONT_FRACTIONAL__,
-            GraphicObjectProperties.__GO_X_AXIS_AUTO_TICKS__,
-            GraphicObjectProperties.__GO_Y_AXIS_AUTO_TICKS__,
-            GraphicObjectProperties.__GO_Z_AXIS_AUTO_TICKS__,
-            GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__,
-            GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__,
-            GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__
-    ));
+                GraphicObjectProperties.__GO_FONT_SIZE__,
+                GraphicObjectProperties.__GO_FONT_COLOR__,
+                GraphicObjectProperties.__GO_FONT_STYLE__,
+                GraphicObjectProperties.__GO_FONT_FRACTIONAL__,
+                GraphicObjectProperties.__GO_X_AXIS_AUTO_TICKS__,
+                GraphicObjectProperties.__GO_Y_AXIS_AUTO_TICKS__,
+                GraphicObjectProperties.__GO_Z_AXIS_AUTO_TICKS__,
+                GraphicObjectProperties.__GO_X_AXIS_LOG_FLAG__,
+                GraphicObjectProperties.__GO_Y_AXIS_LOG_FLAG__,
+                GraphicObjectProperties.__GO_Z_AXIS_LOG_FLAG__
+            ));
 
     /**
      * Map of up to date {@see RulerSpriteManager}
@@ -71,7 +72,7 @@ class RulerDrawerManager {
     public RulerDrawer[] get(Axes axes) {
         RulerDrawer[] rulerSpriteManager = rulerSpriteManagerMap.get(axes.getIdentifier());
         if (rulerSpriteManager == null) {
-            rulerSpriteManager = new RulerDrawer[]{new RulerDrawer(textureManager), new RulerDrawer(textureManager), new RulerDrawer(textureManager)};
+            rulerSpriteManager = new RulerDrawer[] {new RulerDrawer(textureManager), new RulerDrawer(textureManager), new RulerDrawer(textureManager)};
             rulerSpriteManager[0].setSpriteFactory(new AxesRulerSpriteFactory(axes, 0));
             rulerSpriteManager[1].setSpriteFactory(new AxesRulerSpriteFactory(axes, 1));
             rulerSpriteManager[2].setSpriteFactory(new AxesRulerSpriteFactory(axes, 2));
@@ -85,8 +86,9 @@ class RulerDrawerManager {
      * Update the data if needed.
      * @param id the modified object.
      * @param property the changed property.
+     * @return true if it is really updated
      */
-    public void update(String id, int property) {
+    public boolean update(String id, int property) {
 
         /**
          * If update affect {@see Axes} ruler sprites, we clear the corresponding {@see RulerSpriteManager}.
@@ -94,7 +96,27 @@ class RulerDrawerManager {
          */
         if (SPRITE_PROPERTIES.contains(property)) {
             dispose(id);
+            return true;
         }
+
+        if (property == GraphicObjectProperties.__GO_X_AXIS_TICKS_LABELS__) {
+            RulerDrawer[] rulerSpriteManager = rulerSpriteManagerMap.get(id);
+            if (rulerSpriteManager != null) {
+                rulerSpriteManager[0].disposeResources();
+            }
+        } else if (property == GraphicObjectProperties.__GO_Y_AXIS_TICKS_LABELS__) {
+            RulerDrawer[] rulerSpriteManager = rulerSpriteManagerMap.get(id);
+            if (rulerSpriteManager != null) {
+                rulerSpriteManager[1].disposeResources();
+            }
+        } else if (property == GraphicObjectProperties.__GO_Z_AXIS_TICKS_LABELS__) {
+            RulerDrawer[] rulerSpriteManager = rulerSpriteManagerMap.get(id);
+            if (rulerSpriteManager != null) {
+                rulerSpriteManager[2].disposeResources();
+            }
+        }
+
+        return false;
     }
 
     /**
index 1a0ea17..3fbffd5 100644 (file)
@@ -2,6 +2,7 @@
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2009-2010 - DIGITEO - Pierre Lando
  * Copyright (C) 2011-2012 - DIGITEO - Manuel Juliachs
+ * Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -89,14 +90,14 @@ public class LabelManager {
 
         /* Get the positioner associated to the label */
         if (parentAxes.getXAxisLabel().equals(label.getIdentifier())) {
-            labelPositioner = axesDrawer.getXAxisLabelPositioner();
+            labelPositioner = axesDrawer.getXAxisLabelPositioner(parentAxes);
         } else if (parentAxes.getYAxisLabel().equals(label.getIdentifier())) {
-            labelPositioner = axesDrawer.getYAxisLabelPositioner();
+            labelPositioner = axesDrawer.getYAxisLabelPositioner(parentAxes);
         } else if (parentAxes.getZAxisLabel().equals(label.getIdentifier())) {
-            labelPositioner = axesDrawer.getZAxisLabelPositioner();
+            labelPositioner = axesDrawer.getZAxisLabelPositioner(parentAxes);
             drawnFlag = (parentAxes.getViewAsEnum() == Camera.ViewType.VIEW_3D);
         } else if (parentAxes.getTitle().equals(label.getIdentifier())) {
-            labelPositioner = axesDrawer.getTitlePositioner();
+            labelPositioner = axesDrawer.getTitlePositioner(parentAxes);
         } else {
             /* Do not do anything */
             return;
diff --git a/scilab/modules/renderer/tests/nonreg_tests/bug_11982.dia.ref b/scilab/modules/renderer/tests/nonreg_tests/bug_11982.dia.ref
new file mode 100644 (file)
index 0000000..01e38f3
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
+//
+//// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- TEST WITH GRAPHIC -->
+//
+// <-- Non-regression test for bug 11982 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/11982
+//
+// <-- Short Description -->
+// Ticks computations was made asynchronously
+drawlater();
+plot3d();
+a=gca();
+computed=a.x_ticks.locations;
+expected=(-4:1:4)'; 
+assert_checkequal(computed, expected);
diff --git a/scilab/modules/renderer/tests/nonreg_tests/bug_11982.tst b/scilab/modules/renderer/tests/nonreg_tests/bug_11982.tst
new file mode 100644 (file)
index 0000000..15fa773
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Calixte DENIZET
+//
+//// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- TEST WITH GRAPHIC -->
+//
+// <-- Non-regression test for bug 11982 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/11982
+//
+// <-- Short Description -->
+// Ticks computations was made asynchronously
+
+drawlater();
+plot3d();
+a=gca();
+computed=a.x_ticks.locations;
+expected=(-4:1:4)'; 
+assert_checkequal(computed, expected);
\ No newline at end of file