Preventing a connection...

Jan 22, 2015 at 11:02 AM
Edited Jan 22, 2015 at 11:03 AM
Hi there I want to prevent a connection between a Polyline between two RoundedBox objects, when there are multiple up level connections already to prevent a cyclic situation. So I need to be able to:

1) Identify the source RoundedBox object, and the target RoundedBox object. I think I can do this as the repository_connectioninserted event get called twice, I think the first call contains the source object in e.TargetShape, and the target of the connection in the second calls e.TargetShape.
2) I now need to check the target RoundedBox connections and it's parents to see if any of these match the source RoundedBox, and if so prevent the connection from happening.

Can you advice the best approach to achieve this.
Coordinator
Jan 28, 2015 at 11:02 AM
1) The best approach would be to derive your own shape class and override/implement the method
    public abstract bool CanConnect(ControlPointId ownPointId, Shape otherShape, ControlPointId otherPointId);
This method will be called before creating the connection, so you do not have to deal with reverting connections etc.
Moreover, the Tools of the toolbox will not indicate a possible connection if this method returns false.

2) I think what you need is one of the following methods:
public abstract IEnumerable<ShapeConnectionInfo> GetConnectionInfos(ControlPointId ownPointId, Shape otherShape);
public abstract ShapeConnectionInfo GetConnectionInfo(ControlPointId gluePointId, Shape otherShape);
public abstract ControlPointId IsConnected(ControlPointId ownPointId, Shape otherShape);
You can...
  • ... override CanConnect in the MyRoundedBox class calling one of the line shape's (otherShape / otherPointId) methods (see above) for checking whether the other GluePoint is connected to another RoundedBox.
    Caution: Do not forget to check whether 'otherShape' is ILinearShape as there are also planar shapes that have gluePoints (e.g. the Label).
  • ... override CanConnect in the line shape calling the methods above for checking whether the other GluePoint is connected to another RoundedBox.
Usefull methods for this task:
public abstract bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability);
public abstract IEnumerable<ControlPointId> GetControlPointIds(ControlPointCapabilities controlPointCapability);
You can use ControlPointId.FirstVertex and ControlPointId.LastVertex for referencing the line shape's glue points (sticky ends).