We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Link state after ChildrenChangeComplete

Hi, After event OnChildrenChangeComplete of diagram I''m checking the existings links in the diagram with this for(int i=0; i
7 Replies

AD Administrator Syncfusion Team December 29, 2004 02:00 PM UTC

Hi Jose, This is the correct behavior. When the ChildrenChangeComplete event is generated, the newly added Link nodes will not have their From and To connections established. For Links object, use the Diagram.Model.ConnectionsChanging and Model.ConnectionsChangeComplete events to intercept or obtain information about the state of any newly formed Links. The event''s ConnectionCollection.EventArgs event argument provides information about the nature of the change and the Connection(s) that were involved. Examining the Connection object''s SourcePort and TargetPort properties for an object of type ''LinkPort'', and accessing the LinkPort''s Container property will let you get hold of the Link that was involved in the connection. The following code should help, // Handle the Diagram.ConnectionsChangeComplete event to determine when a new Link has been added or removed private void diagramComponent_ConnectionsChangeComplete(object sender, Syncfusion.Windows.Forms.Diagram.ConnectionCollection.EventArgs evtArgs) { if((evtArgs.ChangeType == Syncfusion.Windows.Forms.Diagram.CollectionEx.ChangeType.Insert) && (evtArgs.Connection != null)) { // A new connection was added to the Diagram. Examine the Connection object and // access the involved Link. Connection newconn = evtArgs.Connection; Link newlink = null; if(newconn.SourcePort is LinkPort) newlink = newconn.SourcePort.Container as Link; else if(newconn.TargetPort is LinkPort) newlink = newconn.TargetPort.Container as Link; if(newlink != null) MessageBox.Show("A new link was added to the Diagram"); } } There is an Essential Diagram KB article on this issue - http://www.syncfusion.com/Support/article.aspx?id=10556. The article, however, does not dwell on accessing the Link object from the event. I will go ahead and update it to do so for future reference. Regards, Prakash Syncfusion, Inc


JS Jose Santos December 29, 2004 02:33 PM UTC

Thanks. By the way, there seems to be a "little" problem. I can''t find documentation for ConnectionCollection.EventArgs Class so I don''t know what other properties/methods I may use. I suppose there''s a property to don''t allow the link to occur, right ? Another thing, can I activate the link tool with the tail port already assigned ? I made some experiments with the link factory but I didn''t achieve it. How''s this done ? Regards, Jose Santos


AD Administrator Syncfusion Team December 29, 2004 08:21 PM UTC

Jose, The automated class reference generation that we have been using has trouble handling nested classes and hence the missing documentation for the ConnectionCollection.EventArgs class. I have raised this issue with our development group and we will try to fix this problem before the next version of Essential Diagram. The ConnectionCollection.EventArgs class implements/inherits the following properties that you can access, /// Inherited from the CollectionEx.EventArgs base class /// Type of change that caused the event. public ChangeType ChangeType { get{...} } /// Zero-based index into the collection at which the event occurred. public int Index { get{...} set{...} } /// Indicates whether the operation should be cancelled. public bool Cancel { get{...} set{..l. } /// Defined in ConnectionCollection.EventArgs /// The connection involved in the event. public Connection Connection { get{...} } /// Array of connections involved in the event. public Connection[] Connections { get{...} } Please accept my apologies for the inconvenience and bear with us for the time being. Thanks, Prakash


AD Administrator Syncfusion Team December 29, 2004 08:55 PM UTC

Jose, As for activating the LinkTool with a partly initialized link, providing a default LinkFactory alone will not help. The best way to go about this would be to implement a custom LinkTool that is based on the Syncfusion.Windows.Forms.Diagram.Tool class and implements the Syncfusion.Windows.Forms.Diagram.IMouseEventReceiver interface. The base Diagram.LinkTool implementation can be cloned and re-used except for the IMouseEventReceiver.MouseUp method create where you will create the Syncfusion.Windows.Forms.Diagram.LinkCmd object with the source/target port that you want the Link to connect to. If your requirement necessitates it, you can also provide a custom implementation for the LinkCmd class that the LinkTool will use. If you have the source code version of Essential Diagram, please refer to the ''..Diagram.Base\Src\Tools\LinkTool.cs'' and ''..Diagram.Base\Src\Cmd\LinkCmd.cs'' files for details on implementing your LinkTool type. If you do not have the source version of the product, please send an email to ''prakashs@syncfusion.com'' referring to this forum post and I will send you the required files. Regards, Prakash


AD Administrator Syncfusion Team December 29, 2004 09:01 PM UTC

Please note that the custom link Tool type should not be a subclass of the Diagram.LinkTool, but instead will have to be a new Tool type that implements the Syncfusion.Windows.Forms.Diagram.Tool class and the Syncfusion.Windows.Forms.Diagram.IMouseEventReceiver interface. You will use this custom Tool type in your Diagram.Controller.ActivateTool() method (as shown in the DiagramBuilder sample) in place of the default ''LinkTool'' type. This is actually simpler than it sounds and referring to the base class implementation for the LinkTool and LinkCmd classes should help clarify things a great deal. Prakash


JS Jose Santos December 30, 2004 04:59 PM UTC

Hi, I''ve managed to do my DirectedLinkTool class. I did the following. Copy LinkTool.cs to LinkToolDirected.cs On the activate event I put this 2 lines: if(this.Controller.SelectionList.Count>0&&(this.Controller.SelectionList[0] is Symbol) SetSourcePort((this.Controller.SelectionList[0] as Symbol).CenterPort); In I''ve Copy the if(this.Controller.SelectionList.Count>0&&(this.Controller.SelectionList[0] is Symbol) SetSourcePort((this.Controller.SelectionList[0] as Symbol).CenterPort); And the SetSourcePort is: private void SetSourcePort(Port sourcePort){ System.Drawing.Point ptScreen = this.Controller.View.ViewToDevice(this.Controller.View.WorldToView(sourcePort.Location)); this.sourcePort = sourcePort; this.points.Add(ptScreen); this.tracking = true; this.InitTrackingPoints(ptScreen); if (this.trackingPts != null) this.Controller.View.DrawTrackingLines(this.trackingPts); } This seems to be working fine. I''m assuming the source port is the centerport of the selected node in diagram (which is exactly what I want here). Do you see any problem in my implementation ? Can this give problems in some cases ? By the way, why can''t I inherit from LinkTool and had to clone it ? Shouldn''t it work with inheritance also ?


AD Administrator Syncfusion Team January 3, 2005 08:48 PM UTC

Hi Jose, Based on the above code snippet I cannot see anything that might possibly induce errors in your implementation. If overriding the LinkTool.OnActivate() method is sufficient to add the extra functionality that you require, then subclassing the LinkTool will certainly do. The reason that I had advocated implementing the custom Tool class from scratch was that I had assumed you would have to overide(hide via inheritance) the base implementation of the IMouseEventReceiver interface methods, which would not have seemed very elegant. My apologies for this bit of confusion. Prakash Syncfusion, INc

Loader.
Live Chat Icon For mobile
Up arrow icon