依据对SALOME、FreeCAD等开源软件的研究,同时结合大型CAx软件ACISE的研发实践,总结了CAx软件设计与开发过程中的部分研究心得。希望能对从事国产CAx软件研发的同行们有所帮助,这是编写本文的主要目的。
青,取之于蓝,而青于蓝;冰,水为之,而寒于水。--- 《荀子·劝学》
注1:限于研究水平,分析难免不当,欢迎批评指正。
注2:文章内容会不定期更新。
零、工作量预估
对SALOME、FreeCAD等大型CAX软件做代码量统计如下,
Total | kernel | ||
SALOME | 152w/226w, 67% | 22w/37w,59% | 16% |
FreeCAD | 89w/132w, 67% | 23w/33w,70% | 25% |
从上述有限的统计可以看出,
- 具有一定规模的大型CAx软件的代码量在150w~200w行左右;
- 核心代码在35万行左右,约占20%左右
- 代码注释在40万行左右,约占30%左右
一、代码实现
1.1 Knowledges about OOD: GoF
Ref. from Acise: A CAx Industrial Software Ecology
Object-oriented design ecourages the distribution of behavior among objects. Such distribution can result in a object structure with many connections between objects. [Mediator]
Structuring a system into subsystems helps reduce complexity. A common design goal is to minimize the communication and dependencies between subsystems. [Facade]
A common side-effect of partitioning a system into a collection of cooperation classes is the need to maintain consistency between related objects. [Observer]
Framework use abstract classes to define and maitain relationship beween objects. [Factory Method]
1.2 常用设计模式
序号 | 模式 | 备注 |
1 | Mediator | Layered MVP |
2 | Observer | Layered MVP |
3 | Command | Layered MVP |
4 | Template Method | |
5 | Abstract Factory | |
6 | Factory Method | |
7 | Iterator | |
8 | Composite | |
9 | Prototype | |
10 | Memento | |
11 | Singleton | |
12 | Adapter | |
13 | Bridge | MDF |
14 | Chain of Responsibility | |
15 | Proxy |
1.3 对象职责编排
序号 | 组件 | 描述 | 典型实现 |
1 | Reflection | RTTR, Qt, MFC,FreeCAD,VTK, OCC | |
2 | MetaObject | ||
3 | Type | ||
4 | TypeRegistry | ||
5 | Logger | Boost.Log | |
6 | MessageHandler | QtxMsgHandlerCallback | |
7 | StringUtils | ||
8 | Persistence | Boost Serilization FreeCAD: ZipWriter, XMLReader, SALOME LightApp_Driver | |
Writer | |||
Reader | |||
9 | PropertyContainer | FreeCAD | |
Property | |||
10 | Object | ||
11 | ObjectRegistry | ||
12 | Entity | ||
13 | signal | Boost.signals2, Qt | |
14 | slot | ||
15 | Data Object | ||
16 | Data Model | Represents a portion of data related to some Module, contains a tree of Data Objects | |
17 | Document | Layered Architecture | |
19 | Application | Layered Architecture | |
20 | Preference | Hold App/Gui configuration data. | FreeCAD: ParameterManager SALOME: QtxResourceMgr SALOME: QtxPreferenceMgr Boost.PropertyTree |
Preference Manager | |||
ParameterGrp | |||
Parameter Manager | |||
Resource Manager | |||
21 | Module | Qt: QPlugin, QLibrary Boost DLL x3py | |
Module Manager | |||
Plugin | |||
Plugin Manager | |||
22 | ArgvKeeper | ||
23 | Application | ||
24 | Command | 对应MVP的命令模型 | |
25 | Request | ||
26 | Command Manager | ||
27 | Transaction | ||
28 | MainWindow | ||
29 | Workbench | ||
30 | Workbench Manager | ||
31 | Action | ||
32 | Action Manager | ||
33 | Menu Item | ||
34 | Menu Manager | ||
35 | Toolbar Item | ||
36 | Toolbar Manager | ||
37 | DockWindow Item | ||
38 | DockWindow Manager | ||
39 | Presenter | ||
40 | View Object | ||
41 | TreeItem TreeModel | ||
42 | PropertyItem PropertyEditor PropertyModel | FreeCAD: PropertyView QtPropertyBrowser | |
43 | PropertyBrowser | ||
44 | View | Abstract Factory | FreeCAD: Gui::View3DInventorViewer SALOME: SOCC_Viewer, VTK_Viewer OpenCASCADE: V3d_Viewer VTK: vtkActorCollection OpenSceneGraph: osgViewer::Viewer |
Hold a group of view objects for views of the given type. | |||
ViewModel | |||
Viewer | Abstract Factory | ||
Viewer Registry | |||
View Manager | |||
45 | DataOwner SelectionObject | SALOME, FreeCAD | |
SelectionManager SelectionSingleton | |||
Selector | |||
SelectionFilter SelectionGate | |||
46 | Launcher | ||
47 | Job | ||
48 | Job Manager | ||
49 | Job Watcher | ||
50 | UserAgent | ||
51 | AsyncConnection | ||
52 | AsyncMessenger | ||
53 | Proxy |
三、架构设计
3.1 Knowledges about architecture: Roy T. Fielding
Ref. from Acise: A CAx Industrial Software Ecology
A software architecture is an abstraction of the run-time elements of a software system during some phase of its operation. A system may be composed of many levels of abstraction and many phases of operation, each with its own software architecture.
Software architecture research investigates methods for determining how best to partition a system, how components identify and communicate with each other, how information is communicated, how elements of a system can evolve independently, and how all of the above can be described using formal and informal notations.
3.2 软件的质量属性
序号 | 属性 | 备注 |
1 | 可维护性 | |
2 | 可移植性 | |
3 | 性能 | |
4 | 安全性 | |
3.3 (架构)设计原则与惯例
序号 | 原则、惯例 | 备注 |
1 | Seperation of Concerns, SoC | |
2 | Single Responsibility Principle | |
3 | Interface Segregation Principle | |
3.4 架构模式
序号 | 模式 | 备注 |
1 | Layered Architecture | 1. 应用场景:业务逻辑垂直切分 2. 典型实现 Two Layers: Business, Presentation Run Mode: Console, GUI Singleton, Facade |
2 | MVP | 1. 释义:Model-View-Presenter 2. 应用场景:界面程序 3. 典型实现 MFC Document/View Architecture Qt Model/View |
3 | CQRS | 1. 释义:Command Query Responsibility Segregation 2. 应用场景:业务水平切分为查询模型、命令模型 |
4 | EDA | 1. 释义:Event-Driven Architecture 2. 应用场景:集成组件 |
5 | MDF | 1. 释义:Modular Development Framework 2. 应用场景:业务逻辑水平切分 |
6 | Cloud Native | 1. 应用场景:多维度切分业务 |
四、原型验证:CAx软件开发框架ACISE
参考文献
Erich Gamma. Design Patterns:elements of reusable object-oriented software. Addison Wesley, 1994.
Joseph Ingeno. Software Architect's Handbook. Packt Publishing, 2018.
Roy T. Fielding. Architectural Styles and the Design of Network-based Software Architectures. 2000.
网络资料
SALOMEhttps://www.salome-platform.org/
FreeCADhttps://www.freecadweb.org/
Martin Fowler's GUI Architecturehttps://martinfowler.com/eaaDev/uiArchs.html
Qt Model/View Programminghttps://doc.qt.io/qt-6/model-view-programming.html