Profile Picture

Port in Line

Posted By Volvick Derose 14 Years Ago
Author
Message
Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
Assume that I have a vertical or a horizontal line, I try to add couple of ports to it, but when I rotate the line or change the direction of the line, I want the ports to remain steady. Currently, the ports keep moving, I couldn't find a way to prevent them from moving.

I try something like this

NLineShape myLine = new NLineShape(0, 0, 1000, 0);

//add the ports to the line
myLine .CreateShapeElements(ShapeElementsMask.Ports);

NDynamicPort midPoint = new NDynamicPort(entityLine.UniqueId, ContentAlignment.TopCenter, DynamicPortGlueMode.GlueToContour);
myLine .Ports.AddChild(midPoint);
myLine .Ports.DefaultInwardPortUniqueId = midPoint.UniqueId;

I try both the logical line, but still gives the same problem.

I try to put a series of points on a line like this picture, but when the line is rotated or moved, I want the ports to remain on the lines without moving or changing location

Attachments
pict2.png (100 views, 13.00 KB)
Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi,

you want the ports to be fixed at there initial location and remain there even if you move or rotate the line. Is that right ? If not, please, elaborate.



Best Regards,
Nevron Support Team



Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
That's right, I want the ports to be fixed at their locations even when I move or rotate the line.

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Ok Volvick,

The easiest way to maintain the position of the port is to set the point you want it on to its Tag property and then constantly set it to its Location property each time a NodeBoundsChanged event occurs.

 

Here’s an example:

 

1.       Create the port:

 

NPointPort port = new NPointPort();

line.Ports.AddChild(port);

port.Location = new NPointF(100, 100);

port.Tag = new NPointF(100, 100);

 

 

2.       Subscribe to the NodeBoundsChanged event of the document’s event sink service:

 

document.EventSinkService.NodeBoundsChanged += new NodeEventHandler(EventSinkService_NodeBoundsChanged);

 

 

3.       Use the following code in the event handler:

 

private void EventSinkService_NodeBoundsChanged(NNodeEventArgs args)

{

      NShape shape = args.Node as NShape;

      if(shape == null)

            return;

 

      foreach (NPort port in shape.Ports)

      {

            if (port.Tag != null && port.Tag is NPointF)

            {

                  port.Location = (NPointF)port.Tag;

            }

      }

}



Best Regards,
Nevron Support Team



Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
Your solution should works, but there is something wrong with it. It looks like it only works for shape that are not added to the library.

Try this for instance

NLineShape lineShape = new NLineShape (0, 0, 500, 0);

this create an horizontal line.

Now try to add one port to it like

NPointPort port = new NPointPort();
line.Ports.AddChild(port);
port.Location = new NPointF(0, 0);
port.Tag = new NPointF(0, 0);

It does not matter you can put it anywhere one the line (presumably)

Now add it to the library, then when you drag it from the library, you can see that the point stays fix at location (0,0), as you move the line, the point does not move. So it looks like is not a part ofthe line. I spend times on it and I couldn't get it right. I try an example from the digram designer by using the logicalpoint line, it seems to work fine in the digram designer, but not outside the digram designer.

Hope you make it work


Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Volvick,

how do you add the shape to the library ? You can send your sample solution to our support e-mail and we'll tell you what's wrong with it.



Best Regards,
Nevron Support Team



Volvick Derose
Posted 14 Years Ago
View Quick Profile
Forum Guru

Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)Forum Guru (71 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 71, Visits: 1
I don't have a simple project to send you. I am working in a big project, it will take time for me to create a simple one, but here is an example code.

NLineShape lineShape = new NLineShape(0, 0, 400, 0);

lineShape.CreateShapeElements(ShapeElementsMask.Ports);

//add only one port

NPointPort port = new NPointPort();
lineShape.Ports.AddChild(port);
port.Location = new NPointF(0, 0);
port.Tag = new NPointF(0, 0);

lineShape.Name = "myLine";


//now add it to the library
NMaster myMaster = new NMaster(lineShape, NGraphicsUnit.Pixel, "line", "line");
nLibraryDocument1.AddChild(myMaster);

Then in the event sink I have

private void EventSinkService_NodeBoundsChanged(NNodeEventArgs args)
{
NShape myLine = args.Node as NShape;

if (myLine== null)
{
return;
}
else if (myLine.Name == "myLine")
{
foreach (NPort port in myLine.Ports)
{
if (port.Tag != null && port.Tag is NPointF)
{
port.Location = (NPointF)port.Tag;
}
}
}
}

All you need to do now, just drop the line from the library to the drawing are, you will see that point is not on the line. The only way to put it on the line, you have to drag it at location 0, 0.

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Volvick,

that's exactly what the goal was. The port always stays on a fixed location on the drawing suface, no matter what you do with the line shape. If this was not your intention, please explain more clearly what do you want to achive and will help you achieve it.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic