Nevron Forum

Problem of adding a NPointPort to a NCustomShape

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

By Wilhelm Vortisch - Wednesday, April 21, 2010

Hi folks,

I have a problem in adding a NPointPort to a NCustomShape. The NCustomShape is in a library browser.
Always if I drop (a copy of) the master in the drawing document, the port is on position 0,0 of the drawing document and not in the shape bounds.
In the following code I create the custom shape with one port (to the fourth point):

private NCompositeShape createComplexCompositeShape()
{
NCompositeShape shape = new NCompositeShape()

NPolygonPath newElement = new NPolygonPath(new NPointF[]
{
new NPointF(0, 10),
new NPointF(0, 90),
new NPointF(50, 90),
new NPointF(50, 100),
new NPointF(50,90),
new NPointF(100, 90),
new NPointF(100, 10),
new NPointF(50, 10),
new NPointF(50, 0),
new NPointF(50,10),
});
shape.Primitives.AddChild(newElement);
shape.UpdateModelBounds();

shape.Style.FillStyle = new NColorFillStyle(Color.AliceBlue);
shape.Style.StrokeStyle = new NStrokeStyle(1, Color.FromArgb(0, 0, 0x88));

// create the shape ports
shape.CreateShapeElements(ShapeElementsMask.Ports);

NPointPort port1 = new NPointPort(shape.UniqueId, PointIndexMode.Custom, 4);
shape.Ports.AddChild(port1);

return shape;
}


Any tips?

Kind Regards

Wilhelm
By Nevron Support - Thursday, April 22, 2010

Hi Wilhelm,

The problem with the port positioning is the anchor model that you pass to the NPointPoint constructor. A composite shape does not implement the INPoints interface and that is why the point port cannot position itself correctly - it will always return (0,0) as its scene coordinates. To fix the problem just replace:

NPointPort port1 = new NPointPort(shape.UniqueId, PointIndexMode.Custom, 4);

with

NPointPort port1 = new NPointPort(newElement.UniqueId, PointIndexMode.Custom, 4);
By Wilhelm Vortisch - Saturday, April 24, 2010

Hi Nevron support,

thank you for the good tip. It works now.

Regards

Wilhelm