This workaround is also good..
Thanks very much for the suggestion Jan.
I had to bite the bullet and learn how to code some editor customizations, but it was easier than I expected.
Here's a bit more detail for anyone else who wants to try this out..
First, it would be a good idea to read the document Example.DSLCustomizations.doc which you should find in the folder 2006.09\VisualStudioIntegration\Samples\DSLTools\Example.DesignerCustomizations
This gives you the background information that you really need to know before you attempt this, and tells you how to do all kinds of interesting stuff besides.
The steps you need to do the shape embedding are:
1) For each shape mapping where you want to embed a shape inside another one: select the mapping, go to the DSL details window, select the "Has custom parent element" checkbox, but NOT the "Has custom parent shape" checkbox. Also, delete anything that you have in the "Parent element path" box, or you'll still get validation errors.
2) Select the Diagram shape from the Diagram Elements area of the designer, and in the Properties window set "Generates Double Derived" to True.
3) Save your DslDefinition and press the "Transform all Templates" button on the Solution Explorer - you should get no errors.
4) Find the Diagram.cs file under Diagram.tt in the GeneratedCode folder and open it. You should be able to find some calls to methods called GetParentForXXX (where XXX is the name of your element). These methods don't exist yet, and you have to code them manually. If you can't find these calls, try to build your solution and you should get a compile error for a missing method for each shape map that uses a custom parent element. You can double-click the errors and it will locate the calls to those missing methods.
5) Create a new code folder called Custom, and add a new .cs file. The name of the file doesn't matter, since it will contain a partial class or classes - it doesn't have to match the name of the class. The easiest thing to do is to copy and paste the partial class declaration from the partial class FixUpDiagram in Diagram.cs into your new file. Also, get the 3 "using" directives at the top of the file. Delete the metadata tags above the class declaration: You only have these once even though the class is spread across multiple files.
6) Code the GetParentForXXX methods. They should have return type ModelElement and take a single parameter of the type you are dealing with (i.e. XXX). You just have a single line in each method to return the parent that you would expect to have for that entity. e.g. If you have an entity called ModelClass which is embedded in an entity called ModelRoot, and the role name for the containing relationship is also ModelRoot, your custom GetParent method would look like:
DslModeling::ModelElement GetParentForModelClass(global::MyCompanyName.MyDSLName.ModelClass myNewClass) {
return myNewClass.ModelRoot;
}
7) Now you should be able to build and run your project with no errors.
Despite warnings of bugginess with embedded shapes I haven't yet experienced anything that would make me want to avoid using this functionality.
I'm sure there are some problems there or the DSL tools team wouldn't have made it so hard to do it!
(that could be interpreted as an invitation to elaborate on what the issues are exactly.. ;) |