예제 #1
0
        private void breakButton_Click(object sender, EventArgs e)
        {
            LegFace     face = this.CurrentFace;
            StraightLeg leg  = (face.Leg as StraightLeg);

            if (leg == null)
            {
                return;
            }

            // You can't break a staggered leg (this should have already been trapped by disabling the button).
            if (leg.IsStaggered)
            {
                MessageBox.Show("You cannot break a staggered leg.");
                return;
            }

            // Get the selected distance
            Distance dist = GetSel();

            if (dist == null)
            {
                MessageBox.Show("You must first select a distance from the list.");
                return;
            }

            // Are we breaking before or after the currently selected distance?
            bool isBefore = brkBeforeRadioButton.Checked;

            // You can't break at the very beginning or end of the leg.
            int index = leg.PrimaryFace.GetIndex(dist);

            if (isBefore && index == 0)
            {
                MessageBox.Show("You can't break at the very beginning of the leg.");
                return;
            }

            if (!isBefore && (index + 1) == face.Count)
            {
                MessageBox.Show("You can't break at the very end of the leg.");
                return;
            }

            // Break the leg.
            if (!isBefore)
            {
                index++;
            }

            m_Edits.BreakLeg(m_CurFaceIndex, index);

            StraightLeg newLeg = leg.Break(index);

            if (newLeg == null)
            {
                return;
            }

            // Make the new leg the current one, and select the very first distance.
            int faceIndex = m_Faces.IndexOf(face);

            Debug.Assert(faceIndex >= 0);
            m_Faces.Insert(faceIndex + 1, newLeg.PrimaryFace);
            SetCurrentFace(faceIndex + 1);
            Refresh(0);
        }