Forcing order of swimlanes
I have the following situation: A neural network consists of multiple layers (modelled using swimlanes.) There are three types of layers: Input, Hidden and Output layers. I'm basically done with the modelling, but want to restrict the order of these layers in the diagram: The order should always be fixed: Input, 0..n Hidden, Output.
E.g. if the user adds more hidden layers, these should be inserted between the last hidden and the output layer. I've managed to arrange NestedChildShapes this way and have looked at the Anchoring, which are both the way I'd like the diagram to appear. However: On screen the newly added hidden layers always appear after the output layer.
Any hints what I need to do to change this ordering scheme?
Thank you for your support!
Michael
Hi Michael,
Sorry for the delayed response.
Our modeling system has a feature called Rules that are fired within or at the end of a transaction (but before it's complete), that allows you to respond to changes in the model. You need to create a rule that provides that placement that you're looking for.
A rule is a class that derives from one of the rules defined in the modeling system (in this case the AddRule), and overrides one or more of its methods (ElementAdded). It also needs a RuleOn attribute placed ont he class. The attribute allows you to say what type it works one and when the rule should fire (inline, local commit, and top level commit). You need to add an AddRule for the Hidden neural layer swimlane Shape so that when that shape is added, it will reposition the shape before drawing the diagram. Here is some code I tried that worked:
using
System;using
System.Collections.Generic;using
System.Text;using
Microsoft.VisualStudio.Modeling;using
Microsoft.VisualStudio.Modeling.Diagrams;namespace
Microsoft.Language2{
//This defines the rule that will be fired when a "Hidden" Domain class (Swimlane shape)//will be added in the store[
RuleOn(typeof(Hidden), FireTime = TimeToFire.TopLevelCommit)]public sealed class MyRuleClass : AddRule{
//Here we will change the index of the added element so that it is one//less than its current index (basically before the Outer swimlane shape).public override void ElementAdded(ElementAddedEventArgs e){
if (e == null) throw new ArgumentNullException("e");base.ElementAdded(e);ShapeElement shape = e.ModelElement as ShapeElement;int currentIndex = shape.ParentShape.NestedChildShapes.Count - 1;shape.ParentShape.NestedChildShapes.Move(currentIndex, currentIndex - 1);
}
}
//This is needed to register our AddRule. Please change the Class namepublic partial class Language2DomainModel{
protected override Type[] GetCustomDomainModelTypes(){
return new System.Type[] {typeof(MyRuleClass)};
}
}
}
Let me know if you have additional questions.
Thanks,
Bhavin B
DSL Tools - Test team
Unfortunately your Rule does not work for me. I've tried with both the September'06 and December'06 CTP releases, but both with the same results. Even though the NestedChildShapes collection is rearranged the on-screen appearance is wrong until refreshed by another event, such as adding another swimlane.
I've tried this with my solution and a new TaskFlow based project. In both cases I get the same results. Note that I already managed to rearrange the NestedChildShape collection, but it appears that the Rule you provided fires *after* the layout has been calculated and does not cause another layout run. Could you provide me with your test project to verify this behavior?
Michael
Michael,
Try using shape.Diagram.Invalidate() or Invalidate(true) in your code after rearranging the shapes and see if it helps. This will cause the diagram to refresh.
The rule is fired after the TopLevel Transaction based on the FireOn attribute defined. This is necessary so that the NestedChildShapes does not get refreshed after the custom rule modifies it. The diagram layout should be however after the Add transaction is completed.
If none of the above helps, it could be a bug in the DSL Toolkit which I will follow up with but unfortunately you will not be able to see a fix in that case for at least some more time.
Hope this helps.
Bhavin B.