I was trying to implement Rotation of a node and I am doing something like node.RotationAngle +=90
and seems to be working properly but, there are some issues I am facing related to it
For testing I just enabled Rotatable = True in the xaml for one of our nodes and using the rotating handle I tried to rotate. the aggregate rotates but the adornments are haphazard like below
When I do undo I am facing the same issue
Also while deserializing I face the same issue but along with that I see that all the nodes come 180 rotated even though the value of node.RotationAngle is 90. For serializing we also have a additional property in NodeData which is binded to xaml template
I have tried doing
node.UpdateLayout();
node.UpdateAdornments();
but nothing worked. Also I am not binding Rotating tool as we do not need the rotating handle. From our UI there will be a button in the menu which will be used to rotate the aggregate by 90 degs.
Am I missing something here for the implementation?
Interactive rotation does work, as you can see in samples such as DraggableLink. Maybe the node template doesn’t have the LocationSpot == Spot.Center to match the (default) RotationSpot.
But you don’t want users to use the RotatingTool, do you?
and that seems to work well, except for the Adornments. It seems the default adornment templates don’t detect changes to the angle, and I’m not sure why it works correctly with the RotatingTool.
A work-around for undo/redo problems:
myDiagram.Model.Changed += (object sndr, ModelChangedEventArgs e) => {
if (e.Change == ModelChange.FinishedUndo || e.Change == ModelChange.FinishedRedo) {
foreach (var n in myDiagram.Nodes) {
n.InvalidateRelationships();
if (n.IsSelected) { n.IsSelected = false; n.IsSelected = true; }
}
}
};
Alas, the proper method to call is internal. Setting IsSelected to false and then back to true is just a hack that seems to work.
I tried adding the RotatingTool and following code I added as part of it ( the code is borrowed from DraggableLink example from Demo application
class CustomRotatingTool: RotatingTool
{
private const String ToolCategory = "Resize";
public override void UpdateAdornments(Part part)
{
if (part == null || part is Link) return; // this tool never applies to Links
Adornment adornment = null;
if (part.IsSelected)
{
FrameworkElement selelt = part.SelectionElement;
if (selelt != null && part.CanRotate() && Part.IsVisibleElement(selelt))
{
adornment = part.GetAdornment(ToolCategory);
if (adornment != null)
{
var nodeData = part.Data as NodeData;
Node node = Diagram.PartManager.FindNodeForData(nodeData, Diagram.Model);
adornment.Location = node.Location;
}
}
}
part.SetAdornment(ToolCategory, adornment);
}
protected override void DoRotate(double newangle)
{
base.DoRotate(newangle + 90);
}
public override void DoCancel()
{
base.DoRotate(this.OriginalAngle);
StopTool();
}
After the above change I see all my nodes are getting adornments like this irrespective of rotation done on them or not. But the adornment are relatively correct. I mean they don’t go in random way on undo redo or for any number of rotation or loading a model.
Do you have a custom ResizeAdornmentTemplate? The problem is occurring with what appears to be the resize adornment for the rotated node, not the rotate adornment.