Ejemplo n.º 1
0
 private void OnLeftClick(object sender, MouseEventArgs e)
 {
     if (!string.IsNullOrEmpty(_flowChartCtlBasic.RefStateMachine.LockText))
     {
         return;
     }
     if (!EditMode)
     {
         EditMode = true;
     }
     else
     {
         SMContainerPanel panel = sender as SMContainerPanel;
         CurrentSel = null;
         if (_emptyFlowSpot && panel != null && !PreventEdit)
         {
             if (Control.ModifierKeys != Keys.Control)
             {
                 new NewItemForm(this, PixelToGridSnap(panel.PointToClient(MousePosition))).ShowDialog();
             }
             else
             {
                 if (!_draging)
                 {
                     ShowContextMenu(null, PixelToGridSnap(panel.PointToClient(MousePosition)));
                 }
             }
         }
     }
 }
        /// <summary>
        /// Rebuild all controls
        /// </summary>
        public override void Rebuild()
        {
            //int count = this.Controls.Count;
            int count = this.smFlowPanel.Controls.Count;

            if (count > 0)
            {
                Control[] ctls = new Control[count];
                //this.Controls.CopyTo(ctls, 0);
                this.smFlowPanel.Controls.CopyTo(ctls, 0);

                foreach (Control ctl in ctls)
                {
                    // Only dispose of SMContainerPanels
                    if (ctl is SMContainerPanel)
                    {
                        //this.Controls.Remove(ctl);
                        this.smFlowPanel.Controls.Remove(ctl);
                        ctl.Dispose();
                    }
                }
            }
            _currentContainerPanel = null;
            ShowFlowContainer(_stateMachine);
        }
Ejemplo n.º 3
0
        private void OnMouseUp(object sender, MouseEventArgs e)
        {
            SMContainerPanel panel = sender as SMContainerPanel;

            _draging = false;
            if (panel != null)
            {
                _lastMousePos = Point.Empty;
                panel.Cursor  = Cursors.Default;

                //if (Control.ModifierKeys != Keys.Control)
                //{
                //    if (_isCropping && !PreventEdit)
                //    {
                //        GetCropControlList();
                //    }
                //}
                //else
                //{
                //    if (_selectedCtrlList != null && _selectedCtrlList.Count > 0)
                //    {
                //        foreach (SMCtlBase smCtrl in _selectedCtrlList)
                //        {
                //            PointF newPos = SMContainerPanel.PixelToGridSnap(smCtrl.Location);
                //            smCtrl.FlowItem.GridLoc = newPos;
                //            smCtrl.OnMouseUp(null, e);
                //        }

                //    }
                //    this.Redraw();
                //}


                if (Control.ModifierKeys == Keys.Control)
                {
                    if (_selectedCtrlList == null)
                    {
                        if (_isCropping && !PreventEdit)
                        {
                            GetCropControlList();
                        }
                    }
                    else
                    {
                        foreach (SMCtlBase smCtrl in _selectedCtrlList)
                        {
                            PointF newPos = SMContainerPanel.PixelToGridSnap(smCtrl.Location);
                            smCtrl.FlowItem.GridLoc = newPos;
                            smCtrl.OnMouseUp(null, e);
                        }
                        this.Redraw();
                    }
                }

                this.Refresh();
            }
        }
 /// <summary>
 /// Remove this subroutine panel
 /// </summary>
 /// <param name="subroutine"></param>
 public void RemoveFlowContainer(SMFlowContainer flowContainer)
 {
     if (flowContainer != null && Controls.ContainsKey(flowContainer.Nickname))
     {
         SMContainerPanel containerPanel = Controls[flowContainer.Nickname] as SMContainerPanel;
         //this.Controls.Remove(containerPanel);
         this.smFlowPanel.Controls.Remove(containerPanel);
         containerPanel.Dispose();
     }
 }
        /// <summary>
        /// Show this panel and create or show the subroutine panel
        /// </summary>
        /// <param name="subroutine"></param>
        public void ShowFlowContainer(SMFlowContainer flowContainer)
        {
            if (_currentContainerPanel != null)
            {
                if (_currentContainerPanel.Name == flowContainer.Nickname)
                {
                    _currentContainerPanel.PreventEdit = !_enableSMOperation;
                    return;
                }
                _currentContainerPanel.Hide();
            }

            //if (!Controls.ContainsKey(flowContainer.Nickname))
            if (!this.smFlowPanel.Controls.ContainsKey(flowContainer.Nickname))
            {
                // Constructor will rebuild
                //SMContainerPanel subPanel = new SMContainerPanel(this, flowContainer, lblHeader.Size.Height);
                SMContainerPanel subPanel = new SMContainerPanel(this, flowContainer, 0);
                //this.Controls.Add(subPanel);
                this.smFlowPanel.Controls.Add(subPanel);
            }
            //_currentContainerPanel = this.Controls[flowContainer.Nickname] as SMContainerPanel;
            _currentContainerPanel = this.smFlowPanel.Controls[flowContainer.Nickname] as SMContainerPanel;
            _currentContainerPanel.Show();
            _currentFlowContainer = flowContainer;
            lblHeader.Text        = _currentFlowContainer.PathText;
            tbSubroutineName.Text = _currentFlowContainer.Text;
            UpdateAutoScope();

            tbSubroutineName.Hide();
            if (_currentFlowContainer is SMStateMachine)
            {
                if (_currentFlowContainer.IsEditing(_currentContainerPanel.Name))
                {
                    btnClose.Text    = "X";
                    btnClose.Enabled = true;
                }
                else
                {
                    btnClose.Text    = string.Empty;
                    btnClose.Enabled = false;
                }
            }
            else
            {
                btnClose.Text    = "X";
                btnClose.Enabled = true;
            }

            _currentContainerPanel.PreventEdit = !_enableSMOperation;
            lblHeader.BringToFront();
            btnClose.BringToFront();
        }
Ejemplo n.º 6
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            _isCropping = false;
//            System.Diagnostics.Debug.WriteLine(string.Format("FlowChart MouseMove"));
            if (onMouseMove != null)
            {
                //              System.Diagnostics.Debug.WriteLine(string.Format("Fire FlowChart MouseMove event"));
                onMouseMove(this, e);
                return;
            }

            SMContainerPanel panel = sender as SMContainerPanel;

            if (panel == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                if (Control.ModifierKeys != Keys.Control)
                {
                    if (_emptyFlowSpot)
                    {
                        // turn off New Flow Item readiness
                        panel.Cursor   = Cursors.Hand;
                        _emptyFlowSpot = false;
                    }
                    if (!_lastMousePos.IsEmpty)
                    {
                        // Dragging
                        Point newPos     = _flowChartCtlBasic.PointToClient(MousePosition);
                        Point deltaMoved = newPos;

                        deltaMoved.Offset(-_lastMousePos.X, -_lastMousePos.Y);
                        panel.Top    += deltaMoved.Y;
                        panel.Left   += deltaMoved.X;
                        _lastMousePos = newPos;

                        ////Cropping
                        //this.Refresh();
                        //_cropWidth = Math.Abs(e.X - _cropX);
                        //_cropHeight = Math.Abs(e.Y - _cropY);

                        //_oCropX = Math.Min(_cropX, e.X);
                        //_oCropY = Math.Min(_cropY, e.Y);

                        //this.CreateGraphics().DrawRectangle(_cropPen, _oCropX, _oCropY, _cropWidth, _cropHeight);
                        //_isCropping = true;
                    }
                }
                else
                {
                    if (_selectedCtrlList != null)
                    {
                        _draging = true;
                        if (_selectedCtrlList != null && _selectedCtrlList.Count > 0)
                        {
                            foreach (SMCtlBase smCtrl in _selectedCtrlList)
                            {
                                try
                                {
                                    smCtrl.OnMouseMove(null, e);
                                }
                                catch { }
                                finally { }
                            }
                        }
                    }
                    else
                    {
                        //Cropping
                        //this.Refresh();
                        if (_g != null)
                        {
                            _g.Clear(Color.FromArgb(255, 236, 233, 216));
                            _g.Dispose();
                            _g = null;
                        }

                        _g = this.CreateGraphics();
                        _g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                        _g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;


                        _cropWidth  = Math.Abs(e.X - _cropX);
                        _cropHeight = Math.Abs(e.Y - _cropY);

                        _oCropX = Math.Min(_cropX, e.X);
                        _oCropY = Math.Min(_cropY, e.Y);

                        _g.DrawRectangle(_cropPen, _oCropX, _oCropY, _cropWidth, _cropHeight);
                        _isCropping = true;
                    }
                }
            }
            else if (EditMode)
            {
                if (e.Button == MouseButtons.Right)
                {
                    if (!_lastMousePos.IsEmpty)
                    {
                        // Dragging
                        Point newPos     = _flowChartCtlBasic.PointToClient(MousePosition);
                        Point deltaMoved = newPos;

                        deltaMoved.Offset(-_lastMousePos.X, -_lastMousePos.Y);

                        if (Math.Abs(deltaMoved.X) > GridToPixelX(1.0f))
                        {
                            // Change in X
                            if (deltaMoved.X > 0)
                            {
                                _flowContainer.MoveAll(new PointF(1f, 0f));
                            }
                            else
                            {
                                _flowContainer.MoveAll(new PointF(-1f, 0f));
                            }
                            _lastMousePos = newPos;
                            Redraw();
                        }
                        else if (Math.Abs(deltaMoved.Y) > GridToPixelY(1.0f))
                        {
                            // Chang in Y
                            if (deltaMoved.Y > 0)
                            {
                                _flowContainer.MoveAll(new PointF(0f, 1f));
                            }
                            else
                            {
                                _flowContainer.MoveAll(new PointF(0f, -1f));
                            }
                            _lastMousePos = newPos;
                            Redraw();
                        }
                    }
                }

                else
                {
                    // If over an empty space, show
                    PointF gridPos = PixelToGrid(panel.PointToClient(MousePosition));
                    double x       = gridPos.X - (int)gridPos.X;
                    double y       = gridPos.Y - (int)gridPos.Y;

                    if (x < 0.7 && x > 0.3 && y < 0.6 && y > 0.4)
                    {
                        _emptyFlowSpot = true;
                        panel.Cursor   = _flowItemCursor;
                    }
                    else
                    {
                        _emptyFlowSpot = false;
                        panel.Cursor   = Cursors.Default;
                    }
                }
            }
        }