/// <summary>
 /// Overridden to pad the number of bends so that there are always 2 mod 3 by duplicating the last location, if necessary.
 /// </summary>
 protected override IEdge CreateEdge(IGraph graph, IPortCandidate sourcePortCandidate,
                                     IPortCandidate targetPortCandidate)
 {
     if (CreateSmoothSplines && DummyEdge.Style is yWorks.Graph.Styles.BezierEdgeStyle)
     {
         if (DummyEdge.Bends.Any())
         {
             augmenting = true;
             try {
                 var lastLocation = DummyEdge.Bends.Last().Location.ToPointD();
                 if (DummyEdge.Bends.Count % 3 == 1)
                 {
                     //We can reach this branch if we finish the edge creation
                     //without having finished a control point triple
                     //Just duplicate the last bend
                     DummyEdgeGraph.AddBend(DummyEdge, lastLocation);
                 }
                 else if (DummyEdge.Bends.Count % 3 == 0)
                 {
                     //Actually, we shouldn't be able to come here
                     //since we always create bend triples and have an initial single control point
                     DummyEdgeGraph.AddBend(DummyEdge, lastLocation);
                     DummyEdgeGraph.AddBend(DummyEdge, lastLocation);
                 }
             } finally {
                 augmenting = false;
             }
         }
     }
     return(base.CreateEdge(graph, sourcePortCandidate, targetPortCandidate));
 }
        private IEdge EdgeCreator(IInputModeContext context, IGraph graph, IPortCandidate sourcePort,
                                  IPortCandidate targetPort, IEdge templateEdge)
        {
            //We perform the edge creation indirectly through the model
            Customer sourceCustomer   = (Customer)sourcePort.Owner.Tag;
            Customer targetCustomer   = (Customer)targetPort.Owner.Tag;
            var      relatedCustomers = sourceCustomer.RelatedCustomers;

            if (sourceCustomer != targetCustomer && !sourceCustomer.RelatedCustomers.Contains(targetCustomer))
            {
                relatedCustomers.Add(targetCustomer);
                var edge = Graph.GetEdge(sourcePort.Owner, targetPort.Owner);
                //Return the newly created edge...
                return(edge);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Callback used by <see cref="CreateEdgeInputMode"/> to create an edge.
        /// </summary>
        /// <remarks>
        /// This implementation adds a label to the newly created edge and sets up the correct business object.
        /// Note that only edges from Customers to Products are allowed.
        /// </remarks>
        private IEdge CreateEdge(IInputModeContext context, IGraph graph, IPortCandidate sourcePortCandidate, IPortCandidate targetPortCandidate, IEdge templateEdge)
        {
            var sourcePort = sourcePortCandidate.Port ?? sourcePortCandidate.CreatePort(context);
            var targetPort = targetPortCandidate.Port ?? targetPortCandidate.CreatePort(context);
            var customer   = sourcePort.Owner.Tag as Customer;
            var product    = targetPort.Owner.Tag as Product;

            if (customer != null && product != null)
            {
                var edge     = graph.CreateEdge(sourcePort, targetPort, edgeStyle);
                var relation = new Relation()
                {
                    Customer = customer, Product = product
                };
                var label = graph.AddLabel(edge, relation.ToString());
                label.Tag = relation;
                return(edge);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called by the create edge mode to find the port candidates for the end of the edge given
        /// the source port candidate on the other end of the edge.
        /// </summary>
        public override IEnumerable <IPortCandidate> GetTargetPortCandidates(IInputModeContext context, IPortCandidate sourcePortCandidate)
        {
            var ceim          = context.ParentInputMode as CreateEdgeInputMode;
            var canvasControl = context.CanvasControl;

            if (ceim != null && canvasControl != null)
            {
                return(GenerateEndNodePortCandidates(context));
            }
            return(base.GetTargetPortCandidates(context, sourcePortCandidate));
        }
            /// <summary>
            /// Returns all port candidates that apply for the provided opposite port candidate.
            /// </summary>
            /// <remarks>
            /// In this implementation only source ports with the same color and source ports of nodes
            /// with the same color as the target port are accepted.
            /// </remarks>
            public override IEnumerable <IPortCandidate> GetTargetPortCandidates(IInputModeContext context, IPortCandidate source)
            {
                List <IPortCandidate> candidates = new List <IPortCandidate>();
                var graph = context.GetGraph();

                if (graph != null)
                {
                    foreach (IPort port in node.Ports)
                    {
                        DefaultPortCandidate portCandidate = new DefaultPortCandidate(port);
                        var  sourcePort = source.CreatePort(context);
                        bool valid      = port.Tag.Equals(source.Owner.Tag) || sourcePort != null && port.Tag.Equals(sourcePort.Tag);
                        portCandidate.Validity = valid ? PortCandidateValidity.Valid : PortCandidateValidity.Invalid;
                        candidates.Add(portCandidate);
                    }
                }

                return(candidates);
            }
 /// <summary>
 /// Returns a central port candidate if the owner node of the source
 /// candidate is green, and an empty list otherwise.
 /// </summary>
 public override IEnumerable <IPortCandidate> GetTargetPortCandidates(IInputModeContext context, IPortCandidate source)
 {
     // Check if the source node is green
     if (Color.Green.Equals(source.Owner.Tag))
     {
         return(PortCandidateProviders.FromNodeCenter(node).GetTargetPortCandidates(context, source));
     }
     else
     {
         return(new IPortCandidate[0]);
     }
 }
 public IEnumerable <IPortCandidate> GetTargetPortCandidates(IInputModeContext context, IPortCandidate source)
 {
     return(GetCandidatesForDirection(EdgeDirection.In, context));
 }
 /// <summary>
 /// not queried
 /// </summary>
 /// <returns>no elements</returns>
 public IEnumerable <IPortCandidate> GetSourcePortCandidates(IInputModeContext context, IPortCandidate target)
 {
     return(GetCandidatesForDirection(EdgeDirection.Out, context));
 }