Example #1
0
        /// <summary>
        /// Apply new line width
        /// </summary>
        public static bool ApplyLineWidth(DrawingCanvas drawingCanvas, double value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange             = false;


            // LineWidth is set for all objects except of GraphicsText.
            // Though GraphicsText has this property, it should remain constant.

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                if (g is GraphicsRectangle ||
                    g is GraphicsLine ||
                    g is GraphicsPolyLine)
                {
                    if (g.LineWidth != value)
                    {
                        g.LineWidth = value;
                        wasChange   = true;
                    }
                }
            }

            if (wasChange && addToHistory)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return(wasChange);
        }
        /// <summary>
        /// Apply new font family
        /// </summary>
        public static bool ApplyFontFamily(DrawingCanvas drawingCanvas, string value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                GraphicsText gt = g as GraphicsText;

                if (gt != null)
                {
                    if (gt.TextFontFamilyName != value)
                    {
                        gt.TextFontFamilyName = value;
                        wasChange = true;
                    }
                }
            }

            if (wasChange  && addToHistory )
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return wasChange;
        }
Example #3
0
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.NetSelection)
            {
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint));

                selectMode = SelectionMode.None;
            }

            if (resizedObject != null)
            {
                resizedObject.Normalize();
                resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            if (commandChangeState != null && wasMove)
            {
                commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Example #4
0
 /// <summary>
 /// Add change to history.
 /// Called after finishing moving/resizing.
 /// </summary>
 public void AddChangeToHistory(DrawingCanvas drawingCanvas)
 {
     if (commandChangeState != null && wasMove)
     {
         // Keep state after moving/resizing and add command to history
         commandChangeState.NewState(drawingCanvas);
         drawingCanvas.AddCommandToHistory(commandChangeState);
         commandChangeState = null;
     }
 }
 /// <summary>
 /// Add change to history.
 /// Called after finishing moving/resizing.
 /// </summary>
 public void AddChangeToHistory(DrawingCanvas drawingCanvas)
 {
     if (commandChangeState != null && wasMove)
     {
         // Keep state after moving/resizing and add command to history
         commandChangeState.NewState(drawingCanvas);
         drawingCanvas.AddCommandToHistory(commandChangeState);
         commandChangeState = null;
     }
 }
Example #6
0
        /// <summary>
        /// Return true if currently active properties (line width, color etc.)
        /// can be applied to selected items.
        ///
        /// If at least one selected object has property different from currently
        /// active property value, properties can be applied.
        /// </summary>
        //public static bool CanApplyProperties(DrawingCanvas drawingCanvas)
        //{
        //	foreach(GraphicsBase graphicsBase in drawingCanvas.GraphicsList)
        //	{
        //		if ( ! graphicsBase.IsSelected )
        //		{
        //			continue;
        //		}

        //		// ObjectColor - used in all graphics objects
        //		if ( graphicsBase.ObjectColor != drawingCanvas.ObjectColor )
        //		{
        //			return true;
        //		}



        //	return false;
        //}

        /// <summary>
        /// Apply currently active properties to selected objects
        /// </summary>
        public static void ApplyProperties(DrawingCanvas drawingCanvas)
        {
            // Apply every property.
            // Call every Apply* function with addToHistory = false.
            // History is updated here and not in called functions.

            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange             = false;



            if (wasChange)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }
        }
        /// <summary>
        /// Apply new color
        /// </summary>
        public static bool ApplyColor(DrawingCanvas drawingCanvas, Color value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                if (g.ObjectColor != value)
                {
                    g.ObjectColor = value;
                    wasChange = true;
                }
            }

            if ( wasChange && addToHistory )
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return wasChange;
        }
Example #8
0
        /// <summary>
        /// Apply new color
        /// </summary>
        public static bool ApplyColor(DrawingCanvas drawingCanvas, Color value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange             = false;

            foreach (GraphicsBase g in drawingCanvas.Selection)
            {
                if (g.ObjectColor != value)
                {
                    g.ObjectColor = value;
                    wasChange     = true;
                }
            }

            if (wasChange && addToHistory)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return(wasChange);
        }
        /// <summary>
        /// Handle mouse down.
        /// Start moving, resizing or group selection.
        /// </summary>
        public override void OnMouseDown(DrawingCanvas drawingCanvas, MouseButtonEventArgs e)
        {
            commandChangeState = null;
            wasMove = false;

            Point point = e.GetPosition(drawingCanvas);

            selectMode = SelectionMode.None;

            GraphicsBase o;
            GraphicsBase movedObject = null;
            int handleNumber;

            // Test for resizing (only if control is selected, cursor is on the handle)
            for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
            {
                o = drawingCanvas[i];

                if ( o.IsSelected )
                {
                    handleNumber = o.MakeHitTest(point);

                    if (handleNumber > 0)
                    {
                        selectMode = SelectionMode.Size;

                        // keep resized object in class member
                        resizedObject = o;
                        resizedObjectHandle = handleNumber;

                        // Since we want to resize only one object, unselect all other objects
                        HelperFunctions.UnselectAll(drawingCanvas);
                        o.IsSelected = true;

                        commandChangeState = new CommandChangeState(drawingCanvas);

                        break;
                    }
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
                {
                    o = drawingCanvas[i];

                    if (o.MakeHitTest(point) == 0)
                    {
                        movedObject = o;
                        break;
                    }
                }

                if (movedObject != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if (Keyboard.Modifiers != ModifierKeys.Control  && ! movedObject.IsSelected)
                    {
                        HelperFunctions.UnselectAll(drawingCanvas);
                    }

                    // Select clicked object
                    movedObject.IsSelected = true;

                    // Set move cursor
                    drawingCanvas.Cursor = Cursors.SizeAll;

                    commandChangeState = new CommandChangeState(drawingCanvas);
                }
            }

            // Click on background
            if (selectMode == SelectionMode.None)
            {
                // Unselect all if Ctrl is not pressed
                if (Keyboard.Modifiers != ModifierKeys.Control)
                {
                    HelperFunctions.UnselectAll(drawingCanvas);
                }

                // Group selection. Create selection rectangle.
                GraphicsSelectionRectangle r = new GraphicsSelectionRectangle(
                    point.X, point.Y,
                    point.X + 1, point.Y + 1,
                    drawingCanvas.ActualScale);

                r.Clip = new RectangleGeometry(new Rect(0, 0, drawingCanvas.ActualWidth, drawingCanvas.ActualHeight));

                drawingCanvas.GraphicsList.Add(r);

                selectMode = SelectionMode.GroupSelection;
            }

            lastPoint = point;

            // Capture mouse until MouseUp event is received
            drawingCanvas.CaptureMouse();
        }
Example #10
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove = false;

            selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    resizedObject = o;
                    resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    break;
                }
            }

            // Test for move (cursor is on the object)
            if ( selectMode == SelectionMode.None )
            {
                int n1 = drawArea.GraphicsList.Count;
                DrawObject o = null;

                for ( int i = 0; i < n1; i++ )
                {
                    if ( drawArea.GraphicsList[i].HitTest(point) == 0 )
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if ( o != null )
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ( ( Control.ModifierKeys & Keys.Control ) == 0  && !o.Selected )
                        drawArea.GraphicsList.UnselectAll();

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if ( selectMode == SelectionMode.None )
            {
                // click on background
                if ( ( Control.ModifierKeys & Keys.Control ) == 0 )
                    drawArea.GraphicsList.UnselectAll();

                selectMode = SelectionMode.NetSelection;

            }

            lastPoint.X = e.X;
            lastPoint.Y = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if ( selectMode == SelectionMode.NetSelection )
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Example #11
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
            if ( selectMode == SelectionMode.NetSelection )
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint));

                selectMode = SelectionMode.None;
            }

            if ( resizedObject != null )
            {
                // after resizing
                resizedObject.Normalize();
                resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            if ( commandChangeState != null  && wasMove )
            {
                // Keep state after moving/resizing and add command to history
                commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Example #12
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
        {
#if EWSAPP
            int newx;
            int newy;


            switch (selectMode)
            {
            case SelectionMode.NetSelection:
                Trace.WriteLine("ToolPointer OnMouseUp MouseButtons.Left SelectionMode.NetSelection");
                drawArea.Pages.SelectInRectangle(drawArea.NetRectangle);

                selectMode = SelectionMode.None;

                drawArea.DrawNetRectangle = false;
                if (resizedObject != null)
                {
                    // after resizing
                    resizedObject.Normalize();
                    resizedObject = null;
                }

                drawArea.Capture = false;
                drawArea.Refresh();

                if (commandChangeState != null && wasMove)
                {
                    // Keep state after moving/resizing and add command to history
                    commandChangeState.NewState(drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo]);
                    drawArea.Pages.AddCommandToHistory(commandChangeState);
                    commandChangeState = null;
                }
                lastPoint = drawArea.BackTrackMouse(e.Location);
                break;

            case SelectionMode.Size:
                Trace.WriteLine("ToolPointer OnMouseUp MouseButtons.Left SelectionMode.Size");
                break;

            case SelectionMode.Move:
                newx = e.X - FirstPoint.X;
                newy = e.Y - FirstPoint.Y;
                //newx = drawArea.FittoSnap(e.X, drawArea.SnapX);
                //newy = drawArea.FittoSnap(e.Y, drawArea.SnapY);
                if ((newx != 0) || (newy != 0))
                {
                    if (drawArea.SnapEnable)
                    {
                        foreach (DrawObject o in drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo].Selection)
                        {
                            //o.MoveTo(drawArea.FittoSnap(o._rectangle.X + newx, drawArea.SnapX), drawArea.FittoSnap(o._rectangle.Y + newy, drawArea.SnapY));
                            int _x = o.rectangle.X;
                            _x = o.rectangle.X + newx;
                            _x = drawArea.FittoSnap(o.rectangle.X, drawArea.SnapX);
                            int _y = o.rectangle.Y;
                            _y = o.rectangle.Y + newy;
                            _y = drawArea.FittoSnap(o.rectangle.Y, drawArea.SnapY);

                            o.MoveTo(_x, _y);
                            if ((o is DrawFBDBox))
                            {
                                ((DrawFBDBox)o).UpdateWireConnections();
                            }
                        }
                    }

                    drawArea.Cursor = Cursors.SizeAll;
                    drawArea.Refresh();
                    drawArea.Pages.Dirty = true;
                }
                break;

            default:

                break;
            }

            selectMode      = SelectionMode.None;
            drawArea.Cursor = Cursors.Default;
#endif
        }
        /// <summary>
        /// Apply currently active properties to selected objects
        /// </summary>
        public static void ApplyProperties(DrawingCanvas drawingCanvas)
        {
            // Apply every property.
            // Call every Apply* function with addToHistory = false.
            // History is updated here and not in called functions.

            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            // Line Width
            if ( ApplyLineWidth(drawingCanvas, drawingCanvas.LineWidth, false))
            {
                wasChange = true;
            }

            // Color
            if ( ApplyColor(drawingCanvas, drawingCanvas.ObjectColor, false) )
            {
                wasChange = true;
            }

            // Font properties
            if ( ApplyFontFamily(drawingCanvas, drawingCanvas.TextFontFamilyName, false) )
            {
                wasChange = true;
            }

            if ( ApplyFontSize(drawingCanvas, drawingCanvas.TextFontSize, false) )
            {
                wasChange = true;
            }

            if ( ApplyFontStretch(drawingCanvas, drawingCanvas.TextFontStretch, false) )
            {
                wasChange = true;
            }

            if ( ApplyFontStyle(drawingCanvas, drawingCanvas.TextFontStyle, false) )
            {
                wasChange = true;
            }

            if ( ApplyFontWeight(drawingCanvas, drawingCanvas.TextFontWeight, false) )
            {
                wasChange = true;
            }

            if ( wasChange )
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }
        }
        /// <summary>
        /// Apply new line width
        /// </summary>
        public static bool ApplyLineWidth(DrawingCanvas drawingCanvas, double value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            // LineWidth is set for all objects except of GraphicsText.
            // Though GraphicsText has this property, it should remain constant.

            foreach(GraphicsBase g in drawingCanvas.Selection)
            {
                if (g is GraphicsRectangle ||
                     g is GraphicsEllipse ||
                     g is GraphicsLine ||
                     g is GraphicsPolyLine)
                {
                    if ( g.LineWidth != value )
                    {
                        g.LineWidth = value;
                        wasChange = true;
                    }
                }
            }

            if (wasChange  && addToHistory)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return wasChange;
        }
        /// <summary>
        /// Apply new font style
        /// </summary>
        public static bool ApplyFontStyle(DrawingCanvas drawingCanvas, FontStyle value, bool addToHistory)
        {
            CommandChangeState command = new CommandChangeState(drawingCanvas);
            bool wasChange = false;

            foreach (GraphicsBase g in drawingCanvas.GraphicsList)
            {
                if (g.IsSelected)
                {
                    GraphicsText gt = g as GraphicsText;

                    if (gt != null)
                    {
                        if (gt.TextFontStyle != value)
                        {
                            gt.TextFontStyle = value;
                            wasChange = true;
                        }
                    }
                }
            }

            if (wasChange  && addToHistory)
            {
                command.NewState(drawingCanvas);
                drawingCanvas.AddCommandToHistory(command);
            }

            return wasChange;
        }
Example #16
0
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode          = SelectionMode.Size;
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected         = true;
                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);
                    break;
                }
            }

            if (selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;

                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            if (selectMode == SelectionMode.None)
            {
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                selectMode = SelectionMode.NetSelection;
            }

            lastPoint.X  = e.X;
            lastPoint.Y  = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (selectMode == SelectionMode.NetSelection)
            {
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Example #17
0
        /// <summary>
        /// Handle mouse down.
        /// Start moving, resizing or group selection.
        /// </summary>
        public override void OnMouseDown(DrawingCanvas drawingCanvas, Point position)
        {
            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;

            GraphicsBase o;
            GraphicsBase movedObject = null;
            int          handleNumber;

            // Test for resizing (only if control is selected, cursor is on the handle)
            for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
            {
                o = drawingCanvas[i];

                if (o.IsSelected)
                {
                    handleNumber = o.MakeHitTest(position);

                    if (handleNumber > 0)
                    {
                        selectMode = SelectionMode.Size;

                        // keep resized object in class member
                        resizedObject       = o;
                        resizedObjectHandle = handleNumber;

                        // Since we want to resize only one object, unselect all other objects
                        HelperFunctions.UnselectAll(drawingCanvas);
                        o.IsSelected = true;

                        commandChangeState = new CommandChangeState(drawingCanvas);

                        break;
                    }
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                for (int i = drawingCanvas.GraphicsList.Count - 1; i >= 0; i--)
                {
                    o = drawingCanvas[i];

                    if (o.MakeHitTest(position) == 0)
                    {
                        movedObject = o;
                        break;
                    }
                }

                if (movedObject != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if (Keyboard.Modifiers != ModifierKeys.Control && !movedObject.IsSelected)
                    {
                        HelperFunctions.UnselectAll(drawingCanvas);
                    }

                    // Select clicked object
                    movedObject.IsSelected = true;

                    // Set move cursor
                    drawingCanvas.Cursor = Cursors.SizeAll;

                    commandChangeState = new CommandChangeState(drawingCanvas);
                }
            }

            // Click on background
            if (selectMode == SelectionMode.None)
            {
                // Unselect all if Ctrl is not pressed
                if (Keyboard.Modifiers != ModifierKeys.Control)
                {
                    HelperFunctions.UnselectAll(drawingCanvas);
                }

                // Group selection. Create selection rectangle.
                GraphicsSelectionRectangle r = new GraphicsSelectionRectangle(
                    position.X, position.Y,
                    position.X + 1, position.Y + 1,
                    drawingCanvas.ActualScale);

                //r.Clip = new RectangleGeometry(new Rect(0, 0, drawingCanvas.ActualWidth, drawingCanvas.ActualHeight));

                drawingCanvas.GraphicsList.Add(r);

                selectMode = SelectionMode.GroupSelection;
            }


            lastPoint = position;

            // Capture mouse until MouseUp event is received
            drawingCanvas.CaptureMouse();
        }
Example #18
0
        public override void MouseDoubleClick(DrawArea drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);

            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;
            Trace.WriteLine("ToolPointer OnMouseDown ");
            if (e.Button == MouseButtons.Left)
            {
                Point point;
                //    if (drawArea.SnapEnable)
                {
                    //      point = drawArea.BackTrackMouse(new Point(drawArea.FittoSnap(e.X, drawArea.SnapX), drawArea.FittoSnap(e.Y, drawArea.SnapY)));
                }
                //else
                {
                    point = drawArea.BackTrackMouse(pointscroll);
                }
                startPoint = point;
                lastPoint  = point;
                FirstPoint = point;

                //DrawObject o = null;
                int hittestresult = -1;
                //for (int i = 0; i < drawArea.graphicsList.List.Count; i++)
                foreach (DrawObject drawobject in drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo].List)
                {
                    //o = drawArea.graphicsList.List[i];
                    if (drawArea.Pages.LayerIsNotLock((LAYERS)drawobject.Layer))
                    {
                        hittestresult = drawobject.HitTest(point);
                        if (hittestresult != -1)
                        {
                            if (drawobject is DrawFunctionBlock)
                            {
                            }
                            else
                            {
                                if (drawobject is DrawFunction)
                                {
                                }
                                else
                                {
                                    if (drawobject is DrawFunctionEx)
                                    {
                                    }
                                    else
                                    {
                                        if (drawobject is DrawVariable)
                                        {
#if EWSAPP
                                            VariableForm varlistfrm = new VariableForm(/*drawArea.mainEWSForm,*/ ((TabFBDPageControl)drawArea.ParentTabGraphicPageControl).ID);
                                            if (DialogResult.OK == varlistfrm.ShowDialog())
                                            {
                                                ((DrawVariable)drawobject).tblvariable         = varlistfrm.tblvariable;
                                                ((DrawVariable)drawobject).tblformalparameter  = varlistfrm.tblformalparameter;
                                                ((DrawVariable)drawobject).ExtendedPropertyTXT = varlistfrm.SubPropertyTxt;
                                                drawArea.Capture = false;
                                            }
#endif
                                        }
                                    }
                                }
                            }

                            break;
                        }
                    }
                }
            }
        }
Example #19
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            Point pointscroll = GetEventPointInArea(drawArea, e);

            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;
            Trace.WriteLine("ToolPointer OnMouseDown ");
            if (e.Button == MouseButtons.Left)
            {
                Point point;
                //    if (drawArea.SnapEnable)
                {
                    //      point = drawArea.BackTrackMouse(new Point(drawArea.FittoSnap(e.X, drawArea.SnapX), drawArea.FittoSnap(e.Y, drawArea.SnapY)));
                }
                //else
                {
                    point = drawArea.BackTrackMouse(pointscroll);
                }
                startPoint = point;
                lastPoint  = point;
                FirstPoint = point;

                DrawObject o             = null;
                int        hittestresult = -1;
                for (int i = 0; i < drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo].List.Count; i++)
                //foreach (DrawObject o in drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo].List)
                {
                    o = drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo].List[i];
                    if (drawArea.Pages.LayerIsNotLock((LAYERS)o.Layer))
                    {
                        hittestresult = o.HitTest(point);
                        if (hittestresult != -1)
                        {
#if EWSAPP
                            Trace.WriteLine("ToolPointer OnMouseDown Click over an object");
                            if (o.Selected)      // object was selected
                            {
                                Trace.WriteLine("ToolPointer OnMouseDown object was selected");
                                if (hittestresult > 0)  // over control points
                                {
                                    Console.WriteLine("ToolPointer OnMouseDown over control points e.x {0}  e.y {1}  First.x {2} First.y {3}", o.rectangle.X, o.rectangle.Y, FirstPoint.X, FirstPoint.Y);
                                    selectMode          = SelectionMode.Size;
                                    resizedObject       = o;
                                    resizedObjectHandle = hittestresult;
                                    // Since we want to resize only one object, unselect all other objects
                                    drawArea.UnselectAll();
                                    o.Selected           = true;
                                    commandChangeState   = new CommandChangeState(drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo]);
                                    drawArea.Pages.Dirty = true;
                                }
                                else                  // clicked inside object
                                {
                                    Trace.WriteLine("ToolPointer OnMouseDown clicked inside object ");
                                    //drawArea.Graphics.UnselectAll();
                                    selectMode      = SelectionMode.Move;
                                    drawArea.Cursor = Cursors.SizeAll;
                                    startPoint      = point;
                                }
                            }
                            else  // object was not selected
                            {
                                Trace.WriteLine("ToolPointer OnMouseDown object was not selected ");
                                if ((Control.ModifierKeys & Keys.Control) == 0)
                                {
                                    drawArea.UnselectAll();
                                }
                                o.Selected = true;
                                DCS.Forms.MainForm.Instance().m_propertyGrid.SelectedObject = o;
                                DCS.Forms.MainForm.Instance().m_propertyGrid.Refresh();
                                commandChangeState = new CommandChangeState(drawArea.Pages.GraphicPagesList[drawArea.ActivePageNo]);
                                selectMode         = SelectionMode.Move;
                                drawArea.Cursor    = Cursors.SizeAll;
                                drawArea.Refresh();
                            }
                            break;
#endif
                        }
                    }
                }

                if (hittestresult == -1)   // not clicked over any objet
                {
                    Trace.WriteLine("ToolPointer OnMouseDown not clicked over an objet ");
                    selectMode = SelectionMode.NetSelection;
                    if ((Control.ModifierKeys & Keys.Control) == 0)
                    {
                        drawArea.UnselectAll();
                    }
                }
            }
            else
            {
            }
        }
Example #20
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"></param>
        /// <param name="e"></param>
        public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e)
        {
            commandChangeState = null;
            wasMove            = false;

            selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    resizedObject       = o;
                    resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                selectMode = SelectionMode.NetSelection;
            }

            lastPoint.X  = e.X;
            lastPoint.Y  = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
        /// <summary>
        /// Hide in-place editing textbox.
        /// Called from TextTool, when user pressed Enter or Esc,
        /// or from this class, when user clicks on the canvas.
        /// 
        /// graphicsText passed to this function can be new text added by
        /// ToolText, or existing text opened for editing.
        /// If ToolText.OldText is empty, this is new object.
        /// If not, this is existing object.
        /// </summary>
        internal void HideTextbox(GraphicsText graphicsText)
        {
            if (toolText.TextBox == null )
            {
                return;
            }

            graphicsText.IsSelected = true;   // restore selection which was removed for better textbox appearance

            if (toolText.TextBox.Text.Trim().Length == 0)
            {
                // Textbox is empty: remove text object.

                if ( ! String.IsNullOrEmpty(toolText.OldText) )  // existing text was edited
                {
                    // Since text object is removed now,
                    // Add Delete command to the history
                    undoManager.AddCommandToHistory(new CommandDelete(this));
                }

                // Remove empty text object
                graphicsList.Remove(graphicsText);
            }
            else
            {
                if (!String.IsNullOrEmpty(toolText.OldText))  // existing text was edited
                {
                    if ( toolText.TextBox.Text.Trim() != toolText.OldText )     // text was really changed
                    {
                        // Create command
                        CommandChangeState command = new CommandChangeState(this);

                        // Make change in the text object
                        graphicsText.Text = toolText.TextBox.Text.Trim();
                        graphicsText.UpdateRectangle();

                        // Keep state after change and add command to the history
                        command.NewState(this);
                        undoManager.AddCommandToHistory(command);
                    }
                }
                else                                          // new text was added
                {
                    // Make change in the text object
                    graphicsText.Text = toolText.TextBox.Text.Trim();
                    graphicsText.UpdateRectangle();

                    // Add command to the history
                    undoManager.AddCommandToHistory(new CommandAdd(graphicsText));
                }
            }

            // Remove textbox and set it to null.
            this.Children.Remove(toolText.TextBox);
            toolText.TextBox = null;

            // This enables back all ApplicationCommands,
            // which are disabled while textbox is active.
            this.Focus();
        }