예제 #1
0
 public void PaintLayerTest()
 {
     var layers = new List<LayerViewModel>();
     var A = new LayerViewModel {Name = "A"};
     var B = new LayerViewModel { Name = "B" };
     layers.Add(A);
     layers.Add(B);
     LayerMapper.PaintLayers(layers);
     Assert.AreEqual(0.75, A.Color.H);
     Assert.AreEqual(0.25,B.Color.H);
 }
예제 #2
0
        public static IEnumerable<LayerViewModel> PaintLayers(List<LayerViewModel> layers,
            IColorData parentColorData = null,LayerViewModel parent = null,int depth = 0)
        {
            var toPaintDistinct = new List<LayerViewModel>();
            var toPaintSameColor = new List<LayerViewModel>();
            if (parentColorData == null)
                parentColorData = _pallette.GetStartingColorData();
            IColorData sameColor;
            if (parent != null && parent.Invisible)
            {
                //Parent is invisible, paint all layers with the parent color
                toPaintSameColor = layers;
                sameColor = parentColorData;
            }
            else
            {
                sameColor = _pallette.GetSubColor(parentColorData);
                if (depth == 0  && layers.Sum(x => x.Descendants) < 5)
                {
                    toPaintDistinct = layers;
                }
                else
                {
                    //TODO: Maybe not require children if the tree is shorter than 3?
                    toPaintDistinct = layers.Where(l => l.Children.Any() && !l.Invisible).ToList();
                    toPaintSameColor = layers.Where(l => !l.Children.Any() || l.Invisible).ToList();
                }
            }
            var distinctColors = new Stack<IColorData>();
            if (toPaintDistinct.Count > 1)
                distinctColors = _pallette.GetDistinctColors(parentColorData,toPaintDistinct.Count);
            if(toPaintDistinct.Count == 1)
                distinctColors = new Stack<IColorData>(_pallette.GetDistinctColors(parentColorData,2).Take(1));

            foreach (var layer in toPaintSameColor)
            {
                PaintLayer(layer, sameColor);
            }

            foreach (var layer in toPaintDistinct)
            {
                var colorData = distinctColors.Pop();
                PaintLayer(layer, colorData);
            }

            return layers;
        }
예제 #3
0
        public LayerView(LayerViewModel layerModel)
        {
            InitializeComponent();
            LayerName = layerModel.Name;
            NameBlock.Text = layerModel.Name;
            Row = layerModel.Row;
            Column = layerModel.Column;
            var childMargin = GetChildMargin();
            var childs = layerModel.Children.Select(ViewModelGenerator.CreateViewFromViewModel).ToList();
            foreach (var child in childs)
            {
                if(child is LayerView)
                    (child as LayerView).Border.Margin = childMargin;
                ChildHolder.Children.Add(child.UiElement);
                Grid.SetColumn(child.UiElement, child.Column);
                Grid.SetRow(child.UiElement, child.Row);
            }

            for (var i = 0; i < layerModel.Rows; i++)
                ChildHolder.RowDefinitions.Add(new RowDefinition());

            for (var i = 0; i < layerModel.Columns; i++)
                ChildHolder.ColumnDefinitions.Add(new ColumnDefinition());

            DataContext = this;

            var color = layerModel.Color;
            var borderColor = CalculateBorderColor(color);
            var textColor = CalculateTextColor(color);
            Border.Background = new SolidColorBrush(color);
            Border.BorderBrush = new SolidColorBrush(borderColor);
            NameBlock.Foreground = new SolidColorBrush(textColor);
            if (!childs.Any())
            {
                DockPanel.VerticalAlignment = VerticalAlignment.Center;
                Border.Background = new LinearGradientBrush(color, borderColor, 30);
            }
            if (layerModel.Anonymous) HideName();
            if (layerModel.Invisible) Hide();
        }
예제 #4
0
        private static void SetupColumnAndRows(LayerViewModel node, IEnumerable<DiagramSymbolViewModel> children)
        {
            children.OfType<LayerViewModel>().ForEach(model => SetupColumnAndRows(model, model.Children));

            var column = 0;
            var row = 0;
            foreach (var childLayer in children)
            {
                childLayer.Column = column;
                childLayer.Row = row;
                if (node.Orientation == Horizontal)
                    column++;
                else
                    row++;
            }
            node.Rows = row;
            node.Columns = column;
        }
예제 #5
0
 private static void PaintLayer(LayerViewModel layer, IColorData colorData,int depth = 0)
 {
     layer.Color = colorData.GetColor();
     PaintLayers(layer.Children.OfType<LayerViewModel>().ToList(), colorData, layer,depth + 1);
 }