Exemplo n.º 1
0
        private void OnMouseDown(object sender, MouseSelectHandler e)
        {
            if ((selected && !e.remove) || (!selected && e.remove))
            {
                return;
            }

            //Find Screen Point
            Point2d mouse_pt         = new Point2d(e.point.X, e.point.Y);
            Line    l                = e.viewport.ClientToWorld(mouse_pt);
            Plane   projection_plane = e.viewport.GetConstructionPlane().Plane;
            Point3d viewport_point;

            if (Rhino.Geometry.Intersect.Intersection.LinePlane(l, projection_plane, out double p))
            {
                viewport_point = l.PointAt(p);
            }
            else
            {
                return;
            }

            //Create Ray from camera
            Point3d  camera_pt = e.viewport.CameraLocation;
            Vector3d direction = new Vector3d(viewport_point - camera_pt);
            Ray3d    r         = new Rhino.Geometry.Ray3d(camera_pt, direction);

            if (!parent.selectFaces)
            {
                //Object selection
                parameter = Rhino.Geometry.Intersect.Intersection.MeshRay(brep_renderMesh, r);
                if (parameter > 0.0)
                {
                    parent.mouseSelector.selected.Add(this);
                }
            }
            else
            {
                //Face selection
                for (int i = 0; i < face_renderMesh.Length; i++)
                {
                    p = Rhino.Geometry.Intersect.Intersection.MeshRay(face_renderMesh[i], r);
                    face_parameters[i] = p;
                }
                int index_max = face_parameters.ToList <double>().IndexOf(face_parameters.Max());
                if (face_parameters[index_max] > 0)
                {
                    face_selected[index_max] = true;
                    parent.mouseSelector.selected.Add(this);
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnMouseDown(MouseCallbackEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.MouseButton == MouseButton.Right)
            {
                return;
            }

            selected = new List <SelectionGeometry>();

            MouseSelectHandler mouseSelect = new MouseSelectHandler(e.View.ActiveViewport, e.ViewportPoint, e.CtrlKeyDown);

            MousePressed?.Invoke(this, mouseSelect);

            if (selected.Count > 0)
            {
                if (!parent.selectFaces)
                {
                    double min           = System.Double.PositiveInfinity;
                    int    index_closest = 0;
                    for (int i = 0; i < selected.Count; i++)
                    {
                        if (selected[i].parameter < min)
                        {
                            min           = selected[i].parameter;
                            index_closest = i;
                        }
                    }

                    if (!e.CtrlKeyDown)
                    {
                        if (parent.selectThroughObjects == true)
                        {
                            for (int i = 0; i < selected.Count; i++)
                            {
                                selected[i].selected = true;
                                parent.selectionGeometriesStack.Push(selected[i]);
                            }
                        }
                        else
                        {
                            selected[index_closest].selected = true;
                            parent.selectionGeometriesStack.Push(selected[index_closest]);
                        }
                    }
                    else
                    {
                        if (parent.selectThroughObjects == true)
                        {
                            for (int i = 0; i < selected.Count; i++)
                            {
                                selected[i].selected = false;

                                List <SelectionGeometry> selected_list = parent.selectionGeometriesStack.ToList <SelectionGeometry>();
                                selected_list.Remove(selected[i]);
                                parent.selectionGeometriesStack = new Stack <SelectionGeometry>(selected_list);
                            }
                        }
                        else
                        {
                            selected[index_closest].selected = false;

                            List <SelectionGeometry> selected_list = parent.selectionGeometriesStack.ToList <SelectionGeometry>();
                            selected_list.Remove(selected[index_closest]);
                            parent.selectionGeometriesStack = new Stack <SelectionGeometry>(selected_list);
                        }
                    }
                }
                else
                {
                }

                parent.selectionRetrigger = true;
                parent.ExpireSolution(true);
                e.View.Redraw();
            }
        }