public TileCollection SetTileGrid(int numberOfRows, int numberOfColumns) { TileCollection tiles = new TileCollection(); Platform.CheckPositive(numberOfRows, "numberOfRows"); Platform.CheckPositive(numberOfColumns, "numberOfColumns"); double tileWidth = 1.0d / numberOfColumns; double tileHeight = 1.0d / numberOfRows; for (int row = 0; row < numberOfRows; row++) { for (int column = 0; column < numberOfColumns; column++) { double x = column * tileWidth; double y = row * tileHeight; RectangleF rect = new RectangleF((float)x, (float)y, (float)tileWidth, (float)tileHeight); PrintViewTile tile = new PrintViewTile(); tile.NormalizedRectangle = rect; tiles.Add(tile); } } return(tiles); }
private TileCollection LoadConfigGridXml(string fileName) { var xml = new XmlDocument(); try { var tileCollection = new TileCollection(); xml.Load(fileName); var root = xml.DocumentElement; foreach (XmlNode item in root.ChildNodes) { float x = float.Parse(item.Attributes["x"].Value); float y = float.Parse(item.Attributes["y"].Value); float width = float.Parse(item.Attributes["width"].Value); float height = float.Parse(item.Attributes["height"].Value); var tile = new PrintViewTile(); tile.NormalizedRectangle = new RectangleF(x, y, width, height); tileCollection.Add(tile); } return(tileCollection); } catch (Exception e) { Platform.Log(LogLevel.Error, e); } return(null); }
/// <summary> /// Creates a rectangular grid of tiles. /// </summary> /// <remarks> /// Each time this method is called, existing tiles in the <see cref="ImageBox"/> /// are removed and new ones added. The exception is when the number of rows /// and columns has not changed, in which case the method does nothing /// and returns immediately. /// </remarks> /// <param name="numberOfRows">Number of <see cref="ImageBox"/> rows.</param> /// <param name="numberOfColumns">Number of <see cref="ImageBox"/> columns.</param> /// <exception cref="ArgumentException"><paramref name="numberOfRows"/> or /// <paramref name="numberOfColumns"/> is less than 1.</exception> public void SetTileGrid(int numberOfRows, int numberOfColumns) { Platform.CheckPositive(numberOfRows, "numberOfRows"); Platform.CheckPositive(numberOfColumns, "numberOfColumns"); //// Don't bother if nothing's changed. //if (this.Tiles.Count == numberOfColumns * numberOfRows) //{ // return; //} _rows = numberOfRows; _columns = numberOfColumns; DisposeTiles(); double tileWidth = 1.0d / numberOfColumns; double tileHeight = 1.0d / numberOfRows; for (int row = 0; row < numberOfRows; row++) { for (int column = 0; column < numberOfColumns; column++) { double x = column * tileWidth; double y = row * tileHeight; RectangleF rect = new RectangleF((float)x, (float)y, (float)tileWidth, (float)tileHeight); PrintViewTile tile = new PrintViewTile(); tile.NormalizedRectangle = rect; this.Tiles.Add(tile); } } EventsHelper.Fire(_layoutCompletedEvent, this, EventArgs.Empty); }
private void OnTileAdded(object sender, ListEventArgs <ITile> e) { PrintViewTile tile = (PrintViewTile)e.Item; tile.ImageViewer = this.ImageViewer; tile.ParentImageBox = this; EventsHelper.Fire(_tileAddedEvent, this, new ItemEventArgs <ITile>(e.Item)); }
private void SetImage(int startImageIndex, int tileIndex) { PrintViewTile tile = this.Tiles[tileIndex] as PrintViewTile; // If there's an image, put it in a tile if (startImageIndex + tileIndex < _displaySet.PresentationImages.Count) { tile.PresentationImage = this.DisplaySet.PresentationImages[startImageIndex + tileIndex]; } // If there are no images left (the case when there are fewer images than tiles) // then just set the tile to blank else { tile.PresentationImage = null; tile.Deselect(); } }
public void ClearAllImages() { foreach (var selectPresentationImage in this.DisplaySet.PresentationImages) { selectPresentationImage.Dispose(); } this.DisplaySet.PresentationImages.Clear(); foreach (var tile in this.RootImageBox.Tiles) { PrintViewTile printViewTile = tile as PrintViewTile; printViewTile.PresentationImage = null; } referenceLines.Clear(); RootImageBox.TotleImageCount = 0; Draw(); PropertyValueChanged(); }
internal void Deselect() { if (this.Selected) { //Platform.CheckMemberIsSet(this.DisplaySet, "ImageBox.DisplaySet"); this.Selected = false; if (_displaySet != null) { _displaySet.Selected = false; } if (this.SelectedTile != null) { _selectedTile.Deselect(); _selectedTile = null; } } }
private TileCollection SetTileGridFactory(ImageDisplayFormat displayFormat) { TileCollection tiles = null; if (RootImageBox == null || displayFormat == null) { return(null); } int row = displayFormat.Modifiers[1]; int col = displayFormat.Modifiers[0]; switch (displayFormat.Format) { case ImageDisplayFormat.FormatEnum.STANDARD: tiles = SetTileGrid(row, col); break; case ImageDisplayFormat.FormatEnum.ROW: tiles = new TileCollection(); double tileWidth = 1.0d / 2; double tileHeight = 1.0d / 2; RectangleF rect1 = new RectangleF(0, 0, 1, (float)tileHeight); PrintViewTile tile1 = new PrintViewTile(); tile1.NormalizedRectangle = rect1; tiles.Add(tile1); for (int r = 1; r == 1; r++) { for (int column = 0; column < 2; column++) { double x = column * tileWidth; double y = r * tileHeight; RectangleF rect = new RectangleF((float)x, (float)y, (float)tileWidth, (float)tileHeight); PrintViewTile tile = new PrintViewTile(); tile.NormalizedRectangle = rect; tiles.Add(tile); } } break; case ImageDisplayFormat.FormatEnum.COL: tiles = new TileCollection(); double ColtileWidth = 1.0d / 2; double ColtileHeight = 1.0d / 2; RectangleF Colrect = new RectangleF(0, 0, (float)ColtileWidth, 1); PrintViewTile Coltile = new PrintViewTile(); Coltile.NormalizedRectangle = Colrect; tiles.Add(Coltile); for (int r = 0; r < 2; r++) { for (int column = 1; column == 1; column++) { double x = column * ColtileWidth; double y = r * ColtileHeight; RectangleF rect = new RectangleF((float)x, (float)y, (float)ColtileWidth, (float)ColtileHeight); PrintViewTile tile = new PrintViewTile(); tile.NormalizedRectangle = rect; tiles.Add(tile); } } break; } return(tiles); }
public void MergerGrid() { if (RootImageBox.SelectedTile == null) { return; } var printViewTile = RootImageBox.SelectedTile as PrintViewTile; var memorableCommand = new MemorableUndoableCommand(RootImageBox) { BeginState = RootImageBox.CreateMemento() }; List <PrintViewTile> selectTiles; if (RootImageBox.DisplaySet != null && RootImageBox.DisplaySet.PresentationImages.Count != 0) { selectTiles = new List <PrintViewTile>(); foreach (var selectPresentationImage in RootImageBox.SelectPresentationImages) { if (selectPresentationImage.Tile == null) { continue; } var tile = selectPresentationImage.Tile as PrintViewTile; if (!selectTiles.Contains(tile)) { selectTiles.Add(tile); } } if (!selectTiles.Contains(printViewTile)) { selectTiles.Add(printViewTile); } } else { selectTiles = new List <PrintViewTile>(); foreach (var selectTile in RootImageBox.SelectTiles) { if (!selectTiles.Contains(selectTile)) { selectTiles.Add(selectTile); } } } if (selectTiles.Count <= 1) { return; } //合并单元格 //并集合 var mycell = RectangleF.Union(selectTiles[0].NormalizedRectangle, selectTiles[1].NormalizedRectangle); for (int i = 2; i < selectTiles.Count; i++) { mycell = RectangleF.Union(mycell, selectTiles[i].NormalizedRectangle); } //移出与合并之后相交的单元格 var intersecTiles = new List <ITile>(); foreach (var tile in RootImageBox.Tiles) { if (mycell.IntersectsWith(tile.NormalizedRectangle)) { intersecTiles.Add(tile); } } if (intersecTiles.Count == 0) { return; } //确定单元格的位置 int index = RootImageBox.Tiles.IndexOf(intersecTiles[0]); if (index == -1) { return; } var mergerResult = new PrintViewTile(); mergerResult.NormalizedRectangle = mycell; RootImageBox.Tiles.Insert(index, mergerResult); //移出相交的单元格 foreach (var item in intersecTiles) { RootImageBox.Tiles.Remove(item); } EventsHelper.Fire(_layoutCompletedEvent, this, EventArgs.Empty); this.RootImageBox.TopLeftPresentationImageIndex = 0; this.RootImageBox.Draw(); ClearSelectTiles(); this.RootImageBox.SelectDefaultTile(); memorableCommand.EndState = RootImageBox.CreateMemento(); var historyCommand = new DrawableUndoableCommand(RootImageBox) { Name = "RootImageBoxMergerGrid" }; historyCommand.Enqueue(memorableCommand); CommandHistory.AddCommand(historyCommand); PropertyValueChanged(); }