/// <summary> /// Checks whether the current data is enough to construct a direction. If so, /// draw it. Take care to erase any previously drawn direction. /// </summary> void OnChange() { Direction dir=null; // Constructed direction. AngleDirection angle; // Angle from a backsight. DeflectionDirection deflect; // Deflection angle. BearingDirection bearing; // Bearing from north. ParallelDirection par; // Parallel to 2 points. double srad; // Signed radian value. // Apply sign to any angle we have. if (m_IsClockwise) srad = m_Radians; else srad = -m_Radians; if (m_Backsight!=null) { // If we have a backsight, we could either have a regular // angle or a deflection. To construct either, we need a // from-point as well. // Note that an angle of zero (passing through the backsight // or foresight) is fine. if (m_From!=null) { IAngle obsv = new RadianValue(srad); if (m_IsDeflection) { deflect = new DeflectionDirection(m_Backsight, m_From, obsv); dir = deflect; } else { angle = new AngleDirection(m_Backsight, m_From, obsv); dir = angle; } } } else if (m_From!=null) { // No backsight, so we could have either a bearing, // or a direction defined using 2 parallel points. // Since a bearing of zero is quite valid, we check // the dialog field to see if this is an entered value, // or just the initial value. if (m_Par1!=null && m_Par2!=null) { par = new ParallelDirection(m_From, m_Par1, m_Par2); dir = par; } else { if (m_Radians>Constants.TINY || angleTextBox.Text.Trim().Length==0) { bearing = new BearingDirection(m_From, new RadianValue(srad)); dir = bearing; } } } // If we have formed a direction, apply any offset. if (dir!=null) dir.Offset = m_Offset; // Try to calulate the position of the sideshot. IPosition to = RadialOperation.Calculate(dir, this.Length); // Return if we calculated a position that is identical to the old one. //if (to!=null && to.IsAt(m_To, Double.Epsilon)) // return; m_Dir = dir; m_To = to; m_Cmd.ErasePainting(); }
/// <summary> /// Uses the currently displayed information to try to construct a /// direction object. /// </summary> /// <returns>The constructed direction (null if a direction cannot be created /// based on the information that's currently displayed)</returns> Direction GetCurrentDirection() { Direction result = null; // Get signed direction double srad = (m_IsClockwise ? m_Radians : -m_Radians); IAngle dir = new RadianValue(srad); if (m_Backsight!=null) { // If we have a backsight, we could either have a regular // angle or a deflection. To construct either, we need a // from-point as well. // Note that an angle of zero (passing through the backsight // or foresight) is fine. if (m_From!=null) { if (m_IsDeflection) result = new DeflectionDirection(m_Backsight, m_From, dir); else result = new AngleDirection(m_Backsight, m_From, dir); } } else if (m_From!=null) { // No backsight, so we could have either a bearing, // or a direction defined using 2 parallel points. // Since a bearing of zero is quite valid, we check // the dialog field to see if this is an entered value, // or just the initial value. if (m_Par1!=null && m_Par2!=null) result = new ParallelDirection(m_From, m_Par1, m_Par2); else if (m_Radians > Constants.TINY || directionTextBox.Text.Length>0) result = new BearingDirection(m_From, dir); } // If we haven't formed a direction, ignore any offset if (result==null) return null; // An offset could have been specified by a point, or by // entering a distance left or right of the direction. Offset offset = null; if (m_OffsetPoint!=null) offset = new OffsetPoint(m_OffsetPoint); else if (m_OffsetDistance!=null) offset = new OffsetDistance(m_OffsetDistance, !m_IsRight); // If we got an offset, include it in the direction. if (offset!=null) result.Offset = offset; return result; }