Issue 40: Fix group, rotate, ungroup scenario when children are not themselves rotated.
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@606 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
f70cdf5043
commit
eb44c62740
|
@ -87,7 +87,6 @@
|
|||
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
||||
<img class="tool_button" id="tool_clone_multi" src="images/clone.png" title="Clone Elements [C]" alt="Clone"/>
|
||||
<img class="tool_button" id="tool_delete_multi" src="images/delete.png" title="Delete Selected Elements [Delete/Backspace]" alt="Delete"/>
|
||||
<img class="tool_button" id="tool_group" src="images/shape_group.png" title="Group Elements [G]" alt="Group"/>
|
||||
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
||||
<img class="tool_button" id="tool_alignleft" src="images/align-left.png" title="Align Left" alt="Left"/>
|
||||
<img class="tool_button" id="tool_aligncenter" src="images/align-center.png" title="Align Center" alt="Center"/>
|
||||
|
@ -102,6 +101,8 @@
|
|||
<option value="smallest">smallest object</option>
|
||||
<option value="page">page</option>
|
||||
</select>
|
||||
<img class="tool_sep" src="images/sep.png" alt="|"/>
|
||||
<img class="tool_button" id="tool_group" src="images/shape_group.png" title="Group Elements [G]" alt="Group"/>
|
||||
</div>
|
||||
|
||||
<div id="g_panel">
|
||||
|
|
|
@ -3016,8 +3016,8 @@ function BatchCommand(text) {
|
|||
canvas.addToSelection([g]);
|
||||
};
|
||||
|
||||
// TODO: if the group has a rotational transform on it, transfer that transform
|
||||
// to each child element and add the change commands to the batch command
|
||||
// TODO: when transferring group's rotational transform to the children, must deal
|
||||
// with children who are already rotated within the group
|
||||
this.ungroupSelectedElement = function() {
|
||||
var g = selectedElements[0];
|
||||
if (g.tagName == "g") {
|
||||
|
@ -3027,6 +3027,9 @@ function BatchCommand(text) {
|
|||
var children = new Array(g.childNodes.length);
|
||||
var xform = g.getAttribute("transform");
|
||||
var i = 0;
|
||||
var gbox = g.getBBox(),
|
||||
gx = gbox.x + gbox.width/2,
|
||||
gy = gbox.y + gbox.height/2;
|
||||
while (g.firstChild) {
|
||||
var elem = g.firstChild;
|
||||
var oldNextSibling = elem.nextSibling;
|
||||
|
@ -3034,15 +3037,29 @@ function BatchCommand(text) {
|
|||
children[i++] = elem = parent.insertBefore(elem, anchor);
|
||||
batchCmd.addSubCommand(new MoveElementCommand(elem, oldNextSibling, oldParent));
|
||||
if (xform) {
|
||||
var angle = canvas.getRotationAngle(g) * Math.PI / 180.0;
|
||||
var childBox = elem.getBBox();
|
||||
var cx = childBox.x + childBox.width/2,
|
||||
cy = childBox.y + childBox.height/2,
|
||||
dx = cx - gx,
|
||||
dy = cy - gy,
|
||||
r = Math.sqrt(dx*dx + dy*dy);
|
||||
angle += Math.atan2(dy,dx);
|
||||
var newcx = r * Math.cos(angle) + gx,
|
||||
newcy = r * Math.sin(angle) + gy;
|
||||
childBox.x += (newcx - cx);
|
||||
childBox.y += (newcy - cy);
|
||||
elem.setAttribute("transform", xform);
|
||||
batchCmd.addSubCommand(recalculateDimensions(elem, elem.getBBox()));
|
||||
batchCmd.addSubCommand(recalculateDimensions(elem, childBox));
|
||||
}
|
||||
}
|
||||
|
||||
// remove transform and make it undo-able
|
||||
if (xform) {
|
||||
var changes = {};
|
||||
changes['transform'] = xform;
|
||||
changes["transform"] = xform;
|
||||
g.setAttribute("transform", "");
|
||||
g.removeAttribute("transform");
|
||||
batchCmd.addSubCommand(new ChangeElementCommand(g, changes));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue