/// <summary> /// Controls the PaintFeedbackArgs for while building an internal uniqueness constraint. /// </summary> /// <param name="sourceShapeElement">The shape that the internal uniqueness constraint is being added to.</param> /// <param name="sourcePoint">The point where the internal uniqueness constraint was added.</param> /// <param name="targetShapeElement">The shape that the mouse is currently over.</param> /// <param name="targetPoint">The point that the mouse is currently over.</param> /// <param name="paintFeedbackArgs">The current PaintFeedbackArgs.</param> /// <returns>The modified PaintFeedbackArgs</returns> public override PaintFeedbackArgs UpdatePaintFeedbackParameters(ShapeElement sourceShapeElement, PointD sourcePoint, ShapeElement targetShapeElement, PointD targetPoint, PaintFeedbackArgs paintFeedbackArgs) { PaintFeedbackArgs args = base.UpdatePaintFeedbackParameters(sourceShapeElement, sourcePoint, targetShapeElement, targetPoint, paintFeedbackArgs); args.DisplaySourceAndTargetFeedback = false; args.TargetConnectionPoint = args.SourceConnectionPoint; return(args); }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { ORMDiagram diagram = (ORMDiagram)sourceShapeElement.Diagram; RoleConnectAction action = diagram.RoleConnectAction; ObjectType objectType; RoleBase sourceRole = action.mySourceRole; RoleBase roleBase; RoleBase targetRole; FactTypeShape factTypeShape; if (sourceRole != null && sourceShapeElement == targetShapeElement && null != (targetRole = action.myLastMouseMoveRole) && targetRole != sourceRole && null != (factTypeShape = sourceShapeElement as FactTypeShape)) { LinkedElementCollection <RoleBase> displayedRoles = factTypeShape.GetEditableDisplayRoleOrder(); displayedRoles.Move(displayedRoles.IndexOf(sourceRole), displayedRoles.IndexOf(targetRole)); } else if ((null != (roleBase = sourceRole) && null != (objectType = ObjectTypeFromShape(targetShapeElement))) || (null != (objectType = action.mySourceObjectType) && null != (roleBase = action.myLastMouseMoveRole))) { // Don't trigger a change if none is indicated. Turn this into a noop Role role = roleBase.Role; if (role.RolePlayer != objectType) { role.RolePlayer = objectType; } } else if (targetShapeElement == diagram && action.mySourceRoleMissingConnector) { diagram.PlaceORMElementOnDiagram(null, roleBase.Role.RolePlayer, paintFeedbackArgs.TargetFeedbackBounds.Location, ORMPlacementOption.AllowMultipleShapes, null, null); } }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { ORMDiagram diagram = (ORMDiagram)sourceShapeElement.Diagram; RoleConnectAction action = diagram.RoleConnectAction; ObjectType objectType; RoleBase sourceRole = action.mySourceRole; RoleBase roleBase; RoleBase targetRole; FactTypeShape factTypeShape; if (sourceRole != null && sourceShapeElement == targetShapeElement && null != (targetRole = action.myLastMouseMoveRole) && targetRole != sourceRole && null != (factTypeShape = sourceShapeElement as FactTypeShape)) { LinkedElementCollection<RoleBase> displayedRoles = factTypeShape.GetEditableDisplayRoleOrder(); displayedRoles.Move(displayedRoles.IndexOf(sourceRole), displayedRoles.IndexOf(targetRole)); } else if ((null != (roleBase = sourceRole) && null != (objectType = ObjectTypeFromShape(targetShapeElement))) || (null != (objectType = action.mySourceObjectType) && null != (roleBase = action.myLastMouseMoveRole))) { // Don't trigger a change if none is indicated. Turn this into a noop Role role = roleBase.Role; if (role.RolePlayer != objectType) { role.RolePlayer = objectType; } } else if (targetShapeElement == diagram && action.mySourceRoleMissingConnector) { diagram.PlaceORMElementOnDiagram(null, roleBase.Role.RolePlayer, paintFeedbackArgs.TargetFeedbackBounds.Location, ORMPlacementOption.AllowMultipleShapes, null, null); } }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { SubtypeConnectAction action = (sourceShapeElement.Diagram as ORMDiagram).SubtypeConnectAction; ObjectType sourceObjectType; ObjectType targetObjectType; if ((null != (sourceObjectType = action.mySourceObjectType)) && (null != (targetObjectType = ObjectTypeFromShape(targetShapeElement)))) { SubtypeFact.Create(sourceObjectType, targetObjectType); } }
/// <summary> /// Create a connection between a FactTypeShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { IConstraint constraint; InternalUniquenessConstraintConnectAction action; IList <Role> selectedRoles; int rolesCount; if ((null != (action = (sourceShapeElement.Diagram as ORMDiagram).InternalUniquenessConstraintConnectAction)) && (null != (constraint = action.ActiveConstraint)) && (null != (selectedRoles = action.SelectedRoleCollection)) && (0 != (rolesCount = selectedRoles.Count))) { UniquenessConstraint iuConstraint; if (null != (iuConstraint = constraint as UniquenessConstraint) && iuConstraint.IsInternal) { // Keep the collection ordered, this ends up as constraint order on objectified FactTypes LinkedElementCollection <Role> roles = iuConstraint.RoleCollection; int existingRolesCount = roles.Count; for (int i = existingRolesCount - 1; i >= 0; --i) { Role testRole = roles[i]; if (!selectedRoles.Contains(testRole)) { roles.Remove(testRole); --existingRolesCount; } } for (int i = 0; i < rolesCount; ++i) { Role selectedRole = selectedRoles[i]; int existingIndex = roles.IndexOf(selectedRole); if (existingIndex == -1) { if (i < existingRolesCount) { roles.Insert(i, selectedRole); } else if (!roles.Contains(selectedRole)) { roles.Add(selectedRole); } ++existingRolesCount; } else if (existingIndex != i) { roles.Move(existingIndex, i); } } } } }
/// <summary> /// Controls the PaintFeedbackArgs for while building an internal uniqueness constraint. /// </summary> /// <param name="sourceShapeElement">The shape that the internal uniqueness constraint is being added to.</param> /// <param name="sourcePoint">The point where the internal uniqueness constraint was added.</param> /// <param name="targetShapeElement">The shape that the mouse is currently over.</param> /// <param name="targetPoint">The point that the mouse is currently over.</param> /// <param name="paintFeedbackArgs">The current PaintFeedbackArgs.</param> /// <returns>The modified PaintFeedbackArgs</returns> public override PaintFeedbackArgs UpdatePaintFeedbackParameters(ShapeElement sourceShapeElement, PointD sourcePoint, ShapeElement targetShapeElement, PointD targetPoint, PaintFeedbackArgs paintFeedbackArgs) { PaintFeedbackArgs args = base.UpdatePaintFeedbackParameters(sourceShapeElement, sourcePoint, targetShapeElement, targetPoint, paintFeedbackArgs); args.DisplaySourceAndTargetFeedback = false; args.TargetConnectionPoint = args.SourceConnectionPoint; return args; }
/// <summary> /// Create a connection between an ModelNoteShape and a FactType or ObjectType. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { ModelNoteConnectAction action = (sourceShapeElement.Diagram as ORMDiagram).ModelNoteConnectAction; ORMModelElement sourceElement; ORMModelElement targetElement; if (null != (sourceElement = action.mySourceElement) && null != (targetElement = ElementFromShape <ORMModelElement>(targetShapeElement))) { ModelNote note = null; if (null == (note = sourceElement as ModelNote)) { if (null != (note = targetElement as ModelNote)) { // Switch the source and target targetElement = sourceElement; } } if (note != null) { FactType factType; ObjectType objectType; SetConstraint setConstraint; SetComparisonConstraint setComparisonConstraint; if (null != (factType = targetElement as FactType)) { new ModelNoteReferencesFactType(note, factType); } else if (null != (objectType = targetElement as ObjectType)) { new ModelNoteReferencesObjectType(note, objectType); } else if (null != (setConstraint = targetElement as SetConstraint)) { new ModelNoteReferencesSetConstraint(note, setConstraint); } else if (null != (setComparisonConstraint = targetElement as SetComparisonConstraint)) { new ModelNoteReferencesSetComparisonConstraint(note, setComparisonConstraint); } } } }
/// <summary> /// Create a connection between a FactTypeShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { IConstraint constraint; InternalUniquenessConstraintConnectAction action; IList<Role> selectedRoles; int rolesCount; if ((null != (action = (sourceShapeElement.Diagram as ORMDiagram).InternalUniquenessConstraintConnectAction)) && (null != (constraint = action.ActiveConstraint)) && (null != (selectedRoles = action.SelectedRoleCollection)) && (0 != (rolesCount = selectedRoles.Count))) { UniquenessConstraint iuConstraint; if (null != (iuConstraint = constraint as UniquenessConstraint) && iuConstraint.IsInternal) { // Keep the collection ordered, this ends up as constraint order on objectified FactTypes LinkedElementCollection<Role> roles = iuConstraint.RoleCollection; int existingRolesCount = roles.Count; for (int i = existingRolesCount - 1; i >= 0; --i) { Role testRole = roles[i]; if (!selectedRoles.Contains(testRole)) { roles.Remove(testRole); --existingRolesCount; } } for (int i = 0; i < rolesCount; ++i) { Role selectedRole = selectedRoles[i]; int existingIndex = roles.IndexOf(selectedRole); if (existingIndex == -1) { if (i < existingRolesCount) { roles.Insert(i, selectedRole); } else if (!roles.Contains(selectedRole)) { roles.Add(selectedRole); } ++existingRolesCount; } else if (existingIndex != i) { roles.Move(existingIndex, i); } } } } }
/// <summary> /// Move the feedback dragline to the center /// </summary> /// <param name="sourceShapeElement"></param> /// <param name="sourcePoint"></param> /// <param name="targetShapeElement"></param> /// <param name="targetPoint"></param> /// <param name="paintFeedbackArgs"></param> /// <returns></returns> public override PaintFeedbackArgs UpdatePaintFeedbackParameters(ShapeElement sourceShapeElement, PointD sourcePoint, ShapeElement targetShapeElement, PointD targetPoint, PaintFeedbackArgs paintFeedbackArgs) { PaintFeedbackArgs args = base.UpdatePaintFeedbackParameters(sourceShapeElement, sourcePoint, targetShapeElement, targetPoint, paintFeedbackArgs); RectangleD bounds = sourceShapeElement.AbsoluteBoundingBox; args.SourceConnectionPoint = bounds.Center; return args; }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { ExternalConstraintShape constraintShape; IConstraint constraint; ExternalConstraintConnectAction action; IList<Role> selectedRoles; int rolesCount; if ((null != (constraintShape = sourceShapeElement as ExternalConstraintShape)) && (null != (constraint = constraintShape.AssociatedConstraint)) && (null != (action = (sourceShapeElement.Diagram as ORMDiagram).ExternalConstraintConnectAction)) && (null != (selectedRoles = action.SelectedRoleCollection)) && (0 != (rolesCount = selectedRoles.Count))) { SetComparisonConstraint mcConstraint; SetConstraint scConstraint; ConstraintRoleSequence modifyRoleSequence = null; if (null != (mcConstraint = constraint as SetComparisonConstraint)) { ConstraintRoleSequence constraintRoleSequenceBeingEdited = action.ConstraintRoleSequenceToEdit; // Add a new role set if (null == constraintRoleSequenceBeingEdited) { LinkedElementCollection<SetComparisonConstraintRoleSequence> roleSequences = mcConstraint.RoleSequenceCollection; if (action.mySubtypeConnection) { // All editing is done as a single column, add role sequences to the constraint // instead of roles to the sequence Store store = mcConstraint.Store; for (int i = 0; i < rolesCount; ++i) { SetComparisonConstraintRoleSequence roleSequence = new SetComparisonConstraintRoleSequence(store); roleSequence.RoleCollection.Add(selectedRoles[i]); roleSequences.Add(roleSequence); } } else { SetComparisonConstraintRoleSequence roleSequence = new SetComparisonConstraintRoleSequence(mcConstraint.Store); LinkedElementCollection<Role> roles = roleSequence.RoleCollection; for (int i = 0; i < rolesCount; ++i) { roles.Add(selectedRoles[i]); } roleSequences.Add(roleSequence); } } else if (action.mySubtypeConnection) { LinkedElementCollection<SetComparisonConstraintRoleSequence> existingSequences = mcConstraint.RoleSequenceCollection; int existingSequenceCount = existingSequences.Count; // Pull out removed ones first for (int i = existingSequenceCount - 1; i >= 0; --i) { SetComparisonConstraintRoleSequence existingSequence = existingSequences[i]; LinkedElementCollection<Role> sequenceRoles = existingSequence.RoleCollection; if (sequenceRoles.Count != 1 || !selectedRoles.Contains(sequenceRoles[0])) { existingSequences.Remove(existingSequence); --existingSequenceCount; } } Store store = mcConstraint.Store; for (int i = 0; i < rolesCount; ++i) { Role selectedRole = selectedRoles[i]; int existingIndex = -1; for (int j = 0; j < existingSequenceCount; ++j) { if (existingSequences[j].RoleCollection[0] == selectedRole) { existingIndex = j; break; } } if (existingIndex == -1) { SetComparisonConstraintRoleSequence roleSequence = new SetComparisonConstraintRoleSequence(store); roleSequence.RoleCollection.Add(selectedRoles[i]); if (i < existingSequenceCount) { existingSequences.Insert(i, roleSequence); } else { existingSequences.Add(roleSequence); } ++existingSequenceCount; } else if (existingIndex != i) { existingSequences.Move(existingIndex, i); } } } // Edit the existing role set. else { modifyRoleSequence = constraintRoleSequenceBeingEdited; } } else if (null != (scConstraint = constraint as SetConstraint)) { // The single-column constraint is its own role set, just add the roles. modifyRoleSequence = scConstraint; switch (constraint.ConstraintType) { case ConstraintType.ExternalUniqueness: case ConstraintType.Frequency: // Translate selected unary roles back to the implied role bool duplicatedSelectedRoles = false; for (int i = 0; i < rolesCount; ++i) { Role testRole = selectedRoles[i]; Role oppositeRole; ObjectType oppositeRolePlayer; if (null != (oppositeRole = testRole.OppositeRole as Role) && null != (oppositeRolePlayer = oppositeRole.RolePlayer) && oppositeRolePlayer.IsImplicitBooleanValue) { if (!duplicatedSelectedRoles) { duplicatedSelectedRoles = true; Role[] dupRoles = new Role[rolesCount]; selectedRoles.CopyTo(dupRoles, 0); selectedRoles = dupRoles; } selectedRoles[i] = oppositeRole; } } break; } } if (modifyRoleSequence != null) { // Note that we don't just blow away the collection here, there are too // many side effects (such as removing the preferred identifier when a compatible // link is added) LinkedElementCollection<Role> roles = modifyRoleSequence.RoleCollection; int existingRolesCount = roles.Count; for (int i = existingRolesCount - 1; i >= 0; --i) { Role testRole = roles[i]; if (!selectedRoles.Contains(testRole)) { roles.Remove(testRole); --existingRolesCount; } } for (int i = 0; i < rolesCount; ++i) { Role selectedRole = selectedRoles[i]; int existingIndex = roles.IndexOf(selectedRole); if (existingIndex == -1) { if (i < existingRolesCount) { roles.Insert(i, selectedRole); } else if (!roles.Contains(selectedRole)) { roles.Add(selectedRole); } ++existingRolesCount; } else if (existingIndex != i) { roles.Move(existingIndex, i); } } } } }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { }
/// <summary> /// Create a connection between an ExternalConstraintShape and a FactType. Roles /// used in the connection are stored with the currently active connect action. /// </summary> /// <param name="sourceShapeElement">The source of the requested connection</param> /// <param name="targetShapeElement">The target of the requested connection</param> /// <param name="paintFeedbackArgs">PaintFeedbackArgs</param> public override void CreateConnection(ShapeElement sourceShapeElement, ShapeElement targetShapeElement, PaintFeedbackArgs paintFeedbackArgs) { SubtypeConnectAction action = (sourceShapeElement.Diagram as ORMDiagram).SubtypeConnectAction; ObjectType sourceObjectType; ObjectType targetObjectType; if ((null != (sourceObjectType = action.mySourceObjectType)) && (null != (targetObjectType = ObjectTypeFromShape(targetShapeElement)))) { SubtypeFact.Create(sourceObjectType, targetObjectType); } }