private void updateButton_Click(object sender, EventArgs e) { // Get the selected distance. Distance d = GetSel(); if (d == null) { MessageBox.Show("You must first select a distance from the list."); return; } Distance dCopy = new Distance(d); using (DistForm dist = new DistForm(dCopy, false)) { if (dist.ShowDialog(this) == DialogResult.OK) { // Change the distance stored in the leg LegFace face = this.CurrentFace; int spanIndex = distancesListBox.SelectedIndex; SpanInfo spanInfo = face.GetSpanData(spanIndex); spanInfo.ObservedDistance = dist.Distance; // Change the displayed distance distancesListBox.Items[spanIndex] = spanInfo.ObservedDistance; m_Edits.UpdateSpan(m_CurFaceIndex, spanIndex, dist.Distance); Rework(); Refresh(spanIndex); } } }
private void insertButton_Click(object sender, EventArgs e) { LegFace face = CurrentFace; if (face == null) { return; } Distance dist = GetSel(); if (dist == null) { MessageBox.Show("You must first select a distance from the list."); return; } // Are we inserting before or after the currently selected distance? bool isBefore = insBeforeRadioButton.Checked; // Get the user to specify a new distance. using (var dial = new DistForm(dist, false)) { if (dial.ShowDialog() == DialogResult.OK) { // Insert the new distance into the current leg. Distance newDist = dial.Distance; m_Edits.InsertSpan(m_CurFaceIndex, newDist, dist, isBefore); int index = face.Insert(newDist, dist, isBefore, true); Rework(); Refresh(index); } } }
/// <summary> /// Prepares the legs on this path by allocating a unique ID to each primary face (and /// ensure that the primary face is cross-referenced to it's associated leg). /// </summary> /// <param name="opSequence">The sequence of the edit that created the legs.</param> /// <param name="legs">The legs involved (with only primary faces attached).</param> /// <returns>The last internal ID that was reserved.</returns> static uint PrepareLegs(uint opSequence, Leg[] legs) { // Allocate sequence numbers for each leg + primary face uint nextId = opSequence; foreach (Leg leg in legs) { // Reserve an ID for the leg itself (used for center point if the leg // is a circular arc). nextId++; // We should only be dealing with the primary face (alternate face comes via update, // or via deserialization of data that originated from the CEdit application). Debug.Assert(leg.AlternateFace == null); // Allocate a sequence number for the face LegFace face = leg.PrimaryFace; nextId++; face.Sequence = new InternalIdValue(nextId); // Reserve two IDs for every span (regardless of whether any feature will be created for it). nextId += ((uint)face.NumSpan * 2); // Ensure the face has been cross-referenced to the associated leg face.Leg = leg; } return(nextId); }
private void newFaceButton_Click(object sender, EventArgs e) { LegFace face = CurrentFace; if (face == null) { return; } // Get the observed length of the leg (in meters on the ground). double len = face.GetTotal(); try { this.WindowState = FormWindowState.Minimized; // Present a data entry dialog for the new face. using (LegForm dial = new LegForm(len)) { if (dial.ShowDialog() != DialogResult.OK) { return; } // Create the new face and insert it after the current leg. // Must be at least two distances Distance[] dists = dial.Distances; if (dists == null || dists.Length < 2) { MessageBox.Show("The new face must have at least two spans"); return; } // Default annotations to the flip side foreach (Distance d in dists) { d.IsAnnotationFlipped = true; } // Attach the new face to the leg var newFace = new LegFace(face.Leg, dists); // Insert the new face into our array of faces. int faceIndex = m_Faces.IndexOf(face); m_Faces.Insert(faceIndex + 1, newFace); // Make the new face the current leg, and select the very first distance. SetCurrentFace(m_CurFaceIndex + 1); Refresh(0); } } finally { this.WindowState = FormWindowState.Normal; } }
/* * /// <summary> * /// Ensures a point feature exists at a specific location in the map model. * /// </summary> * /// <param name="p">The position where a point feature is required</param> * /// <param name="extraPoints">Any extra points that should be considered. This should be * /// loaded with any points that have been freshly created by this editing operation (since * /// these new points will not exist in the map model until the edit commits)</param> * /// <returns>The point feature at the specified position (may be a new point)</returns> * internal PointFeature EnsurePointExists(IPosition p, List<PointFeature> extraPoints) * { * // First check for the obvious * if (p is PointFeature) * return (p as PointFeature); * * // Ensure the supplied position has been rounded to internal resolution * IPointGeometry pg = PointGeometry.Create(p); * * // First check the list of extra points * foreach (PointFeature x in extraPoints) * { * if (x.IsCoincident(pg)) * return x; * } * * // Get the map model to create an extra point if necessary * PointFeature result = MapModel.EnsurePointExists(pg, this); * * // If the points was freshly created, assign an ID and add to the list of extra points * if (Object.ReferenceEquals(result.Creator, this)) * { * if (result.FeatureId==null) * result.SetNextId(); * * extraPoints.Add(result); * } * * return result; * } */ /* * /// <summary> * /// Returns adjustment parameters (the bare bones). * /// </summary> * /// <param name="rotation">The rotation to apply.</param> * /// <param name="sfac">The scale factor to apply.</param> * /// <returns></returns> * bool GetAdjustment(out double rotation, out double sfac) * { * PathInfo pd = new PathInfo(this); * * double dN; // Misclosure in northings * double dE; // Misclosure in eastings * double precision; // Precision denominator * double length; // Total observed length * * return pd.Adjust(out dN, out dE, out precision, out length, out rotation, out sfac); * } */ /* * /// <summary> * /// Returns the total number of observed spans for this connection path. * /// </summary> * /// <returns>The total number of observed spans for this connection path.</returns> * int GetCount() * { * // Accumulate the number of spans in each leg. Treat cul-de-sacs * // with no observed spans as a count of 1 (although there is no * // observation, a feature is still created for it). * * int tot = 0; * * foreach (Leg leg in m_Legs) * { * int nspan = Math.Max(1, leg.Count); * tot += nspan; * } * * return tot; * } */ /* * // @mfunc Draw observed angles recorded as part of this op. * // * // @parm The point the observation must be made from. * // Specify 0 for all points. * // @parm The view to draw in. * // @parm Display context for the draw. * // @parm The ground window for the draw (0 for no check). * // * ////////////////////////////////////////////////////////////////////// * * void CePath::DrawAngles ( const CePoint* const pFrom * , CeView* view * , CDC* pDC * , const CeWindow* const pWin ) const { * * // If a from-point has been specified, it must be a point * // that was created by this path (you can't start a path * // off with an angle, so the angle in question would have * // to be some interior angle). * if ( pFrom && pFrom->GetpCreator()!=(CeOperation*)this ) return; * * // Skip this op if it has an update. * if ( this->GetpLatest() ) return; * * // Get the rotation & scale factor that was applied to * // this path. * FLOAT8 rotation; * FLOAT8 sfac; * GetAdjustment( rotation, sfac ); * * // Initial bearing is whatever the rotation was. * FLOAT8 bearing = rotation; * * // The first leg does not have a backsight. We pass down * // vertices to each leg because the leg may contain empty * // spans (i.e. with neither an arc or a point feature). * * CeVertex bs; * CeVertex from(*m_pFrom); * CeVertex to; * * // Get each leg to draw its angles. * for ( UINT2 i=0; i<m_NumLeg; i++ ) { * m_pLegs[i]->DrawAngles(pFrom,*this,sfac,bs,from,bearing,to,view,pDC,pWin); * bs = from; * from = to; * } * * } // end of DrawAngles * * ////////////////////////////////////////////////////////////////////// * // * // @mfunc Draw observed angles recorded as part of this op. * // * // @parm The point the observation must be made from. * // Specify 0 for all points. * // @parm The thing we're drawing to. * // * ////////////////////////////////////////////////////////////////////// * * void CePath::DrawAngles ( const CePoint* const pFrom * , CeDC& gdc ) const { * * // If a from-point has been specified, it must be a point * // that was created by this path (you can't start a path * // off with an angle, so the angle in question would have * // to be some interior angle). * if ( pFrom && pFrom->GetpCreator()!=(CeOperation*)this ) return; * * // Skip this op if it has an update. * if ( this->GetpLatest() ) return; * * // Get the rotation & scale factor that was applied to * // this path. * FLOAT8 rotation; * FLOAT8 sfac; * GetAdjustment( rotation, sfac ); * * // Initial bearing is whatever the rotation was. * FLOAT8 bearing = rotation; * * // The first leg does not have a backsight. We pass down * // vertices to each leg because the leg may contain empty * // spans (i.e. with neither an arc or a point feature). * * CeVertex bs; * CeVertex from(*m_pFrom); * CeVertex to; * * // Get each leg to draw its angles. * for ( UINT2 i=0; i<m_NumLeg; i++ ) { * m_pLegs[i]->DrawAngles(pFrom,*this,sfac,bs,from,bearing,to,gdc); * bs = from; * from = to; * } * * } // end of DrawAngles */ /// <summary> /// Returns the definition of the leg face which created a specific feature. /// </summary> /// <param name="feature">The feature to find.</param> /// <returns>The face that created the feature (or null if the face /// could not be found).</returns> internal LegFace GetLegFace(Feature feature) { foreach (Leg leg in m_Legs) { LegFace face = leg.PrimaryFace; if (face.IsCreatorOf(feature)) { return(face); } face = leg.AlternateFace; if (face.IsCreatorOf(feature)) { return(face); } } return(null); }
private void flipDistButton_Click(object sender, EventArgs e) { LegFace face = CurrentFace; if (face == null) { return; } m_Edits.FlipLegAnnotations(m_CurFaceIndex); foreach (SpanInfo span in face.Spans) { if (span.HasLine) { span.ObservedDistance.ToggleIsFlipped(); } } m_UpdCmd.ErasePainting(); }
private void UpdatePathForm_Shown(object sender, EventArgs e) { // Initialize radio buttons. insBeforeRadioButton.Checked = true; brkBeforeRadioButton.Checked = true; // Only let the user flip annotations if they're currently visible flipDistButton.Enabled = EditingController.Current.AreLineAnnotationsDrawn; // Display the precision of the connection path. PathInfo p = new PathInfo(m_pop.StartPoint, m_pop.EndPoint, GetLegs()); ShowPrecision(p); // A feature on the connection path should have been selected - determine which leg face it's part of LegFace face = null; Feature f = m_UpdCmd.GetUpdate(); if (f != null) { face = m_pop.GetLegFace(f); int faceIndex = GetFaceIndex(face.Sequence); SetCurrentFace(faceIndex); } if (m_CurFaceIndex < 0) { SetCurrentFace(0); } if (face == null) { Refresh(-1); } else { Refresh(face.GetIndex(f)); } }
/// <summary> /// Refreshes the display upon selection of a specific observed distance. /// </summary> /// <param name="index">The array index of the currently selected distance (-1 if nothing is /// currently selected).</param> void Refresh(int index) { if (m_CurFaceIndex < 0 || m_CurFaceIndex >= NumFace) { return; } this.Text = String.Format("Leg {0} of {1}", m_CurFaceIndex + 1, NumFace); // Enable the back/next buttons, depending on what leg we're on. previousButton.Enabled = (m_CurFaceIndex > 0); nextButton.Enabled = (m_CurFaceIndex + 1 < NumFace); // Get the corresponding face. LegFace face = CurrentFace; Leg leg = face.Leg; // If it's a curve, enable the circular arc button and disable the angle & break buttons. if (leg is CircularLeg) { curveButton.Enabled = true; angleButton.Enabled = false; breakButton.Enabled = false; } else { curveButton.Enabled = false; // You can break a straight leg so long as it has not been staggered. breakButton.Enabled = (leg.IsStaggered == false); // Enable the angle button so long as the preceding leg exists, and is also a straight leg. bool isPrevStraight = false; if (m_CurFaceIndex > 0 && m_Faces[m_CurFaceIndex - 1].Leg is StraightLeg) { isPrevStraight = true; } angleButton.Enabled = isPrevStraight; } // You can't create a new face if the leg is already staggered. newFaceButton.Enabled = (leg.IsStaggered == false); // Indicate whether we're on the second face secondFaceLabel.Visible = (face == leg.AlternateFace); // List the observed distances for the leg. distancesListBox.Items.Clear(); if (face.Count == 0) { distancesListBox.Items.Add("see central angle"); distancesListBox.SelectedIndex = 0; } else { Distance[] dists = face.GetObservedDistances(); distancesListBox.Items.AddRange(dists); // Select the first (or last) item in the list. if (index < 0) { distancesListBox.SelectedIndex = dists.Length - 1; } else if (index < dists.Length) { distancesListBox.SelectedIndex = index; } } // Always leave the focus in the list of distances. distancesListBox.Focus(); }
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); }
private void newFaceButton_Click(object sender, EventArgs e) { LegFace face = CurrentFace; if (face == null) return; // Get the observed length of the leg (in meters on the ground). double len = face.GetTotal(); try { this.WindowState = FormWindowState.Minimized; // Present a data entry dialog for the new face. using (LegForm dial = new LegForm(len)) { if (dial.ShowDialog() != DialogResult.OK) return; // Create the new face and insert it after the current leg. // Must be at least two distances Distance[] dists = dial.Distances; if (dists == null || dists.Length < 2) { MessageBox.Show("The new face must have at least two spans"); return; } // Default annotations to the flip side foreach (Distance d in dists) d.IsAnnotationFlipped = true; // Attach the new face to the leg var newFace = new LegFace(face.Leg, dists); // Insert the new face into our array of faces. int faceIndex = m_Faces.IndexOf(face); m_Faces.Insert(faceIndex + 1, newFace); // Make the new face the current leg, and select the very first distance. SetCurrentFace(m_CurFaceIndex + 1); Refresh(0); } } finally { this.WindowState = FormWindowState.Normal; } }