Esempio n. 1
0
        public void DeleteLastSegment(SMPathOut firstSeg)
        {
            // Never delete the first one.
            SMPathSegment thisPathSeg = firstSeg.Next;

            int nSeg = 1;

            while (thisPathSeg != null)
            {
                if (thisPathSeg.Next == null)
                {
                    // Delete this one
                    SegmentCtl segCtl = GetSegmentCtl(thisPathSeg);
                    if (segCtl != null)
                    {
                        _containerPanel.Controls.Remove(segCtl);
                        segCtl.Dispose();
                    }
                    thisPathSeg.Delete();
                    PreMoveIt(firstSeg);
                    return;
                }
                thisPathSeg = thisPathSeg.Next;
                nSeg++;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="containerPanel"></param>
 /// <param name="flowItem"></param>
 /// <param name="ctlBase"></param>
 /// <param name="pathSeg"></param>
 public SegmentCtl(SMContainerPanel containerPanel, SMFlowBase flowItem,
                   SMCtlBase ctlBase, SMPathSegment pathSeg)
 {
     _containerPanel = containerPanel;
     _flowItem       = flowItem;
     _ctlBase        = ctlBase;
     _pathSeg        = pathSeg;
     if (pathSeg.First is SMPathOutError)
     {
         _penLine     = new Pen(Color.Red, 2);
         _penSelected = new Pen(Color.Red, 6);
         _penNoTarget = new Pen(Color.Salmon, 6);
     }
     else if (pathSeg.First is SMPathOutStop)
     {
         _penLine     = new Pen(Color.Black, 2);
         _penSelected = new Pen(Color.Blue, 6);
         _penNoTarget = new Pen(Color.DarkGray, 6);
     }
     else
     {
         _penLine     = new Pen(Color.Green, 2);
         _penSelected = new Pen(Color.Green, 6);
         _penNoTarget = new Pen(Color.DarkGreen, 6);
     }
     _ctlBase.LocationChanged += new EventHandler(ctlBase_OnLocationChanged);
     InitializeComponent();
 }
Esempio n. 3
0
 private void BuildSegment(SMPathSegment pathSeg)
 {
     if (pathSeg != null)
     {
         CreateSegmentCtl(pathSeg);
         BuildSegment(pathSeg.Next);
     }
 }
Esempio n. 4
0
        private void SetSegGridLoc(SMPathSegment pathSeg, int xPix, int yPix)
        {
            float gridDelta = pathSeg.Vertical ?
                              SMContainerPanel.PixelToGridY(yPix) :
                              SMContainerPanel.PixelToGridX(xPix);

            pathSeg.GridDistance = gridDelta;
        }
Esempio n. 5
0
        private SegmentCtl CreateSegmentCtl(SMPathSegment pathSeg)
        {
            SegmentCtl segCtl = new SegmentCtl(_containerPanel, _flowItem, this, pathSeg);

            segCtl.Name = BuildSegName(pathSeg);
            _containerPanel.Controls.Add(segCtl);
            return(segCtl);
        }
Esempio n. 6
0
        /// <summary>
        /// Move the arrow to the right position
        /// </summary>
        /// <param name="flowItem"></param>
        /// <param name="pathOut"></param>
        public void MoveIt(SMFlowBase flowItem, SMPathOut pathOut)
        {
            try
            {
                _ctrlBasefromPathOut = _containerPanel.GetFlowCtl(pathOut.Owner.Name);
                _ctlBaseTgt          = _containerPanel.GetFlowCtl(pathOut.TargetID);
                if (_ctlBaseTgt == null)
                {
                    return;
                }
                Size  arrowSize      = global::MCore.Comp.SMLib.SMFlowChart.Properties.Resources.ArrowUp.Size;
                Point borderLocation = _ctlBaseTgt.Location;
                Size  borderSize     = _ctlBaseTgt.Size;
                borderLocation.Offset(-arrowSize.Width, -arrowSize.Height);
                borderSize.Width  += arrowSize.Width;
                borderSize.Height += arrowSize.Height;
                Rectangle     rcBorder    = new Rectangle(borderLocation, borderSize);
                PointF        endPt       = flowItem.FindEndPoint(pathOut);
                Point         pixXY       = SMContainerPanel.GridToPixel(endPt);
                SMPathSegment pathLastSeg = pathOut.Last;
                if (pathLastSeg.Vertical)
                {
                    if (pathLastSeg.GridDistance < 0)
                    {  // Up
                        SetBackgroundImage(global::MCore.Comp.SMLib.SMFlowChart.Properties.Resources.ArrowUp);
                        Location = new Point(pixXY.X - arrowSize.Width / 2, rcBorder.Bottom);
                    }
                    else
                    {  // Down
                        SetBackgroundImage(global::MCore.Comp.SMLib.SMFlowChart.Properties.Resources.ArrowDown);
                        Location = new Point(pixXY.X - arrowSize.Width / 2, rcBorder.Top);
                    }
                }
                else
                {
                    if (pathLastSeg.GridDistance < 0)
                    {  // Left
                        SetBackgroundImage(global::MCore.Comp.SMLib.SMFlowChart.Properties.Resources.ArrowLeft);
                        Location = new Point(rcBorder.Right, pixXY.Y - arrowSize.Height / 2);
                    }
                    else
                    {  // Right
                        SetBackgroundImage(global::MCore.Comp.SMLib.SMFlowChart.Properties.Resources.ArrowRight);
                        Location = new Point(rcBorder.Left, pixXY.Y - arrowSize.Height / 2);
                    }
                }

                _ctrlBasefromPathOut.LocationChanged += new EventHandler(ctrlBasefromPathOut_OnLocationChanged);
                _locOfstFromCtrlBase = new Point(_ctrlBasefromPathOut.Location.X - this.Location.X, _ctrlBasefromPathOut.Location.Y - this.Location.Y);
                Show();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Esempio n. 7
0
        //public SegmentCtl GetLastSegmentCtl(SMPathOut pathOut)
        //{
        //    SMPathSegment pathSeg = pathOut.Next;
        //    int nSeg = 0;
        //    while (pathSeg != null)
        //    {
        //        if (pathSeg.Next == null)
        //        {
        //            return GetSegmentCtl(pathSeg, nSeg);
        //        }
        //        pathSeg = pathSeg.Next;
        //        nSeg++;
        //    }
        //    return null;
        //}
        private SegmentCtl GetSegmentCtl(SMPathSegment pathSeg)
        {
            string name = BuildSegName(pathSeg);

            if (_containerPanel.Controls.ContainsKey(name))
            {
                return(_containerPanel.Controls[name] as SegmentCtl);
            }
            return(null);
        }
Esempio n. 8
0
        private void CreateNewSegment(eDrag dragMode, int pixDeltaX, int pixDeltaY)
        {
            SMPathSegment newPathSeg = _pathSeg.Append();

            SetSegGridLoc(newPathSeg, pixDeltaX, pixDeltaY);
            // Create the control
            _newSegCtl = _ctlBase.AppendSegmentCtl(newPathSeg);
            _ctlBase.MoveItem();
            _newSegCtl.Handoff(_lastMousePosition, dragMode, new SMPathSegment[] { newPathSeg });
        }
Esempio n. 9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="flowChart"></param>
 /// <param name="panel"></param>
 /// <param name="flowItem"></param>
 /// <param name="ctlBase"></param>
 /// <param name="pathSeg"></param>
 public SegmentCtl(SMGenericFlowChart flowChart, Panel panel, SMFlowBase flowItem,
                   SMCtlBase ctlBase, SMPathSegment pathSeg)
 {
     _flowChart = flowChart;
     _panel     = panel;
     _flowItem  = flowItem;
     _ctlBase   = ctlBase;
     _pathSeg   = pathSeg;
     ArrowEnd   = IsLast;
     InitializeComponent();
 }
Esempio n. 10
0
        private string GetSegTypeName(SMPathSegment pathSeg)
        {
            SMPathOut pathSegOut = pathSeg.First;
            string    typeName   = typeName = pathSegOut.GetType().Name.Substring(6);

            if (pathSegOut is SMPathOutBool)
            {
                typeName += (pathSegOut as SMPathOutBool).ID;
            }
            return(typeName);
        }
Esempio n. 11
0
        private void DoMove(SMPathSegment pathSeg, int xDelta, int yDelta)
        {
            if (pathSeg != null)
            {
                float gridDelta = pathSeg.Vertical ?
                                  SMContainerPanel.PixelToGridY(yDelta) :
                                  SMContainerPanel.PixelToGridX(xDelta);

                pathSeg.GridDistance += gridDelta;
            }
        }
Esempio n. 12
0
        private void CreateNewSegment(eDrag dragMode, float gridDistance)
        {
            SMPathSegment newPathSeg = _pathSeg.Append();

            newPathSeg.GridDistance = gridDistance;
            // Create the control
            _newSegCtl = _ctlBase.AppendSegmentCtl(newPathSeg);
            //newSegCtl.Size = new Size(_rcHead.Width, _rcHead.Height);
            _ctlBase.MoveItem();
            _newSegCtl.Handoff(_lastMousePosition, dragMode);
        }
Esempio n. 13
0
        public SegmentCtl AppendSegmentCtl(SMPathSegment newPathSeg)
        {
            // it is already appended, just not created
            SMPathSegment pathSeg = newPathSeg.First;
            int           nSeg    = 0;

            while (pathSeg.Next != null)
            {
                pathSeg = pathSeg.Next;
                nSeg++;
            }
            return(CreateSegmentCtl(newPathSeg));
        }
Esempio n. 14
0
 private void DisposeSegment(SMPathSegment pathSeg)
 {
     if (pathSeg != null)
     {
         string segName = BuildSegName(pathSeg);
         if (_containerPanel.Controls.ContainsKey(segName))
         {
             SegmentCtl segCtl = _containerPanel.Controls[segName] as SegmentCtl;
             _containerPanel.Controls.Remove(segCtl);
             segCtl.Dispose();
             DisposeSegment(pathSeg.Next);
         }
     }
 }
Esempio n. 15
0
 private PointF MoveSegment(SMPathSegment pathSeg, PointF startGridPt)
 {
     if (pathSeg != null)
     {
         string segName = BuildSegName(pathSeg);
         if (_containerPanel.Controls.ContainsKey(segName))
         {
             SegmentCtl segCtl    = _containerPanel.Controls[segName] as SegmentCtl;
             PointF     endGridPt = segCtl.MoveIt(startGridPt);
             return(MoveSegment(pathSeg.Next, endGridPt));
         }
     }
     return(startGridPt);
 }
Esempio n. 16
0
 private SMPathSegment GetHorizontalPathSecment(SMPathSegment endPath, eHorizontalDir horDir)
 {
     if ((horDir == eHorizontalDir.Right && !endPath.Vertical && endPath.GridDistance > 0) ||
         (horDir == eHorizontalDir.Left && !endPath.Vertical && endPath.GridDistance < 0))
     {
         return(endPath);
     }
     else if (endPath.Previous != null)
     {
         return(GetHorizontalPathSecment(endPath.Previous, horDir));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 17
0
 private SMPathSegment GetVerticalPathSecment(SMPathSegment endPath, eVerticalDir verDir)
 {
     if ((verDir == eVerticalDir.Down && endPath.Vertical && endPath.GridDistance > 0) ||
         (verDir == eVerticalDir.Up && endPath.Vertical && endPath.GridDistance < 0))
     {
         return(endPath);
     }
     else if (endPath.Previous != null)
     {
         return(GetVerticalPathSecment(endPath.Previous, verDir));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 18
0
        private void ReconnectPathLine(PointF ptGridPt, SMFlowBase targetFlow, eInsertGridMode insertMode)
        {
            switch (insertMode)
            {
            case eInsertGridMode.rowBefore:
                foreach (SMFlowBase flow in _flowContainer.ChildArray)
                {
                    if (flow.GridLoc.Y >= ptGridPt.Y)
                    {
                        continue;
                    }
                    foreach (SMPathOut pathOut in flow.PathArray)
                    {
                        if (pathOut.TargetID == targetFlow.Name)
                        {
                            SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Down);
                            if (verticalSecment != null)
                            {
                                verticalSecment.GridDistance += 1;
                            }
                        }
                    }

                    foreach (SMPathOut pathOut in targetFlow.PathArray)
                    {
                        if (pathOut.TargetID == flow.Name)
                        {
                            SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Up);
                            if (verticalSecment != null)
                            {
                                verticalSecment.GridDistance -= 1;
                            }
                        }
                    }
                }

                break;

            case eInsertGridMode.rowAfter:
                foreach (SMFlowBase flow in _flowContainer.ChildArray)
                {
                    if (flow.GridLoc.Y >= ptGridPt.Y + 1)
                    {
                        continue;
                    }
                    foreach (SMPathOut pathOut in flow.PathArray)
                    {
                        if (pathOut.TargetID == targetFlow.Name)
                        {
                            SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Down);
                            if (verticalSecment != null)
                            {
                                verticalSecment.GridDistance += 1;
                            }
                        }
                    }

                    foreach (SMPathOut pathOut in targetFlow.PathArray)
                    {
                        if (pathOut.TargetID == flow.Name)
                        {
                            SMPathSegment verticalSecment = GetVerticalPathSecment(pathOut.Last, eVerticalDir.Up);
                            if (verticalSecment != null)
                            {
                                verticalSecment.GridDistance -= 1;
                            }
                        }
                    }
                }

                break;

            case eInsertGridMode.columnBefore:
                foreach (SMFlowBase flow in _flowContainer.ChildArray)
                {
                    if (flow.GridLoc.X >= ptGridPt.X)
                    {
                        continue;
                    }
                    foreach (SMPathOut pathOut in flow.PathArray)
                    {
                        if (pathOut.TargetID == targetFlow.Name)
                        {
                            SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Right);
                            if (horizontalSecment != null)
                            {
                                horizontalSecment.GridDistance += 1;
                            }
                        }
                    }

                    foreach (SMPathOut pathOut in targetFlow.PathArray)
                    {
                        if (pathOut.TargetID == flow.Name)
                        {
                            SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Left);
                            if (horizontalSecment != null)
                            {
                                horizontalSecment.GridDistance -= 1;
                            }
                        }
                    }
                }

                break;

            case eInsertGridMode.columnAfter:
                foreach (SMFlowBase flow in _flowContainer.ChildArray)
                {
                    if (flow.GridLoc.X >= ptGridPt.X + 1)
                    {
                        continue;
                    }
                    foreach (SMPathOut pathOut in flow.PathArray)
                    {
                        if (pathOut.TargetID == targetFlow.Name)
                        {
                            SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Right);
                            if (horizontalSecment != null)
                            {
                                horizontalSecment.GridDistance += 1;
                            }
                        }
                    }

                    foreach (SMPathOut pathOut in targetFlow.PathArray)
                    {
                        if (pathOut.TargetID == flow.Name)
                        {
                            SMPathSegment horizontalSecment = GetHorizontalPathSecment(pathOut.Last, eHorizontalDir.Left);
                            if (horizontalSecment != null)
                            {
                                horizontalSecment.GridDistance -= 1;
                            }
                        }
                    }
                }

                break;

            default:
                break;
            }
        }
Esempio n. 19
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (IsDisposed)
            {
                return;
            }
            if (_newSegCtl != null)
            {
                _newSegCtl.OnMouseMove(sender, e);
                return;
            }
            if (_containerPanel.EditMode) // && object.ReferenceEquals(this, sender))
            {
                Point newMousePosition = MousePosition;
                if (e.Button != MouseButtons.Left)
                {
                    Point ptCtlLoc = PointToClient(newMousePosition);
                    // No Left button.  Not trying to drag.  Just set cursor
                    Rectangle rcEntire = new Rectangle(Point.Empty, Size);
                    if (rcEntire.Contains(ptCtlLoc))
                    {
                        _containerPanel.Cursor = Cursors.SizeAll;
                    }
                    else
                    {
                        _containerPanel.Cursor = Cursors.Default;
                    }
                }
                else
                {
                    // Get Head in panel coordinates
                    int x = newMousePosition.X - _lastMousePosition.X;
                    int y = newMousePosition.Y - _lastMousePosition.Y;
                    if (x == 0 && y == 0)
                    {
                        return;
                    }
                    // Which Drag are we trying to do?
                    bool bMovingVertical = Math.Abs(x) < Math.Abs(y);
                    bool bInLine         = bMovingVertical == Vertical;
                    switch (DragMode)
                    {
                    case eDrag.None:
                        return;

                    case eDrag.BodyClick:
                    case eDrag.HeadClick:
                    case eDrag.TailClick:
                        // Not dragging yet
                        // Have we dragged far enough
                        int totalPixDragDistance = (x * x + y * y);
                        if (totalPixDragDistance < 5 || Math.Abs(x) == Math.Abs(y))
                        {
                            // Not far enough or indeterminatant
                            return;
                        }
                        if (bInLine)
                        {
                            _segMoves = new SMPathSegment[] { _pathSeg };
                            DragMode  = eDrag.Extending;
                        }
                        break;
                    }
                    // Not in line move
                    SMPathSegment segPrevious = _pathSeg.Previous;;
                    SMPathSegment segNext     = _pathSeg.Next;;
                    switch (DragMode)
                    {
                    case  eDrag.BodyClick:
                        if (segPrevious == null)
                        {
                            DragMode = eDrag.None;
                            _flowItem.ChangeExit(FirstPathSeg, x, y);
                            _ctlBase.RebuildSegment(FirstPathSeg);
                            return;
                        }
                        _segMoves = new SMPathSegment[] { segPrevious, segNext };
                        DragMode  = eDrag.Extending;
                        break;

                    case eDrag.HeadClick:
                        if (IsLast)
                        {
                            CreateNewSegment(eDrag.Extending, x, y);
                        }
                        else
                        {
                            // Same as moving the body
                            _segMoves = new SMPathSegment[] { segPrevious, segNext };
                            DragMode  = eDrag.Extending;
                        }
                        break;

                    case eDrag.TailClick:
                        _segMoves = new SMPathSegment[] { segPrevious, segNext };
                        DragMode  = eDrag.Extending;
                        break;
                    }
                    //
                    if (DragMode == eDrag.Extending)
                    {
                        DoExtensions(x, y);
                        _lastMousePosition = newMousePosition;
                    }
                }
            }
        }
Esempio n. 20
0
        // protected virtual void RepaintPath(SMFlowBase.eDir dir)
        // {
        //     SMPathOut pathOut = _flowItem[dir];
        //     if (pathOut != null)
        //     {
        //         Repaint(pathOut);
        //     }
        // }
        //public void Repaint(SMPathOut pathOut)
        // {
        //     SMPathSegment pathSeg = pathOut;
        //     int nSeg = 0;
        //     do
        //     {
        //         SegmentCtl segCtl = GetSegmentCtl(pathSeg);
        //         if (segCtl != null)
        //         {
        //             segCtl.Refresh();
        //         }
        //         pathSeg = pathSeg.Next;
        //         nSeg++;
        //     } while(pathSeg != null);
        // }

        private string BuildSegName(SMPathSegment pathSeg)
        {
            return(string.Format("{0}-{1}-{2}", this.Name, GetSegTypeName(pathSeg), pathSeg.Index));
        }