Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to correctly nest DiagramItems? (Read 2393 times)
roger huber
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Nov 8th, 2016
How to correctly nest DiagramItems?
Nov 8th, 2016 at 1:16pm
Print Post  
Hello everybody,

In my domain model I have kind of composite pattern that allows to nest diagrams. If I have diagramA->diagramB>nodeX, I use the following types in the UI layer:

diagramA:Diagram
diagramB:ContainerNode
nodeX:DiagramNodeAdapter

I asked myself how I have to add nodeX (or any other decendant diagram) so that it is visible in diagramA. I tried the following:

- diagramB.Add(nodeX) will throw a NullReferenceException when Mindfusion wants to create the subordinate group.
- nodeX.AttachTo(diagramB) ditto

Since the constructor overload DiagramNodeAdapter(Diagram parent, UIElement item) doesn't set DiagramItem's Parent:Diagram property, the NullReferenceException will be thrown.

However, the following works:

Code
Select All
diagramA.Nodes.Add(nodeX);
diagramB.Add(nodeX); 



So I have three questions:

  1. I saw that Add calls AttachTo under the hood. What does Add what AttachTo doesn't do? Wich one shall I use?

    Code
    Select All
    diagramA.Nodes.Add(nodeX);
    diagramB.Add(nodeX); 
    
    

    or

    Code
    Select All
    diagramA.Nodes.Add(nodeX);
    nodeX.AttachTo(diagramB); 
    
    
  2. Is it the best idea to have diagramA hosting all descendant "diagrams", nodes and links? I can see one benefit of that: Given MouseInputMode.HandledByDiagram, a event handler for e.g. NodeModified can easily delegate the work to the right DiagramNode.
  3. Is there a chance to get relative positions when e.g. NodeModified or LinkModified is fired? Or do I have to convert the data myself?


Thanks for your help!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3378
Joined: Oct 19th, 2005
Re: How to correctly nest DiagramItems?
Reply #1 - Nov 8th, 2016 at 3:00pm
Print Post  
Hi,

ContainerNodes just group other elements of same parent diagram, so whatever you add to a container must be added to the diagram indeed.

Quote:
1.I saw that Add calls AttachTo under the hood. What does Add what AttachTo doesn't do? Wich one shall I use?


There'll be some difference if you fold the container - attached nodes won't hide but added one will do. We plan to re-implement containers without using groups soon, so Add won't use AttachTo then anyway.

Quote:
2.Is it the best idea to have diagramA hosting all descendant "diagrams", nodes and links? I can see one benefit of that: Given MouseInputMode.HandledByDiagram, a event handler for e.g. NodeModified can easily delegate the work to the right DiagramNode.


From our side it's much easier if the diagram has direct access to all nodes including children in containers, especially in situations such as links connecting nodes from different containers, moving child nodes between containers, etc. Maybe you could implement true nesting by showing a child Diagram inside DiagramNodeAdapter inside the parent Diagram, as long as you don't need to draw links between nodes of child diagrams, and doing some re-parenting of child nodes when moving between containers.

Quote:
3.Is there a chance to get relative positions when e.g. NodeModified or LinkModified is fired? Or do I have to convert the data myself?


There's the TransformDiagramToItem method you could use to transform a child node's position to container-relative one:

Code
Select All
void OnContainerChildAdded(object sender, ContainerChildEventArgs e)
{
	var diagramPos = e.Node.Bounds.Location;
	var localPos = e.Container.TransformDiagramToItem(diagramPos);
	Debug.WriteLine("diagram: " + diagramPos);
	Debug.WriteLine("local: " + localPos);
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
roger huber
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Nov 8th, 2016
Re: How to correctly nest DiagramItems?
Reply #2 - Nov 10th, 2016 at 8:19pm
Print Post  
Thank you Slavcho for your quick and helpful answer!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint