public void SelectUSegment(System.Drawing.Point mousePosition)
{
for (int i = 0; i < m_uSegLinePathListList.Count; i++)
{
GridLine2D gridLine2D = m_uGridLines2D[i];
List<GraphicsPath> pathList = m_uSegLinePathListList[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_uGridLines2D[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_selectedUIndex = i;
m_selectedUSegmentIndex = 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();
m_selectedUIndex = -1;
m_selectedUSegmentIndex = -1;
// update the hints
{
string msg = "Select a segment";
KeyValuePair<string, bool> statusMsg = new KeyValuePair<string, bool>(msg, false);
m_myDocument.Message = statusMsg;
}
}