Diagram displacement when displayed

Mar 27, 2014 at 8:56 AM

I have problem with displacement of my diagram when the diagram is displayed. The diagram's (0,0) coordinate does not correspond to sheet's (0,0) coordinate, but it is relative to the Display component's (0,0) coordinate. See the picture: http://snag.gy/kvO1j.jpg

The whole diagram is created in code and represents some business objects I want to display.

The code is straight forward:
this.Project.AddLibrary(Assembly.GetExecutingAssembly(), false);

this.Project.Repository.Insert(new Template("BoxTemplate", this.Project.ShapeTypes["Box"].CreateInstance()));

this.Diagram = new Diagram("Diagram");

foreach (var myObject in this.objects)
    Box shape = this.Project.Repository.GetTemplate("BoxTemplate").CreateShape() as Box;
    shape.Width = myObject .Width;
    shape.Height = myObject .Height;
    shape.X = myObject .X;
    shape.Y = myObject .Y;

    this.Diagram.AddShapeToLayers(shape, Dataweb.NShape.Advanced.LayerIds.All);

this.display1.Diagram = this.Diagram;
this.display1.ActiveTool = new SelectionTool();
I think I'm missing something but I just don't see it.

Mar 27, 2014 at 1:30 PM
Edited Mar 27, 2014 at 1:31 PM
Hello Zvonko,

the display has methods to convert between control coordinates and display coordinates and vice versa:

The source of your problem is the fact that shape.X and shape.Y do not refer to the top left corder of the shape but to the balance point of the shape.
What you want to do is:
    RectangleBase shape = 
        as RectangleBase;
    shape.Width = myObject .Width;
    shape.Height = myObject .Height;
    shape.X = myObject.X + (int)Math.Round((shape.Width / 2f));
    shape.Y = myObject.Y + (int)Math.Round((shape.Height / 2f));

    // Shapes that do not belong to any layer will always be visible.
    // this.Diagram.AddShapeToLayers(shape, Dataweb.NShape.Advanced.LayerIds.All);
Best regards,
Kurt Holzinger
Mar 27, 2014 at 1:33 PM

Thank you for the explanation. I was sure I am missing something (and you proved my assumption).

Thanks again,