/// <summary> /// Gets the path of a DomNode and converts it to an AdaptablePath<object></summary> /// <param name="domNode">DomNode</param> /// <returns>Object path to the specified DomNode</returns> public static AdaptablePath <object> AdaptDomPath(DomNode domNode) { List <object> path = new List <object>(); while (domNode != null) { foreach (DomNode pnode in domNode.Lineage) { path.Add(pnode); } domNode = null; IGame game = Adapters.As <IGame>(path.Last()); if (game != null && game.Parent != null) { DomNode gameRef = game.Parent.Cast <DomNode>(); path[path.Count - 1] = gameRef; domNode = gameRef.Parent; } } path.Reverse(); AdaptablePath <object> adaptablePath = new AdaptablePath <object>(path); return(adaptablePath); }
private bool UpdateSelection(object item, Keys modifiers, bool isSelected, AdaptablePath <object> hitPath) { bool result = false; if ((modifiers & m_toggleModifierKey) != 0) { m_selectionContext.Toggle(item); result = !isSelected; } else if ((modifiers & m_extendModifierKey) != 0) { m_selectionContext.Add(item); result = true; } else { if (isSelected) { m_selectionContext.Add(item); } else { m_selectionContext.Set(item); } result = true; } UpdateSelectionPath(item, hitPath); return(result); }
/// <summary> /// Traverses a given path of groups, starting at the last (picked) item through a given destination group, for the pin /// that corresponds to the given group pin in the last group in the path. The last (innermost) group of "hitPath" is the picked item.</summary> /// <typeparam name="TEdgeRoute">Pin</typeparam> /// <param name="hitPath">Path of groups to traverse</param> /// <param name="destNode">Destination group (last group to search) which contains the pin searched for</param> /// <param name="hitRoute">Pin in innermost group where search begins</param> /// <returns>Group pin in destination group "destNode" corresponding to "hitRoute" group pin in innermost group in path</returns> static public TEdgeRoute EdgeRouteTraverser <TEdgeRoute>(AdaptablePath <object> hitPath, object destNode, TEdgeRoute hitRoute) where TEdgeRoute : class, ICircuitPin { if (!hitPath.Last.Is <Element>()) { return(null); } int fromIndex = hitPath.Count - 1; //start from the hit sub-item int toIndex = hitPath.IndexOf(destNode); if (toIndex < 0 || toIndex > fromIndex) { return(null); } var circuitPin = hitRoute; var currentElement = hitPath.Last; for (int i = fromIndex - 1; i >= toIndex; --i) { ICircuitPin matchedPin = null; var parent = hitPath[i]; if (parent.Is <Group>()) { var group = parent.Cast <Group>(); foreach (var pin in group.AllInputGroupPins) { var grpPin = pin.Cast <GroupPin>(); if (grpPin.InternalElement.Equals(currentElement) && grpPin.InternalElement.InputPin(grpPin.InternalPinName) == circuitPin) { matchedPin = grpPin; break; } } if (matchedPin == null) { foreach (var pin in group.OutputGroupPins) { var grpPin = pin.Cast <GroupPin>(); if (grpPin.InternalElement.Equals(currentElement) && grpPin.InternalElement.OutputPin(grpPin.InternalPinName) == circuitPin) { matchedPin = grpPin; break; } } } } if (matchedPin == null) { return(null); } circuitPin = matchedPin.Cast <TEdgeRoute>(); currentElement = parent; } return(circuitPin); }
/// <summary> /// Updates selection path for the given item</summary> /// <param name="item">Item to update selection path for</param> /// <param name="path">New path</param> public void UpdateSelectionPath(object item, AdaptablePath<object> path) { if (m_selectionContext.SelectionContains(item)) { // item added or remain in selection, update hit path if (m_selectionPathMap.ContainsKey(item)) m_selectionPathMap[item] = path; else m_selectionPathMap.Add(item, path); } }
/// <summary> /// Updates selection path for the given item</summary> /// <param name="item">Item to update selection path for</param> /// <param name="path">New path</param> public void UpdateSelectionPath(object item, AdaptablePath <object> path) { if (m_selectionContext.SelectionContains(item)) { // item added or remain in selection, update hit path if (m_selectionPathMap.ContainsKey(item)) { m_selectionPathMap[item] = path; } else { m_selectionPathMap.Add(item, path); } } }
/// <summary> /// Gets the path of a DomNode and converts it to an AdaptablePath<object></summary> /// <param name="domNode">DomNode</param> /// <returns>Object path to the specified DomNode</returns> public static AdaptablePath<object> AdaptDomPath(DomNode domNode) { List<object> path = new List<object>(); while (domNode != null) { foreach (DomNode pnode in domNode.Lineage) path.Add(pnode); domNode = null; IGame game = Adapters.As<IGame>(path.Last()); if (game != null && game.Parent != null) { DomNode gameRef = game.Parent.Cast<DomNode>(); path[path.Count - 1] = gameRef; domNode = gameRef.Parent; } } path.Reverse(); AdaptablePath<object> adaptablePath = new AdaptablePath<object>(path); return adaptablePath; }
private bool UpdateSelection(object item, Keys modifiers, bool isSelected, AdaptablePath<object> hitPath ) { bool result = false; if ((modifiers & m_toggleModifierKey) != 0) { m_selectionContext.Toggle(item); result = !isSelected; } else if ((modifiers & m_extendModifierKey) != 0) { m_selectionContext.Add(item); result = true; } else { if (isSelected) m_selectionContext.Add(item); else m_selectionContext.Set(item); result = true; } UpdateSelectionPath(item, hitPath); return result; }
/// <summary> /// Inserts the specified child into the specified parent</summary> /// <param name="parent">Parent to insert into</param> /// <param name="child">Child to be inserted</param> /// <remarks>This method is used by copy-paste and drag-drop from various sources. /// When making any changes to this method, please test the following: /// - Copy/Paste, Cut/Paste /// - Drag-drop from {Palette|ResourceLister} to {ProjectLister|DesignView} /// Pay special attention to: /// - (GameObjects with) GameObjectReferences /// - (GameObjects with) ResourceReferences incl. Locators /// - GameObjectGroups (and hierarchies thereof) /// - GameObjectFolders (and hierarchies thereof) /// - Pasting the same objects more than once</remarks> public void Insert(object parent, object child) { if (!CanInsert(parent, child)) { return; } var hierarchical = parent.AsAll <IHierarchical>(); // Extract node list from IDataObject IEnumerable <object> items = Util.ConvertData(child, true); DomNode parentRoot = null; DomNode parentNode = parent.As <DomNode>(); if (parentNode != null) { parentRoot = parentNode.GetRoot(); } List <DomNode> copyList = new List <DomNode>(); List <object> objectlist = new List <object>(); foreach (object item in items) { if (item.Is <IGameObject>() || item.Is <IGameObjectFolder>()) { DomNode childNode = item.As <DomNode>(); DomNode childRoot = childNode.GetRoot(); if ((parentRoot != null && childRoot.Is <IGame>() && parentRoot != childRoot)) { childNode.RemoveFromParent(); copyList.Add(childNode); continue; } } objectlist.Add(item); } if (copyList.Count > 0) { IEnumerable <DomNode> copies = DomNode.Copy(copyList); // remvoe lock foreach (DomNode copy in copies) { this.SetLocked(copy, false); } objectlist.AddRange(copies); } foreach (object obj in objectlist) { DomNode node = obj.As <DomNode>(); if (node != null) { node.InitializeExtensions(); } } List <DomNode> insertedNodes = new List <DomNode>(); foreach (object obj in objectlist) { object insertedObj = null; bool inserted = false; foreach (var h in hierarchical) { if (h.AddChild(obj)) { inserted = true; break; } } if (inserted) { insertedObj = obj; } else { IResource res = obj as IResource; var gob = m_resourceConverterService.Convert(res); foreach (var h in hierarchical) { if (h.AddChild(gob)) { inserted = true; break; } } if (inserted) { insertedObj = gob; } } DomNode insertNode = Adapters.As <DomNode>(insertedObj); if (insertNode != null) { insertedNodes.Add(insertNode); } } IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(insertedNodes); List <object> newSelection = new List <object>(); foreach (DomNode rootNode in rootDomNodes) { AdaptablePath <object> path = Util.AdaptDomPath(rootNode); if (path.First.Is <IGame>() && (rootNode.Is <IGameObject>() || rootNode.Is <IGameObjectFolder>())) { newSelection.Add(path); } } if (newSelection.Count > 0) { if (InTransaction) { m_savedSelection = new List <object>(MasterContext.Selection); } MasterContext.SetRange(newSelection); } }