From 1a6d3d462181fa0ab540fa0cf48387694680708c Mon Sep 17 00:00:00 2001 From: "seongwon.shim" Date: Wed, 28 May 2014 20:11:54 +0900 Subject: [PATCH] ANIMATOR : Bug fix for merge/split keyframe Condition added for predefined and previous/next Keyframe unit getter metod Change-Id: Iaef27bbbe8e04e5b8b5e02770c979625678c4cc4 Signed-off-by: seongwon.shim --- .../animator/model/AnimatorKeyframe.java | 186 +++++++++++------- .../animator/model/AnimatorSelector.java | 218 ++++++++++++--------- .../gef/editparts/HoverViewerEditPart.java | 5 +- 3 files changed, 240 insertions(+), 169 deletions(-) diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorKeyframe.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorKeyframe.java index 71b3141..2e8f217 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorKeyframe.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorKeyframe.java @@ -199,22 +199,6 @@ public class AnimatorKeyframe extends AnimatorModel { return AnimatorUtils.subtractDouble(currentTime, delay); } - /** - * Get Last frame from list - * - * @return Return last frame - */ -// public AnimatorFrame getLastFrame() { -// AnimatorFrame result = null; -// for (AnimatorModel model : getChildren()) { -// AnimatorFrame frame = (AnimatorFrame) model; -// -// if (Double.compare(frame.getFrameTime(), duration) == 0) -// result = frame; -// } -// return result; -// } - public AnimatorFrame getLastFrame() { return (AnimatorFrame)getChild(getChildrenSize() -1); } @@ -225,24 +209,16 @@ public class AnimatorKeyframe extends AnimatorModel { } return null; } - -// /** -// * Get First frame from list -// * -// * @return Return first frame -// */ -// public AnimatorFrame getFirstFrame() { -// AnimatorFrame result = null; -// for (AnimatorModel model : getChildren()) { -// AnimatorFrame frame = (AnimatorFrame) model; -// -// if (Double.compare(frame.getFrameTime(), 0.0) == 0) { -// result = frame; -// break; -// } -// } -// return result; -// } + + public AnimatorFrame getFrameById(String id) { + for(AnimatorModel model : getChildren()) { + AnimatorFrame frame = (AnimatorFrame)model; + if(frame.getId().equals(id)) { + return frame; + } + } + return null; + } /** * Update duration, delay and children's frame time assume that frame is going to be added at @@ -427,24 +403,27 @@ public class AnimatorKeyframe extends AnimatorModel { public boolean mergeKeyframe(AnimatorFrame frame, Queue removedKeyframes) { boolean result = false; AnimatorSelector selector = (AnimatorSelector) getParent(); -// AnimatorKeyframe previousParent = (AnimatorKeyframe) selector.getPrevChild(this); - AnimatorKeyframe nextParent = (AnimatorKeyframe) selector.getNextChild(this); + AnimatorKeyframe nextParent = (AnimatorKeyframe) selector.getNextAnimatorKeyframeByTime(this); AnimatorKeyframe previousParent = selector.getPreviousAnimatorKeyframeByTime(this); int keyframeChildrenSize = getChildrenSize(); if (keyframeChildrenSize == 1) {// case 1 if (getChildIndex(frame) == 0) { boolean merged = false; if (previousParent != null) { - AnimatorFrame previousFrame = previousParent.getLastFrame(); - if (!previousFrame.hasSamePropertyValue(frame)) { - previousParent.mergeFrame(frame, true); - merged = true; - result = true; - removedKeyframes.add(this); + AnimatorFrame previousFrame = previousParent.getPreviousAnimatorFrameByTime(frame); + if(previousFrame != null) { + if (previousFrame.getPropertySize() !=0 && !previousFrame.hasSamePropertyValue(frame)) { + if(previousParent.getChildIndex(previousFrame) == previousParent.getChildrenSize() -1) { + previousParent.mergeFrame(frame, true); + merged = true; + result = true; + removedKeyframes.add(this); + } + } } } if (nextParent != null) { - AnimatorFrame nextFrame = nextParent.getFirstFrame(); + AnimatorFrame nextFrame = nextParent.getNextAnimatorFrameByTime(frame); if (!nextFrame.hasSamePropertyValue(frame)) { if (merged) { previousParent.mergeFrame(nextFrame, true); @@ -460,22 +439,35 @@ public class AnimatorKeyframe extends AnimatorModel { if (getChildIndex(frame) == 0) { // case 2.1 (left most case) // merge left and check right if (previousParent != null) { - AnimatorFrame previousFrame = previousParent.getLastFrame(); - if (!previousFrame.hasSamePropertyValue(frame)) { - previousParent.mergeFrame(frame, true); - result = true; - removedKeyframes.add(this); + AnimatorFrame previousFrame = previousParent.getPreviousAnimatorFrameByTime(frame); + if(previousFrame != null) { + if(previousFrame.getPropertySize() !=0 && !previousFrame.hasSamePropertyValue(frame)) { + //If previousFrame is last frame in previousParent + if(previousParent.getChildIndex(previousFrame) == previousParent.getChildrenSize() -1) { + previousParent.mergeFrame(frame, true); + result = true; + removedKeyframes.add(this); + } else { + if(!previousFrame.isPredefined()) { + previousParent.mergeFrame(frame, true); + result = true; + removedKeyframes.add(this); + } + } + } } } } else if (getChildIndex(frame) == (keyframeChildrenSize - 1)) { // case 2.2 (right most case) // merge next frame if (nextParent != null) { - AnimatorFrame nextFrame = nextParent.getFirstFrame(); - if (!nextFrame.hasSamePropertyValue(frame)) { - mergeFrame(nextFrame, true); - result = true; - removedKeyframes.add(nextParent); - } + AnimatorFrame nextFrame = nextParent.getNextAnimatorFrameByTime(frame); + if(nextFrame != null) { + if (!frame.isPredefined() && !nextFrame.isPredefined() && !nextFrame.hasSamePropertyValue(frame)) { + mergeFrame(nextFrame, true); + result = true; + removedKeyframes.add(nextParent); + } + } } } else {// case 2.3 (inside case) // check left and right(rare case) @@ -488,7 +480,73 @@ public class AnimatorKeyframe extends AnimatorModel { return result; } - /** + private AnimatorFrame getPreviousAnimatorFrameByTime(AnimatorFrame currentFrame) { + AnimatorKeyframe currentKeyframe = (AnimatorKeyframe)currentFrame.getParent(); + double baseTime = currentKeyframe.getDelay() + currentFrame.getFrameTime(); + + AnimatorFrame result = null; + if(Double.compare(getDelay() + getDuration(), baseTime) <= 0) { + result = getLastFrame(); + } else { + AnimatorFrame previousFrame = null; + for(AnimatorModel model :getChildren()) { + AnimatorFrame frame = (AnimatorFrame)model; + double currentFrameTime = getDelay() + frame.getFrameTime(); + //less than currentTime + if(Double.compare(currentFrameTime, baseTime) < 0) { + if(previousFrame == null) { + previousFrame = frame; + continue; + } else { + double previousFrameTime = getDelay() + previousFrame.getFrameTime(); + if(Double.compare(baseTime - previousFrameTime, baseTime - currentFrameTime) > 0) { + previousFrame = frame; + } + } + } + } + + result = previousFrame; + } + + return result; + } + + + private AnimatorFrame getNextAnimatorFrameByTime(AnimatorFrame currentFrame) { + AnimatorKeyframe currentKeyframe = (AnimatorKeyframe)currentFrame.getParent(); + double baseTime = currentKeyframe.getDelay() + currentFrame.getFrameTime(); + + AnimatorFrame result = null; + if(Double.compare(getDelay(), baseTime) >= 0) { + result = getFirstFrame(); + } else { + AnimatorFrame nextFrame = null; + for(AnimatorModel model :getChildren()) { + AnimatorFrame frame = (AnimatorFrame)model; + double currentFrameTime = getDelay() + frame.getFrameTime(); + //bigger than currentTime + if(Double.compare(currentFrameTime, baseTime) > 0) { + if(nextFrame == null) { + nextFrame = frame; + continue; + } else { + double nextFrameTime = getDelay() + nextFrame.getFrameTime(); + if(Double.compare(nextFrameTime - baseTime, currentFrameTime - baseTime) > 0) { + nextFrame = frame; + } + } + } + } + + result = nextFrame; + } + + return result; + } + + + /** * recursively merge frame and remainders * * @param frame @@ -531,10 +589,9 @@ public class AnimatorKeyframe extends AnimatorModel { AnimatorSelector selector = (AnimatorSelector) getParent(); AnimatorFrame previousFrame = (AnimatorFrame) getPrevChild(frame); AnimatorFrame nextFrame = (AnimatorFrame) getNextChild(frame); + if (previousFrame != null) { if (previousFrame.hasSamePropertyValue(frame)) { -// AnimatorKeyframe currentKeyframe = -// selector.createKeyframe(modelFactory, "custom", frame.getFrameTime()); AnimatorKeyframe currentKeyframe = null; if(!removedKeyframes.isEmpty()) { currentKeyframe = removedKeyframes.poll(); @@ -549,8 +606,6 @@ public class AnimatorKeyframe extends AnimatorModel { if (nextFrame != null) { if (nextFrame.hasSamePropertyValue(frame)) { -// AnimatorKeyframe nextKeyframe = -// selector.createKeyframe(modelFactory, "custom", frame.getFrameTime()); AnimatorKeyframe nextKeyframe = null; if(!removedKeyframes.isEmpty()) { nextKeyframe = removedKeyframes.poll(); @@ -566,8 +621,7 @@ public class AnimatorKeyframe extends AnimatorModel { selector.addChild(nextKeyframe); } } - - + } /** @@ -649,14 +703,4 @@ public class AnimatorKeyframe extends AnimatorModel { return ((AnimatorSelector)getParent()).getPropertyInPreviousFrames(key, this); } - - public AnimatorFrame getFrameById(String id) { - for(AnimatorModel model : getChildren()) { - AnimatorFrame frame = (AnimatorFrame)model; - if(frame.getId().equals(id)) { - return frame; - } - } - return null; - } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorSelector.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorSelector.java index 3569b05..1902689 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorSelector.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorSelector.java @@ -283,6 +283,16 @@ public class AnimatorSelector extends AnimatorModel { return false; } + + public AnimatorKeyframe getAnimatorKeyframeById(String id) { + for(AnimatorModel model : getChildren()) { + AnimatorKeyframe currentKeyframeById = (AnimatorKeyframe)model; + if(currentKeyframeById.getId().equals(id)) { + return currentKeyframeById; + } + } + return null; + } /** * Update selector time for add keyframe @@ -491,12 +501,25 @@ public class AnimatorSelector extends AnimatorModel { * @return */ public AnimatorKeyframe getCurrentKeyframe(double currentTime) { + AnimatorKeyframe result = null; for (AnimatorModel model : getChildren()) { AnimatorKeyframe keyframe = (AnimatorKeyframe) model; - if (keyframe.isInclude(currentTime)) - return keyframe; + if (keyframe.isInclude(currentTime)) { + if(result != null) { + if(result.getName().equals("custom")) { + continue; + } else { + if(keyframe.getName().equals("custom")) { + result = keyframe; + } + } + } else { + result = keyframe; + } + } } - return null; + + return result; } @@ -511,20 +534,45 @@ public class AnimatorSelector extends AnimatorModel { return keyframes; } + public List getNextKeyframesByCurrentTime(double currentTime) { + List keyframes = new ArrayList(); + for (AnimatorModel model : getChildren()) { + AnimatorKeyframe keyframe = (AnimatorKeyframe) model; + if (Double.compare(keyframe.getDelay(), currentTime) > 0) { + keyframes.add(keyframe); + } + } + return keyframes; + } + /** * Get AnimatorFrame by current time * * @param currentTime * @return */ - public AnimatorFrame getAnimatorFrameByCurrentTime(double currentTime) { - AnimatorKeyframe customKeyframe = getCurrentKeyframe(currentTime); - if (customKeyframe != null) { - if (customKeyframe.isInclude(currentTime)) - return customKeyframe.getFrameByCurrentTime(currentTime); - } - - return null; + public AnimatorFrame getAnimatorFrameByCurrentTime(double currentTime) { + + AnimatorFrame result = null; + for(AnimatorModel model : getChildren()) { + AnimatorKeyframe keyframe = (AnimatorKeyframe)model; + AnimatorFrame frame = keyframe.getFrameByCurrentTime(currentTime); + if(frame != null) { + if(result != null) { + if(!result.isPredefined()) { + continue; + } else { + if(!frame.isPredefined()) { + result = frame; + } + } + } else { + result = frame; + } + } + } + + return result; } public AnimatorFrame getAnimatorFrameById(String id) { @@ -538,41 +586,6 @@ public class AnimatorSelector extends AnimatorModel { return null; } - -// /** -// * Merge Frame if two frame at same time If next frame has property that has previous frame, -// * next frame's property will be ignored -// * -// * @param keyframe -// * @return -// */ -// public boolean mergeKeyframe(AnimatorKeyframe keyframe) { -// boolean result = false; -// AnimatorKeyframe previousKeyframe = (AnimatorKeyframe) getPrevChild(keyframe); -// AnimatorKeyframe nextKeyframe = (AnimatorKeyframe) getNextChild(keyframe); -// -// if (previousKeyframe != null) { -// AnimatorFrame previousFrame = previousKeyframe.getLastFrame(); -// if (previousFrame != null) { -// if (!previousFrame.hasSamePropertyValue(keyframe.getFirstFrame())) { -// previousKeyframe.mergeFrame(keyframe.getFirstFrame(), true); -// keyframe = previousKeyframe; -// result = true; -// } -// } -// } -// -// if (nextKeyframe != null) { -// AnimatorFrame nextFrame = nextKeyframe.getFirstFrame(); -// if (nextFrame != null) { -// if (!keyframe.getLastFrame().hasSamePropertyValue(nextFrame)) { -// keyframe.mergeFrame(nextFrame, true); -// } -// } -// } -// -// return result; -// } /** * Check with two keyframes that has same properties @@ -609,32 +622,35 @@ public class AnimatorSelector extends AnimatorModel { } } else { //previousFrame is one of middle frame in expectedPreviousKeyframe - //if previousFrame and current frame are one of predefined animation - //merge or split is not happened - if(!currentFrame.isPredefined() && !previousFrame.isPredefined()) { - if(previousFrame.hasSamePropertyValue(currentFrame)) { - if(expectedPreviousKeyframe.equals(currentKeyframe)) { - AnimatorKeyframe nextKeyframe = (AnimatorKeyframe)getNextChild(currentKeyframe); - if(nextKeyframe == null) { - nextKeyframe = - createKeyframe(modelFactory, "custom", currentKeyframe.getDelay() + currentFrame.getFrameTime()); - addChild(nextKeyframe); - } - currentKeyframe.removeChild(currentFrame, true); - nextKeyframe.addChild(currentFrame, true); - result = true; - } - } else { - if(!previousFrame.getParent().equals(currentFrame.getParent())) { - currentKeyframe.removeChild(currentFrame, true); - expectedPreviousKeyframe.addChild(currentFrame, true); - expectedPreviousKeyframe.addName(currentKeyframe.getName()); - if(currentKeyframe.getChildrenSize() == 0) { - removedKeyframes.add(currentKeyframe); - } - result = true; - } - } + if(currentFrame.getPropertySize() != 0 && previousFrame.getPropertySize() != 0) { + //If currentFrame or previousFrame has no properties just skip + if(!currentFrame.isPredefined() && !previousFrame.isPredefined()) { + //if previousFrame and current frame are one of predefined animation + //merge or split is not happened + if(previousFrame.hasSamePropertyValue(currentFrame)) { + if(expectedPreviousKeyframe.equals(currentKeyframe)) { + AnimatorKeyframe nextKeyframe = (AnimatorKeyframe)getNextChild(currentKeyframe); + if(nextKeyframe == null) { + nextKeyframe = + createKeyframe(modelFactory, "custom", currentKeyframe.getDelay() + currentFrame.getFrameTime()); + addChild(nextKeyframe); + } + currentKeyframe.removeChild(currentFrame, true); + nextKeyframe.addChild(currentFrame, true); + result = true; + } + } else { + if(!previousFrame.getParent().equals(currentFrame.getParent())) { + currentKeyframe.removeChild(currentFrame, true); + expectedPreviousKeyframe.addChild(currentFrame, true); + expectedPreviousKeyframe.addName(currentKeyframe.getName()); + if(currentKeyframe.getChildrenSize() == 0) { + removedKeyframes.add(currentKeyframe); + } + result = true; + } + } + } } } } @@ -708,6 +724,39 @@ public class AnimatorSelector extends AnimatorModel { } return result; } + + public AnimatorKeyframe getNextAnimatorKeyframeByTime(AnimatorModel model) { + //Return Next AnimatorKeyframe that located after passed AnimatorKeyframe + Double baseTime = 0.0; + if(model instanceof AnimatorKeyframe) { + baseTime = ((AnimatorKeyframe)model).getDelay(); + } else { + baseTime = ((AnimatorKeyframe)model.getParent()).getDelay(); + } + + AnimatorKeyframe result = null; + for(AnimatorKeyframe keyframe : getNextKeyframesByCurrentTime(baseTime)) { + if(Double.compare(keyframe.getDelay() + keyframe.getDuration(), + ((AnimatorKeyframe)model).getDelay() + ((AnimatorKeyframe)model).getDuration()) > 0) { + if(result != null) { + if(Double.compare(result.getDelay() + result.getDuration(), keyframe.getDelay() + keyframe.getDuration()) > 0) { + result = keyframe; + } else if (Double.compare(result.getDelay() + result.getDuration(), keyframe.getDelay() + keyframe.getDuration()) == 0){ + if(result.getName().contains("custom")) { + continue; + } else { + if(keyframe.getName().contains("custom")) { + result = keyframe; + } + } + } + } else { + result = keyframe; + } + } + } + return result; + } public AnimatorFrame getPreviousAnimatorFrameByTime(AnimatorFrame currentFrame) { @@ -879,18 +928,6 @@ public class AnimatorSelector extends AnimatorModel { return result; } - public AnimatorFrame createAnimatorFrame(AnimatorModelFactory modelFactory, double currentTime) { - AnimatorKeyframe keyframe = getCurrentKeyframe(currentTime); - if (keyframe == null) { - keyframe = createKeyframe(modelFactory, "custom", currentTime); - addChild(keyframe); - } - - AnimatorFrame frame = keyframe.createAnimatorFrame(modelFactory, currentTime); - keyframe.addChild(frame, true); - - return frame; - } /** * if there exists a Frame, return null. if not, create and return it. @@ -1031,7 +1068,7 @@ public class AnimatorSelector extends AnimatorModel { currentKeyframe.removeChild(currentFrame, true); currentFrame.setFrameTime(currentTime); - currentKeyframeById.addChild(currentFrame, false); + currentKeyframeById.addChild(currentFrame, true); addChild(currentKeyframeById); // modelManager.fireEvent(true, this, AnimatorModelEvent.EventType.KEYFRAME_ADD, // AnimatorModelEvent.Origin.TIMELINE, currentKeyframeById); @@ -1041,15 +1078,4 @@ public class AnimatorSelector extends AnimatorModel { } } } - - - public AnimatorKeyframe getAnimatorKeyframeById(String id) { - for(AnimatorModel model : getChildren()) { - AnimatorKeyframe currentKeyframeById = (AnimatorKeyframe)model; - if(currentKeyframeById.getId().equals(id)) { - return currentKeyframeById; - } - } - return null; - } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java index 8443c9f..e54e4c8 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/editparts/HoverViewerEditPart.java @@ -207,8 +207,9 @@ public class HoverViewerEditPart extends AbstractGraphicalEditPart implements IP ((HoverBrowserViewer) getViewer()).updateModel(); ((HoverBrowserViewer) getViewer()).updateAllPositionsForce(); - ((AnimatorWidgetPart) e.getPart()).widgetPropertyEdit(); - + if(e.getPart() instanceof AnimatorWidgetPart) { + ((AnimatorWidgetPart) e.getPart()).widgetPropertyEdit(); + } } @Override -- 2.7.4