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));
                }
            }
        }
Example #2
0
        protected override void RebuildChildrens()
        {
            base.RebuildChildrens();

            foreach (var elem in Elements)
            {
                Nodes.Add(ProjectElementNode.CreateDefault(elem));
            }
        }
Example #3
0
        public static ProjectElementNode CreateDefault(PartElement element)
        {
            var node = new ProjectElementNode(element);

            if (element is PartSurface surface)
            {
                if (surface.SurfaceID == 0)
                {
                    node.Text = ModelLocalizations.Label_MainSurface;

                    node.ImageKey = "Surface_Main";
                }
                else
                {
                    node.Text     = string.Format(ModelLocalizations.Label_DecorationSurfaceNumber, surface.SurfaceID);
                    node.ImageKey = "Surface_Decoration";
                }
            }
            else
            {
                node.Text = element.Name;
                if (element is SurfaceComponent component)
                {
                    node.ImageKey = $"Model_{component.ComponentType}";
                }
                else if (element is PartConnection connection)
                {
                    node.ImageKey = $"Connection_{connection.ConnectorType}";
                }
                else if (element is PartCollision collision)
                {
                    node.ImageKey = $"Collision_{collision.CollisionType}";
                }
                else if (element is ModelMeshReference || element is ModelMesh)
                {
                    node.ImageKey = "Mesh";
                }
            }
            return(node);
        }
Example #4
0
        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));
                }
            }
        }