private void replaceOneItem(LayerBrick layer, Layer.LayerItem itemToRemove, Layer.LayerItem itemToAdd) { // memorise the brick index order and the group of the old brick int oldItemIndex = -1; Layer.Group oldItemGroup = itemToRemove.Group; // first remove the item from its group, in case it belongs to a group // (so that later if someone ask all item of this group, it won't get this limbo item) if (itemToRemove.Group != null) { itemToRemove.Group.removeItem(itemToRemove); } // check if the item to remove is a group or a simple brick if (itemToRemove.IsAGroup) { List <Layer.LayerItem> bricksToRemove = (itemToRemove as Layer.Group).getAllLeafItems(); foreach (Layer.LayerItem item in bricksToRemove) { oldItemIndex = layer.removeBrick(item as LayerBrick.Brick); } // we alsways take the last index to be sure we don't keep an index bigger than the brick list // after removing all the parts of the group } else { oldItemIndex = layer.removeBrick(itemToRemove as LayerBrick.Brick); } // check if the item to add is a group or a simple brick if (itemToAdd.IsAGroup) { List <Layer.LayerItem> bricksToAdd = (itemToAdd as Layer.Group).getAllLeafItems(); // since we will add all the brick at the same index, iterating in the normal order // the insertion order will be reversed. So we reverse the list to make the insertion in correct order bricksToAdd.Reverse(); foreach (Layer.LayerItem item in bricksToAdd) { layer.addBrick(item as LayerBrick.Brick, oldItemIndex); } } else { layer.addBrick(itemToAdd as LayerBrick.Brick, oldItemIndex); } // then once the item has been added to the layer, add it also to the group if the old item had a group if (oldItemGroup != null) { oldItemGroup.addItem(itemToAdd); } // notify the part list view (after actually adding and deleting the bricks because the total map size need to be recomputed) MainForm.Instance.NotifyPartListForBrickRemoved(layer, itemToRemove, false); MainForm.Instance.NotifyPartListForBrickAdded(layer, itemToAdd, false); }
public override void redo() { // clear the selection to reselect the parts of the group mBrickLayer.clearSelection(); // add all the part of the group in the same order as in the group int insertIndex = mInsertIndex; foreach (Layer.LayerItem item in mBricksInTheGroup) { mBrickLayer.addBrick(item as LayerBrick.Brick, insertIndex); // update the connectivity of each brick, in order to also create connections // between bricks inside the same group, otherwise if we update the connectivity of // the selection, the connectivity inside the selection will not change mBrickLayer.updateFullBrickConnectivityForOneBrick(item as LayerBrick.Brick); // select the brick (in order to select the whole group at the end mBrickLayer.addObjectInSelection(item); // increase the index if it is valid if (insertIndex != -1) { insertIndex++; } } // set the prefered index after the adding, // because the connection of the brick will move automatically the the active connection setActiveConnectionIndex(mNextPreferedActiveConnectionIndex); // notify the part list view (after actually adding the brick because the total map size need to be recomputed) MainForm.Instance.NotifyPartListForBrickAdded(mBrickLayer, mGroup, false); }
public override void redo() { // and add this brick in the list of the layer mBrickLayer.addBrick(mBrick, mBrickIndex); // change the selection to the new added brick (should be done after the add) mBrickLayer.selectOnlyThisObject(mBrick); // update the connectivity of the bricks after selecting it mBrickLayer.updateBrickConnectivityOfSelection(false); // notify the part list view (after actually adding the brick because the total map size need to be recomputed) MainForm.Instance.NotifyPartListForBrickAdded(mBrickLayer, mBrick, false); }
public override void redo() { // and add all the bricks in the reverse order for (int i = mBricks.Count - 1; i >= 0; --i) { mBrickLayer.addBrick(mBricks[i] as LayerBrick.Brick, mBrickIndex[i]); // update the connectivity of each brick, in order to also create connections // between bricks inside the same group, otherwise if we update the connectivity of // the selection, the connectivity inside the selection will not change mBrickLayer.updateFullBrickConnectivityForOneBrick(mBricks[i] as LayerBrick.Brick); } // finally reselect all the undeleted brick mBrickLayer.selectOnlyThisObject(mBricks); // notify the part list view (after actually adding the brick because the total map size need to be recomputed) MainForm.Instance.NotifyPartListForBrickAdded(mBrickLayer, mBrickOrGroup, false); }
public override void undo() { // and add all the texts in the reverse order for (int i = mBricks.Count - 1; i >= 0; --i) { mBrickLayer.addBrick(mBricks[i] as LayerBrick.Brick, mBrickIndex[i]); // recompute the connexions of each brick, we must do it one by one, else // the bricks inside the group deleted will not be connected. // the other solution is to perform a full connectivity rebuild outside of this loop // but it is not guaranted to be faster. mBrickLayer.updateFullBrickConnectivityForOneBrick(mBricks[i] as LayerBrick.Brick); } // finally reselect all the undeleted brick mBrickLayer.selectOnlyThisObject(mBricks); // notify the part list view (after actually adding the brick because the total map size need to be recomputed) foreach (Layer.LayerItem item in mBricksForNotification) { MainForm.Instance.NotifyPartListForBrickAdded(mBrickLayer, item, false); } }
public override void redo() { // add all the bricks (by default all the brick index are initialized with -1 // so the first time they are added, we just add them at the end, // after the index is record in the array during the undo) // We must add all the bricks in the reverse order to avoid crash (insert with an index greater than the size of the list) for (int i = mItems.Count - 1; i >= 0; --i) { mBrickLayer.addBrick(mItems[i] as LayerBrick.Brick, mItemIndex[i]); // recompute the connexions of each brick, we must do it one by one, else // the bricks inside the group deleted will not be connected. // the other solution is to perform a full connectivity rebuild outside of this loop // but it is not guaranted to be faster. mBrickLayer.updateFullBrickConnectivityForOneBrick(mItems[i] as LayerBrick.Brick); } // finally reselect all the duplicated brick mBrickLayer.selectOnlyThisObject(mItems); // notify the part list view (after actually adding the brick because the total map size need to be recomputed) foreach (Layer.LayerItem item in mBricksForNotification) { MainForm.Instance.NotifyPartListForBrickAdded(mBrickLayer, item, false); } }