/// <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 void DummyGraph_BendRemoved(object sender, BendEventArgs e)
 {
     if (!augmenting)
     {
         if (CreateSmoothSplines && DummyEdge.Style is yWorks.Graph.Styles.BezierEdgeStyle)
         {
             augmenting = true;
             try {
                 if (DummyEdge.Bends.Any() && DummyEdge.Bends.Count % 3 == 0)
                 {
                     //Undo bend creation that finished a triple
                     DummyEdgeGraph.Remove(DummyEdge.Bends.Last());
                 }
             } finally { augmenting = false; }
         }
     }
 }
 private void DummyGraph_BendAdded(object sender, ItemEventArgs <IBend> e)
 {
     if (!augmenting)
     {
         if (CreateSmoothSplines && DummyEdge.Style is yWorks.Graph.Styles.BezierEdgeStyle)
         {
             augmenting = true;
             try {
                 if (DummyEdge.Bends.Count % 3 == 0)
                 {
                     //Bend creation that finishes a control point line
                     //Insert a middle bend
                     var cp0 = DummyEdge.Bends[DummyEdge.Bends.Count - 2].Location.ToPointD();
                     var cp2 = e.Item.Location.ToPointD();
                     var cp1 = 0.5 * (cp2 - cp0) + cp0;
                     DummyEdgeGraph.AddBend(DummyEdge, cp1, DummyEdge.Bends.Count - 1);
                 }
             } finally { augmenting = false; }
         }
     }
 }