Layout just new data

I have a scenario where multiple business objects can be dropped onto my WPF diagram in a single drag/drop operation. I’m then creating new node model objects and the nodes appear on my diagram at the drop point. But there’s an issue: the multiple objects exist at the same location so they visually overlap. How can I layout just these new nodes using something simple like a Grid layout?

Is it as simple as this?

  1. Define a GroupTemplateDictionary that includes my normal group templates plus an empty data template. Would this empty template also define the Layout for the group?
  2. Create a new node model (or perhaps always have one around) with a Category property that refers to this empty data template and has IsSubGraph=true.
  3. Create new node models for the dropped data.
  4. Set the SubGraphKey on the new node models to point to the node key created in step 2.
  5. Add the new node models to the diagram. A layout should now occur of just those nodes.
  6. When the layout completes, clear the SubGraphKey on every member of that group.
If that's roughly correct, I'm still a little unclear on how to wire up the layout to the group template and determine when it's done (is that just handling the Diagram.LayoutCompleted and then clearing my special group every time, even though it may be empty?).

If you really want to do something like that, it would be easier to use a MultiLayout and temporarily have the nodes (and links?) use the temporary layout’s LayoutId.

But it really sounds like overkill for this kind of situation.

You might instead just add some code in a Diagram.ExternalObjectsDropped event handler that iterates over the Diagram.SelectedParts collection and makes sure they are all positioned the way you want. This also has the advantage of being very context specific, so you can be smarter about the positioning than a more general purpose automatic layout would be.

I saw the Diagram.ExternalObjectsDropped event, but I couldn’t quite put together the call chain. It seems like it’s designed to work when both the source and target are GoXam controls (such as a Palette and a Diagram). I couldn’t work out how to make it work when dropping from a non-GoXam external source.

Yes, only other Diagrams have built-in support for conveying graphical model data to a target Diagram.

I assume you have already read the topics in this forum dealing with external drag and drop, such as:
http://www.nwoods.com/forum/forum_posts.asp?TID=3538
If you are talking about WPF, the data being transferred should be either an instance of your model’s NodeType, or an instance of IDataCollection if you want to support multiple node (and link) data objects at once.

If you cannot easily use your node data type or IDataCollection as source data, you can override DraggingTool.MayAcceptData and AcceptData to convert whatever data formats you want into IDataCollection.