# my-pyumlmodel **Repository Path**: sn_yang/my-pyumlmodel ## Basic Information - **Project Name**: my-pyumlmodel - **Description**: Python Convert UML xmi to C++ Models - **Primary Language**: Unknown - **License**: LGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-01-08 - **Last Updated**: 2024-10-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python UML Model ## 主要功能 ### 转换 UML Model 为 C++ 代码 #### 输入数据 - [DC.xmi](.\data\uml\DC.xmi) The Diagram Common (DC) package contains abstractions shared by the Diagram Interchange and the Diagram Graphics packages - [DI.xmi](.\data\uml\DI.xmi) The Diagram Interchange (DI) package enables interchange of graphical information that language users have control over, such as position of nodes and line routing points. Language specifications specialize elements of DI to define diagram interchange elements for a language. - [UML.xmi](.\data\uml\UML-v2.5-PrimitiveTypes.xmi) UML 类的定义包 - [UMLDI.xmi](.\data\uml\UML-v2.5-UMLDI.xmi) UML 视图类的定义包 - [StandardProfile.xmi](.\data\uml\UML-v2.5-StandardProfile.xmi) UML 标准 Profile 定义 - [PrimitiveTypes.xmi](.\data\uml\UML-v2.5-PrimitiveTypes.xmi) #### 输出数据 - `data\uml-json\*_orig.json`: 将 XMI 转换成 json 文件。 - `data\uml-json\*.json`: 将上述 json 文件,根据一些(为了能够更好的生成代码而建立的)规则转换成的文件。 - `uml/[*.h|*.cpp]`: UML 类 - `umldi/[*.h|*.cpp]`: UML 视图类 #### 转换规则 - 消除菱形属性 - 关键字替换(字段,getter,setter,function,paramater) ```json keyword_map = { "class": "class2", "default": "default2", "interface": "interface2", "namespace": "namespace2", "slots": "slots2", "template": "template2", } ``` ### 根据 UML 类,生成支持 QtPropertyBrowser 的代码 - 修改 `gen\gen_providers.py` ```py property_providers = ["Class", "State", "Actor", "Trigger"] ``` - 修改 `main.py`,让它运行 `app.gen_property_provider()` ```py if __name__ == "__main__": start_time = time.time() app = main() # app.run() app.gen_property_provider() end_time = time.time() print(timedelta(seconds=end_time - start_time)) ``` - 运行 `main.py` - 复制生成的代码到 QtPropertyBrowser 项目中 生成的代码:`temp\providers` ## 安装 python ### 国内源 - 创建目录 `%USERPROFILE%/pip` - `%USERPROFILE%/pip/pip.ini` ```ini [global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com ``` ### 安装组件 - 这是安装在 Python 目录里 - mypy: 支持强类型 - flake8, black, pylint, isort: 用于代码的规范检查和格式化 - poetry: 是一个 Python 虚拟环境和依赖管理的工具 ```sh python -m pip install --upgrade pip pip install poetry # dev: pip install mypy flake8 pylint black isort # for product pip install scipy numpy pyside2 plotly kaleido # poetry: 检测版本(直接运行) poetry --version # poetry: 检测版本(以 python 模块方式运行) python -m poetry --version ``` ### 安装项目依赖包 ```sh # 设置默认源 poetry source add aliyun "http://mirrors.aliyun.com/pypi/simple/" # 激活 python 虚拟环境 poetry shell # 安装项目的依赖包 poetry install # 退出虚拟环境 poetry deativate ``` ### 运行 ### 单元测试 ```sh ./unittest.sh ``` ## 其它 有些项目使用来管理第三方的包。这时,使用下面的命令来安装包 - Requirements.txt ```sh python -m venv .venv ./.venv/Scripts/activate pip install -r requirements.txt ```