public override string getName() { if (mItems.Count == 1) { string actionName = BlueBrick.Properties.Resources.ActionMoveText; // if the first item is a group, search recursively the first non group item Layer.LayerItem firstItem = mItems[0]; while (firstItem.IsAGroup) { firstItem = (firstItem as Layer.Group).Items[0]; } // get the text and cut it if it is too long string text = (firstItem as LayerText.TextCell).Text.Replace("\r\n", " "); if (text.Length > 10) { text = text.Substring(0, 10) + "..."; } // construct the action name actionName = actionName.Replace("&", text); return(actionName); } else { return(BlueBrick.Properties.Resources.ActionMoveSeveralTexts); } }
/// <summary> /// From a list of items to group, find and construct the top items of the forest, such as /// you can only group the top items and get a hierarchical tree. /// </summary> /// <param name="itemsToGroup">A list of items (usually not group) that you want to group</param> /// <returns>A list of top tree items (that can be group) that can be put inside a group</returns> static public List <Layer.LayerItem> findItemsToGroup(List <Layer.LayerItem> itemsToGroup) { // create a search list that we will expend and to keep the original selection intact List <Layer.LayerItem> searchList = new List <Layer.LayerItem>(itemsToGroup); List <Layer.LayerItem> result = new List <Layer.LayerItem>(itemsToGroup.Count); // we cannot use a foreach keyword here because it through an exception when // the list is modified during the iteration, which is exactly what I want to do for (int i = 0; i < searchList.Count; ++i) { Layer.LayerItem item = searchList[i]; if (!result.Contains(item)) { if (item.Group == null) { result.Add(item); } else if (!searchList.Contains(item.Group)) { searchList.Add(item.Group); } } } return(result); }
private string mPartNumber = string.Empty; //if the list contains only one brick or one group, this is the name of this specific brick or group public DeleteBrick(LayerBrick layer, List <Layer.LayerItem> bricksToDelete) { mBrickLayer = layer; mBrickIndex = new List <int>(bricksToDelete.Count); mBricksForNotification = Layer.sFilterListToGetOnlyBricksInLibrary(bricksToDelete); // copy the list, because the pointer may change (specially if it is the selection) mBricks = new List <Layer.LayerItem>(bricksToDelete.Count); foreach (Layer.LayerItem obj in bricksToDelete) { mBricks.Add(obj); } // try to get a part number (which can be the name of a group) Layer.LayerItem topItem = Layer.sGetTopItemFromList(mBricks); if (topItem != null) { if (topItem.IsAGroup) { mPartNumber = (topItem as Layer.Group).PartNumber; } else { mPartNumber = (topItem as LayerBrick.Brick).PartNumber; } } }
public static List <Layer.Group> findItemsToUngroup(List <Layer.LayerItem> itemsToUngroup) { // create a search list that we will expend and to keep the original selection intact List <Layer.LayerItem> searchList = new List <Layer.LayerItem>(itemsToUngroup); List <Layer.Group> result = new List <Layer.Group>(itemsToUngroup.Count); // Search the top group of the tree, because this action only ungroup the top of the tree // The list of items to ungroup can also be a forest, so keep all the top of the trees for (int i = 0; i < searchList.Count; ++i) { Layer.LayerItem item = searchList[i]; // check if this item as a father group or is single (top item) if (item.Group == null) { // check if this item is a group that can be ungrouped or a simple item by casting it Layer.Group group = item as Layer.Group; // if it is a group that can be ungrouped and not already in the list, add it to the list if ((group != null) && group.CanUngroup && !result.Contains(group)) { result.Add(group); } } else if (!searchList.Contains(item.Group)) { // add it to the search list even if this father group is cannot be ungroup because a grand father // could be ungroupable above, so we need to do the exhaustive forest search searchList.Add(item.Group); } } return(result); }
public DuplicateBrick(LayerBrick layer, List <Layer.LayerItem> bricksToDuplicate, bool needToAddOffset) : base(bricksToDuplicate, needToAddOffset, Budget.Budget.Instance.ShouldUseBudgetLimitation) { // init the layer mBrickLayer = layer; // elagate the list according to the budget limit mWereItemsTrimmed = trimItemListWithBudgetLimitation(); // get bricks for the notification from the trimmed list mBricksForNotification = Layer.sFilterListToGetOnlyBricksInLibrary(mItems); // remove the group that were added to the item list for brick notification purpose // they are added at the end, so find the first one and erase the end if (Budget.Budget.Instance.ShouldUseBudgetLimitation) { for (int i = 0; i < mItems.Count; ++i) { if (mItems[i].IsAGroup) { mItems.RemoveRange(i, mItems.Count - i); break; } } } // try to get a part number (which can be the name of a group) Layer.LayerItem topItem = Layer.sGetTopItemFromList(mItems); if (topItem != null) { mPartNumber = topItem.PartNumber; } }
protected void rotate(Layer.LayerItem item, Matrix rotation, float rotationAngle, bool adjustPivot) { // get the pivot point of the part before the rotation PointF pivot = item.Pivot; // change the orientation of the picture item.Orientation = (item.Orientation + rotationAngle); // for some items partially attached, we may don't want to adjust the pivot if (adjustPivot) { // adjust the position of the pivot for a group of items if (mItems.Count > 1) { PointF[] points = { new PointF(pivot.X - mCenter.X, pivot.Y - mCenter.Y) }; rotation.TransformVectors(points); // assign the new position pivot.X = mCenter.X + points[0].X; pivot.Y = mCenter.Y + points[0].Y; } // assign the new pivot position after rotation item.Pivot = pivot; } }
public AddBrick(LayerBrick layer, Layer.LayerItem brickOrGroup) { mBrickLayer = layer; mBrickOrGroup = brickOrGroup; // after setting the brick or group, call the init brick list function initBrickList(); }
private void SelectAllButton_Click(object sender, EventArgs e) { // get the search part string searchingPartNumber = this.FindComboBox.SelectedItem as string; // the new list of object to select List <Layer.LayerItem> objectToSelect = new List <Layer.LayerItem>(); // get the current selected layer because we will need it (normally it is never null) Layer selectedLayer = Map.Instance.SelectedLayer; if (selectedLayer != null) { // check if the selection must be performed in the current selection // or in a new layer if (this.inCurrentSelectionRadioButton.Checked) { // sub select in current selection, iterate on the selection int nbSelectedItems = selectedLayer.SelectedObjects.Count; for (int i = 0; i < nbSelectedItems; ++i) { Layer.LayerItem currentItem = selectedLayer.SelectedObjects[i]; string currentPartNumber = (currentItem as LayerBrick.Brick).PartNumber; if (currentPartNumber.Equals(searchingPartNumber)) { objectToSelect.Add(currentItem); } } } else if (this.LayerCheckedListBox.CheckedItems.Count == 1) { // find in which layer the selection should be done LayerBrick layerToSelect = mBrickOnlyLayerList[this.LayerCheckedListBox.CheckedIndices[0]]; // First we need to select the target layer if not already selected if (selectedLayer != layerToSelect) { Actions.ActionManager.Instance.doAction(new Actions.Layers.SelectLayer(layerToSelect)); // important to update the new selected layer for the rest of the code selectedLayer = layerToSelect; } // then iterate on all the bricks of the selected layer to find the one we search foreach (LayerBrick.Brick brick in layerToSelect.BrickList) { if (brick.PartNumber.Equals(searchingPartNumber)) { objectToSelect.Add(brick); } } } } // select the new objects selectedLayer.clearSelection(); selectedLayer.addObjectInSelection(objectToSelect); // close the window this.Close(); }
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); }
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); } } } } }
public AddBrick(LayerBrick layer, string partNumber) { mBrickLayer = layer; if (BrickLibrary.Instance.isAGroup(partNumber)) mBrickOrGroup = new Layer.Group(partNumber); else mBrickOrGroup = new LayerBrick.Brick(partNumber); // after setting the brick or group, call the init brick list function initBrickList(); }
private string mPartNumber = string.Empty; //if the list contains only one brick or one group, this is the name of this specific brick or group public MoveBrick(LayerBrick layer, List <Layer.LayerItem> bricks, PointF move) : base(layer, bricks, move) { // try to get a part number (which can be the name of a group) Layer.LayerItem topItem = Layer.sGetTopItemFromList(mItems); if (topItem != null) { mPartNumber = topItem.PartNumber; // part number is virtual, works both for part and group } }
/// <summary> /// Add a new single part which has the specified partNumber on the specifier layer, and connected it to /// the specified selectedItem (part or group) using the specified wanted connection for that new part. /// </summary> /// <param name="layer">The layer on which to add the part, and in which the selectedItem is selected</param> /// <param name="selectedItem">The single selected item (this can be a single part or a single group). This parameter cannot be null.</param> /// <param name="partNumber">The number of the part to add</param> /// <param name="wantedConnexion">The connection index of the part to add that should be used to connect to the selected item, or -1 if you don't care.</param> public AddConnectBrick(LayerBrick layer, Layer.LayerItem selectedItem, string partNumber, int wantedConnexion) { // the selected item should not be null System.Diagnostics.Debug.Assert(selectedItem != null); mBrickLayer = layer; mBrick = new LayerBrick.Brick(partNumber); LayerBrick.Brick selectedBrick = layer.getConnectableBrick(); bool hasAGoodConnectionBeenFound = false; // check if the selected brick and the brick to add have connection points, and if we can find a good connection match // The selected brick can be null if there's no connection in the single group connected in the layer if ((selectedBrick != null) && selectedBrick.HasConnectionPoint && mBrick.HasConnectionPoint) { // choose the best active connection point for the brick hasAGoodConnectionBeenFound = setBestConnectionPointIndex(selectedBrick, mBrick, wantedConnexion); } // check if we found a good connection, continue to set the position of the brick to add relative to the connection if (hasAGoodConnectionBeenFound) { // then rotate the brick to connect mBrick.Orientation = sGetOrientationOfConnectedBrick(selectedBrick, mBrick); // the place the brick to add at the correct position mBrick.ActiveConnectionPosition = selectedBrick.ActiveConnectionPosition; } else { // and just compute the position to the right of the selected item PointF position = selectedItem.Position; position.X += selectedItem.DisplayArea.Width; mBrick.Position = position; // the reassing the selected brick with the first brick of the group if the selected item is a group // so that the brick index can correctly be set if (selectedItem.IsAGroup) { selectedBrick = (selectedItem as Layer.Group).getAllLeafItems()[0] as LayerBrick.Brick; } else { selectedBrick = selectedItem as LayerBrick.Brick; } } // set the index of the brick in the list just after the selected brick if (selectedBrick != null) { mBrickIndex = layer.BrickList.IndexOf(selectedBrick) + 1; } }
private List <int> mBrickIndex = null; // this list of index is for the redo, to add each text at the same place public AddBrick(LayerBrick layer, string partNumber) { mBrickLayer = layer; if (BrickLibrary.Instance.isAGroup(partNumber)) { mBrickOrGroup = new Layer.Group(partNumber); } else { mBrickOrGroup = new LayerBrick.Brick(partNumber); } // after setting the brick or group, call the init brick list function initBrickList(); }
private Layer.LayerItem createReplacementBrick(Layer.LayerItem brick, string newPartNumber) { // compute the altitude of the brick we want to replace float altitude = 0.0f; if (brick.IsAGroup) { // get the average altitude of all the children List <Layer.LayerItem> children = (brick as Layer.Group).getAllLeafItems(); if (children.Count > 0) { foreach (Layer.LayerItem child in children) { altitude += (child as LayerBrick.Brick).Altitude; } altitude /= children.Count; } } else { altitude = (brick as LayerBrick.Brick).Altitude; } // create a new brick and copy all the parameters of the old one Layer.LayerItem newBrick = null; if (BrickLibrary.Instance.isAGroup(newPartNumber)) { newBrick = new Layer.Group(newPartNumber); // set the altitude to all children List <Layer.LayerItem> children = (newBrick as Layer.Group).getAllLeafItems(); foreach (Layer.LayerItem child in children) { (child as LayerBrick.Brick).Altitude = altitude; } } else { newBrick = new LayerBrick.Brick(newPartNumber); (newBrick as LayerBrick.Brick).Altitude = altitude; } newBrick.Orientation = brick.Orientation; newBrick.Center = brick.Center; // return the new brick return(newBrick); }
/// <summary> /// Call this method when you want to notify the budget counter that a brick has been removed /// </summary> /// <param name="layer">The layer on which the brick is removed</param> /// <param name="brick">the brick that was removed</param> /// <param name="isDueToUngroup">tell if the brick is a group that is ungrouped</param> public void removeBrickNotification(LayerBrick layer, Layer.LayerItem brickOrGroup, bool isDueToUngroup) { string partID = brickOrGroup.PartNumber; if (partID != string.Empty) { // get the current count int currentCount = 0; mCount.TryGetValue(partID, out currentCount); if (currentCount > 0) { // update the value mCount.Remove(partID); mCount.Add(partID, currentCount - 1); } // also update in the layered dictionary Dictionary <string, int> layeredCount = null; if (mCountPerLayer.TryGetValue(layer, out layeredCount)) { int currentCountInLayer = 0; layeredCount.TryGetValue(partID, out currentCountInLayer); if (currentCountInLayer > 0) { layeredCount.Remove(partID); layeredCount.Add(partID, currentCountInLayer - 1); } } // if the layer doesn't exist, we have nothing to remove } // remove also all the named children if the brick is a group // (unless it is a ungroup in that case we leave the children and just remove the one we ungrouped) if (!isDueToUngroup) { Layer.Group group = brickOrGroup as Layer.Group; if (group != null) { foreach (Layer.LayerItem item in group.Items) { removeBrickNotification(layer, item, isDueToUngroup); } } } }
/// <summary> /// Call this method when you want to notify the budget counter that a new brick has been added /// </summary> /// <param name="layer">The layer on which the brick is added</param> /// <param name="brick">the brick that was added</param> /// <param name="isDueToRegroup">tells if the brick is a group that was regrouped by an undo</param> public void addBrickNotification(LayerBrick layer, Layer.LayerItem brickOrGroup, bool isDueToRegroup) { string partID = brickOrGroup.PartNumber; if (partID != string.Empty) { // get the current count in the count dictionary int currentCount = 0; mCount.TryGetValue(partID, out currentCount); // and update the value in the global dictionnary mCount.Remove(partID); mCount.Add(partID, currentCount + 1); // also update in the layered dictionary Dictionary <string, int> layeredCount = null; if (mCountPerLayer.TryGetValue(layer, out layeredCount)) { int currentCountInLayer = 0; layeredCount.TryGetValue(partID, out currentCountInLayer); layeredCount.Remove(partID); layeredCount.Add(partID, currentCountInLayer + 1); } else { // this is a new layer (this layer didn't exist before), so add the layer and also the count layeredCount = new Dictionary <string, int>(); layeredCount.Add(partID, 1); mCountPerLayer.Add(layer, layeredCount); } } // add also all the named children if the brick is a group // (unless it is a regroup in that case the children are already counted) if (!isDueToRegroup) { Layer.Group group = brickOrGroup as Layer.Group; if (group != null) { foreach (Layer.LayerItem item in group.Items) { addBrickNotification(layer, item, isDueToRegroup); } } } }
protected override void commonConstructor(Layer layer, List <Layer.LayerItem> bricks, float angle, bool forceKeepLastCenter) { // call the base method base.commonConstructor(layer, bricks, angle, forceKeepLastCenter); // try to get a part number (which can be the name of a group) Layer.LayerItem topItem = Layer.sGetTopItemFromList(mItems); if (topItem != null) { if (topItem.IsAGroup) { mPartNumber = (topItem as Layer.Group).PartNumber; } else { mPartNumber = (topItem as LayerBrick.Brick).PartNumber; } } }
protected override void addItem(Layer.LayerItem item, int position) { (mLayer as LayerRuler).addRulerItem(item as LayerRuler.RulerItem, position); }
private int mNextPreferedActiveConnectionIndex = 0; // the prefered active connection index according to the brick library /// <summary> /// Add a new named group which has the specified partNumber on the specifier layer, and connected it to /// the specified selectedItem (part or group) using the specified wanted connection for that new part. /// </summary> /// <param name="layer">The layer on which to add the group, and in which the selectedItem is selected</param> /// <param name="selectedItem">The single selected item (this can be a single part or a single group). This parameter cannot be null.</param> /// <param name="partNumber">The number of the named group to add</param> /// <param name="wantedConnexion">The connection index of the group to add that should be used to connect to the selected item, or -1 if you don't care.</param> public AddConnectGroup(LayerBrick layer, Layer.LayerItem selectedItem, string partNumber, int wantedConnexion) { // the selected item should not be null System.Diagnostics.Debug.Assert(selectedItem != null); // save the layer and construct the group mBrickLayer = layer; mGroup = new Layer.Group(partNumber); // get the flat list of bricks from the hierarchical group mBricksInTheGroup = mGroup.getAllLeafItems(); // get the connectable brick among the selection, and also the selected item (in case the selected item is a single group without connections points) LayerBrick.Brick selectedBrick = layer.getConnectableBrick(); LayerBrick.Brick brickToConnectInAddedGroup = null; // check if we can attach the group to the unique selected object if ((selectedBrick != null) && selectedBrick.HasConnectionPoint) { // find the brick of the group that will be connected to the selected brick brickToConnectInAddedGroup = findBrickToConnectAndSetBestConnectionPointIndex(selectedItem, ref wantedConnexion); } // check if the brick to connect is valid and has connection point if ((brickToConnectInAddedGroup != null) && brickToConnectInAddedGroup.HasConnectionPoint) { // after setting the active connection point index from which this brick will be attached, // get the prefered index from the library mNextPreferedActiveConnectionIndex = BrickLibrary.Instance.getConnectionNextPreferedIndex(partNumber, wantedConnexion); // Compute the orientation of the bricks float newOrientation = AddConnectBrick.sGetOrientationOfConnectedBrick(selectedBrick, brickToConnectInAddedGroup); newOrientation -= brickToConnectInAddedGroup.Orientation; // Rotate all the bricks of the group first before translating RotateBrickOnPivotBrick rotateBricksAction = new RotateBrickOnPivotBrick(layer, mBricksInTheGroup, newOrientation, brickToConnectInAddedGroup); rotateBricksAction.MustUpdateBrickConnectivity = false; rotateBricksAction.redo(); // compute the translation to add to all the bricks PointF translation = new PointF(selectedBrick.ActiveConnectionPosition.X - brickToConnectInAddedGroup.ActiveConnectionPosition.X, selectedBrick.ActiveConnectionPosition.Y - brickToConnectInAddedGroup.ActiveConnectionPosition.Y); mGroup.translate(translation); } else { // and just compute the position to the right of the selected item PointF position = selectedItem.Position; position.X += selectedItem.DisplayArea.Width; mGroup.Position = position; // the reassing the selected brick with the first brick of the group if the selected item is a group // so that the brick index can correctly be set if (selectedItem.IsAGroup) { selectedBrick = (selectedItem as Layer.Group).getAllLeafItems()[0] as LayerBrick.Brick; } else { selectedBrick = selectedItem as LayerBrick.Brick; } } // set the index of the group in the list just after the selected brick if (selectedBrick != null) { mInsertIndex = layer.BrickList.IndexOf(selectedBrick) + 1; } }
protected override int removeItem(Layer.LayerItem item) { return((mLayer as LayerRuler).removeRulerItem(item as LayerRuler.RulerItem)); }
/// <summary> /// This tool method clones all the item of the specified list into a new list. /// This method also clone the groups that may belong to this list of bricks. /// The cloned items are in the same order as the original list /// </summary> /// <param name="listToClone">The original list of brick to copy</param> /// <param name="addGroupsInItemList">if this parameter is true, the groups are also added in the Items list</param> /// <returns>A clone list of cloned brick with there cloned groups</returns> protected List <Layer.LayerItem> cloneItemList(List <Layer.LayerItem> listToClone, bool addGroupsInItemList) { // the resulting list List <Layer.LayerItem> result = new List <Layer.LayerItem>(listToClone.Count); // use a dictionnary to recreate the groups that may be inside the list of brick to duplicate // this dictionnary makes an association between the group to duplicate and the new duplicated one Dictionary <Layer.Group, Layer.Group> groupsToCreate = new Dictionary <Layer.Group, Layer.Group>(); // also use a list of item that we will make grow to create all the groups List <Layer.LayerItem> fullOriginalItemList = new List <Layer.LayerItem>(listToClone); // use a for instead of a foreach because the list will grow for (int i = 0; i < fullOriginalItemList.Count; ++i) { // get the current item Layer.LayerItem originalItem = fullOriginalItemList[i]; Layer.LayerItem duplicatedItem = null; // check if the item is a group or a brick if (originalItem.IsAGroup) { // if the item is a group that means the list already grown, and that means we also have it in the dictionnary Layer.Group associatedGroup = null; groupsToCreate.TryGetValue(originalItem as Layer.Group, out associatedGroup); duplicatedItem = associatedGroup; // check if we also need to add the group if (addGroupsInItemList) { result.Add(duplicatedItem); } } else { // if the item is a brick, just clone it and add it to the result // clone the item (because the same list of text to add can be paste several times) duplicatedItem = originalItem.Clone(); // add the duplicated item in the list result.Add(duplicatedItem); } // check if the item to clone belongs to a group then also duplicate the group if (originalItem.Group != null) { // get the duplicated group if already created otherwise create it and add it in the dictionary Layer.Group duplicatedGroup = null; groupsToCreate.TryGetValue(originalItem.Group, out duplicatedGroup); if (duplicatedGroup == null) { duplicatedGroup = new Layer.Group(originalItem.Group); groupsToCreate.Add(originalItem.Group, duplicatedGroup); fullOriginalItemList.Add(originalItem.Group); } // assign the group to the brick duplicatedGroup.addItem(duplicatedItem); // check if we need to also assign the brick that hold the connection point if (originalItem.Group.BrickThatHoldsActiveConnection == originalItem) { duplicatedGroup.BrickThatHoldsActiveConnection = (duplicatedItem as LayerBrick.Brick); } } } // delete the dictionary groupsToCreate.Clear(); fullOriginalItemList.Clear(); // return the cloned list return(result); }
/// <summary> /// This method is used to sort items in a list in the same order as they are in the layer list. /// The items can be groups, in that case, we use the max index of all the leaf children. /// </summary> /// <param name="item1">the first item to compare</param> /// <param name="item2">the second item t compare</param> /// <returns>distance between the two items in the layer list (index1 - index2)</returns> public override int compareItemOrderOnLayer(Layer.LayerItem item1, Layer.LayerItem item2) { return(compareItemOrderOnLayer(mTexts, item1, item2)); }
protected abstract void addItem(Layer.LayerItem item, int position);
protected abstract int removeItem(Layer.LayerItem item);
protected override int removeItem(Layer.LayerItem item) { return((mLayer as LayerText).removeTextCell(item as LayerText.TextCell)); }
protected override void addItem(Layer.LayerItem item, int position) { (mLayer as LayerText).addTextCell(item as LayerText.TextCell, position); }
protected override void addItem(Layer.LayerItem item, int position) { (mLayer as LayerBrick).addBrickWithoutChangingConnectivity(item as LayerBrick.Brick, position); }
protected override int removeItem(Layer.LayerItem item) { return((mLayer as LayerBrick).removeBrickWithoutChangingConnectivity(item as LayerBrick.Brick)); }
public BrickPair(Layer.LayerItem oldBrick, Layer.LayerItem newBrick) { mOldBrick = oldBrick; mNewBrick = newBrick; }
public ReplaceBrick(List <LayerBrick> layerList, string partNumberToReplace, string newPartNumber, bool replaceInSelectionOnly) { // store the list of layer for which this action apply and create a list of the same size for the bricks mBrickLayerList = layerList; mPartNumberToReplace = partNumberToReplace; mBrickPairList = new List <List <BrickPair> >(layerList.Count); // use a counter of brick replaced, to avoid exceeding the budget int replacedBrickCount = 0; // iterate on all the layers foreach (LayerBrick layer in layerList) { // memorize the layer that has the selected bricks if (layer.SelectedObjects.Count > 0) { mLayerWhereToSelectTheReplacedBricks = layer; } // add the list of brick pair (that can stay empty if no brick is found in that layer) List <BrickPair> currentPairList = new List <BrickPair>(); mBrickPairList.Add(currentPairList); // compute the list of bricks on which we should iterate List <Layer.LayerItem> itemsToReplace = null; if (replaceInSelectionOnly) { itemsToReplace = computeListOfItemToReplace(layer.SelectedObjects); } else { itemsToReplace = computeListOfItemToReplace(layer.BrickList); } // iterate on all the bricks of the layer or on the selection to find the brick to replace foreach (Layer.LayerItem item in itemsToReplace) { // increase the count of brick to replace replacedBrickCount++; // then check if we can add the brick if (Budget.Budget.Instance.canAddBrick(newPartNumber, replacedBrickCount, true)) { // create the new item Layer.LayerItem newItem = createReplacementBrick(item, newPartNumber); // create the pair and add it to the list BrickPair brickPair = new BrickPair(item, newItem); currentPairList.Add(brickPair); // check if we also need to add this pair to the list of brick to reselect if (layer.SelectedObjects.Contains(item)) { mReplacedBricksToSelect.Add(brickPair); } } else { // beep if we reach the limit Map.Instance.giveFeedbackForNotAddingBrick(Map.BrickAddability.YES_AND_NO_REPLACEMENT_LIMITED_BY_BUDGET); // no need to continue if we cannot add more bricks, so stop the iteration mIsLimitedByBudget = true; break; } } // stop iterating on the layer if we reach the limit if (mIsLimitedByBudget) { break; } } }
private void MapPanel_DragLeave(object sender, EventArgs e) { // if the user leave the panel while is was dropping a part, // just cancel the drop if (mCurrentPartDrop != null) { // remove and destroy the part if (mBrickLayerThatReceivePartDrop != null) { mBrickLayerThatReceivePartDrop.removeTemporaryPartDrop(mCurrentPartDrop); mBrickLayerThatReceivePartDrop = null; } mCurrentPartDrop = null; // update the view updateView(); } }
private void MapPanel_DragEnter(object sender, DragEventArgs e) { // if the number of click is null, that means it can be a dragndrop from another view, such as the part lib // check if we need to search the image dropped, or if we already have it if (mCurrentPartDrop == null) { // by default do not accept the drop e.Effect = DragDropEffects.None; // ask the main window if one part was selected in the part lib // because the getData from the event doesn't work well under mono, normally it should be: e.Data.GetData(DataFormats.SystemString) as string string partDropNumber = (this.TopLevelControl as MainForm).getDraggingPartNumberInPartLib(); // check if we can add it Map.BrickAddability canAdd = Map.Instance.canAddBrick(partDropNumber); if (canAdd == Map.BrickAddability.YES) { mBrickLayerThatReceivePartDrop = Map.Instance.SelectedLayer as LayerBrick; if (partDropNumber != null && mBrickLayerThatReceivePartDrop != null) { if (BrickLibrary.Instance.isAGroup(partDropNumber)) mCurrentPartDrop = new Layer.Group(partDropNumber); else mCurrentPartDrop = new LayerBrick.Brick(partDropNumber); mBrickLayerThatReceivePartDrop.addTemporaryPartDrop(mCurrentPartDrop); // set the effect in order to get the drop event e.Effect = DragDropEffects.Copy; } } else Map.Instance.giveFeedbackForNotAddingBrick(canAdd); } // check again if we are not dragging a part, maybe we drag a file if (mCurrentPartDrop == null) (this.TopLevelControl as MainForm).MainForm_DragEnter(sender, e); }
private void MapPanel_DragDrop(object sender, DragEventArgs e) { if (mCurrentPartDrop != null) { // we have finished a dragndrop, remove the temporary part if (mBrickLayerThatReceivePartDrop != null) { mBrickLayerThatReceivePartDrop.removeTemporaryPartDrop(mCurrentPartDrop); mBrickLayerThatReceivePartDrop = null; } // and add the real new part Map.Instance.addBrick(mCurrentPartDrop); // reset the dropping part number here and there mCurrentPartDrop = null; (this.TopLevelControl as MainForm).resetDraggingPartNumberInPartLib(); // refresh the view updateView(); // and give the focus to the map panel such as if the user use the wheel to zoom // just after after the drop, the zoom is performed instead of the part lib scrolling this.Focus(); } else { // if it is not a string, call the drag enter of the main app (this.TopLevelControl as MainForm).MainForm_DragDrop(sender, e); } }