/// <summary> /// Creates the list of candidates where the edge creation ends. /// </summary> private IEnumerable <IPortCandidate> GenerateEndNodePortCandidates(IInputModeContext context) { var canvasControl = context.CanvasControl; // check if behavior is toggled. var shiftPressed = KeyEventRecognizers.ShiftPressed(context.CanvasControl, canvasControl.LastInputEvent); // check if the node is already occupied in that direction var targetNodeOccupied = IsTargetNodeOccupied(context, node); if (shiftPressed != targetNodeOccupied) { // only display dynamic port candidates return(new IPortCandidate[] { new DefaultPortCandidate(node, FreeNodePortLocationModel.Instance), }); } else { // only display static port candidates var existingPorts = new List <IPortCandidate>(); AddExistingPorts(node, existingPorts); if (node.Lookup <ITable>() == null) { // don't provide a default port for table nodes existingPorts.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeCenterAnchored)); } return(existingPorts); } }
/// <summary> /// Returns <see cref="HandlePositions.Corners"/> or <see cref="HandlePositions.Border"/> as available handle /// positions depending on the modifier state of <c>Ctrl</c>. /// </summary> /// <param name="context">The context the handles are created in.</param> /// <returns><see cref="HandlePositions.Corners"/> or <see cref="HandlePositions.Border"/></returns> public HandlePositions GetAvailableHandles(IInputModeContext context) { var ctrlPressed = KeyEventRecognizers.CtrlPressed(this, context.CanvasControl.LastMouse2DEvent); // when Ctrl is pressed, all border positions are returned, otherwise only the corner positions return(ctrlPressed ? HandlePositions.Border : HandlePositions.Corners); }
protected override IEnumerable <IPortCandidate> GetPortCandidates(IInputModeContext context) { var portCandidates = new List <IPortCandidate>(); // provide existing ports as candidates only if they use EventPortStyle and have no edges attached to them. foreach (IPort port in node.Ports) { if (port.Style is EventPortStyle && context.Lookup <IGraph>().EdgesAt(port).Count == 0) { portCandidates.Add(new DefaultPortCandidate(port)); } } if (node.Style is ActivityNodeStyle || node.Style is ChoreographyNodeStyle || node.Style is DataObjectNodeStyle || node.Style is AnnotationNodeStyle || node.Style is GroupNodeStyle || node.Style is DataStoreNodeStyle) { portCandidates.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeTopAnchored)); portCandidates.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeBottomAnchored)); portCandidates.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeLeftAnchored)); portCandidates.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeRightAnchored)); } else if (node.Style is EventNodeStyle || node.Style is GatewayNodeStyle) { double dmax = Math.Min(node.Layout.Width / 2, node.Layout.Height / 2); var model = FreeNodePortLocationModel.Instance; portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(0, -dmax)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(dmax, 0)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(0, dmax)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(-dmax, 0)))); } else if (node.Style is ConversationNodeStyle) { double dx = 0.5 * Math.Min(node.Layout.Width, node.Layout.Height / BpmnConstants.ConversationWidthHeightRatio); double dy = dx * BpmnConstants.ConversationWidthHeightRatio; var model = FreeNodePortLocationModel.Instance; portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(0, -dy)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(dx, 0)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(0, dy)))); portCandidates.Add(new DefaultPortCandidate(node, model.CreateParameter(new PointD(0.5, 0.5), new PointD(-dx, 0)))); } var ceim = context.ParentInputMode as CreateEdgeInputMode; var canvasControl = context.CanvasControl; if (ceim == null || canvasControl == null || KeyEventRecognizers.ShiftPressed(canvasControl, canvasControl.LastMouse2DEvent)) { // add a dynamic candidate portCandidates.Add(new DefaultPortCandidate(node, new FreeNodePortLocationModel())); } return(portCandidates); }
/// <summary> /// A custom <see cref="EventRecognizer"/> to be used as modifier recognizer. /// </summary> /// <remarks> /// Has to return true if the move input mode is allowed to move a node. /// </remarks> private bool IsRecognized(object eventSource, EventArgs eventArg) { // return the value according to the Mode combo box switch (cmbMode.SelectedIndex) { case 0: // always case 2: // on top (this is handled by custom IHitTestable) // the same as the unmodified MoveUnselectedInputMode; return(true); case 1: // shift is not pressed return(!KeyEventRecognizers.ShiftPressed(eventSource, eventArg)); case 3: // if enabled return(btnEnable.Checked); default: return(false); } }
/// <summary> /// Creates the list of candidates where the edge creation starts. /// </summary> private IEnumerable <IPortCandidate> GenerateStartNodePortCandidates(IInputModeContext context) { var canvasControl = context.CanvasControl; // since we turned on dynamic port candidate resolution without a modifier in the demo, we decide here // what to do. if (KeyEventRecognizers.ShiftPressed(context.CanvasControl, canvasControl.LastInputEvent)) { // yield the center and a dynamic candidate return(new IPortCandidate[] { new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeCenterAnchored), new DefaultPortCandidate(node, FreeNodePortLocationModel.Instance), }); } else { // yield static candidates, only var existingPorts = new List <IPortCandidate>(); AddExistingPorts(node, existingPorts); existingPorts.Add(new DefaultPortCandidate(node, FreeNodePortLocationModel.NodeCenterAnchored)); return(existingPorts); } }