/// <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> /// Called as the pointer is moved over potential targets after a source is selected /// So should be pretty quick /// </summary> /// <remarks> /// The cursor can change dependant on CanCreateConnection when this returns true /// </remarks> /// <param name="sourceShapeElement">ShapeElement</param> /// <param name="targetShapeElement">ShapeElement</param> /// <returns></returns> public override bool IsValidSourceAndTarget(ShapeElement sourceShapeElement, ShapeElement targetShapeElement) { ORMDiagram diagram = (ORMDiagram)sourceShapeElement.Diagram; RoleConnectAction action = diagram.RoleConnectAction; action.myRoleReorderConnector = false; ObjectType objectType; RoleBase sourceRole = action.mySourceRole; RoleBase role; RoleBase targetRole; Objectification objectification; // Reorder roles in the same shape if (sourceRole != null && sourceShapeElement == targetShapeElement && null != (targetRole = action.myLastMouseMoveRole) && targetRole != sourceRole) { action.myRoleReorderConnector = true; return(true); } else if ((null != (role = sourceRole) && null != (objectType = ObjectTypeFromShape(targetShapeElement)) && (null == (objectification = objectType.Objectification) || !objectification.IsImplied)) || (null != (objectType = action.mySourceObjectType) && null != (role = action.myLastMouseMoveRole))) { return(role.Role.FactType != objectType.NestedFactType); } // Allow the user to drag out an existing role player from a // role on a shape that is not connected. else if (targetShapeElement == diagram && action.mySourceRoleMissingConnector) { return(true); } return(false); }