public MoveDiagramNodeCommand(IMoBiReactionBuildingBlock targetBuildingBlock, string targetNodeName, IBaseNode destinationNode) : base(targetBuildingBlock) { _destinationNode = destinationNode; _destinationParentLocation = destinationNode.GetParent().Location; _targetNodeName = targetNodeName; }
public bool ContainsChildNode(IBaseNode node, bool recursive) { if (recursive) { return(_nodes.Contains(node.Id)); } return(node.GetParent() == this); }
public static string GetLongName(this IBaseNode baseNode) { string longName = baseNode.Name; var parent = baseNode.GetParent() as IContainerNode; while (parent != null) { longName = parent.Name + "/" + longName; parent = parent.GetParent() as IContainerNode; } return(longName); }
public static IEnumerable <IContainerNode> GetParentNodes(this IBaseNode baseNode) { IList <IContainerNode> parentNodes = new List <IContainerNode>(); var parent = baseNode.GetParent() as IContainerNode; while (parent != null) { addUnique(parentNodes, parent); parent = parent.GetParent() as IContainerNode; } return(parentNodes); }
protected override void RemoveFrom(IReactionBuilder reactionBuilderToRemove, IMoBiReactionBuildingBlock reactionBuildingBlock, IMoBiContext context) { reactionBuildingBlock.Remove(reactionBuilderToRemove); if (reactionBuildingBlock.DiagramModel == null) { return; } _originalNode = reactionBuildingBlock.DiagramModel.FindByName(reactionBuilderToRemove.Name); if (_originalNode != null) { _originalParentLocation = new PointF(_originalNode.GetParent().Location.X, _originalNode.GetParent().Location.Y); // take a clone because we want to be able to put the node back to it's original place if this action is reverted _originalNode = _originalNode.Copy(); } reactionBuildingBlock.DiagramManager.RemoveObjectBase(reactionBuilderToRemove); }
public void RemoveNode(string id) { IBaseNode node = GetNode(id); if (node == null) { return; } IContainerBase parent = node.GetParent(); parent.RemoveChildNode(node); if (_nodes.Contains(id)) { _nodes.Remove(id); } }
/// <summary> /// Handle select event by selecting node. /// </summary> public void Handle(EntitySelectedEvent eventToHandle) { if (DiagramManager == null) { return; } if (!DiagramManager.MustHandleExisting(eventToHandle.ObjectBase.Id)) { return; } IBaseNode baseNode = DiagramModel.GetNode(eventToHandle.ObjectBase.Id); if (baseNode == null) { return; } IContainerBase parentContainer = baseNode.GetParent(); // Show node and parents baseNode.Hidden = false; baseNode.ShowParents(); _view.ExpandParents(baseNode); // Expand parent var parentContainerNode = parentContainer as IContainerNode; if (parentContainerNode != null) { Focus(parentContainerNode); } _view.ClearSelection(); _view.Select(baseNode); _view.CenterAt(baseNode); }
protected virtual void SetSelectionMenuItems(IContextMenuView contextMenuView, IContainerBase containerBase, IBaseNode node) { contextMenuView.AddMenuItem(SubMenuSelect); if (containerBase != null) { SubMenuSelect.AddItem(CreateMenuButton.WithCaption("All Children") .WithActionCommand(() => Presenter.SelectChildren(containerBase))); } if (Presenter.SelectionContains <IBaseNode>()) { SubMenuSelect.AddItem(CreateMenuButton.WithCaption("Visible Linked nodes") .WithActionCommand(() => Presenter.SelectVisibleLinkedNodesForDiagramSelection())); if (node != null) { SubMenuSelect.AddItem(CreateMenuButton.WithCaption("Invert Selection") .WithActionCommand(() => Presenter.InvertSelection(node.GetParent()))); } IHasLayoutInfo selectedNode = Presenter.GetFirstSelected <IHasLayoutInfo>(); if (selectedNode != null) { SubMenuDiagram.AddItem(CreateMenuCheckButton.WithCaption("Location Fixed").AsGroupStarter() .WithChecked(selectedNode.LocationFixed) .WithCheckedAction(locationFixed => Presenter.SetLocationFixedForDiagramSelection(locationFixed))); } contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("Hide Selection").WithActionCommand(() => Presenter.HideSelection())); } if (Presenter.SelectionContains <IElementBaseNode>()) { var subMenuNodeSize = CreateSubMenu.WithCaption("Nodesize") .WithItem(CreateMenuButton.WithCaption("Large").WithActionCommand(() => Presenter.SetNodeSizeForDiagramSelection(NodeSize.Large))) .WithItem(CreateMenuButton.WithCaption("Middle").WithActionCommand(() => Presenter.SetNodeSizeForDiagramSelection(NodeSize.Middle))) .WithItem(CreateMenuButton.WithCaption("Small").WithActionCommand(() => Presenter.SetNodeSizeForDiagramSelection(NodeSize.Small))); contextMenuView.AddMenuItem(subMenuNodeSize); } // Shows all children (e.g. after hiding a selection) if (containerBase != null) { contextMenuView.AddMenuItem(CreateMenuButton.WithCaption("Show All Children").WithActionCommand(() => Presenter.ShowChildren(containerBase))); } }
/// <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); }