Ejemplo n.º 1
0
        private void replace(bool newByOld)
        {
            // iterate on all the layers
            for (int i = 0; i < mBrickLayerList.Count; ++i)
            {
                // get the layer and the list of brick pair to replace
                LayerBrick       currentLayer    = mBrickLayerList[i];
                List <BrickPair> currentPairList = mBrickPairList[i];

                // clear the selection (we will select the replaced brick for updating the connectivity)
                currentLayer.clearSelection();

                if (currentPairList.Count > 0)
                {
                    // iterate on all the brick pair
                    foreach (BrickPair brickPair in currentPairList)
                    {
                        // get the old and new brick
                        Layer.LayerItem oldOne = brickPair.mOldBrick;
                        Layer.LayerItem newOne = brickPair.mNewBrick;
                        // reverse them if needed
                        if (newByOld)
                        {
                            oldOne = brickPair.mNewBrick;
                            newOne = brickPair.mOldBrick;
                        }
                        // replace the old brick with the new one in the current layer
                        replaceOneItem(currentLayer, oldOne, newOne);
                        // add the brick in the selection for updating connectivity later
                        currentLayer.addObjectInSelection(newOne);
                    }

                    // update the connectivity of the whole layer after replacement
                    currentLayer.updateFullBrickConnectivityForSelectedBricksOnly();
                    // clear the selection again (it was only use for fast connectivity update)
                    currentLayer.clearSelection();
                }

                // If the current layer is the one which has the selection
                // reselect all the new brick
                if (currentLayer == mLayerWhereToSelectTheReplacedBricks)
                {
                    foreach (BrickPair brickPair in mReplacedBricksToSelect)
                    {
                        if (newByOld)
                        {
                            currentLayer.addObjectInSelection(brickPair.mOldBrick);
                        }
                        else
                        {
                            currentLayer.addObjectInSelection(brickPair.mNewBrick);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public override void redo()
        {
            // special case for easy editing: if the group of brick has connection points and is connected
            // to bricks not deleted we select the connected brick,
            // such as the user can press several times on the del button to delete a full line of track.
            LayerBrick.Brick nextBrickToSelect = null;
            int nextActiveConnectionPointIndex = -1;

            foreach (Layer.LayerItem item in mBricks)
            {
                LayerBrick.Brick brick = item as LayerBrick.Brick;
                if (brick.HasConnectionPoint)
                {
                    foreach (LayerBrick.Brick.ConnectionPoint connexion in brick.ConnectionPoints)
                    {
                        if (!connexion.IsFree && !mBricks.Contains(connexion.ConnectionLink.mMyBrick))
                        {
                            nextBrickToSelect = connexion.ConnectionLink.mMyBrick;
                            nextActiveConnectionPointIndex = connexion.ConnectionLink.Index;
                            break;
                        }
                    }
                }
                if (nextBrickToSelect != null)
                {
                    break;
                }
            }

            // remove the specified brick from the list of the layer,
            // but do not delete it, also memorise its last position
            mBrickIndex.Clear();
            foreach (Layer.LayerItem obj in mBricks)
            {
                mBrickIndex.Add(mBrickLayer.removeBrick(obj as LayerBrick.Brick));
            }
            // don't need to update the connectivity of the bricks because we do it specifically for the brick removed
            // mBrickLayer.updateBrickConnectivityOfSelection(false);

            // check if we have to select a brick
            if (nextBrickToSelect != null)
            {
                mBrickLayer.clearSelection();
                mBrickLayer.addObjectInSelection(nextBrickToSelect);
                // set also the active connection point
                if (nextActiveConnectionPointIndex >= 0)
                {
                    nextBrickToSelect.ActiveConnectionPointIndex = nextActiveConnectionPointIndex;
                }
            }

            // notify the part list view (after actually deleting the brick because the total map size need to be recomputed)
            foreach (Layer.LayerItem item in mBricksForNotification)
            {
                MainForm.Instance.NotifyPartListForBrickRemoved(mBrickLayer, item, false);
            }
        }