I’d like to decide if the new node dragged is dropped onto an otherone.
If such, I want not only add the new node but also add a link between the new node and the node below, and finally deplace the new node location for readability.
But I don’t use the “group” node model.
All my node have the same type.
May i override some draggingtool functions or may i modify my PartManager.AddedNode overriding ?
I have soon override DraggingTool to decide to move all part’s node if “hidden”.
public class MyDragDropTool : DraggingTool
{
private void GetEffectiveCollection(List<Part> oPartList, Node oNode)
{
foreach (Link l in oNode.FindLinksOutOfPort("Out"))
{
Node n = l.GetOtherNode(oNode);
if (n != null && n != oNode)
{
oPartList.Add(n);
GetEffectiveCollection(oPartList, n);
}
}
}
public override Dictionary<Part, Info> ComputeEffectiveCollection(IEnumerable<Part> parts)
{
List<Part> MyPart = new List<Part>();
foreach (Part oPart in parts)
{
MyPart.Add(oPart);
if (oPart is Node)
{
Node oNode = (Node)oPart;
MyNodeData oData = (MyNodeData)oNode.Data;
//if a SphPart is closed (not expanded) all the inside node should move with the part
if (oData != null && !oData.EverExpanded)
{
GetEffectiveCollection(MyPart, oNode);
}
}
}
Dictionary<Part, Info> oCol = base.ComputeEffectiveCollection(MyPart);
return oCol;
}
Maybe, I make a mistake, should I use group ?
Aurore
Are you using the latest version 1.1 beta? If so, you might not need to customize the DraggingTool.
Just set the Part.DropOntoBehavior. For example, look at the new behavior in the OrgChartEditor sample. When the user drops a node over another node, a link is drawn from the stationary node to the dropped node. This is implemented by adding this attribute to the node’s DataTemplate:
go:Part.DropOntoBehavior="AddsLinkFromNode"
No Groups needed.
Then, whether the dropped node is moved or not depends on what Diagram.Layout there is and under what conditions it performs layouts.
The default Layout only moves Nodes to give them a Location if they don’t already have one. But since the user’s dropping of a Node already assigns a Location for the new Node, it won’t move. So you’ll need to implement a Diagram.ExternalObjectsDropped event handler to shift the dropped Node(s), which are accessible via the Diagram.SelectedParts collection.
For the other kinds of Layout, the standard conditions will automatically cause a layout to be performed when adding a Node or a Link, so the dropped node(s) will be moved without any coding on your part.
I have the latest version (1.1.0.3), I see the above option. but I don’t understand.
When I run the sample, I can create new guy with double-click but when I drop a node over another one, nothing change.
It appears from your definitions that when the user drops a Node onto either a QDPart or a QDGroup, it will also create a new Link from that QDPart or QDGroup to that dropped Node. Was that your intent?
I can’t tell from your templates whether a QDGroup node is actually a Group node or not. Only Group nodes can have member Nodes and member Links. If it is a Group, then specifying go:Part.DropOntoBehavior=“AddsToGroup” will have the effect of adding dropped Nodes to the Group as new members.
Well, that’s puzzling. I wonder what else of importance might be different from the OrgChartEditor sample and our internal test cases.
Could you define a custom DraggingTool and look at the values of a couple of predicates during the drag?
public class CustomDraggingTool : DraggingTool {
protected override bool ConsiderDragOver(Point pt, Part p) {
bool result = base.ConsiderDragOver(pt, p);
System.Diagnostics.Debug.WriteLine("ConsiderDragOver: " + result.ToString());
return result;
}
public override bool IsValidLink(Node fromnode, Node tonode, Link relink) {
bool result = base.IsValidLink(fromnode, tonode, relink);
System.Diagnostics.Debug.WriteLine("IsValidLink: " + result.ToString());
return result;
}
}
and install by replacing the Diagram.DraggingTool:
Maybe you can get a clue about what's going on this way. You'll probably need to improve the information that is displayed, and perhaps you'll want to set breakpoints here or on other methods to look at the arguments more carefully.