Answered Automatic layout with nested shapes/ How to implement StackPanel functionality

  • Saturday, March 10, 2012 4:43 PM
     
     

    Hi,

    I have a DSL with nested Models. I want the parent shape to adjust the child shapes automatically like the StackPanel control in WPF/ WindowsForms. I tried to use BoundsRules but GetCompliantBounds() will be called for adding children and moving parent. I want the same behavior like the DSL Editor.

    Thanks,

    Thomas

All Replies

  • Thursday, April 12, 2012 3:55 PM
    Owner
     
     Proposed Answer

    Hi Thomas

    I assume you are referring to nesting of shapes, but in that case I don't quite understand the behaviour of the DSL Designer to which you are referring, since the DSL Designer itself does not have any nested shapes. What specific behaviour of the DSL Designer is it that you wish to emulate?

    You may find Jean-Marc's blog posting on nested shapes helpful.

    Regards

    Blair

  • Tuesday, May 29, 2012 1:28 PM
     
     

    If you create a DSL Language Project  Visual Studio 2010 has a build-in Designer for creation DSLs. After Dropping a DomainClass the Designer will organize the shapes like a stackpanel. To change to order you have to select a shape and press ctrl+arrow down/ ctrl+arrow up.

    I want this behaviour for my DSL Designer. I'm on this. I found a great post

    http://social.msdn.microsoft.com/Forums/en-US/dslvsarchx/thread/0fecd2f3-e38e-473b-b178-c2b0cbd436b4

  • Tuesday, June 05, 2012 2:54 PM
    Owner
     
     Answered

    Hi Thomas

    Sorry, the DSl Designer is a very complex DSL (50 kloc) with a lot of custom code, which uses Domain elements for the domain concepts but also for a "View Model" that takes care of this stacked layout. There is not simple way to do that with an out of the box DSL.

    Regards


    Jean-Marc

  • Tuesday, June 12, 2012 8:16 AM
     
     Answered

    I made a easy solution that works for me.

    1. Every shape has a public property "OrderIndex" that will be assigned inside the method ElementAdded() a in class AddShapeRule. Create a special StackPanelClass or implement GetNextOrderIndex() in the diagram class.
    2. In the method GetCompliantBounds() in class BoundsRules assigned to the shape I call a custom method GetShapeLocation() that returns the calculated location.
    3. If the implemented shapes nests shapes they can change the height and width. In GetCompliantBounds() in BoundsRules assigned to the diagram I sort the nested shapes of the diagram by the Property AbsoluteBoundingBox.Top in descanding order. I check if any shape is intersecting another shape with LinkedElementCollection.Intersect(). I assign all shapes that intersect a "fake"-Location to enforce the call of BoundsRules of the shape.