/// <summary>
        /// Handles the MouseDown event when the plot point tool is selected
        /// </summary>
        /// <param name="e">The mouse event args</param>

        public override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);

            PointF mouseXY = new PointF(e.X, e.Y);
            PointF graphXY = _grac.PixelToPrintableAreaCoordinates(mouseXY);

            // search for a object first
            IHitTestObject clickedObject;
            int            clickedLayerNumber = 0;

            _grac.FindGraphObjectAtPixelPosition(mouseXY, true, out clickedObject, out clickedLayerNumber);
            if (null != clickedObject && clickedObject.HittedObject is XYColumnPlotItem)
            {
                m_PlotItem = (XYColumnPlotItem)clickedObject.HittedObject;
                PointF[] transXY = new PointF[] { graphXY };
                Matrix   inv     = clickedObject.Transformation.Clone();
                inv.Invert();
                inv.TransformPoints(transXY);
                XYScatterPointInformation scatterPoint = m_PlotItem.GetNearestPlotPoint(clickedObject.ParentLayer, transXY[0]);

                this._PlotItemNumber = GetPlotItemNumber(clickedLayerNumber, m_PlotItem);
                this._LayerNumber    = clickedLayerNumber;


                if (null != scatterPoint)
                {
                    this._PlotIndex = scatterPoint.PlotIndex;
                    this._RowIndex  = scatterPoint.RowIndex;
                    // convert this layer coordinates first to PrintableAreaCoordinates
                    PointF printableCoord = clickedObject.ParentLayer.LayerToGraphCoordinates(scatterPoint.LayerCoordinates);
                    m_Cross    = printableCoord;
                    m_Cross.X += _grac.Doc.PrintableBounds.X;
                    m_Cross.Y += _grac.Doc.PrintableBounds.Y;

                    PointF newPixelCoord = _grac.PrintableAreaToPixelCoordinates(printableCoord);
                    Cursor.Position = new Point((int)(Cursor.Position.X + newPixelCoord.X - mouseXY.X), (int)(Cursor.Position.Y + newPixelCoord.Y - mouseXY.Y));


                    this.DisplayData(m_PlotItem, scatterPoint.RowIndex,
                                     m_PlotItem.XYColumnPlotData.XColumn[scatterPoint.RowIndex],
                                     m_PlotItem.XYColumnPlotData.YColumn[scatterPoint.RowIndex]);



                    // here we shoud switch the bitmap cache mode on and link us with the AfterPaint event
                    // of the grac
                    _grac.RepaintGraphArea(); // no refresh necessary, only invalidate to show the cross
                }
            }
        } // end of function
        /// <summary>
        /// Handles the MouseDown event when the object pointer tool is selected
        /// </summary>
        /// <param name="position">Mouse position.</param>
        /// <param name="e">The mouse event args</param>
        /// <remarks>
        /// The strategy to handle the mousedown event is as following:
        ///
        /// Have we clicked on already selected objects?
        ///   if yes (we have clicked on already selected objects) and the shift or control key was pressed -> deselect the object and repaint
        ///   if yes (we have clicked on already selected objects) and none shift nor control key was pressed-> activate the object moving  mode
        ///   if no (we have not clicked on already selected objects) and shift or control key was pressed -> search for the object and add it to the selected objects, then aktivate moving mode
        ///   if no (we have not clicked on already selected objects) and no shift or control key pressed -> if a object was found add it to the selected objects and activate moving mode
        ///                                                                                                  if no object was found clear the selection list, deactivate moving mode
        /// </remarks>
        public override void OnMouseDown(PointD2D position, MouseButtonEventArgs e)
        {
            base.OnMouseDown(position, e);

            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return; // then there is nothing to do here
            }
            // first, if we have a mousedown without shift key and the
            // position has changed with respect to the last mousedown
            // we have to deselect all objects
            var keyboardModifiers = System.Windows.Input.Keyboard.Modifiers;

            bool bControlKey = keyboardModifiers.HasFlag(ModifierKeys.Control);
            bool bShiftKey   = keyboardModifiers.HasFlag(ModifierKeys.Shift);

            var mousePixelCoord = position;                                                  // Mouse pixel coordinates
            var rootLayerCoord  = _grac.ConvertMouseToRootLayerCoordinates(mousePixelCoord); // Graph area coordinates

            ActiveGrip = GripHitTest(rootLayerCoord);
            if ((ActiveGrip is SuperGrip) && (bShiftKey || bControlKey))
            {
                var superGrip = ActiveGrip as SuperGrip;
                if (superGrip.GetHittedElement(rootLayerCoord, out var gripHandle, out var hitTestObj))
                {
                    _selectedObjects.Remove(hitTestObj);
                    superGrip.Remove(gripHandle);
                    return;
                }
            }
            else if (ActiveGrip != null)
            {
                ActiveGrip.Activate(rootLayerCoord, false);
                return;
            }
            _grac.FindGraphObjectAtPixelPosition(mousePixelCoord, false, out var clickedObject, out var clickedLayerNumber);

            if (!bShiftKey && !bControlKey) // if shift or control are pressed, we add the object to the selection list and start moving mode
            {
                ClearSelections();
            }

            if (null != clickedObject)
            {
                AddSelectedObject(rootLayerCoord, clickedObject);
            }
        } // end of function
        /// <summary>
        /// Handles the MouseDown event when the plot point tool is selected
        /// </summary>
        /// <param name="position">Mouse position.</param>
        /// <param name="e">The mouse event args</param>
        public override void OnMouseDown(PointD2D position, MouseButtonEventArgs e)
        {
            base.OnMouseDown(position, e);

            var graphXY = _grac.ConvertMouseToRootLayerCoordinates(position);

            _grac.FindGraphObjectAtPixelPosition(position, true, out var clickedObject, out var clickedLayerNumber);
            if (null != clickedObject && clickedObject.HittedObject is XYColumnPlotItem)
            {
                _PlotItem = (XYColumnPlotItem)clickedObject.HittedObject;
                var transXY = clickedObject.Transformation.InverseTransformPoint(graphXY);

                _layer = (XYPlotLayer)(clickedObject.ParentLayer);
                XYScatterPointInformation scatterPoint = _PlotItem.GetNearestPlotPoint(_layer, transXY);
                _PlotItemNumber = GetPlotItemNumber(_layer, _PlotItem);

                if (null != scatterPoint)
                {
                    _PlotIndex = scatterPoint.PlotIndex;
                    _RowIndex  = scatterPoint.RowIndex;
                    // convert this layer coordinates first to PrintableAreaCoordinates
                    var rootLayerCoord = clickedObject.ParentLayer.TransformCoordinatesFromHereToRoot(scatterPoint.LayerCoordinates);
                    _positionOfCrossInRootLayerCoordinates = rootLayerCoord;
                    // m_Cross.X -= _grac.GraphViewOffset.X;
                    // m_Cross.Y -= _grac.GraphViewOffset.Y;

                    var newPixelCoord = _grac.ConvertGraphToMouseCoordinates(rootLayerCoord);

                    // TODO (Wpf)
                    //var newCursorPosition = new Point((int)(Cursor.Position.X + newPixelCoord.X - mouseXY.X),(int)(Cursor.Position.Y + newPixelCoord.Y - mouseXY.Y));
                    //SetCursorPos(newCursorPosition.X, newCursorPosition.Y);

                    DisplayData(_PlotItem, scatterPoint.RowIndex,
                                _PlotItem.XYColumnPlotData.XColumn[scatterPoint.RowIndex],
                                _PlotItem.XYColumnPlotData.YColumn[scatterPoint.RowIndex]);

                    // here we shoud switch the bitmap cache mode on and link us with the AfterPaint event
                    // of the grac
                    _grac.RenderOverlay(); // no refresh necessary, only invalidate to show the cross
                }
            }
        } // end of function
Exemple #4
0
        /// <summary>
        /// Handles the MouseDown event when the object pointer tool is selected
        /// </summary>
        /// <param name="e">The mouse event args</param>
        /// <remarks>
        /// The strategy to handle the mousedown event is as following:
        ///
        /// Have we clicked on already selected objects?
        ///   if yes (we have clicked on already selected objects) and the shift or control key was pressed -> deselect the object and repaint
        ///   if yes (we have clicked on already selected objects) and none shift nor control key was pressed-> activate the object moving  mode
        ///   if no (we have not clicked on already selected objects) and shift or control key was pressed -> search for the object and add it to the selected objects, then aktivate moving mode
        ///   if no (we have not clicked on already selected objects) and no shift or control key pressed -> if a object was found add it to the selected objects and activate moving mode
        ///                                                                                                  if no object was found clear the selection list, deactivate moving mode
        /// </remarks>
        public override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.Button != MouseButtons.Left)
            {
                return; // then there is nothing to do here
            }
            // first, if we have a mousedown without shift key and the
            // position has changed with respect to the last mousedown
            // we have to deselect all objects
            bool bControlKey = (Keys.Control == (Control.ModifierKeys & Keys.Control)); // Control pressed
            bool bShiftKey   = (Keys.Shift == (Control.ModifierKeys & Keys.Shift));

            PointF mouseXY = new PointF(e.X, e.Y);                           // Mouse pixel coordinates
            PointF graphXY = _grac.PixelToPrintableAreaCoordinates(mouseXY); // Graph area coordinates


            // if we have exacly one object selected, and the one object is grippable,
            // we hit test for the grip areas
            if (SingleSelectedObject is IGrippableObject)
            {
                IGrippableObject gripObject = (IGrippableObject)SingleSelectedObject;
                // first switch to the layer graphics context (from printable context)

                PointF layerCoord = SingleSelectedHitTestObject.ParentLayer.GraphToLayerCoordinates(graphXY);

                _grip.Handle = gripObject.GripHitTest(layerCoord);

                if (_grip.Handle != null)
                {
                    _grip.Layer  = SingleSelectedHitTestObject.ParentLayer.Number;
                    _grip.Object = gripObject;
                    return; //
                }
            }



            // have we clicked on one of the already selected objects
            IHitTestObject clickedSelectedObject            = null;
            bool           bClickedOnAlreadySelectedObjects = IsPixelPositionOnAlreadySelectedObject(mouseXY, out clickedSelectedObject);

            if (bClickedOnAlreadySelectedObjects)
            {
                if (bShiftKey || bControlKey) // if shift or control is pressed, remove the selection
                {
                    m_SelectedObjects.Remove(clickedSelectedObject);
                    _grac.RefreshGraph(); // repaint the graph
                }
                else // not shift or control pressed -> so activate the object moving mode
                {
                    StartMovingObjects(mouseXY);
                }
            }    // end if bClickedOnAlreadySelectedObjects
            else // not clicked on a already selected object
            {
                // search for a object first
                IHitTestObject clickedObject;
                int            clickedLayerNumber = 0;
                _grac.FindGraphObjectAtPixelPosition(mouseXY, false, out clickedObject, out clickedLayerNumber);

                if (bShiftKey || bControlKey) // if shift or control are pressed, we add the object to the selection list and start moving mode
                {
                    if (null != clickedObject)
                    {
                        m_SelectedObjects.Add(clickedObject);

                        StartMovingObjects(mouseXY);
                        _grac.RepaintGraphArea();
                    }
                }
                else // no shift or control key pressed
                {
                    if (null != clickedObject)
                    {
                        ClearSelections();
                        m_SelectedObjects.Add(clickedObject);

                        StartMovingObjects(mouseXY);
                        _grac.RepaintGraphArea();
                    }
                    else // if clicked to nothing
                    {
                        ClearSelections(); // clear the selection list
                    }
                } // end else no shift or control
            }     // end else (not cklicked on already selected object)
        }         // end of function