How to: Edit a UML Model and Diagrams
Updated: March 2011
You can create and edit a UML model through the views provided by several different types of diagram. By providing different perspectives on your system, these diagrams help you understand and discuss different aspects of its design and requirements. Visual Studio Ultimate provides templates for five of the most frequently used types of UML diagram.
This topic describes techniques for editing the model that are common among the different diagram types.
For more information that is specific to particular types of diagrams, see Developing Models for Software Design.
You can create and use UML diagrams only in modeling projects. For more information about how to create diagrams and projects, see How to: Create UML Modeling Projects and Diagrams.
A modeling project contains a single UML model. Every UML diagram in the project is a view of the UML model.
You can see the model in UML Model Explorer. On the Architecture menu, point to Windows, and then click UML Model Explorer.
Each shape on a diagram is a view of an element in the model. When you place a new shape on a diagram, you are creating a new element in the model.
When you save any diagram, Visual Studio Ultimate saves the whole model, all its diagrams, and the modeling project file.
To create a UML modeling diagram
On the Architecture menu, click New Diagram. The Architecture menu is available only in Visual Studio Ultimate.
The Add New Diagram dialog box appears.
Click the type of diagram you want and enter the diagram name.
In the Add to modeling project box, you can either select an existing modeling project, or select Create a new modeling project.
A modeling diagram can exist only as part of a modeling project.
You can also add a diagram to an existing modeling project in Solution Explorer. Right-click the modeling project, point to Add, and then click New Item.
To create an empty UML modeling project
On the File menu, point to New, click Project, and in the New Project dialog box, double-click Modeling Projects.
For more information about how to manage modeling projects, see How to: Create UML Modeling Projects and Diagrams.
A modeling diagram displays a collection of model elements linked by relationships. Each element is displayed as a shape and each relationship is displayed as a connector between two shapes.
There are two kinds of tools, one for elements and one for relationships. For example, in the UML class diagram Toolbox, Class is an element tool, and Association is a relationship tool.
If you want information that is specific to particular diagram types, see Developing Models for Software Design.
To create elements and relationships in a UML modeling diagram
To create a model element, click an element tool in the Toolbox, and then click the diagram where you want it to appear. After you have created the element, adjust its size and shape by dragging its handles.
In some cases, you can place a new element inside another element. For example, on a UML class diagram, you can place a class inside a Package.
If you cannot see the toolbox, click Toolbox on the View menu.
To create a relationship, click a relationship tool, click the element where you want the relationship to start, and then click the element where you want it to end.
Different types of relationships can start or end on different types of elements. For example, on a UML class diagram, an Association relationship cannot start or end on a Comment element.
To use the same tool several times, double-click the tool. When you have finished, click the Pointer tool.
On some kinds of diagrams, you can also draw simple shapes. These shapes are not part of the model, but you can use them to draw attention to parts of the diagram or to divide it into different areas.
Importing UML Elements from Other Modeling Tools
You can export elements from other modeling tools as XML Metadata Interchange (XMI) 2.1 files. To import UML class, sequence, and use case elements from .xmi files, download and install Visualization and Modeling Feature Pack. To add imported elements to the corresponding diagrams, drag the imported elements from UML Model Explorer.
For more information, see:
When you resize or color a shape, or reroute a connector, there is no effect on the underlying model. However, when you rename a shape on the diagram or in the UML Model Explorer, the corresponding element is renamed in UML Model Explorer and in any other diagrams that present that element.
There is a simple way to make new toolbox items from which you can create groups of elements, or elements with your own choice of properties. For more information, see How to: Define a Custom Modeling Toolbox Item.
The following figure shows how to change the size of a shape or its name.
The built-in commands do not include a command for neatly aligning shapes. However, you can easily create your own alignment command by copying the code in the example in How to: Display a Model on Diagrams.
The following figure shows how to adjust the route and position of a connector or its labels.
To move one end of a connector to another shape
Do one of the following:
Press CTRL and move the end.
- or -
Right-click the connector and then click Reconnect.
Click the end of the connector you want to move.
Click the shape that you want the connector to move to.
To change color or other properties of an element, relationship, or diagram
Click the element and set the fields in the Properties window.
If you cannot see the Properties window, right-click the element, and then click Properties.
To zoom in and out on a modeling diagram
Press and hold the CTRL key while you rotate the mouse wheel.
- or -
Press and hold CTRL+SHIFT, and then click the left or right mouse button.
- or -
On the Architecture Designers toolbar, click the plus sign (+) or minus sign (-), or choose a zoom level.
The Quick Find function will find items on a diagram. You must set Look in: to Current Document.
To search for text in a modeling diagram
- or -
On the Edit menu, point to Find and Replace, and then click Quick Find.
In the Find and Replace dialog box, you must leave the Look in field set to Current Document. The other options are not supported.
Type the text that you want to find, and then click Find Next.
If the text you want to find is inside a collapsed shape, the shape will be highlighted. Expand the shape, and then click Find Next again.
You can undo and redo changes that you have made to the model and diagrams by using the Undo and Redo commands on the Edit menu.
Each modeling project has a single stack of changes. All changes that you make to the model and the diagrams are kept on this stack. The stack also includes changes of focus from one diagram to another. The Undo command reverses the changes on this stack.
For example, let's say that you perform these operations: Make a change to Diagram1; change focus to Diagram 2; change Diagram2. When you undo changes, the first undo will reverse the last change; the next undo will shift focus back to Diagram 1; and the third undo will reverse the change to Diagram 1.
Closing a diagram truncates the stack of changes. If you close a diagram, you cannot undo the changes that you performed in that diagram, and you cannot undo earlier changes to the model or any of its diagrams.
You cannot undo while you are editing a property. While you are editing a property in the Properties window, or in a label on a diagram, you can only undo changes that you have made in that property. Complete your change in the property by pressing ENTER, or cancel it by pressing ESC. You will then be able to undo changes in the model and diagrams.
Closing a diagram without saving might not have the effect you expect. If you make some changes, and then close a diagram without saving it, your changes will still be preserved in the model. It is recommended to close the whole model if you want to do so without saving it.
You can make a specific instance of a model element appear more than once in your diagrams. This applies to classes, interfaces, components, use cases, and actors.
This is useful if you want to show different groups of relationships in different diagrams. For example, on one diagram, you could show the associations between the Customer and Address classes. On another diagram, you could show the Address class again, with its association to Postal Area.
You can change the properties of a model element, such as its name, by selecting any of its views on any diagram, or by selecting it in UML Model Explorer.
Each kind of diagram can only show some kinds of model element. For example, you cannot show a use case on a component diagram. Therefore, the following procedures will work only for some combinations of model element and diagram.
To add a new view of a model element by using UML Model Explorer
To open UML Model Explorer, on the Architecture menu, point to Windows, and then click UML Model Explorer.
Drag the model element from UML Model Explorer to a compatible diagram in the same project.
A shape providing a view of the model element appears, which may be in addition to the views on other diagrams or on the same diagram.
The effect is different when you drag a class or component onto a sequence diagram. In that case, a new lifeline is created whose type is that class or component. For more information, see UML Sequence Diagrams: Guidelines.
To add a new view of a model element by using Paste Reference
Right-click an existing element, and then click Copy.
You can copy several elements at the same time. Hold down the CTRL key while you click each element, right-click one of them, and then click Copy.
Right-click an empty part of a compatible diagram, and then click Paste Reference.
Another view of the same element appears.
This differs from the Paste command, which creates a new element in the model. For more information, see Copying Elements and Groups of Related Elements.
If you add to a diagram views of two model elements that are already connected by a relationship, a view of the relationship will also appear on the diagram. You can delete this view only by removing one of the elements from the diagram, or by deleting the relationship from the model.
You can copy and paste model elements, and you can copy and paste groups of elements together with the relationships between them.
The Paste and Paste Reference commands have different effects. Paste creates new elements whose properties are like those of the copied elements. Paste Reference creates new views of the same elements.
To copy elements and their relationships
In the diagram with the elements that you want to copy, select one or more elements.
You cannot copy relationships except as part of a group of elements.
On the Edit menu, click Copy.
If you want to copy the elements to another diagram, create the new diagram or open the existing diagram.
On the Edit menu, click Paste.
Copies of the elements appear, together with copies of any relationships that link between them.
Each new element will have a new automatically generated name.
Adjust the positions, names, and other properties of the new elements and relationships.
You cannot copy a model element from one model to another, for example if you have two models in the same solution. But you can copy elements from one diagram to another.
To replicate a diagram
Create a new diagram.
Select all the elements in an existing diagram, copy them, and paste them into the new one.
You cannot replicate a diagram by copying and pasting in Solution Explorer.
Some kinds of elements, specifically classifiers, can be removed from a diagram without deleting them from the model. Classifiers are the major elements that are displayed on class diagrams, component diagrams, and use case diagrams. They can appear on more than one diagram. For these types of elements, there are two separate commands: Remove from Diagram and Delete from Model.
By contrast, when you delete a relationship from a diagram, you are always deleting it from the model.
Certain kinds of elements on a UML diagram have labels. When you select such elements by drawing a rectangle around them, it is possible to select the labels but not the elements that own those labels. Deleting a subset of elements that are selected in this way is not supported. To select a subset of these elements, press and hold the CTRL key while you click each element.
To remove a classifier's view from a diagram
Right-click the element on the diagram, and then click Remove from Diagram.
- or -
Click the element on the diagram and then press the DELETE key.
This view of the element vanishes. However, the element remains in the model, and you can still find it in UML Model Explorer. Any other views of the same element also remain.
Every connector that terminates at this shape is removed from the diagram, but the relationship it represents remains in the model. You can see the relationship in UML Model Explorer under Relationships, under each element that it connects.
To delete an element from the model
Right-click the element either in UML Model Explorer or on a diagram, and then click Delete from Model.
The element is deleted from every diagram on which it appears.
Every relationship that terminates at this element is also deleted from the model.
To delete a relationship from the model
Right-click the relationship on a diagram or in UML Model Explorer, and then click Delete from Model.
You cannot remove a relationship from a diagram without removing it from the model.
The relationship is deleted from the model and is deleted from every diagram on which it appears.
The following features help you to draw attention to particular parts of your diagram, add explanations, or divide a diagram into different areas of interest.
You can copy any part of a diagram into a Word, PowerPoint, or other document. Select the shapes and connectors you want, right-click and then click Copy.
The color of any shape or connector can be changed. Select one or more shapes and change the Color property. If you cannot see the Properties window, press F4.
On diagrams of some kinds, you can draw lines, rectangles and ellipses from the Simple Shapes section of the Toolbox. These shapes do not form part of the UML model.
To label an area, you can drag a Comment from the Toolbox and then set its Transparent property to True. Like Simple Shapes, comments do not form part of the UML model and do not appear in UML Model Explorer.
To add notes and explanations to model elements, you can create comments and then link them to the elements.
To neatly align a column or row shapes on the diagram, you can install the Align Shapes command. This is available as a sample UML extension: UML: Command to Align Shapes
To Export a Diagram as an Image
For more information, see How to: Export Images of Diagrams.
You can add new functionality to the UML tools and adapt the diagram notation to your own needs. For more information, see Extending UML Models and Diagrams.
There are several sample extensions available. You can either just install and use them, or you can use their source code as the basis for your own extensions. The samples include:
Menu command that helps you tidy a diagram.
Link any UML element to Word headings, PowerPoint slides, files of any type, UML diagrams, or other UML elements. The link can be made simply by dragging. Later, you can double-click the element to see the linked item. For example, you could link use cases to Word specifications or detailed activity diagrams, and actions to storyboard slides.
Create a model quickly by using text entry. Useful for capturing ideas in meetings.
Colors classes according to stereotype. You can easily extend the code to work for your own stereotypes.
Convenient defaults for business models. Associations are shown without arrows by default, and operations do not appear in classes.