public bool FulFills(MarkerNode me, MarkerNode other) { if (me.Edges.Count > Max - 1) { return false; } return true; }
protected override void OnButtonPressed(ButtonEventArgs args) { SetFocus(); Point position = args.Position; position.X /= scaleFactor; position.Y /= scaleFactor; popupWindow.Hide(); initialScrollPosition = Point.Zero; PipelineNode node = GetNodeAt(position, true); if (node != null) { ButtonEventArgs nodeArgs = new ButtonEventArgs(); nodeArgs.X = position.X - node.bound.Location.X; nodeArgs.Y = position.Y - node.bound.Location.Y; nodeArgs.Button = args.Button; nodeArgs.MultiplePress = args.MultiplePress; if (node.OnButtonPressed(nodeArgs)) { return; } } switch (args.Button) { case PointerButton.Left: if (node != null) { // clicked on node if (args.MultiplePress >= 2) { OpenOptionWindow(node); mouseAction = MouseAction.None; args.Handled = true; break; } else { MarkerNode mNode = node.GetMarkerNodeAt(position); if (mNode != null && !mNode.compatible.IsFinal()) { connectNodesStartMarker = mNode; mouseAction |= MouseAction.AddEdge | MouseAction.AddEdgeNew; } else { if (node.bound.Contains(position)) { nodeToMoveOffset = new Point( node.bound.Location.X - position.X, node.bound.Location.Y - position.Y ); lastSelectedNode = node; mouseAction |= MouseAction.MoveNode; } } } } else { Tuple<MarkerNode, MarkerEdge> edge = GetEdgeAt(position); if (edge != null) { // clicked on edge if (edge.Item2.r >= 0.5) { connectNodesStartMarker = edge.Item1; } else { connectNodesStartMarker = (MarkerNode) edge.Item2.to; } edge.Item1.RemoveEdge(edge.Item2); lastSelectedEdge = edge; mouseAction |= MouseAction.MoveEdge; args.Handled = true; } } break; case PointerButton.Right: lastSelectedEdge = GetEdgeAt(position); if (lastSelectedEdge != null) { contextMenuEdge.Popup(); } else { PipelineNode nodeRight = GetNodeAt(position, true); if (nodeRight != null) { lastSelectedNode = nodeRight; if (lastSelectedNode.algorithm.options.Count > 0) { contextMenuNodeOptions.Show(); } else { contextMenuNodeOptions.Hide(); } contextMenuNode.Popup(); } } break; case PointerButton.Middle: mouseMover.EnableMouseMover(args.Position); if (oldCursor != CursorType.Move) { oldCursor = this.Cursor; this.Cursor = CursorType.Move; } break; } }
/// <summary> /// Shows popover window with results. /// </summary> /// <param name="mNode">M node.</param> void ShowResultPopover(MarkerNode mNode) { if (mNode.IsInput) { return; } PipelineNode pNode = mNode.parent; if (pNode.results == null || pNode.results.Count == 0) { return; } if (pNode.results[0].Item1.Length - 1 < mNode.Position) { return; } if (popupWindow.Content != null) { popupWindow.Content.Dispose(); } List<Tuple<IType[], Result[]>> resultCopy = pNode.results.FindAll(x => x.Item1[mNode.Position].RawData() != null); if (resultCopy.Count > 0) { ResultPopupView popupView = new ResultPopupView(resultCopy, mNode.Position); popupWindow.Content = popupView; popupWindow.Size = new Size(1, 1); popupWindow.Location = Desktop.MouseLocation.Offset(-10, -10); popupWindow.Show(); } }
/// <summary> /// Tests if another node is compatible with this one. /// Compatible == there can be a edge between this nodes. /// </summary> /// <returns><c>true</c>, if compatible, <c>false</c> otherwise.</returns> /// <param name="otherNode">The other compatible instance.</param> public bool Match(MarkerNode otherNode) { if (this == otherNode) return false; if (parent == otherNode.parent) return false; if (IsInput == otherNode.IsInput) return false; foreach (Edge edge in edges) { if (edge.to.ID == otherNode.ID) { return false; } } if (IsInput) { return otherNode.compatible.Match(otherNode, this); } return compatible.Match(this, otherNode); }
/// <summary> /// Tests if another instance is compatible with this one /// </summary> /// <returns><c>true</c>, if compatible, <c>false</c> otherwise.</returns> /// <param name="nodeFrom"></param> /// <param name="nodeTo"></param> public bool Match(MarkerNode nodeFrom, MarkerNode nodeTo) { Compatible another = nodeTo.compatible; Type typeFrom = Type; Type typeTo = another.Type; if (typeFrom.IsGenericType) { typeFrom = typeFrom.GetGenericArguments()[0]; } if (typeTo.IsGenericType) { typeTo = typeTo.GetGenericArguments()[0]; } if (typeTo.IsInterface) { if (!typeFrom.GetInterfaces().Contains(typeTo)) { return false; } } else if (typeFrom.IsInterface) { if (!typeTo.GetInterfaces().Contains(typeFrom)) { return false; } } else { if (!typeFrom.Equals(typeTo)) { return false; } } foreach (BaseConstraint constraint in Constraints) { if (!constraint.FulFills(nodeFrom, nodeTo)) { return false; } } foreach (BaseConstraint constraint in another.Constraints) { if (!constraint.FulFills(nodeTo, nodeFrom)) { return false; } } return true; }
public Context ComputeStroke(Context ctx, MarkerNode from, Point offset = default(Point)) { Rectangle fromBound = from.Bounds.Offset(offset); Rectangle toBound = to.Bounds.Offset(offset); ctx.MoveTo(fromBound.Center.X, fromBound.Center.Y); double horizontalSpace = Math.Abs(fromBound.Center.X - toBound.Center.X); double verticalSpace = Math.Abs(fromBound.Center.Y - toBound.Center.Y); double minLength = absMinLength; // if to-node is right of from-node if (toBound.Center.X - fromBound.Center.X >= absMinLength * 2) { if (horizontalSpace > verticalSpace) { minLength = Math.Max((horizontalSpace - verticalSpace) / 2, absMinLength); } if (verticalSpace > (horizontalSpace - 2 * minLength)) { minLength = horizontalSpace / 2; } if (verticalSpace > (horizontalSpace - minLength) && minLength > absMinLength) { double minSpace = Math.Min(horizontalSpace - absMinLength, verticalSpace + absMinLength); int verticalNeg = fromBound.Center.Y - toBound.Center.Y < 0 ? 1 : -1; ctx.LineTo(fromBound.Center.X + absMinLength, fromBound.Center.Y); // fromNode- if (minSpace / 2 - absMinLength > 0) { // \ ctx.LineTo(fromBound.Center.X + minSpace / 2, fromBound.Center.Y + ((minSpace / 2 - absMinLength) * verticalNeg)); } if (minSpace / 2 - absMinLength > -minSpace / 2) { ctx.LineTo(fromBound.Center.X + Math.Max(minSpace / 2, absMinLength), toBound.Center.Y - minSpace / 2 * verticalNeg); // | ctx.LineTo(fromBound.Center.X + Math.Max(minSpace, absMinLength), toBound.Center.Y); // \ } else { ctx.LineTo(fromBound.Center.X + absMinLength, toBound.Center.Y); // | } ctx.LineTo(toBound.Center.X, toBound.Center.Y); // -toNode } else { ctx.LineTo(fromBound.Center.X + minLength, fromBound.Center.Y); ctx.LineTo(toBound.Center.X - minLength, toBound.Center.Y); ctx.LineTo(toBound.Center.X, toBound.Center.Y); } } else { // to node is left of from node MarkerNode toNode = to as MarkerNode; if (toNode != null) { PipelineNode parent = toNode.parent; ctx.LineTo(fromBound.Center.X + absMinLength, fromBound.Center.Y); // fromNode- if (toBound.Center.Y - fromBound.Center.Y > 0) { ctx.LineTo(fromBound.Center.X + absMinLength, parent.BoundWithExtras.Top); // | ctx.LineTo(parent.bound.Left - minLength, parent.BoundWithExtras.Top); // <- } else { ctx.LineTo(fromBound.Center.X + absMinLength, parent.BoundWithExtras.Bottom); // | ctx.LineTo(parent.bound.Left - minLength, parent.BoundWithExtras.Bottom); // <- } ctx.LineTo(parent.bound.Left - minLength, toNode.Bounds.Center.Y); // | ctx.LineTo(toNode.Bounds.Center.X, toNode.Bounds.Center.Y); // -> } } return ctx; }
/// <summary> /// Draws a edge from one marker, to another /// </summary> /// <param name="ctx">Context.</param> /// <param name="from">From.</param> public void Draw(Context ctx, MarkerNode from) { MarkerNode toNode = to as MarkerNode; if (toNode != null) { ComputeStroke(ctx, from, new Point(2.5, 2.5)); ctx.SetLineWidth(4.5); ctx.SetColor(Colors.DimGray.WithAlpha(0.3)); ctx.Stroke(); ComputeStroke(ctx, from); ctx.SetLineWidth(6); ctx.SetColor(Colors.DimGray.WithAlpha(0.7)); ctx.StrokePreserve(); ctx.SetLineWidth(4.0); ctx.SetColor(from.NodeColor.BlendWith(toNode.NodeColor, 0.5).WithAlpha(1.0)); ctx.Stroke(); } }