private void OnCmdCreateGroup() { ObservableCollection<IElement> addCollection = new ObservableCollection<IElement>(); ObservableCollection<GroupInfo> groupCollection = new ObservableCollection<GroupInfo>(); RectElement groupframe = new RectElement(); groupframe.ElementSelectedState = SelectedState.Selected; groupframe.EleType = ElementType.groupframe; groupframe.ZIndex = 2; groupframe.GroupName = _myScreenLayer.MaxGroupName + 1; _myScreenLayer.MaxGroupName += 1; groupframe.ZOrder = _myScreenLayer.MaxZorder + 1; _myScreenLayer.MaxZorder += 1; groupframe.X = _currentSelectedElement[-1].SelectedElementRect.X; groupframe.Y = _currentSelectedElement[-1].SelectedElementRect.Y; groupframe.Width=_currentSelectedElement[-1].SelectedElementRect.Width; groupframe.Height = _currentSelectedElement[-1].SelectedElementRect.Height; groupframe.ParentElement = _myScreenLayer; for (int i = 0; i < _currentSelectedElement[-1].SelectedGroupElementList.Count; i++) { RectElement rect = (RectElement)(RectElement)_currentSelectedElement[-1].SelectedGroupElementList[i]; rect.GroupName = groupframe.GroupName; GroupInfo groupInfo = new GroupInfo(rect, new OldAndNewType(-1, rect.GroupName)); groupCollection.Add(groupInfo); } _groupframeList.Add(groupframe.GroupName, groupframe); _myScreenLayer.ElementCollection.Add(groupframe); addCollection.Add(groupframe); foreach (int key in _currentSelectedElement.Keys) { if (key == -1 && _currentSelectedElement[key].SelectedGroupElementList.Count==0 && _currentSelectedElement[key].NoSelectedGroupElementList.Count==0) { _groupframeList.Remove(key); break; } } GetCurrentElementInfo(); AddAction addAction = new AddAction(_myScreenLayer,addCollection); CreatOrCancelGroupAction groupAction = new CreatOrCancelGroupAction(groupCollection); using (Transaction.Create(SmartLCTActionManager)) { SmartLCTActionManager.RecordAction(addAction); SmartLCTActionManager.RecordAction(groupAction); } }
private void OnCmdCancelGroup() { ObservableCollection<IElement> deleteCollection = new ObservableCollection<IElement>(); ObservableCollection<GroupInfo> groupInfoCollection = new ObservableCollection<GroupInfo>(); foreach (int key in _currentSelectedElement.Keys) { if (_currentSelectedElement[key].SelectedGroupElementList.Count == 0) { continue; } for (int i = 0; i < _currentSelectedElement[key].SelectedGroupElementList.Count; i++) { IRectElement rect = _currentSelectedElement[key].SelectedGroupElementList[i]; GroupInfo groupInfo = new GroupInfo(rect,new OldAndNewType(rect.GroupName,-1)); groupInfoCollection.Add(groupInfo); rect.GroupName = -1; } deleteCollection.Add(_groupframeList[key]); _myScreenLayer.ElementCollection.Remove(_groupframeList[key]); _groupframeList.Remove(key); } if(!_groupframeList.Keys.Contains(-1)) _groupframeList.Add(-1, null); GetCurrentElementInfo(); DeleteAction deleteAction = new DeleteAction(_myScreenLayer,deleteCollection); CreatOrCancelGroupAction groupAction = new CreatOrCancelGroupAction(groupInfoCollection); using (Transaction.Create(SmartLCTActionManager)) { SmartLCTActionManager.RecordAction(deleteAction); SmartLCTActionManager.RecordAction(groupAction); } }