Commit d194a39f authored by Cloud's avatar Cloud

Resolve stash pop conflicts in modelicaExporter.js with camelCase instance names

parent 231f4574
...@@ -87,6 +87,7 @@ export function exportToModelica(data, modelName = 'Circuit') { ...@@ -87,6 +87,7 @@ export function exportToModelica(data, modelName = 'Circuit') {
} }
}); });
const usedPackages = new Set(); const usedPackages = new Set();
// 占位 — 后续回填 import 语句 // 占位 — 后续回填 import 语句
const importInsertIdx = lines.length; const importInsertIdx = lines.length;
...@@ -95,7 +96,7 @@ export function exportToModelica(data, modelName = 'Circuit') { ...@@ -95,7 +96,7 @@ export function exportToModelica(data, modelName = 'Circuit') {
nodes.forEach((node, idx) => { nodes.forEach((node, idx) => {
const td = node.data?.templateData; const td = node.data?.templateData;
const type = td?.type; const type = td?.type;
const label = node.data?.label || `comp_${idx}`; const label = node.data?.label || '';
const mapping = getModelMapping(type); const mapping = getModelMapping(type);
...@@ -104,8 +105,11 @@ export function exportToModelica(data, modelName = 'Circuit') { ...@@ -104,8 +105,11 @@ export function exportToModelica(data, modelName = 'Circuit') {
if (mapping && mapping.modelName) { if (mapping && mapping.modelName) {
baseName = mapping.modelName.charAt(0).toLowerCase() + mapping.modelName.slice(1); baseName = mapping.modelName.charAt(0).toLowerCase() + mapping.modelName.slice(1);
} else { } else {
baseName = toMoId(label); const safeLabel = label || (type || 'comp');
baseName = safeLabel.replace(/[-_]([a-zA-Z])/g, (_, c) => c.toUpperCase());
baseName = toMoId(baseName); // Enforce valid Mo ID
} }
// 按 baseName 分组计数,生成唯一序号 // 按 baseName 分组计数,生成唯一序号
if (!instanceCounter[baseName]) instanceCounter[baseName] = 0; if (!instanceCounter[baseName]) instanceCounter[baseName] = 0;
instanceCounter[baseName]++; instanceCounter[baseName]++;
...@@ -193,6 +197,7 @@ export function exportToModelica(data, modelName = 'Circuit') { ...@@ -193,6 +197,7 @@ export function exportToModelica(data, modelName = 'Circuit') {
// 插入组件声明 // 插入组件声明
declLines.forEach(l => lines.push(l)); declLines.forEach(l => lines.push(l));
lines.push(''); lines.push('');
// ===== 2. 构建流程节点端口到连接源的映射 ===== // ===== 2. 构建流程节点端口到连接源的映射 =====
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment