Visual Studio DSL entry 7-DSL graphical representation 2

Source: Internet
Author: User

The previous section describes the graphical symbols of vs.net DSL, including charts, editors, and shapes. in this section, we will look at the relationship between a single symbol and metadata. How are they mapped together.
Model Elements are represented by shapes, while domain relationships are represented by connectors. graphical ing defines that model elements are visually represented by shapes, while connector ing defines how links are visually represented by connectors.
Shape ing
Let's first take a look at the shape ing, and then open the DSL file in our languagesm project. Select the line between the domain class exampleelement and the graphic exampleshape. You can see the DSL details below:

This window has two tabs. The General tab mainly defines the connection between the domain class and the graph. You can select the shape and domain class to set the ing between them. Parent element path (parent element path) it specifies the logical parent element of the referenced domain class and the chart element of the current shape.
Why do we need to specify the parent element path? Because when the designer is running, all chart elements (except the chart itself) must have parent chart elements (which can be charts or shapes ), in this way, we can know where we put this chart, so we need to specify the chart element after the shape is created as its father.
The parent element PATH uses simple path syntax to represent the entire element and link structure. In our example, it indicates that exampleelement is followed by examplemodelhaselements. examplemodel /! The chart element corresponding to the element pair obtained in the middle path of examplemodel is the chart where the parent element of the shape is located. In this example, that is, the examplemodel element of the chart itself, because our exampleshape is directly placed on the image.
The other two configurable items have a custom parent shape (has custome parent shape) and a custom parent element (has custom parent element, the generated code adds a custom code segment. You must implement the corresponding method to compile the Code. In the specified method, you can return the parent element and parent shape.

Hide row number copy code?
  1. if(element is global::Company.LanguageSm.ExampleElement)
  2.             {
  3.                 // Method:
  4.                 // private DslDiagrams::NodeShape CreateShapeForExampleElement(ExampleElement newElement)
  5.                 // {
  6.                 // }
  7.                 // must be implemented in a partial class of LanguageSmDiagram.  Given an instance of ExampleElement,
  8.                 // the method should return a new shape or connector instance that should be associated with this element.  If no shape or connector should be created, the method should return null.
  9.                 DslDiagrams::NodeShape newShape = CreateShapeForExampleElement((global::Company.LanguageSm.ExampleElement)element);
  10.                 if(newShape != null) newShape.Size = newShape.DefaultSize; // set default shape size
  11.                 return newShape;
  12.             }

You must implement the getshapforexampleelement method in the partial class of languagesmdi#to compile and pass.
Decorator ing
Let's take a look at the decorator tab, which mainly involves ing attributes and decorator. In some cases, the appearance of the decorator may need to be dynamically changed as the model information changes, the modifier ing is mainly used to define this line.

The above shows the name modifier ing of exampleshape in DSL. The display property is mainly for text decorator ), this is used to set the domain attributes of the domain class corresponding to the text to be displayed. the visibility filter is mainly used to set whether the decorator determines whether to display the domain attributes based on the domain attributes of the domain class. The filter property is used to set the Attribute Based on, in the visibility entries on the right, if the value is set to a small value, the modifier will display the information. If the logic is more complex, we can add computing attributes. In addition, you can also set the visibility settings for the icon decorator. For example, you can set a small icon in the upper right corner when an object is an inherited object.
The above is a ing definition for all shapes, but for some shapes, there will be some special points. Let's give a rough introduction:
1. Compartment shape.
In addition to shape ing, you also need to map the compartment:

This is the clasing of classshape in the project we created based on the class diagrams template. Here we can see the butescompartment and operationscompartment mappings, on the left is the set of elements used to create compartment items. Here we also find the attribute from the class through the attribute path. Of course, we can also set the set of custom elements here, just like above, you need to customize the corresponding implementation method. The right side is the actual information to be displayed for each element. Here, the attribute name to be displayed for the attribute element is set.
2. Port
Note that the elements identified by the parent element path must be mapped to an acceptable port graph, including the geometric shape. compartment shape. another port shape (or set the custom parent element to true). Otherwise, an error is returned.
3. Swimming Channels
When an element is mapped to a shape that should be contained in a swimming track, the parent path must identify the element mapped to the swimming track. When ing a swimming track, the corresponding elements of the chart must be identified in the parent path. Otherwise, an error is reported, and the swimming track cannot be taken as the father in a geometric shape.

Connector ing
Shape ing maps the shape to the domain class, while connector ing maps the connector to a domain relationship, and there is no need to set the parent element path here. The connector connects the source element of the corresponding link to the shape of the target element. Similarly, you can set a custom source (has custom source) here ), has a custom target (has custom target ). similarly, you can set the modifier ing for the connector ing, because the domain relationship also has attributes.

Now, we have introduced some basic knowledge about vs.net DSL Based on the created default languagesm project. These knowledge must be mastered before using vs.net DSL, next, we will start to create our own DSL. The requirements of this project have been described in section 2.

Reference resources
1. Development Guide for specific fields of visual stuido DSL tools
2. dsl tools lab http://code.msdn.microsoft.com/DSLToolsLab series tutorial

Author: lone knight (like a year of water)
Source: http://lonely7345.cnblogs.com/
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.