public ScrollViewer GetMappedLayerWeights() { WrapPanel panel = new WrapPanel(); panel.BeginInit(); panel.UseLayoutRounding = true; panel.SnapsToDevicePixels = true; panel.Orientation = Orientation.Horizontal; panel.HorizontalAlignment = HorizontalAlignment.Stretch; panel.VerticalAlignment = VerticalAlignment.Stretch; for (int map = 0; map < MapCount; map++) { Grid grid = new Grid(); grid.SnapsToDevicePixels = true; grid.UseLayoutRounding = true; grid.Background = System.Windows.Media.Brushes.White; grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; grid.VerticalAlignment = System.Windows.VerticalAlignment.Top; grid.Width = double.NaN; grid.Height = double.NaN; grid.Margin = new Thickness(4); for (int col = 0; col < MapWidth; col++) { ColumnDefinition colDef = new ColumnDefinition(); colDef.Width = new GridLength(0, GridUnitType.Auto); grid.ColumnDefinitions.Add(colDef); } for (int row = 0; row < MapHeight; row++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = new GridLength(0, GridUnitType.Auto); grid.RowDefinitions.Add(rowDef); } double weightMin = Weights.Min(weight => weight.Value); double weightMax = Weights.Max(weight => weight.Value); double range = GetRangeFactor(weightMin, weightMax); grid.BeginInit(); for (int y = 0; y < ReceptiveFieldWidth; y++) { for (int x = 0; x < ReceptiveFieldHeight; x++) { int index = x + (y * ReceptiveFieldWidth) + (map * ((ReceptiveFieldWidth * ReceptiveFieldHeight) + 1)); System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle(); rectangle.BeginInit(); rectangle.SnapsToDevicePixels = true; rectangle.UseLayoutRounding = true; rectangle.HorizontalAlignment = HorizontalAlignment.Stretch; ToolTip tip = new ToolTip(); tip.Content = Weights[index].Value.ToString("N17", CultureInfo.CurrentUICulture); rectangle.ToolTip = tip; rectangle.VerticalAlignment = VerticalAlignment.Stretch; rectangle.Margin = new Thickness(0); rectangle.Height = 8; rectangle.Width = 8; rectangle.Stretch = Stretch.Uniform; rectangle.Fill = GetBrushFromRange(range, weightMin, weightMax, Weights[index].Value); rectangle.EndInit(); Grid.SetColumn(rectangle, x); Grid.SetRow(rectangle, y); grid.Children.Add(rectangle); tip = null; rectangle = null; } }; grid.EndInit(); panel.Children.Add(grid); } panel.EndInit(); ScrollViewer scr = new ScrollViewer(); scr.BeginInit(); scr.SnapsToDevicePixels = true; scr.UseLayoutRounding = true; scr.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; scr.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; scr.HorizontalContentAlignment = HorizontalAlignment.Left; scr.VerticalContentAlignment = VerticalAlignment.Top; scr.VerticalAlignment = VerticalAlignment.Stretch; scr.HorizontalAlignment = HorizontalAlignment.Stretch; scr.Content = panel; scr.Height = double.NaN; scr.Width = double.NaN; scr.EndInit(); return (scr); }
public ScrollViewer GetMappedLayerOutputs() { WrapPanel panel = new WrapPanel(); panel.BeginInit(); panel.UseLayoutRounding = true; panel.SnapsToDevicePixels = true; panel.Orientation = Orientation.Horizontal; panel.HorizontalAlignment = HorizontalAlignment.Stretch; panel.VerticalAlignment = VerticalAlignment.Stretch; for (int map = 0; map < MapCount; ++map) { Grid grid = new Grid(); grid.SnapsToDevicePixels = true; grid.UseLayoutRounding = true; grid.Background = System.Windows.Media.Brushes.White; grid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; grid.VerticalAlignment = System.Windows.VerticalAlignment.Top; grid.Width = double.NaN; grid.Height = double.NaN; grid.Margin = new Thickness(4); for (int col = 0; col < MapWidth; col++) { ColumnDefinition colDef = new ColumnDefinition(); colDef.Width = new GridLength(0, GridUnitType.Auto); grid.ColumnDefinitions.Add(colDef); } for (int row = 0; row < MapHeight; row++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = new GridLength(0, GridUnitType.Auto); grid.RowDefinitions.Add(rowDef); } grid.BeginInit(); for (int y = 0; y < MapHeight; y++) { for (int x = 0; x < MapWidth; x++) { int index = x + (y * MapWidth) + (map * MapWidth * MapHeight); byte color = (byte)(255 - ((Neurons[index].Output + 1D) * 127D)); System.Windows.Media.SolidColorBrush brush = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(color, color, color)); brush.Freeze(); System.Windows.Shapes.Rectangle rectangle = new System.Windows.Shapes.Rectangle(); rectangle.BeginInit(); rectangle.SnapsToDevicePixels = true; rectangle.UseLayoutRounding = true; rectangle.HorizontalAlignment = HorizontalAlignment.Stretch; ToolTip tip = new ToolTip(); tip.Content = Neurons[index].Output.ToString("N17", CultureInfo.CurrentUICulture); rectangle.ToolTip = tip; rectangle.VerticalAlignment = VerticalAlignment.Stretch; rectangle.Margin = new Thickness(0); rectangle.Height = 8; rectangle.Width = 8; rectangle.Stretch = Stretch.Uniform; rectangle.Fill = brush; rectangle.EndInit(); Grid.SetColumn(rectangle, x); Grid.SetRow(rectangle, y); grid.Children.Add(rectangle); brush = null; tip = null; rectangle = null; } } grid.EndInit(); panel.Children.Add(grid); } panel.EndInit(); ScrollViewer scr = new ScrollViewer(); scr.BeginInit(); scr.SnapsToDevicePixels = true; scr.UseLayoutRounding = true; scr.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; scr.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; scr.HorizontalContentAlignment = HorizontalAlignment.Left; scr.VerticalContentAlignment = VerticalAlignment.Top; scr.VerticalAlignment = VerticalAlignment.Stretch; scr.HorizontalAlignment = HorizontalAlignment.Stretch; scr.Content = panel; scr.Height = double.NaN; scr.Width = double.NaN; scr.EndInit(); return (scr); }
private void GenerateRows(int StartZeile, int EndZeile) { try { if (StartZeile == EndZeile) return; if (oTable == null) { oTable = new Grid(); oTable.BeginInit(); } oTable.SetValue(TextBlock.FontFamilyProperty, new FontFamily("Verdana")); if (Configuration.FontSize < 4) configuration.FontSize = 8; oTable.SetValue(TextBlock.FontSizeProperty, (double)Configuration.FontSize); GenerateColumns(); for (int i = StartZeile; i <= EndZeile + 1; i++) { oTable.RowDefinitions.Add(new RowDefinition()); } int ColBorders = 1; int ColBorderLeft = 1; int ColBorderRight = 0; int ColBorderButtom = 1; if (!HasRowLines) ColBorderButtom = 0; if (!HasColumnLines) ColBorders = 0; int row = 1; int col = -1; GenerateHeaderRow(ColBorders); for (int currow = StartZeile; currow < EndZeile; currow++) { DataRow item = oData.Rows[currow]; row++; if (currow + 1 == EndZeile) ColBorderButtom = 1; int FirstCol = 1; int colcount = 0; //nur ECHTE Spalten col = -1; for (int i = CurrentRange.From; i <= CurrentRange.Until; i++) { ColumnDefinition colDef = Columns[i]; col++; ColBorderLeft = 1; ColBorderRight = 0; colcount++; if (ColBorders == 0 && FirstCol != 1) ColBorderLeft = 0; if (colcount == (CurrentRange.Until - CurrentRange.From + 1)) ColBorderRight = 1; string sValue = ""; sValue = item.Field<string>(colDef.Name); if (sValue.Contains("\n")) sValue = sValue.Split('\n')[0]; if (sValue.Contains("\r")) sValue = sValue.Split('\r')[0]; GenerateCell(sValue, colDef, new Thickness(ColBorderLeft, 0, ColBorderRight, ColBorderButtom), row, col, null); FirstCol = 0; } } return; } catch (Exception ex) { } }
public void GenerateFixedDocument(bool InPrintMode) { PrintDocument = new FixedDocument(); int RowsOnPage = 100; PageSupplemental oSupplemental = new PageSupplemental(Configuration); PageDefinition def = definition; //Verteilung auf mehreren Seiten? GenerateRanges(); int RowsOnFirstPage = CalculateRowsOnPage(ref RowsOnPage, def); UpdatePages(); int from = PageSelectionFrom; int until = PageSelectionUntil; if (AllPages | !InPrintMode) { from = 1; until = maxPages; } ProgressContext.Init(Properties.Resources.prgSeiten, (until - from + 1)); PrintDocument.DocumentPaginator.PageSize = def.PageSize; for (int i = from; i <= until; i++) { for (int x = 1; x <= ColRanges.Count; x++) { oTable = new Grid(); oTable.BeginInit(); ProgressContext.UpdateProgress(i - from + x); if (ProgressContext.Canceled) { ProgressContext.Finish(); return; } offset = x - 1; PageContent oPage = new PageContent(); FixedPage oFixed = CreatePage(); int RowsUntil = Math.Min((i - 1) * RowsOnPage + RowsOnFirstPage, oData.Rows.Count); int RowsFrom = (i - 2) * RowsOnPage + RowsOnFirstPage; if (RowsFrom < 0) RowsFrom = 0; GenerateRows(RowsFrom, RowsUntil); oTable.Width = def.ContentSize.Width; oTable.Margin = new Thickness(def.ContentOrigin.X, def.ContentOrigin.Y, 0, 0); oTable.EndInit(); oFixed.Children.Add(oTable); FrameworkElement oHeader = oSupplemental.PageHeader(); oHeader.Width = def.ContentSize.Width; oHeader.Margin = new Thickness(def.HeaderRect.Left, def.HeaderRect.Top, 0, 0); oFixed.Children.Add(oHeader); string currentpage = Convert.ToString(((int)i)); if (ColRanges.Count > 1) currentpage = currentpage.AddLetter(x); FrameworkElement oFooter = oSupplemental.PageFooter(currentpage, Maximum); oFooter.Margin = new Thickness(def.FooterRect.Left, def.FooterRect.Top, 0, 0); oFooter.Width = def.ContentSize.Width; oFixed.Children.Add(oFooter); oFixed.Measure(def.PageSize); oFixed.Arrange(new Rect(new Point(), def.PageSize)); oFixed.UpdateLayout(); ((IAddChild)oPage).AddChild(oFixed); PrintDocument.Pages.Add(oPage); } } ticket.PageBorderless = PageBorderless.Borderless; oTable = null; ProgressContext.Finish(); NotifyPropertyChanged("PrintDocument"); NotifyPropertyChanged("Maximum"); NotifyPropertyChanged("PageSelectionFrom"); NotifyPropertyChanged("PageSelectionUntil"); }
private void ResizeRows(Grid grid, double deltaX) { GridResizeBehavior effectiveGridResizeBehavior = this.DetermineEffectiveResizeBehavior(); int row = Grid.GetRow(this); int upperRow; int lowerRow; switch (effectiveGridResizeBehavior) { case GridResizeBehavior.PreviousAndCurrent: upperRow = row - 1; lowerRow = row; break; case GridResizeBehavior.PreviousAndNext: upperRow = row - 1; lowerRow = row + 1; break; default: upperRow = row; lowerRow = row + 1; break; } if (lowerRow >= grid.RowDefinitions.Count) { return; } var upperRowDefinition = grid.RowDefinitions[upperRow]; var lowerRowDefinition = grid.RowDefinitions[lowerRow]; var upperRowGridUnitType = upperRowDefinition.Height.GridUnitType; var lowerRowGridUnitType = lowerRowDefinition.Height.GridUnitType; var upperRowActualHeight = upperRowDefinition.ActualHeight; var lowerRowActualHeight = lowerRowDefinition.ActualHeight; var upperRowMaxHeight = upperRowDefinition.MaxHeight; var lowerRowMaxHeight = lowerRowDefinition.MaxHeight; var upperRowMinHeight = upperRowDefinition.MinHeight; var lowerRowMinHeight = lowerRowDefinition.MinHeight; //deltaX = 200; if (upperRowActualHeight + deltaX > upperRowMaxHeight) { deltaX = Math.Max( 0, upperRowDefinition.MaxHeight - upperRowActualHeight); } if (upperRowActualHeight + deltaX < upperRowMinHeight) { deltaX = Math.Min( 0, upperRowDefinition.MinHeight - upperRowActualHeight); } if (lowerRowActualHeight - deltaX > lowerRowMaxHeight) { deltaX = -Math.Max( 0, lowerRowDefinition.MaxHeight - lowerRowActualHeight); } if (lowerRowActualHeight - deltaX < lowerRowMinHeight) { deltaX = -Math.Min( 0, lowerRowDefinition.MinHeight - lowerRowActualHeight); } var newUpperRowActualHeight = upperRowActualHeight + deltaX; var newLowerRowActualHeight = lowerRowActualHeight - deltaX; grid.BeginInit(); double totalStarRowsHeight = 0; double starRowsAvailableHeight = grid.ActualHeight; if (upperRowGridUnitType == GridUnitType.Star || lowerRowGridUnitType == GridUnitType.Star) { foreach (var rowDefinition in grid.RowDefinitions) { if (rowDefinition.Height.GridUnitType == GridUnitType.Star) { totalStarRowsHeight += rowDefinition.Height.Value; } else { starRowsAvailableHeight -= rowDefinition.ActualHeight; } } } if (upperRowGridUnitType == GridUnitType.Star) { if (lowerRowGridUnitType == GridUnitType.Star) { // If both rows are star rows // - totalStarRowsHeight won't change and // as much as one of the rows grows // - the other row will shrink by the same value. // If there is no width available to star rows // - we can't resize two of them. if (starRowsAvailableHeight < 1) { return; } var oldStarHeight = upperRowDefinition.Height.Value; var newStarHeight = Math.Max( 0, totalStarRowsHeight * newUpperRowActualHeight / starRowsAvailableHeight); upperRowDefinition.Height = new GridLength(newStarHeight, GridUnitType.Star); lowerRowDefinition.Height = new GridLength( Math.Max( 0, lowerRowDefinition.Height.Value - newStarHeight + oldStarHeight), GridUnitType.Star); } else { var newStarRowsAvailableHeight = starRowsAvailableHeight + lowerRowActualHeight - newLowerRowActualHeight; if (newStarRowsAvailableHeight - newUpperRowActualHeight >= 1) { var newStarHeight = Math.Max( 0, (totalStarRowsHeight - upperRowDefinition.Height.Value) * newUpperRowActualHeight / (newStarRowsAvailableHeight - newUpperRowActualHeight)); upperRowDefinition.Height = new GridLength(newStarHeight, GridUnitType.Star); } } } else { upperRowDefinition.Height = new GridLength( newUpperRowActualHeight, GridUnitType.Pixel); } if (lowerRowGridUnitType == GridUnitType.Star) { if (upperRowGridUnitType != GridUnitType.Star) { var newStarRowsAvailableHeight = starRowsAvailableHeight + upperRowActualHeight - newUpperRowActualHeight; if (newStarRowsAvailableHeight - newLowerRowActualHeight >= 1) { var newStarHeight = Math.Max( 0, (totalStarRowsHeight - lowerRowDefinition.Height.Value) * newLowerRowActualHeight / (newStarRowsAvailableHeight - newLowerRowActualHeight)); lowerRowDefinition.Height = new GridLength(newStarHeight, GridUnitType.Star); } } // else handled in the upper row width calculation block } else { lowerRowDefinition.Height = new GridLength( newLowerRowActualHeight, GridUnitType.Pixel); } grid.EndInit(); }
private void ResizeColumns(Grid grid, double deltaX) { GridResizeBehavior effectiveGridResizeBehavior = this.DetermineEffectiveResizeBehavior(); int column = Grid.GetColumn(this); int leftColumn; int rightColumn; switch (effectiveGridResizeBehavior) { case GridResizeBehavior.PreviousAndCurrent: leftColumn = column - 1; rightColumn = column; break; case GridResizeBehavior.PreviousAndNext: leftColumn = column - 1; rightColumn = column + 1; break; default: leftColumn = column; rightColumn = column + 1; break; } if (rightColumn >= grid.ColumnDefinitions.Count) { return; } var leftColumnDefinition = grid.ColumnDefinitions[leftColumn]; var rightColumnDefinition = grid.ColumnDefinitions[rightColumn]; var leftColumnGridUnitType = leftColumnDefinition.Width.GridUnitType; var rightColumnGridUnitType = rightColumnDefinition.Width.GridUnitType; var leftColumnActualWidth = leftColumnDefinition.ActualWidth; var rightColumnActualWidth = rightColumnDefinition.ActualWidth; var leftColumnMaxWidth = leftColumnDefinition.MaxWidth; var rightColumnMaxWidth = rightColumnDefinition.MaxWidth; var leftColumnMinWidth = leftColumnDefinition.MinWidth; var rightColumnMinWidth = rightColumnDefinition.MinWidth; //deltaX = 200; if (leftColumnActualWidth + deltaX > leftColumnMaxWidth) { deltaX = Math.Max( 0, leftColumnDefinition.MaxWidth - leftColumnActualWidth); } if (leftColumnActualWidth + deltaX < leftColumnMinWidth) { deltaX = Math.Min( 0, leftColumnDefinition.MinWidth - leftColumnActualWidth); } if (rightColumnActualWidth - deltaX > rightColumnMaxWidth) { deltaX = -Math.Max( 0, rightColumnDefinition.MaxWidth - rightColumnActualWidth); } if (rightColumnActualWidth - deltaX < rightColumnMinWidth) { deltaX = -Math.Min( 0, rightColumnDefinition.MinWidth - rightColumnActualWidth); } var newLeftColumnActualWidth = leftColumnActualWidth + deltaX; var newRightColumnActualWidth = rightColumnActualWidth - deltaX; grid.BeginInit(); double totalStarColumnsWidth = 0; double starColumnsAvailableWidth = grid.ActualWidth; if (leftColumnGridUnitType == GridUnitType.Star || rightColumnGridUnitType == GridUnitType.Star) { foreach (var columnDefinition in grid.ColumnDefinitions) { if (columnDefinition.Width.GridUnitType == GridUnitType.Star) { totalStarColumnsWidth += columnDefinition.Width.Value; } else { starColumnsAvailableWidth -= columnDefinition.ActualWidth; } } } if (leftColumnGridUnitType == GridUnitType.Star) { if (rightColumnGridUnitType == GridUnitType.Star) { // If both columns are star columns // - totalStarColumnsWidth won't change and // as much as one of the columns grows // - the other column will shrink by the same value. // If there is no width available to star columns // - we can't resize two of them. if (starColumnsAvailableWidth < 1) { return; } var oldStarWidth = leftColumnDefinition.Width.Value; var newStarWidth = Math.Max( 0, totalStarColumnsWidth * newLeftColumnActualWidth / starColumnsAvailableWidth); leftColumnDefinition.Width = new GridLength(newStarWidth, GridUnitType.Star); rightColumnDefinition.Width = new GridLength( Math.Max( 0, rightColumnDefinition.Width.Value - newStarWidth + oldStarWidth), GridUnitType.Star); } else { var newStarColumnsAvailableWidth = starColumnsAvailableWidth + rightColumnActualWidth - newRightColumnActualWidth; if (newStarColumnsAvailableWidth - newLeftColumnActualWidth >= 1) { var newStarWidth = Math.Max( 0, (totalStarColumnsWidth - leftColumnDefinition.Width.Value) * newLeftColumnActualWidth / (newStarColumnsAvailableWidth - newLeftColumnActualWidth)); leftColumnDefinition.Width = new GridLength(newStarWidth, GridUnitType.Star); } } } else { leftColumnDefinition.Width = new GridLength( newLeftColumnActualWidth, GridUnitType.Pixel); } if (rightColumnGridUnitType == GridUnitType.Star) { if (leftColumnGridUnitType != GridUnitType.Star) { var newStarColumnsAvailableWidth = starColumnsAvailableWidth + leftColumnActualWidth - newLeftColumnActualWidth; if (newStarColumnsAvailableWidth - newRightColumnActualWidth >= 1) { var newStarWidth = Math.Max( 0, (totalStarColumnsWidth - rightColumnDefinition.Width.Value) * newRightColumnActualWidth / (newStarColumnsAvailableWidth - newRightColumnActualWidth)); rightColumnDefinition.Width = new GridLength(newStarWidth, GridUnitType.Star); } } // else handled in the left column width calculation block } else { rightColumnDefinition.Width = new GridLength( newRightColumnActualWidth, GridUnitType.Pixel); } grid.EndInit(); }