void undoMove(CreateNodeAction createNodeAction) { if (createNodeAction == null) { return; } StageNode stageNode = new StageNode(createNodeAction.Position, createNodeAction.Width); if (createNodeAction.IndexInList != GlobalConst.INVALID_ID) { nodes.RemoveAt(createNodeAction.IndexInList); } else { nodes.RemoveAt(Nodes.Count - 1); } }
void makeMove(CreateNodeAction createNodeAction) { if (createNodeAction == null) { return; } StageNode stageNode = new StageNode(createNodeAction.Position, createNodeAction.Width); if (createNodeAction.IndexInList != GlobalConst.INVALID_ID) { Nodes.Insert(createNodeAction.IndexInList, stageNode); } else { Nodes.Add(stageNode); } }
/// <summary> /// Generates <see cref="NodeAction"/> according to <see cref="NodeDifference.MovementInfo"/>. /// </summary> /// <param name="difference">The difference.</param> protected virtual void ProcessMovement(NodeDifference difference) { var source = difference.Source; var target = difference.Target; var isImmutable = Context.IsImmutable; var isChanged = (difference.MovementInfo & MovementInfo.Changed) != 0; var isCreated = (difference.MovementInfo & MovementInfo.Created) != 0; var isRemoved = (difference.MovementInfo & MovementInfo.Removed) != 0 || (isImmutable && difference.HasChanges && !isCreated); var sc = StringComparer.OrdinalIgnoreCase; switch (Stage) { case UpgradeStage.CleanupData: if (difference.IsDataChanged) { Hints.GetHints <UpdateDataHint>(difference.Source) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); Hints.GetHints <DeleteDataHint>(difference.Source) .Where(hint => !hint.PostCopy) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); } break; case UpgradeStage.Prepare: if (isRemoved && !difference.IsRemoveOnCleanup) { if (!Context.IsRemoved || difference.IsDependentOnParent) { AddAction(UpgradeActionType.PreCondition, new RemoveNodeAction { Path = (source ?? target).Path }); } } break; case UpgradeStage.Cleanup: if (!Context.IsRemoved || difference.IsDependentOnParent) { AddAction(UpgradeActionType.PreCondition, new RemoveNodeAction { Path = (source ?? target).Path }); } break; case UpgradeStage.TemporaryRename: RegisterTemporaryRename(source); var temporaryName = GetTemporaryName(source); AddAction(UpgradeActionType.Rename, new MoveNodeAction { Path = source.Path, Parent = source.Parent == null ? string.Empty : source.Parent.Path, Name = temporaryName, Index = null, NewPath = GetPathWithoutName(source) + temporaryName }); break; case UpgradeStage.CopyData: Hints.GetHints <CopyDataHint>(difference.Source) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); break; case UpgradeStage.PostCopyData: if (difference.IsDataChanged) { Hints.GetHints <DeleteDataHint>(difference.Source) .Where(hint => hint.PostCopy) .Where(hint => sc.Compare(hint.SourceTablePath, difference.Source.Path) == 0) .ForEach(hint => AddAction(UpgradeActionType.Regular, new DataAction { DataHint = hint })); } break; case UpgradeStage.Upgrade: if (target == null) { break; } if (isCreated) { var action = new CreateNodeAction { Path = target.Parent == null ? string.Empty : target.Parent.Path, Type = target.GetType(), Name = target.Name, Index = target.Nesting.IsNestedToCollection ? (int?)target.Index : null }; AddAction(UpgradeActionType.PostCondition, action); } else if (isChanged) { var action = new MoveNodeAction { Path = source.Path, Parent = target.Parent == null ? string.Empty : target.Parent.Path, Name = target.Name, Index = target.Nesting.IsNestedToCollection ? (int?)source.Index : null, NewPath = target.Path }; AddAction(UpgradeActionType.PostCondition, action); } break; } }
void createNewFlag(Vector3 pos) { if (flagPrefab == null) { return; } if (snapToGrid) { pos.x = pos.x / gridCellSize; pos.x = (float)(gridCellSize * (int)pos.x); pos.z = pos.z / gridCellSize; pos.z = (float)(gridCellSize * (int)pos.z); } Flag flag = createNewFlagGameObject(); flag.gameObject.transform.localPosition = pos; if (flag != null) { float dist; int startPointIndex = findClosestLineSegment(pos, out dist); if (startPointIndex != GlobalConst.INVALID_ID) { if (dist > 4f) //MAGIC NUMBER TODO { startPointIndex = -1; } } if (startPointIndex == GlobalConst.INVALID_ID) {//New flag should be added at end or beggining bool addAtEnd = true; if (flags.Count > 1) { Vector3 startPoint = flags [0].transform.position; Vector3 endPoint = flags [flags.Count - 1].transform.localPosition; float startPointDist = Vector3.Distance(startPoint, pos); float endPointDist = Vector3.Distance(endPoint, pos); if (startPointDist < endPointDist) { addAtEnd = false; } } if (addAtEnd) { startPointIndex = GlobalConst.INVALID_ID; flags.Add(flag); } else { startPointIndex = 0; flags.Insert(0, flag); } } else {//New flag should be inserted somewhere in between flags.Insert(startPointIndex, flag); } flag.OnAddedByUser(); setNewCurrentFlag(flag); StageAction stageAction = new CreateNodeAction(startPointIndex, pos, flag.Width); stage.MakeAndAddAction(stageAction); refreshViews(); stage.RefreshGeometry(); } }