예제 #1
0
        /// <summary>
        /// (De)Select the given map object
        /// </summary>
        /// <param name="mapObject"></param>
        public void SelectMapObject(MapObject mapObject)
        {
            MapObjectGroup selection = controller.Selection;

            if (mapObject != null)
            {
                if (modifierKey == Keys.Control)
                {
                    if (selection.Contains(mapObject))
                    {
                        mapObject.Selected = false;
                        selection.Remove(mapObject);
                    }
                    else
                    {
                        mapObject.Selected = true;
                        selection.Add(mapObject);
                    }
                }
                else if (!selection.Contains(mapObject))
                {
                    selection.Clear();
                    mapObject.Selected = true;
                    selection.Add(mapObject);
                }
            }
            else if (!selection.Empty)
            {
                // deselect
                SolidGrabHandles handles = controller.RubberBand.Handles;
                selection.Clear();
                handles.ResetMode();
            }
        }
예제 #2
0
        public override bool OnMouseDown(Point mouseCurPos, MouseButtons button, BaseViewport viewport)
        {
            MapObjectGroup selectedMapObjectGroup = controller.Selection;
            MapObject      rootMapObject          = controller.GetMapObjectIfHit(mouseCurPos.X, mouseCurPos.Y, viewport);

            if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE)
            {
                if (rootMapObject == null)
                {
                    SetAllFacesSelected(false);
                    selectedMapObjectGroup.Clear();
                }
                else
                {
                    SolidFaceHitOperation operation = new SolidFaceHitOperation(viewport, mouseCurPos);
                    rootMapObject.PerformOperation(operation);

                    SolidFace hitFace = operation.hitFace;
                    if (modifierKey == Keys.Control)
                    {
                        if (!AreAnyFacesSelected(rootMapObject))
                        {
                            controller.Selection.Add(rootMapObject);
                        }

                        hitFace.Selected = !hitFace.Selected;

                        if (!AreAnyFacesSelected(rootMapObject))
                        {
                            controller.Selection.Remove(rootMapObject);
                        }
                    }
                    else if (!hitFace.Selected)
                    {
                        SetAllFacesSelected(false);
                        selectedMapObjectGroup.Clear();

                        hitFace.Selected = true;
                        selectedMapObjectGroup.Add(rootMapObject);
                    }
                }
            }
            else if (rootMapObject == null) // deselect faces when pressing in empty ortho viewport space
            {
                SetAllFacesSelected(false);
                controller.Selection.Clear();
            }

            controller.UpdateUserInterface();

            return(true);
        }
예제 #3
0
        public override bool OnMouseDown(Point mouseCurPos, MouseButtons button, BaseViewport viewport)
        {
            if (button == MouseButtons.Left)
            {
                currentActionViewport = viewport.ViewportType;
                MapObjectGroup selectedMapObjectGroup = controller.Selection;

                bool isControlPressed = modifierKey == Keys.Control;
                newHandlesHit = GetHandlesHitWithMouse(viewport, mouseCurPos);

                // Check if we hit a vertex handle
                if (newHandlesHit.Count > 0)
                {
                    Action dragStartPositionAction = () =>
                    {
                        // any vertex will do
                        var   first       = newHandlesHit.First();
                        Solid solid       = first.Key;
                        int   firstVertex = first.Value[0];

                        SetSelectDragAction(solid.VertexPositions[firstVertex], viewport);
                    };

                    Action isAnySelected = () =>
                    {
                        // if still any selected left, setSelectDrag
                        bool selected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index)));
                        if (selected)
                        {
                            dragStartPositionAction();
                        }
                    };

                    bool anySelected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index)));
                    if (isControlPressed)
                    {
                        foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit)
                        {
                            pair.Value.ForEach((index) =>
                            {
                                if (pair.Key.SelectedVertices.Contains(index))
                                {
                                    pair.Key.SelectedVertices.Remove(index);
                                }
                                else
                                {
                                    pair.Key.SelectedVertices.Add(index);
                                }
                            });
                        }

                        isAnySelected();
                    }
                    else if (anySelected)
                    {
                        dragStartPositionAction();
                    }
                    else
                    {
                        ClearAllSelectedVertices();
                        foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit)
                        {
                            pair.Value.ForEach((index) =>
                            {
                                if (!pair.Key.SelectedVertices.Contains(index))
                                {
                                    pair.Key.SelectedVertices.Add(index);
                                }
                            });
                        }

                        isAnySelected();
                    }
                }
                else // if no handles hit, check if we hit a solid
                {
                    MapObject rootMapObject = controller.GetMapObjectIfHit(mouseCurPos.X, mouseCurPos.Y, viewport);
                    if (rootMapObject == null)
                    {
                        if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE)
                        {
                            ClearAllSelectedVertices();
                        }
                        else // no map object hit for orthographic set action to SelectMultiple
                        {
                            currentAction = VertexToolActionType.SelectMultiple;
                        }
                    }
                    else
                    {
                        if (isControlPressed)
                        {
                            if (!rootMapObject.Selected)
                            {
                                rootMapObject.Selected = true;
                                selectedMapObjectGroup.Add(rootMapObject);
                            }
                            else
                            {
                                DoSolidAction(rootMapObject, (solid) =>
                                {
                                    solid.SelectedVertices.Clear();
                                });
                                rootMapObject.Selected = false;
                                selectedMapObjectGroup.Remove(rootMapObject);
                            }
                        }
                        else if (!rootMapObject.Selected)
                        {
                            ClearAllSelectedVertices();
                            selectedMapObjectGroup.Clear();
                            rootMapObject.Selected = true;
                            selectedMapObjectGroup.Add(rootMapObject);
                        }
                        else
                        {
                            // solid we hit was already selected so we set action to SelectMultiples
                            currentAction = VertexToolActionType.SelectMultiple;
                        }
                    }
                }

                mouseDownPos = mouseCurPos;
            }

            return(true);
        }