Revit.SDK.Samples.CurtainWallGrid.CS.GridDrawing.SelectVSegment C# (CSharp) Method

SelectVSegment() public method

pick up a segment of a V grid line
public SelectVSegment ( System mousePosition ) : void
mousePosition System /// the location of the mouse cursor ///
return void
        public void SelectVSegment(System.Drawing.Point mousePosition)
        {
            for (int i = 0; i < m_vSegLinePathListList.Count; i++)
             {
            GridLine2D gridLine2D = m_vGridLines2D[i];
            List<GraphicsPath> pathList = m_vSegLinePathListList[i];
            Pen redPen = new Pen(System.Drawing.Color.Red, m_outlineSelectPenWidth);

            // find out which segment it's on and which grid line does the segment belong to
            for (int j = 0; j < pathList.Count; j++)
            {
               SegmentLine2D segLine2D = m_vGridLines2D[i].Segments[j];
               GraphicsPath path = pathList[j];

               if (path.IsOutlineVisible(mousePosition, redPen))
               {
                  if (LineOperationType.AddSegment == m_myDocument.ActiveOperation.OpType)
                  {
                     // the operation is add segment, but the selected segment hasn't been removed
                     // so skip this segment
                     if (false == segLine2D.Removed)
                     {
                        string msg = "It's only allowed to add segment on a removed segment";
                        KeyValuePair<string, bool> statusMsg = new KeyValuePair<string, bool>(msg, true);
                        m_myDocument.Message = statusMsg;
                        return;
                     }
                  }
                  else if (LineOperationType.RemoveSegment == m_myDocument.ActiveOperation.OpType)
                  {
                     // the operation is remove segment, but the selected segment has been removed
                     // so skip this segment
                     if (true == segLine2D.Removed)
                     {
                        return;
                     }
                     // if there's only segment existing, forbid to delete it
                     if (gridLine2D.RemovedNumber == gridLine2D.Segments.Count - 1)
                     {
                        string msg = "It's not allowed to delete the last segment";
                        KeyValuePair<string, bool> statusMsg = new KeyValuePair<string, bool>(msg, true);
                        m_myDocument.Message = statusMsg;
                        return;
                     }
                  }

                  m_selectedVIndex = i;
                  m_selectedVSegmentIndex = j;
                  m_drawObject = new DrawObject(segLine2D, new Pen(System.Drawing.Color.Red, m_selectedSegmentPenWidth));

                  // update the status strip hint
                  {
                     string msg = "Left-click to finish the operation";
                     KeyValuePair<string, bool> statusMsg = new KeyValuePair<string, bool>(msg, false);
                     m_myDocument.Message = statusMsg;
                  }
                  return;
               }
            }
             }

             m_drawObject.Clear();
             // selection failed
             m_selectedVIndex = -1;
             m_selectedVSegmentIndex = -1;
             // update the status hint
             {
            string msg = "Select a segment";
            KeyValuePair<string, bool> statusMsg = new KeyValuePair<string, bool>(msg, false);
            m_myDocument.Message = statusMsg;
             }
        }