PurplePen.EventDB.AddLeg C# (CSharp) Method

AddLeg() public method

public AddLeg ( Leg leg ) : Id
leg Leg
return Id
        public Id<Leg> AddLeg(Leg leg)
        {
            return legStore.Add(leg);
        }

Usage Example

Example #1
0
        // Change the flagging associated with a leg. If changing to Begin/End flagging, then a bend will be introduced if no bends currently exist
        // in the leg. If the leg ends in the finish, the finish symbol may be changed to match if appropriate.
        public static void ChangeFlagging(EventDB eventDB, Id<ControlPoint> controlId1, Id<ControlPoint> controlId2, FlaggingKind flagging)
        {
            ControlPoint control1 = eventDB.GetControl(controlId1);
            ControlPoint control2 = eventDB.GetControl(controlId2);

            if (control2.kind == ControlPointKind.Finish && flagging == FlaggingKind.All) {
                // If the leg ends in the finish control, we can set all flagging by just changing the finish control symbol.
                ChangeDescriptionSymbol(eventDB, controlId2, 0, "14.1");
                return;
            }

            // We need a leg object. Create a new one or get the existing one.
            Id<Leg> legId = QueryEvent.FindLeg(eventDB, controlId1, controlId2);
            Leg leg;
            if (legId.IsNone)
                leg = new Leg(controlId1, controlId2);
            else
                leg = (Leg) eventDB.GetLeg(legId).Clone();

            // Set the flagging kind.
            leg.flagging = flagging;

            if (flagging == FlaggingKind.Begin || flagging == FlaggingKind.End) {
                // These kinds of flagging require a bend in the flaggingStartStop field.
                if (leg.bends != null && leg.bends.Length > 0) {
                    // Already have a bend we can use.
                    leg.flagStartStop = (flagging == FlaggingKind.Begin) ? leg.bends[leg.bends.Length - 1] : leg.bends[0];
                }
                else {
                    // Create a bend half-way along the leg.
                    leg.flagStartStop = new PointF((control1.location.X + control2.location.X) / 2, (control1.location.Y + control2.location.Y) / 2);
                    leg.bends = new PointF[] { leg.flagStartStop };
                }
            }

            // Update the leg object.
            if (legId.IsNone)
                eventDB.AddLeg(leg);
            else {
                if (leg.IsVacuous())
                    eventDB.RemoveLeg(legId);
                else
                    eventDB.ReplaceLeg(legId, leg);
            }

            // Update the finish control symbol if reasonable.
            if (control2.kind == ControlPointKind.Finish) {
                // Update the finish control symbol.
                if ((flagging == FlaggingKind.None || flagging == FlaggingKind.Begin) && control2.symbolIds[0] == "14.1") {
                    // Remove the "flagged from last control symbol" and change it to "no flagging".
                    ChangeDescriptionSymbol(eventDB, controlId2, 0, "14.3");
                }
                else if (flagging == FlaggingKind.End) {
                    // If partial flagging on the end part of the leg, change the symbol to finish funnel.
                    ChangeDescriptionSymbol(eventDB, controlId2, 0, "14.2");
                }
            }
        }
All Usage Examples Of PurplePen.EventDB::AddLeg