C++ 如何使用 Enterprise Architect 或 Rational Software Architect 从源代码创建类图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12432016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:15:54  来源:igfitidea点击:

How to create class diagram from source code using either Enterprise Architect or Rational Software Architect?

c++umlenterprise-architect

提问by Dan Nissenbaum

I am not fluent in UML, but I would like to create a class diagram based on existing C++ code. Other StackOverflow questions have indicated that two programs - Enterprise Architect and Rational Software Architect - are fairly good at "reverse engineering" C++ code (i.e., creating UML class diagrams based on existing C++ code).

我不精通 UML,但我想根据现有的 C++ 代码创建一个类图。其他 StackOverflow 问题表明两个程序——Enterprise Architect 和 Rational Software Architect——非常擅长“逆向工程”C++ 代码(即,基于现有 C++ 代码创建 UML 类图)。

I have downloaded the trial version for both of these applications. However, I cannot make any headway into understanding what to do to create a class diagram in either of these applications.

我已经下载了这两个应用程序的试用版。但是,我无法在理解如何在这些应用程序中的任何一个中创建类图方面取得任何进展。

In Rational Software Architect, I have created a UML project, but I cannot find any way within the program to select, and reverse engineer, my existing C++ code.

在 Rational Software Architect 中,我创建了一个 UML 项目,但是我在程序中找不到任何方法来选择和反向工程我现有的 C++ 代码。

In Enterprise Architect, I was able to import my C++ code, but all the elements (classes) appeared in a useless, overlapping diagonal line within the diagram. I attempted other settings, such as circle, but these were equally impossible to read because the diagrams were so large (due to the attributes and methods taking up alot of space) that no amount of panning and zooming was useful. What I would like is to hide everything except the class names (i.e., not display any methods or attributes) so that all 20 classes appear conveniently and legibly in one screen.

在 Enterprise Architect 中,我能够导入我的 C++ 代码,但所有元素(类)都出现在图中一条无用的、重叠的对角线上。我尝试了其他设置,例如圆,但这些设置同样无法阅读,因为图表太大(由于属性和方法占用了大量空间)以至于没有多少平移和缩放是有用的。我想要的是隐藏除类名之外的所有内容(即,不显示任何方法或属性),以便所有 20 个类都可以方便且清晰地出现在一个屏幕中。

However, I am unable to find a way to hide everything except the class names. Rather, when I found an option (in Enterprise Architect) that seemed like it might hide everything but the class names, for some reason the elements all vanished in the class diagram, and no amount of repeating the steps & deleting and re-adding packages made the class diagram reappear.

但是,我无法找到隐藏除类名以外的所有内容的方法。相反,当我发现一个选项(在 Enterprise Architect 中)似乎可能隐藏除类名之外的所有内容时,出于某种原因,类图中的元素都消失了,并且没有重复步骤和删除和重新添加包使类图重新出现。

Note: My C++ code (at least those files I selected for import into Enterprise Architect) amount to only about 20 classes.

注意:我的 C++ 代码(至少是我选择导入 Enterprise Architect 的那些文件)只有大约 20 个类。

Sadly, a very careful search of the documentation for both of these programs provides only generalities - no specific instructions are given regarding reverse engineering for either of these programs, so far as I could find.

可悲的是,对这两个程序的文档进行了非常仔细的搜索,仅提供了一般性 - 就我所能找到的而言,没有给出关于这两个程序中任何一个的逆向工程的具体说明。

I would be grateful if someone could tell me the basic steps to create a legible, easy-to-navigate diagram via. reverse engineering (i.e., C++-to-UML) that shows only the class names, so that about 20 classes fit (legibly) on one screen, using either Enterprise Architect, or Rational Software Architect - OR any other tool whatsoever that is capable of doing this (I suggest EA and Rational only because they have been highlighted in other StackOverflow answers as the best programs available for this purpose).

如果有人能告诉我创建清晰易读的图表的基本步骤,我将不胜感激。逆向工程(即,C++-to-UML)只显示类名,因此使用 Enterprise Architect 或 Rational Software Architect - 或任何其他能够执行此操作的工具,大约 20 个类可以(清晰地)显示在一个屏幕上这样做(我建议 EA 和 Rational 只是因为它们在其他 StackOverflow 答案中被强调为可用于此目的的最佳程序)。

回答by Uffe

This answer applies to EA.

此答案适用于 EA。

You can import individual files or whole directories, recursively or no. Directory import is by far the most common case; single file import does not allow you to create a diagram automatically.

您可以递归或不导入单个文件或整个目录。目录导入是迄今为止最常见的情况;单个文件导入不允许您自动创建图表。

When you import a source directory, you have the option of creating diagrams for each UML package, or no diagrams at all. You also decide whether to create packages for each source code directory, namespace (default) or file.

当您导入源目录时,您可以选择为每个 UML 包创建图表,或者根本不创建图表。您还决定是否为每个源代码目录、命名空间(默认)或文件创建包。

If your code constists of only 20 classes then it's likely they're in a single directory and/or namespace, so play around with that option (Package Structure in the Import Source dialog) to get the right number of diagrams.

如果您的代码仅包含 20 个类,那么它们很可能位于单个目录和/或命名空间中,因此请使用该选项(导入源对话框中的包结构)以获得正确数量的图表。

In the same dialog, there's a button "New Diagram Options," which opens another config dialog where you can choose whether the diagrams should contain the classes' attributes and/or operations. You can also make the decision on a visibility basis, eg show public members only.

在同一个对话框中,有一个按钮“New Diagram Options”,它打开另一个配置对话框,您可以在其中选择图表是否应包含类的属性和/或操作。您还可以根据可见性做出决定,例如仅显示公共成员。

This dialog only affects what's shown in the diagrams when they are created. The members are still imported, just not displayed. This sounds like what you're after.

此对话框仅影响创建图表时显示的内容。成员仍然被导入,只是不显示。这听起来像你所追求的。

You can change the display options for any diagram by double-clicking an empty area of it, or right-clicking and selecting Properties. It sounds like you got into this dialog and changed something around, but I can't really tell what. The situation you describe, where you can't get the display back the way it was, is not one I've ever encountered in EA.

您可以通过双击任何图表的空白区域或右键单击并选择“属性”来更改任何图表的显示选项。听起来你进入了这个对话并改变了一些东西,但我真的不知道是什么。您描述的情况,您无法将显示恢复原状,这不是我在 EA 中遇到过的。

It is also possible to select display options on a per-class basis by right-clicking it in the diagram and selecting Feature Visibility. I don't recommend you use this in reverse-engineered diagrams, I'm just mentioning it for completeness.

也可以通过在图表中右键单击它并选择特征可见性来基于每个类选择显示选项。我不建议你在逆向工程图中使用它,我只是为了完整性而提到它。

The layout you describe, with all classes in a meaningless diagonal, suggests to me that the diagram isn't being laid out properly after creation. The diagram creation is a two-step process; first all the classes are dropped onto it, then the layout is applied.

您描述的布局,所有类都在一个无意义的对角线上,向我表明该图在创建后没有正确布局。图的创建是一个两步过程;首先将所有类放到它上面,然后应用布局。

This is strange, as EA automatically lays out generated diagrams and I haven't been able to find an option which allows you to deselect this behaviour. If this persists, send a bug report to Sparx Systems. You can always lay out the diagram by opening it and selecting Layout Diagram from the top-level Diagram menu.

这很奇怪,因为 EA 会自动布置生成的图表,而我找不到允许您取消选择此行为的选项。如果这种情况仍然存在,请向 Sparx Systems 发送错误报告。您始终可以通过打开图表并从顶级图表菜单中选择布局图表来布置图表。

If, finally, your classes are spread out among different packages andnamespaces so that EA generates multiple diagrams for them, you'll have to merge them manually. Do this by opening both diagrams, selecting all (Ctrl-A) in one, copying (Ctrl-C) and pasting (Ctrl-V) into the other, then ask EA to Layout Diagram again.

最后,如果您的类分布在不同的包命名空间中,以便 EA 为它们生成多个图表,则必须手动合并它们。通过打开两个图表,在一个图表中选择所有 (Ctrl-A),复制 (Ctrl-C) 并粘贴 (Ctrl-V) 到另一个图表,然后再次要求 EA 布局图表。

So:

所以:

  1. Right-click an empty package in the project browser, select Code Engineering - Import Source Directory.
  2. In the dialog, select the root directory and source type.
  3. Tick "Create Logical Diagram for Each Package" and select the Package Structure which best fits your source structure.
  4. Click "New Diagram Options" and in the new dialog untick "Show Attributes," "Show Operations" and "Show Property Methods" if applicable.
  5. OK both dialogs.
  6. If multiple diagrams have been created, copy all classes into a single diagram.
  7. If the layout looks bad, select Diagram - Layout Diagram.
  1. 在项目浏览器中右键单击一个空包,选择代码工程 - 导入源目录。
  2. 在对话框中,选择根目录和源类型。
  3. 勾选“为每个包创建逻辑图”并选择最适合您的源结构的包结构。
  4. 单击“新建图表选项”,然后在新对话框中取消选中“显示属性”、“显示操作”和“显示属性方法”(如果适用)。
  5. 确定两个对话框。
  6. 如果创建了多个图表,请将所有类复制到一个图表中。
  7. 如果布局看起来很糟糕,请选择图表 - 布局图表。

Hope this helps.

希望这可以帮助。

回答by Amruth A

Auto Generate Class Diagram From Source Code Using Enterprise architect 15

使用企业架构师从源代码自动生成类图 15

Explanation in vedio

视频中的解释

Generate Class Diagram From Source Code Simple Example Explained How to import source code in Enterprise Architect 15? Steps are -

从源代码生成类图简单示例解释如何在 Enterprise Architect 15 中导入源代码?步骤是——

1) Select the model – as a class diagram.

1) 选择模型——作为类图。

2) Delete the sample example in the default model created.

2) 删除创建的默认模型中的示例示例。

3) Import Source files in the model.

3) 在模型中导入源文件。

4) And Select the necessary options.

4)并选择必要的选项。