private static void DelayValidateExternalConstraintShapeFullyConnected(ModelElement element) { if (!element.IsDeleted) { ExternalConstraintShape shape = (ExternalConstraintShape)element; int linkCount = 0; foreach (LinkConnectsToNode link in LinkConnectsToNode.GetLinksToLink(shape)) { if (link.Link is ExternalConstraintLink) { ++linkCount; } } bool keepShape = false; IConstraint constraint = shape.AssociatedConstraint; switch (constraint.ConstraintStorageStyle) { case ConstraintStorageStyle.SetConstraint: keepShape = ((SetConstraint)constraint).FactTypeCollection.Count == linkCount; break; case ConstraintStorageStyle.SetComparisonConstraint: keepShape = ((SetComparisonConstraint)constraint).FactTypeCollection.Count == linkCount; break; } if (!keepShape) { shape.Delete(); } } }
/// <summary> /// AddRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ExclusiveOrConstraintCoupler), FireTime=TopLevelCommit, Priority=DiagramFixupConstants.AddShapeRulePriority; /// Remove shapes associated with the exclusion constraint /// when exclusion and mandatory constraints are coupled. /// </summary> private static void ExclusiveOrCouplerAddedRule(ElementAddedEventArgs e) { ExclusiveOrConstraintCoupler link = e.ModelElement as ExclusiveOrConstraintCoupler; MandatoryConstraint mandatory = link.MandatoryConstraint; ExclusionConstraint exclusion = link.ExclusionConstraint; LinkedElementCollection <PresentationElement> pels = PresentationViewsSubject.GetPresentation(exclusion); for (int i = pels.Count - 1; i >= 0; --i) { ExternalConstraintShape shape = pels[i] as ExternalConstraintShape; if (shape != null) { shape.Delete(); } } InvalidateAssociatedDisplay(mandatory); }