Esempio n. 1
0
 public static void CleanUpSelectedChildrenNames(OperationSourceContainerObject3D item)
 {
     if (item is ISelectableChildContainer selectableChildContainer)
     {
         var allVisibleNames = item.SourceContainer.VisibleMeshes().Select(i => i.Name);
         // remove any names from SelectedChildren that are not in visible meshes
         foreach (var name in selectableChildContainer.SelectedChildren.ToArray())
         {
             if (!allVisibleNames.Contains(name))
             {
                 selectableChildContainer.SelectedChildren.Remove(name);
             }
         }
     }
 }
        public static void CleanUpSelectedChildrenNames(OperationSourceContainerObject3D item)
        {
            if (item is ISelectableChildContainer selectableChildContainer)
            {
                var parentOfSubtractTargets = item.DescendantsAndSelfMultipleChildrenFirstOrSelf();

                var allVisibleNames = parentOfSubtractTargets.Children.Select(i => i.Name);
                // remove any names from SelectedChildren that are not a child we can select
                foreach (var name in selectableChildContainer.SelectedChildren.ToArray())
                {
                    if (!allVisibleNames.Contains(name))
                    {
                        selectableChildContainer.SelectedChildren.Remove(name);
                    }
                }
            }
        }
Esempio n. 3
0
        private static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceContainer, ThemeConfig theme, Action selectionChanged)
        {
            GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                Margin = new BorderDouble(0, 3, 0, 0),
            };

            var parentOfSubtractTargets = sourceContainer.SourceContainer.DescendantsAndSelfMultipleChildrenFirstOrSelf();

            var sourceChildren = parentOfSubtractTargets.Children.ToList();

            var objectChecks = new Dictionary <ICheckbox, IObject3D>();

            var radioSiblings = new List <GuiWidget>();

            for (int i = 0; i < sourceChildren.Count; i++)
            {
                var itemIndex    = i;
                var child        = sourceChildren[itemIndex];
                var rowContainer = new FlowLayoutWidget()
                {
                    Padding = new BorderDouble(15, 0, 0, 3)
                };

                GuiWidget selectWidget;
                if (sourceChildren.Count == 2)
                {
                    var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
                    {
                        Checked   = childSelector.Contains(child.ID),
                        TextColor = theme.TextColor,
                        Margin    = 0,
                    };
                    radioSiblings.Add(radioButton);
                    radioButton.SiblingRadioButtonList = radioSiblings;
                    selectWidget = radioButton;
                }
                else
                {
                    selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
                    {
                        Checked   = childSelector.Contains(child.ID),
                        TextColor = theme.TextColor,
                    };
                }

                objectChecks.Add((ICheckbox)selectWidget, child);

                rowContainer.AddChild(selectWidget);
                var checkBox = selectWidget as ICheckbox;

                checkBox.CheckedStateChanged += (s, e) =>
                {
                    if (s is ICheckbox checkbox)
                    {
                        if (checkBox.Checked)
                        {
                            if (!childSelector.Contains(objectChecks[checkbox].ID))
                            {
                                childSelector.Add(objectChecks[checkbox].ID);
                            }
                        }
                        else
                        {
                            if (childSelector.Contains(objectChecks[checkbox].ID))
                            {
                                childSelector.Remove(objectChecks[checkbox].ID);
                            }
                        }

                        selectionChanged?.Invoke();
                    }
                };

                tabContainer.AddChild(rowContainer);
            }

            return(tabContainer);
        }
        private static GuiWidget CreateSourceChildSelector(SelectedChildren childSelector, OperationSourceContainerObject3D sourceCantainer, ThemeConfig theme)
        {
            GuiWidget tabContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            var sourceChildren = sourceCantainer.SourceContainer.VisibleMeshes().ToList();

            var objectChecks = new Dictionary <ICheckbox, IObject3D>();

            var radioSiblings = new List <GuiWidget>();

            for (int i = 0; i < sourceChildren.Count; i++)
            {
                var itemIndex    = i;
                var child        = sourceChildren[itemIndex];
                var rowContainer = new FlowLayoutWidget();

                GuiWidget selectWidget;
                if (sourceChildren.Count == 2)
                {
                    var radioButton = new RadioButton(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
                    {
                        Checked   = childSelector.Contains(child.Name),
                        TextColor = theme.TextColor
                    };
                    radioSiblings.Add(radioButton);
                    radioButton.SiblingRadioButtonList = radioSiblings;
                    selectWidget = radioButton;
                }
                else
                {
                    selectWidget = new CheckBox(string.IsNullOrWhiteSpace(child.Name) ? $"{itemIndex}" : $"{child.Name}")
                    {
                        Checked   = childSelector.Contains(child.Name),
                        TextColor = theme.TextColor
                    };
                }

                objectChecks.Add((ICheckbox)selectWidget, child);

                rowContainer.AddChild(selectWidget);
                var checkBox = selectWidget as ICheckbox;

                checkBox.CheckedStateChanged += (s, e) =>
                {
                    if (s is ICheckbox checkbox)
                    {
                        if (checkBox.Checked)
                        {
                            if (!childSelector.Contains(objectChecks[checkbox].Name))
                            {
                                childSelector.Add(objectChecks[checkbox].Name);
                            }
                        }
                        else
                        {
                            if (childSelector.Contains(objectChecks[checkbox].Name))
                            {
                                childSelector.Remove(objectChecks[checkbox].Name);
                            }
                        }
                    }
                };

                tabContainer.AddChild(rowContainer);
            }

            return(tabContainer);
        }