Nevron Forum

How to change the type of an edge

https://www.nevron.com/Forum/Topic4466.aspx

By Sandor Nagy - Thursday, November 11, 2010

Hi,

I'm using the NGraphDataSourceImporter class to import the vertices and edges into the diagram. By default the types of the edges is NRoutableConnector.
How can I change the type of some edges to e.g. NArrowShape in the NGraphDataSourceImporter.EdgeImported event?

Thanks,
Sandor Nagy
By Nevron Support - Friday, November 12, 2010

Hi,
You can create a shape factory (by implementing the INShapeFactory interface) that creates the edge types you want and assign it to the EdgesShapeFactory property of the graph importer.
By Sandor Nagy - Tuesday, November 16, 2010

Hi,
Can you provide me a sample code?

Thanks,
Sandor Nagy
By Nevron Support - Tuesday, November 16, 2010

Hi Sandor,

The following is a simple implementation of a shape factory:

 

public class MyEdgeShapeFactory : NShapesFactory

{

      public MyEdgeShapeFactory()

            : base("MyEdgeShapeFactory")

      {

      }

 

      public override int ShapesCount

      {

            get

            {

                  return Enum.GetValues(GetEnumType()).Length;

            }

      }

     

      public override NShape CreateShape(int index)

      {

            switch ((MyEdgeShapes)index)

            {

                  case MyEdgeShapes.ArrowShape:

                        NArrowShape arrowShape = new NArrowShape(new NPointF(0, 0), new NPointF(DefaultSize.Width, DefaultSize.Height));

                        return arrowShape;

 

                  default:

                        throw new Exception("New shape type ?");

            }

      }

      protected override NShapeInfo CreateShapeInfo(int index)

      {

            MyEdgeShapes edgeShape = (MyEdgeShapes)index;

            NShapeInfo info = new NShapeInfo(NSystem.InsertSpacesBeforeUppers(edgeShape.ToString()));

            return info;

      }

      protected override Type GetEnumType()

      {

            return typeof(MyEdgeShapes);

      }

}

 

public enum MyEdgeShapes

{

      ArrowShape

}

 

To make the graph data importer use this shape factory to create edges, use the following piece of code:

 

MyEdgeShapeFactory edgesFactory = new MyEdgeShapeFactory();

edgesFactory.DefaultSize = new NSizeF(60, 30);

graphImporter.EdgeShapesFactory = edgesFactory;

graphImporter.EdgeShapesName = MyEdgeShapes.ArrowShape.ToString();

By Sandor Nagy - Monday, November 22, 2010

Hi,

Thanks, it is working. But I have another question.
With this sample code all edges will be NArrowShape edges. But I need different edge types during importing edges using NGraphDataSourceImporter.
So the selected edge type should be determined based on the current database record in the MyEdgeShapeFactory.CreateShape method. How can I do this?
When a breakpoint is hit in the NGraphDataSourceImporter.EdgeImported event, the edge is already created as NArrowShape.

Thanks,
Sandor Nagy