This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is it possible to allow multiple connections to a single connection point. In the "More than 4 connection points" post I read the following Create a custom node type. Do this by looking at the CustomNodeType sample, or let me know if you need more information.
This makes it sound like the only way to have multiple connections to a point is to continually add more points. To allow unlimited connections I would then need to setup some sort of dynamic adding mechanism. Is there a simpler way to just allow multiple connections to the 4 connections created at the time of construction.
|
|
|
Hello Greg Yes a single connection point can be set up to accept any number of connections. In flow diagrams, the built in logic states that a process node can only have a single outbound connection, but can receive any number of inbound connections. Sounds like you want to override this behaviour to have any number of inbound and outbound connections on any point. To do this, you can create a custom node and override the CanReceiveNewConnections and CanOriginateNewConnections to both return true. Regards |
|
|
I tried overriding the property referenced above in a custom node. However each connection point is still limited to only on inbound and outbound connection. I want to be able to have an arbitrary number for each connection point. |
|
|
Hello Greg I missed out on a detail. You'll also need to extend OutboundConnectionPoint and override CanOriginateNewConnections to return true, and extend InboundConnectionPoint to override CanReceiveNewConnections to return true. These will both need a constructor that takes a FlowDiagramNode and an Edge parameter which can simply be pased to the base constructor. Then in the custom node constructor, use these custom connection points rather than the flow diagram ones. Note that we will soon be releasing WPF diagrams 2.0 which comes with a new diagram type which doesn't have any constraints on the connection points or nodes just like what you want. (along with many other improvements) - Jason |
|
|
Hey Jason, I am still on Diagrams 1.0 and I successfully followed your instructions to Greg. I extended the OutboundConnectionPoint class to allow multiple outputs from a point on a decision node. However when I add text to multiple connections at the same outbound point, the text from one connection overlays the text from the other connection. Is there a way to cause the Data (Text) on the FlowDiagramConnection to appear in the middle of the connection rather than at the "From" end of the connection. My application needs a variable number of outbound connections (that can be annotated with text) from a single decision node. Thanks in advance, John Fingerlin |
|
|
Hello John I have attached a simple example of how to display the connection data in the center of the connection path. To achieve this, I created a custom connection style which gets applied to all the connections in the diagram. Rather than using triggers to position the connection data presenter like the default styles do, I have set the RenderTransform of the data presenter using a binding to the Segments property with a custom converter. This can be seen on line 84 of MainWindow.xaml. The custom converter takes the collection of DiagramConnectionSegment objects that make up the connection path, and obtains the center segment based on index. It then uses the StartPoint and EndPoint properties of this segment to calculate the center of the segment which is used in the returned TranslateTransform. My implementation is very simple but it is a great place to start. You may want to change this to use a multi binding with a multi value converter so you can use other information such as the width and height of the data presenter in your calculations. You may also want to use the center of the connection path based on length rather than segment index. To run the sample, you will need to include a reference to your copy of the FlowDiagrams and Foundation dlls. Let us know how it goes. |
|
|
Jason, Your sample worked fine when I added it to my code. Thank you. Can you point me to some code that adds another connection point at the midpoint between the Top and Right Edges (say "TopRight") on the Decision node? I saw an enum for Edge that only had 4 values: Top, Right, Bottom and Left. I wasn't sure how to extend the number of Points/Edges. John |
|
|
Hello John To include more connection points, you will need to create a custom node. Take a look at the CustomNodeType sample. You can set up all the connection points you need in the constructor of a custom node as seen in the SendMessageNode and WaitNode classes. To set the positions of the connection points, you use a calculator selector in the diagram style. A calculator selector can be seen on line 113 of MainWindow.xaml. Here you create mappings between the Edge property of the connection point, the type of node the connection point is on, and the calculator selector that the connection point should use. In general you should use the OffsetPositionCalculator. Here you can set the XFactor and YFactor values. These are generally values between 0 and 1. For example, with the XFactor, 0 is the left of the node, 0.5 would be center, and 1 is the right side and so on. For the "TopRight" position that you need, (assuming your custom node will have the same diamond shape as a decision), you will want XFactor = 0.75, YFactor = 0.25. So the Edge enum doesn't define where the connection points actually get rendered. It just specifies which edge it is placed on which can be used for selecting the calculator. It is also used by the connection pathfinders to work out which direction the connections should come in and out of the nodes. Your TopRight connection point should either have an edge of "Top" or "Right". If you still want all the other four connection points as seen on a DecisionNode, then you're going to end up with an edge that has more than 1 connection point. To support this you will need to create a custom connection point, custom connection point calculator, and a custom calculator selector. An example of these can be seen in the FlowDiagrams.ConnectionPointRelocation sample. You should be able to copy the 3 classes you need from here. Let us know if you need further information. |
|
|
Jason, I have not found the FlowDiagrams.ConnectionPointRelocation sample. Is it in WPF Diagrams 2? - John |
|
|
Hello John There is a version of the sample that is compatable with Diagrams 1.0, but turns out it's not included in the samples solution. So I have attached it to this post instead so you can start working with it right away. Make sure to include a reference to your copy of the FlowDiagrams and Foundation dlls if you need to run it. - Jason |
|
|
I adapted the sample code into my classes and it works now. Thanks! |
|
|
Hello Jason, Seems I have small problem. The code works but I am getting the run time error below which I also get when I run the CenterConnectionDataSample. This was the example that moved the Connection Data (text) to the middle of the connection line. System.Windows.Data Error: 40 : Any ideas on how to correct this? Thanks, John |
|
|
Hell John I have not been able to reproduce this run time error at my end. It may just be something to do with your version of Visual Studio. You could try to download the latest nightly builds to see if this solves the problem. Nightly builds for WPF Diagrams 1.0 can be downloaded from your account page. If this still does not fix the issue, please list the steps that can reproduce the error. - Jason |
|