This project has moved and is read-only. For the latest updates, please go here.

For Shape, how to provide a control point which only for output?

Oct 13, 2015 at 9:29 AM
I have a feature requirement: for one shape, 1 control points, I want this control point only can be connected (Input), but don't want it connect to other shape(output), how to do that? any hints?

I know in DiamondBase class, HasControlPointCapability(...) function,
return ((controlPointCapability & ControlPointCapabilities.Connect) != 0 && IsConnectionPointEnabled(controlPointId));
this line of code seems allow other shape can connect those points(input).
but I want also these points cannot be connect to other shape.

Thanks in advance.
Oct 15, 2015 at 8:09 AM
There are two types of control points in Shape, active connection points (e.g. the end of lines) and passive onnection points (e.g. all connection points of a diamond shape).
The active connection points ('glue' points, capability: ControlPointCapabilities.Glue) are able to establish or dismiss a connection to a passive connection point (capability: ControlPointCapabilitiesConnect). Moreover, they follow the passive connection point if it moves. The only shapes (shipped with NShape) that have active connection points are the different types of lines and the label shape.

If I understand correctly, 'input' connections should match the passive connection points while 'output' connection should match the active connection points, right?
return ((controlPointCapability & ControlPointCapabilities.Connect) != 0 && IsConnectionPointEnabled(controlPointId));
This line defines the behavior of a passive connection point.


Hope this helps.
Oct 16, 2015 at 3:09 AM
This is not my want, maybe my description is not good.
For ShapeA->PointA, I defined "return ((controlPointCapability & ControlPointCapabilities.Connect) != 0 && IsConnectionPointEnabled(controlPointId)); "
Now can draw a line from ShapeB->PointB to ShapeA->PointA,
but at the same time, I also want: Forbid from ShapeA->PointA to Any other points (ShapeB->PointB), how to do that?

Or, if user add a connection line at start point ShapeA->PointA, how to get that click event at the start point, so I can add some "if" code to forbid it.

Thanks in advance.
Oct 16, 2015 at 12:23 PM
Edited Oct 16, 2015 at 1:31 PM
Try overriding Shape's method
public abstract bool CanConnect(ControlPointId ownPointId, Shape otherShape, ControlPointId otherPointId);
I case you need to know if the connecting line has a direction, you can add such a direction property, check the CapStyle of the line (e.g. Polyline.StartCapStyle, PolyLine.EndCapStyle) or the connecting point which should be ControlPointId.FirstVertex or ControlPointId.LastVertex for linear shapes.
Oct 18, 2015 at 3:48 AM
In myShape class which derive from ShapeBase, CanConnect() works only if this Shape is as TargetShape,
I debug NShape code, if I drag myShape into Diagram and try to add LinearShape from MyShape,
in my case if myShape'ControlpointID is not I want, I want to skip this action (AddLine action)
I think I may need update code in Tools.cs ProcessMouseClick(...) and in Creatline(), if the sourceShape is myShape, just skip it.

I think update Tool.cs code may not the good way,
do I need write another myLinearShape class?

What's your hints? Thanks .
Nov 2, 2015 at 1:55 PM
I think the best way would be to derive your own LinearShapeCreationTool and override the ProcessMouseEvent method:
In this method, you will have access to the IDiagrampresenter (which is in most cases the Display component) and the MouseEventArgsDg which is an UI technique independent version of the WinForms mouse event args.

The IDiagramPresenter interface provides methods for converting coordinates and to the diagram itself.
The diagram provides a ShapeCollection that offers methods for searching shapes (don't worry, searching shapes is fast even if there are many shapes in the diagram).

The strategy would now be to find all shapes at the current mouse position (in diagrmam coordinates) and test whether the shape of the tool's template (this.Template.Shape) can connect to any of the shape of the found shapes. If not, do nothing and return true (for signalling the diagram presenter that the tool has processed the mouse event). Otherwise, call the base class' ProcessMouseEvent method.