protected override void RebuildChildrens() { base.RebuildChildrens(); if (Collection.ElementType == typeof(PartConnection)) { foreach (var elemGroup in Collection.GetElements().OfType <PartConnection>().GroupBy(x => x.ConnectorType)) { string groupTitle = ModelLocalizations.ResourceManager.GetString($"Label_{elemGroup.Key}Connectors"); AutoGroupElements(elemGroup, groupTitle, 4, 10); } } else if (Collection.ElementType == typeof(PartCollision)) { foreach (var elemGroup in Collection.GetElements().OfType <PartCollision>().GroupBy(x => x.CollisionType)) { string groupTitle = elemGroup.Key == LDD.Primitives.Collisions.CollisionType.Box ? ModelLocalizations.Label_CollisionBoxes : ModelLocalizations.Label_CollisionSpheres; AutoGroupElements(elemGroup, groupTitle, 10, 10, true); } } else { foreach (var elem in Collection.GetElements()) { Nodes.Add(ProjectElementNode.CreateDefault(elem)); } } }
protected override void RebuildChildrens() { base.RebuildChildrens(); foreach (var elem in Elements) { Nodes.Add(ProjectElementNode.CreateDefault(elem)); } }
protected void AutoGroupElements(IEnumerable <PartElement> elements, string groupTitle, int groupWhen, int maxGroupSize, bool groupOnSameLevel = false) { int totalElements = elements.Count(); if (totalElements > groupWhen) { ProjectTreeNode groupNode = this; if (!groupOnSameLevel) { groupNode = new ProjectTreeNode(groupTitle) { nodesDirty = false, NodeID = $"{NodeID}_{groupTitle}" }; Nodes.Add(groupNode); } //var parentNode = groupNode.Parent; if (totalElements > maxGroupSize) { int remaining = totalElements; int currIdx = 0; while (remaining > 0) { int takeCount = Math.Min(remaining, maxGroupSize); string rangeText = string.Empty; if (takeCount / (double)maxGroupSize < 0.5) { rangeText = string.Format(ModelLocalizations.NodeRangeFormat2, currIdx + 1); } else { rangeText = string.Format(ModelLocalizations.NodeRangeFormat1, currIdx + 1, currIdx + takeCount); } var rangeNode = new ElementGroupNode(rangeText); rangeNode.NodeID = $"{NodeID}_{groupTitle}_{currIdx + 1}"; if (groupOnSameLevel) { rangeNode.Text = groupTitle + " " + rangeNode.Text; } rangeNode.Elements.AddRange(elements.Skip(currIdx).Take(maxGroupSize)); groupNode.Nodes.Add(rangeNode); currIdx += takeCount; remaining -= takeCount; } } else { foreach (var elem in elements) { groupNode.Nodes.Add(ProjectElementNode.CreateDefault(elem)); } } } else { foreach (var elem in elements) { Nodes.Add(ProjectElementNode.CreateDefault(elem)); } } }