using System; namespace Netron.Diagramming.Core.Layout.Force { /// ///Abstract base class for force functions in a force simulation. This ///skeletal version provides support for storing and retrieving float-valued ///parameters of the force function. Subclasses should use the protected ///field parms to store parameter values. /// public abstract class AbstractForce : IForce { #region Fields /// /// temporary paramters blobs /// protected float[] parms; /// /// min values /// protected float[] minValues; /// /// max values /// protected float[] maxValues; #endregion #region Properties /// ///Returns false. /// public virtual bool IsSpringForce { get { return false; } } /// /// Returns the number of parameters (e.g., gravitational constant or /// spring force coefficient) affecting this force function. /// /// /// the number of parameters public int ParameterCount { get { return (parms == null ? 0 : parms.Length); } } /// ///Gets whether this is a force. /// public virtual bool IsItemForce { get { return false; } } #endregion #region Methods /// /// Initialize this force function. This default implementation does nothing. /// Subclasses should override this method with any needed initialization. /// /// the encompassing ForceSimulator public virtual void Init(ForceSimulator fsim) { // do nothing. } /// /// Gets the parameter names. /// /// protected abstract String[] ParameterNames { get; } /// /// Returns the specified, numbered parameter. /// /// i the index of the parameter to return /// the parameter value public float GetParameter(int i) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { return parms[i]; } } /// /// Gets the minimum value. /// /// The i. /// public float GetMinValue(int i) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { return minValues[i]; } } /// /// Gets the maximum value. /// /// The i. /// public float GetMaxValue(int i) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { return maxValues[i]; } } /// /// Gets the text name of the requested parameter. /// /// i the index of the parameter /// /// a String containing the name of this parameter /// public String GetParameterName(int i) { String[] pnames = this.ParameterNames; if (i < 0 || pnames == null || i >= pnames.Length) { throw new ArgumentOutOfRangeException(); } else { return pnames[i]; } } /// /// Sets the specified parameter value. /// /// the index of the parameter /// the new value of the parameter public void SetParameter(int i, float val) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { parms[i] = val; } } /// /// Set the suggested minimum value for a parameter. This value is not /// strictly enforced, but is used by interface components that allow force /// parameters to be varied. /// /// the parameter index /// the suggested minimum value to use public void SetMinValue(int i, float val) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { minValues[i] = val; } } /// /// Set the suggested maximum value for a parameter. This value is not /// strictly enforced, but is used by interface components that allow force /// parameters to be varied. /// /// the parameter index /// the suggested maximum value to use public void SetMaxValue(int i, float val) { if (i < 0 || parms == null || i >= parms.Length) { throw new ArgumentOutOfRangeException(); } else { maxValues[i] = val; } } /// ///Returns the force acting on the given item. /// public virtual void GetForce(ForceItem item) { throw new NotImplementedException("This class does not support this operation"); } /// /// Updates the force calculation on the given Spring. The ForceItems /// attached to Spring will have their force values updated appropriately. /// /// spring the Spring on which to compute updated forces public virtual void GetForce(Spring spring) { throw new NotImplementedException("This class does not support this operation"); } #endregion } }