예제 #1
0
        protected void doResolveTopPick(DrawContext dc, Point pickPoint)
        {
            PickedObjectList pol = dc.getPickedObjects();

            if (pol != null && pol.size() == 1)
            {
                // If there is only one picked object, then it must be the top object so we're done.
                pol.get(0).setOnTop();
            }
            else if (pol != null && pol.size() > 1)
            {
                // If there is more than one picked object, then find the picked object corresponding to the top color at
                // the pick point, and mark it as on top
                int colorCode = dc.getPickColorAtPoint(pickPoint);
                if (colorCode != 0)
                {
                    foreach (PickedObject po in pol)
                    {
                        if (po != null && po.getColorCode() == colorCode)
                        {
                            po.setOnTop();
                            break; // No need to check the remaining picked objects.
                        }
                    }
                }
            }
        }
예제 #2
0
        public Position getCurrentPosition()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            Position     p   = null;
            PickedObject top = pol.getTopPickedObject();

            if (top != null && top.hasPosition())
            {
                p = top.getPosition();
            }
            else if (pol.getTerrainObject() != null)
            {
                p = pol.getTerrainObject().getPosition();
            }

            return(p);
        }
예제 #3
0
 public SelectEvent(Object source, String eventAction, Rectangle pickRectangle, PickedObjectList pickedObjects) : base(source)
 {
     this.eventAction   = eventAction;
     this.pickPoint     = default(Point);
     this.pickRect      = pickRectangle;
     this.mouseEvent    = null;
     this.pickedObjects = pickedObjects;
 }
예제 #4
0
        public SelectEvent(object source, string eventAction, MouseEvent mouseEvent, PickedObjectList pickedObjects) : base(source)
        {
            this.eventAction = eventAction;
            this.pickPoint   = mouseEvent != null?mouseEvent.getPoint() : null;

            this.pickRect      = default(Rectangle);
            this.mouseEvent    = mouseEvent;
            this.pickedObjects = pickedObjects;
        }
예제 #5
0
        protected PickedObjectList getCurrentBoxSelection()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.sceneController.getObjectsInPickRectangle();

            return(pol != null && pol.size() > 0 ? pol : null);
        }
        protected Position computeSelectedPosition()
        {
            PickedObjectList pickedObjects = this.wwd.getObjectsAtCurrentPosition();

            if (pickedObjects != null)
            {
                if (pickedObjects.getTerrainObject() != null)
                {
                    return(pickedObjects.getTerrainObject().getPosition());
                }
            }
            return(null);
        }
예제 #7
0
        protected void doDeepPick(DrawContext dc)
        {
            PickedObjectList currentPickedObjects     = this.lastPickedObjects;
            PickedObjectList currentObjectsInPickRect = this.lastObjectsInPickRect;

            dc.setDeepPickingEnabled(true);
            this.doNonTerrainPick(dc);
            dc.setDeepPickingEnabled(false);

            this.lastPickedObjects     = this.mergePickedObjectLists(currentPickedObjects, dc.getPickedObjects());
            this.lastObjectsInPickRect = this.mergePickedObjectLists(currentObjectsInPickRect,
                                                                     dc.getObjectsInPickRectangle());
        }
예제 #8
0
        protected PickedObject getCurrentSelection()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            PickedObject top = pol.getTopPickedObject();

            return(top.isTerrain() ? null : top);
        }
예제 #9
0
        protected PickedObjectList mergePickedObjectLists(PickedObjectList listA, PickedObjectList listB)
        {
            if (listA == null || listB == null || !listA.hasNonTerrainObjects() || !listB.hasNonTerrainObjects())
            {
                return(listA);
            }

            foreach (PickedObject pb in listB)
            {
                if (pb.isTerrain())
                {
                    continue;
                }

                bool common = false; // cannot modify listA within its iterator, so use a flag to indicate commonality
                foreach (PickedObject pa in listA)
                {
                    if (pa.isTerrain())
                    {
                        continue;
                    }

                    if (pa.getObject() == pb.getObject())
                    {
                        common = true;
                        break;
                    }
                }

                if (!common)
                {
                    listA.add(pb);
                }
            }

            return(listA);
        }
예제 #10
0
        protected void pick(DrawContext dc)
        {
            this.pickTime              = System.currentTimeMillis();
            this.lastPickedObjects     = null;
            this.lastObjectsInPickRect = null;

            try
            {
                dc.enablePickingMode();
                this.pickTerrain(dc);
                this.doNonTerrainPick(dc);

                if (this.isDeferOrderedRendering())
                {
                    return;
                }

                this.resolveTopPick(dc);
                this.lastPickedObjects     = new PickedObjectList(dc.getPickedObjects());
                this.lastObjectsInPickRect = new PickedObjectList(dc.getObjectsInPickRectangle());

                if (this.isDeepPickEnabled() &&
                    (this.lastPickedObjects.hasNonTerrainObjects() || this.lastObjectsInPickRect.hasNonTerrainObjects()))
                {
                    this.doDeepPick(dc);
                }
            }
            catch (Throwable e)
            {
                Logging.logger().log(Level.SEVERE, Logging.getMessage("BasicSceneController.ExceptionDuringPick"), e);
            }
            finally
            {
                dc.disablePickingMode();
                this.pickTime = System.currentTimeMillis() - this.pickTime;
            }
        }
예제 #11
0
        /** Releases resources associated with this scene controller. */
        public void dispose()
        {
            if (this.lastPickedObjects != null)
            {
                this.lastPickedObjects.clear();
            }
            this.lastPickedObjects = null;

            if (this.lastObjectsInPickRect != null)
            {
                this.lastObjectsInPickRect.clear();
            }
            this.lastObjectsInPickRect = null;

            if (this.dc != null)
            {
                this.dc.dispose();
            }

            if (this.textRendererCache != null)
            {
                this.textRendererCache.dispose();
            }
        }
예제 #12
0
 public DragSelectEvent(object source, string eventAction, MouseEvent mouseEvent, PickedObjectList pickedObjects,
                        Point previousPickPoint) : base(source, eventAction, mouseEvent, pickedObjects)
 {
     this.previousPickPoint = previousPickPoint;
 }
예제 #13
0
        protected void doResolveTopPick(DrawContext dc, Rectangle pickRect)
        {
            PickedObjectList pol = dc.getObjectsInPickRectangle();

            if (pol != null && pol.size() == 1)
            {
                // If there is only one picked object, then it must be the top object so we're done.
                pol.get(0).setOnTop();
            }
            else if (pol != null && pol.size() > 1)
            {
                int[] minAndMaxColorCodes = null;

                foreach (PickedObject po in pol)
                {
                    int colorCode = po.getColorCode();

                    // Put all of the eligible picked objects in a map to provide constant time access to a picked object
                    // by its color code. Since the number of unique color codes and picked objects may both be large, using
                    // a hash map reduces the complexity of the next loop from O(n*m) to O(n*c), where n and m are the
                    // lengths of the unique color list and picked object list, respectively, and c is the constant time
                    // associated with a hash map access.
                    this.pickableObjects.put(colorCode, po);

                    // Keep track of the minimum and maximum color codes of the scene's picked objects. These values are
                    // used to cull the number of colors that the draw context must consider with identifying the unique
                    // pick colors in the specified screen rectangle.
                    if (minAndMaxColorCodes == null)
                    {
                        minAndMaxColorCodes = new int[] { colorCode, colorCode }
                    }
                    ;
                    else
                    {
                        if (minAndMaxColorCodes[0] > colorCode)
                        {
                            minAndMaxColorCodes[0] = colorCode;
                        }
                        if (minAndMaxColorCodes[1] < colorCode)
                        {
                            minAndMaxColorCodes[1] = colorCode;
                        }
                    }
                }

                // If there is more than one picked object, then find the picked objects corresponding to each of the top
                // colors in the pick rectangle, and mark them all as on top.
                int[] colorCodes = dc.getPickColorsInRectangle(pickRect, minAndMaxColorCodes);
                if (colorCodes != null && colorCodes.length > 0)
                {
                    // Find the top picked object for each unique color code, if any, and mark it as on top.
                    foreach (int colorCode in colorCodes)
                    {
                        if (colorCode != 0) // This should never happen, but we check anyway.
                        {
                            PickedObject po = this.pickableObjects.get(colorCode);
                            if (po != null)
                            {
                                po.setOnTop();
                            }
                        }
                    }
                }

                // Clear the map of eligible picked objects so that the picked objects from this frame do not affect the
                // next frame. This also ensures that we do not leak memory by retaining references to picked objects.
                this.pickableObjects.clear();
            }
        }
예제 #14
0
 protected void setPickedObjectList(PickedObjectList pol)
 {
     this.lastPickedObjects = pol;
 }