* Bug #12017 - figure.pixel_drawing_mode is ignored 07/18707/1
Caio SOUZA [Sun, 24 Jul 2016 17:35:24 +0000 (14:35 -0300)]
Change-Id: I3f26d159d781ac7eb09ecfdeec2af06870535b99

scilab/CHANGES.md
scilab/modules/graphic_objects/src/java/org/scilab/modules/graphic_objects/figure/Figure.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/util/PixelDrawingModeUtils.java [new file with mode: 0644]
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLDrawingTools.java
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLPixelDrawingMode.java [new file with mode: 0644]
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/drawer/JoGLShapeDrawer.java

index e95c10e..008691b 100644 (file)
@@ -336,6 +336,7 @@ Bug Fixes
 * [#11375](http://bugzilla.scilab.org/show_bug.cgi?id=11375): When a localized help subdirectory has only a CHAPTER file specifying the section title, it was ignored.
 * [#11692](http://bugzilla.scilab.org/show_bug.cgi?id=11692): The summary of a help section built from both default en_US and localized files was never sorted overall.
 * [#11959](http://bugzilla.scilab.org/show_bug.cgi?id=11959): Allow "Zoom Area" to be clicked out of axes
+* [#12017](http://bugzilla.scilab.org/show_bug.cgi?id=12017): `figure.pixel_drawing_mode` is ignored for filled regular polygons and other shapes, still does not work for vectorial export (eps, pdf, etc).
 * [#12110](http://bugzilla.scilab.org/show_bug.cgi?id=12110): Unable to zoom multiple axes at once
 * [#12431](http://bugzilla.scilab.org/show_bug.cgi?id=12431): The page describing the `%helps` variable needed clarification.
 * [#13166](http://bugzilla.scilab.org/show_bug.cgi?id=13166): `l` and `b` endian flags used with `mget` and `mgeti` were sticky
index 7cdb36b..a337f37 100644 (file)
@@ -142,7 +142,7 @@ public class Figure extends GraphicObject implements AxesContainer {
     }
 
     /** Pixel drawing logical operations */
-    private enum PixelDrawingMode {
+    public enum PixelDrawingMode {
         CLEAR, AND, ANDREVERSE, COPY, ANDINVERTED, NOOP, XOR, OR, NOR, EQUIV, INVERT, ORREVERSE, COPYINVERTED, ORINVERTED, NAND, SET;
 
         /**
index dfc321b..8380721 100755 (executable)
@@ -32,6 +32,7 @@ import javax.swing.SwingUtilities;
 import org.scilab.forge.scirenderer.Canvas;
 import org.scilab.forge.scirenderer.Drawer;
 import org.scilab.forge.scirenderer.DrawingTools;
+import org.scilab.forge.scirenderer.implementation.jogl.JoGLDrawingTools;
 import org.scilab.forge.scirenderer.SciRendererException;
 import org.scilab.forge.scirenderer.buffers.ElementsBuffer;
 import org.scilab.forge.scirenderer.buffers.BuffersManager;
@@ -89,6 +90,7 @@ import org.scilab.modules.renderer.JoGLView.text.TextManager;
 import org.scilab.modules.renderer.JoGLView.util.ColorFactory;
 import org.scilab.modules.renderer.JoGLView.util.LightingUtils;
 import org.scilab.modules.renderer.JoGLView.util.OutOfMemoryException;
+import org.scilab.modules.renderer.JoGLView.util.PixelDrawingModeUtils;
 
 /**
  * @author Pierre Lando
@@ -405,6 +407,9 @@ public class DrawerVisitor implements Visitor, Drawer, GraphicView {
                 colorMap = figure.getColorMap();
                 drawingTools.clear(ColorFactory.createColor(colorMap, figure.getBackground()));
                 drawingTools.clearDepthBuffer();
+                if (drawingTools instanceof JoGLDrawingTools) {
+                    ((JoGLDrawingTools)drawingTools).setPixelDrawingMode(PixelDrawingModeUtils.figureToJoGLmode(figure.getPixelDrawingModeAsEnum()));
+                }
                 if (figure.isValid() && figure.getVisible() && figure.getImmediateDrawing() && dims.width > 1 && dims.height > 1) {
                     askAcceptVisitor(figure.getChildren());
                 }
diff --git a/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/util/PixelDrawingModeUtils.java b/scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/util/PixelDrawingModeUtils.java
new file mode 100644 (file)
index 0000000..02f9cd7
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Caio SOUZA
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ */
+package org.scilab.modules.renderer.JoGLView.util;
+
+import static org.scilab.modules.graphic_objects.figure.Figure.PixelDrawingMode;
+import org.scilab.forge.scirenderer.implementantion.jogl.JoGLPixelDrawingMode;
+
+public class PixelDrawingModeUtils {
+
+    public static JoGLPixelDrawingMode figureToJoGLmode(PixelDrawingMode mode) {
+        switch (mode) {
+            case CLEAR:
+                return JoGLPixelDrawingMode.CLEAR;
+            case AND:
+                return JoGLPixelDrawingMode.AND;
+            case ANDREVERSE:
+                return JoGLPixelDrawingMode.AND_REVERSE;
+            case COPY:
+                return JoGLPixelDrawingMode.COPY;
+            case ANDINVERTED:
+                return JoGLPixelDrawingMode.AND_INVERTED;
+            case NOOP:
+                return JoGLPixelDrawingMode.NOOP;
+            case XOR:
+                return JoGLPixelDrawingMode.XOR;
+            case OR:
+                return JoGLPixelDrawingMode.OR;
+            case NOR:
+                return JoGLPixelDrawingMode.NOR;
+            case EQUIV:
+                return JoGLPixelDrawingMode.EQUIV;
+            case INVERT:
+                return JoGLPixelDrawingMode.INVERT;
+            case ORREVERSE:
+                return JoGLPixelDrawingMode.OR_REVERSE;
+            case COPYINVERTED:
+                return JoGLPixelDrawingMode.COPY_INVERTED;
+            case ORINVERTED:
+                return JoGLPixelDrawingMode.OR_INVERTED;
+            case NAND:
+                return JoGLPixelDrawingMode.NAND;
+            case SET:
+                return JoGLPixelDrawingMode.SET;
+            default:
+                return  null;
+
+        }
+    }
+}
index 6a78491..86cc779 100644 (file)
@@ -21,6 +21,7 @@ import org.scilab.forge.scirenderer.clipping.ClippingManager;
 import org.scilab.forge.scirenderer.implementation.jogl.clipping.JoGLClippingManager;
 import org.scilab.forge.scirenderer.implementation.jogl.drawer.JoGLShapeDrawer;
 import org.scilab.forge.scirenderer.implementation.jogl.lightning.JoGLLightManager;
+import org.scilab.forge.scirenderer.implementantion.jogl.JoGLPixelDrawingMode;
 import org.scilab.forge.scirenderer.lightning.LightManager;
 import org.scilab.forge.scirenderer.renderer.Renderer;
 import org.scilab.forge.scirenderer.shapes.appearance.Appearance;
@@ -49,6 +50,7 @@ public class JoGLDrawingTools implements DrawingTools {
     private final JoGLClippingManager clippingManager;
     private final JoGLCanvas canvas;
     private GL2 gl;
+    private int PixelDrawingMode;
 
     /**
      * Default constructor.
@@ -61,6 +63,8 @@ public class JoGLDrawingTools implements DrawingTools {
 
         this.canvas = canvas;
 
+        this.PixelDrawingMode = GL2.GL_COPY;
+
         transformationManager.addListener(new TransformationManagerListener() {
             @Override
             public void transformationChanged(TransformationManager transformationManager) {
@@ -122,6 +126,66 @@ public class JoGLDrawingTools implements DrawingTools {
         return clippingManager;
     }
 
+    public void setPixelDrawingMode(JoGLPixelDrawingMode mode) {
+        switch (mode) {
+            case CLEAR:
+                PixelDrawingMode = GL2.GL_CLEAR;
+                break;
+            case AND:
+                PixelDrawingMode = GL2.GL_AND;
+                break;
+            case AND_REVERSE:
+                PixelDrawingMode = GL2.GL_AND_REVERSE;
+                break;
+            case COPY:
+                PixelDrawingMode = GL2.GL_COPY;
+                break;
+            case AND_INVERTED:
+                PixelDrawingMode = GL2.GL_AND_INVERTED;
+                break;
+            case NOOP:
+                PixelDrawingMode = GL2.GL_NOOP;
+                break;
+            case XOR:
+                PixelDrawingMode = GL2.GL_XOR;
+                break;
+            case OR:
+                PixelDrawingMode = GL2.GL_OR;
+                break;
+            case NOR:
+                PixelDrawingMode = GL2.GL_NOR;
+                break;
+            case EQUIV:
+                PixelDrawingMode = GL2.GL_EQUIV;
+                break;
+            case INVERT:
+                PixelDrawingMode = GL2.GL_INVERT;
+                break;
+            case OR_REVERSE:
+                PixelDrawingMode = GL2.GL_OR_REVERSE;
+                break;
+            case COPY_INVERTED:
+                PixelDrawingMode = GL2.GL_COPY_INVERTED;
+                break;
+            case OR_INVERTED:
+                PixelDrawingMode = GL2.GL_OR_INVERTED;
+                break;
+            case NAND:
+                PixelDrawingMode = GL2.GL_NAND;
+                break;
+            case SET:
+                PixelDrawingMode = GL2.GL_SET;
+                break;
+            default:
+                PixelDrawingMode = GL2.GL_COPY;
+                break;
+        }
+    }
+
+    public int getGLPixelDrawingMode() {
+        return PixelDrawingMode;
+    }
+
     @Override
     public void clear(Color color) {
         gl.glClearColor(color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat(), 1.f);
diff --git a/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLPixelDrawingMode.java b/scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLPixelDrawingMode.java
new file mode 100644 (file)
index 0000000..0365823
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Caio SOUZA
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ */
+package org.scilab.forge.scirenderer.implementantion.jogl;
+
+public enum JoGLPixelDrawingMode {
+    CLEAR, AND, AND_REVERSE, COPY, AND_INVERTED, NOOP, XOR, OR, NOR, EQUIV, INVERT, OR_REVERSE, COPY_INVERTED, OR_INVERTED, NAND, SET;
+
+    /**
+     * Converts an integer to the corresponding enum
+     * @param intValue the integer value
+     * @return  the pixel drawing mode enum
+     */
+    public static JoGLPixelDrawingMode intToEnum(Integer intValue) {
+        switch (intValue) {
+            case 0:
+                return JoGLPixelDrawingMode.CLEAR;
+            case 1:
+                return JoGLPixelDrawingMode.AND;
+            case 2:
+                return JoGLPixelDrawingMode.AND_REVERSE;
+            case 3:
+                return JoGLPixelDrawingMode.COPY;
+            case 4:
+                return JoGLPixelDrawingMode.AND_INVERTED;
+            case 5:
+                return JoGLPixelDrawingMode.NOOP;
+            case 6:
+                return JoGLPixelDrawingMode.XOR;
+            case 7:
+                return JoGLPixelDrawingMode.OR;
+            case 8:
+                return JoGLPixelDrawingMode.NOR;
+            case 9:
+                return JoGLPixelDrawingMode.EQUIV;
+            case 10:
+                return JoGLPixelDrawingMode.INVERT;
+            case 11:
+                return JoGLPixelDrawingMode.OR_REVERSE;
+            case 12:
+                return JoGLPixelDrawingMode.COPY_INVERTED;
+            case 13:
+                return JoGLPixelDrawingMode.OR_INVERTED;
+            case 14:
+                return JoGLPixelDrawingMode.NAND;
+            case 15:
+                return JoGLPixelDrawingMode.SET;
+            default:
+                return  null;
+        }
+    }
+};
index 5008513..2b1066c 100644 (file)
@@ -81,13 +81,14 @@ public final class JoGLShapeDrawer {
                 gl.glDisable(GL2.GL_CULL_FACE);
                 break;
         }
-
+        gl.glEnable(GL2.GL_COLOR_LOGIC_OP);
+        gl.glLogicOp(drawingTools.getGLPixelDrawingMode());
         if (drawingTools.getCanvas().getJoGLParameters().useVBO()) {
             vboDrawing(drawingTools, geometry, appearance);
         } else {
             directDrawing(drawingTools, geometry, appearance);
         }
-
+        gl.glDisable(GL2.GL_COLOR_LOGIC_OP);
         GLShortCuts.useLineAppearance(gl, null);
         gl.glDisable(GL2.GL_CULL_FACE);
     }