万一有人需要解决方案,这就是我最终提出这个问题的方式。该解决方案的灵感来自于 shape.xml(来自 源代码的第 38 行):
定义要添加到调色板的形状(来自 Sidebar.js 文件的函数)
this.createVertexTemplateEntry( 'shape=mxgraph.module.type;', 100, 100, '', 'Type', null, null, '')
在 Stencils/module.xml 中添加带有约束的形状元素,描述输入-输出引脚坐标(命名为 N,S)、形状矩形rect和带有指向 png 图片路径的图像元素:
<shapes name="mxgraph.module">
<shape aspect="variable" h="100" name="Type" strokewidth="1" w="100">
<connections>
<constraint name="N" perimeter="0" x="0.5" y="0"/>
<constraint name="S" perimeter="0" x="0.5" y="1"/>
</connections>
<foreground>
<rect h="60" w="30" x="0" y="0"/>
<fillstroke/>
</foreground>
</shape>
<shape aspect="variable" h="60" name="Workbench Connection" strokewidth="1" w="30">
<connections>
<constraint name="N" perimeter="0" x="0.5" y="0"/>
<constraint name="S" perimeter="0" x="0.5" y="1"/>
<constraint name="E" perimeter="0" x="0" y="0.5"/>
</connections>
<foreground>
<rect h="100" w="100" x="0" y="0"/>
<fillstroke/>
<image src="assets/picture.png" x="0" y="0" w="100" h="10" flipH="0"/>
</foreground>
</shape>
</shapes>
这样,可以定义输入/输出引脚并保留覆盖。