/// <summary> /// Sets flag bit(s) /// </summary> /// <param name="flag">The flag bit(s) to set</param> /// <param name="setting">True to set, false to clear</param> void SetFlag(LegItemFlag flag, bool setting) { if (setting) { m_Switches |= flag; } else { m_Switches &= (~flag); } }
/// <summary> /// Sets the distance of a specific span in this face. /// </summary> /// <param name="distance">The distance to assign.</param> /// <param name="index">The index of the distance [0,NumSpan-1]</param> /// <param name="qualifier"></param> /// <returns>True if index was valid.</returns> internal bool SetDistance(Distance distance, int index, LegItemFlag qualifier) { // Return if index is out of range. if (index < 0 || index >= NumSpan) { return(false); } // Remember any qualifier. if (qualifier != 0) { m_Spans[index].Flags |= qualifier; } // Assign the distance m_Spans[index].ObservedDistance = distance; return(true); }
/// <summary> /// Sets the distance of a specific span in this face. /// </summary> /// <param name="distance">The distance to assign.</param> /// <param name="index">The index of the distance [0,NumSpan-1]</param> /// <param name="qualifier"></param> /// <returns>True if index was valid.</returns> internal bool SetDistance(Distance distance, int index, LegItemFlag qualifier) { // Return if index is out of range. if (index < 0 || index >= NumSpan) return false; // Remember any qualifier. if (qualifier != 0) m_Spans[index].Flags |= qualifier; // Assign the distance m_Spans[index].ObservedDistance = distance; return true; }
/// <summary> /// Creates a straight leg. /// </summary> /// <param name="items">Array of path items.</param> /// <param name="si">Index to the item where the leg data starts.</param> /// <param name="nexti">Index of the item where the next leg starts.</param> /// <returns>The new leg.</returns> static StraightLeg CreateStraightLeg(PathItem[] items, int si, out int nexti) { // Get the leg ID. int legnum = items[si].LegNumber; // How many distances have we got? int ndist = 0; for (nexti = si; nexti < items.Length && items[nexti].LegNumber == legnum; nexti++) { if (items[nexti].IsDistance) { ndist++; } } // Create the leg. StraightLeg leg = new StraightLeg(ndist); // Assign each distance. ndist = 0; for (int i = si; i < nexti; i++) { Distance d = items[i].GetDistance(); if (d != null) { // See if there is a qualifier after the distance LegItemFlag qual = LegItemFlag.Null; if ((i + 1) < nexti) { PathItemType nexttype = items[i + 1].ItemType; if (nexttype == PathItemType.MissConnect) { qual = LegItemFlag.MissConnect; } if (nexttype == PathItemType.OmitPoint) { qual = LegItemFlag.OmitPoint; } } leg.PrimaryFace.SetDistance(d, ndist, qual); ndist++; } } // If the first item is an angle, remember it as part of the leg. if (items[si].ItemType == PathItemType.Angle) { leg.StartAngle = items[si].Value; } else if (items[si].ItemType == PathItemType.Deflection) { leg.SetDeflection(items[si].Value); } // Return a reference to the new leg return(leg); }
/// <summary> /// Creates a circular leg. /// </summary> /// <param name="items">Array of path items.</param> /// <param name="si">Index to the item where the leg data starts.</param> /// <param name="nexti">Index of the item where the next leg starts.</param> /// <returns>The new leg.</returns> static CircularLeg CreateCircularLeg(PathItem[] items, int si, out int nexti) { // Confirm that the first item refers to the BC. if (items[si].ItemType != PathItemType.BC) { throw new Exception("PathParser.CreateCircularLeg - Not starting at BC"); } // The BC has to be followed by at least 3 items: angle, radius // and EC (add an extra 1 to account for 0-based indexing). if (items.Length < si + 4) { throw new Exception("PathParser.CreateCircularLeg - Insufficient curve data"); } double bangle = 0.0; // Angle at BC double cangle = 0.0; // Central angle double eangle = 0.0; // Angle at EC bool twoangles = false; // True if bangle & eangle are both defined. bool clockwise = true; // True if curve is clockwise int irad = 0; // Index of the radius item bool cul = false; // True if cul-de-sac case // Point to item following the BC. nexti = si + 1; PathItemType type = items[nexti].ItemType; // If the angle following the BC is a central angle if (type == PathItemType.CentralAngle) { // We have a cul-de-sac cul = true; // Get the central angle. cangle = items[nexti].Value; nexti++; } else if (type == PathItemType.BcAngle) { // Get the entry angle. bangle = items[nexti].Value; nexti++; // Does an exit angle follow? if (items[nexti].ItemType == PathItemType.EcAngle) { eangle = items[nexti].Value; twoangles = true; nexti++; } } else { // The field after the BC HAS to be an angle. throw new ApplicationException("Angle does not follow BC"); } // Must be followed by radius. if (items[nexti].ItemType != PathItemType.Radius) { throw new ApplicationException("Radius does not follow angle"); } // Get the radius Distance radius = items[nexti].GetDistance(); irad = nexti; nexti++; // The item after the radius indicates whether the curve is counterclockwise. if (items[nexti].ItemType == PathItemType.CounterClockwise) { nexti++; clockwise = false; } // Get the leg ID. int legnum = items[si].LegNumber; // How many distances have we got? int ndist = 0; for (; nexti < items.Length && items[nexti].LegNumber == legnum; nexti++) { if (items[nexti].IsDistance) { ndist++; } } // Create the leg. CircularLeg leg = new CircularLeg(radius, clockwise, ndist); CircularLegMetrics metrics = leg.Metrics; // Set the entry angle or the central angle, depending on what we have. if (cul) { metrics.SetCentralAngle(cangle); } else { metrics.SetEntryAngle(bangle); } // Assign second angle if we have one. if (twoangles) { metrics.SetExitAngle(eangle); } // Assign each distance, starting one after the radius. ndist = 0; for (int i = irad + 1; i < nexti; i++) { Distance dist = items[i].GetDistance(); if (dist != null) { // See if there is a qualifier after the distance LegItemFlag qual = LegItemFlag.Null; if (i + 1 < nexti) { PathItemType nexttype = items[i + 1].ItemType; if (nexttype == PathItemType.MissConnect) { qual = LegItemFlag.MissConnect; } if (nexttype == PathItemType.OmitPoint) { qual = LegItemFlag.OmitPoint; } } leg.PrimaryFace.SetDistance(dist, ndist, qual); ndist++; } } // Return the new leg. return(leg); }
/// <summary> /// Creates new <c>SpanInfo</c> with everything set to null. /// </summary> internal SpanInfo() { m_Distance = null; m_Feature = null; m_Switches = LegItemFlag.Null; }