private void simpleOpenGlControl1_MouseUp(object sender, MouseEventArgs e)
 {
     startmove = false;
     if (drawSelRect)
     {
         drawSelRect = false;
     }
     if (e.Button != System.Windows.Forms.MouseButtons.Left)
     {
         return;
     }
     Selection = GroupPick(e.Location);
     if (Selection == null)
     {
         if (GroupMemberSelected != null)
         {
             GroupMemberSelected(null);
         }
         return;
     }
     if (GroupMemberSelected != null)
     {
         GroupMemberSelected(Groups[Selection.GroupId].GetEntry(Selection.Index - 1));
     }
     Selection = null;
     Render();
     Render();
 }
Esempio n. 2
0
        /// <summary>
        /// Pick first position
        /// </summary>
        /// <param name="ray">Ray</param>
        /// <param name="facingOnly">Select only facing triangles</param>
        /// <param name="result">Picking result</param>
        /// <returns>Returns true if picked position found</returns>
        public bool PickFirst(Ray ray, bool facingOnly, out PickingResult <T> result)
        {
            Stopwatch w = Stopwatch.StartNew();

            try
            {
                result = new PickingResult <T>()
                {
                    Distance = float.MaxValue,
                };

                if (this.Root.PickFirst(ray, facingOnly, out Vector3 position, out T item, out float distance))
                {
                    result.Position = position;
                    result.Item     = item;
                    result.Distance = distance;

                    return(true);
                }

                return(false);
            }
            finally
            {
                w.Stop();

                Counters.AddPick((float)w.Elapsed.TotalSeconds);
            }
        }
        private void simpleOpenGlControl1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }
            Selection = GroupPick(e.Location);

            /*if (Selection == null)
             * {
             *      if (GroupMemberSelected != null) GroupMemberSelected(null);
             *      return;
             * }
             * if (GroupMemberSelected != null) GroupMemberSelected(Groups[Selection.GroupId].GetEntry(Selection.Index - 1));*/
        }
Esempio n. 4
0
        //-------------------------------------------------------------------
        protected override void OnMouseWheel(MouseEventArgs e)
        {
            if (Root == null)
            {
                return;
            }

            if (ModifierKeys.HasFlag(Keys.Control))
            {
                Options.Zoom *= Math.Sign(e.Delta) > 0 ? 1.1f : 0.9f;
                EditionToolUpdate(null);
                ShortcutModeClear();
                RefreshGraph();
                if (Selected != null)
                {
                    Goto(Selected);
                }
                return;
            }

            PickingResult pickResult = PickTaxon(Root, ClientToGraph(e.Location));
            TaxonTreeNode pick       = pickResult?.GetMain();

            if (pick != null)
            {
                if (e.Delta > 0)
                {
                    pick.ExpandExtended();
                    RefreshGraph();
                }
                else
                {
                    pick.CollapseExtended();
                    RefreshGraph();
                    if (pick.R.Bottom < e.Location.Y - Origin.Y)
                    {
                        Origin.Y = e.Location.Y + 10 - pick.R.Bottom;
                    }
                }
            }
        }
Esempio n. 5
0
        //-------------------------------------------------------------------
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (Root == null)
            {
                return;
            }

            if (mouseDown)
            {
                if (Math.Max(Math.Abs(e.Location.X - mouseX), Math.Abs(e.Location.Y - mouseY)) > 3)
                {
                    mouseDown = false;
                    move      = true;
                    _InertiaMove.StartSamples(e.Location);
                }
                return;
            }

            if (move)
            {
                _InertiaMove.AddSample(e.Location);
                int dx = e.Location.X - mouseX;
                int dy = e.Location.Y - mouseY;
                mouseX = e.Location.X;
                mouseY = e.Location.Y;

                Offset(dx, dy);

                if (mouseY > ClientRectangle.Bottom)
                {
                    _InertiaMove.OffsetRef(0, -ClientRectangle.Height);
                    mouseY         -= ClientRectangle.Height;
                    Cursor.Position = PointToScreen(new Point(mouseX, mouseY));
                }
                else if (mouseY < ClientRectangle.Top)
                {
                    _InertiaMove.OffsetRef(0, ClientRectangle.Height);
                    mouseY         += ClientRectangle.Height;
                    Cursor.Position = PointToScreen(new Point(mouseX, mouseY));
                }
                if (mouseX > ClientRectangle.Right)
                {
                    _InertiaMove.OffsetRef(-ClientRectangle.Width, 0);
                    mouseX         -= ClientRectangle.Width;
                    Cursor.Position = PointToScreen(new Point(mouseX, mouseY));
                }
                else if (mouseX < ClientRectangle.Left)
                {
                    _InertiaMove.OffsetRef(ClientRectangle.Width, 0);
                    mouseX         += ClientRectangle.Width;
                    Cursor.Position = PointToScreen(new Point(mouseX, mouseY));
                }
                return;
            }

            PickingResult pickResult = PickTaxon(Root, ClientToGraph(e.Location));

            BelowMouse           = pickResult?.BelowMouseIncludingShortcut;
            BelowMouseNoShortcut = pickResult?.BelowMouse;
            mouseX = e.Location.X;
            mouseY = e.Location.Y;
            Invalidate();
        }
Esempio n. 6
0
        //-------------------------------------------------------------------
        public PickingResult PickTaxonRectangular(TaxonTreeNode _in, int X, int Y)
        {
            if (X < _in.R.Left)
            {
                return(null);
            }
            if (Y < _in.R.Top)
            {
                return(null);
            }
            if (Y > _in.R.Bottom)
            {
                return(null);
            }

            if (_in.R.Contains(X, Y))
            {
                if (ShortcutModeKeyOn() && ShortcutModeDatas.TryGetValue(_in, out ShortcutData data))
                {
                    if (data.R.Contains(X, Y))
                    {
                        return new PickingResult()
                               {
                                   BelowMouse = _in, BelowMouseIncludingShortcut = _in
                               }
                    }
                    ;
                    foreach (KeyValuePair <TaxonTreeNode, Rectangle> tuple in data.Siblings)
                    {
                        if (tuple.Value.Contains(X, Y))
                        {
                            return new PickingResult()
                                   {
                                       BelowMouse = _in, BelowMouseIncludingShortcut = tuple.Key
                                   }
                        }
                    }
                    ;
                    //return null;
                }
                return(new PickingResult()
                {
                    BelowMouse = _in, BelowMouseIncludingShortcut = _in
                });
            }

            foreach (TaxonTreeNode child in _in.Children)
            {
                PickingResult result = PickTaxonRectangular(child, X, Y);
                if (result != null)
                {
                    return(result);
                }
            }
            return(null);
        }

        //-------------------------------------------------------------------
        TaxonTreeNode PickTaxonCircular(TaxonTreeNode _in, int X, int Y)
        {
            if (_in.CircularInfo != null)
            {
                if (_in.CircularInfo.InternalPoint)
                {
                    int delta = (X - (int)_in.CircularInfo.X);
                    if (delta > -5 && delta < 5)
                    {
                        delta = (Y - (int)_in.CircularInfo.Y);

                        if (delta > -5 && delta < 5)
                        {
                            return(_in);
                        }
                    }
                }
                else
                {
                    double t = (X - _CircularParams.CenterX) * _in.CircularInfo.Dx + (Y - _CircularParams.CenterY) * _in.CircularInfo.Dy;
                    if (t >= _CircularParams.Radius && t <= _CircularParams.Radius + _CircularParams.TaxonWidth)
                    {
                        t = (X - _CircularParams.CenterX) * _in.CircularInfo.Nx + (Y - _CircularParams.CenterY) * _in.CircularInfo.Ny;
                        if (Math.Abs(t) < _CircularParams.TaxonHeightO2)
                        {
                            return(_in);
                        }
                    }
                    return(null);
                }
            }

            foreach (TaxonTreeNode child in _in.Children)
            {
                TaxonTreeNode result = PickTaxonCircular(child, X, Y);
                if (result != null)
                {
                    return(result);
                }
            }
            return(null);
        }
Esempio n. 7
0
        public bool Select(Double2 xy, out PickingResult result)
        {
            bool unselect = inputHandler.IsKeyPressed(Key.ShiftLeft);
            List <PickingResult> r;

            result = null;
            if (sg.Pick(xy, 5, out r))
            {
                if (Validator == null)
                {
                    result = r[0];
                }
                else
                {
                    bool success = false;
                    for (int i = 0; i < r.Count; ++i)
                    {
                        result = r[i];
                        if (Validator(result))
                        {
                            success = true;
                            break;
                        }
                    }
                    if (!success)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            if (Pick != null)
            {
                Pick(result, unselect);
            }

            int geometryID = result.GeometryIndex;


            int id = result.PrimitiveIndex;
            PhongPatchPNTriangleGeometry g = result.Node.Geometries[geometryID] as PhongPatchPNTriangleGeometry;

            if (g != null && patchSelectionEnabled)
            {
                int patchID = g.GetRangeIndex(id);
                int index   = GetIndex(result.Node, patchID);

                if (index < 0 && !unselect)
                {
                    if (!multiSelect)
                    {
                        Clear();
                    }

                    SelectionElement se = new SelectionElement(result.Node, geometryID, patchID);
                    se.Highlight();
                    selection.Add(se);
                }
                else if (index >= 0 && unselect)
                {
                    Unselect(index);
                }
                return(true);
            }
            else
            {
                SelectableSceneNode n = result.Node as SelectableSceneNode;
                if (n != null)
                {
                    int index = GetIndex(result.Node, -1);

                    if (index < 0 && !unselect)
                    {
                        if (!multiSelect)
                        {
                            Clear();
                        }

                        SelectionElement se = new SelectionElement(result.Node, geometryID);
                        se.Highlight();
                        selection.Add(se);
                    }
                    else if (index >= 0 && unselect)
                    {
                        Unselect(index);
                    }
                    return(true);
                }
            }
            return(false);
            //}
            //return false;
            //else if (!multiSelect)
            //    Clear();
        }
Esempio n. 8
0
        private void simpleOpenGlControl1_MouseUp(object sender, MouseEventArgs e)
        {
            startmove = false;
            if (drawSelRect)
            {
                drawSelRect = false;

            }
            if (e.Button != System.Windows.Forms.MouseButtons.Left) return;
            Selection = GroupPick(e.Location);
            if (Selection == null)
            {
                if (GroupMemberSelected != null) GroupMemberSelected(null);
                return;
            }
            if (GroupMemberSelected != null) GroupMemberSelected(Groups[Selection.GroupId].GetEntry(Selection.Index - 1));
            Selection = null;
            Render();
            Render();
        }
Esempio n. 9
0
 private void simpleOpenGlControl1_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button != System.Windows.Forms.MouseButtons.Left) return;
     Selection = GroupPick(e.Location);
     /*if (Selection == null)
     {
         if (GroupMemberSelected != null) GroupMemberSelected(null);
         return;
     }
     if (GroupMemberSelected != null) GroupMemberSelected(Groups[Selection.GroupId].GetEntry(Selection.Index - 1));*/
 }