Esempio n. 1
0
        internal LineSubdivisionControl(LineSubdivisionUI cmd, LineFeature line, Operation recall)
        {
            InitializeComponent();

            // Remember the command.
            m_Cmd = cmd;

            // Remember the line involved & its length (in meters)
            m_Line         = line;
            m_GroundLength = line.GroundLength.Meters;

            // No distances so far.
            m_Distances = null;
            m_FromStart = true;

            // If we are recalling a previous operation, grab the observed distances from there (only the primary face)
            LineSubdivisionOperation op = (recall as LineSubdivisionOperation);

            if (op != null)
            {
                LineFeature[] sections = op.Face.Sections;
                m_Distances = new List <Distance>(sections.Length);
                foreach (LineFeature s in sections)
                {
                    m_Distances.Add(new Distance(s.ObservedLength));
                }
            }
        }
        private void LineSubdivisionUpdateForm_Shown(object sender, EventArgs e)
        {
            // Get the object that was selected for update.
            Feature feat = m_UpdCmd.GetUpdate();

            if (feat == null)
            {
                throw new InvalidOperationException("Unexpected update object");
            }

            // Get the edit that created the primary face
            m_pop = (feat.Creator as LineSubdivisionOperation);
            Debug.Assert(m_pop != null);

            if (!m_pop.IsPrimaryFace)
            {
                m_pop = m_pop.OtherSide;
                Debug.Assert(m_pop != null);
                Debug.Assert(m_pop.IsPrimaryFace);
            }

            // Grab something we throw away if the user decides to cancel
            m_Face1 = CreateWorkingFace(m_pop.Face, true);
            m_Face2 = (m_pop.OtherSide == null ? null : CreateWorkingFace(m_pop.OtherSide.Face, false));

            // If we have two faces, the "New Face" button means you want to switch to the other face.
            if (m_Face2 != null)
            {
                newFaceButton.Text = "&Other Face";
            }

            // Default to the face containing the initially selected feature
            m_CurrentFace = (feat.Creator == m_pop ? m_Face1 : m_Face2);

            // If a line was selected, remember where it is in our working copy (and if it's actually on
            // the alternate face, make that the initial face for editing).
            m_SelectedLine = null;
            LineFeature selectedLine = (feat as LineFeature);

            if (selectedLine != null)
            {
                LineFeature[] sections  = (m_CurrentFace == m_Face1 ? m_pop.Face.Sections : m_pop.OtherSide.Face.Sections);
                int           lineIndex = Array.FindIndex <LineFeature>(sections, t => t == selectedLine);

                if (lineIndex >= 0)
                {
                    m_SelectedLine = m_CurrentFace.Sections[lineIndex];
                }
            }

            // Disable the option to flip annotation if annotation is currently invisible
            if (!EditingController.Current.AreLineAnnotationsDrawn)
            {
                flipDistButton.Enabled = false;
            }

            // Reload the list and repaint
            RefreshList();
        }
Esempio n. 3
0
        /// <summary>
        /// Saves a new edit that defines an alternate face for a previously subdivided line.
        /// </summary>
        /// <param name="firstSide">The edit that initially subdivided the line.</param>
        /// <param name="altFace">The definition of the alternate face</param>
        void AddOtherSide(LineSubdivisionOperation firstSide, LineSubdivisionFace altFace)
        {
            try
            {
                LineSubdivisionOperation op = new LineSubdivisionOperation(firstSide.Parent, altFace.ObservedLengths, altFace.IsEntryFromEnd);
                op.OtherSide = firstSide;
                op.Execute();
                firstSide.OtherSide = op;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
Esempio n. 4
0
        internal void Save()
        {
            // Return if we do not have at least 2 distances
            if (m_Distances.Count < 2)
            {
                MessageBox.Show("At least two distances must be specified.");
                return;
            }

            // Subdivide the line...
            LineSubdivisionOperation op = null;

            try
            {
                Distance[] distances = GetDistances();
                op = new LineSubdivisionOperation(m_Line, distances, !m_FromStart);
                op.Execute();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
Esempio n. 5
0
        internal override bool DialFinish(Control wnd)
        {
            if (m_Dialog == null && m_UpDial == null)
            {
                throw new Exception("LineSubdivisionUI.DialFinish - No dialog!");
            }

            UpdateUI up      = this.Update;
            bool     doAbort = false;

            if (up != null)
            {
                // Get the original operation.
                LineSubdivisionOperation pop = (up.GetOp() as LineSubdivisionOperation);
                if (pop == null)
                {
                    MessageBox.Show("LineSubdivisionUI.DialFinish - Unexpected edit type.");
                    return(false);
                }

                // Ensure we've got the edit for the primary face
                if (!pop.IsPrimaryFace)
                {
                    pop = pop.OtherSide;
                    Debug.Assert(pop != null);
                    Debug.Assert(pop.IsPrimaryFace);
                }

                // Package up any changes to the primary face
                UpdateItemCollection changes = pop.GetUpdateItems(m_UpDial.WorkingFace1);
                if (changes.Count > 0)
                {
                    up.AddUpdate(pop, changes);
                }

                // If a second face has just been defined, append a new edit.
                LineSubdivisionFace face2 = m_UpDial.WorkingFace2;
                if (face2 != null)
                {
                    if (pop.OtherSide == null)
                    {
                        AddOtherSide(pop, face2);
                    }
                    else
                    {
                        changes = pop.OtherSide.GetUpdateItems(face2);
                        if (changes.Count > 0)
                        {
                            up.AddUpdate(pop.OtherSide, changes);
                        }
                    }
                }

                // If all we've done is add a new face, UpdateUI.AddUpdate wouldn't have been
                // called, which will later lead to an exception from UpdateUI.FinishCommand (via
                // the FinishCommand done below). So remember to abort in that case.
                doAbort = (up.HasRevisions == false);
            }
            else
            {
                // Ensure that the parent line has been de-selected by the view.
                Controller.ClearSelection();

                // Get the dialog to save.
                m_Dialog.Save();
            }

            // Destroy the dialog(s).
            KillDialogs();

            // Get the base class to finish up.
            if (doAbort)
            {
                return(AbortCommand());
            }
            else
            {
                return(FinishCommand());
            }
        }