Exemplo n.º 1
0
        private void ControlDown(MouseEventArgs e)
        {
            List <Tuple <Point, PickedGeometry> > allPickedGeometrys = this.scene.Pick(
                e.Location, this.PickingGeometryType);
            PickedGeometry pickedGeometry = null;

            if (allPickedGeometrys != null && allPickedGeometrys.Count > 0)
            {
                pickedGeometry = allPickedGeometrys[0].Item2;
            }

            if (pickedGeometry != null)
            {
                PickableRenderer pickableRenderer = null;
                var renderer = pickedGeometry.FromRenderer as HighlightedPickableRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.SetHighlightIndexes(
                        this.PickingGeometryType.ToDrawMode(), pickedGeometry.VertexIds);
                    this.highlightedRenderer = renderer;
                    pickableRenderer         = renderer.PickableRenderer;
                }
                else
                {
                    pickableRenderer = pickedGeometry.FromRenderer as PickableRenderer;
                }

                FormBulletinBoard bulletinBoard = this.bulletinBoard;
                if ((bulletinBoard != null) && (!bulletinBoard.IsDisposed))
                {
                    ICamera camera     = this.scene.FirstCamera;
                    mat4    projection = camera.GetProjectionMatrix();
                    mat4    view       = camera.GetViewMatrix();
                    mat4    model      = pickableRenderer.GetModelMatrix().Value;
                    this.bulletinBoard.SetContent(pickedGeometry.ToString(
                                                      projection, view, model));
                }

                this.glCanvas1.Cursor = Cursors.Hand;
            }
            else
            {
                HighlightedPickableRenderer renderer = this.highlightedRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.ClearHighlightIndexes();
                }
                this.bulletinBoard.SetContent("picked nothing.");

                this.glCanvas1.Cursor = Cursors.Default;
            }
            this.pickedGeometry = pickedGeometry;
        }
 private void UpdatePickingBoard(PickedGeometry pickedGeometry)
 {
     if (pickedGeometry != null)
     {
         this.pickedGeometryBoard.SetContent(pickedGeometry.ToString(
                                                 camera.GetProjectionMat4(), camera.GetViewMat4(), mat4.identity()));
     }
     else
     {
         this.pickedGeometryBoard.SetContent("picked nothing.");
     }
 }
        private void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            if (lastMousePosition == e.Location)
            {
                return;
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseMove(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                DragParam dragParam = this.dragParam;
                if (dragParam != null && this.pickedGeometry != null)
                {
                    var node = this.pickedGeometry.FromRenderer as PickableNode;
                    var currentWindowSpacePos  = new vec3(e.X, this.winGLCanvas1.Height - e.Y - 1, this.pickedGeometry.PickedPosition.z);
                    var currentModelSpacePos   = glm.unProject(currentWindowSpacePos, dragParam.viewMatrix * node.GetModelMatrix(), dragParam.projectionMatrix, dragParam.viewport);
                    var modelSpacePositionDiff = currentModelSpacePos - dragParam.lastModelSpacePos;
                    dragParam.lastModelSpacePos = currentModelSpacePos;
                    IList <vec3> newPositions = node.MovePositions(
                        modelSpacePositionDiff,
                        dragParam.pickedVertexIds);

                    this.UpdateHightlight(newPositions);
                    this.UpdateClipPlane(newPositions[0], newPositions[1], newPositions[2]);
                }
            }
            else
            {
                int x = e.X;
                int y = this.winGLCanvas1.Height - e.Y - 1;
                this.pickedGeometry = this.pickingAction.Pick(x, y, GeometryType.Triangle, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

                if (this.pickedGeometry != null)
                {
                    var text = string.Format("picked: {0}", this.pickedGeometry.FromRenderer);
                }
                else
                {
                    var text = string.Format("picked: nothing");
                }

                this.UpdateHightlight();
            }

            this.lastMousePosition = e.Location;
        }
        private void ControlDown(MouseEventArgs e)
        {
            List<Tuple<Point, PickedGeometry>> allPickedGeometrys = this.scene.Pick(
                e.Location, this.PickingGeometryType);
            PickedGeometry pickedGeometry = null;
            if (allPickedGeometrys != null && allPickedGeometrys.Count > 0)
            { pickedGeometry = allPickedGeometrys[0].Item2; }

            if (pickedGeometry != null)
            {
                PickableRenderer pickableRenderer = null;
                var renderer = pickedGeometry.FromRenderer as HighlightedPickableRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.SetHighlightIndexes(
                        this.PickingGeometryType.ToDrawMode(), pickedGeometry.VertexIds);
                    this.highlightedRenderer = renderer;
                    pickableRenderer = renderer.PickableRenderer;
                }
                else
                {
                    pickableRenderer = pickedGeometry.FromRenderer as PickableRenderer;
                }

                FormBulletinBoard bulletinBoard = this.bulletinBoard;
                if ((bulletinBoard != null) && (!bulletinBoard.IsDisposed))
                {
                    ICamera camera = this.scene.FirstCamera;
                    mat4 projection = camera.GetProjectionMatrix();
                    mat4 view = camera.GetViewMatrix();
                    mat4 model = pickableRenderer.GetModelMatrix().Value;
                    this.bulletinBoard.SetContent(pickedGeometry.ToString(
                        projection, view, model));
                }

                this.glCanvas1.Cursor = Cursors.Hand;
            }
            else
            {
                HighlightedPickableRenderer renderer = this.highlightedRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.ClearHighlightIndexes();
                }
                this.bulletinBoard.SetContent("picked nothing.");

                this.glCanvas1.Cursor = Cursors.Default;
            }
            this.pickedGeometry = pickedGeometry;
        }
Exemplo n.º 5
0
 private void UpdateHightlight(PickedGeometry pickedGeometry)
 {
     if (pickedGeometry != null)
     {
         triangleTip.Vertex0 = pickedGeometry.Positions[0];
         triangleTip.Vertex1 = pickedGeometry.Positions[1];
         triangleTip.Vertex2 = pickedGeometry.Positions[2];
         triangleTip.Parent  = pickedGeometry.FromObject as SceneNodeBase;
     }
     else
     {
         triangleTip.Parent = null;
     }
 }
Exemplo n.º 6
0
 private void UpdateHightlight(PickedGeometry pickedGeometry)
 {
     //if (pickedGeometry != null)
     //{
     //    triangleTip.Vertex0 = pickedGeometry.Positions[0];
     //    triangleTip.Vertex1 = pickedGeometry.Positions[1];
     //    triangleTip.Vertex2 = pickedGeometry.Positions[2];
     //    triangleTip.Parent = pickedGeometry.FromObject as SceneNodeBase;
     //}
     //else
     //{
     //    triangleTip.Parent = null;
     //}
 }
        private PickedGeometry RunPicking(RenderEventArgs arg, int x, int y)
        {
            lock (this.synObj)
            {
                // prepare pickable elements
                PickableRenderer pickable = this.rendererDict[this.SelectedModel].PickableRenderer;
                pickable.MVP = this.camera.GetProjectionMat4() * this.camera.GetViewMat4();

                PickedGeometry pickedGeometry = ColorCodedPicking.Pick(
                    arg, x, y,
                    pickable);

                return(pickedGeometry);
            }
        }
Exemplo n.º 8
0
        private void glCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            if (lastMousePosition == e.Location)
            {
                return;
            }

            //if (e.Button == System.Windows.Forms.MouseButtons.Right)
            //{
            //    //// operate camera
            //    //rotator.MouseMove(e.X, e.Y);
            //}
            //else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            //{
            //    // move vertex
            //    DragParam dragParam = this.dragParam;
            //    if (dragParam != null && this.pickedGeometry != null)
            //    {
            //        var node = this.pickedGeometry.FromObject as PickableNode;
            //        var currentWindowSpacePos = new vec3(e.X, this.winGLCanvas1.Height - e.Y - 1, this.pickedGeometry.PickedPosition.z);
            //        var currentModelSpacePos = glm.unProject(currentWindowSpacePos, dragParam.viewMatrix * node.GetModelMatrix(), dragParam.projectionMatrix, dragParam.viewport);
            //        var modelSpacePositionDiff = currentModelSpacePos - dragParam.lastModelSpacePos;
            //        dragParam.lastModelSpacePos = currentModelSpacePos;
            //        IList<vec3> newPositions = node.MovePositions(
            //              modelSpacePositionDiff,
            //              dragParam.pickedVertexIds);

            //        this.UpdateHightlight(newPositions);
            //    }
            //}
            //else
            {
                int            x = e.X;
                int            y = this.winGLCanvas1.Height - e.Y - 1;
                PickedGeometry pickedGeometry = this.pickingAction.Pick(x, y, PickingGeometryTypes.Triangle | PickingGeometryTypes.Quad, this.winGLCanvas1.Width, this.winGLCanvas1.Height);
                this.pickedGeometry = pickedGeometry;
                this.UpdateHightlight(pickedGeometry);

                if (pickedGeometry != null)
                {
                    this.winGLCanvas1.Invalidate();
                }
            }

            this.lastMousePosition = e.Location;

            //this.winGLCanvas1.Invalidate();// redraw the scene.
        }
Exemplo n.º 9
0
        private void glCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            if (lastMousePosition == e.Location)
            {
                return;
            }


            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseMove(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                DragParam dragParam = this.dragParam;
                if (dragParam != null && this.pickedGeometry != null)
                {
                    var current            = new ivec2(e.X, this.winGLCanvas1.Height - e.Y - 1);
                    var differenceOnScreen = new ivec2(
                        current.x - dragParam.lastMousePositionOnScreen.x,
                        current.y - dragParam.lastMousePositionOnScreen.y);
                    dragParam.lastMousePositionOnScreen = current;
                    var node = this.pickedGeometry.FromRenderer as PickableNode;

                    IList <vec3> newPositions = node.MovePositions(
                        differenceOnScreen,
                        dragParam.viewMatrix, dragParam.projectionMatrix,
                        dragParam.viewport,
                        dragParam.pickedVertexIds);

                    this.UpdateHightlight(newPositions);
                }
            }
            else
            {
                int x = e.X;
                int y = this.winGLCanvas1.Height - e.Y - 1;
                this.pickedGeometry = this.pickingAction.Pick(x, y, true, true, false);

                this.UpdateHightlight();
            }

            this.lastMousePosition = e.Location;
        }
Exemplo n.º 10
0
        private void glCanvas1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseUp(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex

                PickedGeometry geometry = this.pickedGeometry;
                if (geometry != null && this.lastMouseDownPosition == e.Location)
                {
                    var frm = new FormProperyGrid(geometry.FromRenderer);
                    frm.Show();
                    var frmIndexBufferBoard = new FormIndexBufferBoard();
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        frmIndexBufferBoard.SetTarget(renderer.PickableRenderer.IndexBuffer);
                    }
                    else
                    {
                        var tmp = geometry.FromRenderer as PickableRenderer;
                        if (tmp != null)
                        {
                            frmIndexBufferBoard.SetTarget(tmp.IndexBuffer);
                            //frmIndexBufferBoard.SetTarget((geometry.From as PickableRenderer).IndexBuffer);
                        }
                    }
                    frmIndexBufferBoard.Show();
                }
                {
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.ClearHighlightIndexes();
                        this.highlightedRenderer = null;
                    }
                }
                this.dragParam = null;
            }

            this.lastMousePosition = e.Location;
        }
Exemplo n.º 11
0
        private void TryPicking(MouseEventArgs e)
        {
            List <Tuple <Point, PickedGeometry> > allPickedGeometrys = this.scene.Pick(
                e.Location, pickingGeometryType);
            PickedGeometry geometry = null;

            if (allPickedGeometrys != null && allPickedGeometrys.Count > 0)
            {
                geometry = allPickedGeometrys[0].Item2;
            }

            if (geometry != null)
            {
                var renderer = geometry.FromRenderer as RendererBase;
                if (renderer != null)
                {
                    var script = renderer.BindingSceneObject.GetScript <PickingScript>();
                    if (script != null)
                    {
                        script.Bind();
                    }
                }

                this.glCanvas1.Cursor = Cursors.Hand;
            }
            else
            {
                if (this.pickedGeometry != null)
                {
                    var renderer = this.pickedGeometry.FromRenderer as RendererBase;
                    if (renderer != null)
                    {
                        var script = renderer.BindingSceneObject.GetScript <PickingScript>();
                        if (script != null)
                        {
                            script.Unbind();
                        }
                    }
                }
                this.glCanvas1.Cursor = Cursors.Default;
            }

            this.pickedGeometry = geometry;
        }
Exemplo n.º 12
0
        private void UpdateHightlight()
        {
            PickedGeometry picked = this.pickedGeometry;

            if (picked != null)
            {
                switch (picked.Type)
                {
                case GeometryType.Point:
                    throw new NotImplementedException();

                case GeometryType.Line:
                    throw new NotImplementedException();

                case GeometryType.Triangle:
                    triangleTip.Vertex0 = picked.Positions[0];
                    triangleTip.Vertex1 = picked.Positions[1];
                    triangleTip.Vertex2 = picked.Positions[2];
                    triangleTip.Parent  = picked.FromRenderer as SceneNodeBase;
                    quadTip.Parent      = null;
                    break;

                case GeometryType.Quad:
                    quadTip.Vertex0    = picked.Positions[0];
                    quadTip.Vertex1    = picked.Positions[1];
                    quadTip.Vertex2    = picked.Positions[2];
                    quadTip.Vertex3    = picked.Positions[3];
                    quadTip.Parent     = picked.FromRenderer as SceneNodeBase;
                    triangleTip.Parent = null;
                    break;

                case GeometryType.Polygon:
                    throw new NotImplementedException();

                default:
                    throw new NotDealWithNewEnumItemException(typeof(GeometryType));
                }
            }
            else
            {
                triangleTip.Parent = null;
                quadTip.Parent     = null;
            }
        }
Exemplo n.º 13
0
        private void MouseMoveFree(MouseEventArgs e)
        {
            if (this.controlDown)
            {
                ControlDown(e);
            }
            else
            {
                if (this.pickedGeometry != null)
                {
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.ClearHighlightIndexes();
                    }
                    this.bulletinBoard.SetContent("picked nothing.");

                    this.glCanvas1.Cursor = Cursors.Default;
                    this.pickedGeometry   = null;
                }
            }
        }
        private void glCanvas1_MouseDown(object sender, MouseEventArgs e)
        {
            this.lastMousePosition = e.Location;

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.SetBounds(this.glCanvas1.Width, this.glCanvas1.Height);
                //rotator.MouseDown(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                UpdateColorInformationAtMouse(e.X, e.Y);

                PickedGeometry pickedGeometry = RunPicking(
                    new RenderEventArgs(
                        RenderModes.ColorCodedPicking,
                        this.glCanvas1.ClientRectangle,
                        this.camera,
                        this.PickingGeometryType),
                    e.X, e.Y);
                if (pickedGeometry != null)
                {
                    this.rendererDict[this.selectedModel].Highlighter.SetHighlightIndexes(
                        this.PickingGeometryType.ToDrawMode(),
                        pickedGeometry.Indexes);
                    var dragParam = new DragParam(
                        camera.GetProjectionMat4(),
                        camera.GetViewMat4(),
                        new Point(e.X, glCanvas1.Height - e.Y - 1));
                    dragParam.pickedIndexes.AddRange(pickedGeometry.Indexes);
                    this.dragParam = dragParam;
                }

                this.pickedGeometry = pickedGeometry;
            }
        }
Exemplo n.º 15
0
        void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            int x       = e.X;
            int y       = this.winGLCanvas1.Height - e.Y - 1;
            var builder = new StringBuilder();

            {
                var      array  = new Pixel[1];
                GCHandle pinned = GCHandle.Alloc(array, GCHandleType.Pinned);
                IntPtr   header = pinned.AddrOfPinnedObject();
                // same result with: IntPtr header = Marshal.UnsafeAddrOfPinnedArrayElement(array, 0);
                // get coded color.
                GL.Instance.ReadPixels(x, y, 1, 1, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, header);
                pinned.Free();
                builder.AppendFormat("Color at Mouse: vec4({0})", array[0]);
                builder.AppendLine();
            }
            {
                PickedGeometry pickedGeometry = this.pickingAction.Pick(x, y, PickingGeometryTypes.Triangle, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

                if (pickedGeometry != null)
                {
                    builder.AppendFormat("CSharpGL - picked: {0}", pickedGeometry);
                    builder.AppendLine();
                }
                else
                {
                    builder.AppendFormat("Picked: nothing.");
                    builder.AppendLine();
                }

                this.UpdateHightlight(pickedGeometry);
            }

            this.textBox1.Text = builder.ToString();
        }
        private void MouseMoveFree(MouseEventArgs e)
        {
            if (this.controlDown)
            {
                ControlDown(e);
            }
            else
            {
                if (this.pickedGeometry != null)
                {
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.ClearHighlightIndexes();
                    }
                    this.bulletinBoard.SetContent("picked nothing.");

                    this.glCanvas1.Cursor = Cursors.Default;
                    this.pickedGeometry = null;
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Color coded picking.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            LegacyTriangleNode triangleTip = this.triangleTip;

            if (triangleTip == null)
            {
                return;
            }
            LegacyQuadNode quadTip = this.quadTip;

            if (quadTip == null)
            {
                return;
            }

            int            x = e.X;
            int            y = this.winGLCanvas1.Height - e.Y - 1;
            PickedGeometry pickedGeometry = null;

            try
            {
                pickedGeometry = this.pickingAction.Pick(x, y, PickingGeometryTypes.Triangle | PickingGeometryTypes.Quad, this.winGLCanvas1.Width, this.winGLCanvas1.Height);
            }
            catch (Exception)
            { }
            if (pickedGeometry != null)
            {
                switch (pickedGeometry.Type)
                {
                case GeometryType.Point:
                    throw new NotImplementedException();

                case GeometryType.Line:
                    throw new NotImplementedException();

                case GeometryType.Triangle:
                    triangleTip.Vertex0 = pickedGeometry.Positions[0];
                    triangleTip.Vertex1 = pickedGeometry.Positions[1];
                    triangleTip.Vertex2 = pickedGeometry.Positions[2];
                    triangleTip.Parent  = pickedGeometry.FromObject as SceneNodeBase;
                    quadTip.Parent      = null;
                    break;

                case GeometryType.Quad:
                    quadTip.Vertex0    = pickedGeometry.Positions[0];
                    quadTip.Vertex1    = pickedGeometry.Positions[1];
                    quadTip.Vertex2    = pickedGeometry.Positions[2];
                    quadTip.Vertex3    = pickedGeometry.Positions[3];
                    quadTip.Parent     = pickedGeometry.FromObject as SceneNodeBase;
                    triangleTip.Parent = null;
                    break;

                case GeometryType.Polygon:
                    throw new NotImplementedException();

                default:
                    throw new NotDealWithNewEnumItemException(typeof(GeometryType));
                }
            }
            else
            {
                triangleTip.Parent = null;
                quadTip.Parent     = null;
            }
        }
        private void glCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            if (lastMousePosition == e.Location)
            {
                return;
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseMove(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                DragParam dragParam = this.dragParam;
                if (dragParam != null)
                {
                    var   current            = new Point(e.X, glCanvas1.Height - e.Y - 1);
                    Point differenceOnScreen = new Point(
                        current.X - dragParam.lastMousePositionOnScreen.X,
                        current.Y - dragParam.lastMousePositionOnScreen.Y);
                    dragParam.lastMousePositionOnScreen = current;
                    PickableRenderer renderer = null;
                    {
                        var tmp = this.pickedGeometry.From as HighlightedPickableRenderer;
                        if (tmp != null)
                        {
                            renderer = tmp.PickableRenderer;
                        }
                    }

                    if (renderer == null)
                    {
                        renderer = this.pickedGeometry.From as PickableRenderer;
                    }

                    renderer.MovePositions(
                        differenceOnScreen,
                        dragParam.viewMatrix, dragParam.projectionMatrix,
                        dragParam.viewport,
                        dragParam.pickedVertexIds);
                }
            }
            else
            {
                UpdateColorInformationAtMouse(e.X, e.Y);

                PickedGeometry pickedGeometry = this.scene.ColorCodedPicking(
                    e.Location, this.PickingGeometryType);
                if (pickedGeometry != null)
                {
                    PickableRenderer pickableRenderer = null;
                    var renderer = pickedGeometry.From as HighlightedPickableRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.SetHighlightIndexes(
                            this.PickingGeometryType.ToDrawMode(), pickedGeometry.VertexIds);
                        this.highlightedRenderer = renderer;
                        pickableRenderer         = renderer.PickableRenderer;
                    }
                    else
                    {
                        pickableRenderer = pickedGeometry.From as PickableRenderer;
                    }

                    FormBulletinBoard bulletinBoard = this.bulletinBoard;
                    if ((bulletinBoard != null) && (!bulletinBoard.IsDisposed))
                    {
                        ICamera camera     = this.scene.Camera;
                        mat4    projection = camera.GetProjectionMatrix();
                        mat4    view       = camera.GetViewMatrix();
                        mat4    model      = pickableRenderer.GetModelMatrix();
                        this.bulletinBoard.SetContent(pickedGeometry.ToString(
                                                          projection, view, model));
                    }

                    this.glCanvas1.Cursor = Cursors.Hand;
                }
                else
                {
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.ClearHighlightIndexes();
                    }
                    this.bulletinBoard.SetContent("picked nothing.");

                    this.glCanvas1.Cursor = Cursors.Default;
                }
                this.pickedGeometry = pickedGeometry;
            }

            this.lastMousePosition = e.Location;
        }
Exemplo n.º 19
0
        /// <summary>
        /// 把选中的对象设置为选中状态
        /// </summary>
        /// <param name="gss"></param>
        private void SetSelects(List <IntersectGeometry> gss)
        {
            if (gss.Count > 0)
            {
                this.RemoveTemporaryVisualsByType(1);
                SelectIntersectGeometrys.ForEach(x =>
                {
                    x.GeometryShape.UnSelect();
                });

                SelectIntersectGeometrys = gss;

                SelectIntersectGeometrys.ForEach(x =>
                {
                    if (x.IntersectPoint != null && x.IntersectPoint.Point != null)
                    {
                        x.GeometryShape.Select(x.IntersectPoint.Point);
                    }
                });
                if (isPick)
                {
                    if (Picked != null)
                    {
                        var resultSSG = gss.FindAll(x => !(x.GeometryShape is SelectingBox));
                        if (resultSSG != null && resultSSG.Count > 0)
                        {
                            PickedEventArgs ges = new PickedEventArgs(resultSSG[0]);
                            ges.PickType = pickType;
                            Picked(ges);

                            PickedGeometry sg = new PickedGeometry(gss[0]);
                            this.AddTemporaryVisual(sg);
                            sg.Update();
                        }
                    }
                }
                else
                {
                    //对选中的对象进行清除
                    gss.ForEach(x =>
                    {
                        if (!(x.GeometryShape is ImageGeometry))
                        {
                            SelectedGeometry sg = new SelectedGeometry(x);
                            this.AddTemporaryVisual(sg);
                            sg.Update();
                        }
                    });
                    //多选事件
                    if (SelectChanged != null)
                    {
                        MultiSelectedEventArgs ges = new MultiSelectedEventArgs(gss);
                        SelectChanged(ges);
                    }
                }
                //指定当前的命名模式
                if (this.EAction is DrawingKernel.Commands.ICommand)
                {
                    if (gss[0].GeometryShape != null && gss[0].GeometryShape.IsCommand)
                    {
                        (this.EAction as DrawingKernel.Commands.ICommand).SetIntersectGeometry(gss[0]);

                        if (EAction is DrawingKernel.Commands.AlignCommand && (this.EAction as DrawingKernel.Commands.ICommand).GetTarget() == null)
                        {
                            this.Cursor = CursorGetter.Getter(CursorStyle.Command);
                        }
                        else
                        {
                            this.Cursor = CursorGetter.Getter(CursorStyle.Cross);
                        }
                    }
                }
            }
            else
            {
                if (this.EAction is DrawingKernel.Commands.ICommand)
                {
                    this.Cursor = CursorGetter.Getter(CursorStyle.Command);
                }
            }
        }
Exemplo n.º 20
0
        private void DrawText(PaintEventArgs e)
        {
            Point          mousePosition  = this.glCanvas1.PointToClient(Control.MousePosition);
            PickedGeometry pickedGeometry = this.pickedGeometry;

            if (pickedGeometry != null)
            {
                string content = string.Format("[index: {0}]",
                                               pickedGeometry.VertexIds.PrintArray());
                //SizeF size = e.Graphics.MeasureString(content, font);
                Size size = this.uiText.Size;
                // make sure the text displayed.
                int x = mousePosition.X - (size.Width / 2) - pickedGeometry.FromViewPort.Location.X;
                if (x + (size.Width) >= this.glCanvas1.Width)
                {
                    x = this.glCanvas1.Width - size.Width;
                }
                else if (x < 0)
                {
                    x = 0;
                }
                // make sure the text displayed.
                int y = this.glCanvas1.Height - mousePosition.Y - 1 - pickedGeometry.FromViewPort.Location.Y;
                if (y + size.Height + 1 >= this.glCanvas1.Height)
                {
                    y = this.glCanvas1.Height - 15 - 5;
                }
                else if (y < 15)
                {
                    if (y > 0)
                    {
                        y += 15;
                    }
                    else
                    {
                        y = 15;
                    }
                }
                else
                {
                    y += 15;
                }
                //OpenGL.DrawText(x, y,
                //    this.TextColor, "Courier New", fontSize,
                //    content);
                this.lblDrawText.Text = content;
                Padding margin = this.uiText.Margin;
                margin.Left         = x; margin.Bottom = y;
                this.uiText.Margin  = margin;
                this.uiText.Text    = content;
                this.uiText.Enabled = false;// invalid for now.
            }
            else
            {
                //OpenGL.DrawText(mousePosition.X,
                //    this.glCanvas1.Height - mousePosition.Y - 1,
                //    this.TextColor, "Courier New", fontSize,
                //    "");
                this.lblDrawText.Text = "";
                //this.uiText.Text = "";
                this.uiText.Enabled = false;
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Color coded picking.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void winGLCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            //LegacyTriangleNode triangleTip = this.triangleTip;
            //if (triangleTip == null) { return; }
            //LegacyQuadNode quadTip = this.quadTip;
            //if (quadTip == null) { return; }
            HighlightGeometryNode tipNode = this.tipNode;

            int            x = e.X;
            int            y = this.winGLCanvas1.Height - e.Y - 1;
            PickedGeometry pickedGeometry = null;

            try
            {
                pickedGeometry = this.pickingAction.Pick(x, y, PickingGeometryTypes.Triangle | PickingGeometryTypes.Quad, this.winGLCanvas1.Width, this.winGLCanvas1.Height);
            }
            catch (Exception)
            { }

            if (pickedGeometry != null)
            {
                switch (pickedGeometry.Type)
                {
                case GeometryType.Point:
                    tipNode.Vertex0     = pickedGeometry.Positions[0];
                    tipNode.CurrentMode = CSharpGL.DrawMode.Points;
                    tipNode.Parent      = pickedGeometry.FromObject as SceneNodeBase;
                    //tipNode.Parent = this.scene.RootNode;
                    break;

                case GeometryType.Line:
                    tipNode.Vertex0     = pickedGeometry.Positions[0];
                    tipNode.Vertex1     = pickedGeometry.Positions[1];
                    tipNode.CurrentMode = CSharpGL.DrawMode.Lines;
                    tipNode.Parent      = pickedGeometry.FromObject as SceneNodeBase;
                    //tipNode.Parent = this.scene.RootNode;
                    break;

                case GeometryType.Triangle:
                    //triangleTip.Vertex0 = pickedGeometry.Positions[0];
                    //triangleTip.Vertex1 = pickedGeometry.Positions[1];
                    //triangleTip.Vertex2 = pickedGeometry.Positions[2];
                    //triangleTip.Parent = pickedGeometry.FromObject as SceneNodeBase;
                    //quadTip.Parent = null;
                    tipNode.Vertex0     = pickedGeometry.Positions[0];
                    tipNode.Vertex1     = pickedGeometry.Positions[1];
                    tipNode.Vertex2     = pickedGeometry.Positions[2];
                    tipNode.CurrentMode = CSharpGL.DrawMode.Triangles;
                    tipNode.Parent      = pickedGeometry.FromObject as SceneNodeBase;
                    //tipNode.Parent = this.scene.RootNode;
                    break;

                case GeometryType.Quad:
                    //quadTip.Vertex0 = pickedGeometry.Positions[0];
                    //quadTip.Vertex1 = pickedGeometry.Positions[1];
                    //quadTip.Vertex2 = pickedGeometry.Positions[2];
                    //quadTip.Vertex3 = pickedGeometry.Positions[3];
                    //quadTip.Parent = pickedGeometry.FromObject as SceneNodeBase;
                    //triangleTip.Parent = null;
                    tipNode.Vertex0     = pickedGeometry.Positions[0];
                    tipNode.Vertex1     = pickedGeometry.Positions[1];
                    tipNode.Vertex2     = pickedGeometry.Positions[2];
                    tipNode.Vertex3     = pickedGeometry.Positions[3];
                    tipNode.CurrentMode = CSharpGL.DrawMode.Quads;
                    tipNode.Parent      = pickedGeometry.FromObject as SceneNodeBase;
                    //tipNode.Parent = this.scene.RootNode;
                    break;

                case GeometryType.Polygon:
                    throw new NotImplementedException();

                default:
                    throw new NotDealWithNewEnumItemException(typeof(GeometryType));
                }
            }
            else
            {
                //triangleTip.Parent = null;
                //quadTip.Parent = null;
                tipNode.Parent = null;
            }
        }
Exemplo n.º 22
0
        private void TryPicking(MouseEventArgs e)
        {
            List<Tuple<Point, PickedGeometry>> allPickedGeometrys = this.scene.Pick(
              e.Location, pickingGeometryType);
            PickedGeometry geometry = null;
            if (allPickedGeometrys != null && allPickedGeometrys.Count > 0)
            { geometry = allPickedGeometrys[0].Item2; }

            if (geometry != null)
            {
                var renderer = geometry.FromRenderer as RendererBase;
                if (renderer != null)
                {
                    var script = renderer.BindingSceneObject.GetScript<PickingScript>();
                    if (script != null)
                    {
                        script.Bind();
                    }
                }

                this.glCanvas1.Cursor = Cursors.Hand;
            }
            else
            {
                if (this.pickedGeometry != null)
                {
                    var renderer = this.pickedGeometry.FromRenderer as RendererBase;
                    if (renderer != null)
                    {
                        var script = renderer.BindingSceneObject.GetScript<PickingScript>();
                        if (script != null)
                        {
                            script.Unbind();
                        }
                    }
                }
                this.glCanvas1.Cursor = Cursors.Default;
            }

            this.pickedGeometry = geometry;
        }
Exemplo n.º 23
0
        private void DrawText(PaintEventArgs e)
        {
            Point          mousePosition  = this.glCanvas1.PointToClient(Control.MousePosition);
            PickedGeometry pickedGeometry = this.pickedGeometry;

            if (pickedGeometry != null)
            {
                string content = string.Format("[index: {0}]",
                                               pickedGeometry.Indexes.PrintArray());
                //SizeF size = e.Graphics.MeasureString(content, font);
                Size size = this.uiText.Size;
                // make sure the text be displayed.
                int x = mousePosition.X - (size.Width / 2);
                if (x + (size.Width) >= this.glCanvas1.Width)
                {
                    x = this.glCanvas1.Width - size.Width;
                }
                else if (x < 0)
                {
                    x = 0;
                }
                // make sure the text be displayed.
                int y = this.glCanvas1.Height - mousePosition.Y - 1;
                if (y + size.Height + 1 >= this.glCanvas1.Height)
                {
                    y = this.glCanvas1.Height - 15 - 5;
                }
                else if (y < 15)
                {
                    if (y > 0)
                    {
                        y += 15;
                    }
                    else
                    {
                        y = 15;
                    }
                }
                else
                {
                    y += 15;
                }
                //OpenGL.DrawText(x, y,
                //    this.TextColor, "Courier New", fontSize,
                //    content);
                this.lblDrawText.Text = content;
                Padding margin = this.uiText.Margin;
                margin.Left         = x; margin.Bottom = y;
                this.uiText.Margin  = margin;
                this.uiText.Text    = content;
                this.uiText.Enabled = true;
            }
            else
            {
                //OpenGL.DrawText(mousePosition.X,
                //    this.glCanvas1.Height - mousePosition.Y - 1,
                //    this.TextColor, "Courier New", fontSize,
                //    "");
                this.lblDrawText.Text = "";
                //this.uiText.Text = "";
                this.uiText.Enabled = false;
            }
            {
                // Cross cursor shows where the mouse is.
                OpenGL.DrawText(mousePosition.X - offset.X,
                                this.glCanvas1.Height - (mousePosition.Y + offset.Y) - 1,
                                Color.Red, "Courier New", crossCursorSize, "o");
            }
        }