コード例 #1
0
ファイル: ReplaceBrick.cs プロジェクト: Shevonar/BlueBrick
        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);
        }
コード例 #2
0
ファイル: GroupItems.cs プロジェクト: Shevonar/BlueBrick
        public override void redo()
        {
            // add all the items in the group
            mGroup.addItem(mItemsToGroup);

            // reselect the current selection, because the regroup may affect a currently selected item
            // and if we don't reselect, we may end up with some items of the same group selected and some
            // not selected. So by reselecting the current selection, the grouping links will ensure to have
            // a correct status.
            List <Layer.LayerItem> currentSelection = new List <Layer.LayerItem>(mLayer.SelectedObjects);

            mLayer.clearSelection();
            mLayer.addObjectInSelection(currentSelection);
        }
コード例 #3
0
        public SaveGroupNameForm()
        {
            InitializeComponent();

            // create an array of forbidden char for the group name (before setting the name of the group)
            List<char> charList = new List<char>(System.IO.Path.GetInvalidFileNameChars());
            foreach (char character in System.IO.Path.GetInvalidPathChars())
                if (!charList.Contains(character))
                    charList.Add(character);
            charList.Add('&'); // the ampersome is authorized in file name, but brings trouble in xml, since it is the escape char.
            mForbiddenChar = charList.ToArray();

            // save the error list from the text field
            char[] separator = { '|' };
            mErrorHint = this.nameErrorLabel.Text.Split(separator);

            // fill the language combo
            fillAndSelectLanguageComboBox();

            // set the author (could be overriden later)
            this.authorTextBox.Text = this.Author;

            // get the list of the top items
            List<Layer.LayerItem> topItems = Layer.sGetTopItemListFromList(Map.Instance.SelectedLayer.SelectedObjects);
            // fill the name if there's only one group selected
            if (topItems.Count == 1)
            {
                // if this window is called with one object, it should be normally a group
                // otherwise the save group cannot be called
                mGroupToSave = (topItems[0]) as Layer.Group;
                mWasGroupToSaveCreated = false;
                if (mGroupToSave.IsANamedGroup)
                {
                    string partNumber = mGroupToSave.PartNumber;
                    // set the name here and init the rest in the function
                    nameTextBox.Text = partNumber;
                    initControlWithPartInfo(partNumber);
                }
            }
            else
            {
                // sort the top items as on the layer
                topItems.Sort(Map.Instance.SelectedLayer.compareItemOrderOnLayer);
                // create a group temporally for the export purpose
                mGroupToSave = new Layer.Group();
                mGroupToSave.addItem(topItems);
                mWasGroupToSaveCreated = true;
            }

            // call explicitly the event to set the correct color and error message
            // after setting all the data members used to check the validity of the name
            this.nameTextBox_TextChanged(nameTextBox, null);

            // configure the xmlSetting for writing
            mXmlSettings.CheckCharacters = false;
            mXmlSettings.CloseOutput = true;
            mXmlSettings.ConformanceLevel = System.Xml.ConformanceLevel.Document;
            mXmlSettings.Encoding = new UTF8Encoding(false);
            mXmlSettings.Indent = true;
            mXmlSettings.IndentChars = "\t";
            mXmlSettings.NewLineChars = "\r\n";
            mXmlSettings.NewLineOnAttributes = false;
            mXmlSettings.OmitXmlDeclaration = false;
        }
コード例 #4
0
        public SaveGroupNameForm()
        {
            InitializeComponent();

            // create an array of forbidden char for the group name (before setting the name of the group)
            List <char> charList = new List <char>(System.IO.Path.GetInvalidFileNameChars());

            foreach (char character in System.IO.Path.GetInvalidPathChars())
            {
                if (!charList.Contains(character))
                {
                    charList.Add(character);
                }
            }
            charList.Add('&');             // the ampersome is authorized in file name, but brings trouble in xml, since it is the escape char.
            mForbiddenChar = charList.ToArray();

            // save the error list from the text field
            char[] separator = { '|' };
            mErrorHint = this.nameErrorLabel.Text.Split(separator);

            // fill the language combo
            fillAndSelectLanguageComboBox();

            // set the author (could be overriden later)
            this.authorTextBox.Text = this.Author;

            // get the list of the top items
            List <Layer.LayerItem> topItems = Layer.sGetTopItemListFromList(Map.Instance.SelectedLayer.SelectedObjects);

            // fill the name if there's only one group selected
            if (topItems.Count == 1)
            {
                // if this window is called with one object, it should be normally a group
                // otherwise the save group cannot be called
                mGroupToSave           = (topItems[0]) as Layer.Group;
                mWasGroupToSaveCreated = false;
                if (mGroupToSave.IsANamedGroup)
                {
                    string partNumber = mGroupToSave.PartNumber;
                    // set the name here and init the rest in the function
                    nameTextBox.Text = partNumber;
                    initControlWithPartInfo(partNumber);
                }
            }
            else
            {
                // sort the top items as on the layer
                topItems.Sort(Map.Instance.SelectedLayer.compareItemOrderOnLayer);
                // create a group temporally for the export purpose
                mGroupToSave = new Layer.Group();
                mGroupToSave.addItem(topItems);
                mWasGroupToSaveCreated = true;
            }

            // call explicitly the event to set the correct color and error message
            // after setting all the data members used to check the validity of the name
            this.nameTextBox_TextChanged(nameTextBox, null);

            // configure the xmlSetting for writing
            mXmlSettings.CheckCharacters     = false;
            mXmlSettings.CloseOutput         = true;
            mXmlSettings.ConformanceLevel    = System.Xml.ConformanceLevel.Document;
            mXmlSettings.Encoding            = new UTF8Encoding(false);
            mXmlSettings.Indent              = true;
            mXmlSettings.IndentChars         = "\t";
            mXmlSettings.NewLineChars        = "\r\n";
            mXmlSettings.NewLineOnAttributes = false;
            mXmlSettings.OmitXmlDeclaration  = false;
        }