public void UnExecute() { StageView stage = MainForm.CurrentStage; Library lib = MainForm.CurrentLibrary; LibraryView libView = MainForm.CurrentLibraryView; for (int i = removedTreeNodes.Length - 1; i >= 0; i--) { LibraryTreeNode liv = removedTreeNodes[i]; lib.AddLibraryItem(liv.item); libView.InsertNode(liv, removedPaths[i], removedIndexes[i]); } // todo: need to readd bonds and snaps. for (int i = removedInstances.Length - 1; i >= 0; i--) { stage.AddInstance(removedInstances[i]); } libView.SelectNode(selectedNode); removedInstances = null; removedTreeNodes = null; removedPaths = null; removedIndexes = null; selectedNode = null; stage.InvalidateAll(); libView.RefreshCurrentNode(); }
public void Execute() { StageView stage = MainForm.CurrentStage; // store old selection prevSelected = stage.Selection.IdsByDepth;// SelectedIds; prevOffset = stage.Selection.StrokeBounds.Point; // create symbol from selected Vex.Timeline tl = new Vex.Timeline(stage.Library.NextLibraryId()); tl.Name = stage.Library.GetNextDefaultName(); tl.StrokeBounds = stage.Selection.StrokeBounds.TranslatedRectangle(-prevOffset.X, -prevOffset.Y); // delete old symbols DesignInstance[] oldInstances = stage.RemoveInstancesById(prevSelected); for (int i = 0; i < prevSelected.Length; i++) { DesignInstance inst = oldInstances[i];// instMgr[prevSelected[i]]; Vex.Matrix m = inst.GetMatrix(); m.TranslateX -= prevOffset.X; m.TranslateY -= prevOffset.Y; inst.SetMatrix(m); tl.AddInstance(inst.Instance); stage.InstanceManager.AddInstance(inst); // reusing, so must readd (todo: don't reuse ids?) } LibraryItem li = stage.CreateLibraryItem(tl, true); newLibraryItemId = li.DefinitionId; stage.Library.AddLibraryItem(li); LibraryView.CurrentLibraryView.AddItemToLibrary(li); // add new symbol to stage DesignInstance di = stage.AddInstance(tl.Id, prevOffset); newInstanceId = di.InstanceHash; // select new symbol stage.Selection.Set(new uint[] { di.InstanceHash }); stage.ResetTransformHandles(); stage.InvalidateSelection(); }
public void Execute() { StageView stage = MainForm.CurrentStage; InstanceGroup sel = stage.Selection; InstanceManager instMgr = stage.InstanceManager; prevSelection = sel.IdsByDepth; List <uint> addedInstances = new List <uint>(); List <uint> newSelection = new List <uint>(); List <uint> toBreakApart = new List <uint>(); List <int> originalDepths = new List <int>(); for (int i = 0; i < prevSelection.Length; i++) { DesignInstance di = instMgr[prevSelection[i]]; if (CanBreakApart(di)) { toBreakApart.Add(prevSelection[i]); originalDepths.Add(di.Depth); } else { newSelection.Add(prevSelection[i]); } } prevInstances = toBreakApart.ToArray(); prevDepths = originalDepths.ToArray(); sel.Clear(); for (int i = 0; i < toBreakApart.Count; i++) { uint id = toBreakApart[i]; DesignInstance di = instMgr[id]; int orgDepth = di.Depth; Matrix orgMatrix = di.GetSysMatrix(); Vex.Point offset = di.Location; uint[] instances = ((DesignTimeline)di).InstanceIds; for (int j = instances.Length - 1; j >= 0; j--) { DesignInstance orgInstance = instMgr[instances[j]]; uint subLibId = orgInstance.LibraryItem.DefinitionId; DesignInstance inst = stage.AddInstance(subLibId, Vex.Point.Zero); stage.CurrentEditItem.ChangeDepth(inst.Depth, orgDepth); using (Matrix m = orgInstance.GetSysMatrix().Clone()) { m.Multiply(orgMatrix, MatrixOrder.Append); stage.SetDesignInstanceMatrix(inst, m.VexMatrix()); } addedInstances.Add(inst.InstanceHash); newSelection.Add(inst.InstanceHash); } stage.RemoveInstancesById(new uint[] { id }); } newInstances = addedInstances.ToArray(); sel.Set(newSelection.ToArray()); stage.ResetTransformHandles(); }