|
Even if coding is underway, you can use UML diagrams to better understand a project. If you develop projects in Microsoft Visual C++ 6, Microsoft Visual Basic 6 (or newer versions of either), you can reverse engineer your projects’ class definitions and generate UML static structure models in the Model Explorer. Visio includes the Microsoft Visio UML Add-In, which you can run from within Visual C++, and the Microsoft Visio UML Visual Basic Add- In, which you can run from within Visual Basic. Each add-in provides a toolbar similar to the one shown in Figure 20-15. With the toolbar buttons, you can open Visio and start a new diagram based on the UML Model Diagram template from within Visual C++ or Visual Basic as well as reverse engineer source code. After you reverse engineer a project, you can create a class diagram in Visio by dragging elements from the static structure model onto the drawing page.
Figure 20-15: The UML add-in adds a toolbar to Visual C++ and Visual Basic. In Visual Basic, the Visio UML Options button does not appear.
Note | The first time you install Visio, you must start it and exit it at least once before you can reverse engineer code. In addition, Microsoft Visual Studio Service Pack 3 must be installed to reverse engineer code. |
Microsoft extends the reverse engineering capabilities of the UML Model Diagram template with Visual Studio .NET, which can reverse engineer code from Visual Basic 7, Visual C++ 7, and C#. In addition, Visual Studio .NET Enterprise Edition can generate code skeletons for Visual C++ 6 and later and Visual Basic 7.
When you reverse engineer a Visual C++ project, you must first customize Visual C++ with the Visio UML add-in. Your Visual C++ project must include a browse information file, which the Visio UML add-in uses to create a model in Visio. The Visio UML add-in can reverse engineer the following C++ language constructs: classes, user-defined types, enumerated types, member functions, member variables, and method parameters.
Follow these steps to customize Visual C++ code so you can reverse engineer it:
In Visual C++, choose Tools, Customize.
In the Customize dialog box, click the Add-Ins And Macro Files tab.
In the Add-Ins And Macro Files list, select Visio UML Add-In.
Click Close to add the floating Visio UML Add-In toolbar.
If you don’t already have a browse information file for a project, open the project, and then choose Project, Settings.
In the Project Settings dialog box, choose the type of build configuration you want, click the C/C++ tab, and then select Generate Browse Info.
Click the Browse Info tab to specify the name and location of the browse information file, select Build Browse Info File, and then click OK.
Follow these steps to reverse engineer Visual C++ 6 source code:
Build the project in Visual C++.
Tip | Make sure your project includes header files for your classes. If your project doesn’t have a header file for a class, that class will not appear in the model that Visio reverse engineers. |
In Visual C++, click the Reverse Engineer UML Model button on the Visio UML Add- In toolbar.
Note | If more than one project exists in the Visual C++ workspace, in the Select Project dialog box, select the project you want to reverse engineer, and then click OK. If more than one browse information file appears in the project hierarchy, in the Select Browse File dialog box, select the file you want to use, and then click OK. |
Visio opens a blank static structure diagram drawing page and the Model Explorer, which is populated with elements that reflect the class definitions in the source code.
To create a static structure diagram, drag elements from the Model Explorer onto the blank static structure diagram drawing page.
Visio creates a model based on the contents of a browse information file, which can include errors. According to Microsoft, the browse information file application programming interface (API) has several known bugs that affect its ability to handle C++ templates. Because of this limitation, long parameter lists are not always reverse engineered, and class names and class method names are sometimes corrupted, which causes Visio to ignore them or sometimes add the corrupted name to the UML model. Visio creates a log file of errors detected during the reverse engineering process and saves the file in the system temporary folder with the name of the project; for example, C:\Winnt\Temp\Project.txt.
To reverse engineer Visual Basic source code, you must load the Microsoft Visio UML Visual Basic Add-In into Visual Basic. The add-in displays the Microsoft Visio UML Solution toolbar and adds the Microsoft Visio UML Solution menu to the Tools menu; both the toolbar and the menu will continue to appear every time you open Visual Basic. The UML add-in can reverse engineer the following Visual Basic language constructs: classes, modules, and forms; functions and subroutines; parameters; constants; member variables; properties; events; and user-defined types.
Follow these steps to customize Visual Basic so you can reverse engineer Visual Basic 6 code:
In Visual Basic, choose Add-Ins, Add-In Manager.
Select Microsoft Visio UML Visual Basic Addin. For Load Behavior, select the Loaded/ Unloaded and Load On Startup check boxes, and then click OK.
Note | You need to set up the add-in in the Add-In Manager only once. |
Open the project that contains the source code you want to reverse engineer.
In Visual Basic, click the Reverse Engineer UML Model button on the Visio UML Solution toolbar.
Visio opens a blank static structure diagram drawing page and the Model Explorer, which is populated with elements that reflect the class definitions in the source code.
Drag elements from the Model Explorer onto the blank static structure diagram drawing page to create a static structure diagram.
|