public void Copy(IContainerBase sourceTopContainer, IContainerBase targetTopContainer) { if (sourceTopContainer == null || targetTopContainer == null) { return; } bool expanded = true; PointF location = targetTopContainer.Location; int topLevelsToSkip = 0; var targetContainerNode = targetTopContainer as IContainerNode; if (targetContainerNode != null) { expanded = targetContainerNode.IsExpanded; location = targetContainerNode.Location; targetContainerNode.IsExpanded = true; topLevelsToSkip = 1; } foreach (var targetNode in targetTopContainer.GetDirectChildren <IContainerNode>()) { copyContainerRecursive(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip); var sourceNode = getNodeByPath(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip); if (sourceNode == null) { continue; } targetNode.CopyLayoutInfoFrom(sourceNode, location); } foreach (var targetNode in targetTopContainer.GetDirectChildren <IElementBaseNode>()) { var sourceNode = getNodeByPath(sourceTopContainer, targetTopContainer, targetNode, topLevelsToSkip); if (sourceNode == null) { continue; } targetNode.CopyLayoutInfoFrom(sourceNode, location); } if (targetContainerNode != null) { targetContainerNode.IsExpanded = expanded; targetContainerNode.Location = location; var sourceContainerNode = sourceTopContainer as IContainerNode; if (sourceContainerNode != null) { targetContainerNode.IsExpandedByDefault = sourceContainerNode.IsExpandedByDefault; } } }
public XmlDocument ContainerToXmlDocument(IContainerBase containerBase) { GoXmlWriter writer = new GoXmlWriter(); RegisterTransformers(writer); // containerBase can be Document or GoNode var diagramModel = containerBase as IDiagramModel; if (diagramModel != null) { writer.Objects = (IEnumerable)diagramModel; } else // containerBase is IContainerBaseNode { writer.Objects = containerBase.GetDirectChildren <IBaseNode>(); } writer.RootElementName = ElementName; var xmlDoc = writer.Generate(); xmlDoc.DocumentElement.SetAttribute(LocationX, containerBase.Location.X.ToString()); xmlDoc.DocumentElement.SetAttribute(LocationY, containerBase.Location.Y.ToString()); return(xmlDoc); }
public void SelectChildren(IContainerBase containerBase) { _view.ClearSelection(); foreach (var baseNode in containerBase.GetDirectChildren <IBaseNode>()) { _view.Select(baseNode); } _view.Refresh(); }
public void CopyRecursive(IContainerBase source, IContainerBase target) { foreach (var targetChild in target.GetDirectChildren <IContainerNode>()) { CopyRecursive(source, targetChild); } Copy(source, target); }
public void InvertSelection(IContainerBase containerBase) { IList <IBaseNode> notSelectedNodes = new List <IBaseNode>(); foreach (var baseNode in containerBase.GetDirectChildren <IBaseNode>()) { if (!_view.SelectionContains(baseNode)) { notSelectedNodes.Add(baseNode); } } _view.ClearSelection(); foreach (var baseNode in notSelectedNodes) { _view.Select(baseNode); } }
private IEnumerable <IContainerBase> getExpandedChildren(IContainerBase containerBase, int level) { var children = new List <IContainerBase>(); if (level == 0) { children.Add(containerBase); } else { foreach (var childContainerNode in containerBase.GetDirectChildren <IContainerNode>()) { if (childContainerNode.IsExpanded) { children.AddRange(getExpandedChildren(childContainerNode, level - 1)); } } } return(children); }
private void replaceInnerNeighborhoodNodesByDirectLinks(IContainerBase containerBase, GoLayoutForceDirectedNetwork net) { // replace neighborhood nodes and neighbor links by direct links between the nodes they connect (ContainerNodes or PortNodes) foreach (var neighborHoodNode in containerBase.GetDirectChildren <INeighborhoodNode>()) { var fromLink = net.FindLink(neighborHoodNode.FirstNeighborLink as GoObject); var toLink = net.FindLink(neighborHoodNode.SecondNeighborLink as GoObject); if (fromLink == null || toLink == null) { continue; } var netLink = new GoLayoutForceDirectedLink { FromNode = fromLink.ToNode, ToNode = toLink.ToNode }; netLink.GoObject = neighborHoodNode as GoObject; netLink.Length = Config.BaseSpringLength * Config.RelativeSpringLengthOf[NodeLayoutType.CONTAINER_NODE, NodeLayoutType.CONTAINER_NODE].Value; netLink.Stiffness = Config.BaseSpringLength * Config.RelativeSpringStiffnessOf[NodeLayoutType.CONTAINER_NODE, NodeLayoutType.CONTAINER_NODE].Value; net.DeleteNode(neighborHoodNode as GoObject); net.AddLink(netLink); } }
public void PerformLayout(IContainerBase containerBase, IList <IHasLayoutInfo> freeNodes) { string text = "DiagramModel"; var containerBaseNode = containerBase as IContainerNode; if (containerBaseNode != null) { text = containerBaseNode.GetLongName(); } if (Config.LogPositions) { Console.WriteLine("PerformLayout for " + text + " with Bounds " + containerBase.Bounds); } ContainerBaseBounds = containerBase.Bounds; var originalBounds = containerBase.Bounds; var originalLocation = containerBase.Location; var net = CreateNetwork(); net.AddNodesAndLinksFromCollection(containerBase as IGoCollection, true); foreach (var n in containerBase.GetDirectChildren <IContainerNode>()) { if (n.Name == Captions.MoleculeProperties) { _mpNode = net.FindNode((GoObject)n); break; } } if (Config.LogPositions) { PrintNodes("<", net); } if (Config.LogPositions) { PrintLinks("<", net); } if (containerBaseNode != null) { insertExternalNeighborLinks(containerBaseNode, net); } if (Config.LogPositions) { PrintNodes("+extNeighborLinks ", net); } if (Config.LogPositions) { PrintLinks("+extNeighborLinks ", net); } // delete invisible nodes before replacing inner neighborhoods by links, to keep "end" neighbor nodes as nodes deleteInvisibleNodes(net); if (Config.LogPositions) { PrintNodes("-invisible ", net); } if (Config.LogPositions) { PrintLinks("-invisible ", net); } // Remove neighborhood nodes and neighbor links and insert direct links between the nodes they connect (ContainerNodes or PortNodes) replaceInnerNeighborhoodNodesByDirectLinks(containerBase, net); if (Config.LogPositions) { PrintNodes("+intNeighborLinks ", net); } if (Config.LogPositions) { PrintLinks("+intNeighborLinks ", net); } setNodeType(net, freeNodes); Network = net; if (Config.LogPositions) { PrintNodes("<", net); } if (Config.LogPositions) { PrintLinks("<", net); } if (net.NodeCount > 0) { base.PerformLayout(); } if (Config.LogPositions) { PrintNodes(">", net); } if (Config.LogPositions) { Console.WriteLine(" Bounds " + containerBase.Bounds); } var newBounds = containerBase.CalculateBounds(); if (Config.LogPositions) { Console.WriteLine(" After " + newBounds + "ComputeBounds: Bounds " + containerBase.Bounds); } if (containerBaseNode != null && containerBaseNode.LocationFixed) { containerBase.Location = originalLocation; } PointF containerTranslation = containerBase.Bounds.Location.Minus(originalBounds.Location); foreach (var netNode in net.Nodes) { netNode.GoObject.Position = netNode.GoObject.Position.Minus(containerTranslation); } if (Config.LogPositions) { Console.WriteLine(" Bounds " + containerBase.Bounds); } }
/// <summary> /// finds node in container with same name, type and parent containers as other node /// container can be a ContainerBaseNode (with name) or BaseDiagram (without name) /// </summary> private IBaseNode getNodeByPath(IContainerBase container, IContainerBase otherContainer, IBaseNode otherNode, int topLevelsToSkip) { string otherContainerName = otherContainer.IsAnImplementationOf <IContainerNode>() ? ((IContainerNode)otherContainer).Name : ""; bool nameFound; IContainerBase parent = container; // fill otherParentNodes with Parent nodes of otherNode IList <IContainerNode> otherParentNodes = new List <IContainerNode>(); var parentNode = otherNode.GetParent() as IContainerNode; // find corresponding parent by path in container if (parentNode != null) { otherParentNodes.Insert(0, parentNode); while (parentNode != null && parentNode != otherContainer) { parentNode = parentNode.GetParent() as IContainerNode; if (parentNode != null) { otherParentNodes.Insert(0, parentNode); } } // skip/neglect topLevels for (int i = 0; i < topLevelsToSkip && otherParentNodes.Count > 0; i++) { otherParentNodes.RemoveAt(0); } // navigate down in container using the names of otherParentNodes parent = container; nameFound = true; foreach (var otherParentNode in otherParentNodes) { nameFound = false; // find container with same name as otherParentNode foreach (var containerNode in parent.GetDirectChildren <IContainerNode>()) { if (compareNames(containerNode.Name, otherParentNode.Name, otherContainerName)) { parent = containerNode; nameFound = true; break; } } if (!nameFound) { break; } } } // find node in corresponding container with same name and type as otherNode nameFound = false; IBaseNode node = null; foreach (var baseNode in parent.GetDirectChildren <IBaseNode>()) { if (compareNames(baseNode.Name, otherNode.Name, otherContainerName)) { node = baseNode; nameFound = true; break; } } if (!nameFound) { return(null); } if (!compareTypes(node, otherNode)) { return(null); } return(node); }
public void HideChildren(IContainerBase containerBase) { setHidden(containerBase.GetDirectChildren <IBaseNode>(), true); }
public void ShowChildren(IContainerBase containerBase) { setHidden(containerBase.GetDirectChildren <IBaseNode>(), false); }