Merge remote-tracking branch 'origin/5.5' 71/16771/1
Vincent COUVERT [Fri, 3 Jul 2015 08:31:39 +0000 (10:31 +0200)]
Change-Id: I2b0118b704748131e154ceb15e37145f585e04bc

1  2 
scilab/modules/renderer/src/java/org/scilab/modules/renderer/JoGLView/DrawerVisitor.java

@@@ -14,7 -14,6 +14,7 @@@ package org.scilab.modules.renderer.JoG
  import java.awt.Component;
  import java.awt.Dimension;
  import java.nio.ByteBuffer;
 +import java.nio.FloatBuffer;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.HashMap;
@@@ -31,9 -30,7 +31,9 @@@ import org.scilab.forge.scirenderer.Dra
  import org.scilab.forge.scirenderer.DrawingTools;
  import org.scilab.forge.scirenderer.SciRendererException;
  import org.scilab.forge.scirenderer.buffers.ElementsBuffer;
 +import org.scilab.forge.scirenderer.buffers.BuffersManager;
  import org.scilab.forge.scirenderer.shapes.appearance.Appearance;
 +import org.scilab.forge.scirenderer.shapes.appearance.Color;
  import org.scilab.forge.scirenderer.shapes.geometry.DefaultGeometry;
  import org.scilab.forge.scirenderer.shapes.geometry.Geometry;
  import org.scilab.forge.scirenderer.texture.AbstractTextureDataProvider;
@@@ -162,7 -159,7 +162,7 @@@ public class DrawerVisitor implements V
      public static int[] getSize() {
          return new int[] {visitorMap.size(), openGLChildren.size()};
      }
 -    
 +
      public DrawerVisitor(Component component, Canvas canvas, AxesContainer figure) {
          GraphicController.getController().register(this);
  
                          geometry.setTextureCoordinates(dataManager.getTextureCoordinatesBuffer(polyline.getIdentifier()));
                          appearance.setTexture(getColorMapTexture());
                      } else {
 -                        geometry.setColors(null);
 +                        if (polyline.getColorSet()) {
 +                            ElementsBuffer colors = dataManager.getColorBuffer(polyline.getIdentifier());
 +                            geometry.setColors(colors);
 +                            appearance.setLineColor(null);
 +                        } else {
 +                            geometry.setColors(null);
 +                            appearance.setLineColor(ColorFactory.createColor(colorMap, polyline.getLineColor()));
 +                        }
                      }
  
                      Integer lineColor = polyline.getSelected() ? polyline.getSelectedColor() : polyline.getLineColor();
                      }
  
                      if (polyline.getMarkMode()) {
                          ElementsBuffer positions = dataManager.getVertexBuffer(polyline.getIdentifier());
                          int offset = polyline.getMarkOffset();
                          int stride = polyline.getMarkStride();
 -                        drawingTools.draw(sprite, AnchorPosition.CENTER, positions, offset, stride, 0);
 +                        if (polyline.getColorSet() && (polyline.getNumMarkForegrounds() > 0) || (polyline.getNumMarkBackgrounds() > 0)) {
 +                            ElementsBuffer colors = dataManager.getColorBuffer(polyline.getIdentifier());
 +                            Color auxColor;
 +                            if (polyline.getNumMarkBackgrounds() > 0) {
 +                                auxColor = ColorFactory.createColor(colorMap, polyline.getMark().getForeground());
 +                            } else {
 +                                auxColor = ColorFactory.createColor(colorMap, polyline.getMark().getBackground());
 +                            }
 +                                      FloatBuffer data = positions.getData();
 +                                      FloatBuffer colorData = colors.getData();
 +                              Integer[] sizes = polyline.getMarkSizes();
 +                              if ( (sizes.length > 0) && (data != null) && (colorData != null) && (positions.getSize() == sizes.length) && (colors.getSize() == sizes.length) ) {
 +                                      
 +                                              Integer markSizeTmp = polyline.getMarkSize();
 +                                              
 +                                              // markers with different sizes
 +                                                      data.rewind();
 +                                                      colorData.rewind();
 +                                                      
 +                                    stride = stride < 1 ? 1 : stride;
 +                                    offset = offset < 0 ? 0 : offset;
 +
 +                                    int elementSize = positions.getElementsSize();
 +                                                      int mark = offset * elementSize;
 +                                                      int k = 0;
 +                                                      
 +                                    while (data.remaining() >= stride * elementSize) {
 +                                                      
 +                                      // Be careful, do not use polyline.setMarkSize since this will destroy the sizes
 +                                                              polyline.getMark().setSize(sizes[k++]);
 +
 +                                                              BuffersManager bufferManager = drawingTools.getCanvas().getBuffersManager();
 +                                                      ElementsBuffer singlePosition = bufferManager.createElementsBuffer();
 +                                                      ElementsBuffer singleColor = bufferManager.createElementsBuffer();
 +
 +                                                      float[] position = {0, 0, 0, 1};
 +                                        data.position(mark);
 +                                                      data.get(position);
 +                                                      
 +                                        float[] color = {0, 0, 0, 0};
 +                                        colorData.position(mark);
 +                                        colorData.get(color);
 +
 +                                                      mark += stride * elementSize;
 +                                                      
 +                                                      singlePosition.setData(position, elementSize);
 +                                                      singleColor.setData(color, elementSize);
 +
 +                                                      Texture sprite = markManager.getMarkSprite(polyline, null, appearance);
 +                                                      drawingTools.draw(sprite, AnchorPosition.CENTER, singlePosition, 0, 0, 0, auxColor, singleColor);
 +                                              
 +                                                      bufferManager.dispose(singleColor);
 +                                                      bufferManager.dispose(singlePosition);
 +                                              }
 +                                              // restore the size of the mark
 +                                      // Be careful, do not use polyline.setMarkSize since this will destroy the sizes
 +                                                      polyline.getMark().setSize(markSizeTmp);
 +                              } else {
 +                                Texture sprite = markManager.getMarkSprite(polyline, null, appearance);
 +                                      drawingTools.draw(sprite, AnchorPosition.CENTER, positions, offset, stride, 0, auxColor, colors);
 +                              }
 +                        } else {
 +                              FloatBuffer data = positions.getData();
 +                              Integer[] sizes = polyline.getMarkSizes();
 +                              if ( (sizes.length > 0) && (data != null) && (positions.getSize() == sizes.length) ) {
 +                                      
 +                                      Integer markSizeTmp = polyline.getMarkSize();
 +                                      
 +                                      // markers with different sizes
 +                                              data.rewind();
 +                                              
 +                                stride = stride < 1 ? 1 : stride;
 +                                offset = offset < 0 ? 0 : offset;
 +
 +                                int elementSize = positions.getElementsSize();
 +                                              int mark = offset * elementSize;
 +                                              int k = 0;
 +                                              
 +                                while (data.remaining() >= stride * elementSize) {
 +                                                      
 +                                      // setting the size of the mark temporary 
 +                                                      polyline.getMark().setSize(sizes[k++]);
 +
 +                                                      BuffersManager bufferManager = drawingTools.getCanvas().getBuffersManager();
 +                                              ElementsBuffer singlePosition = bufferManager.createElementsBuffer();
 +
 +                                              float[] position = {0, 0, 0, 1};
 +                                    data.position(mark);
 +                                              data.get(position);
 +                                              mark += stride * elementSize;
 +                                              singlePosition.setData(position, elementSize);
 +
 +                                              Texture sprite = markManager.getMarkSprite(polyline, colorMap, appearance);
 +                                              drawingTools.draw(sprite, AnchorPosition.CENTER, singlePosition, 0, 0, 0, null, null);
 +                                              
 +                                              bufferManager.dispose(singlePosition);
 +                                      }
 +                                      // restore the size of the mark
 +                                      polyline.getMark().setSize(markSizeTmp);
 +                              }
 +                              else {
 +                                      Texture sprite = markManager.getMarkSprite(polyline, colorMap, appearance);
 +                                      drawingTools.draw(sprite, AnchorPosition.CENTER, positions, offset, stride, 0, null, null);
 +                              }
 +                        }
                      }
                  } catch (ObjectRemovedException e) {
                      invalidate(polyline, e);
                          appearance.setLineWidth(plot3d.getLineThickness().floatValue());
                      }
  
 -                    Texture texture = markManager.getMarkSprite(plot3d, colorMap, appearance);
                      ElementsBuffer positions = dataManager.getVertexBuffer(plot3d.getIdentifier());
 -                    drawingTools.draw(texture, AnchorPosition.CENTER, positions);
 +                    if ((plot3d.getMark().getBackground() == -3 || plot3d.getMark().getForeground() == -3) && plot3d.getColorFlag() == 1) {
 +                        Texture sprite = markManager.getMarkSprite(plot3d, null, appearance);
 +                        ElementsBuffer colors = dataManager.getColorBuffer(plot3d.getIdentifier());
 +                        Color auxColor;
 +                        if (plot3d.getMark().getBackground() == -3) {
 +                            auxColor = ColorFactory.createColor(colorMap, plot3d.getMark().getForeground());
 +                        } else {
 +                            auxColor = ColorFactory.createColor(colorMap, plot3d.getMark().getBackground());
 +                        }
 +                        drawingTools.draw(sprite, AnchorPosition.CENTER, positions, auxColor, colors);
 +                    } else {
 +                        Texture sprite = markManager.getMarkSprite(plot3d, colorMap, appearance);
 +                        drawingTools.draw(sprite, AnchorPosition.CENTER, positions, null, null);
 +                    }
                  }
              } catch (ObjectRemovedException e) {
                  invalidate(plot3d, e);
              }
              axesDrawer.disableClipping(plot3d.getClipProperty());
          }
 -
      }
  
      @Override
                   * in order to obtain the latter's Mark (all arrows are supposed to have the same contour properties for now).
                   */
                  if (segs.getMarkMode()) {
                      ElementsBuffer positions = dataManager.getVertexBuffer(segs.getIdentifier());
                      // Take only into account start-end of segs and not the arrow head.
                      positions.getData().limit(segs.getNumberArrows() * 2 * 4);
 -                    drawingTools.draw(texture, AnchorPosition.CENTER, positions);
 +
 +                    if (segs.getArrows().get(0).getMark().getBackground() == -3 || segs.getArrows().get(0).getMark().getForeground() == -3) {
 +                        Texture sprite = markManager.getMarkSprite(segs.getIdentifier(), segs.getArrows().get(0).getMark(), null, null);
 +                        ElementsBuffer colors = dataManager.getColorBuffer(segs.getIdentifier());
 +                        Color auxColor;
 +                        if (segs.getArrows().get(0).getMark().getBackground() == -3) {
 +                            auxColor = ColorFactory.createColor(colorMap, segs.getArrows().get(0).getMark().getForeground());
 +                        } else {
 +                            auxColor = ColorFactory.createColor(colorMap, segs.getArrows().get(0).getMark().getBackground());
 +                        }
 +                        drawingTools.draw(sprite, AnchorPosition.CENTER, positions, auxColor, colors);
 +                    } else {
 +                        Texture sprite = markManager.getMarkSprite(segs.getIdentifier(), segs.getArrows().get(0).getMark(), colorMap, null);
 +                        drawingTools.draw(sprite, AnchorPosition.CENTER, positions, null, null);
 +                    }
 +
                      positions.getData().limit(positions.getData().capacity());
                  }
  
          GraphicObject object = GraphicController.getController().getObjectFromId(id);
          int objectType = (Integer) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_TYPE__);
          int objectStyle = (objectType == GraphicObjectProperties.__GO_UICONTROL__ ? (Integer) GraphicController.getController().getProperty(id, GraphicObjectProperties.__GO_STYLE__) : -1);
-         if ((object != null) && isFigureChild(id) || (objectType == GraphicObjectProperties.__GO_UICONTROL__ && objectStyle == GraphicObjectProperties.__GO_UI_FRAME__)
+         if ((object != null) && (isFigureChild(id) || isFigureParent(id)) || (objectType == GraphicObjectProperties.__GO_UICONTROL__ && objectStyle == GraphicObjectProperties.__GO_UI_FRAME__)
                  && objectType != GraphicObjectProperties.__GO_UIMENU__ && objectType != GraphicObjectProperties.__GO_UI_FRAME_BORDER__) {
  
              if (GraphicObjectProperties.__GO_VALID__ == property) {
                  if (property == GraphicObjectProperties.__GO_SIZE__
                          || property == GraphicObjectProperties.__GO_AXES_SIZE__
                          || property == GraphicObjectProperties.__GO_CHILDREN__
-                         || property == GraphicObjectProperties.__GO_POSITION__) {
-                     Figure fig = (Figure) object;
-                     for (Integer gid : fig.getChildren()) {
+                         || property == GraphicObjectProperties.__GO_POSITION__
+                         || property == GraphicObjectProperties.__GO_VISIBLE__) {
+                     for (Integer gid : figure.getChildren()) {
                          GraphicObject go = GraphicController.getController().getObjectFromId(gid);
                          if (go instanceof Axes) {
+                             axesDrawer.computeMargins((Axes) go);
                              axesDrawer.computeRulers((Axes) go);
                          }
                      }
      }
  
      /**
+      * Check if the given id correspond to a parent of the current {@see Figure}.
+      * @param id the given id.
+      * @return true if the given id correspond to a parent of the current {@see Figure}.
+      */
+     private boolean isFigureParent(Integer id) {
+         GraphicObject object = GraphicController.getController().getObjectFromId(id);
+         if (object != null) {
+             Object parentObject = GraphicController.getController().getProperty(figure.getIdentifier(), GraphicObjectProperties.__GO_PARENT__);
+             Integer parentUID = parentObject == null ? 0 : (Integer) parentObject;
+             while (parentUID.intValue() != 0) {
+                 if (parentUID.intValue() == id.intValue()) {
+                     return true;
+                 }
+                 parentObject = GraphicController.getController().getProperty(parentUID, GraphicObjectProperties.__GO_PARENT__);
+                 parentUID = parentObject == null ? 0 : (Integer) parentObject;
+             }
+         }
+         return false;
+     }
+     /**
       * Check if the given id correspond to a child of the current {@see Figure}.
       * @param id the given id.
       * @return true if the given id correspond to a child of the current {@see Figure}.